Commit in hps-java/src/main/java/org/lcsim/hps on MAIN | |||
users/meeg/EvioFileReader.java | -128 | 1.12 removed | |
evio/LCSimTestRunEventBuilder.java | -7 | 1.14 -> 1.15 | |
/ECalEvioReader.java | +194 | -215 | 1.6 -> 1.7 |
/TestRunEvioToLcio.java | +169 | -119 | 1.3 -> 1.4 |
+363 | -469 |
merge EvioFIleReader into TestRunEvioToLcio; clean up ECal mode handling
diff -N EvioFileReader.java --- EvioFileReader.java 29 Apr 2012 02:10:05 -0000 1.12 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,128 +0,0 @@
-package org.lcsim.hps.users.meeg; - -import java.io.FileInputStream; -import java.io.InputStream; - -import org.freehep.record.loop.event.RecordSuppliedEvent; -import org.jlab.coda.jevio.EvioEvent; -import org.jlab.coda.jevio.EvioReader; -import org.lcsim.event.EventHeader; -import org.lcsim.hps.evio.EventConstants; -import org.lcsim.hps.evio.LCSimTestRunEventBuilder; -import org.lcsim.job.JobControlManager; -import org.lcsim.util.DriverAdapter; - -// This is copied and modified from Carl Timmer's EvioProducer class in et 12 org.jlab.coda.et.apps package. -// TODO Add option to set number of events in put array. -// TODO Add option for multiple EVIO input files. -public class EvioFileReader { - - EvioReader reader; - String evioFileName; - private static final String defaultDetectorName = "HPS-Test-JLAB-v4pt0"; - private static final String defaultSteeringFile = "/org/lcsim/hps/steering/print_ids.lcsim"; - String steeringFile = defaultSteeringFile; - String detectorName = defaultDetectorName; - InputStream is = null; - private JobControlManager jobMgr; - boolean debug = false; - int ecalMode = EventConstants.ECAL_PULSE_INTEGRAL_MODE; - int delay = 0; - - EvioFileReader() { - } - - private static void usage() { - System.out.println("\nUsage: java Producer -e <evio file> [-s <steering file>] [-d <detector>]\n\n" - + " -s steering file\n" - + " -m ECal mode\n" - + " -d detector name\n"); - System.exit(1); - } - - public static void main(String[] args) { - (new EvioFileReader()).doMain(args); // call wrapper method - } - - public void doMain(String[] args) { - try { - for (int i = 0; i < args.length; i++) { - if (args[i].equalsIgnoreCase("-e")) { - evioFileName = new String(args[++i]); - } else if (args[i].equalsIgnoreCase("-v")) { - debug = true; - } else if (args[i].equalsIgnoreCase("-s")) { - is = new FileInputStream(args[++i]); - } else if (args[i].equalsIgnoreCase("-r")) { - steeringFile = new String(args[++i]); - } else if (args[i].equalsIgnoreCase("-d")) { - detectorName = new String(args[++i]); - } else if (args[i].equalsIgnoreCase("-m")) { - ecalMode = Integer.parseInt(args[++i]); - } else if (args[i].equalsIgnoreCase("-w")) { - delay = Integer.parseInt(args[++i]); - } else { - usage(); - return; - } - } - - if (evioFileName == null) { - usage(); - return; - } - - // Job manager to run LCSim. - jobMgr = new JobControlManager(); - //jobMgr.checkInputFiles(false); - jobMgr.setPerformDryRun(true); - if (is == null) { - is = this.getClass().getResourceAsStream(steeringFile); - } - jobMgr.setup(is); - - // Make a DriverAdapter for wrapping event loop. - DriverAdapter driverAdapter = jobMgr.getDriverAdapter(); - - // Call wrapper to startOfData() on DriverAdapter. - driverAdapter.configure(null); - - // Setup the event builder. - LCSimTestRunEventBuilder eventBuilder = new LCSimTestRunEventBuilder(); - eventBuilder.setDetectorName(detectorName); - eventBuilder.setDebug(debug); - eventBuilder.setEcalMode(ecalMode); - - // Open EVIO reader. - reader = new EvioReader(evioFileName); - -// // Print number of events. -// System.out.println("EVIO file opened with " + reader.getEventCount() + " events"); - - // Loop until event source is exhausted. - //int eventCount = 0; - do { - EvioEvent evioEvent = null; - do { - try { - evioEvent = reader.parseNextEvent(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - } while (evioEvent == null || !eventBuilder.isPhysicsEvent(evioEvent)); - - // Create LCSim event from EVIO data. - EventHeader lcsimEvent = eventBuilder.makeLCSimEvent(evioEvent); - - // Supply record to Driver Adapter. - driverAdapter.recordSupplied(new RecordSuppliedEvent(new Object(), lcsimEvent)); - Thread.sleep(delay); - } while (reader.getNumEventsRemaining() != 0); - // Cleanup. - driverAdapter.finish(null); - reader.close(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } -}
diff -u -r1.14 -r1.15 --- LCSimTestRunEventBuilder.java 27 Apr 2012 22:13:52 -0000 1.14 +++ LCSimTestRunEventBuilder.java 29 Apr 2012 23:05:26 -0000 1.15 @@ -37,13 +37,6 @@
svtReader = new SVTEvioReader(); }
- public void setEcalMode(int ecalMode) { - if (ecalMode != EventConstants.ECAL_WINDOW_MODE && ecalMode != EventConstants.ECAL_PULSE_MODE && ecalMode != EventConstants.ECAL_PULSE_INTEGRAL_MODE) { - throw new IllegalArgumentException("invalid mode " + ecalMode); - } - ecalReader.setMode(ecalMode); - } -
public void setDetectorName(String detectorName) { // Make a dummy event to setup the conditions system. EventHeader dummyEvent = new BaseLCSimEvent(0, 0, detectorName);
diff -u -r1.6 -r1.7 --- ECalEvioReader.java 27 Apr 2012 22:13:52 -0000 1.6 +++ ECalEvioReader.java 29 Apr 2012 23:05:26 -0000 1.7 @@ -17,228 +17,207 @@
/** * * @author Sho Uemura <[log in to unmask]>
- * @version $Id: ECalEvioReader.java,v 1.6 2012/04/27 22:13:52 meeg Exp $
+ * @version $Id: ECalEvioReader.java,v 1.7 2012/04/29 23:05:26 meeg Exp $
*/ public class ECalEvioReader extends EvioReader {
- // Names of subdetectors.
+ // Names of subdetectors.
- private String ecalName = "Ecal"; - private HPSEcalDaqIDConverter ecalIDConverter = null; - private int mode = EventConstants.ECAL_PULSE_INTEGRAL_MODE; - private int bankTag = EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG; - private Class hitClass = RawCalorimeterHit.class; - - public ECalEvioReader() { - hitCollectionName = "EcalReadoutHits"; - } - - public void setEcalName(String ecalName) { - this.ecalName = ecalName; - ecalIDConverter = null; - } - - public void setMode(int mode) { - this.mode = mode; - if (mode != EventConstants.ECAL_WINDOW_MODE && mode != EventConstants.ECAL_PULSE_MODE && mode != EventConstants.ECAL_PULSE_INTEGRAL_MODE) { - throw new IllegalArgumentException("invalid mode " + mode); - } - switch (mode) { - case EventConstants.ECAL_WINDOW_MODE: - bankTag = EventConstants.ECAL_WINDOW_BANK_TAG; - hitClass = RawTrackerHit.class; - break; - case EventConstants.ECAL_PULSE_MODE: - bankTag = EventConstants.ECAL_PULSE_BANK_TAG; - hitClass = RawTrackerHit.class; - break; - case EventConstants.ECAL_PULSE_INTEGRAL_MODE: - bankTag = EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG; - hitClass = RawCalorimeterHit.class; - break; - } - } - - @Override - public boolean makeHits(EvioEvent event, EventHeader lcsimEvent) { - boolean foundHits = false; - if (ecalIDConverter == null) { - ecalIDConverter = new HPSEcalDaqIDConverter(); - ecalIDConverter.fillDaqCellMap(lcsimEvent.getDetector().getSubdetector(ecalName)); - } - List<Object> hits = new ArrayList<Object>(); - hitClass = Object.class; - for (BaseStructure bank : event.getChildren()) { - BaseStructureHeader header = bank.getHeader(); - int crateBankTag = header.getTag(); - if (crateBankTag == EventConstants.ECAL_TOP_BANK_TAG || crateBankTag == EventConstants.ECAL_BOTTOM_BANK_TAG) { - foundHits = true; - if (bank.getChildCount() > 0) { - if (debug) { - System.out.println("ECal bank tag: " + header.getTag() + "; childCount: " + bank.getChildCount()); - } - for (BaseStructure slotBank : bank.getChildren()) { - CompositeData cdata = null; - try { - cdata = slotBank.getCompositeData(); - } catch (EvioException e) { - throw new RuntimeException(e); - } - if (slotBank.getHeader().getTag() != bankTag) { - System.out.println("Unexpected ECal format - bank tag " + slotBank.getHeader().getTag()); - } - switch (slotBank.getHeader().getTag()) { - case EventConstants.ECAL_WINDOW_BANK_TAG: - hits.addAll(makeWindowHits(cdata, crateBankTag)); - hitClass = RawTrackerHit.class; - break; - case EventConstants.ECAL_PULSE_BANK_TAG: - hits.addAll(makePulseHits(cdata, crateBankTag)); - hitClass = RawTrackerHit.class; - break; - case EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG: - hits.addAll(makeIntegralHits(cdata, crateBankTag)); - hitClass = RawCalorimeterHit.class; - break; - default: - throw new RuntimeException("Unsupported ECal format - bank tag " + slotBank.getHeader().getTag()); - - } - } - } - } - } - String readoutName = lcsimEvent.getDetector().getSubdetector(ecalName).getReadout().getName(); - lcsimEvent.put(hitCollectionName, hits, hitClass, 0, readoutName); - return foundHits; - } - - private List<BaseRawTrackerHit> makeWindowHits(CompositeData cdata, int bankTag) { - List<BaseRawTrackerHit> hits = new ArrayList<BaseRawTrackerHit>(); - if (debug) { - int n = cdata.getNValues().size(); - for (int i = 0; i < n; i++) { - System.out.println("cdata.N[" + i + "]=" + cdata.getNValues().get(i)); - } - int ni = cdata.getItems().size(); - for (int i = 0; i < ni; i++) { - System.out.println("cdata.type[" + i + "]=" + cdata.getTypes().get(i)); - } - } - - int crate = bankTag; - short slot = cdata.getByte(); - int trigger = cdata.getInt(); - long timestamp = cdata.getLong(); - int nchannels = cdata.getNValue(); - if (debug) { - System.out.println("slot#=" + slot + "; trigger=" + trigger + "; timestamp=" + timestamp + "; nchannels=" + nchannels); - } - for (int j = 0; j < nchannels; j++) { - short channel = cdata.getByte(); - int nSamples = cdata.getNValue(); - if (debug) { - System.out.println(" channel=" + channel + "; nSamples=" + nSamples); - } - long daqID = HPSEcalDaqIDConverter.getDaqID(crate, slot, channel); - Long id = ecalIDConverter.daqToPhysicalID(daqID); - - short[] adcValues = new short[nSamples]; - for (int i = 0; i < nSamples; i++) { - adcValues[i] = cdata.getShort(); - }
+ private String ecalName = "Ecal"; + private HPSEcalDaqIDConverter ecalIDConverter = null; + private int bankTag = EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG; + private Class hitClass = RawCalorimeterHit.class; + + public ECalEvioReader() { + hitCollectionName = "EcalReadoutHits"; + } + + public void setEcalName(String ecalName) { + this.ecalName = ecalName; + ecalIDConverter = null; + } + + @Override + public boolean makeHits(EvioEvent event, EventHeader lcsimEvent) { + boolean foundHits = false; + if (ecalIDConverter == null) { + ecalIDConverter = new HPSEcalDaqIDConverter(); + ecalIDConverter.fillDaqCellMap(lcsimEvent.getDetector().getSubdetector(ecalName)); + } + List<Object> hits = new ArrayList<Object>(); + hitClass = Object.class; + for (BaseStructure bank : event.getChildren()) { + BaseStructureHeader header = bank.getHeader(); + int crateBankTag = header.getTag(); + if (crateBankTag == EventConstants.ECAL_TOP_BANK_TAG || crateBankTag == EventConstants.ECAL_BOTTOM_BANK_TAG) { + foundHits = true; + if (bank.getChildCount() > 0) { + if (debug) { + System.out.println("ECal bank tag: " + header.getTag() + "; childCount: " + bank.getChildCount()); + } + for (BaseStructure slotBank : bank.getChildren()) { + CompositeData cdata = null; + try { + cdata = slotBank.getCompositeData(); + } catch (EvioException e) { + throw new RuntimeException(e); + } + if (slotBank.getHeader().getTag() != bankTag) { + bankTag = slotBank.getHeader().getTag(); + System.out.printf("ECal format tag: 0x%x\n", bankTag); + } + switch (slotBank.getHeader().getTag()) { + case EventConstants.ECAL_WINDOW_BANK_TAG: + hits.addAll(makeWindowHits(cdata, crateBankTag)); + hitClass = RawTrackerHit.class; + break; + case EventConstants.ECAL_PULSE_BANK_TAG: + hits.addAll(makePulseHits(cdata, crateBankTag)); + hitClass = RawTrackerHit.class; + break; + case EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG: + hits.addAll(makeIntegralHits(cdata, crateBankTag)); + hitClass = RawCalorimeterHit.class; + break; + default: + throw new RuntimeException("Unsupported ECal format - bank tag " + slotBank.getHeader().getTag()); + + } + } + } + } + } + String readoutName = lcsimEvent.getDetector().getSubdetector(ecalName).getReadout().getName(); + lcsimEvent.put(hitCollectionName, hits, hitClass, 0, readoutName); + return foundHits; + } + + private List<BaseRawTrackerHit> makeWindowHits(CompositeData cdata, int bankTag) { + List<BaseRawTrackerHit> hits = new ArrayList<BaseRawTrackerHit>(); + if (debug) { + int n = cdata.getNValues().size(); + for (int i = 0; i < n; i++) { + System.out.println("cdata.N[" + i + "]=" + cdata.getNValues().get(i)); + } + int ni = cdata.getItems().size(); + for (int i = 0; i < ni; i++) { + System.out.println("cdata.type[" + i + "]=" + cdata.getTypes().get(i)); + } + } + + int crate = bankTag; + short slot = cdata.getByte(); + int trigger = cdata.getInt(); + long timestamp = cdata.getLong(); + int nchannels = cdata.getNValue(); + if (debug) { + System.out.println("slot#=" + slot + "; trigger=" + trigger + "; timestamp=" + timestamp + "; nchannels=" + nchannels); + } + for (int j = 0; j < nchannels; j++) { + short channel = cdata.getByte(); + int nSamples = cdata.getNValue(); + if (debug) { + System.out.println(" channel=" + channel + "; nSamples=" + nSamples); + } + long daqID = HPSEcalDaqIDConverter.getDaqID(crate, slot, channel); + Long id = ecalIDConverter.daqToPhysicalID(daqID); + + short[] adcValues = new short[nSamples]; + for (int i = 0; i < nSamples; i++) { + adcValues[i] = cdata.getShort(); + }
// if (debug) { // System.out.println(" pulseTime=" + pulseTime + "; pulseIntegral=" + pulseIntegral); // }
- hits.add(new BaseRawTrackerHit(id, 0, adcValues)); - } - return hits; - } - - private List<BaseRawTrackerHit> makePulseHits(CompositeData cdata, int bankTag) { - List<BaseRawTrackerHit> hits = new ArrayList<BaseRawTrackerHit>(); - if (debug) { - int n = cdata.getNValues().size(); - for (int i = 0; i < n; i++) { - System.out.println("cdata.N[" + i + "]=" + cdata.getNValues().get(i)); - } - int ni = cdata.getItems().size(); - for (int i = 0; i < ni; i++) { - System.out.println("cdata.type[" + i + "]=" + cdata.getTypes().get(i)); - } - } - - int crate = bankTag; - short slot = cdata.getByte(); - int trigger = cdata.getInt(); - long timestamp = cdata.getLong(); - int nchannels = cdata.getNValue(); - if (debug) { - System.out.println("slot#=" + slot + "; trigger=" + trigger + "; timestamp=" + timestamp + "; nchannels=" + nchannels); - } - for (int j = 0; j < nchannels; j++) { - short channel = cdata.getByte(); - int npulses = cdata.getNValue(); - if (debug) { - System.out.println(" channel=" + channel + "; npulses=" + npulses); - } - long daqID = HPSEcalDaqIDConverter.getDaqID(crate, slot, channel); - Long id = ecalIDConverter.daqToPhysicalID(daqID); - - for (int k = 0; k < npulses; k++) { - short pulseNum = cdata.getByte(); - int sampleCount = cdata.getNValue(); - short[] adcValues = new short[sampleCount]; - for (int i = 0; i < sampleCount; i++) { - adcValues[i] = cdata.getShort(); - }
+ hits.add(new BaseRawTrackerHit(id, 0, adcValues)); + } + return hits; + } + + private List<BaseRawTrackerHit> makePulseHits(CompositeData cdata, int bankTag) { + List<BaseRawTrackerHit> hits = new ArrayList<BaseRawTrackerHit>(); + if (debug) { + int n = cdata.getNValues().size(); + for (int i = 0; i < n; i++) { + System.out.println("cdata.N[" + i + "]=" + cdata.getNValues().get(i)); + } + int ni = cdata.getItems().size(); + for (int i = 0; i < ni; i++) { + System.out.println("cdata.type[" + i + "]=" + cdata.getTypes().get(i)); + } + } + + int crate = bankTag; + short slot = cdata.getByte(); + int trigger = cdata.getInt(); + long timestamp = cdata.getLong(); + int nchannels = cdata.getNValue(); + if (debug) { + System.out.println("slot#=" + slot + "; trigger=" + trigger + "; timestamp=" + timestamp + "; nchannels=" + nchannels); + } + for (int j = 0; j < nchannels; j++) { + short channel = cdata.getByte(); + int npulses = cdata.getNValue(); + if (debug) { + System.out.println(" channel=" + channel + "; npulses=" + npulses); + } + long daqID = HPSEcalDaqIDConverter.getDaqID(crate, slot, channel); + Long id = ecalIDConverter.daqToPhysicalID(daqID); + + for (int k = 0; k < npulses; k++) { + short pulseNum = cdata.getByte(); + int sampleCount = cdata.getNValue(); + short[] adcValues = new short[sampleCount]; + for (int i = 0; i < sampleCount; i++) { + adcValues[i] = cdata.getShort(); + }
// if (debug) { // System.out.println(" pulseTime=" + pulseTime + "; pulseIntegral=" + pulseIntegral); // }
- hits.add(new BaseRawTrackerHit(id, pulseNum, adcValues)); - } - } - return hits; - } - - private List<RawCalorimeterHit> makeIntegralHits(CompositeData cdata, int bankTag) { - List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>(); - if (debug) { - int n = cdata.getNValues().size(); - for (int i = 0; i < n; i++) { - System.out.println("cdata.N[" + i + "]=" + cdata.getNValues().get(i)); - } - int ni = cdata.getItems().size(); - for (int i = 0; i < ni; i++) { - System.out.println("cdata.type[" + i + "]=" + cdata.getTypes().get(i)); - } - } - - int crate = bankTag; - short slot = cdata.getByte(); - int trigger = cdata.getInt(); - long timestamp = cdata.getLong(); - int nchannels = cdata.getNValue(); - if (debug) { - System.out.println("slot#=" + slot + "; trigger=" + trigger + "; timestamp=" + timestamp + "; nchannels=" + nchannels); - } - for (int j = 0; j < nchannels; j++) { - short channel = cdata.getByte(); - int npulses = cdata.getNValue(); - if (debug) { - System.out.println(" channel=" + channel + "; npulses=" + npulses); - } - long daqID = HPSEcalDaqIDConverter.getDaqID(crate, slot, channel); - Long id = ecalIDConverter.daqToPhysicalID(daqID); - - for (int k = 0; k < npulses; k++) { - short pulseTime = cdata.getShort(); - int pulseIntegral = cdata.getInt(); - if (debug) { - System.out.println(" pulseTime=" + pulseTime + "; pulseIntegral=" + pulseIntegral); - } - hits.add(new BaseRawCalorimeterHit(id, pulseIntegral, pulseTime)); - } - } - return hits; - }
+ hits.add(new BaseRawTrackerHit(id, pulseNum, adcValues)); + } + } + return hits; + } + + private List<RawCalorimeterHit> makeIntegralHits(CompositeData cdata, int bankTag) { + List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>(); + if (debug) { + int n = cdata.getNValues().size(); + for (int i = 0; i < n; i++) { + System.out.println("cdata.N[" + i + "]=" + cdata.getNValues().get(i)); + } + int ni = cdata.getItems().size(); + for (int i = 0; i < ni; i++) { + System.out.println("cdata.type[" + i + "]=" + cdata.getTypes().get(i)); + } + } + + int crate = bankTag; + short slot = cdata.getByte(); + int trigger = cdata.getInt(); + long timestamp = cdata.getLong(); + int nchannels = cdata.getNValue(); + if (debug) { + System.out.println("slot#=" + slot + "; trigger=" + trigger + "; timestamp=" + timestamp + "; nchannels=" + nchannels); + } + for (int j = 0; j < nchannels; j++) { + short channel = cdata.getByte(); + int npulses = cdata.getNValue(); + if (debug) { + System.out.println(" channel=" + channel + "; npulses=" + npulses); + } + long daqID = HPSEcalDaqIDConverter.getDaqID(crate, slot, channel); + Long id = ecalIDConverter.daqToPhysicalID(daqID); + + for (int k = 0; k < npulses; k++) { + short pulseTime = cdata.getShort(); + int pulseIntegral = cdata.getInt(); + if (debug) { + System.out.println(" pulseTime=" + pulseTime + "; pulseIntegral=" + pulseIntegral); + } + hits.add(new BaseRawCalorimeterHit(id, pulseIntegral, pulseTime)); + } + } + return hits; + }
}
diff -u -r1.3 -r1.4 --- TestRunEvioToLcio.java 26 Apr 2012 21:16:50 -0000 1.3 +++ TestRunEvioToLcio.java 29 Apr 2012 23:05:26 -0000 1.4 @@ -1,7 +1,6 @@
package org.lcsim.hps.evio;
-import java.io.File; -import java.io.IOException;
+import java.io.*;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser;
@@ -31,121 +30,172 @@
*/ public class TestRunEvioToLcio {
- /** - * Defines command line options for this program. - * - * @return The command line options. - */ - private static Options createCommandLineOptions() { - Options options = new Options(); - - Option evioFileOpt = new Option("e", true, "The input EVIO file containing Test Run data."); - Option lcioFileOpt = new Option("l", true, "The name of the output LCIO file."); - Option detectorNameOpt = new Option("d", true, "The name of the detector to use for LCSim conditions."); - Option lcsimXmlOpt = new Option("x", true, "The LCSim XML file to process the LCIO events."); - - options.addOption(evioFileOpt); - options.addOption(lcioFileOpt); - options.addOption(detectorNameOpt); - options.addOption(lcsimXmlOpt); - - return options; - } - - /** - * This method will execute the EVIO to LCIO conversion and perform an - * intermediate LCSim job. Then the resultant LCIO events will be - * written to disk. - * - * @param args The command line arguments. - */ - public static void main(String[] args) { - - // Set up command line parsing. - Options options = createCommandLineOptions(); - if (args.length == 0) { - System.out.println("TestRunEvioToLcio [options]"); - HelpFormatter help = new HelpFormatter(); - help.printHelp(" ", options); - System.exit(1); - } - CommandLineParser parser = new PosixParser(); - - // Parse command line arguments. - CommandLine cl = null; - try { - cl = parser.parse(options, args); - } catch (ParseException e) { - throw new RuntimeException("Problem parsing command line options.", e); - } - - // EVIO input file. - String evioFileName = cl.getOptionValue("e"); - File evioFile = new File(evioFileName); - - // LCIO output file. - String lcioFileName = cl.getOptionValue("l"); - File lcioFile = new File(lcioFileName); - - // Name of detector. - String detectorName = cl.getOptionValue("d"); - - // LCSim XML file to execute inline. - String lcsimXmlName = cl.getOptionValue("x"); - File lcsimXmlFile = new File(lcsimXmlName); - - // EVIO reader. - EvioReader reader = null; - try { - reader = new EvioReader(evioFile); - } catch (IOException e) { - throw new RuntimeException(e); - } - - // LCIO writer. - LCIOWriter writer = null; - try { - writer = new LCIOWriter(lcioFile); - } catch (IOException e) { - throw new RuntimeException(e); - } - - // LCSim job manager. - JobControlManager jobManager = new JobControlManager(); - jobManager.setup(lcsimXmlFile); - jobManager.configure(); - - // LCSim event builder. - LCSimEventBuilder eventBuilder = new LCSimTestRunEventBuilder(); - eventBuilder.setDetectorName(detectorName); - - // Loop over EVIO events, build LCSim events, process them, and then - // write events to disk. - while (true) { - EvioEvent evioEvent = null; - EventHeader lcioEvent = null; - try { - do { - evioEvent = reader.parseNextEvent(); - } while (!eventBuilder.isPhysicsEvent(evioEvent)); - - lcioEvent = eventBuilder.makeLCSimEvent(evioEvent); - jobManager.processEvent(lcioEvent); - writer.write(lcioEvent); - if (reader.getNumEventsRemaining() == 0) { - break; - } - } catch (EvioException e) { - throw new RuntimeException(e); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - jobManager.finish(); - try { - writer.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - }
+ private static final String defaultDetectorName = "HPS-Test-JLAB-v4pt0"; + private static final String defaultSteeringFile = "/org/lcsim/hps/steering/DummyMonitoring.lcsim"; + + /** + * Defines command line options for this program. + * + * @return The command line options. + */ + private static Options createCommandLineOptions() { + Options options = new Options(); + + Option evioFileOpt = new Option("e", false, "Deprecated: The input EVIO file containing Test Run data."); + Option lcioFileOpt = new Option("l", true, "The name of the output LCIO file."); + Option detectorNameOpt = new Option("d", true, "The name of the detector to use for LCSim conditions."); + Option lcsimXmlOpt = new Option("x", true, "The LCSim XML file to process the LCIO events."); + Option sleepOpt = new Option("s", true, "Sleep duration between events (in ms)"); + + options.addOption(evioFileOpt); + options.addOption(lcioFileOpt); + options.addOption(detectorNameOpt); + options.addOption(lcsimXmlOpt); + options.addOption(sleepOpt); + + return options; + } + + /** + * This method will execute the EVIO to LCIO conversion and perform an + * intermediate LCSim job. Then the resultant LCIO events will be written to + * disk. + * + * @param args The command line arguments. + */ + public static void main(String[] args) { + + // Set up command line parsing. + Options options = createCommandLineOptions(); + if (args.length == 0) { + System.out.println("TestRunEvioToLcio [options]"); + HelpFormatter help = new HelpFormatter(); + help.printHelp(" ", options); + System.exit(1); + } + CommandLineParser parser = new PosixParser(); + + // Parse command line arguments. + CommandLine cl = null; + try { + cl = parser.parse(options, args); + } catch (ParseException e) { + throw new RuntimeException("Problem parsing command line options.", e); + } + + String lcioFileName = null; + String detectorName = defaultDetectorName; + InputStream steeringStream = null; + int sleepTime = -1; + + // Remind people not to use -e any more + if (cl.hasOption("e")) { + System.out.println("Option -e is deprecated; EVIO file name is now a non-option argument"); + } + + // LCIO output file. + if (cl.hasOption("l")) { + lcioFileName = cl.getOptionValue("l"); + } + + // Name of detector. + if (cl.hasOption("d")) { + detectorName = cl.getOptionValue("d"); + } + + // LCSim XML file to execute inline. + if (cl.hasOption("x")) { + String lcsimXmlName = cl.getOptionValue("x"); + try { + steeringStream = new FileInputStream(lcsimXmlName); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } + + if (steeringStream == null) { + steeringStream = TestRunEvioToLcio.class.getResourceAsStream(defaultSteeringFile); + } + + // Sleep time. + if (cl.hasOption("s")) { + sleepTime = Integer.getInteger(cl.getOptionValue("s")); + } + + // LCIO writer. + LCIOWriter writer = null; + if (lcioFileName != null) { + try { + writer = new LCIOWriter(new File(lcioFileName)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + // LCSim job manager. + JobControlManager jobManager = new JobControlManager(); + jobManager.setup(steeringStream); + jobManager.configure(); + + // LCSim event builder. + LCSimEventBuilder eventBuilder = new LCSimTestRunEventBuilder(); + eventBuilder.setDetectorName(detectorName); + + // EVIO input file. + File evioFile = new File(cl.getArgs()[0]); + + // EVIO reader. + EvioReader reader = null; + try { + reader = new EvioReader(evioFile); + } catch (IOException e) { + throw new RuntimeException(e); + } + + // Loop over EVIO events, build LCSim events, process them, and then + // write events to disk. + while (true) { + EvioEvent evioEvent = null; + try { + do { + try { + evioEvent = reader.parseNextEvent(); + } catch (NullPointerException e) { + evioEvent = null; + e.printStackTrace(); + } + } while (evioEvent == null || !eventBuilder.isPhysicsEvent(evioEvent)); + + EventHeader lcioEvent = eventBuilder.makeLCSimEvent(evioEvent); + jobManager.processEvent(lcioEvent); + if (writer != null) { + writer.write(lcioEvent); + writer.flush(); + } + if (reader.getNumEventsRemaining() == 0) { + break; + } + } catch (EvioException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + if (sleepTime > 0) { + try { + Thread.sleep(sleepTime); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + + jobManager.finish(); + if (writer != null) { + try { + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }
}
\ No newline at end of file
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1