|
| 1 | +package org.jlab.detector.serial; |
| 2 | + |
| 3 | +import java.util.TreeMap; |
| 4 | +import java.util.TreeSet; |
| 5 | +import org.jlab.detector.calib.utils.ConstantsManager; |
| 6 | +import org.jlab.detector.decode.CLASDecoder; |
| 7 | +import org.jlab.detector.helicity.HelicitySequence; |
| 8 | +import org.jlab.detector.helicity.HelicityState; |
| 9 | +import org.jlab.detector.scalers.DaqScalersSequence; |
| 10 | +import org.jlab.jnp.hipo4.data.Bank; |
| 11 | +import org.jlab.jnp.hipo4.data.Event; |
| 12 | +import org.jlab.jnp.hipo4.data.SchemaFactory; |
| 13 | +import org.jlab.jnp.hipo4.io.HipoWriterSorted; |
| 14 | + |
| 15 | +/** |
| 16 | + * |
| 17 | + * @author baltzell |
| 18 | + */ |
| 19 | +public class SerialHoncho { |
| 20 | + |
| 21 | + static final String[] TAG1BANKS = {"RUN::scaler","HEL::scaler","RAW::scaler","RAW::epics","HEL::flip","COAT::config"}; |
| 22 | + |
| 23 | + SchemaFactory schema; |
| 24 | + Bank[] tag1banks; |
| 25 | + Bank runConfig; |
| 26 | + Bank helicityAdc; |
| 27 | + ConstantsManager conman; |
| 28 | + TreeMap<Integer,Integer> eventUnix; |
| 29 | + TreeSet<HelicityState> helicities; |
| 30 | + DaqScalersSequence scalers; |
| 31 | + |
| 32 | + public SerialHoncho(SchemaFactory schema) { |
| 33 | + this.schema = schema; |
| 34 | + conman = new ConstantsManager(); |
| 35 | + conman.init("/runcontrol/hwp","/runcontrol/helicity"); |
| 36 | + runConfig = new Bank(schema.getSchema("RUN::config")); |
| 37 | + helicityAdc = new Bank(schema.getSchema("HEL::adc")); |
| 38 | + helicities = new TreeSet<>(); |
| 39 | + scalers = new DaqScalersSequence(schema); |
| 40 | + eventUnix = new TreeMap<>(); |
| 41 | + tag1banks = new Bank[TAG1BANKS.length]; |
| 42 | + for (int i=0; i<tag1banks.length; ++i) |
| 43 | + tag1banks[i] = new Bank(schema.getSchema(TAG1BANKS[i])); |
| 44 | + } |
| 45 | + |
| 46 | + public synchronized Event read(Event event) { |
| 47 | + scalers.add(event); |
| 48 | + event.read(runConfig); |
| 49 | + event.read(helicityAdc); |
| 50 | + if (runConfig.getRows() > 0) { |
| 51 | + int unix = runConfig.getInt("unixtime",0); |
| 52 | + int evno = runConfig.getInt("event",0); |
| 53 | + if (unix > 0 && evno > 0) eventUnix.put(evno, unix); |
| 54 | + } |
| 55 | + helicities.add(HelicityState.createFromFadcBank(helicityAdc, runConfig, conman)); |
| 56 | + return CLASDecoder.createTaggedEvent(event, runConfig, tag1banks); |
| 57 | + } |
| 58 | + |
| 59 | + public void finish(HipoWriterSorted writer) { |
| 60 | + writer.addEvent(getUnixEvent(runConfig),1); |
| 61 | + HelicitySequence.writeFlips(schema, writer, helicities); |
| 62 | + } |
| 63 | + |
| 64 | + public void clear() { |
| 65 | + while (helicities.size() > 100) helicities.pollFirst(); |
| 66 | + scalers.clear(100); |
| 67 | + } |
| 68 | + |
| 69 | + Event getUnixEvent(Bank config) { |
| 70 | + Bank unix = new Bank(schema.getSchema("RUN::unix")); |
| 71 | + unix.setRows(eventUnix.size()); |
| 72 | + int row = 0; |
| 73 | + for (int evno : eventUnix.keySet()) { |
| 74 | + unix.putInt("event", row, evno); |
| 75 | + unix.putInt("unixtime",row, eventUnix.get(evno)); |
| 76 | + row++; |
| 77 | + } |
| 78 | + Event e = new Event(); |
| 79 | + e.write(config); |
| 80 | + e.write(unix); |
| 81 | + return e; |
| 82 | + } |
| 83 | + |
| 84 | + public DaqScalersSequence getScalers() { |
| 85 | + return scalers; |
| 86 | + } |
| 87 | + |
| 88 | + public TreeSet<HelicityState> getHelicities() { |
| 89 | + return helicities; |
| 90 | + } |
| 91 | + |
| 92 | + public ConstantsManager getConstantsManager() { |
| 93 | + return conman; |
| 94 | + } |
| 95 | + |
| 96 | + public SchemaFactory getSchemaFactory() { |
| 97 | + return schema; |
| 98 | + } |
| 99 | +} |
0 commit comments