11 modified files
java/trunk/record-util/src/main/java/org/hps/record
--- java/trunk/record-util/src/main/java/org/hps/record/AbstractRecordProcessor.java 2014-09-04 21:36:13 UTC (rev 953)
+++ java/trunk/record-util/src/main/java/org/hps/record/AbstractRecordProcessor.java 2014-09-05 18:16:21 UTC (rev 954)
@@ -1,6 +1,5 @@
package org.hps.record;
-import org.freehep.record.loop.LoopEvent;
/**
* An abstract implementation of {@link RecordProcessor} with "no op" method implementions.
java/trunk/record-util/src/main/java/org/hps/record
--- java/trunk/record-util/src/main/java/org/hps/record/AbstractRecordQueue.java 2014-09-04 21:36:13 UTC (rev 953)
+++ java/trunk/record-util/src/main/java/org/hps/record/AbstractRecordQueue.java 2014-09-05 18:16:21 UTC (rev 954)
@@ -10,7 +10,9 @@
/**
* Implementation of <tt>AbstractRecordSource</tt> using a dynamic queue that
- * can receive events "on the fly" e.g. from an ET ring.
+ * can receive events "on the fly" e.g. from an ET ring. Polling is used in the
+ * {@link #next()} method to get the next record, which might not be immediately
+ * available.
*/
public abstract class AbstractRecordQueue<RecordType> extends AbstractRecordSource {
java/trunk/record-util/src/main/java/org/hps/record
--- java/trunk/record-util/src/main/java/org/hps/record/EndRunException.java 2014-09-04 21:36:13 UTC (rev 953)
+++ java/trunk/record-util/src/main/java/org/hps/record/EndRunException.java 2014-09-05 18:16:21 UTC (rev 954)
@@ -12,6 +12,10 @@
this.runNumber = runNumber;
}
+ /**
+ * Get the run number.
+ * @return The run number.
+ */
public int getRunNumber() {
return runNumber;
}
java/trunk/record-util/src/main/java/org/hps/record
--- java/trunk/record-util/src/main/java/org/hps/record/MaxRecordsException.java 2014-09-04 21:36:13 UTC (rev 953)
+++ java/trunk/record-util/src/main/java/org/hps/record/MaxRecordsException.java 2014-09-05 18:16:21 UTC (rev 954)
@@ -1,8 +1,9 @@
package org.hps.record;
/**
- * Exception to be thrown when maximum number of records is reached.
+ * Exception thrown when maximum number of records is reached.
*/
+// FIXME: Use loop(nevents) instead of this for controlling number of records run.
public class MaxRecordsException extends Exception {
int maxRecords;
@@ -12,6 +13,10 @@
this.maxRecords = maxRecords;
}
+ /**
+ * Get the maximum number of records.
+ * @return The maximum number of records.
+ */
public int getMaxRecords() {
return maxRecords;
}
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 21:36:13 UTC (rev 953)
+++ java/trunk/record-util/src/main/java/org/hps/record/RecordProcessingException.java 2014-09-05 18:16:21 UTC (rev 954)
@@ -1,10 +1,14 @@
package org.hps.record;
/**
- * Error type for exceptions that occur during event processing.
+ * Generic error type for exceptions that occur during event processing.
+ * It extends <code>RuntimeException</code> so that methods need not
+ * declare a <code>throws</code> clause in their definitions to use it.
*/
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 21:36:13 UTC (rev 953)
+++ java/trunk/record-util/src/main/java/org/hps/record/RecordProcessor.java 2014-09-05 18:16:21 UTC (rev 954)
@@ -1,7 +1,11 @@
package org.hps.record;
/**
- * This is a generic interface for event processing.
+ * This is a generic interface for event processing which implements
+ * hooks for starting the job, starting a new run, processing individual
+ * records, ending a run and ending a job. This interface should not
+ * be implemented directly. Instead the {@link AbstractRecordProcessor}
+ * should be extended with a specific type declaration.
*
* @param <RecordType> The concrete type of the event record.
*/
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 21:36:13 UTC (rev 953)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoop.java 2014-09-05 18:16:21 UTC (rev 954)
@@ -2,12 +2,10 @@
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.RecordLoop.Command;
import org.freehep.record.source.NoSuchRecordException;
import org.freehep.record.source.RecordSource;
import org.hps.record.EndRunException;
@@ -39,19 +37,39 @@
CompositeLoopConfiguration config = null;
+ /**
+ * No argument constructor.
+ * The {@link #configure(CompositeLoopConfiguration)} method must be
+ * called on the loop manually.
+ */
public CompositeLoop() {
setRecordSource(recordSource);
}
+ /**
+ * Create the loop with the given configuration.
+ * @param config The configuration parameters of the loop.
+ */
public CompositeLoop(CompositeLoopConfiguration config) {
setRecordSource(recordSource);
configure(config);
}
+ /**
+ * Set to true in order to have this loop stop on all
+ * event processing errors. Certain types of fatal errors
+ * will never be ignored.
+ * @param stopOnErrors True for this loop to stop on errors.
+ */
public void setStopOnErrors(boolean stopOnErrors) {
this.stopOnErrors = stopOnErrors;
}
+ /**
+ * Add a {@link CompositeLoopAdapter} which will process
+ * {@link CompositeRecord} objects.
+ * @param adapter The CompositeLoopAdapter object.
+ */
public void addAdapter(CompositeLoopAdapter adapter) {
addLoopListener(adapter);
addRecordListener(adapter);
@@ -68,7 +86,7 @@
}
/**
- * Handle errors in the client such as adapters.
+ * Handle errors from the client such as registered adapters.
* If the loop is setup to try and continue on errors,
* only non-fatal record processing exceptions are ignored.
*/
@@ -90,6 +108,9 @@
done = true;
}
+ /**
+ * Handle errors thrown by the <code>RecordSource</code>.
+ */
protected void handleSourceError(Throwable x) {
x.printStackTrace();
@@ -108,6 +129,14 @@
done = true;
}
+ /**
+ * True if an error is ignorable. If <code>stopOnErrors</code>
+ * is true, then this method always returns false. Otherwise,
+ * the error cause determines whether the loop can continue
+ * processing.
+ * @param x The error that occurred.
+ * @return True if the error can be ignored.
+ */
private boolean isIgnorable(Throwable x) {
// Should the loop try to recover from the error if possible?
@@ -144,10 +173,19 @@
}
}
+ /**
+ * True if the loop is done processing. This is
+ * set to <code>true</code> when fatal errors occur.
+ * @return
+ */
public boolean isDone() {
return done;
}
+ /**
+ * Get the last error that occurred.
+ * @return The last error that occurred.
+ */
public Throwable getLastError() {
return _exception;
}
@@ -167,10 +205,19 @@
paused = false;
}
+ /**
+ * True if loop is paused.
+ * @return True if loop is current paused.
+ */
public boolean isPaused() {
return paused;
}
+ /**
+ * Loop over events from the source.
+ * @param number The number of events to process or -1 for unlimited.
+ * @return The number of records that were processed.
+ */
public long loop(long number) {
if (number < 0L) {
execute(Command.GO, true);
@@ -181,6 +228,10 @@
return getSupplied();
}
+ /**
+ * Configure the loop using a {@link CompositeLoopConfiguration} object.
+ * @param config The CompositeLoopConfiguration object containing the loop configuration parameter values.
+ */
public final void configure(CompositeLoopConfiguration config) {
if (this.config != null)
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 21:36:13 UTC (rev 953)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoopAdapter.java 2014-09-05 18:16:21 UTC (rev 954)
@@ -11,6 +11,9 @@
/**
* Adapter for listening on the {@link CompositeLoop} for records and loop events.
+ * Classes that should be part of an "event processing chain" implemented by the
+ * {@link CompositeLoop} should extend this API in order to receive {@link CompositeRecord}
+ * objects that can be modified.
*/
public class CompositeLoopAdapter extends AbstractLoopListener implements RecordListener {
@@ -52,8 +55,6 @@
*/
@Override
public void recordSupplied(RecordEvent record) {
- //System.out.println("CompositeLoopAdapter.recordSupplied");
- //System.out.flush();
for (CompositeRecordProcessor processor : processors) {
try {
// Activate the processing step on the CompositeRecord.
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoopConfiguration.java 2014-09-04 21:36:13 UTC (rev 953)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoopConfiguration.java 2014-09-05 18:16:21 UTC (rev 954)
@@ -14,10 +14,16 @@
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.
+ * A configuration object for the {@link CompositeLoop}.
+ *
+ * The instance variables are readable within the package,
+ * e.g. by {@link CompositeLoop}, but their values must be
+ * set through the public set methods when the class is
+ * used outside its package.
+ *
+ * Depending on how this object is setup, some arguments
+ * may end up being ignored (e.g. setting a file path
+ * when actually using an ET server, etc.).
*/
public class CompositeLoopConfiguration {
@@ -39,52 +45,113 @@
List<Driver> drivers = new ArrayList<Driver>();
List<CompositeRecordProcessor> compositeProcessors = new ArrayList<CompositeRecordProcessor>();
List<EtEventProcessor> etProcessors = new ArrayList<EtEventProcessor>();
-
+
+ /**
+ * Set the full path to a file being used as an event source.
+ * This is ignored if the ET system is being used.
+ * @param filePath The full path to a file.
+ * @return This object.
+ */
public CompositeLoopConfiguration setFilePath(String filePath) {
this.filePath = filePath;
return this;
}
+ /**
+ * Set the ET connection parameters.
+ * This is ignored if using direct file streaming.
+ * @param connection The ET connection parameters.
+ * @return This object.
+ */
public CompositeLoopConfiguration setEtConnection(EtConnection connection) {
this.connection = connection;
return this;
}
+ /**
+ * Set the data source type e.g. ET server, EVIO file or LCIO file.
+ * @param sourceType The data source type.
+ * @return This object.
+ */
public CompositeLoopConfiguration setDataSourceType(DataSourceType sourceType) {
this.sourceType = sourceType;
return this;
}
+ /**
+ * Set the processing stage to include i.e. ET only, ET to EVIO, or EVIO to LCIO.
+ * This may be ignored if the argument does not make sense given the
+ * {@link org.hps.record.enums.DataSourceType} of this configuration.
+ * @param processingStage The processing stage to include in the record chaining.
+ * @return This object.
+ */
public CompositeLoopConfiguration setProcessingStage(ProcessingStage processingStage) {
this.processingStage = processingStage;
return this;
}
+ /**
+ * Set directly the <code>RecordSource</code> that will supply records.
+ * @param recordSource The <code>RecordSource</code> that will supply records.
+ * @return This object.
+ */
public CompositeLoopConfiguration setRecordSource(RecordSource recordSource) {
this.recordSource = recordSource;
return this;
}
+ /**
+ * Set the <code>LCSimEventBuilder</code> that will be used to translate from raw EVIO
+ * events to LCIO.
+ *
+ * The detector name will be set on this object from within {@link CompositeLoop}.
+ *
+ * @param eventBuilder The LCSimEventBuilder object.
+ * @return This object.
+ */
public CompositeLoopConfiguration setLCSimEventBuilder(LCSimEventBuilder eventBuilder) {
this.eventBuilder = eventBuilder;
return this;
}
+ /**
+ * Set the name of the detector definition to be used e.g. from detector-data/detectors dir.
+ * @param detectorName The name of the detector.
+ * @return This object.
+ */
public CompositeLoopConfiguration setDetectorName(String detectorName) {
this.detectorName = detectorName;
return this;
}
+ /**
+ * Set whether the loop will stop when event processing errors occur.
+ * Certain types of errors are considered fatal or are used to control
+ * the loop and will never be ignored (e.g. ET system errors, etc.).
+ * @param stopOnErrors True to stop the loop when errors occur.
+ * @return This object.
+ */
public CompositeLoopConfiguration setStopOnErrors(boolean stopOnErrors) {
this.stopOnErrors = stopOnErrors;
return this;
}
+ /**
+ * Set whether loop will stop when an end of run record is encountered
+ * e.g. from an EvioEvent.
+ * @param stopOnEndRun True to stop on end of run.
+ * @return This object.
+ */
public CompositeLoopConfiguration setStopOnEndRun(boolean stopOnEndRun) {
this.stopOnEndRun = stopOnEndRun;
return this;
}
+ /**
+ * Set the maximum number of records to run.
+ * @param maxRecords
+ * @return
+ */
public CompositeLoopConfiguration setMaxRecords(int maxRecords) {
if (maxRecords < 1)
throw new IllegalArgumentException("Invalid maxRecords value: " + maxRecords);
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeRecord.java 2014-09-04 21:36:13 UTC (rev 953)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeRecord.java 2014-09-05 18:16:21 UTC (rev 954)
@@ -6,7 +6,9 @@
/**
* This class is used to group together corresponding ET, EVIO and LCIO events
- * for use by the {@link CompositeLoop}.
+ * for use by the {@link CompositeLoop}. The loop's <code>RecordListener</code>
+ * objects may alter this record by setting references to event objects
+ * such as an <code>EvioEvent</code>.
*/
public final class CompositeRecord {
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/EventProcessingThread.java 2014-09-04 21:36:13 UTC (rev 953)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/EventProcessingThread.java 2014-09-05 18:16:21 UTC (rev 954)
@@ -1,9 +1,7 @@
package org.hps.record.composite;
-import org.freehep.record.loop.RecordLoop.Command;
-
/**
- * Thread for running the event processing chain.
+ * Class for running the {@link CompositeLoop} on a separate thread.
*/
public final class EventProcessingThread extends Thread {
@@ -22,14 +20,15 @@
// Is the processing unpaused?
if (!loop.isPaused()) {
- // Loop until done, error occurs, or pause is requested.
+ // Loop until done, error occurs, or pause is requested.
+ // FIXME: The maximum number of records should be used here.
loop.loop(-1);
// Is loop done?
if (loop.isDone()) {
// Stop record processing.
break;
- }
+ }
}
// Sleep for a little while between loop iterations (e.g. while paused).
SVNspam 0.1