|
| 1 | +import org.jlab.detector.scalers.DaqScalers; |
| 2 | +import org.jlab.detector.scalers.DaqScalersSequence; |
| 3 | +import org.jlab.detector.calib.utils.ConstantsManager; |
| 4 | +import org.jlab.jnp.hipo4.io.HipoReader; |
| 5 | +import org.jlab.jnp.hipo4.data.Event; |
| 6 | +import org.jlab.jnp.hipo4.data.Bank; |
| 7 | +import org.jlab.jnp.hipo4.data.SchemaFactory; |
| 8 | +import java.util.List; |
| 9 | +import java.util.ArrayList; |
| 10 | + |
| 11 | +if(args.length<3) { |
| 12 | + System.err.println """ |
| 13 | + USAGE: groovy ${this.class.getSimpleName()}.groovy [HIPO file] [output directory] [suffix] |
| 14 | + """ |
| 15 | + System.exit(101) |
| 16 | +} |
| 17 | +def in_file = args[0] |
| 18 | +def out_dir = args[1] |
| 19 | +def suffix = args[2] |
| 20 | + |
| 21 | +List<String> filenames = new ArrayList<>(); |
| 22 | +filenames.add(in_file); |
| 23 | + |
| 24 | +ConstantsManager consts = new ConstantsManager(); |
| 25 | +consts.init("/runcontrol/fcup","/runcontrol/slm","/runcontrol/helicity","/daq/config/scalers/dsc1","/runcontrol/hwp"); |
| 26 | +DaqScalersSequence seq = DaqScalersSequence.rebuildSequence(1, consts, filenames); |
| 27 | + |
| 28 | +// seq.fixClockRollover(); |
| 29 | + |
| 30 | +def out_file_name = "${out_dir}/clock_${suffix}.dat"; |
| 31 | +def out_file = new File(out_file_name); |
| 32 | +def out_file_writer = out_file.newWriter(false); |
| 33 | + |
| 34 | +out_file_writer << [ "timestamp/L", "clock_gated/L", "clock_ungated/L" ].join(':') << '\n'; |
| 35 | + |
| 36 | +for(String filename : filenames) { |
| 37 | + HipoReader reader = new HipoReader(); |
| 38 | + reader.setTags(1); |
| 39 | + reader.open(filename); |
| 40 | + SchemaFactory schema = reader.getSchemaFactory(); |
| 41 | + |
| 42 | + while(reader.hasNext()) { |
| 43 | + Bank rcfgBank = new Bank(schema.getSchema("RUN::config")); |
| 44 | + Event event = new Event(); |
| 45 | + reader.nextEvent(event); |
| 46 | + event.read(rcfgBank); |
| 47 | + long timestamp = -1; |
| 48 | + if (rcfgBank.getRows()>0) |
| 49 | + timestamp = rcfgBank.getLong("timestamp",0); |
| 50 | + DaqScalers ds=seq.get(timestamp); |
| 51 | + if (ds!=null) { |
| 52 | + out_file_writer << [ds.getTimestamp(), ds.dsc2.gatedClock, ds.dsc2.clock].join(' ') << '\n'; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + reader.close(); |
| 57 | +} |
| 58 | + |
| 59 | +out_file_writer.flush(); |
| 60 | +out_file_writer.close(); |
| 61 | +System.out.println("WROTE $out_file_name"); |
0 commit comments