LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  October 2015

HPS-SVN October 2015

Subject:

r3771 - /java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Tue, 6 Oct 2015 18:39:49 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (384 lines)

Author: [log in to unmask]
Date: Tue Oct  6 11:39:47 2015
New Revision: 3771

Log:
Reorganize so that parsing options and running the job are separate methods.

Modified:
    java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java

Modified: java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java
 =============================================================================
--- java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java	(original)
+++ java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java	Tue Oct  6 11:39:47 2015
@@ -24,6 +24,7 @@
 import org.apache.commons.cli.PosixParser;
 import org.freehep.record.source.NoSuchRecordException;
 import org.hps.conditions.database.DatabaseConditionsManager;
+import org.hps.detector.svt.SvtDetectorSetup;
 import org.hps.job.JobManager;
 import org.hps.record.LCSimEventBuilder;
 import org.hps.record.evio.EvioEventQueue;
@@ -42,9 +43,8 @@
 
 /**
  * <p>
- * This class converts EVIO to LCIO, performing an LCSim job in the same
- * session. The processed events are then (optionally) written to disk using an
- * LCIOWriter.
+ * This class converts EVIO to LCIO, performing an LCSim job in the same session. The processed events are then
+ * (optionally) written to disk using an LCIOWriter.
  * <p>
  * To run this class from the command line:<br>
  * java -cp hps-distribution-bin.jar EvioToLcio [options] [evioFiles]
@@ -54,23 +54,20 @@
  * <p>
  * Extra arguments are treated as paths to EVIO files.
  * <p>
- * This class attempts to automatically configure itself for Test Run or
- * Engineering Run based on the run numbers in the EVIO file. It will use an
- * appropriate default detector unless one is given on the command line, and it
- * will also use the correct event builder. It will not handle jobs correctly
- * with files from both the Test and Engineering Run, so don't do this!
+ * This class attempts to automatically configure itself for Test Run or Engineering Run based on the run numbers in the
+ * EVIO file. It will use an appropriate default detector unless one is given on the command line, and it will also use
+ * the correct event builder. It will not handle jobs correctly with files from both the Test and Engineering Run, so
+ * don't do this!
  * <p>
  * The conditions system can be initialized in one of three ways.<br/>
  * <ol>
- * <li>user specified run number in which case the conditions system is frozen
- * for the rest of the job</li>
+ * <li>user specified run number in which case the conditions system is frozen for the rest of the job</li>
  * <li>run number from an EVIO pre start event</li>
  * <li>run number from a header bank in an event</li>
  * </ol>
  * <p>
- * In the case where a file has no pre start event and there are header banks
- * present, the "-m" command line option can be used to buffer a number of EVIO
- * events. If there is a head bank found while adding these events to queue, the
+ * In the case where a file has no pre start event and there are header banks present, the "-m" command line option can
+ * be used to buffer a number of EVIO events. If there is a head bank found while adding these events to queue, the
  * conditions system will be initialized from it.
  *
  * @author Jeremy McCormick <[log in to unmask]>
@@ -79,8 +76,7 @@
 public class EvioToLcio {
 
     /**
-     * The default steering resource, which basically does nothing except print
-     * event numbers.
+     * The default steering resource, which basically does nothing except print event numbers.
      */
     private static final String DEFAULT_STEERING_RESOURCE = "/org/hps/steering/EventMarker.lcsim";
 
@@ -96,7 +92,8 @@
      */
     public static void main(final String[] args) {
         final EvioToLcio evioToLcio = new EvioToLcio();
-        evioToLcio.run(args);
+        evioToLcio.parse(args);
+        evioToLcio.run();
     }
 
     /**
@@ -112,41 +109,50 @@
     /**
      * The command line options which will be defined in the constructor.
      */
-    private Options options = null;
+    private static Options OPTIONS = new Options();
+    static {
+        OPTIONS.addOption(new Option("d", true, "detector name (required)"));
+        OPTIONS.getOption("d").setRequired(true);
+        OPTIONS.addOption(new Option("f", true, "text file containing a list of EVIO files"));
+        OPTIONS.addOption(new Option("L", true, "log level (INFO, FINE, etc.)"));
+        OPTIONS.addOption(new Option("x", true, "LCSim steeering file for processing the LCIO events"));
+        OPTIONS.addOption(new Option("r", false, "interpret steering from -x argument as a resource instead of a file"));
+        OPTIONS.addOption(new Option("D", true, "define a steering file variable with format -Dname=value"));
+        OPTIONS.addOption(new Option("l", true, "path of output LCIO file"));
+        OPTIONS.addOption(new Option("R", true, "fixed run number which will override run numbers of input files"));
+        OPTIONS.addOption(new Option("n", true, "maximum number of events to process in the job"));
+        OPTIONS.addOption(new Option("b", false, "enable headless mode in which plots will not show"));
+        OPTIONS.addOption(new Option("v", false, "print EVIO XML for each event"));
+        OPTIONS.addOption(new Option("m", true, "set the max event buffer size"));
+        OPTIONS.addOption(new Option("t", true, "specify a conditions tag to use"));
+        OPTIONS.addOption(new Option("M", false, "use memory mapping instead of sequential reading"));
+    }
 
     /**
      * The run number for conditions.
      */
     private Integer runNumber = null;
 
-    /**
-     * The default constructor, which defines command line arguments and sets
-     * the default log level.
-     */
-    protected EvioToLcio() {
-        LOGGER.config("initializing EVIO to LCIO converter ...");
-        options = new Options();
-        options.addOption(new Option("d", true, "detector name (required)"));
-        options.getOption("d").setRequired(true);
-        options.addOption(new Option("f", true, "text file containing a list of EVIO files"));
-        options.addOption(new Option("L", true, "log level (INFO, FINE, etc.)"));
-        options.addOption(new Option("x", true, "LCSim steeering file for processing the LCIO events"));
-        options.addOption(new Option("r", false, "interpret steering from -x argument as a resource instead of a file"));
-        options.addOption(new Option("D", true, "define a steering file variable with format -Dname=value"));
-        options.addOption(new Option("l", true, "path of output LCIO file"));
-        options.addOption(new Option("R", true, "fixed run number which will override run numbers of input files"));
-        options.addOption(new Option("n", true, "maximum number of events to process in the job"));
-        options.addOption(new Option("b", false, "enable headless mode in which plots will not show"));
-        options.addOption(new Option("v", false, "print EVIO XML for each event"));
-        options.addOption(new Option("m", true, "set the max event buffer size"));
-        options.addOption(new Option("t", true, "specify a conditions tag to use"));
-        options.addOption(new Option("M", false, "use memory mapping instead of sequential reading"));
-    }
-
-    /**
-     * Buffer up to <code>maxBufferSize</code> events in the
-     * <code>eventQueue</code>. This method will also initialize the conditions
-     * system using a run number if a header bank is found.
+    private int maxEvents = -1;
+    private int nEvents = 0;
+    private int maxBufferSize = 40;
+    private List<String> evioFileList = null;
+    private boolean printXml = false;
+    private boolean useMemoryMapping = false;
+    private JobManager jobManager = null;
+    private String lcioFileName = null;
+    private LCIOWriter writer = null;
+    private InputStream steeringStream = null;
+
+    /**
+     * The default constructor, which defines command line arguments and sets the default log level.
+     */
+    public EvioToLcio() {
+    }
+
+    /**
+     * Buffer up to <code>maxBufferSize</code> events in the <code>eventQueue</code>. This method will also initialize
+     * the conditions system using a run number if a header bank is found.
      *
      * @param reader the EVIO reader
      * @param eventQueue the event queue
@@ -205,8 +211,7 @@
     }
 
     /**
-     * Check if the conditions system and event builder need to be initialized
-     * or updated given a run number.
+     * Check if the conditions system and event builder need to be initialized or updated given a run number.
      *
      * @param runNumber The run number.
      * @param freeze True to freeze conditions system after it is setup.
@@ -239,24 +244,11 @@
     private void printUsage() {
         System.out.println("EvioToLcio [options] [evioFiles]");
         final HelpFormatter help = new HelpFormatter();
-        help.printHelp(" ", options);
+        help.printHelp(" ", OPTIONS);
         System.exit(1);
     }
 
-    /**
-     * This method will execute the EVIO to LCIO conversion and optionally
-     * process the events with LCSim Drivers from a steering file. Then the
-     * resultant LCIO events will be written to disk if this option is enabled
-     * in the command line arguments.
-     *
-     * @param args The command line arguments.
-     */
-    public void run(final String[] args) {
-
-        int maxEvents = -1;
-        int nEvents = 0;
-        int maxBufferSize = 40;
-
+    public void parse(String[] args) {
         // Parse the command line options.
         if (args.length == 0) {
             this.printUsage();
@@ -264,7 +256,7 @@
         final CommandLineParser parser = new PosixParser();
         CommandLine cl = null;
         try {
-            cl = parser.parse(options, args);
+            cl = parser.parse(OPTIONS, args);
         } catch (final ParseException e) {
             throw new RuntimeException("Problem parsing command line options.", e);
         }
@@ -282,7 +274,7 @@
         }
 
         // Add all extra arguments to the EVIO file list.
-        final List<String> evioFileList = new ArrayList<String>(Arrays.asList(cl.getArgs()));
+        evioFileList = new ArrayList<String>(Arrays.asList(cl.getArgs()));
 
         // Process text file containing list of EVIO file paths, one per line.
         if (cl.hasOption("f")) {
@@ -315,10 +307,6 @@
             this.printUsage();
         }
 
-        String lcioFileName = null;
-        LCIOWriter writer = null;
-        InputStream steeringStream = null;
-
         // Get the LCIO output file.
         if (cl.hasOption("l")) {
             LOGGER.config("set LCIO file to " + lcioFileName);
@@ -331,7 +319,8 @@
             if (cl.hasOption("r")) {
                 steeringStream = EvioToLcio.class.getResourceAsStream(lcsimXmlName);
                 if (steeringStream == null) {
-                    IllegalArgumentException e = new IllegalArgumentException("XML steering resource was not found.");
+                    final IllegalArgumentException e = new IllegalArgumentException(
+                            "XML steering resource was not found.");
                     LOGGER.log(Level.SEVERE, "LCSim steering resource " + lcsimXmlName + " was not found.", e);
                     throw e;
                 }
@@ -374,13 +363,13 @@
         }
 
         // Process the LCSim job variable definitions, if any.
-        final JobManager jobManager = new JobManager();
+        jobManager = new JobManager();
         if (cl.hasOption("D")) {
             final String[] steeringOptions = cl.getOptionValues("D");
             for (final String def : steeringOptions) {
                 final String[] s = def.split("=");
                 if (s.length != 2) {
-                    IllegalArgumentException e = new IllegalArgumentException("Bad variable format: " + def);
+                    final IllegalArgumentException e = new IllegalArgumentException("Bad variable format: " + def);
                     LOGGER.log(Level.SEVERE, "bad variable format: " + def, e);
                     throw e;
                 }
@@ -419,16 +408,10 @@
         // Add conditions system tag filters.
         if (cl.hasOption("t")) {
             final String[] tags = cl.getOptionValues("t");
-            for (String tag : tags) {
+            for (final String tag : tags) {
                 LOGGER.config("adding conditions tag " + tag);
                 DatabaseConditionsManager.getInstance().addTag(tag);
             }
-        }
-
-        // Is there a run number from the command line options?
-        if (runNumber != null) {
-            // Initialize the conditions system before the job starts and freeze it.
-            this.checkConditions(runNumber, true);
         }
 
         // Print out the EVIO file list before the job starts.
@@ -442,20 +425,44 @@
         LOGGER.config(buff.toString());
 
         // Get whether to debug print XML from the EVIO events.
-        boolean printXml = false;
         if (cl.hasOption("v")) {
             printXml = true;
+            LOGGER.config("print XML enabled");
         }
 
         // Get the maximum number of EVIO events to buffer.
         if (cl.hasOption("m")) {
             maxBufferSize = Integer.parseInt(cl.getOptionValue("m"));
+            LOGGER.config("max event buffer size set to " + maxBufferSize);
+        }
+
+        if (cl.hasOption("M")) {
+            useMemoryMapping = true;
+            LOGGER.config("EVIO reader memory mapping is enabled.");
+        }
+    }
+
+    /**
+     * This method will execute the EVIO to LCIO conversion and optionally process the events with LCSim Drivers from a
+     * steering file. Then the resultant LCIO events will be written to disk if this option is enabled in the command
+     * line arguments.
+     *
+     * @param args The command line arguments.
+     */
+    public void run() {
+
+        // Register class for setting up SVT detector state from conditions data.
+        DatabaseConditionsManager.getInstance().addConditionsListener(new SvtDetectorSetup());
+
+        // Is there a run number from the command line options?
+        if (runNumber != null) {
+            // Initialize the conditions system before the job starts and freeze it.
+            this.checkConditions(runNumber, true);
         }
 
         // Loop over the input EVIO files.
         EvioReader reader = null;
-        fileLoop:
-        for (final String evioFileName : evioFileList) {
+        fileLoop: for (final String evioFileName : evioFileList) {
 
             // Get the next EVIO input file.
             final File evioFile = new File(evioFileName);
@@ -463,10 +470,11 @@
                 throw new RuntimeException("EVIO file " + evioFile.getPath() + " does not exist.");
             }
             LOGGER.info("Opening EVIO file " + evioFileName + " ...");
+            LOGGER.getHandlers()[0].flush();
 
             // Open the EVIO reader.
             try {
-                reader = new EvioReader(evioFile, false, !cl.hasOption("M"));
+                reader = new EvioReader(evioFile, false, !useMemoryMapping);
             } catch (final Exception e) {
                 throw new RuntimeException("Error opening the EVIO file reader.", e);
             }
@@ -476,8 +484,7 @@
 
             // Loop over events.
             final EvioEventQueue eventQueue = new EvioEventQueue(-1L, maxBufferSize);
-            eventLoop:
-            for (;;) {
+            eventLoop: for (;;) {
 
                 // Buffer the EVIO events into the queue.
                 this.bufferEvents(reader, eventQueue, maxBufferSize);
@@ -489,8 +496,7 @@
                 }
 
                 // Loop over the EVIO events in the buffer until it is empty.
-                recordLoop:
-                while (eventQueue.hasNext()) {
+                recordLoop: while (eventQueue.hasNext()) {
 
                     // Read and parse the next EVIO event.
                     EvioEvent evioEvent = null;
@@ -568,7 +574,8 @@
                         // Build the LCIO event.
                         final EventHeader lcioEvent = eventBuilder.makeLCSimEvent(evioEvent);
                         eventTime = lcioEvent.getTimeStamp() / 1000000;
-                        LOGGER.finest("created LCIO event " + lcioEvent.getEventNumber() + " with time " + new Date(eventTime));
+                        LOGGER.finest("created LCIO event " + lcioEvent.getEventNumber() + " with time "
+                                + new Date(eventTime));
                         if (firstEvent) {
                             LOGGER.info("first physics event time: " + eventTime / 1000 + " - " + new Date(eventTime));
                             firstEvent = false;
@@ -644,13 +651,10 @@
     }
 
     /**
-     * Setup the LCSimEventBuilder based on the current detector name and run
-     * number.
+     * Setup the LCSimEventBuilder based on the current detector name and run number.
      *
-     * @param detectorName The detector name to be assigned to the event
-     * builder.
-     * @param runNumber The run number which determines which event builder to
-     * use.
+     * @param detectorName The detector name to be assigned to the event builder.
+     * @param runNumber The run number which determines which event builder to use.
      * @return The LCSimEventBuilder for the Test Run or Engineering Run.
      */
     private void setupEventBuilder(final int runNumber) {

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use