7 added + 26 removed + 14 modified, total 47 files
java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/DataSourcePanel.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/DataSourcePanel.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -15,7 +15,7 @@
import javax.swing.JTextField;
import org.hps.monitoring.gui.model.ConfigurationModel;
-import org.hps.record.DataSourceType;
+import org.hps.record.processing.DataSourceType;
/**
* A sub-panel of the settings window for selecting a data source,
java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/MonitoringApplication.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/MonitoringApplication.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -77,11 +77,11 @@
import org.hps.monitoring.subsys.SystemStatusRegistry;
import org.hps.monitoring.subsys.et.EtSystemMonitor;
import org.hps.monitoring.subsys.et.EtSystemStripCharts;
-import org.hps.record.DataSourceType;
-import org.hps.record.chain.EventProcessingChain;
-import org.hps.record.chain.EventProcessingConfiguration;
-import org.hps.record.chain.EventProcessingThread;
-import org.hps.record.etevent.EtConnection;
+import org.hps.record.et.EtConnection;
+import org.hps.record.processing.DataSourceType;
+import org.hps.record.processing.ProcessingChain;
+import org.hps.record.processing.ProcessingConfiguration;
+import org.hps.record.processing.ProcessingThread;
import org.jlab.coda.et.EtAttachment;
import org.jlab.coda.et.EtConstants;
import org.jlab.coda.et.EtStation;
@@ -126,8 +126,8 @@
// Event processing objects.
private JobControlManager jobManager;
private LCSimEventBuilder eventBuilder;
- private EventProcessingChain eventProcessing;
- private EventProcessingThread eventProcessingThread;
+ private ProcessingChain processingChain;
+ private ProcessingThread processingThread;
private Thread sessionWatchdogThread;
// Logging objects.
@@ -825,7 +825,6 @@
// Setup the EventProcessingChain object using the EtConnection.
setupEventProcessingChain();
- //setupEventProcessingChainNew();
// Setup the system status monitor table.
setupSystemStatusMonitor();
@@ -843,10 +842,8 @@
errorHandler.setError(e)
.log()
.printStackTrace();
- /*.showErrorDialog("Error setting up the session.");*/
-
+
// Disconnect from the session.
- //if (this.connected())
disconnect(ConnectionStatus.ERROR);
} finally {
@@ -1093,7 +1090,7 @@
*/
private void nextEvent() {
this.setConnectionStatus(ConnectionStatus.CONNECTED);
- eventProcessing.next();
+ processingChain.next();
log(Level.FINEST, "Getting next event.");
this.setConnectionStatus(ConnectionStatus.PAUSED);
}
@@ -1103,7 +1100,7 @@
*/
private void resumeEventProcessing() {
// Notify event processor to continue.
- eventProcessing.resume();
+ processingChain.resume();
// Set state of event buttons.
buttonsPanel.setPauseModeState(false);
@@ -1118,7 +1115,7 @@
*/
private void pauseEventProcessing() {
- eventProcessing.pause();
+ processingChain.pause();
// Set GUI state.
buttonsPanel.setPauseModeState(true);
@@ -1159,42 +1156,38 @@
*/
private void setupEventProcessingChain() {
- EventProcessingConfiguration configuration = new EventProcessingConfiguration();
+ ProcessingConfiguration processingConfiguration = new ProcessingConfiguration();
- configuration.setStopOnEndRun(configurationModel.getDisconnectOnEndRun());
- // FIXME: This doesn't work properly in the event processing chain right now so hard code to true
- // until that is fixed. (Need to talk with Dima about it.)
- //configurationModel.getDisconnectOnError();
- configuration.setStopOnErrors(true);
-
- configuration.setDataSourceType(configurationModel.getDataSourceType());
- configuration.setEtConnection(connection);
- configuration.setFilePath(configurationModel.getDataSourcePath());
- configuration.setLCSimEventBuild(eventBuilder);
- configuration.setDetectorName(configurationModel.getDetectorName());
+ processingConfiguration.setStopOnEndRun(configurationModel.getDisconnectOnEndRun());
+ processingConfiguration.setStopOnErrors(configurationModel.getDisconnectOnError());
+ processingConfiguration.setDataSourceType(configurationModel.getDataSourceType());
+ processingConfiguration.setEtConnection(connection);
+ processingConfiguration.setFilePath(configurationModel.getDataSourcePath());
+ processingConfiguration.setLCSimEventBuild(eventBuilder);
+ processingConfiguration.setDetectorName(configurationModel.getDetectorName());
// Add all Drivers from the pre-configured JobManager.
for (Driver driver : jobManager.getDriverExecList()) {
- configuration.add(driver);
+ processingConfiguration.add(driver);
}
- // ET system monitor processor.
- configuration.add(new EtSystemMonitor());
+ // ET system monitor.
+ processingConfiguration.add(new EtSystemMonitor());
- // ET system strip charts processor.
- configuration.add(new EtSystemStripCharts());
+ // ET system strip charts.
+ processingConfiguration.add(new EtSystemStripCharts());
- // RunPanel updater processor.
- configuration.add(runPanel.new RunModelUpdater());
+ // RunPanel updater.
+ processingConfiguration.add(runPanel.new RunModelUpdater());
- // Create the EventProcessingChain object.
- eventProcessing = new EventProcessingChain(configuration);
+ // Create the ProcessingChain object.
+ processingChain = new ProcessingChain(processingConfiguration);
- // Create the event processing thread.
- eventProcessingThread = new EventProcessingThread(eventProcessing);
+ // Create the processing thread.
+ processingThread = new ProcessingThread(processingChain);
- // Start the event processing thread.
- eventProcessingThread.start();
+ // Start the processing thread.
+ processingThread.start();
}
/**
@@ -1339,15 +1332,15 @@
*/
private void stopEventProcessing() {
- if (eventProcessingThread != null) {
+ if (processingThread != null) {
// Is the event processing thread actually still alive?
- if (eventProcessingThread.isAlive()) {
+ if (processingThread.isAlive()) {
// Interrupt and kill the event processing watchdog thread if necessary.
killSessionWatchdogThread();
// Request the event processing to stop.
- eventProcessing.stop();
+ processingChain.stop();
}
// Wait for the event processing thread to finish. This should just return
@@ -1356,19 +1349,19 @@
// In the case where ET is configured for sleep or timed wait, an untimed join could
// block forever, so only wait for ~1 second before continuing. The EventProcessingChain
// should still cleanup automatically when its thread completes after the ET system goes down.
- eventProcessingThread.join(1000);
+ processingThread.join(1000);
} catch (InterruptedException e) {
// Don't know when this would ever happen.
}
// Handle last error that occurred in event processing.
- if (eventProcessing.getLastError() != null) {
- errorHandler.setError(eventProcessing.getLastError()).log().printStackTrace();
+ if (processingChain.getLastError() != null) {
+ errorHandler.setError(processingChain.getLastError()).log().printStackTrace();
}
// Reset event processing objects.
- eventProcessing = null;
- eventProcessingThread = null;
+ processingChain = null;
+ processingThread = null;
}
}
@@ -1401,7 +1394,7 @@
try {
// When the event processing thread finishes, the session should be stopped and
// disconnect should occur.
- eventProcessingThread.join();
+ processingThread.join();
// Activate a disconnect using the ActionEvent which is used by the disconnect button.
// FIXME: When this happens the event processing object and its thread don't get set to null!
java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/RunPanel.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/RunPanel.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -26,7 +26,7 @@
import org.hps.evio.EventConstants;
import org.hps.monitoring.gui.model.RunModel;
import org.hps.record.composite.CompositeRecord;
-import org.hps.record.composite.CompositeRecordProcessor;
+import org.hps.record.composite.CompositeProcessor;
import org.jlab.coda.jevio.EvioEvent;
/**
@@ -90,7 +90,7 @@
timer.purge();
}
- class RunModelUpdater extends CompositeRecordProcessor {
+ class RunModelUpdater extends CompositeProcessor {
@Override
public void startJob() {
@@ -99,7 +99,7 @@
}
@Override
- public void processEvent(CompositeRecord event) {
+ public void process(CompositeRecord event) {
model.incrementEventsReceived();
EvioEvent evioEvent = event.getEvioEvent();
if (evioEvent != null) {
java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/ConfigurationModel.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/ConfigurationModel.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -4,7 +4,7 @@
import java.util.logging.Level;
import org.hps.monitoring.enums.SteeringType;
-import org.hps.record.DataSourceType;
+import org.hps.record.processing.DataSourceType;
import org.jlab.coda.et.enums.Mode;
/**
java/trunk/monitoring-app/src/main/java/org/hps/monitoring/subsys/et
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/subsys/et/EtSystemMonitor.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/subsys/et/EtSystemMonitor.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -7,13 +7,13 @@
import org.hps.monitoring.subsys.Subsystem;
import org.hps.monitoring.subsys.SystemStatus;
import org.hps.monitoring.subsys.SystemStatusImpl;
-import org.hps.record.etevent.EtEventProcessor;
+import org.hps.record.et.EtProcessor;
import org.jlab.coda.et.EtEvent;
/**
* This is a class for monitoring the ET system.
*/
-public final class EtSystemMonitor extends EtEventProcessor {
+public final class EtSystemMonitor extends EtProcessor {
SystemStatus systemStatus;
int events = 0;
@@ -22,7 +22,7 @@
Timer timer = new Timer("ET Event Monitor");
public EtSystemMonitor() {
- systemStatus = new SystemStatusImpl(Subsystem.ET, "Example ET Monitor", false);
+ systemStatus = new SystemStatusImpl(Subsystem.ET, "ET System Monitor", false);
systemStatus.setStatus(StatusCode.UNKNOWN, "System is not active yet.");
}
@@ -52,7 +52,7 @@
timer.schedule(task, 0, 1000);
}
- public void processEvent(EtEvent event) {
+ public void process(EtEvent event) {
eventReceivedMillis = System.currentTimeMillis();
}
java/trunk/monitoring-app/src/main/java/org/hps/monitoring/subsys/et
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/subsys/et/EtSystemStripCharts.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/subsys/et/EtSystemStripCharts.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -2,14 +2,14 @@
import org.hps.monitoring.plotting.MonitoringPlotFactory;
import org.hps.monitoring.subsys.SystemStatisticsImpl;
-import org.hps.record.etevent.EtEventProcessor;
+import org.hps.record.et.EtProcessor;
import org.jlab.coda.et.EtEvent;
import org.lcsim.util.aida.AIDA;
/**
* A basic set of strip charts for monitoring the ET system.
*/
-public final class EtSystemStripCharts extends EtEventProcessor {
+public final class EtSystemStripCharts extends EtProcessor {
SystemStatisticsImpl stats = new SystemStatisticsImpl();
MonitoringPlotFactory plotFactory = (MonitoringPlotFactory)
@@ -73,7 +73,7 @@
}
@Override
- public void processEvent(EtEvent event) {
+ public void process(EtEvent event) {
stats.update(event.getLength());
}
java/trunk/record-util/src/main/java/org/hps/record
--- java/trunk/record-util/src/main/java/org/hps/record/DataSourceType.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/DataSourceType.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,25 +0,0 @@
-package org.hps.record;
-
-/**
- * The type of data source that will supply events to the app.
- */
-public enum DataSourceType {
-
- ET_SERVER("ET Server"),
- EVIO_FILE("EVIO File"),
- LCIO_FILE("LCIO File");
-
- String description;
-
- private DataSourceType(String description) {
- this.description = description;
- }
-
- public String description() {
- return description;
- }
-
- public boolean isFile() {
- return this.ordinal() > ET_SERVER.ordinal();
- }
-}
java/trunk/record-util/src/main/java/org/hps/record
--- java/trunk/record-util/src/main/java/org/hps/record/ErrorState.java (rev 0)
+++ java/trunk/record-util/src/main/java/org/hps/record/ErrorState.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -0,0 +1,36 @@
+package org.hps.record;
+
+public class ErrorState {
+
+ Exception lastError;
+
+ public ErrorState() {
+ }
+
+ public Throwable getLastError() {
+ return lastError;
+ }
+
+ public void setLastError(Exception lastError) {
+ this.lastError = lastError;
+ }
+
+ public boolean hasError() {
+ return lastError != null;
+ }
+
+ public void rethrow() throws Exception {
+ Exception throwMe = lastError;
+ clear(); // Clear error state before throwing.
+ throw throwMe;
+ }
+
+ public void clear() {
+ lastError = null;
+ }
+
+ public void print() {
+ lastError.printStackTrace();
+ }
+
+}
java/trunk/record-util/src/main/java/org/hps/record
--- java/trunk/record-util/src/main/java/org/hps/record/EventProcessingException.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/EventProcessingException.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,9 +0,0 @@
-package org.hps.record;
-
-public class EventProcessingException extends RuntimeException {
-
- public EventProcessingException(String message, Throwable x) {
- super(message, x);
- }
-
-}
java/trunk/record-util/src/main/java/org/hps/record
--- java/trunk/record-util/src/main/java/org/hps/record/EventProcessor.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/EventProcessor.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,37 +0,0 @@
-package org.hps.record;
-
-/**
- * This is a generic interface for event processing.
- *
- * @param <EventType> The concrete type of the event record.
- */
-public interface EventProcessor<EventType> {
-
- /**
- * Start of job action.
- */
- void startJob();
-
- /**
- * Start run action.
- * @param event
- */
- void startRun(EventType event);
-
- /**
- * Process a single event.
- * @param event
- */
- void processEvent(EventType event) throws Exception;
-
- /**
- * End of run action.
- * @param event
- */
- void endRun(EventType event);
-
- /**
- * End of job action.
- */
- void endJob();
-}
java/trunk/record-util/src/main/java/org/hps/record
--- java/trunk/record-util/src/main/java/org/hps/record/HasErrorState.java (rev 0)
+++ java/trunk/record-util/src/main/java/org/hps/record/HasErrorState.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -0,0 +1,6 @@
+package org.hps.record;
+
+
+public interface HasErrorState {
+ ErrorState getErrorState();
+}
java/trunk/record-util/src/main/java/org/hps/record
--- java/trunk/record-util/src/main/java/org/hps/record/MaxRecordsException.java (rev 0)
+++ java/trunk/record-util/src/main/java/org/hps/record/MaxRecordsException.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -0,0 +1,18 @@
+package org.hps.record;
+
+/**
+ * Exception to be thrown when maximum number of records is reached.
+ */
+public class MaxRecordsException extends Exception {
+
+ int maxRecords;
+
+ public MaxRecordsException(String message, int maxRecords) {
+ super(message);
+ this.maxRecords = maxRecords;
+ }
+
+ public int getMaxRecords() {
+ return maxRecords;
+ }
+}
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeRecord.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeRecord.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -6,7 +6,7 @@
/**
* This class is used to group together corresponding ET, EVIO and LCIO events
- * for use by the {@link CompositeRecordLoop}.
+ * for use by the {@link CompositeLoop}.
*/
public final class CompositeRecord {
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeRecordLoop.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeRecordLoop.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,93 +0,0 @@
-package org.hps.record.composite;
-
-import org.freehep.record.loop.DefaultRecordLoop;
-import org.freehep.record.source.RecordSource;
-import org.hps.record.EndRunException;
-import org.hps.record.EventProcessingException;
-
-/**
- * Implementation of a composite record loop for processing
- * ET, EVIO and LCIO events using a single record source.
- */
-public final class CompositeRecordLoop extends DefaultRecordLoop {
-
- CompositeRecordSource recordSource = new CompositeRecordSource();
- CompositeRecordLoopAdapter adapter = new CompositeRecordLoopAdapter();
-
- boolean stopOnErrors = true;
-
- public CompositeRecordLoop() {
- setRecordSource(recordSource);
- addLoopListener(adapter);
- addRecordListener(adapter);
- }
-
- public void setStopOnErrors(boolean stopOnErrors) {
- this.stopOnErrors = stopOnErrors;
- }
-
- /**
- * Set the <code>RecordSource</code> which provides <code>CompositeRecord</code> objects.
- */
- public void setRecordSource(RecordSource source) {
- if (!source.getRecordClass().isAssignableFrom(CompositeRecord.class)) {
- throw new IllegalArgumentException("The RecordSource has the wrong class.");
- }
- super.setRecordSource(source);
- }
-
- /**
- * Add a <code>CompositeRecordProcessor</code> which will receive <code>CompositeRecord</code>
- * objects.
- * @param processor The <code>CompositeRecordProcessor</code> to add.
- */
- public void addProcessor(CompositeRecordProcessor processor) {
- adapter.addProcessor(processor);
- }
-
- protected void handleClientError(Throwable x) {
- System.out.println("CompositeRecordLoop.handleClientError");
- System.out.println(" error: " + x.getClass().getCanonicalName());
- System.out.println(" cause: " + x.getCause().getClass().getCanonicalName());
- System.out.println(" loop state: " + this.getState().toString());
- x.printStackTrace();
- if (isIgnorable(x)) {
- System.out.println(" error is ignored");
- return;
- }
- adapter.finish(null);
- this.execute(Command.STOP);
-
- // Rethrow so the loop caller can catch and handle this error.
- throw new RuntimeException("Error from client during event processing.", x);
- }
-
- protected void handleSourceError(Throwable x) {
- System.out.println("CompositeRecordLoop.handleSourceError");
- System.out.println("error: " + x.getClass().getCanonicalName());
- System.out.println("cause: " + x.getCause().getClass().getCanonicalName());
- x.printStackTrace();
- if (isIgnorable(x)) {
- System.out.println("error is ignored");
- return;
- }
- adapter.finish(null);
- this.execute(Command.STOP);
-
- // Rethrow so the loop caller can catch and handle this error.
- throw new RuntimeException("Error from record source during event processing.", x);
- }
-
- private boolean isIgnorable(Throwable x) {
- if (!stopOnErrors) {
- if ((x instanceof EventProcessingException)
- && !(x.getCause() instanceof EndRunException)
- && !(x.getCause() instanceof IllegalStateException))
- return true;
- } else {
- return false;
- }
- return false;
- }
-}
-
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeRecordLoopAdapter.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeRecordLoopAdapter.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,76 +0,0 @@
-package org.hps.record.composite;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.freehep.record.loop.AbstractLoopListener;
-import org.freehep.record.loop.LoopEvent;
-import org.freehep.record.loop.RecordEvent;
-import org.freehep.record.loop.RecordListener;
-import org.hps.record.EventProcessingException;
-
-/**
- * Adapter for listening on the {@link CompositeRecordLoop} for records and loop events.
- */
-public final class CompositeRecordLoopAdapter extends AbstractLoopListener implements RecordListener {
-
- List<CompositeRecordProcessor> processors = new ArrayList<CompositeRecordProcessor>();
-
- /**
- * Callback for loop finish event.
- * @param loopEvent
- */
- public void finish(LoopEvent loopEvent) {
- System.out.println("CompositeRecordLoopAdapter.finish");
- for (CompositeRecordProcessor processor : processors) {
- // Call end job hook on all registered processors, which are
- // responsible for sending the stop command to their loops.
- processor.endJob();
- }
- }
-
- /**
- * Add a <tt>CompositeRecordProcessor</tt> that will listen to this loop.
- * @param processor The composite record processor to add.
- */
- void addProcessor(CompositeRecordProcessor processor) {
- processors.add(processor);
- }
-
- /**
- * Start event processing which will call {@link CompositeRecordProcessor#startJob()}
- * on all the registered processors.
- * @param loopEvent
- */
- public void start(LoopEvent loopEvent) {
- for (CompositeRecordProcessor processor : processors) {
- processor.startJob();
- }
- }
-
- /**
- * Suspend the loop.
- * @param loopEvent
- */
- public void suspend(LoopEvent loopEvent) {
- System.out.println("CompositeRecordLoopAdapter.suspend");
- //if (loopEvent.getException() != null) {
- // throw new RuntimeException("Error in event processing.", loopEvent.getException());
- //}
- }
-
- /**
- * Process one record.
- * @param record
- */
- @Override
- public void recordSupplied(RecordEvent record) {
- for (CompositeRecordProcessor processor : processors) {
- try {
- processor.processEvent((CompositeRecord) record.getRecord());
- } catch (Exception e) {
- throw new EventProcessingException("Error processing CompositeRecord.", e);
- }
- }
- }
-}
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeRecordProcessor.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeRecordProcessor.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,30 +0,0 @@
-package org.hps.record.composite;
-
-import org.hps.record.EventProcessor;
-
-/**
- * An <code>EventProcessor</code> implementation for processing <code>CompositeRecord</code>
- * records.
- */
-public abstract class CompositeRecordProcessor implements EventProcessor<CompositeRecord> {
-
- @Override
- public void startJob() {
- }
-
- @Override
- public void startRun(CompositeRecord event) {
- }
-
- @Override
- public void processEvent(CompositeRecord event) throws Exception {
- }
-
- @Override
- public void endRun(CompositeRecord event) {
- }
-
- @Override
- public void endJob() {
- }
-}
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeRecordSource.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeRecordSource.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,67 +0,0 @@
-package org.hps.record.composite;
-
-import java.io.IOException;
-
-import org.freehep.record.source.AbstractRecordSource;
-import org.freehep.record.source.NoSuchRecordException;
-
-/**
- * A record source providing <code>CompositeRecord</code> objects.
- */
-public final class CompositeRecordSource extends AbstractRecordSource {
-
- CompositeRecord currentRecord;
- int sequenceNumber = 0;
-
- public void next() throws IOException, NoSuchRecordException {
- currentRecord = new CompositeRecord();
- currentRecord.setSequenceNumber(sequenceNumber);
- ++sequenceNumber;
- }
-
- @Override
- public Object getCurrentRecord() throws IOException {
- return currentRecord;
- }
-
- @Override
- public boolean supportsCurrent() {
- return true;
- }
-
- @Override
- public boolean supportsNext() {
- return true;
- }
-
- @Override
- public boolean supportsPrevious() {
- return false;
- }
-
- @Override
- public boolean supportsIndex() {
- return false;
- }
-
- @Override
- public boolean supportsShift() {
- return false;
- }
-
- @Override
- public boolean supportsRewind() {
- return false;
- }
-
- @Override
- public boolean hasCurrent() {
- return currentRecord != null;
- }
-
- @Override
- public boolean hasNext() {
- // FIXME: Not sure about this one.
- return true;
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/et
--- java/trunk/record-util/src/main/java/org/hps/record/etevent/EtConnection.java 2014-08-27 02:17:30 UTC (rev 915)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtConnection.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,4 +1,4 @@
-package org.hps.record.etevent;
+package org.hps.record.et;
import java.io.IOException;
@@ -74,34 +74,13 @@
* Cleanup the ET connection.
*/
public void cleanup() {
- boolean debug = false;
try {
if (!sys.alive()) {
throw new RuntimeException("EtSystem is not alive!");
}
- if (debug) {
- System.out.println("EtConnection cleanup ...");
- System.out.println("sys.detach ...");
- }
- //if (!att.isUsable()) {
- // throw new RuntimeException("EtAttachment is not usable!");
- //}
- // FIXME: This can hang forever when in getEvents() call!!!
sys.detach(att);
- if (debug) {
- System.out.println("sys.detach okay");
- System.out.println("sys.removeStation ...");
- }
sys.removeStation(stat);
- if (debug) {
- System.out.println("sys.removeStation okay");
- System.out.println("sys.close ...");
- }
sys.close();
- if (debug) {
- System.out.println("sys.close okay");
- System.out.println("EtConnection cleanup successful!");
- }
}
catch (Exception e) {
e.printStackTrace();
java/trunk/record-util/src/main/java/org/hps/record/et
--- java/trunk/record-util/src/main/java/org/hps/record/etevent/EtConnectionParameters.java 2014-08-27 02:17:30 UTC (rev 915)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtConnectionParameters.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,4 +1,4 @@
-package org.hps.record.etevent;
+package org.hps.record.et;
import java.net.InetAddress;
import java.net.UnknownHostException;
java/trunk/record-util/src/main/java/org/hps/record/et
--- java/trunk/record-util/src/main/java/org/hps/record/etevent/EtEventAdapter.java 2014-08-27 02:17:30 UTC (rev 915)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtEventAdapter.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,60 +0,0 @@
-package org.hps.record.etevent;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.freehep.record.loop.AbstractLoopListener;
-import org.freehep.record.loop.LoopEvent;
-import org.freehep.record.loop.RecordEvent;
-import org.freehep.record.loop.RecordListener;
-import org.jlab.coda.et.EtEvent;
-
-/**
- * Adapter for processing <tt>EtEvent</tt> objects using a loop.
- */
-public final class EtEventAdapter extends AbstractLoopListener implements RecordListener {
-
- List<EtEventProcessor> processors = new ArrayList<EtEventProcessor>();
-
- @Override
- public void recordSupplied(RecordEvent recordEvent) {
- Object object = recordEvent.getRecord();
- if (object instanceof EtEvent) {
- EtEvent event = (EtEvent)object;
- processEvent(event);
- }
- }
-
- // NOTE: This is called between every execution of the GO_N command!!!
- public void suspend(LoopEvent event) {
- if (event.getException() != null) {
- for (EtEventProcessor processor : processors) {
- processor.endJob();
- }
- }
- }
-
- @Override
- public void start(LoopEvent event) {
- for (EtEventProcessor processor : processors) {
- processor.startJob();
- }
- }
-
- @Override
- public void finish(LoopEvent event) {
- for (EtEventProcessor processor : processors) {
- processor.endJob();
- }
- }
-
- void addEtEventProcessor(EtEventProcessor processor) {
- processors.add(processor);
- }
-
- private void processEvent(EtEvent event) {
- for (EtEventProcessor processor : processors) {
- processor.processEvent(event);
- }
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/et
--- java/trunk/record-util/src/main/java/org/hps/record/etevent/EtEventLoop.java 2014-08-27 02:17:30 UTC (rev 915)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtEventLoop.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,49 +0,0 @@
-package org.hps.record.etevent;
-
-import org.freehep.record.loop.DefaultRecordLoop;
-import org.freehep.record.source.RecordSource;
-import org.jlab.coda.et.EtEvent;
-
-/**
- * Record loop implementation for processing <tt>EtEvent</tt> objects.
- */
-public final class EtEventLoop extends DefaultRecordLoop {
-
- EtEventAdapter adapter = new EtEventAdapter();
-
- public EtEventLoop() {
- addLoopListener(adapter);
- addRecordListener(adapter);
- }
-
- /**
- * Add an <code>EtEventProcessor</code> to the loop.
- * @param processor The <code>EtEventProcessor</code> to add.
- */
- public void addEtEventProcessor(EtEventProcessor processor) {
- adapter.addEtEventProcessor(processor);
- }
-
- /**
- * Set the <code>RecordSource</code> for the loop.
- * @param source The <code>RecordSource</code> for the loop.
- */
- public void setRecordSource(RecordSource source) {
- if (!source.getRecordClass().isAssignableFrom(EtEvent.class)) {
- throw new IllegalArgumentException("The RecordSource has the wrong class.");
- }
- super.setRecordSource(source);
- }
-
- protected void handleClientError(Throwable x) {
- if (x != null) {
- throw new RuntimeException(x);
- }
- }
-
- protected void handleSourceError(Throwable x) {
- if (x != null) {
- throw new RuntimeException(x);
- }
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/et
--- java/trunk/record-util/src/main/java/org/hps/record/etevent/EtEventProcessor.java 2014-08-27 02:17:30 UTC (rev 915)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtEventProcessor.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,42 +0,0 @@
-package org.hps.record.etevent;
-
-import org.hps.record.EventProcessor;
-import org.jlab.coda.et.EtEvent;
-
-/**
- * This is the basic abstract class that processors of
- * <tt>EtEvent</tt> objects should implement.
- */
-public abstract class EtEventProcessor implements EventProcessor<EtEvent> {
-
- /**
- * Start of ET session.
- */
- @Override
- public void startJob() {
- }
-
- @Override
- public void startRun(EtEvent event) {
-
- }
-
- /**
- * Process one <tt>EtEvent</tt>.
- */
- @Override
- public void processEvent(EtEvent event) {
- }
-
- @Override
- public void endRun(EtEvent event) {
-
- }
-
- /**
- * End of ET session.
- */
- @Override
- public void endJob() {
- }
-}
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/et
--- java/trunk/record-util/src/main/java/org/hps/record/etevent/EtEventQueue.java 2014-08-27 02:17:30 UTC (rev 915)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtEventQueue.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,17 +0,0 @@
-package org.hps.record.etevent;
-
-import org.hps.record.AbstractRecordQueue;
-import org.jlab.coda.et.EtEvent;
-
-/**
- * A dynamic queue for supplying <tt>EtEvent</tt> objects to a loop.
- * This would most likely be run on a separate thread than the
- * loop to avoid undesired blocking behavior.
- */
-public final class EtEventQueue extends AbstractRecordQueue<EtEvent> {
-
- @Override
- public Class<EtEvent> getRecordClass() {
- return EtEvent.class;
- }
-}
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/et
--- java/trunk/record-util/src/main/java/org/hps/record/etevent/EtEventSource.java 2014-08-27 02:17:30 UTC (rev 915)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtEventSource.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,100 +0,0 @@
-package org.hps.record.etevent;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Queue;
-import java.util.concurrent.LinkedBlockingQueue;
-
-import org.freehep.record.source.AbstractRecordSource;
-import org.freehep.record.source.NoSuchRecordException;
-import org.jlab.coda.et.EtEvent;
-
-/**
- * Implement a loop record source supplying <tt>EtEvent</tt> objects
- * from an ET ring server connection.
- */
-public final class EtEventSource extends AbstractRecordSource {
-
- EtConnection connection;
- EtEvent currentRecord;
- Queue<EtEvent> eventQueue = new LinkedBlockingQueue<EtEvent>();
-
- public EtEventSource(EtConnection connection) {
- this.connection = connection;
- }
-
- @Override
- public Object getCurrentRecord() throws IOException {
- return currentRecord;
- }
-
- @Override
- public boolean supportsCurrent() {
- return true;
- }
-
- @Override
- public boolean supportsNext() {
- return true;
- }
-
- @Override
- public boolean supportsPrevious() {
- return false;
- }
-
- @Override
- public boolean supportsIndex() {
- return false;
- }
-
- @Override
- public boolean supportsShift() {
- return false;
- }
-
- @Override
- public boolean supportsRewind() {
- return false;
- }
-
- @Override
- public boolean hasCurrent() {
- return currentRecord != null;
- }
-
- @Override
- public boolean hasNext() {
- return true;
- }
-
- @Override
- public void next() throws IOException, NoSuchRecordException {
-
- // Fill the queue if there are no events cached.
- if (eventQueue.size() == 0) {
- readEtEvents();
- }
-
- // Poll the queue.
- currentRecord = eventQueue.poll();
-
- if (currentRecord == null) {
- throw new NoSuchRecordException("No records in queue.");
- }
- }
-
- @Override
- public long size() {
- return this.eventQueue.size();
- }
-
- void readEtEvents() throws IOException {
- try {
- EtEvent[] mevs = connection.readEtEvents();
- eventQueue.addAll(Arrays.asList(mevs));
- } catch (Exception e) {
- throw new IOException("Error while reading ET events.", e);
- }
- }
-}
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/evio
--- java/trunk/record-util/src/main/java/org/hps/record/evio/EndRunProcessor.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/EndRunProcessor.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,25 +0,0 @@
-package org.hps.record.evio;
-
-import org.hps.evio.EventConstants;
-import org.hps.record.EndRunException;
-import org.hps.record.composite.CompositeRecord;
-import org.hps.record.composite.CompositeRecordProcessor;
-
-/**
- * This is a CompositeRecordProcessor for ending the run when an EVIO
- * end event is received. It should be placed last in the chain of
- * processors so that all the other registered processors are executed
- * beforehand because it throws an Exception.
- */
-public class EndRunProcessor extends CompositeRecordProcessor {
-
- @Override
- public void processEvent(CompositeRecord event) throws EndRunException {
- if (event.getEvioEvent() != null)
- if (EventConstants.isEndEvent(event.getEvioEvent()))
- throw new EndRunException(
- "EVIO end run event received.",
- event.getEvioEvent().getIntData()[1]); // FIXME: Is this right?
-
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/evio
--- java/trunk/record-util/src/main/java/org/hps/record/evio/EvioAdapter.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/EvioAdapter.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -15,8 +15,12 @@
*/
public final class EvioAdapter extends AbstractLoopListener implements RecordListener {
- List<EvioEventProcessor> processors = new ArrayList<EvioEventProcessor>();
+ List<EvioProcessor> processors = new ArrayList<EvioProcessor>();
+ void addEvioEventProcessor(EvioProcessor processor) {
+ processors.add(processor);
+ }
+
@Override
public void recordSupplied(RecordEvent recordEvent) {
Object object = recordEvent.getRecord();
@@ -37,50 +41,42 @@
@Override
public void start(LoopEvent event) {
- for (EvioEventProcessor processor : processors) {
+ for (EvioProcessor processor : processors) {
processor.startJob();
}
}
@Override
public void finish(LoopEvent event) {
- //System.out.println("EvioAdapter.finish");
- for (EvioEventProcessor processor : processors) {
- //System.out.println(processor.getClass().getCanonicalName() + ".endJob");
+ for (EvioProcessor processor : processors) {
processor.endJob();
}
}
- // NOTE: This is called between every execution of the GO_N command!!!
+ @Override
public void suspend(LoopEvent event) {
- //System.out.println("EvioAdapter.suspend");
+ System.out.println("EvioAdapter.suspend");
if (event.getException() != null) {
- //System.out.println("current error: " + event.getException().getMessage());
- //System.out.println("ending job from suspend");
- for (EvioEventProcessor processor : processors) {
+ for (EvioProcessor processor : processors) {
processor.endJob();
}
}
}
-
- void addEvioEventProcessor(EvioEventProcessor processor) {
- processors.add(processor);
- }
-
+
private void processEvent(EvioEvent event) {
- for (EvioEventProcessor processor : processors) {
- processor.processEvent(event);
+ for (EvioProcessor processor : processors) {
+ processor.process(event);
}
}
private void startRun(EvioEvent event) {
- for (EvioEventProcessor processor : processors) {
+ for (EvioProcessor processor : processors) {
processor.startRun(event);
}
}
private void endRun(EvioEvent event) {
- for (EvioEventProcessor processor : processors) {
+ for (EvioProcessor processor : processors) {
processor.endRun(event);
}
}
java/trunk/record-util/src/main/java/org/hps/record/evio
--- java/trunk/record-util/src/main/java/org/hps/record/evio/EvioEventLoop.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/EvioEventLoop.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,60 +0,0 @@
-package org.hps.record.evio;
-
-import java.io.IOException;
-
-import org.freehep.record.loop.DefaultRecordLoop;
-import org.freehep.record.source.RecordSource;
-import org.jlab.coda.jevio.EvioEvent;
-
-/**
- * Implementation of record loop for processing <tt>EvioEvent</tt> objects.
- */
-public final class EvioEventLoop extends DefaultRecordLoop {
-
- EvioAdapter adapter = new EvioAdapter();
-
- public EvioEventLoop() {
- addLoopListener(adapter);
- addRecordListener(adapter);
- }
-
- public void addEvioEventProcessor(EvioEventProcessor processor) {
- adapter.addEvioEventProcessor(processor);
- }
-
- @Override
- public void setRecordSource(RecordSource source) {
- if (!source.getRecordClass().isAssignableFrom(EvioEvent.class)) {
- System.err.println("The class " + source.getRecordClass().getCanonicalName() + " is invalid.");
- throw new IllegalArgumentException("The record class is invalid.");
- }
- super.setRecordSource(source);
- }
-
- public long loop(long number) throws IOException {
- if (number < 0L) {
- execute(Command.GO, true);
- } else {
- execute(Command.GO_N, number, true);
- execute(Command.STOP);
- }
- Throwable t = getProgress().getException();
- if (t != null && t instanceof IOException)
- throw (IOException) t;
- return getSupplied();
- }
-
- protected void handleClientError(Throwable x) {
- if (x != null) {
- x.printStackTrace();
- throw new RuntimeException(x);
- }
- }
-
- protected void handleSourceError(Throwable x) {
- if (x != null) {
- x.printStackTrace();
- throw new RuntimeException(x);
- }
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/evio
--- java/trunk/record-util/src/main/java/org/hps/record/evio/EvioEventProcessor.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/EvioEventProcessor.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,31 +0,0 @@
-package org.hps.record.evio;
-
-import org.hps.record.EventProcessor;
-import org.jlab.coda.jevio.EvioEvent;
-
-/**
- * This is the basic abstract class that processors of
- * <tt>EvioEvent</tt> objects should implement.
- */
-public abstract class EvioEventProcessor implements EventProcessor<EvioEvent> {
-
- @Override
- public void startJob() {
- }
-
- @Override
- public void startRun(EvioEvent event) {
- }
-
- @Override
- public void processEvent(EvioEvent event) {
- }
-
- @Override
- public void endRun(EvioEvent event) {
- }
-
- @Override
- public void endJob() {
- }
-}
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/evio
--- java/trunk/record-util/src/main/java/org/hps/record/evio/EvioEventQueue.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/EvioEventQueue.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,15 +0,0 @@
-package org.hps.record.evio;
-
-import org.hps.record.AbstractRecordQueue;
-import org.jlab.coda.jevio.EvioEvent;
-
-/**
- * A dynamic queue providing <tt>EvioEvent</tt> objects to a loop.
- */
-public final class EvioEventQueue extends AbstractRecordQueue<EvioEvent> {
-
- @Override
- public Class<EvioEvent> getRecordClass() {
- return EvioEvent.class;
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/lcio
--- java/trunk/record-util/src/main/java/org/hps/record/lcio/LcioEventQueue.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/lcio/LcioEventQueue.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,15 +0,0 @@
-package org.hps.record.lcio;
-
-import org.hps.record.AbstractRecordQueue;
-import org.lcsim.event.EventHeader;
-
-/**
- * A dynamic queue providing <tt>EvioEvent</tt> objects to a loop.
- */
-public final class LcioEventQueue extends AbstractRecordQueue<EventHeader> {
-
- @Override
- public Class<EventHeader> getRecordClass() {
- return EventHeader.class;
- }
-}
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/lcio
--- java/trunk/record-util/src/main/java/org/hps/record/lcio/LcioLoop.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/main/java/org/hps/record/lcio/LcioLoop.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,30 +1,36 @@
package org.hps.record.lcio;
+import org.hps.record.ErrorState;
+import org.hps.record.HasErrorState;
import org.lcsim.util.loop.LCSimLoop;
/**
* This class overrides the error handling of <code>LCSimLoop</code>
- * so it does not exit the application when errors occur.
+ * so it does not exit the application when errors occur. It also
+ * adds basic error handling so the caller can determine if an error
+ * occurred without exceptions being thrown.
*/
-public final class LcioLoop extends LCSimLoop {
+public final class LcioLoop extends LCSimLoop implements HasErrorState {
+ ErrorState errorState = new ErrorState();
+
+ public ErrorState getErrorState() {
+ return errorState;
+ }
+
+ /**
+ * Handle errors from the Drivers.
+ */
protected void handleClientError(Throwable x) {
- System.out.println("LcioLoop.handleClientError");
- System.out.println(" initial loop state: " + this.getState().toString());
- if (x != null) {
- this.execute(Command.STOP);
- System.out.println(" loop state after stop: " + this.getState().toString());
- throw new RuntimeException(x);
- }
+ getErrorState().setLastError((Exception) x);
+ getErrorState().print();
}
+ /**
+ * Handle errors from the RecordSource.
+ */
protected void handleSourceError(Throwable x) {
- System.out.println("LcioLoop.handleSourceError");
- System.out.println(" initial loop state: " + this.getState().toString());
- if (x != null) {
- this.execute(Command.STOP);
- System.out.println(" loop state after stop: " + this.getState().toString());
- throw new RuntimeException(x);
- }
+ getErrorState().setLastError((Exception) x);
+ getErrorState().print();
}
}
java/trunk/record-util/src/main/java/org/hps/record/processing
--- java/trunk/record-util/src/main/java/org/hps/record/chain/EtProcessingStep.java 2014-08-28 20:22:29 UTC (rev 920)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/EtProcessingStep.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,26 +1,26 @@
-package org.hps.record.chain;
+package org.hps.record.processing;
import static org.freehep.record.loop.RecordLoop.Command.NEXT;
import org.freehep.record.loop.RecordLoop.Command;
import org.freehep.record.source.NoSuchRecordException;
import org.hps.record.composite.CompositeRecord;
-import org.hps.record.composite.CompositeRecordProcessor;
-import org.hps.record.etevent.EtEventLoop;
+import org.hps.record.composite.CompositeProcessor;
+import org.hps.record.et.EtLoop;
import org.jlab.coda.et.EtEvent;
/**
* ET processing step to load an <tt>EtEvent</tt> from the ET ring
- * using a {@link org.hps.monitoring.record.etevent.EtEventLoop}.
+ * using a {@link org.hps.EtLoop.record.etevent.EtEventLoop}.
*/
-class EtProcessingStep extends CompositeRecordProcessor {
+class EtProcessingStep extends CompositeProcessor {
- EtEventLoop loop = new EtEventLoop();
+ EtLoop loop = new EtLoop();
EtProcessingStep() {
}
- EtEventLoop getLoop() {
+ EtLoop getLoop() {
return loop;
}
@@ -29,11 +29,16 @@
throw new RuntimeException();
}
- public void processEvent(CompositeRecord record) throws Exception {
+ public void process(CompositeRecord record) throws Exception {
// Load the next EtEvent, which calls getEvents() on the ET connection
// and feeds records to any loop listeners like status monitors.
loop.execute(NEXT);
+
+ // Did an error occur while getting ET events from the network?
+ if (loop.getErrorState().hasError())
+ // Rethrow the error.
+ loop.getErrorState().rethrow();
// Get the current EtEvent from the loop, which should have been cached.
EtEvent nextEtEvent = (EtEvent) loop.getRecordSource().getCurrentRecord();
@@ -47,7 +52,6 @@
}
public void endJob() {
- System.out.println("EtProcessingStep.endJob");
loop.execute(Command.STOP);
}
}
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/processing
--- java/trunk/record-util/src/main/java/org/hps/record/chain/EventProcessingChain.java 2014-08-28 20:22:29 UTC (rev 920)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/EventProcessingChain.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,270 +0,0 @@
-package org.hps.record.chain;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.freehep.record.loop.AbstractLoopListener;
-import org.freehep.record.loop.LoopEvent;
-import org.freehep.record.loop.LoopListener;
-import org.freehep.record.loop.RecordLoop;
-import org.freehep.record.loop.RecordLoop.Command;
-import org.hps.record.DataSourceType;
-import org.hps.record.composite.CompositeRecordLoop;
-import org.hps.record.composite.CompositeRecordLoopAdapter;
-import org.hps.record.composite.CompositeRecordProcessor;
-import org.hps.record.etevent.EtEventProcessor;
-import org.hps.record.etevent.EtEventSource;
-import org.hps.record.evio.EndRunProcessor;
-import org.hps.record.evio.EvioEventProcessor;
-import org.hps.record.evio.EvioEventQueue;
-import org.hps.record.evio.EvioFileSource;
-import org.hps.record.lcio.LcioEventQueue;
-import org.lcsim.util.Driver;
-import org.lcsim.util.loop.LCIOEventSource;
-
-/**
- * This class provides a serial implementation of the event processing chain
- * for the monitoring app. Implementations of FreeHep's <tt>RecordLoop</tt>
- * are chained together via a <tt>CompositeRecordLoop</tt>. The processing for
- * each record type is done by activating registered processors on their
- * individual loop implementations. Essentially, the class is a facade that
- * hides the complexity of configuring all the different record loops.
- *
- * The processing chain can be configured to execute the ET, EVIO event building,
- * or LCIO event building stages. The source can be set to an ET ring,
- * EVIO file source, or LCIO file source. Any number of event processors
- * can be registered with the three different loops for processing the different
- * record types, in order to plot, update a GUI component, or analyze the events.
- */
-public class EventProcessingChain extends AbstractLoopListener {
-
- /**
- * Processing stages to execute.
- */
- public enum ProcessingStage {
- ET,
- EVIO,
- LCIO
- }
-
- protected int totalEventsProcessed;
- protected Throwable lastError;
- protected boolean done;
- protected boolean paused;
-
- protected EtProcessingStep etStep = new EtProcessingStep();
- protected EvioProcessingStep evioStep = new EvioProcessingStep();
- protected LcioProcessingStep lcioStep = new LcioProcessingStep();
- protected CompositeRecordLoop compositeLoop = new CompositeRecordLoop();
-
- /**
- * A configuration object must be supplied to use this class.
- * @param configuration The configuration of the event processing.
- */
- public EventProcessingChain(EventProcessingConfiguration configuration) {
- configure(configuration);
- }
-
- private void configure(EventProcessingConfiguration configuration) {
-
- // Add this class as a loop listener.
- compositeLoop.addLoopListener(this);
-
- // Was there no RecordSource provided explicitly?
- if (configuration.recordSource == null) {
- // Using an ET server connection?
- if (configuration.sourceType.equals(DataSourceType.ET_SERVER)) {
- if (configuration.connection != null)
- etStep.getLoop().setRecordSource(new EtEventSource(configuration.connection));
- else
- throw new IllegalArgumentException("Configuration is missing a valid ET connection.");
- // Using an EVIO file?
- } else if (configuration.sourceType.equals(DataSourceType.EVIO_FILE)) {
- if (configuration.filePath != null)
- evioStep.getLoop().setRecordSource(new EvioFileSource(new File(configuration.filePath)));
- else
- throw new IllegalArgumentException("Configuration is missing a file path.");
- // Using an LCIO file?
- } else if (configuration.sourceType.equals(DataSourceType.LCIO_FILE)) {
- if (configuration.filePath != null)
- try {
- lcioStep.getLoop().setLCIORecordSource(new LCIOEventSource(new File(configuration.filePath)));
- } catch (IOException e) {
- throw new RuntimeException("Error configuring LCIOEventSource.", e);
- }
- else
- throw new IllegalArgumentException("Configuration is missing a file path.");
- }
- } else {
- // User provided an EtEventSource?
- if (configuration.recordSource instanceof EtEventSource) {
- etStep.getLoop().setRecordSource((EtEventSource) configuration.recordSource);
- // User provided an EvioFileSource?
- } else if (configuration.recordSource instanceof EvioFileSource) {
- evioStep.getLoop().setRecordSource((EvioFileSource) configuration.recordSource);
- // User provided an LCIOEventSource?
- } else if (configuration.recordSource instanceof LCIOEventSource) {
- try {
- lcioStep.getLoop().setLCIORecordSource((LCIOEventSource)configuration.recordSource);
- } catch (IOException e) {
- throw new RuntimeException("Error setting up LCIORecordSource.", e);
- }
- } else {
- throw new IllegalArgumentException("Unknown RecordSource type was supplied.");
- }
- }
-
- // Using the ET server for events?
- if (configuration.sourceType == DataSourceType.ET_SERVER) {
- // Add the ET event processing step.
- compositeLoop.addProcessor(etStep);
- }
-
- // Building EVIO events?
- if (configuration.processingStage.ordinal() >= ProcessingStage.EVIO.ordinal()) {
- // Using EVIO event source?
- if (configuration.sourceType.ordinal() <= DataSourceType.EVIO_FILE.ordinal()) {
- // Using ET event source?
- if (configuration.sourceType == DataSourceType.ET_SERVER) {
- // Use dynamic event queue.
- evioStep.setEvioEventQueue(new EvioEventQueue());
- }
- // Add EVIO processing step.
- compositeLoop.addProcessor(evioStep);
- }
- }
-
- // Building LCIO events?
- if (configuration.processingStage.ordinal() >= ProcessingStage.LCIO.ordinal()) {
- // Set detector on event builder.
- if (configuration.eventBuilder != null)
- configuration.eventBuilder.setDetectorName(configuration.detectorName);
- else
- throw new IllegalArgumentException("The eventBuilder was not set in the configuration.");
-
- if (configuration.sourceType.ordinal() != DataSourceType.LCIO_FILE.ordinal()) {
- // Use dynamic event queue.
- lcioStep.setLcioEventQueue(new LcioEventQueue());
- }
- // Set event builder.
- lcioStep.setEventBuilder(configuration.eventBuilder);
-
- // Add LCIO processing step.
- compositeLoop.addProcessor(lcioStep);
- }
-
- // Set whether to stop on event processing errors.
- compositeLoop.setStopOnErrors(configuration.stopOnErrors);
-
- // Add EtEventProcessors to loop.
- for (EtEventProcessor processor : configuration.etProcessors) {
- etStep.getLoop().addEtEventProcessor(processor);
- }
-
- // Add EvioEventProcessors to loop.
- for (EvioEventProcessor processor : configuration.evioProcessors) {
- evioStep.getLoop().addEvioEventProcessor(processor);
- }
-
- // Add Drivers to loop.
- for (Driver driver : configuration.drivers) {
- lcioStep.getLoop().add(driver);
- }
-
- // Add CompositeRecordProcessors to loop.
- for (CompositeRecordProcessor processor : configuration.compositeProcessors) {
- compositeLoop.addProcessor(processor);
- }
-
- // Stop on end run?
- if (configuration.stopOnEndRun) {
- // Add the CompositeRecordProcessor that will throw the EndRunException.
- compositeLoop.addProcessor(new EndRunProcessor());
- }
- }
-
- /**
- * Resume event processing from pause mode.
- */
- public void resume() {
- this.paused = false;
- }
-
- /**
- * Suspend event processing e.g. when pausing.
- * @param loopEvent The loop event.
- */
- public void suspend(LoopEvent loopEvent) {
- if (loopEvent.getException() != null) {
- loopEvent.getException().printStackTrace();
- lastError = (Exception) loopEvent.getException();
- }
- }
-
- /**
- * Loop over events until processing ends for some reason.
- */
- public void run() {
- // Keep looping until the event processing is flagged as done.
- while (true) {
- // Is the processing unpaused?
- if (!paused) {
- try {
- // Put the RecordLoop into looping mode and process records until exception occurs.
- System.out.println("loop state: " + compositeLoop.getState().toString());
- compositeLoop.execute(Command.GO, true);
- } catch (Exception exception) {
- // Handle an "error" which might really just be control flow ("end of run" etc.).
- setLastError(exception);
- done = true;
- }
- if (done)
- break;
- }
- }
- }
-
- public void stop() {
- compositeLoop.execute(Command.STOP);
- done = true;
- }
-
- /**
- * Set the last error that occurred during processing.
- * @param error The last error that occurred.
- */
- void setLastError(Throwable error) {
- this.lastError = error;
- }
-
- /**
- * Get the last error that occurred.
- * @return The last error that occurred.
- */
- public Throwable getLastError() {
- return lastError;
- }
-
- /**
- * Pause the event processing.
- */
- public void pause() {
- compositeLoop.execute(Command.PAUSE);
- paused = true;
- }
-
- /**
- * Get the next event e.g. while in pause mode.
- */
- public void next() {
- compositeLoop.execute(Command.GO_N, 1L, true);
- }
-
- /**
- * Get the total number of events processed.
- * @return The number of events processed.
- */
- public int getTotalEventsProcessed() {
- return this.totalEventsProcessed;
- }
-}
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/processing
--- java/trunk/record-util/src/main/java/org/hps/record/chain/EventProcessingConfiguration.java 2014-08-28 20:22:29 UTC (rev 920)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/EventProcessingConfiguration.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,92 +0,0 @@
-package org.hps.record.chain;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.freehep.record.source.RecordSource;
-import org.hps.evio.LCSimEventBuilder;
-import org.hps.record.DataSourceType;
-import org.hps.record.chain.EventProcessingChain.ProcessingStage;
-import org.hps.record.composite.CompositeRecordProcessor;
-import org.hps.record.etevent.EtConnection;
-import org.hps.record.etevent.EtEventProcessor;
-import org.hps.record.evio.EvioEventProcessor;
-import org.lcsim.util.Driver;
-
-/**
- * A configuration object for the {@link EventProcessingChain}.
- * The instance variables are readable within this package, but
- * must be set through the public set methods when used
- * outside of it, e.g. from MonitoringApplication.
- */
-public class EventProcessingConfiguration {
-
- boolean stopOnErrors = true;
- boolean stopOnEndRun = true;
-
- DataSourceType sourceType = DataSourceType.ET_SERVER;
- ProcessingStage processingStage = ProcessingStage.LCIO;
-
- String filePath = null;
- EtConnection connection = null;
- RecordSource recordSource = null;
- LCSimEventBuilder eventBuilder = null;
- String detectorName = null;
-
- List<EvioEventProcessor> evioProcessors = new ArrayList<EvioEventProcessor>();
- List<Driver> drivers = new ArrayList<Driver>();
- List<CompositeRecordProcessor> compositeProcessors = new ArrayList<CompositeRecordProcessor>();
- List<EtEventProcessor> etProcessors = new ArrayList<EtEventProcessor>();
-
- public void setFilePath(String filePath) {
- this.filePath = filePath;
- }
-
- public void setEtConnection(EtConnection connection) {
- this.connection = connection;
- }
-
- public void setDataSourceType(DataSourceType sourceType) {
- this.sourceType = sourceType;
- }
-
- public void setProcessingStage(ProcessingStage processingStage) {
- this.processingStage = processingStage;
- }
-
- public void setRecordSource(RecordSource recordSource) {
- this.recordSource = recordSource;
- }
-
- public void setLCSimEventBuild(LCSimEventBuilder eventBuilder) {
- this.eventBuilder = eventBuilder;
- }
-
- public void setDetectorName(String detectorName) {
- this.detectorName = detectorName;
- }
-
- public void setStopOnErrors(boolean stopOnErrors) {
- this.stopOnErrors = stopOnErrors;
- }
-
- public void setStopOnEndRun(boolean stopOnEndRun) {
- this.stopOnEndRun = stopOnEndRun;
- }
-
- public void add(EtEventProcessor processor) {
- etProcessors.add(processor);
- }
-
- public void add(EvioEventProcessor processor) {
- evioProcessors.add(processor);
- }
-
- public void add(Driver processor) {
- drivers.add(processor);
- }
-
- public void add(CompositeRecordProcessor processor) {
- compositeProcessors.add(processor);
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/processing
--- java/trunk/record-util/src/main/java/org/hps/record/chain/EventProcessingThread.java 2014-08-28 20:22:29 UTC (rev 920)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/EventProcessingThread.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,27 +0,0 @@
-package org.hps.record.chain;
-
-/**
- * Thread for running the event processing chain.
- */
-public final class EventProcessingThread extends Thread {
-
- EventProcessingChain processing;
-
- public EventProcessingThread(EventProcessingChain processing) {
- super("EventProcessingThread");
- this.processing = processing;
- }
-
- public EventProcessingChain getEventProcessingChain() {
- return processing;
- }
-
- @Override
- public void run() {
- try {
- processing.run();
- } catch (Exception e) {
- throw new RuntimeException("Error in event processing.", e);
- }
- }
-}
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/processing
--- java/trunk/record-util/src/main/java/org/hps/record/chain/EvioProcessingStep.java 2014-08-28 20:22:29 UTC (rev 920)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/EvioProcessingStep.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,4 +1,4 @@
-package org.hps.record.chain;
+package org.hps.record.processing;
import static org.freehep.record.loop.RecordLoop.Command.NEXT;
@@ -8,11 +8,10 @@
import org.freehep.record.loop.RecordLoop.Command;
import org.freehep.record.source.NoSuchRecordException;
import org.hps.evio.EventConstants;
-import org.hps.record.DataSourceType;
import org.hps.record.composite.CompositeRecord;
-import org.hps.record.composite.CompositeRecordProcessor;
-import org.hps.record.evio.EvioEventLoop;
-import org.hps.record.evio.EvioEventQueue;
+import org.hps.record.composite.CompositeProcessor;
+import org.hps.record.evio.EvioLoop;
+import org.hps.record.evio.EvioRecordQueue;
import org.jlab.coda.et.EtEvent;
import org.jlab.coda.jevio.BaseStructure;
import org.jlab.coda.jevio.EvioEvent;
@@ -23,18 +22,18 @@
* EVIO processing step to build an <tt>EvioEvent</tt> from the <tt>EtEvent</tt>
* or load the next <tt>EvioEvent</tt> from a file, if using an EVIO file source.
*/
-class EvioProcessingStep extends CompositeRecordProcessor {
+class EvioProcessingStep extends CompositeProcessor {
- EvioEventLoop loop = new EvioEventLoop();
+ EvioLoop loop = new EvioLoop();
DataSourceType sourceType;
- EvioEventQueue evioEventQueue;
+ EvioRecordQueue evioEventQueue;
boolean stopOnEndRun;
/**
* Get the <tt>EvioEventLoop</tt> associated with this processing step.
* @return The <tt>EvioEventLoop</tt> associated with this processing step.
*/
- EvioEventLoop getLoop() {
+ EvioLoop getLoop() {
return loop;
}
@@ -42,7 +41,7 @@
* Set the EVIO event queue.
* @param evioEventQueue The EVIO event queue.
*/
- void setEvioEventQueue(EvioEventQueue evioEventQueue) {
+ void setEvioEventQueue(EvioRecordQueue evioEventQueue) {
this.evioEventQueue = evioEventQueue;
loop.setRecordSource(this.evioEventQueue);
}
@@ -58,7 +57,7 @@
* Set the <tt>EvioEventLoop</tt> for this processing step.
* @param loop The <tt>EvioEventLoop</tt> for this processing step.
*/
- void setEvioEventLoop(EvioEventLoop loop) {
+ void setEvioEventLoop(EvioLoop loop) {
this.loop = loop;
}
@@ -74,7 +73,7 @@
* Load the next <tt>EvioEvent</tt>, either from a record source
* or from the <tt>EtEvent</tt> data.
*/
- public void processEvent(CompositeRecord record) throws Exception {
+ public void process(CompositeRecord record) throws Exception {
if (evioEventQueue != null) {
EvioEvent evioEvent = null;
@@ -92,7 +91,10 @@
}
// Process one EvioEvent.
- loop.execute(NEXT);
+ loop.execute(NEXT);
+ if (loop.getErrorState().hasError())
+ loop.getErrorState().rethrow();
+
EvioEvent nextEvioEvent = (EvioEvent) loop.getRecordSource().getCurrentRecord();
// The call to loop did not create a current record.
java/trunk/record-util/src/main/java/org/hps/record/processing
--- java/trunk/record-util/src/main/java/org/hps/record/chain/LcioProcessingStep.java 2014-08-28 20:22:29 UTC (rev 920)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/LcioProcessingStep.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,4 +1,4 @@
-package org.hps.record.chain;
+package org.hps.record.processing;
import static org.freehep.record.loop.RecordLoop.Command.NEXT;
@@ -7,8 +7,8 @@
import org.freehep.record.source.NoSuchRecordException;
import org.hps.evio.LCSimEventBuilder;
import org.hps.record.composite.CompositeRecord;
-import org.hps.record.composite.CompositeRecordProcessor;
-import org.hps.record.lcio.LcioEventQueue;
+import org.hps.record.composite.CompositeProcessor;
+import org.hps.record.lcio.LcioRecordQueue;
import org.hps.record.lcio.LcioLoop;
import org.jlab.coda.jevio.EvioEvent;
import org.lcsim.event.EventHeader;
@@ -18,11 +18,11 @@
* Processing step for building LCIO events from EVIO
* or reading them directly from an input event file.
*/
-class LcioProcessingStep extends CompositeRecordProcessor {
+class LcioProcessingStep extends CompositeProcessor {
LcioLoop loop = new LcioLoop();
LCSimEventBuilder builder;
- LcioEventQueue lcioEventQueue;
+ LcioRecordQueue lcioEventQueue;
/**
* Get the <code>LcioLoop</code> associated with this processing step.
@@ -45,7 +45,7 @@
* is no direct LCIO record source from a file.
* @param lcioEventQueue The <code>LcioEventQueue</code> to be used as a record source.
*/
- void setLcioEventQueue(LcioEventQueue lcioEventQueue) {
+ void setLcioEventQueue(LcioRecordQueue lcioEventQueue) {
this.lcioEventQueue = lcioEventQueue;
loop.setRecordSource(lcioEventQueue);
}
@@ -62,7 +62,7 @@
* Process a <code>CompositeRecord</code> event by creating an LCIO event
* and adding it to the record.
*/
- public void processEvent(CompositeRecord record) throws Exception {
+ public void process(CompositeRecord record) throws Exception {
// When the loop does not have a direct LCIO file source,
// the events need to be built from the EVIO input.
@@ -93,10 +93,12 @@
throw new NoSuchRecordException("No next LCIO event.");
// Load the next LCIO event, triggering Driver process methods.
- //System.out.println("LcioProcessingStep loop state: " + loop.getState().toString());
- if (!loop.getState().equals(RecordLoop.State.READY) && !loop.getState().equals(RecordLoop.State.IDLE))
- System.out.println("LcioProcessingStep bad loop state: " + loop.getState().toString());
loop.execute(NEXT);
+
+ // Did an error occur?
+ if (loop.getErrorState().hasError())
+ // Rethrow any record processing errors that occurred so the top-level loop can handle properly.
+ loop.getErrorState().rethrow();
// Is there a current record?
if (loop.getRecordSource().getCurrentRecord() == null) {
java/trunk/record-util/src/main/java/org/hps/record/processing
--- java/trunk/record-util/src/main/java/org/hps/record/processing/MaxRecordsProcessor.java (rev 0)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/MaxRecordsProcessor.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -0,0 +1,28 @@
+package org.hps.record.processing;
+
+import org.hps.record.MaxRecordsException;
+import org.hps.record.RecordProcessingException;
+import org.hps.record.composite.CompositeProcessor;
+import org.hps.record.composite.CompositeRecord;
+
+/**
+ * A @{link CompositeProcessor} for throwing an error when the
+ * maximum number of records is reached or exceeded.
+ */
+public class MaxRecordsProcessor extends CompositeProcessor {
+
+ int maxRecords;
+ int recordsReceived;
+
+ public MaxRecordsProcessor(int maxRecords) {
+ this.maxRecords = maxRecords;
+ }
+
+ public void process(CompositeRecord record) {
+ if (recordsReceived >= maxRecords)
+ throw new RecordProcessingException(
+ "Maximum number of records received.",
+ new MaxRecordsException("Maximum number of records received.", maxRecords));
+ ++recordsReceived;
+ }
+}
java/trunk/record-util/src/main/java/org/hps/record/processing
--- java/trunk/record-util/src/main/java/org/hps/record/processing/ProcessingStage.java (rev 0)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/ProcessingStage.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -0,0 +1,10 @@
+package org.hps.record.processing;
+
+/**
+* Processing stages to execute.
+*/
+public enum ProcessingStage {
+ ET,
+ EVIO,
+ LCIO
+}
\ No newline at end of file
java/trunk/record-util/src/test/java/org/hps/record/et
--- java/trunk/record-util/src/test/java/org/hps/record/etevent/EtEventLoopTest.java 2014-08-27 02:17:30 UTC (rev 915)
+++ java/trunk/record-util/src/test/java/org/hps/record/et/EtEventLoopTest.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,39 +0,0 @@
-package org.hps.record.etevent;
-
-import org.freehep.record.loop.RecordLoop.Command;
-import org.jlab.coda.et.EtEvent;
-import org.jlab.coda.et.EtEventImpl;
-
-/**
- * Test that the {@link EtEventLoop} works.
- * @author Jeremy McCormick <[log in to unmask]>
- */
-public class EtEventLoopTest {
-
- public void testEtEventLoop() {
-
- EtEventLoop loop = new EtEventLoop();
- loop.addEtEventProcessor(new DummyEtEventProcessor());
- EtEventQueue queue = new EtEventQueue();
- queue.setTimeOutMillis(10000);
- loop.setRecordSource(queue);
-
- for (int i=0; i<100000; i++) {
- EtEvent event = new EtEventImpl(1000);
- queue.addRecord(event);
- }
-
- loop.execute(Command.GO, true);
-
- System.out.println("loop processed " + loop.getTotalSupplied() + " records");
- }
-
- static class DummyEtEventProcessor extends EtEventProcessor {
-
- public void processEvent(EtEvent event) {
- System.out.println(this.getClass().getSimpleName() + " got EtEvent of length " + event.getLength());
- }
-
- }
-
-}
java/trunk/record-util/src/test/java/org/hps/record/et
--- java/trunk/record-util/src/test/java/org/hps/record/et/EtLoopTest.java (rev 0)
+++ java/trunk/record-util/src/test/java/org/hps/record/et/EtLoopTest.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -0,0 +1,42 @@
+package org.hps.record.et;
+
+import org.freehep.record.loop.RecordLoop.Command;
+import org.hps.record.et.EtLoop;
+import org.hps.record.et.EtProcessor;
+import org.hps.record.et.EtRecordQueue;
+import org.jlab.coda.et.EtEvent;
+import org.jlab.coda.et.EtEventImpl;
+
+/**
+ * Test that the {@link EtLoop} works.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class EtLoopTest {
+
+ public void testEtEventLoop() {
+
+ EtLoop loop = new EtLoop();
+ loop.addEtEventProcessor(new DummyEtEventProcessor());
+ EtRecordQueue queue = new EtRecordQueue();
+ queue.setTimeOutMillis(10000);
+ loop.setRecordSource(queue);
+
+ for (int i=0; i<100000; i++) {
+ EtEvent event = new EtEventImpl(1000);
+ queue.addRecord(event);
+ }
+
+ loop.execute(Command.GO, true);
+
+ System.out.println("loop processed " + loop.getTotalSupplied() + " records");
+ }
+
+ static class DummyEtEventProcessor extends EtProcessor {
+
+ public void process(EtEvent event) {
+ System.out.println(this.getClass().getSimpleName() + " got EtEvent of length " + event.getLength());
+ }
+
+ }
+
+}
java/trunk/record-util/src/test/java/org/hps/record/et
--- java/trunk/record-util/src/test/java/org/hps/record/etevent/MultiThreadedEtEventLoopTest.java 2014-08-27 02:17:30 UTC (rev 915)
+++ java/trunk/record-util/src/test/java/org/hps/record/et/MultiThreadedEtEventLoopTest.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,106 +0,0 @@
-package org.hps.record.etevent;
-
-import org.freehep.record.loop.RecordLoop.Command;
-import org.jlab.coda.et.EtEvent;
-import org.jlab.coda.et.EtEventImpl;
-
-/**
- * Test that the {@link EtEventLoop} works when the loop and source
- * are run on seperate threads.
- *
- * @author Jeremy McCormick <[log in to unmask]>
- */
-public class MultiThreadedEtEventLoopTest {
-
- // Time in milliseconds to wait before queuing a new dummy event.
- static int EVENT_INTERVAL = 10;
-
- public void testThreadedQueue() {
-
- // Setup the loop.
- EtEventLoop loop = new EtEventLoop();
- loop.addEtEventProcessor(new DummyEtEventProcessor());
-
- // Create the event queue.
- EtEventQueue queue = new EtEventQueue();
- queue.setTimeOutMillis(10000);
- loop.setRecordSource(queue);
-
- // Create runnable objects.
- LoopRunnable loopRunnable = new LoopRunnable(loop);
- QueueRunnable queueRunnable = new QueueRunnable(queue, EVENT_INTERVAL);
-
- // Start loop thread.
- Thread loopThread = new Thread(loopRunnable);
- loopThread.start();
-
- // Start queue thread.
- Thread queueThread = new Thread(queueRunnable);
- queueThread.start();
-
- // Wait for queue thread to end.
- try {
- queueThread.join();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- System.out.println("loop got " + loop.getConsumed() + " records");
-
- System.out.println("disposing loop ...");
- loop.dispose();
- loop = null;
- System.gc();
- }
-
- static class LoopRunnable implements Runnable {
-
- EtEventLoop loop;
-
- LoopRunnable(EtEventLoop loop) {
- this.loop = loop;
- }
-
- public void run() {
- loop.execute(Command.GO, false);
- }
- }
-
- static class QueueRunnable implements Runnable {
-
- EtEventQueue queue = null;
- int waitTimeMillis = 0;
-
- QueueRunnable(EtEventQueue queue, int waitTimeMillis) {
- this.queue = queue;
- this.waitTimeMillis = waitTimeMillis;
- }
-
- public void run() {
- for (int i = 1; i <= 1000; i++) {
- byte[] data = new byte[256];
- EtEventImpl event = new EtEventImpl(256);
- event.setData(data);
- queue.addRecord(event);
- delay();
- }
- System.out.println(this.getClass().getSimpleName() + " is done adding events.");
- }
-
- synchronized private void delay() {
- try {
- wait(waitTimeMillis);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
-
- static class DummyEtEventProcessor extends EtEventProcessor {
-
- public void processEvent(EtEvent event) {
- System.out.println(this.getClass().getSimpleName() + " got EtEvent of length " + event.getLength());
- }
-
- }
-}
java/trunk/record-util/src/test/java/org/hps/record/et
--- java/trunk/record-util/src/test/java/org/hps/record/et/MultiThreadedEtLoopTest.java (rev 0)
+++ java/trunk/record-util/src/test/java/org/hps/record/et/MultiThreadedEtLoopTest.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -0,0 +1,109 @@
+package org.hps.record.et;
+
+import org.freehep.record.loop.RecordLoop.Command;
+import org.hps.record.et.EtLoop;
+import org.hps.record.et.EtProcessor;
+import org.hps.record.et.EtRecordQueue;
+import org.jlab.coda.et.EtEvent;
+import org.jlab.coda.et.EtEventImpl;
+
+/**
+ * Test that the {@link EtLoop} works when the loop and source
+ * are run on seperate threads.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class MultiThreadedEtLoopTest {
+
+ // Time in milliseconds to wait before queuing a new dummy event.
+ static int EVENT_INTERVAL = 10;
+
+ public void testThreadedQueue() {
+
+ // Setup the loop.
+ EtLoop loop = new EtLoop();
+ loop.addEtEventProcessor(new DummyEtEventProcessor());
+
+ // Create the event queue.
+ EtRecordQueue queue = new EtRecordQueue();
+ queue.setTimeOutMillis(10000);
+ loop.setRecordSource(queue);
+
+ // Create runnable objects.
+ LoopRunnable loopRunnable = new LoopRunnable(loop);
+ QueueRunnable queueRunnable = new QueueRunnable(queue, EVENT_INTERVAL);
+
+ // Start loop thread.
+ Thread loopThread = new Thread(loopRunnable);
+ loopThread.start();
+
+ // Start queue thread.
+ Thread queueThread = new Thread(queueRunnable);
+ queueThread.start();
+
+ // Wait for queue thread to end.
+ try {
+ queueThread.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ System.out.println("loop got " + loop.getConsumed() + " records");
+
+ System.out.println("disposing loop ...");
+ loop.dispose();
+ loop = null;
+ System.gc();
+ }
+
+ static class LoopRunnable implements Runnable {
+
+ EtLoop loop;
+
+ LoopRunnable(EtLoop loop) {
+ this.loop = loop;
+ }
+
+ public void run() {
+ loop.execute(Command.GO, false);
+ }
+ }
+
+ static class QueueRunnable implements Runnable {
+
+ EtRecordQueue queue = null;
+ int waitTimeMillis = 0;
+
+ QueueRunnable(EtRecordQueue queue, int waitTimeMillis) {
+ this.queue = queue;
+ this.waitTimeMillis = waitTimeMillis;
+ }
+
+ public void run() {
+ for (int i = 1; i <= 1000; i++) {
+ byte[] data = new byte[256];
+ EtEventImpl event = new EtEventImpl(256);
+ event.setData(data);
+ queue.addRecord(event);
+ delay();
+ }
+ System.out.println(this.getClass().getSimpleName() + " is done adding events.");
+ }
+
+ synchronized private void delay() {
+ try {
+ wait(waitTimeMillis);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ static class DummyEtEventProcessor extends EtProcessor {
+
+ public void process(EtEvent event) {
+ System.out.println(this.getClass().getSimpleName() + " got EtEvent of length " + event.getLength());
+ }
+
+ }
+}
java/trunk/record-util/src/test/java/org/hps/record/evio
--- java/trunk/record-util/src/test/java/org/hps/record/evio/EvioEventLoopTest.java 2014-08-30 00:06:43 UTC (rev 929)
+++ java/trunk/record-util/src/test/java/org/hps/record/evio/EvioEventLoopTest.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,56 +0,0 @@
-package org.hps.record.evio;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.jlab.coda.jevio.EvioEvent;
-
-/**
- * Test that the {@link EvioEventLoop} works.
- * @author Jeremy McCormick <[log in to unmask]>
- */
-public class EvioEventLoopTest extends TestCase {
-
- File file1 = new File("/nfs/slac/g/hps3/data/testrun/runs/evio/hps_001351.evio.0");
- File file2 = new File("/nfs/slac/g/hps3/data/testrun/runs/evio/hps_001353.evio.0");
-
- public void testEvioRecordLoop() {
-
- List<File> files = new ArrayList<File>();
- files.add(file1);
- files.add(file2);
-
- EvioEventLoop loop = new EvioEventLoop();
- loop.addEvioEventProcessor(new DummyEvioEventProcessor());
- loop.setRecordSource(new EvioFileSource(files));
- try {
- loop.loop(-1);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- System.out.println("loop processed " + loop.getTotalSupplied() + " events");
- }
-
- static class DummyEvioEventProcessor extends EvioEventProcessor {
-
- public void processEvent(EvioEvent event) {
- System.out.println(this.getClass().getSimpleName() + " got EVIO event " + event.getEventNumber());
- }
-
- public void startRun(EvioEvent event) {
- int[] data = event.getIntData();
- int runNumber = data[1];
- System.out.println(this.getClass().getSimpleName() + " starting run " + runNumber);
- }
-
- public void endRun(EvioEvent event) {
- int[] data = event.getIntData();
- int runNumber = data[1];
- System.out.println(this.getClass().getSimpleName() + " ending run " + runNumber);
- }
- }
-}
java/trunk/record-util/src/test/java/org/hps/record/processing
--- java/trunk/record-util/src/test/java/org/hps/record/chain/EventProcessingChainTest.java 2014-08-28 20:22:29 UTC (rev 920)
+++ java/trunk/record-util/src/test/java/org/hps/record/processing/EventProcessingChainTest.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,81 +0,0 @@
-package org.hps.record.chain;
-
-import org.hps.evio.LCSimTestRunEventBuilder;
-import org.hps.record.DataSourceType;
-import org.hps.record.chain.EventProcessingChain;
-import org.hps.record.chain.EventProcessingConfiguration;
-import org.hps.record.evio.EvioEventProcessor;
-import org.jlab.coda.jevio.EvioEvent;
-import org.lcsim.event.EventHeader;
-import org.lcsim.event.EventHeader.LCMetaData;
-import org.lcsim.util.Driver;
-
-public class EventProcessingChainTest {
-
- //static String evioFilePath = "/work/data/hps/hps_001351.evio.0";
- static String evioFilePath = "/nfs/slac/g/hps3/data/testrun/runs/evio/hps_001351.evio.0";
- //static String lcioFilePath = "/work/data/hps/hps_001351.evio.0_recon.slcio";
- static String lcioFilePath = "/nfs/slac/g/hps3/data/testrun/runs/recon_new/hps_001351.evio.0_recon.slcio";
- static String detectorName = "HPS-TestRun-v8-5";
-
- // ET ring with streaming EVIO file must be running for this to work.
- /*
- public void testEtSource() {
- EventProcessingChain processing = new EventProcessingChain();
- processing.setRecordSource(new EtEventSource());
- processing.setEventBuilder(new LCSimTestRunEventBuilder());
- processing.setDetectorName(detectorName);
- processing.add(new DummyEvioProcessor());
- processing.add(new DummyDriver());
- processing.setStopOnEndRun();
- processing.configure();
- processing.loop();
- }
- */
-
- public void testEvioFile() {
-
- EventProcessingConfiguration config = new EventProcessingConfiguration();
- config.setDataSourceType(DataSourceType.EVIO_FILE);
- config.setFilePath(evioFilePath);
- config.setLCSimEventBuild(new LCSimTestRunEventBuilder());
- config.setDetectorName(detectorName);
- config.add(new DummyEvioProcessor());
- config.add(new DummyDriver());
- EventProcessingChain processing = new EventProcessingChain(config);
- processing.run();
- }
-
- /*
- public void testLcioFile() {
- EventProcessingChain processing = new EventProcessingChain();
- try {
- processing.setRecordSource(new LCIOEventSource(new File(lcioFilePath)));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- processing.setEventBuilder(new LCSimTestRunEventBuilder());
- processing.setDetectorName(detectorName);
- processing.add(new DummyDriver());
- processing.configure();
- processing.loop();
- }
- */
-
- static class DummyDriver extends Driver {
- public void process(EventHeader event) {
- System.out.println(this.getClass().getSimpleName() + " got LCIO event #" + event.getEventNumber());
- for (LCMetaData metaData : event.getMetaData()) {
- String collectionName = metaData.getName();
- Class type = metaData.getType();
- System.out.println (collectionName + " " + event.get(type, collectionName).size());
- }
- }
- }
-
- static class DummyEvioProcessor extends EvioEventProcessor {
- public void processEvent(EvioEvent event) {
- System.out.println(this.getClass().getSimpleName() + " got EVIO event #" + event.getEventNumber());
- }
- }
-}
java/trunk/record-util/src/test/java/org/hps/record/processing
--- java/trunk/record-util/src/test/java/org/hps/record/chain/EventProcessingErrorTest.java 2014-08-28 20:22:29 UTC (rev 920)
+++ java/trunk/record-util/src/test/java/org/hps/record/processing/EventProcessingErrorTest.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,100 +0,0 @@
-package org.hps.record.chain;
-
-import junit.framework.TestCase;
-
-import org.hps.evio.LCSimTestRunEventBuilder;
-import org.hps.record.DataSourceType;
-import org.hps.record.evio.EvioEventProcessor;
-import org.lcsim.event.EventHeader;
-import org.lcsim.util.Driver;
-
-
-public class EventProcessingErrorTest extends TestCase {
-
- static String evioFilePath = "/nfs/slac/g/hps3/data/testcase/hps_000975.evio.0";
-
- public void testError() {
- EventProcessingConfiguration config = new EventProcessingConfiguration();
- config.setFilePath(evioFilePath);
- config.setDataSourceType(DataSourceType.EVIO_FILE);
- LCSimTestRunEventBuilder builder = new LCSimTestRunEventBuilder();
- builder.setDebug(false);
- config.setLCSimEventBuild(builder);
- config.setDetectorName("HPS-TestRun-v8-5");
- config.add(new DummyErrorDriver());
- config.add(new DummyEvioProcessor());
- EventProcessingChain processing = new EventProcessingChain(config);
- processing.run();
- }
-
- public void testNoError() {
- EventProcessingConfiguration config = new EventProcessingConfiguration();
- config.setFilePath(evioFilePath);
- config.setDataSourceType(DataSourceType.EVIO_FILE);
- LCSimTestRunEventBuilder builder = new LCSimTestRunEventBuilder();
- builder.setDebug(false);
- config.setLCSimEventBuild(builder);
- config.setDetectorName("HPS-TestRun-v8-5");
- config.add(new DummyDriver());
- config.add(new DummyEvioProcessor());
- EventProcessingChain processing = new EventProcessingChain(config);
- processing.run();
- }
-
- public void testContinueOnError() {
- EventProcessingConfiguration config = new EventProcessingConfiguration();
- config.setFilePath(evioFilePath);
- config.setDataSourceType(DataSourceType.EVIO_FILE);
- LCSimTestRunEventBuilder builder = new LCSimTestRunEventBuilder();
- builder.setDebug(false);
- config.setLCSimEventBuild(builder);
- config.setDetectorName("HPS-TestRun-v8-5");
- config.add(new DummyErrorDriver());
- config.add(new DummyEvioProcessor());
- config.setStopOnErrors(false);
- EventProcessingChain processing = new EventProcessingChain(config);
- processing.run();
- }
-
- public void testIgnoreEndRun() {
- EventProcessingConfiguration config = new EventProcessingConfiguration();
- config.setFilePath(evioFilePath);
- config.setDataSourceType(DataSourceType.EVIO_FILE);
- LCSimTestRunEventBuilder builder = new LCSimTestRunEventBuilder();
- builder.setDebug(false);
- config.setLCSimEventBuild(builder);
- config.setDetectorName("HPS-TestRun-v8-5");
- config.add(new DummyDriver());
- config.add(new DummyEvioProcessor());
- config.setStopOnEndRun(false);
- EventProcessingChain processing = new EventProcessingChain(config);
- processing.run();
- }
-
-
- static class DummyDriver extends Driver {
- public void process(EventHeader event) {
- }
-
- public void endOfData() {
- System.out.println("DummyErrorDriver.endOfData");
- }
- }
-
- static class DummyErrorDriver extends Driver {
-
- public void process(EventHeader event) {
- throw new RuntimeException("Dummy processing error.");
- }
-
- public void endOfData() {
- System.out.println("DummyErrorDriver.endOfData");
- }
- }
-
- static class DummyEvioProcessor extends EvioEventProcessor {
- public void endJob() {
- System.out.println("DummyEvioDriver.endJob");
- }
- }
-}
java/trunk/record-util/src/test/java/org/hps/record/processing
--- java/trunk/record-util/src/test/java/org/hps/record/chain/EvioEventProcessingTest.java 2014-08-28 20:22:29 UTC (rev 920)
+++ java/trunk/record-util/src/test/java/org/hps/record/processing/EvioEventProcessingTest.java 2014-08-30 01:16:00 UTC (rev 930)
@@ -1,77 +0,0 @@
-package org.hps.record.chain;
-
-import org.hps.evio.LCSimTestRunEventBuilder;
-import org.hps.record.DataSourceType;
-import org.hps.record.chain.EventProcessingChain;
-import org.hps.record.chain.EventProcessingConfiguration;
-import org.hps.record.evio.EvioEventProcessor;
-import org.jlab.coda.jevio.EvioEvent;
-import org.lcsim.event.EventHeader;
-import org.lcsim.event.EventHeader.LCMetaData;
-import org.lcsim.geometry.Detector;
-import org.lcsim.util.Driver;
-
-public class EvioEventProcessingTest {
-
- static String evioFilePath = "/nfs/slac/g/hps3/data/testrun/runs/evio/hps_001351.evio.0";
- static String detectorName = "HPS-TestRun-v8-5";
-
- public void testEvioFile() {
- EventProcessingConfiguration config = new EventProcessingConfiguration();
- config.setDataSourceType(DataSourceType.EVIO_FILE);
- config.setFilePath(evioFilePath);
- config.setLCSimEventBuild(new LCSimTestRunEventBuilder());
- config.setDetectorName(detectorName);
- config.add(new DummyEvioProcessor());
- config.add(new DummyDriver());
- EventProcessingChain processing = new EventProcessingChain(config);
- processing.run();
- }
-
- static class DummyDriver extends Driver {
-
- public void detectorChanged(Detector detector) {
- System.out.println(this.getClass().getSimpleName() + ".detectorChanged - " + detector.getDetectorName());
- }
-
- public void startOfData() {
- System.out.println(this.getClass().getSimpleName() + ".startOfData");
- }
-
- public void process(EventHeader event) {
- System.out.println(this.getClass().getSimpleName() + " got LCIO event #" + event.getEventNumber());
- for (LCMetaData metaData : event.getMetaData()) {
- String collectionName = metaData.getName();
- Class type = metaData.getType();
- System.out.println (collectionName + " " + event.get(type, collectionName).size());
- }
- }
-
- public void endOfData() {
- System.out.println(this.getClass().getSimpleName() + ".endOfData");
- }
- }
-
- static class DummyEvioProcessor extends EvioEventProcessor {
-
- public void startRun(EvioEvent event) {
- System.out.println(this.getClass().getSimpleName() + ".startRun");
- }
-
- public void endRun(EvioEvent event) {
- System.out.println(this.getClass().getSimpleName() + ".endRun");
- }
-
- public void startJob() {
- System.out.println(this.getClass().getSimpleName() + ".startJob");
- }
-
- public void endJob() {
- System.out.println(this.getClass().getSimpleName() + ".endJob");
- }
-
- public void processEvent(EvioEvent event) {
- System.out.println(this.getClass().getSimpleName() + " got EVIO event #" + event.getEventNumber());
- }
- }
-}
SVNspam 0.1