Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.nio.file.Path;
import java.util.TreeMap;
import java.util.TreeSet;
import org.jlab.analysis.postprocess.Processor;
import org.jlab.clara.std.services.EventWriterException;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class DecoderWriter extends HipoToHipoWriter {
Bank runConfig;
Bank helicityAdc;
ConstantsManager conman;
TreeMap<Integer,Integer> unixEventMap;
TreeSet<HelicityState> helicities;
DaqScalersSequence scalers;
SchemaFactory fullSchema;
Expand All @@ -49,6 +51,7 @@ private void init(JSONObject opts) {
runConfig = new Bank(fullSchema.getSchema("RUN::config"));
helicityAdc = new Bank(fullSchema.getSchema("HEL::adc"));
helicities = new TreeSet<>();
unixEventMap = new TreeMap<>();
scalers = new DaqScalersSequence(fullSchema);
conman = new ConstantsManager();
conman.init("/runcontrol/hwp","/runcontrol/helicity");
Expand All @@ -72,7 +75,7 @@ protected HipoWriterSorted createWriter(Path file, JSONObject opts) throws Event
throw new EventWriterException(e);
}
}

/**
* In addition to writing the incoming event, copies all tag-1 banks to new
* tag-1 events and writes them, and stores helicity/scaler readings for later.
Expand All @@ -85,6 +88,14 @@ protected void writeEvent(Object event) throws EventWriterException {
((Event)event).read(runConfig);
((Event)event).read(helicityAdc);
helicities.add(HelicityState.createFromFadcBank(helicityAdc, runConfig, conman));
if (runConfig.getRows() > 0) {
int unix = runConfig.getInt("unixTime",0);
int evno = runConfig.getInt("event",0);
// if this event has a good unix time, store it for later:
if (unix > 0) unixEventMap.put(evno, unix);
// otherwise update it with the latest unix time reading:
else runConfig.putInt("unixTime",0, unixEventMap.get(unixEventMap.floorKey(evno)));
}
Event t = CLASDecoder4.createTaggedEvent((Event)event, runConfig, tag1banks);
if (!t.isEmpty()) writer.addEvent(t, 1);
super.writeEvent(event);
Expand All @@ -100,8 +111,9 @@ protected void closeWriter() {
super.closeWriter();
if (postprocess) postprocess();
// keep the latest helicity/scaler reading for the next file:
while (helicities.size() > 60) helicities.pollFirst();
scalers.clear(10);
while (helicities.size() > 100) helicities.pollFirst();
while (unixEventMap.size() > 100) unixEventMap.pollFirstEntry();
scalers.clear(100);
}

private int getRunNumber() {
Expand Down