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  November 2014

HPS-SVN November 2014

Subject:

r1464 - in /java/trunk/evio/src/main/java/org/hps/evio: EvioToLcio.java TestRunEvioToLcio.java

From:

[log in to unmask]

Reply-To:

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

Date:

Mon, 10 Nov 2014 08:03:30 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (953 lines)

Author: [log in to unmask]
Date: Mon Nov 10 00:03:27 2014
New Revision: 1464

Log:
Copy TestRunEvioToLcio to EvioToLcio and deprecate it.  (Old class not removed for now.)

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

Added: java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java
 =============================================================================
--- java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java	(added)
+++ java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java	Mon Nov 10 00:03:27 2014
@@ -0,0 +1,325 @@
+package org.hps.evio;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+import org.hps.conditions.DatabaseConditionsManager;
+import org.jlab.coda.jevio.EvioEvent;
+import org.jlab.coda.jevio.EvioReader;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+import org.lcsim.event.EventHeader;
+import org.lcsim.job.JobControlManager;
+import org.lcsim.lcio.LCIOWriter;
+
+/**
+ * This class is for converting Test Run EVIO to LCIO events and performing an
+ * LCSim job in the same session. The processed events are then written to disk
+ * using an LCIOWriter.
+ *
+ * To run this class from command line:
+ *
+ * TestRunEvioToLcio [evioFile] -l [lcioFile] -d [detectorName] -x
+ * [lcsimXmlFile]
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class EvioToLcio {
+
+	private static final String defaultDetectorName = "";
+	private static final String defaultSteeringFile = "/org/hps/steering/monitoring/DummyMonitoring.lcsim";
+
+	/**
+	 * Defines command line options for this program.
+	 *
+	 * @return The command line options.
+	 */
+	private static Options createCommandLineOptions() {
+		Options options = new Options();
+		options.addOption(new Option("l", true, "The name of the output LCIO file"));
+		options.addOption(new Option("d", true, "The name of the detector to use for LCSim conditions"));
+		options.addOption(new Option("x", true, "The LCSim XML file to process the LCIO events"));
+		options.addOption(new Option("s", true, "Sleep duration between events (in ms)"));
+		options.addOption(new Option("n", true, "Stop after N events"));
+		options.addOption(new Option("w", false, "Wait after end of data"));
+		options.addOption(new Option("D", true, "Pass a variable to the steering file"));
+		options.addOption(new Option("r", false, "Interpret -x argument as a steering resource instead of a file path"));
+		options.addOption(new Option("R", true, "The run number"));
+		options.addOption(new Option("t", false, "Read test run data"));
+		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) {
+		int maxEvents = 0;
+		int nEvents = 0;
+
+		// Set up command line parsing.
+		Options options = createCommandLineOptions();
+		if (args.length == 0) {
+			System.out.println("TestRunEvioToLcio [options] [evioFiles]");
+			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;
+		LCIOWriter writer = null;
+		String detectorName = defaultDetectorName;
+		InputStream steeringStream = null;
+		int sleepTime = -1;
+
+		// LCIO output file.
+		if (cl.hasOption("l")) {
+			lcioFileName = cl.getOptionValue("l");
+		}
+
+		// Name of detector.
+		if (cl.hasOption("d")) {
+			detectorName = cl.getOptionValue("d");
+		}
+
+		if ("".equals(detectorName)) {
+			throw new RuntimeException("You need to specify a valid detector name as input, use the -d option");
+		}
+
+		// LCSim XML file to execute inline.
+		if (cl.hasOption("x")) {
+			String lcsimXmlName = cl.getOptionValue("x");
+			if (cl.hasOption("r")) {
+				steeringStream = TestRunEvioToLcio.class.getResourceAsStream(lcsimXmlName);
+				if (steeringStream == null) {
+					throw new RuntimeException("resource " + lcsimXmlName + " not found");
+				}
+			} else {
+				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.valueOf(cl.getOptionValue("s"));
+		}
+
+		// Sleep time.
+		if (cl.hasOption("n")) {
+			maxEvents = Integer.valueOf(cl.getOptionValue("n"));
+		}
+
+		// LCIO writer.
+		if (lcioFileName != null) {
+			try {
+				writer = new LCIOWriter(new File(lcioFileName));
+			} catch (IOException e) {
+				throw new RuntimeException(e);
+			}
+		}
+
+		// LCSim job manager.
+		JobControlManager jobManager = new JobControlManager();
+
+		if (cl.hasOption("D")) {
+			String[] steeringOptions = cl.getOptionValues("D");
+			for (String def : steeringOptions) {
+				String[] s = def.split("=");
+				if (s.length != 2) {
+					throw new RuntimeException("Bad variable format: " + def);
+				}
+				String key = s[0];
+				String value = s[1];
+				jobManager.addVariableDefinition(key, value);
+			}
+		}
+
+		int runNumber = 0;
+		if (cl.hasOption("R")) {
+			runNumber = Integer.valueOf(cl.getOptionValue("R"));
+		}
+
+		jobManager.setup(steeringStream);
+		jobManager.configure();
+
+		// LCSim event builder.
+		LCSimEventBuilder eventBuilder = null;
+
+		DatabaseConditionsManager manager = DatabaseConditionsManager.getInstance();
+
+		if (cl.hasOption("t")) {
+			manager.configure("/org/hps/conditions/config/conditions_database_testrun_2012.xml");
+			eventBuilder = new LCSimTestRunEventBuilder();
+		} else {
+			eventBuilder = new LCSimEngRunEventBuilder();
+		}
+
+		try {
+			manager.setDetector(detectorName, runNumber);
+		} catch (ConditionsNotFoundException e) {
+			throw new RuntimeException(e);
+		}
+
+		eventBuilder.setDetectorName(detectorName);
+		ConditionsManager.defaultInstance().addConditionsListener(eventBuilder);
+
+		for (String evioFileName : cl.getArgs()) {
+			// EVIO input file.
+			File evioFile = new File(evioFileName);
+			System.out.println("Opening file " + evioFileName);
+			// EVIO reader.
+			EvioReader reader = null;
+			try {
+				reader = new EvioReader(evioFile);
+			} catch (Exception e) {
+				throw new RuntimeException(e);
+			}
+
+			boolean firstEvent = true;
+			long time = 0; // in ms
+
+			// Loop over EVIO events, build LCSim events, process them, and then
+			// write events to disk.
+			fileLoop: while (maxEvents == 0 || nEvents < maxEvents) {
+				EvioEvent evioEvent = null;
+				try {
+					eventLoop: while (evioEvent == null) {
+						evioEvent = reader.nextEvent();
+						if (evioEvent == null) {
+							break fileLoop;
+						}
+						try {
+							reader.parseEvent(evioEvent);
+						} catch (Exception e) {
+							Logger.getLogger(TestRunEvioToLcio.class.getName()).log(Level.SEVERE, "Error reading EVIO event", e);
+							continue eventLoop;
+						}
+					}
+					// let event builder check for run information
+					eventBuilder.readEvioEvent(evioEvent);
+					// Handlers for different event types.
+					if (EventConstants.isPreStartEvent(evioEvent)) {
+						int[] data = evioEvent.getIntData();
+						//int seconds = data[0];
+						runNumber = data[1];
+						// calibListener.prestart(seconds, runNumber);
+					} else if (EventConstants.isEndEvent(evioEvent)) {
+						int[] data = evioEvent.getIntData();
+						//int seconds = data[0];
+						//int nevents = data[2];
+						// calibListener.endRun(seconds, nevents);
+					} else if (eventBuilder.isPhysicsEvent(evioEvent)) {
+						EventHeader lcioEvent = eventBuilder.makeLCSimEvent(evioEvent);
+
+						time = (lcioEvent.getTimeStamp() / 1000000);
+
+						if (firstEvent) {
+							System.out.println("First physics event time: " + time / 1000 + " - " + new Date(time));
+							firstEvent = false;
+						}
+						// if
+						// (lcioEvent.hasCollection(BaseRawCalorimeterHit.class,
+						// "EcalReadoutHits") &&
+						// !lcioEvent.get(BaseRawCalorimeterHit.class,
+						// "EcalReadoutHits").isEmpty()) {
+						// continue;
+						// }
+						// if (lcioEvent.hasCollection(TriggerData.class,
+						// "TriggerBank")) {
+						// List<TriggerData> triggerList =
+						// lcioEvent.get(TriggerData.class, "TriggerBank");
+						// if (!triggerList.isEmpty()) {
+						// TriggerData triggerData = triggerList.get(0);
+						//
+						// int orTrig = triggerData.getOrTrig();
+						// int topTrig = triggerData.getTopTrig();
+						// int botTrig = triggerData.getBotTrig();
+						// int pairTrig = triggerData.getPairTrig();
+						// if (topTrig != 0 && botTrig != 0) {
+						// System.out.format("%x\t%x\t%x\t%x\n", orTrig,
+						// topTrig, botTrig, pairTrig);
+						// } else {
+						// continue;
+						// }
+						// }
+						// }
+						jobManager.processEvent(lcioEvent);
+						if (writer != null) {
+							writer.write(lcioEvent);
+							writer.flush();
+						}
+
+					}
+				} catch (Exception e) {
+					// Catch all event processing errors and continue.
+					Logger.getLogger(TestRunEvioToLcio.class.getName()).log(Level.SEVERE, "Error in event processing", e);
+					continue;
+				} finally {
+					if (sleepTime > 0) {
+						try {
+							Thread.sleep(sleepTime);
+						} catch (InterruptedException e) {
+							throw new RuntimeException(e);
+						}
+					}
+				}
+				nEvents++;
+			}
+			System.out.println("Last physics event time: " + time / 1000 + " - " + new Date(time));
+			try {
+				reader.close();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		System.out.println("No more data");
+
+		if (!cl.hasOption("w")) {
+			System.out.println("Exiting");
+			jobManager.finish();
+			System.out.println("jobManager finished");
+		}
+
+		if (writer != null) {
+			System.out.println("close writer");
+			try {
+				writer.close();
+			} catch (IOException e) {
+				throw new RuntimeException(e);
+			}
+			System.out.println("closed writer");
+		}
+	}
+}

Modified: java/trunk/evio/src/main/java/org/hps/evio/TestRunEvioToLcio.java
 =============================================================================
--- java/trunk/evio/src/main/java/org/hps/evio/TestRunEvioToLcio.java	(original)
+++ java/trunk/evio/src/main/java/org/hps/evio/TestRunEvioToLcio.java	Mon Nov 10 00:03:27 2014
@@ -8,6 +8,7 @@
 import java.util.Date;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.HelpFormatter;
@@ -15,10 +16,11 @@
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
-import org.hps.util.RunControlDialog;
+import org.hps.conditions.DatabaseConditionsManager;
 import org.jlab.coda.jevio.EvioEvent;
 import org.jlab.coda.jevio.EvioReader;
 import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
 import org.lcsim.event.EventHeader;
 import org.lcsim.job.JobControlManager;
 import org.lcsim.lcio.LCIOWriter;
@@ -34,297 +36,293 @@
  * [lcsimXmlFile]
  *
  * @author Jeremy McCormick <[log in to unmask]>
+ * 
+ * @deprecated use {@link EvioToLcio instead}
  */
-// TODO: Update this class so it works correctly with the database conditions system
-// FIXME:  For now, the run number was added to the command line options so the 
-//         correct set of conditions can be loaded. This needs to be changed to 
-//         get the correct run number from the prestart.
+@Deprecated
 public class TestRunEvioToLcio {
 
-    private static final String defaultDetectorName = "";
-    private static final String defaultSteeringFile = "/org/hps/steering/monitoring/DummyMonitoring.lcsim";
-
-    /**
-     * Defines command line options for this program.
-     *
-     * @return The command line options.
-     */
-    private static Options createCommandLineOptions() {
-        Options options = new Options();
-
-        options.addOption(new Option("l", true, "The name of the output LCIO file."));
-        options.addOption(new Option("d", true, "The name of the detector to use for LCSim conditions."));
-        options.addOption(new Option("x", true, "The LCSim XML file to process the LCIO events."));
-        options.addOption(new Option("s", true, "Sleep duration between events (in ms)"));
-        options.addOption(new Option("n", true, "Stop after N events"));
-        options.addOption(new Option("w", false, "Wait after end of data"));
-        options.addOption(new Option("c", false, "Show run control window"));
-        options.addOption(new Option("D", true, "Pass a variable to the steering file"));
-        options.addOption(new Option("r", false, "Interpret -x argument as a steering resource instead of a file path"));
-        options.addOption(new Option("R", true, "The run number"));
-        options.addOption(new Option("t", false, "Read test run data"));
-
-        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) {
-        int maxEvents = 0;
-        int nEvents = 0;
-
-        // Set up command line parsing.
-        Options options = createCommandLineOptions();
-        if (args.length == 0) {
-            System.out.println("TestRunEvioToLcio [options] [evioFiles]");
-            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;
-        LCIOWriter writer = 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");
-        }
-
-        if ("".equals(detectorName)) {
-            throw new RuntimeException("You need to specify a valid detector name as input, use the -d option");
-        }
-
-        // LCSim XML file to execute inline.
-        if (cl.hasOption("x")) {
-            String lcsimXmlName = cl.getOptionValue("x");
-            if (cl.hasOption("r")) {
-                steeringStream = TestRunEvioToLcio.class.getResourceAsStream(lcsimXmlName);
-                if (steeringStream == null) {
-                    throw new RuntimeException("resource " + lcsimXmlName + " not found");
-                }
-            } else {
-                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.valueOf(cl.getOptionValue("s"));
-        }
-
-        // Sleep time.
-        if (cl.hasOption("n")) {
-            maxEvents = Integer.valueOf(cl.getOptionValue("n"));
-        }
-
-        RunControlDialog runControl = null;
-
-        if (cl.hasOption("c")) {
-            runControl = new RunControlDialog();
-        }
-
-        // LCIO writer.
-        if (lcioFileName != null) {
-            try {
-                writer = new LCIOWriter(new File(lcioFileName));
-            } catch (IOException e) {
-                throw new RuntimeException(e);
-            }
-        }
-
-        // LCSim job manager.
-        JobControlManager jobManager = new JobControlManager();
-
-        if (cl.hasOption("D")) {
-            String[] steeringOptions = cl.getOptionValues("D");
-            for (String def : steeringOptions) {
-                String[] s = def.split("=");
-                if (s.length != 2) {
-                    throw new RuntimeException("Bad variable format: " + def);
-                }
-                String key = s[0];
-                String value = s[1];
-                jobManager.addVariableDefinition(key, value);
-            }
-        }
-
-        int runNumber = 0;
-        if (cl.hasOption("R")) {
-            runNumber = Integer.valueOf(cl.getOptionValue("R"));
-        }
-
-        jobManager.setup(steeringStream);
-        jobManager.configure();
-
-        // LCSim event builder.
-        LCSimEventBuilder eventBuilder = null;
-
-        if (cl.hasOption("t")) {
-            new org.hps.conditions.config.TestRunReadOnlyConfiguration(false).setup().load(detectorName, runNumber);
-            eventBuilder = new LCSimTestRunEventBuilder();
-        } else {
-            new org.hps.conditions.config.DevReadOnlyConfiguration().setup().load(detectorName, runNumber);
-            eventBuilder = new LCSimEngRunEventBuilder();
-
-        }
-
-        eventBuilder.setDetectorName(detectorName);
-        ConditionsManager.defaultInstance().addConditionsListener(eventBuilder);
-
-        for (String evioFileName : cl.getArgs()) {
-            // EVIO input file.
-            File evioFile = new File(evioFileName);
-            System.out.println("Opening file " + evioFileName);
-            // EVIO reader.
-            EvioReader reader = null;
-            try {
-                reader = new EvioReader(evioFile);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-
-            boolean firstEvent = true;
-            long time = 0; //in ms
-
-            // Loop over EVIO events, build LCSim events, process them, and then
-            // write events to disk.
-            fileLoop:
-            while (maxEvents == 0 || nEvents < maxEvents) {
-                EvioEvent evioEvent = null;
-                try {
-                    eventLoop:
-                    while (evioEvent == null) {
-                        evioEvent = reader.nextEvent();
-                        if (evioEvent == null) {
-                            break fileLoop;
-                        }
-                        try {
-                            reader.parseEvent(evioEvent);
-                        } catch (Exception e) {
-                            Logger.getLogger(TestRunEvioToLcio.class.getName()).log(Level.SEVERE, "Error reading EVIO event", e);
-                            continue eventLoop;
-                        }
-                    }
-                    //let event builder check for run information
-                    eventBuilder.readEvioEvent(evioEvent);
-                    // Handlers for different event types.
-                    if (EventConstants.isPreStartEvent(evioEvent)) {
-                        int[] data = evioEvent.getIntData();
-                        int seconds = data[0];
-                        runNumber = data[1];
-//                        calibListener.prestart(seconds, runNumber);
-                    } else if (EventConstants.isEndEvent(evioEvent)) {
-                        int[] data = evioEvent.getIntData();
-                        int seconds = data[0];
-                        int nevents = data[2];
-//                        calibListener.endRun(seconds, nevents);
-                    } else if (eventBuilder.isPhysicsEvent(evioEvent)) {
-                        EventHeader lcioEvent = eventBuilder.makeLCSimEvent(evioEvent);
-                        if (runControl == null || runControl.process(lcioEvent)) {
-                            time = (lcioEvent.getTimeStamp() / 1000000);
-
-                            if (firstEvent) {
-                                System.out.println("First physics event time: " + time / 1000 + " - " + new Date(time));
-                                firstEvent = false;
-                            }
-//                            if (lcioEvent.hasCollection(BaseRawCalorimeterHit.class, "EcalReadoutHits") && !lcioEvent.get(BaseRawCalorimeterHit.class, "EcalReadoutHits").isEmpty()) {
-//                                continue;
-//                            }
-//                            if (lcioEvent.hasCollection(TriggerData.class, "TriggerBank")) {
-//                                List<TriggerData> triggerList = lcioEvent.get(TriggerData.class, "TriggerBank");
-//                                if (!triggerList.isEmpty()) {
-//                                    TriggerData triggerData = triggerList.get(0);
-//
-//                                    int orTrig = triggerData.getOrTrig();
-//                                    int topTrig = triggerData.getTopTrig();
-//                                    int botTrig = triggerData.getBotTrig();
-//                                    int pairTrig = triggerData.getPairTrig();
-//                                    if (topTrig != 0 && botTrig != 0) {
-//                                        System.out.format("%x\t%x\t%x\t%x\n", orTrig, topTrig, botTrig, pairTrig);
-//                                    } else {
-//                                        continue;
-//                                    }
-//                                }
-//                            }
-                            jobManager.processEvent(lcioEvent);
-                            if (writer != null) {
-                                writer.write(lcioEvent);
-                                writer.flush();
-                            }
-                        }
-                    }
-                } catch (Exception e) {
-                    // Catch all event processing errors and continue.
-                    Logger.getLogger(TestRunEvioToLcio.class.getName()).log(Level.SEVERE, "Error in event processing", e);
-                    continue;
-                } finally {
-                    if (sleepTime > 0) {
-                        try {
-                            Thread.sleep(sleepTime);
-                        } catch (InterruptedException e) {
-                            throw new RuntimeException(e);
-                        }
-                    }
-                }
-                nEvents++;
-            }
-            System.out.println("Last physics event time: " + time / 1000 + " - " + new Date(time));
-            try {
-                reader.close();
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-        System.out.println("No more data");
-
-        if (!cl.hasOption("w")) {
-            System.out.println("Exiting");
-            jobManager.finish();
-            System.out.println("jobManager finished");
-        }
-
-        if (writer != null) {
-            System.out.println("close writer");
-            try {
-                writer.close();
-            } catch (IOException e) {
-                throw new RuntimeException(e);
-            }
-            System.out.println("closed writer");
-        }
-    }
+	private static final String defaultDetectorName = "";
+	private static final String defaultSteeringFile = "/org/hps/steering/monitoring/DummyMonitoring.lcsim";
+
+	/**
+	 * Defines command line options for this program.
+	 *
+	 * @return The command line options.
+	 */
+	private static Options createCommandLineOptions() {
+		Options options = new Options();
+		options.addOption(new Option("l", true, "The name of the output LCIO file"));
+		options.addOption(new Option("d", true, "The name of the detector to use for LCSim conditions"));
+		options.addOption(new Option("x", true, "The LCSim XML file to process the LCIO events"));
+		options.addOption(new Option("s", true, "Sleep duration between events (in ms)"));
+		options.addOption(new Option("n", true, "Stop after N events"));
+		options.addOption(new Option("w", false, "Wait after end of data"));
+		options.addOption(new Option("D", true, "Pass a variable to the steering file"));
+		options.addOption(new Option("r", false, "Interpret -x argument as a steering resource instead of a file path"));
+		options.addOption(new Option("R", true, "The run number"));
+		options.addOption(new Option("t", false, "Read test run data"));
+		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) {
+		int maxEvents = 0;
+		int nEvents = 0;
+
+		// Set up command line parsing.
+		Options options = createCommandLineOptions();
+		if (args.length == 0) {
+			System.out.println("TestRunEvioToLcio [options] [evioFiles]");
+			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;
+		LCIOWriter writer = null;
+		String detectorName = defaultDetectorName;
+		InputStream steeringStream = null;
+		int sleepTime = -1;
+
+		// LCIO output file.
+		if (cl.hasOption("l")) {
+			lcioFileName = cl.getOptionValue("l");
+		}
+
+		// Name of detector.
+		if (cl.hasOption("d")) {
+			detectorName = cl.getOptionValue("d");
+		}
+
+		if ("".equals(detectorName)) {
+			throw new RuntimeException("You need to specify a valid detector name as input, use the -d option");
+		}
+
+		// LCSim XML file to execute inline.
+		if (cl.hasOption("x")) {
+			String lcsimXmlName = cl.getOptionValue("x");
+			if (cl.hasOption("r")) {
+				steeringStream = TestRunEvioToLcio.class.getResourceAsStream(lcsimXmlName);
+				if (steeringStream == null) {
+					throw new RuntimeException("resource " + lcsimXmlName + " not found");
+				}
+			} else {
+				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.valueOf(cl.getOptionValue("s"));
+		}
+
+		// Sleep time.
+		if (cl.hasOption("n")) {
+			maxEvents = Integer.valueOf(cl.getOptionValue("n"));
+		}
+
+		// LCIO writer.
+		if (lcioFileName != null) {
+			try {
+				writer = new LCIOWriter(new File(lcioFileName));
+			} catch (IOException e) {
+				throw new RuntimeException(e);
+			}
+		}
+
+		// LCSim job manager.
+		JobControlManager jobManager = new JobControlManager();
+
+		if (cl.hasOption("D")) {
+			String[] steeringOptions = cl.getOptionValues("D");
+			for (String def : steeringOptions) {
+				String[] s = def.split("=");
+				if (s.length != 2) {
+					throw new RuntimeException("Bad variable format: " + def);
+				}
+				String key = s[0];
+				String value = s[1];
+				jobManager.addVariableDefinition(key, value);
+			}
+		}
+
+		int runNumber = 0;
+		if (cl.hasOption("R")) {
+			runNumber = Integer.valueOf(cl.getOptionValue("R"));
+		}
+
+		jobManager.setup(steeringStream);
+		jobManager.configure();
+
+		// LCSim event builder.
+		LCSimEventBuilder eventBuilder = null;
+
+		DatabaseConditionsManager manager = DatabaseConditionsManager.getInstance();
+
+		if (cl.hasOption("t")) {
+			manager.configure("/org/hps/conditions/config/conditions_database_testrun_2012.xml");
+			eventBuilder = new LCSimTestRunEventBuilder();
+		} else {
+			eventBuilder = new LCSimEngRunEventBuilder();
+		}
+
+		try {
+			manager.setDetector(detectorName, runNumber);
+		} catch (ConditionsNotFoundException e) {
+			throw new RuntimeException(e);
+		}
+
+		eventBuilder.setDetectorName(detectorName);
+		ConditionsManager.defaultInstance().addConditionsListener(eventBuilder);
+
+		for (String evioFileName : cl.getArgs()) {
+			// EVIO input file.
+			File evioFile = new File(evioFileName);
+			System.out.println("Opening file " + evioFileName);
+			// EVIO reader.
+			EvioReader reader = null;
+			try {
+				reader = new EvioReader(evioFile);
+			} catch (Exception e) {
+				throw new RuntimeException(e);
+			}
+
+			boolean firstEvent = true;
+			long time = 0; // in ms
+
+			// Loop over EVIO events, build LCSim events, process them, and then
+			// write events to disk.
+			fileLoop: while (maxEvents == 0 || nEvents < maxEvents) {
+				EvioEvent evioEvent = null;
+				try {
+					eventLoop: while (evioEvent == null) {
+						evioEvent = reader.nextEvent();
+						if (evioEvent == null) {
+							break fileLoop;
+						}
+						try {
+							reader.parseEvent(evioEvent);
+						} catch (Exception e) {
+							Logger.getLogger(TestRunEvioToLcio.class.getName()).log(Level.SEVERE, "Error reading EVIO event", e);
+							continue eventLoop;
+						}
+					}
+					// let event builder check for run information
+					eventBuilder.readEvioEvent(evioEvent);
+					// Handlers for different event types.
+					if (EventConstants.isPreStartEvent(evioEvent)) {
+						int[] data = evioEvent.getIntData();
+						//int seconds = data[0];
+						runNumber = data[1];
+						// calibListener.prestart(seconds, runNumber);
+					} else if (EventConstants.isEndEvent(evioEvent)) {
+						int[] data = evioEvent.getIntData();
+						//int seconds = data[0];
+						//int nevents = data[2];
+						// calibListener.endRun(seconds, nevents);
+					} else if (eventBuilder.isPhysicsEvent(evioEvent)) {
+						EventHeader lcioEvent = eventBuilder.makeLCSimEvent(evioEvent);
+
+						time = (lcioEvent.getTimeStamp() / 1000000);
+
+						if (firstEvent) {
+							System.out.println("First physics event time: " + time / 1000 + " - " + new Date(time));
+							firstEvent = false;
+						}
+						// if
+						// (lcioEvent.hasCollection(BaseRawCalorimeterHit.class,
+						// "EcalReadoutHits") &&
+						// !lcioEvent.get(BaseRawCalorimeterHit.class,
+						// "EcalReadoutHits").isEmpty()) {
+						// continue;
+						// }
+						// if (lcioEvent.hasCollection(TriggerData.class,
+						// "TriggerBank")) {
+						// List<TriggerData> triggerList =
+						// lcioEvent.get(TriggerData.class, "TriggerBank");
+						// if (!triggerList.isEmpty()) {
+						// TriggerData triggerData = triggerList.get(0);
+						//
+						// int orTrig = triggerData.getOrTrig();
+						// int topTrig = triggerData.getTopTrig();
+						// int botTrig = triggerData.getBotTrig();
+						// int pairTrig = triggerData.getPairTrig();
+						// if (topTrig != 0 && botTrig != 0) {
+						// System.out.format("%x\t%x\t%x\t%x\n", orTrig,
+						// topTrig, botTrig, pairTrig);
+						// } else {
+						// continue;
+						// }
+						// }
+						// }
+						jobManager.processEvent(lcioEvent);
+						if (writer != null) {
+							writer.write(lcioEvent);
+							writer.flush();
+						}
+
+					}
+				} catch (Exception e) {
+					// Catch all event processing errors and continue.
+					Logger.getLogger(TestRunEvioToLcio.class.getName()).log(Level.SEVERE, "Error in event processing", e);
+					continue;
+				} finally {
+					if (sleepTime > 0) {
+						try {
+							Thread.sleep(sleepTime);
+						} catch (InterruptedException e) {
+							throw new RuntimeException(e);
+						}
+					}
+				}
+				nEvents++;
+			}
+			System.out.println("Last physics event time: " + time / 1000 + " - " + new Date(time));
+			try {
+				reader.close();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		System.out.println("No more data");
+
+		if (!cl.hasOption("w")) {
+			System.out.println("Exiting");
+			jobManager.finish();
+			System.out.println("jobManager finished");
+		}
+
+		if (writer != null) {
+			System.out.println("close writer");
+			try {
+				writer.close();
+			} catch (IOException e) {
+				throw new RuntimeException(e);
+			}
+			System.out.println("closed writer");
+		}
+	}
 }

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