numass-framework/numass-main/src/main/java/inr/numass/actions/SlicingAction.java

83 lines
2.8 KiB
Java
Raw Normal View History

2015-12-18 16:20:47 +03:00
/*
* Copyright 2015 Alexander Nozik.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.actions;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.context.Context;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.ColumnedDataWriter;
2016-03-27 20:40:50 +03:00
import hep.dataforge.meta.Laminate;
2015-12-18 16:20:47 +03:00
import hep.dataforge.meta.Meta;
import inr.numass.data.NMFile;
import inr.numass.data.RawNMPoint;
import java.io.OutputStream;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.math3.util.Pair;
2016-04-30 16:13:50 +03:00
import hep.dataforge.io.reports.Reportable;
2015-12-18 16:20:47 +03:00
/**
*
* @author Darksnake
*/
@TypedActionDef(name = "slicing", inputType = NMFile.class, outputType = NMFile.class)
public class SlicingAction extends OneToOneAction<NMFile, NMFile> {
public static final String name = "slicing";
@Override
public String getName() {
return name;
}
@Override
2016-04-30 16:13:50 +03:00
protected NMFile execute(Context context, Reportable log, String name, Laminate meta, NMFile source) throws ContentException {
2015-12-18 16:20:47 +03:00
boolean normalize;
Map<String, Pair<Integer, Integer>> slicingConfig;
LinkedHashMap<String, Pair<Integer, Integer>> res = new LinkedHashMap<>();
2016-03-27 20:40:50 +03:00
List<? extends Meta> list = meta.getNode("sliceconfig").getNodes("slicepoint");
2015-12-18 16:20:47 +03:00
for (Meta slice : list) {
String title = slice.getString("title", slice.getName());
int from = slice.getInt("from", 0);
int to = slice.getInt("to", RawNMPoint.MAX_CHANEL);
res.put(title, new Pair<>(from, to));
}
slicingConfig = res;
2016-03-27 20:40:50 +03:00
normalize = meta.getBoolean("normalize", false);
2015-12-18 16:20:47 +03:00
if (slicingConfig == null) {
throw new RuntimeException("Slice configuration not defined");
}
2016-04-30 16:13:50 +03:00
log.report("File {} started", source.getName());
2015-12-18 16:20:47 +03:00
SlicedData sData = new SlicedData(source, slicingConfig, normalize);
2016-03-27 20:40:50 +03:00
OutputStream stream = buildActionOutput(context, name);
2015-12-18 16:20:47 +03:00
2016-03-21 15:29:31 +03:00
ColumnedDataWriter.writeDataSet(stream, sData, null);
2015-12-18 16:20:47 +03:00
2016-04-30 16:13:50 +03:00
log.report("File {} completed", source.getName());
2015-12-18 16:20:47 +03:00
return source;
}
}