Author: [log in to unmask] Date: Thu Jan 22 15:40:20 2015 New Revision: 1971 Log: Fix conditions setup based on previous changes to event builder. Also initial support for getting run numbers from events during monitoring session. Added: java/trunk/record-util/src/main/java/org/hps/record/evio/EvioDetectorConditionsProcessor.java Modified: java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/MonitoringApplication.java java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoop.java Modified: java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/MonitoringApplication.java ============================================================================= --- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/MonitoringApplication.java (original) +++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/MonitoringApplication.java Thu Jan 22 15:40:20 2015 @@ -60,7 +60,6 @@ import javax.imageio.ImageIO; import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; @@ -70,7 +69,6 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; import javax.swing.JTable; import javax.swing.SwingUtilities; import javax.swing.table.DefaultTableModel; @@ -97,6 +95,7 @@ import org.hps.record.composite.EventProcessingThread; import org.hps.record.enums.DataSourceType; import org.hps.record.et.EtConnection; +import org.hps.record.evio.EvioDetectorConditionsProcessor; import org.jlab.coda.jevio.EvioException; import org.jlab.coda.jevio.EvioReader; import org.lcsim.conditions.ConditionsManager; @@ -985,7 +984,7 @@ // Start thread which will trigger a disconnect if the event processing finishes. startSessionWatchdogThread(); - // Apparently, the visible plots won't draw without this! (Unless the user clicks directly on the tab.) + // FIXME: Apparently, the visible plots won't draw without this! (Unless the user clicks directly on the tab.) plotWindow.getPlotPane().requestFocusInWindow(); log(Level.INFO, "Successfully started the monitoring session."); @@ -1036,6 +1035,7 @@ throw new IOException(e); } } else { + // This is when a direct file source is used and ET is not needed. this.setConnectionStatus(ConnectionStatus.CONNECTED); } } @@ -1114,16 +1114,19 @@ try { // Create and the job manager. The conditions manager is instantiated from this call but not configured. jobManager = new JobManager(); + + // Setup the event builder to translate from EVIO to LCIO. + // This must happen before Driver setup so the builder's listeners are activated first! + createEventBuilder(); + + // Configure the job manager for the XML steering. jobManager.setPerformDryRun(true); if (steeringType == SteeringType.RESOURCE) { setupSteeringResource(steering); } else if (steeringType.equals(SteeringType.FILE)) { setupSteeringFile(steering); } - - // Setup the event builder to translate from EVIO to LCIO. - createEventBuilder(); - + // Is there a user specified run number from the JobPanel? if (configurationModel.hasPropertyValue(ConfigurationModel.USER_RUN_NUMBER_PROPERTY)) { int userRunNumber = configurationModel.getUserRunNumber(); @@ -1181,10 +1184,7 @@ throw new RuntimeException("Failed to create LCSimEventBuilder.", e); } - // Set the detector name on the event builder so it can find conditions data. - // FIXME: This call should be made unnecessary by modifying the EventBuilder API to remove setDetectorName. - //eventBuilder.setDetectorName(configurationModel.getDetectorName()); - + // Add the builder as a listener so it is notified when conditions change. ConditionsManager.defaultInstance().addConditionsListener(eventBuilder); log(Level.CONFIG, "Successfully initialized event builder <" + eventBuilderClassName + ">"); @@ -1345,10 +1345,13 @@ // RunPanel updater. loopConfig.add(runPanel.new RunModelUpdater()); + + // Setup for conditions activation via EVIO events. + loopConfig.add(new EvioDetectorConditionsProcessor(configurationModel.getDetectorName())); // Create the CompositeLoop with the configuration. loop = new CompositeLoop(loopConfig); - + // Create the processing thread. processingThread = new EventProcessingThread(loop); Modified: java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoop.java ============================================================================= --- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoop.java (original) +++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoop.java Thu Jan 22 15:40:20 2015 @@ -293,9 +293,10 @@ if (config.eventBuilder != null) { if (config.detectorName != null) { // Is LCSim ConditionsManager installed yet? - if (!ConditionsManager.isSetup()) - // Setup LCSim conditions system if not already. + if (!ConditionsManager.isSetup()) { + // Setup default LCSim conditions system if not already. LCSimConditionsManagerImplementation.register(); + } //config.eventBuilder.setDetectorName(config.detectorName); } else { throw new IllegalArgumentException("Missing detectorName in configuration."); Added: java/trunk/record-util/src/main/java/org/hps/record/evio/EvioDetectorConditionsProcessor.java ============================================================================= --- java/trunk/record-util/src/main/java/org/hps/record/evio/EvioDetectorConditionsProcessor.java (added) +++ java/trunk/record-util/src/main/java/org/hps/record/evio/EvioDetectorConditionsProcessor.java Thu Jan 22 15:40:20 2015 @@ -0,0 +1,71 @@ +package org.hps.record.evio; + +import org.jlab.coda.jevio.BaseStructure; +import org.jlab.coda.jevio.EvioEvent; +import org.lcsim.conditions.ConditionsManager; +import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException; + +/** + * <p> + * This is an {@link EvioEventProcessor} for initializing the conditions system + * from EVIO events. + * <p> + * The {@link #startRun(EvioEvent)} method will setup conditions from the pre start + * events. + * <p> + * The {@link #process(EvioEvent)} method will setup conditions from a head bank + * if it is present in the event. + * + * @author Jeremy McCormick <[log in to unmask]> + */ +public class EvioDetectorConditionsProcessor extends EvioEventProcessor { + + private String detectorName; + + public EvioDetectorConditionsProcessor(String detectorName) { + if (detectorName == null) { + throw new IllegalArgumentException("The detectorName argument is null."); + } + this.detectorName = detectorName; + } + + @Override + public void process(EvioEvent evioEvent) throws Exception { + // Get the head head bank from event. + BaseStructure headBank = EvioEventUtilities.getHeadBank(evioEvent); + + // Is the head bank present? + if (headBank != null) { + + // Get the run number from the head bank. + int runNumber = headBank.getIntData()[1]; + + // Initialize the conditions system from the detector name and run number. + try { + ConditionsManager.defaultInstance().setDetector(detectorName, runNumber); + } catch (ConditionsNotFoundException e) { + throw new RuntimeException("Error setting up conditions from EVIO head bank.", e); + } + } + } + + @Override + public void startRun(EvioEvent evioEvent) { + System.out.println("EvioDetectorConditionsProcessor.startRun"); + if (EvioEventUtilities.isPreStartEvent(evioEvent)) { + // Get the pre start event's data bank. + int[] data = EvioEventUtilities.getControlEventData(evioEvent); + + // Get the run number from the bank. + int runNumber = data[1]; + + // Initialize the conditions system from the detector name and run number. + try { + System.out.println(" setting up conditions from pre start: " + detectorName + " #" + runNumber); + ConditionsManager.defaultInstance().setDetector(detectorName, runNumber); + } catch (ConditionsNotFoundException e) { + throw new RuntimeException("Error setting up conditions from EVIO pre start event.", e); + } + } + } +}