[no commit message]

This commit is contained in:
Alexander Nozik 2016-04-02 21:08:37 +03:00
parent 2b9132b116
commit 5ecad13925
7 changed files with 48 additions and 42 deletions

View File

@ -42,13 +42,6 @@ import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
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;
/**
*
@ -64,7 +57,7 @@ public class Main {
}
@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");
Options options = prepareOptions();
@ -76,15 +69,15 @@ public class Main {
} catch (ParseException exp) {
// oops, something went wrong
logger.error("Command line error. Reason: " + exp.getMessage());
return DataNode.empty();
return;
}
if (line.hasOption("lc")) {
printDescription(context, true);
return DataNode.empty();
return;
} else if (line.hasOption("l")) {
printDescription(context, false);
return DataNode.empty();
return;
}
String cfgPath;
@ -99,7 +92,7 @@ public class Main {
cfgPath = line.getOptionValue("c");
if (cfgPath == null) {
logger.info("Configutation path not provided.");
return DataNode.empty();
return;
}
File configFile = context.io().getFile(cfgPath);
@ -107,17 +100,14 @@ public class Main {
if (!configFile.exists()) {
throw new FileNotFoundException("Configuration file not found");
}
Meta config = MetaFileReader.read(configFile).build();
context.putValue(IOManager.ROOT_DIRECTORY_CONTEXT_KEY, configFile.getParentFile().toString());
applyCLItoContext(line, context);
return ActionUtils.runConfig(context, config);
} else {
Workbench.main(args);
return null;
ActionUtils.runConfig(context, config);
}
}

View File

@ -15,6 +15,8 @@
*/
package inr.numass;
import hep.dataforge.data.FileDataFactory;
import hep.dataforge.data.binary.Binary;
import hep.dataforge.io.BasicIOManager;
import hep.dataforge.meta.Meta;
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();
}
public static RawNMFile readAsPaw(File source) throws FileNotFoundException {
return new NumassPawReader().readPaw(source, source.getName());
public static RawNMFile readAsPaw(Binary source, Meta config) throws IOException {
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 {
RawNMFile dataFile;
String extension = FilenameUtils.getExtension(file.getName()).toLowerCase();
String extension = FilenameUtils.getExtension(config.getString(FileDataFactory.FILE_NAME_KEY)).toLowerCase();
switch (extension) {
case "paw":
dataFile = readAsPaw(file);
dataFile = readAsPaw(binary, config);
break;
case "dat":
dataFile = readAsDat(file, config);
dataFile = readAsDat(binary, config);
break;
default:
throw new RuntimeException("Wrong file format");

View File

@ -17,6 +17,7 @@ package inr.numass.actions;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.context.Context;
import hep.dataforge.data.binary.Binary;
import hep.dataforge.description.NodeDef;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
@ -33,16 +34,16 @@ import java.io.File;
* @author Darksnake
*/
@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 = "HVdev", info = "Divider for HV measurements. Should be set to 1.0 for numass data 2014",
def = "2.468555393226049", type = "NUMBER")
@ValueDef(name = "noUset", info = "If 'true', then Uset = Uread")
@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
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());
RawNMFile raw = getNumassData(source, meta);
if (meta.getBoolean("paw", false)) {

View File

@ -15,6 +15,8 @@
*/
package inr.numass.data;
import hep.dataforge.data.FileDataFactory;
import hep.dataforge.data.binary.Binary;
import hep.dataforge.meta.Meta;
import java.io.BufferedInputStream;
import java.io.File;
@ -38,8 +40,8 @@ public class NumassDataReader {
private double HVdev = 2.468555393226049;
private boolean noUset = false;
public NumassDataReader(File file, Meta config) throws IOException {
this(new FileInputStream(file), file.getName(), config);
public NumassDataReader(Binary file, Meta config) throws IOException {
this(file.getStream(), config.getString(FileDataFactory.FILE_NAME_KEY), config);
}
public NumassDataReader(String file, String fname, Meta config) throws FileNotFoundException {

View File

@ -15,9 +15,12 @@
*/
package inr.numass.data;
import hep.dataforge.data.binary.Binary;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import java.util.Scanner;
@ -27,18 +30,18 @@ import java.util.Scanner;
*/
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);
FileInputStream bs = new FileInputStream(file);
return readPaw(new Scanner(bs), name);
return readPaw(file.getStream(), name);
}
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);
while (s.hasNext()) {

View File

@ -15,6 +15,7 @@
*/
package inr.numass.server;
import hep.dataforge.data.binary.Binary;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.io.envelopes.Envelope;
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.values.Value;
import inr.numass.storage.NumassStorage;
import java.io.IOException;
/**
* 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 fileName = message.meta().getString("name")
.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
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();
}
}
@ -120,7 +122,5 @@ public class NumassRun implements Annotated, Responder {
public StateLoader getStates() {
return states;
}
}

View File

@ -15,6 +15,7 @@
*/
package inr.numass.storage;
import hep.dataforge.data.binary.Binary;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.io.envelopes.DefaultEnvelopeReader;
import hep.dataforge.io.envelopes.Envelope;
@ -47,6 +48,8 @@ import java.util.List;
import java.util.Map;
import java.util.function.Function;
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.FileSystemException;
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) {
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.order(ByteOrder.LITTLE_ENDIAN);
double timeCoef = envelope.meta().getDouble("time_coeff",50);
double timeCoef = envelope.meta().getDouble("time_coeff", 50);
while (buffer.hasRemaining()) {
try {
short channel = (short) Short.toUnsignedInt(buffer.getShort());
long time = Integer.toUnsignedLong(buffer.getInt());
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);
} catch (Exception ex) {
//LoggerFactory.getLogger(MainDataReader.class).error("Error in data format", ex);
@ -321,6 +329,6 @@ public class NumassDataLoader extends AbstractLoader implements BinaryLoader<Env
@Override
public void open() throws Exception {
}
}