[no commit message]
This commit is contained in:
parent
2b9132b116
commit
5ecad13925
@ -42,13 +42,6 @@ import org.apache.commons.cli.ParseException;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import static java.util.Locale.setDefault;
|
import static java.util.Locale.setDefault;
|
||||||
import static java.util.Locale.setDefault;
|
|
||||||
import static java.util.Locale.setDefault;
|
|
||||||
import static java.util.Locale.setDefault;
|
|
||||||
import static java.util.Locale.setDefault;
|
|
||||||
import static java.util.Locale.setDefault;
|
|
||||||
import static java.util.Locale.setDefault;
|
|
||||||
import static java.util.Locale.setDefault;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -64,7 +57,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static DataNode run(NumassContext context, String[] args) throws Exception {
|
public static void run(NumassContext context, String[] args) throws Exception {
|
||||||
Logger logger = LoggerFactory.getLogger("numass-main");
|
Logger logger = LoggerFactory.getLogger("numass-main");
|
||||||
|
|
||||||
Options options = prepareOptions();
|
Options options = prepareOptions();
|
||||||
@ -76,15 +69,15 @@ public class Main {
|
|||||||
} catch (ParseException exp) {
|
} catch (ParseException exp) {
|
||||||
// oops, something went wrong
|
// oops, something went wrong
|
||||||
logger.error("Command line error. Reason: " + exp.getMessage());
|
logger.error("Command line error. Reason: " + exp.getMessage());
|
||||||
return DataNode.empty();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.hasOption("lc")) {
|
if (line.hasOption("lc")) {
|
||||||
printDescription(context, true);
|
printDescription(context, true);
|
||||||
return DataNode.empty();
|
return;
|
||||||
} else if (line.hasOption("l")) {
|
} else if (line.hasOption("l")) {
|
||||||
printDescription(context, false);
|
printDescription(context, false);
|
||||||
return DataNode.empty();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String cfgPath;
|
String cfgPath;
|
||||||
@ -99,7 +92,7 @@ public class Main {
|
|||||||
cfgPath = line.getOptionValue("c");
|
cfgPath = line.getOptionValue("c");
|
||||||
if (cfgPath == null) {
|
if (cfgPath == null) {
|
||||||
logger.info("Configutation path not provided.");
|
logger.info("Configutation path not provided.");
|
||||||
return DataNode.empty();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File configFile = context.io().getFile(cfgPath);
|
File configFile = context.io().getFile(cfgPath);
|
||||||
@ -114,10 +107,7 @@ public class Main {
|
|||||||
|
|
||||||
applyCLItoContext(line, context);
|
applyCLItoContext(line, context);
|
||||||
|
|
||||||
return ActionUtils.runConfig(context, config);
|
ActionUtils.runConfig(context, config);
|
||||||
} else {
|
|
||||||
Workbench.main(args);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass;
|
package inr.numass;
|
||||||
|
|
||||||
|
import hep.dataforge.data.FileDataFactory;
|
||||||
|
import hep.dataforge.data.binary.Binary;
|
||||||
import hep.dataforge.io.BasicIOManager;
|
import hep.dataforge.io.BasicIOManager;
|
||||||
import hep.dataforge.meta.Meta;
|
import hep.dataforge.meta.Meta;
|
||||||
import hep.dataforge.names.Name;
|
import hep.dataforge.names.Name;
|
||||||
@ -97,24 +99,24 @@ public class NumassIO extends BasicIOManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RawNMFile readAsDat(File source, Meta config) throws IOException {
|
public static RawNMFile readAsDat(Binary source, Meta config) throws IOException {
|
||||||
return new NumassDataReader(source, config).read();
|
return new NumassDataReader(source, config).read();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RawNMFile readAsPaw(File source) throws FileNotFoundException {
|
public static RawNMFile readAsPaw(Binary source, Meta config) throws IOException {
|
||||||
return new NumassPawReader().readPaw(source, source.getName());
|
return new NumassPawReader().readPaw(source, config.getString(FileDataFactory.FILE_NAME_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RawNMFile getNumassData(File file, Meta config) {
|
public static RawNMFile getNumassData(Binary binary, Meta config) {
|
||||||
try {
|
try {
|
||||||
RawNMFile dataFile;
|
RawNMFile dataFile;
|
||||||
String extension = FilenameUtils.getExtension(file.getName()).toLowerCase();
|
String extension = FilenameUtils.getExtension(config.getString(FileDataFactory.FILE_NAME_KEY)).toLowerCase();
|
||||||
switch (extension) {
|
switch (extension) {
|
||||||
case "paw":
|
case "paw":
|
||||||
dataFile = readAsPaw(file);
|
dataFile = readAsPaw(binary, config);
|
||||||
break;
|
break;
|
||||||
case "dat":
|
case "dat":
|
||||||
dataFile = readAsDat(file, config);
|
dataFile = readAsDat(binary, config);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Wrong file format");
|
throw new RuntimeException("Wrong file format");
|
||||||
|
@ -17,6 +17,7 @@ package inr.numass.actions;
|
|||||||
|
|
||||||
import hep.dataforge.actions.OneToOneAction;
|
import hep.dataforge.actions.OneToOneAction;
|
||||||
import hep.dataforge.context.Context;
|
import hep.dataforge.context.Context;
|
||||||
|
import hep.dataforge.data.binary.Binary;
|
||||||
import hep.dataforge.description.NodeDef;
|
import hep.dataforge.description.NodeDef;
|
||||||
import hep.dataforge.description.TypedActionDef;
|
import hep.dataforge.description.TypedActionDef;
|
||||||
import hep.dataforge.description.ValueDef;
|
import hep.dataforge.description.ValueDef;
|
||||||
@ -33,16 +34,16 @@ import java.io.File;
|
|||||||
* @author Darksnake
|
* @author Darksnake
|
||||||
*/
|
*/
|
||||||
@TypedActionDef(name = "readData",
|
@TypedActionDef(name = "readData",
|
||||||
inputType = File.class, outputType = NMFile.class, description = "Read binary numass data file")
|
inputType = Binary.class, outputType = NMFile.class, description = "Read binary numass data file")
|
||||||
@ValueDef(name = "fileName", info = "The name of the file. By default equals file name.")
|
@ValueDef(name = "fileName", info = "The name of the file. By default equals file name.")
|
||||||
@ValueDef(name = "HVdev", info = "Divider for HV measurements. Should be set to 1.0 for numass data 2014",
|
@ValueDef(name = "HVdev", info = "Divider for HV measurements. Should be set to 1.0 for numass data 2014",
|
||||||
def = "2.468555393226049", type = "NUMBER")
|
def = "2.468555393226049", type = "NUMBER")
|
||||||
@ValueDef(name = "noUset", info = "If 'true', then Uset = Uread")
|
@ValueDef(name = "noUset", info = "If 'true', then Uset = Uread")
|
||||||
@NodeDef(name = "debunch", target = "class::inr.numass.actions.DebunchAction", info = "If given, governs debunching")
|
@NodeDef(name = "debunch", target = "class::inr.numass.actions.DebunchAction", info = "If given, governs debunching")
|
||||||
public class ReadNumassDataAction extends OneToOneAction<File, NMFile> {
|
public class ReadNumassDataAction extends OneToOneAction<Binary, NMFile> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NMFile execute(Context context, Logable log, String name, Laminate meta, File source) throws ContentException {
|
protected NMFile execute(Context context, Logable log, String name, Laminate meta, Binary source) throws ContentException {
|
||||||
// log.logString("File '%s' started", source.getName());
|
// log.logString("File '%s' started", source.getName());
|
||||||
RawNMFile raw = getNumassData(source, meta);
|
RawNMFile raw = getNumassData(source, meta);
|
||||||
if (meta.getBoolean("paw", false)) {
|
if (meta.getBoolean("paw", false)) {
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.data;
|
package inr.numass.data;
|
||||||
|
|
||||||
|
import hep.dataforge.data.FileDataFactory;
|
||||||
|
import hep.dataforge.data.binary.Binary;
|
||||||
import hep.dataforge.meta.Meta;
|
import hep.dataforge.meta.Meta;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -38,8 +40,8 @@ public class NumassDataReader {
|
|||||||
private double HVdev = 2.468555393226049;
|
private double HVdev = 2.468555393226049;
|
||||||
private boolean noUset = false;
|
private boolean noUset = false;
|
||||||
|
|
||||||
public NumassDataReader(File file, Meta config) throws IOException {
|
public NumassDataReader(Binary file, Meta config) throws IOException {
|
||||||
this(new FileInputStream(file), file.getName(), config);
|
this(file.getStream(), config.getString(FileDataFactory.FILE_NAME_KEY), config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NumassDataReader(String file, String fname, Meta config) throws FileNotFoundException {
|
public NumassDataReader(String file, String fname, Meta config) throws FileNotFoundException {
|
||||||
|
@ -15,9 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.data;
|
package inr.numass.data;
|
||||||
|
|
||||||
|
import hep.dataforge.data.binary.Binary;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
@ -27,18 +30,18 @@ import java.util.Scanner;
|
|||||||
*/
|
*/
|
||||||
public class NumassPawReader {
|
public class NumassPawReader {
|
||||||
|
|
||||||
public RawNMFile readPaw(File file, String name) throws FileNotFoundException{
|
public RawNMFile readPaw(Binary file, String name) throws IOException{
|
||||||
Locale.setDefault(Locale.US);
|
Locale.setDefault(Locale.US);
|
||||||
FileInputStream bs = new FileInputStream(file);
|
return readPaw(file.getStream(), name);
|
||||||
return readPaw(new Scanner(bs), name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RawNMFile readPaw(String filePath) throws FileNotFoundException{
|
public RawNMFile readPaw(String filePath) throws FileNotFoundException{
|
||||||
return readPaw(new File(filePath), filePath);
|
return readPaw(new FileInputStream(filePath), filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private RawNMFile readPaw(Scanner s, String fileName) {
|
private RawNMFile readPaw(InputStream stream, String fileName) {
|
||||||
|
Scanner s = new Scanner(stream);
|
||||||
RawNMFile result = new RawNMFile(fileName);
|
RawNMFile result = new RawNMFile(fileName);
|
||||||
|
|
||||||
while (s.hasNext()) {
|
while (s.hasNext()) {
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.server;
|
package inr.numass.server;
|
||||||
|
|
||||||
|
import hep.dataforge.data.binary.Binary;
|
||||||
import hep.dataforge.exceptions.StorageException;
|
import hep.dataforge.exceptions.StorageException;
|
||||||
import hep.dataforge.io.envelopes.Envelope;
|
import hep.dataforge.io.envelopes.Envelope;
|
||||||
import hep.dataforge.io.envelopes.Responder;
|
import hep.dataforge.io.envelopes.Responder;
|
||||||
@ -25,6 +26,7 @@ import hep.dataforge.storage.commons.LoaderFactory;
|
|||||||
import hep.dataforge.storage.commons.MessageFactory;
|
import hep.dataforge.storage.commons.MessageFactory;
|
||||||
import hep.dataforge.values.Value;
|
import hep.dataforge.values.Value;
|
||||||
import inr.numass.storage.NumassStorage;
|
import inr.numass.storage.NumassStorage;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This object governs remote access to numass storage and performs reading and
|
* This object governs remote access to numass storage and performs reading and
|
||||||
@ -96,10 +98,10 @@ public class NumassRun implements Annotated, Responder {
|
|||||||
String filePath = message.meta().getString("path", "");
|
String filePath = message.meta().getString("path", "");
|
||||||
String fileName = message.meta().getString("name")
|
String fileName = message.meta().getString("name")
|
||||||
.replace(NumassStorage.NUMASS_ZIP_EXTENSION, "");// removing .nm.zip if it is present
|
.replace(NumassStorage.NUMASS_ZIP_EXTENSION, "");// removing .nm.zip if it is present
|
||||||
storage.pushNumassData(filePath, fileName, message.getData());
|
storage.pushNumassData(filePath, fileName, Binary.readToBuffer(message.getData()));
|
||||||
//TODO add checksum here
|
//TODO add checksum here
|
||||||
return factory.okResponseBase("numass.data.push.response", false, false).build();
|
return factory.okResponseBase("numass.data.push.response", false, false).build();
|
||||||
} catch (StorageException ex) {
|
} catch (StorageException | IOException ex) {
|
||||||
return factory.errorResponseBase("numass.data.push.response", ex).build();
|
return factory.errorResponseBase("numass.data.push.response", ex).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,6 +123,4 @@ public class NumassRun implements Annotated, Responder {
|
|||||||
return states;
|
return states;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.storage;
|
package inr.numass.storage;
|
||||||
|
|
||||||
|
import hep.dataforge.data.binary.Binary;
|
||||||
import hep.dataforge.exceptions.StorageException;
|
import hep.dataforge.exceptions.StorageException;
|
||||||
import hep.dataforge.io.envelopes.DefaultEnvelopeReader;
|
import hep.dataforge.io.envelopes.DefaultEnvelopeReader;
|
||||||
import hep.dataforge.io.envelopes.Envelope;
|
import hep.dataforge.io.envelopes.Envelope;
|
||||||
@ -47,6 +48,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import org.apache.commons.vfs2.FileObject;
|
import org.apache.commons.vfs2.FileObject;
|
||||||
import org.apache.commons.vfs2.FileSystemException;
|
import org.apache.commons.vfs2.FileSystemException;
|
||||||
import static org.apache.commons.vfs2.FileType.FOLDER;
|
import static org.apache.commons.vfs2.FileType.FOLDER;
|
||||||
@ -159,16 +162,21 @@ public class NumassDataLoader extends AbstractLoader implements BinaryLoader<Env
|
|||||||
*/
|
*/
|
||||||
public static NMPoint readPoint(Envelope envelope, Function<RawNMPoint, NMPoint> transformation) {
|
public static NMPoint readPoint(Envelope envelope, Function<RawNMPoint, NMPoint> transformation) {
|
||||||
List<NMEvent> events = new ArrayList<>();
|
List<NMEvent> events = new ArrayList<>();
|
||||||
ByteBuffer buffer = envelope.getData();
|
ByteBuffer buffer;
|
||||||
|
try {
|
||||||
|
buffer = Binary.readToBuffer(envelope.getData());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
buffer.position(0);
|
buffer.position(0);
|
||||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
double timeCoef = envelope.meta().getDouble("time_coeff",50);
|
double timeCoef = envelope.meta().getDouble("time_coeff", 50);
|
||||||
while (buffer.hasRemaining()) {
|
while (buffer.hasRemaining()) {
|
||||||
try {
|
try {
|
||||||
short channel = (short) Short.toUnsignedInt(buffer.getShort());
|
short channel = (short) Short.toUnsignedInt(buffer.getShort());
|
||||||
long time = Integer.toUnsignedLong(buffer.getInt());
|
long time = Integer.toUnsignedLong(buffer.getInt());
|
||||||
byte status = buffer.get();
|
byte status = buffer.get();
|
||||||
NMEvent event = new NMEvent(channel, (double)time*timeCoef*1e-9);
|
NMEvent event = new NMEvent(channel, (double) time * timeCoef * 1e-9);
|
||||||
events.add(event);
|
events.add(event);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
//LoggerFactory.getLogger(MainDataReader.class).error("Error in data format", ex);
|
//LoggerFactory.getLogger(MainDataReader.class).error("Error in data format", ex);
|
||||||
|
Loading…
Reference in New Issue
Block a user