5 added + 31 removed + 4 modified, total 40 files
java/trunk/record-util/src/main/java/org/hps/record
--- java/trunk/record-util/src/main/java/org/hps/record/AbstractRecordProcessor.java (rev 0)
+++ java/trunk/record-util/src/main/java/org/hps/record/AbstractRecordProcessor.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -0,0 +1,36 @@
+package org.hps.record;
+
+import org.freehep.record.loop.LoopEvent;
+
+/**
+ * An abstract implementation of {@link RecordProcessor} with "no op" method implementions.
+ * Concrete implementations of <code>RecordProcessor</code> should extend this class.
+ *
+ * @param <RecordType> The type of the record processed by this class.
+ */
+public abstract class AbstractRecordProcessor<RecordType> implements RecordProcessor<RecordType> {
+
+ @Override
+ public void startJob() {
+ }
+
+ @Override
+ public void startRun(RecordType record) {
+ }
+
+ @Override
+ public void process(RecordType record) throws Exception {
+ }
+
+ @Override
+ public void endRun(RecordType record) {
+ }
+
+ @Override
+ public void endJob() {
+ }
+
+ @Override
+ public void suspend() {
+ }
+}
java/trunk/record-util/src/main/java/org/hps/record
--- java/trunk/record-util/src/main/java/org/hps/record/ErrorState.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/ErrorState.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,36 +0,0 @@
-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/HasErrorState.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/HasErrorState.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,6 +0,0 @@
-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/RecordProcessingException.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/RecordProcessingException.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,9 +1,10 @@
package org.hps.record;
-public class RecordProcessingException extends RuntimeException {
-
+/**
+ * Error type for exceptions that occur during event processing.
+ */
+public class RecordProcessingException extends RuntimeException {
public RecordProcessingException(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/RecordProcessor.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/RecordProcessor.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -34,4 +34,9 @@
* End of job action.
*/
void endJob();
+
+ /**
+ * Action to be taken when recording processing is suspended.
+ */
+ void suspend();
}
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeEtAdapter.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeEtAdapter.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,65 +0,0 @@
-package org.hps.record.composite;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.freehep.record.loop.LoopEvent;
-import org.freehep.record.loop.RecordEvent;
-import org.freehep.record.source.NoSuchRecordException;
-import org.hps.record.RecordProcessingException;
-import org.hps.record.et.EtProcessor;
-import org.hps.record.et.EtSource;
-import org.jlab.coda.et.EtEvent;
-
-/**
- * An adapter for directly using the CompositeLoop to supply and process EtEvents.
- */
-public class CompositeEtAdapter extends CompositeLoopAdapter {
-
- EtSource source;
- List<EtProcessor> processors = new ArrayList<EtProcessor>();
-
- public CompositeEtAdapter(EtSource source) {
- this.source = source;
- }
-
- public void addProcessor(EtProcessor processor) {
- processors.add(processor);
- }
-
- public void process(EtEvent event) {
- for (EtProcessor processor : processors) {
- processor.process(event);
- }
- }
-
- public void finish(LoopEvent event) {
- for (EtProcessor processor : processors) {
- processor.endJob();
- }
- }
-
- public void start(LoopEvent event) {
- for (EtProcessor processor : processors) {
- processor.startJob();
- }
- }
-
- public void recordSupplied(RecordEvent record) {
- //System.out.println("CompositeEtAdapter.recordSupplied");
- System.out.flush();
- CompositeRecord compositeRecord = (CompositeRecord) record.getRecord();
- try {
- source.next();
- if (source.getCurrentRecord() != null) {
- compositeRecord.setEtEvent((EtEvent) source.getCurrentRecord());
- } else {
- throw new NoSuchRecordException("No ET current record available from EtSource.");
- }
- process(compositeRecord.getEtEvent());
- } catch (IOException | NoSuchRecordException e) {
- throw new RecordProcessingException("Error getting next ET record.", e);
- }
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeEvioAdapter.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeEvioAdapter.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,160 +0,0 @@
-package org.hps.record.composite;
-
-import java.io.IOException;
-import java.nio.BufferUnderflowException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.freehep.record.loop.LoopEvent;
-import org.freehep.record.loop.RecordEvent;
-import org.freehep.record.source.AbstractRecordSource;
-import org.freehep.record.source.NoSuchRecordException;
-import org.hps.evio.EventConstants;
-import org.hps.record.EndRunException;
-import org.hps.record.RecordProcessingException;
-import org.hps.record.evio.EvioProcessor;
-import org.jlab.coda.et.EtEvent;
-import org.jlab.coda.jevio.BaseStructure;
-import org.jlab.coda.jevio.EvioEvent;
-import org.jlab.coda.jevio.EvioException;
-import org.jlab.coda.jevio.EvioReader;
-
-/**
- * An adapter for directly using the CompositeLoop to supply and process EvioEvents.
- */
-public class CompositeEvioAdapter extends CompositeLoopAdapter {
-
- AbstractRecordSource source;
- List<EvioProcessor> processors = new ArrayList<EvioProcessor>();
- boolean stopOnEndRun = true;
-
- public CompositeEvioAdapter(AbstractRecordSource source) {
- this.source = source;
- }
-
- public CompositeEvioAdapter() {
- }
-
- public void addProcessor(EvioProcessor processor) {
- processors.add(processor);
- }
-
- public void setStopOnEndRun(boolean stopOnEndRun) {
- this.stopOnEndRun = stopOnEndRun;
- }
-
- public void recordSupplied(RecordEvent record) {
- //System.out.println("CompositeEvioAdapter.recordSupplied");
- System.out.flush();
- CompositeRecord compositeRecord = (CompositeRecord) record.getRecord();
- try {
- EvioEvent evioEvent;
- // Using ET system?
- if (compositeRecord.getEtEvent() != null) {
- try {
- // Create EVIO from ET byte buffer.
- evioEvent = createEvioEvent(compositeRecord.getEtEvent());
- } catch (BufferUnderflowException | EvioException e) {
- // There was a problem creating EVIO from ET.
- throw new RecordProcessingException("Failed to create EvioEvent from EtEvent.", e);
- }
- } else {
- // Load the next record from the EVIO record source.
- source.next();
- evioEvent = (EvioEvent)source.getCurrentRecord();
- }
- // Failed to create an EvioEvent?
- if (evioEvent == null) {
- throw new NoSuchRecordException("Failed to get next EVIO record.");
- }
-
- // Set event number on the EvioEvent.
- setEventNumber(evioEvent);
-
- // Is pre start event?
- if (EventConstants.isPreStartEvent(evioEvent)) {
- // Activate start of run hook on processors.
- startRun(evioEvent);
- // Is end run event?
- } else if (EventConstants.isEndEvent(evioEvent)) {
- // Activate end of run hook on processors.
- endRun(evioEvent);
-
- // Stop on end run enabled?
- if (stopOnEndRun) {
- throw new EndRunException("EVIO end event received.", evioEvent.getIntData()[1]);
- }
- // Is physics event?
- } else if (EventConstants.isPhysicsEvent(evioEvent)) {
- // Process a single physics EvioEvent.
- process(evioEvent);
- }
-
- // Set EvioEvent on CompositeRecord.
- compositeRecord.setEvioEvent(evioEvent);
- } catch (IOException | NoSuchRecordException e) {
- throw new RecordProcessingException("No next EVIO record available from source.", e);
- }
- }
-
- void process(EvioEvent event) {
- for (EvioProcessor processor : processors) {
- processor.process(event);
- }
- }
-
- void startRun(EvioEvent event) {
- for (EvioProcessor processor : processors) {
- processor.startRun(event);
- }
- }
-
- void endRun(EvioEvent event) {
- for (EvioProcessor processor : processors) {
- processor.endRun(event);
- }
- }
-
- public void finish(LoopEvent event) {
- for (EvioProcessor processor : processors) {
- processor.endJob();
- }
- }
-
- public void start(LoopEvent event) {
- for (EvioProcessor processor : processors) {
- processor.startJob();
- }
- }
-
- /**
- * Create an EvioEvent from an EtEvent byte buffer.
- * @param etEvent The input EtEvent.
- * @return The EvioEvent created from the EtEvent.
- * @throws IOException
- * @throws EvioException
- * @throws BufferUnderflowException
- */
- private EvioEvent createEvioEvent(EtEvent etEvent)
- throws IOException, EvioException, BufferUnderflowException {
- return (new EvioReader(etEvent.getDataBuffer())).parseNextEvent();
- }
-
- /**
- * Set the EVIO event number manually from the event ID bank.
- * @param evioEvent The <tt>EvioEvent</tt> on which to set the event number.
- */
- private void setEventNumber(EvioEvent evioEvent) {
- int eventNumber = -1;
- if (evioEvent.getChildren() != null) {
- for (BaseStructure bank : evioEvent.getChildren()) {
- if (bank.getHeader().getTag() == EventConstants.EVENTID_BANK_TAG) {
- eventNumber = bank.getIntData()[0];
- break;
- }
- }
- }
- if (eventNumber != -1)
- evioEvent.setEventNumber(eventNumber);
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLcioAdapter.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLcioAdapter.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,86 +0,0 @@
-package org.hps.record.composite;
-
-import java.io.IOException;
-
-import org.freehep.record.loop.LoopEvent;
-import org.freehep.record.loop.RecordEvent;
-import org.freehep.record.source.AbstractRecordSource;
-import org.freehep.record.source.NoSuchRecordException;
-import org.hps.evio.EventConstants;
-import org.hps.evio.LCSimEventBuilder;
-import org.hps.record.RecordProcessingException;
-import org.jlab.coda.jevio.EvioEvent;
-import org.lcsim.event.EventHeader;
-import org.lcsim.util.Driver;
-import org.lcsim.util.DriverAdapter;
-
-/**
- * An adapter to supply and process LCSim EventHeader objects using
- * an (optional) LCSimEventBuilder and the existing DriverAdapter class.
- */
-public class CompositeLcioAdapter extends CompositeLoopAdapter {
-
- DriverAdapter drivers;
- Driver top = new Driver();
- LCSimEventBuilder builder;
- AbstractRecordSource source;
-
- public CompositeLcioAdapter(AbstractRecordSource source) {
- this.source = source;
- drivers = new DriverAdapter(top);
- }
-
- public CompositeLcioAdapter() {
- drivers = new DriverAdapter(top);
- }
-
- public void addDriver(Driver driver) {
- top.add(driver);
- }
-
- public void setLCSimEventBuilder(LCSimEventBuilder builder) {
- this.builder = builder;
- }
-
- public void recordSupplied(RecordEvent record) {
- //System.out.println("CompositeLcioAdapter.recordSupplied");
- System.out.flush();
- CompositeRecord compositeRecord = (CompositeRecord) record.getRecord();
- EventHeader lcioEvent = null;
- try {
- // Is there an EVIO event?
- if (compositeRecord.getEvioEvent() != null) {
- // Create the EVIO event.
- EvioEvent evioEvent = compositeRecord.getEvioEvent();
- // Is this a physics EvioEvent?
- if (EventConstants.isPhysicsEvent(evioEvent)) {
- // Use the builder to create the LCIO event.
- lcioEvent = builder.makeLCSimEvent(compositeRecord.getEvioEvent());
- } else {
- // Non-physics events are ignored.
- return;
- }
- } else {
- // Try to use an event source to get the next LCIO event.
- source.next();
- lcioEvent = (EventHeader) source.getCurrentRecord();
- }
-
- // Supply the EventHeader to the DriverAdapter.
- RecordEvent recordEvent = new RecordEvent(null, lcioEvent);
- drivers.recordSupplied(recordEvent);
-
- compositeRecord.setLcioEvent(lcioEvent);
- } catch (IOException | NoSuchRecordException e) {
- throw new RecordProcessingException("Error creating LCIO event.", e);
- }
- }
-
- public void finish(LoopEvent loopEvent) {
- drivers.finish(loopEvent);
- }
-
- public void start(LoopEvent loopEvent) {
- drivers.start(loopEvent);
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoop.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoop.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,16 +1,28 @@
package org.hps.record.composite;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import org.freehep.record.loop.DefaultRecordLoop;
-import org.freehep.record.loop.RecordEvent;
-import org.freehep.record.loop.RecordListener;
+import org.freehep.record.loop.RecordLoop.Command;
import org.freehep.record.source.NoSuchRecordException;
import org.freehep.record.source.RecordSource;
import org.hps.record.EndRunException;
import org.hps.record.MaxRecordsException;
-import org.hps.record.et.EtSource.EtSourceException;
+import org.hps.record.enums.DataSourceType;
+import org.hps.record.enums.ProcessingStage;
+import org.hps.record.et.EtEventProcessor;
+import org.hps.record.et.EtEventSource;
+import org.hps.record.et.EtEventSource.EtSourceException;
+import org.hps.record.evio.EvioEventProcessor;
+import org.hps.record.evio.EvioFileSource;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.util.Driver;
+import org.lcsim.util.loop.LCIOEventSource;
+import org.lcsim.util.loop.LCSimConditionsManagerImplementation;
/**
* Implementation of a composite record loop for processing
@@ -18,17 +30,24 @@
*/
public final class CompositeLoop extends DefaultRecordLoop {
- CompositeSource recordSource = new CompositeSource();
-
+ CompositeRecordSource recordSource = new CompositeRecordSource();
+ List<CompositeLoopAdapter> adapters = new ArrayList<CompositeLoopAdapter>();
+
+ boolean paused = false;
boolean stopOnErrors = true;
boolean done = false;
- List<CompositeLoopAdapter> adapters = new ArrayList<CompositeLoopAdapter>();
-
+ CompositeLoopConfiguration config = null;
+
public CompositeLoop() {
setRecordSource(recordSource);
}
+ public CompositeLoop(CompositeLoopConfiguration config) {
+ setRecordSource(recordSource);
+ configure(config);
+ }
+
public void setStopOnErrors(boolean stopOnErrors) {
this.stopOnErrors = stopOnErrors;
}
@@ -41,7 +60,7 @@
/**
* Set the <code>RecordSource</code> which provides <code>CompositeRecord</code> objects.
*/
- public void setRecordSource(RecordSource source) {
+ public final void setRecordSource(RecordSource source) {
if (!source.getRecordClass().isAssignableFrom(CompositeRecord.class)) {
throw new IllegalArgumentException("The RecordSource has the wrong class.");
}
@@ -130,6 +149,146 @@
}
public Throwable getLastError() {
- return _exception;
+ return _exception;
}
+
+ /**
+ * Pause the event processing.
+ */
+ public void pause() {
+ execute(Command.PAUSE);
+ paused = true;
+ }
+
+ /**
+ * Resume event processing from pause mode.
+ */
+ public void resume() {
+ paused = false;
+ }
+
+ public boolean isPaused() {
+ return paused;
+ }
+
+ public long loop(long number) {
+ if (number < 0L) {
+ execute(Command.GO, true);
+ } else {
+ execute(Command.GO_N, number, true);
+ execute(Command.STOP);
+ }
+ return getSupplied();
+ }
+
+ public final void configure(CompositeLoopConfiguration config) {
+
+ if (this.config != null)
+ throw new RuntimeException("CompositeLoop has already been configured.");
+
+ this.config = config;
+
+ EtEventAdapter etAdapter = null;
+ EvioEventAdapter evioAdapter = null;
+ LcioEventAdapter lcioAdapter = null;
+ CompositeLoopAdapter compositeAdapter = new CompositeLoopAdapter();
+
+ // Was there no RecordSource provided explicitly?
+ if (config.recordSource == null) {
+ // Using an ET server connection?
+ if (config.sourceType.equals(DataSourceType.ET_SERVER)) {
+ if (config.connection != null)
+ etAdapter = new EtEventAdapter(new EtEventSource(config.connection));
+ else
+ throw new IllegalArgumentException("Configuration is missing a valid ET connection.");
+ // Using an EVIO file?
+ } else if (config.sourceType.equals(DataSourceType.EVIO_FILE)) {
+ if (config.filePath != null) {
+ evioAdapter = new EvioEventAdapter(new EvioFileSource(new File(config.filePath)));
+ } else {
+ throw new IllegalArgumentException("Configuration is missing a file path.");
+ }
+ // Using an LCIO file?
+ } else if (config.sourceType.equals(DataSourceType.LCIO_FILE)) {
+ if (config.filePath != null)
+ try {
+ lcioAdapter = new LcioEventAdapter(new LCIOEventSource(new File(config.filePath)));
+ } catch (IOException e) {
+ throw new RuntimeException("Error configuring LCIOEventSource.", e);
+ }
+ else
+ throw new IllegalArgumentException("Configuration is missing a file path.");
+ }
+ }
+
+ // Configure ET system.
+ if (config.sourceType == DataSourceType.ET_SERVER) {
+ //System.out.println("compositeLoop.addAdapter(etAdapter)");
+ addAdapter(etAdapter);
+ }
+
+ // Configure EVIO processing.
+ if (config.processingStage.ordinal() >= ProcessingStage.EVIO.ordinal()) {
+ if (config.sourceType.ordinal() <= DataSourceType.EVIO_FILE.ordinal()) {
+ if (evioAdapter == null)
+ evioAdapter = new EvioEventAdapter();
+ //System.out.println("compositeLoop.addAdapter(evioAdapter)");
+ addAdapter(evioAdapter);
+ }
+ }
+
+ // Configure LCIO processing.
+ if (config.processingStage.ordinal() >= ProcessingStage.LCIO.ordinal()) {
+ if (lcioAdapter == null)
+ lcioAdapter = new LcioEventAdapter();
+ //System.out.println("compositeLoop.addAdapter(lcioAdapter)");
+ addAdapter(lcioAdapter);
+ if (config.eventBuilder != null) {
+ if (config.detectorName != null) {
+ // Is LCSim ConditionsManager installed yet?
+ if (!ConditionsManager.isSetup())
+ // Setup LCSim conditions system if not already.
+ LCSimConditionsManagerImplementation.register();
+ config.eventBuilder.setDetectorName(config.detectorName);
+ } else {
+ throw new IllegalArgumentException("Missing detectorName in configuration.");
+ }
+ lcioAdapter.setLCSimEventBuilder(config.eventBuilder);
+ } else {
+ throw new IllegalArgumentException("Missing an LCSimEventBuilder in configuration.");
+ }
+ }
+
+ // Set whether to stop on event processing errors.
+ setStopOnErrors(config.stopOnErrors);
+
+ // Add EtEventProcessors to loop.
+ for (EtEventProcessor processor : config.etProcessors) {
+ etAdapter.addProcessor(processor);
+ }
+
+ // Add EvioEventProcessors to loop.
+ for (EvioEventProcessor processor : config.evioProcessors) {
+ evioAdapter.addProcessor(processor);
+ }
+
+ // Add Drivers to loop.
+ for (Driver driver : config.drivers) {
+ lcioAdapter.addDriver(driver);
+ }
+
+ // Add CompositeLoopAdapter which should execute last.
+ //System.out.println("compositeLoop.addAdapter(compositeAdapter)");
+ addAdapter(compositeAdapter);
+
+ // Add CompositeRecordProcessors to loop.
+ for (CompositeRecordProcessor processor : config.compositeProcessors) {
+ compositeAdapter.addProcessor(processor);
+ }
+
+ // Max records was set?
+ if (config.maxRecords != -1) {
+ compositeAdapter.addProcessor(new MaxRecordsProcessor(config.maxRecords));
+ }
+ }
}
\ 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/CompositeLoopAdapter.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoopAdapter.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -14,13 +14,13 @@
*/
public class CompositeLoopAdapter extends AbstractLoopListener implements RecordListener {
- List<CompositeProcessor> processors = new ArrayList<CompositeProcessor>();
+ List<CompositeRecordProcessor> processors = new ArrayList<CompositeRecordProcessor>();
/**
* Add a <tt>CompositeRecordProcessor</tt> that will listen to this loop.
* @param processor The composite record processor to add.
*/
- public void addProcessor(CompositeProcessor processor) {
+ public void addProcessor(CompositeRecordProcessor processor) {
processors.add(processor);
}
@@ -30,18 +30,18 @@
*/
public void finish(LoopEvent loopEvent) {
// Call end job hook on all processors.
- for (CompositeProcessor processor : processors) {
+ for (CompositeRecordProcessor processor : processors) {
processor.endJob();
}
}
/**
- * Start event processing which will call {@link CompositeProcessor#startJob()}
+ * Start event processing which will call {@link CompositeRecordProcessor#startJob()}
* on all the registered processors.
* @param loopEvent
*/
public void start(LoopEvent loopEvent) {
- for (CompositeProcessor processor : processors) {
+ for (CompositeRecordProcessor processor : processors) {
processor.startJob();
}
}
@@ -52,9 +52,9 @@
*/
@Override
public void recordSupplied(RecordEvent record) {
- System.out.println("CompositeLoopAdapter.recordSupplied");
- System.out.flush();
- for (CompositeProcessor processor : processors) {
+ //System.out.println("CompositeLoopAdapter.recordSupplied");
+ //System.out.flush();
+ for (CompositeRecordProcessor processor : processors) {
try {
// Activate the processing step on the CompositeRecord.
processor.process((CompositeRecord) record.getRecord());
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoopConfiguration.java (rev 0)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoopConfiguration.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -0,0 +1,114 @@
+package org.hps.record.composite;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.freehep.record.source.RecordSource;
+import org.hps.evio.LCSimEventBuilder;
+import org.hps.record.composite.CompositeRecordProcessor;
+import org.hps.record.enums.DataSourceType;
+import org.hps.record.enums.ProcessingStage;
+import org.hps.record.et.EtConnection;
+import org.hps.record.et.EtEventProcessor;
+import org.hps.record.evio.EvioEventProcessor;
+import org.lcsim.util.Driver;
+
+/**
+ * A configuration object for the {@link ProcessingChain}.
+ * 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 CompositeLoopConfiguration {
+
+ boolean stopOnErrors = true;
+ boolean stopOnEndRun = true;
+
+ int maxRecords = -1;
+
+ 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 CompositeLoopConfiguration setFilePath(String filePath) {
+ this.filePath = filePath;
+ return this;
+ }
+
+ public CompositeLoopConfiguration setEtConnection(EtConnection connection) {
+ this.connection = connection;
+ return this;
+ }
+
+ public CompositeLoopConfiguration setDataSourceType(DataSourceType sourceType) {
+ this.sourceType = sourceType;
+ return this;
+ }
+
+ public CompositeLoopConfiguration setProcessingStage(ProcessingStage processingStage) {
+ this.processingStage = processingStage;
+ return this;
+ }
+
+ public CompositeLoopConfiguration setRecordSource(RecordSource recordSource) {
+ this.recordSource = recordSource;
+ return this;
+ }
+
+ public CompositeLoopConfiguration setLCSimEventBuilder(LCSimEventBuilder eventBuilder) {
+ this.eventBuilder = eventBuilder;
+ return this;
+ }
+
+ public CompositeLoopConfiguration setDetectorName(String detectorName) {
+ this.detectorName = detectorName;
+ return this;
+ }
+
+ public CompositeLoopConfiguration setStopOnErrors(boolean stopOnErrors) {
+ this.stopOnErrors = stopOnErrors;
+ return this;
+ }
+
+ public CompositeLoopConfiguration setStopOnEndRun(boolean stopOnEndRun) {
+ this.stopOnEndRun = stopOnEndRun;
+ return this;
+ }
+
+ public CompositeLoopConfiguration setMaxRecords(int maxRecords) {
+ if (maxRecords < 1)
+ throw new IllegalArgumentException("Invalid maxRecords value: " + maxRecords);
+ this.maxRecords = maxRecords;
+ return this;
+ }
+
+ public CompositeLoopConfiguration add(EtEventProcessor processor) {
+ etProcessors.add(processor);
+ return this;
+ }
+
+ public CompositeLoopConfiguration add(EvioEventProcessor processor) {
+ evioProcessors.add(processor);
+ return this;
+ }
+
+ public CompositeLoopConfiguration add(Driver processor) {
+ drivers.add(processor);
+ return this;
+ }
+
+ public CompositeLoopConfiguration add(CompositeRecordProcessor processor) {
+ compositeProcessors.add(processor);
+ return this;
+ }
+}
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeProcessor.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeProcessor.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,38 +0,0 @@
-package org.hps.record.composite;
-
-import org.hps.record.ErrorState;
-import org.hps.record.HasErrorState;
-import org.hps.record.RecordProcessor;
-
-/**
- * An <code>EventProcessor</code> implementation for processing <code>CompositeRecord</code>
- * records.
- */
-public abstract class CompositeProcessor implements RecordProcessor<CompositeRecord>, HasErrorState {
-
- ErrorState errorState = new ErrorState();
-
- public ErrorState getErrorState() {
- return errorState;
- }
-
- @Override
- public void startJob() {
- }
-
- @Override
- public void startRun(CompositeRecord event) {
- }
-
- @Override
- public void process(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/CompositeSource.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeSource.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,70 +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 CompositeSource extends AbstractRecordSource {
-
- CompositeRecord currentRecord;
- int sequenceNumber = 1;
-
- public void next() throws IOException, NoSuchRecordException {
- //System.out.println("CompositeSource.next");
- //System.out.println(" record #" + sequenceNumber);
- //System.out.flush();
- 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/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/RecordProcessorAdapter.java (rev 0)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/RecordProcessorAdapter.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -0,0 +1,61 @@
+package org.hps.record.composite;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.freehep.record.loop.LoopEvent;
+import org.hps.record.RecordProcessingException;
+import org.hps.record.RecordProcessor;
+
+public abstract class RecordProcessorAdapter<RecordType> extends CompositeLoopAdapter {
+
+ List<RecordProcessor<RecordType>> processors = new ArrayList<RecordProcessor<RecordType>>();
+
+ public void addProcessor(RecordProcessor<RecordType> processor) {
+ processors.add(processor);
+ }
+
+ public void removeProcessor(RecordProcessor<RecordType> processor) {
+ processors.remove(processor);
+ }
+
+ public void startRun(RecordType record) {
+ for (RecordProcessor<RecordType> processor : processors) {
+ processor.startRun(record);
+ }
+ }
+
+ public void endRun(RecordType record) {
+ for (RecordProcessor<RecordType> processor : processors) {
+ processor.endRun(record);
+ }
+ }
+
+ public void process(RecordType record) {
+ for (RecordProcessor<RecordType> processor : processors) {
+ try {
+ processor.process(record);
+ } catch (Exception e) {
+ throw new RecordProcessingException("Error processing record.", e);
+ }
+ }
+ }
+
+ public void finish(LoopEvent loopEvent) {
+ for (RecordProcessor<RecordType> processor : processors) {
+ processor.endJob();
+ }
+ }
+
+ public void start(LoopEvent loopEvent) {
+ for (RecordProcessor<RecordType> processor : processors) {
+ processor.startJob();
+ }
+ }
+
+ public void suspend(LoopEvent loopEvent) {
+ for (RecordProcessor<RecordType> processor : processors) {
+ processor.suspend();
+ }
+ }
+}
java/trunk/record-util/src/main/java/org/hps/record/et
--- java/trunk/record-util/src/main/java/org/hps/record/et/EtAdapter.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtAdapter.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,63 +0,0 @@
-package org.hps.record.et;
-
-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.RecordProcessingException;
-import org.jlab.coda.et.EtEvent;
-
-/**
- * Adapter for processing <tt>EtEvent</tt> objects using a loop.
- */
-public final class EtAdapter extends AbstractLoopListener implements RecordListener {
-
- List<EtProcessor> processors = new ArrayList<EtProcessor>();
-
- void addEtEventProcessor(EtProcessor processor) {
- processors.add(processor);
- }
-
- @Override
- public void recordSupplied(RecordEvent recordEvent) {
- Object object = recordEvent.getRecord();
- if (object instanceof EtEvent) {
- EtEvent event = (EtEvent)object;
- processEvent(event);
- }
- }
-
- @Override
- public void suspend(LoopEvent event) {
- if (event.getException() != null) {
- throw new RecordProcessingException("ET system error.", event.getException());
- //System.out.println("DEBUG");
- //System.out.println("ET system error...");
- //event.getException().printStackTrace();
- //System.exit(1);
- }
- }
-
- @Override
- public void start(LoopEvent event) {
- for (EtProcessor processor : processors) {
- processor.startJob();
- }
- }
-
- @Override
- public void finish(LoopEvent event) {
- for (EtProcessor processor : processors) {
- processor.endJob();
- }
- }
-
- private void processEvent(EtEvent event) {
- for (EtProcessor processor : processors) {
- processor.process(event);
- }
- }
-}
\ 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/et/EtConnectionParameters.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtConnectionParameters.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,179 +0,0 @@
-package org.hps.record.et;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-import org.jlab.coda.et.EtConstants;
-import org.jlab.coda.et.enums.Mode;
-
-/**
- * Connection parameters for ET system consumer.
- */
-public final class EtConnectionParameters {
-
- /**
- * Parameters that are externally settable from within the package.
- */
- String bufferName = "ETBuffer";
- String host = null;
- int port = EtConstants.serverPort;
- boolean blocking = false;
- boolean verbose = false;
- String statName = "MY_STATION";
- int chunk = 1;
- int qSize = 0;
- int position = 1;
- int pposition = 0;
- int flowMode = EtConstants.stationSerial;
- Mode waitMode = Mode.TIMED;
- int waitTime = 10000000; // wait time in microseconds
- int prescale = 1;
-
- public void setBufferName(String etName) {
- this.bufferName = etName;
- }
-
- public void setHost(String host) {
- this.host = host;
- }
-
- public void setPort(int port) {
- this.port = port;
- }
-
- public void setBlocking(boolean blocking) {
- this.blocking = blocking;
- }
-
- public void setVerbose(boolean verbose) {
- this.verbose = verbose;
- }
-
- public void setStationName(String stationName) {
- this.statName = stationName;
- }
-
- public void setChunkSize(int chunk) {
- this.chunk = chunk;
- }
-
- public void setQueueSize(int qSize) {
- this.qSize = qSize;
- }
-
- public void setStationPosition(int position) {
- this.position = position;
- }
-
- public void setStationsParallelPosition(int pposition) {
- this.pposition = pposition;
- }
-
- public void setWaitMode(Mode waitMode) {
- this.waitMode = waitMode;
- }
-
- public void setWaitTime(int waitTime) {
- this.waitTime = waitTime;
- }
-
- public void setPreScale(int prescale) {
- this.prescale = prescale;
- }
-
- public Mode getWaitMode() {
- return waitMode;
- }
-
- public int getWaitTime() {
- return waitTime;
- }
-
- public int getChunkSize() {
- return chunk;
- }
-
- public String getBufferName() {
- return bufferName;
- }
-
- public String getHost() {
- return host;
- }
-
- public int getPort() {
- return port;
- }
-
- public boolean getBlocking() {
- return blocking;
- }
-
- public boolean getVerbose() {
- return verbose;
- }
-
- public String getStationName() {
- return statName;
- }
-
- public int getPrescale() {
- return prescale;
- }
-
- public int getQueueSize() {
- return qSize;
- }
-
- public int getStationPosition() {
- return position;
- }
-
- public int getStationParallelPosition() {
- return pposition;
- }
-
- /**
- * Class constructor.
- */
- public EtConnectionParameters() {
- // Set the default host to this machine.
- try {
- InetAddress addr = InetAddress.getLocalHost();
- host = addr.getHostName();
- } catch (UnknownHostException e) {
- throw new ConnectionParametersException("Unable to assign default host.");
- }
- }
-
- /**
- * This is thrown from the constructor if there a problem setting up the default host.
- */
- public class ConnectionParametersException extends RuntimeException {
- ConnectionParametersException(String msg) {
- super(msg);
- }
- }
-
- /**
- * Convert this class to a readable string (properties format).
- */
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append("bufferName: " + bufferName + '\n');
- buf.append("host: " + host + '\n');
- buf.append("port: " + port + '\n');
- buf.append("blocking: " + blocking + '\n');
- buf.append("verbose: " + verbose + '\n');
- buf.append("statName: " + statName + '\n');
- buf.append("chunk: " + chunk + '\n');
- buf.append("qSize: " + qSize + '\n');
- buf.append("position: " + position + '\n');
- buf.append("pposition: " + pposition + '\n');
- buf.append("flowMode: " + flowMode + '\n');
- buf.append("waitMode: " + waitMode + '\n');
- buf.append("waitTime: " + waitTime + '\n');
- buf.append("prescale: " + prescale + '\n');
- return buf.toString();
- }
-}
\ 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/et/EtLoop.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtLoop.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,55 +0,0 @@
-package org.hps.record.et;
-
-import org.freehep.record.loop.DefaultRecordLoop;
-import org.freehep.record.source.RecordSource;
-import org.hps.record.ErrorState;
-import org.hps.record.HasErrorState;
-import org.jlab.coda.et.EtEvent;
-
-/**
- * Record loop implementation for processing <tt>EtEvent</tt> objects.
- */
-public final class EtLoop extends DefaultRecordLoop implements HasErrorState {
-
- EtAdapter adapter = new EtAdapter();
- ErrorState errorState = new ErrorState();
-
- public EtLoop() {
- addLoopListener(adapter);
- addRecordListener(adapter);
- }
-
- /**
- * Add an <code>EtEventProcessor</code> to the loop.
- * @param processor The <code>EtEventProcessor</code> to add.
- */
- public void addEtEventProcessor(EtProcessor 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) {
- getErrorState().setLastError((Exception) x);
- getErrorState().print();
- }
-
- protected void handleSourceError(Throwable x) {
- getErrorState().setLastError((Exception) x);
- getErrorState().print();
- }
-
- @Override
- public ErrorState getErrorState() {
- return errorState;
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/et
--- java/trunk/record-util/src/main/java/org/hps/record/et/EtProcessor.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtProcessor.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,42 +0,0 @@
-package org.hps.record.et;
-
-import org.hps.record.RecordProcessor;
-import org.jlab.coda.et.EtEvent;
-
-/**
- * This is the basic abstract class that processors of
- * <tt>EtEvent</tt> objects should implement.
- */
-public abstract class EtProcessor implements RecordProcessor<EtEvent> {
-
- /**
- * Start of ET session.
- */
- @Override
- public void startJob() {
- }
-
- @Override
- public void startRun(EtEvent event) {
-
- }
-
- /**
- * Process one <tt>EtEvent</tt>.
- */
- @Override
- public void process(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/et/EtRecordQueue.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtRecordQueue.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,17 +0,0 @@
-package org.hps.record.et;
-
-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 EtRecordQueue 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/et/EtSource.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtSource.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,106 +0,0 @@
-package org.hps.record.et;
-
-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 EtSource extends AbstractRecordSource {
-
- EtConnection connection;
- EtEvent currentRecord;
- Queue<EtEvent> eventQueue = new LinkedBlockingQueue<EtEvent>();
-
- public EtSource(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("ET record queue is empty.");
- }
- }
-
- @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 EtSourceException("Error while reading ET events.", e);
- }
- }
-
- public static class EtSourceException extends IOException {
- public EtSourceException(String message, Exception cause) {
- super(message, cause);
- }
- }
-}
\ 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/EvioAdapter.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/EvioAdapter.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,80 +0,0 @@
-package org.hps.record.evio;
-
-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.evio.EventConstants;
-import org.hps.record.RecordProcessingException;
-import org.jlab.coda.jevio.EvioEvent;
-
-/**
- * Adapter to process <tt>EvioEvent</tt> objects using a record loop.
- */
-public final class EvioAdapter extends AbstractLoopListener implements RecordListener {
-
- List<EvioProcessor> processors = new ArrayList<EvioProcessor>();
-
- void addEvioEventProcessor(EvioProcessor processor) {
- processors.add(processor);
- }
-
- @Override
- public void recordSupplied(RecordEvent recordEvent) {
- Object object = recordEvent.getRecord();
- if (object instanceof EvioEvent) {
- EvioEvent event = (EvioEvent)object;
- if (EventConstants.isPreStartEvent(event)) {
- // Start of run.
- startRun(event);
- } else if (EventConstants.isEndEvent(event)) {
- // End of run.
- endRun(event);
- } else if (EventConstants.isPhysicsEvent(event)) {
- // Process one physics event.
- processEvent(event);
- }
- }
- }
-
- @Override
- public void start(LoopEvent event) {
- for (EvioProcessor processor : processors) {
- processor.startJob();
- }
- }
-
- @Override
- public void finish(LoopEvent event) {
- for (EvioProcessor processor : processors) {
- processor.endJob();
- }
- }
-
- @Override
- public void suspend(LoopEvent event) {
- if (event.getException() != null)
- throw new RecordProcessingException("EVIO error.", event.getException());
- }
-
- private void processEvent(EvioEvent event) {
- for (EvioProcessor processor : processors) {
- processor.process(event);
- }
- }
-
- private void startRun(EvioEvent event) {
- for (EvioProcessor processor : processors) {
- processor.startRun(event);
- }
- }
-
- private void endRun(EvioEvent event) {
- 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/EvioLoop.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/EvioLoop.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,63 +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.hps.record.ErrorState;
-import org.hps.record.HasErrorState;
-import org.jlab.coda.jevio.EvioEvent;
-
-/**
- * Implementation of record loop for processing <tt>EvioEvent</tt> objects.
- */
-public final class EvioLoop extends DefaultRecordLoop implements HasErrorState {
-
- EvioAdapter adapter = new EvioAdapter();
- ErrorState errorState = new ErrorState();
-
- public EvioLoop() {
- addLoopListener(adapter);
- addRecordListener(adapter);
- }
-
- public void addEvioEventProcessor(EvioProcessor 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();
- }
-
- public ErrorState getErrorState() {
- return errorState;
- }
-
- protected void handleClientError(Throwable x) {
- getErrorState().setLastError((Exception) x);
- getErrorState().print();
- }
-
- protected void handleSourceError(Throwable x) {
- getErrorState().setLastError((Exception) x);
- getErrorState().print();
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/evio
--- java/trunk/record-util/src/main/java/org/hps/record/evio/EvioProcessor.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/EvioProcessor.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,31 +0,0 @@
-package org.hps.record.evio;
-
-import org.hps.record.RecordProcessor;
-import org.jlab.coda.jevio.EvioEvent;
-
-/**
- * This is the basic abstract class that processors of
- * <tt>EvioEvent</tt> objects should implement.
- */
-public abstract class EvioProcessor implements RecordProcessor<EvioEvent> {
-
- @Override
- public void startJob() {
- }
-
- @Override
- public void startRun(EvioEvent event) {
- }
-
- @Override
- public void process(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/EvioRecordQueue.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/EvioRecordQueue.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -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 EvioRecordQueue 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/LcioLoop.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/lcio/LcioLoop.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,36 +0,0 @@
-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. 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 implements HasErrorState {
-
- ErrorState errorState = new ErrorState();
-
- public ErrorState getErrorState() {
- return errorState;
- }
-
- /**
- * Handle errors from the Drivers.
- */
- protected void handleClientError(Throwable x) {
- getErrorState().setLastError((Exception) x);
- getErrorState().print();
- }
-
- /**
- * Handle errors from the RecordSource.
- */
- protected void handleSourceError(Throwable x) {
- getErrorState().setLastError((Exception) x);
- getErrorState().print();
- }
-}
java/trunk/record-util/src/main/java/org/hps/record/lcio
--- java/trunk/record-util/src/main/java/org/hps/record/lcio/LcioRecordQueue.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/lcio/LcioRecordQueue.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -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 LcioRecordQueue 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/processing
--- java/trunk/record-util/src/main/java/org/hps/record/processing/DataSourceType.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/DataSourceType.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,25 +0,0 @@
-package org.hps.record.processing;
-
-/**
- * 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/processing
--- java/trunk/record-util/src/main/java/org/hps/record/processing/MaxRecordsProcessor.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/MaxRecordsProcessor.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,29 +0,0 @@
-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.
- */
-// TODO: Handle max record counting in CompositeRecordAdapter.
-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/ProcessingChain.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/ProcessingChain.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,227 +0,0 @@
-package org.hps.record.processing;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.freehep.record.loop.RecordLoop.Command;
-import org.hps.record.composite.CompositeEtAdapter;
-import org.hps.record.composite.CompositeEvioAdapter;
-import org.hps.record.composite.CompositeLcioAdapter;
-import org.hps.record.composite.CompositeLoop;
-import org.hps.record.composite.CompositeLoopAdapter;
-import org.hps.record.composite.CompositeProcessor;
-import org.hps.record.et.EtProcessor;
-import org.hps.record.et.EtSource;
-import org.hps.record.evio.EvioFileSource;
-import org.hps.record.evio.EvioProcessor;
-import org.lcsim.conditions.ConditionsManager;
-import org.lcsim.util.Driver;
-import org.lcsim.util.loop.LCIOEventSource;
-import org.lcsim.util.loop.LCSimConditionsManagerImplementation;
-
-/**
- * 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.
- */
-// TODO: Replace the short loop control methods with direct calls to loop in code using this class.
-public class ProcessingChain {
-
- boolean paused;
- int maxRecords = -1;
-
- CompositeLoop compositeLoop = new CompositeLoop();
- CompositeEtAdapter etAdapter;
- CompositeEvioAdapter evioAdapter;
- CompositeLcioAdapter lcioAdapter;
- CompositeLoopAdapter compositeAdapter;
-
- /**
- * A configuration object must be supplied to use this class.
- * @param configuration The configuration of the event processing.
- */
- public ProcessingChain(ProcessingConfiguration configuration) {
- configure(configuration);
- }
-
- private void configure(ProcessingConfiguration configuration) {
- // 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)
- etAdapter = new CompositeEtAdapter(new EtSource(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) {
- evioAdapter = new CompositeEvioAdapter(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 {
- lcioAdapter = new CompositeLcioAdapter(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.");
- }
- }
-
- // Configure ET system.
- if (configuration.sourceType == DataSourceType.ET_SERVER) {
- //System.out.println("compositeLoop.addAdapter(etAdapter)");
- compositeLoop.addAdapter(etAdapter);
- }
-
- // Configure EVIO processing.
- if (configuration.processingStage.ordinal() >= ProcessingStage.EVIO.ordinal()) {
- if (configuration.sourceType.ordinal() <= DataSourceType.EVIO_FILE.ordinal()) {
- if (evioAdapter == null)
- evioAdapter = new CompositeEvioAdapter();
- //System.out.println("compositeLoop.addAdapter(evioAdapter)");
- compositeLoop.addAdapter(evioAdapter);
- }
- }
-
- // Configure LCIO processing.
- if (configuration.processingStage.ordinal() >= ProcessingStage.LCIO.ordinal()) {
- if (lcioAdapter == null)
- lcioAdapter = new CompositeLcioAdapter();
- //System.out.println("compositeLoop.addAdapter(lcioAdapter)");
- compositeLoop.addAdapter(lcioAdapter);
- if (configuration.eventBuilder != null) {
- if (configuration.detectorName != null) {
- // Is LCSim ConditionsManager installed yet?
- if (!ConditionsManager.isSetup())
- // Setup LCSim conditions system if not already.
- LCSimConditionsManagerImplementation.register();
- configuration.eventBuilder.setDetectorName(configuration.detectorName);
- } else {
- throw new IllegalArgumentException("Missing detectorName in configuration.");
- }
- lcioAdapter.setLCSimEventBuilder(configuration.eventBuilder);
- } else {
- throw new IllegalArgumentException("Missing an LCSimEventBuilder in configuration.");
- }
- }
-
- // Set whether to stop on event processing errors.
- compositeLoop.setStopOnErrors(configuration.stopOnErrors);
-
- // Add EtEventProcessors to loop.
- for (EtProcessor processor : configuration.etProcessors) {
- etAdapter.addProcessor(processor);
- }
-
- // Add EvioEventProcessors to loop.
- for (EvioProcessor processor : configuration.evioProcessors) {
- evioAdapter.addProcessor(processor);
- }
-
- // Add Drivers to loop.
- for (Driver driver : configuration.drivers) {
- lcioAdapter.addDriver(driver);
- }
-
- // Add CompositeLoopAdapter which should execute last.
- CompositeLoopAdapter compositeAdapter = new CompositeLoopAdapter();
- //System.out.println("compositeLoop.addAdapter(compositeAdapter)");
- compositeLoop.addAdapter(compositeAdapter);
-
- // Add CompositeRecordProcessors to loop.
- for (CompositeProcessor processor : configuration.compositeProcessors) {
- compositeAdapter.addProcessor(processor);
- }
-
- // Max records was set?
- if (configuration.maxRecords != -1) {
- compositeAdapter.addProcessor(new MaxRecordsProcessor(configuration.maxRecords));
- }
- }
-
- /**
- * Loop over events until processing ends for some reason.
- */
- public void run() {
-
- if (ConditionsManager.defaultInstance() == null)
- LCSimConditionsManagerImplementation.register();
-
- // Keep looping until the event processing is flagged as done.
- while (true) {
- // Is the processing unpaused?
- if (!paused) {
- // Loop until done, error occurs, or pause is requested.
- compositeLoop.execute(Command.GO, true);
-
- // Is loop done?
- if (compositeLoop.isDone()) {
- // Stop record processing.
- break;
- }
- }
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- //System.out.println("bottom of run loop");
- }
- }
-
- /**
- * Stop the event processing by halting the loop.
- */
- public void stop() {
- compositeLoop.execute(Command.STOP);
- }
-
- /**
- * Get the last error that occurred.
- * @return The last error that occurred.
- */
- public Throwable getLastError() {
- return compositeLoop.getLastError();
- }
-
- /**
- * Pause the event processing.
- */
- public void pause() {
- compositeLoop.execute(Command.PAUSE);
- paused = true;
- }
-
- /**
- * Resume event processing from pause mode.
- */
- public void resume() {
- this.paused = false;
- }
-
- /**
- * Get the next event e.g. while in pause mode.
- */
- public void next() {
- compositeLoop.execute(Command.GO_N, 1L, true);
- }
-
- public CompositeLoop getLoop() {
- return compositeLoop;
- }
-}
\ 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/processing/ProcessingConfiguration.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/ProcessingConfiguration.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,100 +0,0 @@
-package org.hps.record.processing;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.freehep.record.source.RecordSource;
-import org.hps.evio.LCSimEventBuilder;
-import org.hps.record.composite.CompositeProcessor;
-import org.hps.record.et.EtConnection;
-import org.hps.record.et.EtProcessor;
-import org.hps.record.evio.EvioProcessor;
-import org.hps.record.processing.DataSourceType;
-import org.hps.record.processing.ProcessingStage;
-import org.lcsim.util.Driver;
-
-/**
- * A configuration object for the {@link ProcessingChain}.
- * 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 ProcessingConfiguration {
-
- boolean stopOnErrors = true;
- boolean stopOnEndRun = true;
-
- int maxRecords = -1;
-
- 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<EvioProcessor> evioProcessors = new ArrayList<EvioProcessor>();
- List<Driver> drivers = new ArrayList<Driver>();
- List<CompositeProcessor> compositeProcessors = new ArrayList<CompositeProcessor>();
- List<EtProcessor> etProcessors = new ArrayList<EtProcessor>();
-
- 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 setMaxRecords(int maxRecords) {
- if (maxRecords < 1)
- throw new IllegalArgumentException("Invalid maxRecords value: " + maxRecords);
- this.maxRecords = maxRecords;
- }
-
- public void add(EtProcessor processor) {
- etProcessors.add(processor);
- }
-
- public void add(EvioProcessor processor) {
- evioProcessors.add(processor);
- }
-
- public void add(Driver processor) {
- drivers.add(processor);
- }
-
- public void add(CompositeProcessor 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/processing/ProcessingStage.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/ProcessingStage.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,10 +0,0 @@
-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/main/java/org/hps/record/processing
--- java/trunk/record-util/src/main/java/org/hps/record/processing/ProcessingThread.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/ProcessingThread.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,30 +0,0 @@
-package org.hps.record.processing;
-
-/**
- * Thread for running the event processing chain.
- */
-public final class ProcessingThread extends Thread {
-
- ProcessingChain processing;
-
- public ProcessingThread(ProcessingChain processing) {
- super("EventProcessingThread");
- this.processing = processing;
- }
-
- public ProcessingChain getEventProcessingChain() {
- return processing;
- }
-
- @Override
- public void run() {
- //System.out.println("ProcessingThread.run");
- try {
- processing.run();
- } catch (Exception e) {
- //System.out.println("Exception in ProcessingThread...");
- throw new RuntimeException("Error in event processing.", e);
- }
- //System.out.println("ProcessingThread.run - done!");
- }
-}
\ No newline at end of file
java/trunk/record-util/src/test/java/org/hps/record/composite
--- java/trunk/record-util/src/test/java/org/hps/record/composite/CompositeLoopErrorTest.java (rev 0)
+++ java/trunk/record-util/src/test/java/org/hps/record/composite/CompositeLoopErrorTest.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -0,0 +1,117 @@
+package org.hps.record.composite;
+
+import junit.framework.TestCase;
+
+import org.hps.evio.LCSimTestRunEventBuilder;
+import org.hps.record.enums.DataSourceType;
+import org.hps.record.evio.EvioEventProcessor;
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+
+/**
+ * Test the handling of various types of errors than can occurr when using the CompositeLoop.
+ */
+public class CompositeLoopErrorTest extends TestCase {
+
+ static String evioFilePath = "/nfs/slac/g/hps3/data/testcase/hps_000975.evio.0";
+
+ public void testError() {
+ LCSimTestRunEventBuilder builder = new LCSimTestRunEventBuilder();
+ builder.setDebug(false);
+ CompositeLoopConfiguration config = new CompositeLoopConfiguration()
+ .setFilePath(evioFilePath)
+ .setDataSourceType(DataSourceType.EVIO_FILE)
+ .setLCSimEventBuilder(builder)
+ .setDetectorName("HPS-TestRun-v8-5")
+ .add(new DummyErrorDriver())
+ .add(new DummyEvioProcessor());
+ CompositeLoop loop = new CompositeLoop(config);
+ loop.loop(-1);
+ }
+
+ public void testStopOnEndRun() {
+ LCSimTestRunEventBuilder builder = new LCSimTestRunEventBuilder();
+ builder.setDebug(false);
+ CompositeLoopConfiguration config = new CompositeLoopConfiguration()
+ .setFilePath(evioFilePath)
+ .setDataSourceType(DataSourceType.EVIO_FILE)
+ .setLCSimEventBuilder(builder)
+ .setDetectorName("HPS-TestRun-v8-5")
+ .add(new DummyDriver())
+ .add(new DummyEvioProcessor());
+ CompositeLoop loop = new CompositeLoop(config);
+ loop.loop(-1);
+ }
+
+ public void testContinueOnError() {
+ LCSimTestRunEventBuilder builder = new LCSimTestRunEventBuilder();
+ builder.setDebug(false);
+ CompositeLoopConfiguration config = new CompositeLoopConfiguration()
+ .setFilePath(evioFilePath)
+ .setDataSourceType(DataSourceType.EVIO_FILE)
+ .setLCSimEventBuilder(builder)
+ .setDetectorName("HPS-TestRun-v8-5")
+ .add(new DummyErrorDriver())
+ .add(new DummyEvioProcessor())
+ .setStopOnErrors(false);
+ CompositeLoop loop = new CompositeLoop(config);
+ loop.loop(-1);
+ }
+
+ public void testIgnoreEndRun() {
+ LCSimTestRunEventBuilder builder = new LCSimTestRunEventBuilder();
+ builder.setDebug(false);
+
+ CompositeLoopConfiguration config = new CompositeLoopConfiguration()
+ .setFilePath(evioFilePath)
+ .setDataSourceType(DataSourceType.EVIO_FILE)
+ .setLCSimEventBuilder(builder)
+ .setDetectorName("HPS-TestRun-v8-5")
+ .add(new DummyDriver())
+ .add(new DummyEvioProcessor())
+ .setStopOnEndRun(false);
+ CompositeLoop loop = new CompositeLoop(config);
+ loop.loop(-1);
+ }
+
+ public void testMaxRecords() {
+ LCSimTestRunEventBuilder builder = new LCSimTestRunEventBuilder();
+ builder.setDebug(false);
+ CompositeLoopConfiguration config = new CompositeLoopConfiguration()
+ .setFilePath(evioFilePath)
+ .setDataSourceType(DataSourceType.EVIO_FILE)
+ .setLCSimEventBuilder(builder)
+ .setDetectorName("HPS-TestRun-v8-5")
+ .add(new DummyDriver())
+ .add(new DummyEvioProcessor())
+ .setMaxRecords(2);
+ CompositeLoop loop = new CompositeLoop(config);
+ loop.loop(-1);
+ }
+
+ 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/composite
--- java/trunk/record-util/src/test/java/org/hps/record/composite/CompositeLoopTest.java (rev 0)
+++ java/trunk/record-util/src/test/java/org/hps/record/composite/CompositeLoopTest.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -0,0 +1,183 @@
+package org.hps.record.composite;
+
+import junit.framework.TestCase;
+
+import org.hps.evio.EventConstants;
+import org.hps.evio.LCSimEventBuilder;
+import org.hps.evio.LCSimTestRunEventBuilder;
+import org.hps.record.enums.DataSourceType;
+import org.hps.record.et.EtConnection;
+import org.hps.record.et.EtEventProcessor;
+import org.hps.record.evio.EvioEventProcessor;
+import org.jlab.coda.et.EtEvent;
+import org.jlab.coda.jevio.EvioEvent;
+import org.lcsim.event.EventHeader;
+import org.lcsim.geometry.Detector;
+import org.lcsim.job.EventMarkerDriver;
+import org.lcsim.util.Driver;
+
+public class CompositeLoopTest extends TestCase {
+
+ public void testProcessingChain() {
+
+ CompositeLoopConfiguration config = new CompositeLoopConfiguration();
+
+ LCSimEventBuilder builder = new LCSimTestRunEventBuilder();
+ builder.setDebug(false);
+
+ DummyEtProcessor etProcessor = new DummyEtProcessor();
+ DummyEvioProcessor evioProcessor = new DummyEvioProcessor();
+ DummyDriver driver = new DummyDriver();
+ DummyCompositeProcessor compositeProcessor = new DummyCompositeProcessor();
+
+ config.setDataSourceType(DataSourceType.ET_SERVER)
+ .setDetectorName("HPS-TestRun-v8-5")
+ .setEtConnection(EtConnection.createDefaultConnection())
+ .setLCSimEventBuilder(builder)
+ .setStopOnEndRun(true)
+ .setStopOnErrors(true)
+ .add(etProcessor)
+ .add(evioProcessor)
+ .add(new EventMarkerDriver())
+ .add(driver)
+ .add(compositeProcessor);
+
+ CompositeLoop loop = new CompositeLoop(config);
+ loop.loop(-1);
+
+ //
+ // Test assertions...
+ //
+ TestCase.assertTrue(etProcessor.startJobCalled);
+ TestCase.assertTrue(etProcessor.processCalled);
+ TestCase.assertTrue(etProcessor.endJobCalled);
+
+ TestCase.assertTrue(evioProcessor.startJobCalled);
+ TestCase.assertTrue(evioProcessor.processCalled);
+ TestCase.assertTrue(evioProcessor.endJobCalled);
+
+ TestCase.assertTrue(driver.startOfDataCalled);
+ TestCase.assertTrue(driver.detectorChangedCalled);
+ TestCase.assertTrue(driver.processCalled);
+ TestCase.assertTrue(driver.endOfDataCalled);
+
+ TestCase.assertTrue(compositeProcessor.startJobCalled);
+ TestCase.assertTrue(compositeProcessor.processCalled);
+ TestCase.assertTrue(compositeProcessor.endJobCalled);
+ }
+
+ static class DummyCompositeProcessor extends CompositeRecordProcessor {
+
+ boolean startJobCalled = false;
+ boolean endJobCalled = false;
+ boolean processCalled = false;
+
+ public void process(CompositeRecord record) {
+ System.out.println("DummyCompositeProcessor.process");
+ System.out.flush();
+ TestCase.assertNotNull(record);
+ TestCase.assertNotNull(record.getEtEvent());
+ TestCase.assertNotNull(record.getEvioEvent());
+ if (EventConstants.isPhysicsEvent(record.getEvioEvent()))
+ TestCase.assertNotNull(record.getLcioEvent());
+ processCalled = true;
+ }
+
+ public void startJob() {
+ System.out.println("DummyCompositeProcessor.startJob");
+ System.out.flush();
+ startJobCalled = true;
+ }
+
+ public void endJob() {
+ System.out.println("DummyCompositeProcessor.endJob");
+ System.out.flush();
+ endJobCalled = true;
+ }
+ }
+
+ static class DummyDriver extends Driver {
+
+ boolean endOfDataCalled = false;
+ boolean startOfDataCalled = false;
+ boolean processCalled = false;
+ boolean detectorChangedCalled = false;
+
+ public void process(EventHeader event) {
+ System.out.println("DummyDriver.process");
+ System.out.flush();
+ TestCase.assertNotNull(event);
+ processCalled = true;
+ }
+
+ public void endOfData() {
+ System.out.println("DummyDriver.endOfData");
+ System.out.flush();
+ endOfDataCalled = true;
+ }
+
+ public void startOfData() {
+ System.out.println("DummyDriver.startOfData");
+ System.out.flush();
+ startOfDataCalled = true;
+ }
+
+ public void detectorChanged(Detector detector) {
+ System.out.println("DummyDriver.detectorChanged");
+ System.out.flush();
+ detectorChangedCalled = true;
+ }
+ }
+
+ static class DummyEtProcessor extends EtEventProcessor {
+
+ boolean startJobCalled = false;
+ boolean endJobCalled = false;
+ boolean processCalled = false;
+
+ public void process(EtEvent event) {
+ System.out.println("DummyEtProcessor.process");
+ System.out.flush();
+ TestCase.assertNotNull(event);
+ processCalled = true;
+ }
+
+ public void startJob() {
+ System.out.println("DummyEtProcessor.startJob");
+ System.out.flush();
+ startJobCalled = true;
+ }
+
+ public void endJob() {
+ System.out.println("DummyEtProcessor.endJob");
+ System.out.flush();
+ endJobCalled = true;
+ }
+ }
+
+ static class DummyEvioProcessor extends EvioEventProcessor {
+
+ boolean startJobCalled = false;
+ boolean endJobCalled = false;
+ boolean processCalled = false;
+
+ public void process(EvioEvent event) {
+ System.out.println("DummyEvioProcessor.process");
+ System.out.flush();
+ TestCase.assertNotNull(event);
+ processCalled = true;
+ }
+
+ public void startJob() {
+ System.out.println("DummyEvioProcessor.startJob");
+ System.out.flush();
+ startJobCalled = true;
+ }
+
+ public void endJob() {
+ System.out.println("DummyEvioProcessor.endJob");
+ System.out.flush();
+ endJobCalled = true;
+ }
+ }
+}
java/trunk/record-util/src/test/java/org/hps/record/et
--- java/trunk/record-util/src/test/java/org/hps/record/et/EtLoopTest.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/test/java/org/hps/record/et/EtLoopTest.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,42 +0,0 @@
-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/et/MultiThreadedEtLoopTest.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/test/java/org/hps/record/et/MultiThreadedEtLoopTest.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,109 +0,0 @@
-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/EvioLoopTest.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/test/java/org/hps/record/evio/EvioLoopTest.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -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 EvioLoop} works.
- * @author Jeremy McCormick <[log in to unmask]>
- */
-public class EvioLoopTest 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);
-
- EvioLoop loop = new EvioLoop();
- 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 EvioProcessor {
-
- public void process(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/processing/EvioProcessingTest.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/test/java/org/hps/record/processing/EvioProcessingTest.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,77 +0,0 @@
-package org.hps.record.processing;
-
-import org.hps.evio.LCSimTestRunEventBuilder;
-import org.hps.record.evio.EvioProcessor;
-import org.hps.record.processing.DataSourceType;
-import org.hps.record.processing.ProcessingChain;
-import org.hps.record.processing.ProcessingConfiguration;
-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 EvioProcessingTest {
-
- 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() {
- ProcessingConfiguration config = new ProcessingConfiguration();
- config.setDataSourceType(DataSourceType.EVIO_FILE);
- config.setFilePath(evioFilePath);
- config.setLCSimEventBuild(new LCSimTestRunEventBuilder());
- config.setDetectorName(detectorName);
- config.add(new DummyEvioProcessor());
- config.add(new DummyDriver());
- ProcessingChain processing = new ProcessingChain(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 EvioProcessor {
-
- 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 process(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/processing/ProcessingChainErrorTest.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/test/java/org/hps/record/processing/ProcessingChainErrorTest.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,119 +0,0 @@
-package org.hps.record.processing;
-
-import junit.framework.TestCase;
-
-import org.hps.evio.LCSimTestRunEventBuilder;
-import org.hps.record.evio.EvioProcessor;
-import org.hps.record.processing.DataSourceType;
-import org.hps.record.processing.ProcessingChain;
-import org.hps.record.processing.ProcessingConfiguration;
-import org.lcsim.event.EventHeader;
-import org.lcsim.util.Driver;
-
-/**
- * Test the handling of various types of errors than can occur in the processing chain.
- */
-public class ProcessingChainErrorTest extends TestCase {
-
- static String evioFilePath = "/nfs/slac/g/hps3/data/testcase/hps_000975.evio.0";
-
- public void testError() {
- ProcessingConfiguration config = new ProcessingConfiguration();
- 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());
- ProcessingChain processing = new ProcessingChain(config);
- processing.run();
- }
-
- public void testStopOnEndRun() {
- ProcessingConfiguration config = new ProcessingConfiguration();
- 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());
- ProcessingChain processing = new ProcessingChain(config);
- processing.run();
- }
-
- public void testContinueOnError() {
- ProcessingConfiguration config = new ProcessingConfiguration();
- 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);
- ProcessingChain processing = new ProcessingChain(config);
- processing.run();
- }
-
- public void testIgnoreEndRun() {
- ProcessingConfiguration config = new ProcessingConfiguration();
- 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);
- ProcessingChain processing = new ProcessingChain(config);
- processing.run();
- }
-
- public void testMaxRecords() {
- ProcessingConfiguration config = new ProcessingConfiguration();
- 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.setMaxRecords(2);
- ProcessingChain processing = new ProcessingChain(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 EvioProcessor {
- 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/processing/ProcessingChainTest.java 2014-09-04 01:33:53 UTC (rev 950)
+++ java/trunk/record-util/src/test/java/org/hps/record/processing/ProcessingChainTest.java 2014-09-04 21:04:58 UTC (rev 951)
@@ -1,243 +0,0 @@
-package org.hps.record.processing;
-
-import junit.framework.TestCase;
-
-import org.freehep.record.loop.RecordListener;
-import org.freehep.record.loop.RecordLoop.Command;
-import org.hps.evio.EventConstants;
-import org.hps.evio.LCSimEventBuilder;
-import org.hps.evio.LCSimTestRunEventBuilder;
-import org.hps.record.composite.CompositeEtAdapter;
-import org.hps.record.composite.CompositeEvioAdapter;
-import org.hps.record.composite.CompositeLcioAdapter;
-import org.hps.record.composite.CompositeLoop;
-import org.hps.record.composite.CompositeProcessor;
-import org.hps.record.composite.CompositeRecord;
-import org.hps.record.et.EtConnection;
-import org.hps.record.et.EtProcessor;
-import org.hps.record.et.EtSource;
-import org.hps.record.evio.EvioProcessor;
-import org.jlab.coda.et.EtEvent;
-import org.jlab.coda.jevio.EvioEvent;
-import org.lcsim.event.EventHeader;
-import org.lcsim.geometry.Detector;
-import org.lcsim.job.EventMarkerDriver;
-import org.lcsim.util.Driver;
-
-public class ProcessingChainTest extends TestCase {
-
- public void testProcessingChain() {
-
- ProcessingConfiguration configuration = new ProcessingConfiguration();
- configuration.setDataSourceType(DataSourceType.ET_SERVER);
- configuration.setDetectorName("HPS-TestRun-v8-5");
- configuration.setEtConnection(EtConnection.createDefaultConnection());
- LCSimEventBuilder builder = new LCSimTestRunEventBuilder();
- builder.setDebug(false);
- configuration.setLCSimEventBuild(builder);
- configuration.setStopOnEndRun(true);
- configuration.setStopOnErrors(true);
-
- DummyEtProcessor etProcessor = new DummyEtProcessor();
- DummyEvioProcessor evioProcessor = new DummyEvioProcessor();
- DummyDriver driver = new DummyDriver();
- DummyCompositeProcessor compositeProcessor = new DummyCompositeProcessor();
-
- configuration.add(etProcessor);
- configuration.add(evioProcessor);
- configuration.add(new EventMarkerDriver());
- configuration.add(driver);
- configuration.add(compositeProcessor);
-
- ProcessingChain processing = new ProcessingChain(configuration);
- for (RecordListener listener : processing.getLoop().getRecordListeners()) {
- System.out.println("listener: " + listener.getClass().getCanonicalName());
- }
- processing.run();
-
- //
- // Test assertions...
- //
- TestCase.assertTrue(etProcessor.startJobCalled);
- TestCase.assertTrue(etProcessor.processCalled);
- TestCase.assertTrue(etProcessor.endJobCalled);
-
- TestCase.assertTrue(evioProcessor.startJobCalled);
- TestCase.assertTrue(evioProcessor.processCalled);
- TestCase.assertTrue(evioProcessor.endJobCalled);
-
- TestCase.assertTrue(driver.startOfDataCalled);
- TestCase.assertTrue(driver.detectorChangedCalled);
- TestCase.assertTrue(driver.processCalled);
- TestCase.assertTrue(driver.endOfDataCalled);
-
- TestCase.assertTrue(compositeProcessor.startJobCalled);
- TestCase.assertTrue(compositeProcessor.processCalled);
- TestCase.assertTrue(compositeProcessor.endJobCalled);
- }
-
- public void testCompositeLoop() {
-
- // Setup the primary loop.
- CompositeLoop loop = new CompositeLoop();
-
- // Setup ET system.
- EtConnection connection = EtConnection.createDefaultConnection();
- CompositeEtAdapter etAdapter = new CompositeEtAdapter(new EtSource(connection));
- DummyEtProcessor etProcessor = new DummyEtProcessor();
- etAdapter.addProcessor(etProcessor);
- loop.addAdapter(etAdapter);
-
- // Setup EVIO adapter.
- CompositeEvioAdapter evioAdapter = new CompositeEvioAdapter();
- DummyEvioProcessor evioProcessor = new DummyEvioProcessor();
- evioAdapter.addProcessor(evioProcessor);
- loop.addAdapter(evioAdapter);
-
- // Setup LCIO adapter and LCSim.
- LCSimTestRunEventBuilder builder = new LCSimTestRunEventBuilder();
- builder.setDebug(false);
- builder.setDetectorName("HPS-TestRun-v8-5");
- CompositeLcioAdapter lcioAdapter = new CompositeLcioAdapter();
- DummyDriver driver = new DummyDriver();
- lcioAdapter.addDriver(driver);
- lcioAdapter.setLCSimEventBuilder(builder);
- loop.addAdapter(lcioAdapter);
-
- // Loop over records.
- loop.execute(Command.GO, true);
- loop.dispose();
-
- //
- // Test assertions...
- //
- TestCase.assertTrue(etProcessor.startJobCalled);
- TestCase.assertTrue(etProcessor.processCalled);
- TestCase.assertTrue(etProcessor.endJobCalled);
-
- TestCase.assertTrue(evioProcessor.startJobCalled);
- TestCase.assertTrue(evioProcessor.processCalled);
- TestCase.assertTrue(evioProcessor.endJobCalled);
-
- TestCase.assertTrue(driver.startOfDataCalled);
- TestCase.assertTrue(driver.detectorChangedCalled);
- TestCase.assertTrue(driver.processCalled);
- TestCase.assertTrue(driver.endOfDataCalled);
- }
-
- static class DummyCompositeProcessor extends CompositeProcessor {
-
- boolean startJobCalled = false;
- boolean endJobCalled = false;
- boolean processCalled = false;
-
- public void process(CompositeRecord record) {
- System.out.println("DummyCompositeProcessor.process");
- System.out.flush();
- TestCase.assertNotNull(record);
- TestCase.assertNotNull(record.getEtEvent());
- TestCase.assertNotNull(record.getEvioEvent());
- if (EventConstants.isPhysicsEvent(record.getEvioEvent()))
- TestCase.assertNotNull(record.getLcioEvent());
- processCalled = true;
- }
-
- public void startJob() {
- System.out.println("DummyCompositeProcessor.startJob");
- System.out.flush();
- startJobCalled = true;
- }
-
- public void endJob() {
- System.out.println("DummyCompositeProcessor.endJob");
- System.out.flush();
- endJobCalled = true;
- }
- }
-
-
- static class DummyDriver extends Driver {
-
- boolean endOfDataCalled = false;
- boolean startOfDataCalled = false;
- boolean processCalled = false;
- boolean detectorChangedCalled = false;
-
- public void process(EventHeader event) {
- System.out.println("DummyDriver.process");
- System.out.flush();
- TestCase.assertNotNull(event);
- processCalled = true;
- }
-
- public void endOfData() {
- System.out.println("DummyDriver.endOfData");
- System.out.flush();
- endOfDataCalled = true;
- }
-
- public void startOfData() {
- System.out.println("DummyDriver.startOfData");
- System.out.flush();
- startOfDataCalled = true;
- }
-
- public void detectorChanged(Detector detector) {
- System.out.println("DummyDriver.detectorChanged");
- System.out.flush();
- detectorChangedCalled = true;
- }
- }
-
- static class DummyEtProcessor extends EtProcessor {
-
- boolean startJobCalled = false;
- boolean endJobCalled = false;
- boolean processCalled = false;
-
- public void process(EtEvent event) {
- System.out.println("DummyEtProcessor.process");
- System.out.flush();
- TestCase.assertNotNull(event);
- processCalled = true;
- }
-
- public void startJob() {
- System.out.println("DummyEtProcessor.startJob");
- System.out.flush();
- startJobCalled = true;
- }
-
- public void endJob() {
- System.out.println("DummyEtProcessor.endJob");
- System.out.flush();
- endJobCalled = true;
- }
- }
-
- static class DummyEvioProcessor extends EvioProcessor {
-
- boolean startJobCalled = false;
- boolean endJobCalled = false;
- boolean processCalled = false;
-
- public void process(EvioEvent event) {
- System.out.println("DummyEvioProcessor.process");
- System.out.flush();
- TestCase.assertNotNull(event);
- processCalled = true;
- }
-
- public void startJob() {
- System.out.println("DummyEvioProcessor.startJob");
- System.out.flush();
- startJobCalled = true;
- }
-
- public void endJob() {
- System.out.println("DummyEvioProcessor.endJob");
- System.out.flush();
- endJobCalled = true;
- }
- }
-}
SVNspam 0.1