Author: [log in to unmask]
Date: Thu Aug 27 18:40:34 2015
New Revision: 3427
Log:
More updates and changes for run db work.
Added:
java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerConfig.java
- copied, changed from r3424, java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerConfigInt.java
Removed:
java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerConfigInt.java
Modified:
java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/Crawler.java
java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunProcessor.java
java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TiTimeOffsetEvioProcessor.java
java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerConfigVariable.java
Modified: java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/Crawler.java
=============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/Crawler.java (original)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/Crawler.java Thu Aug 27 18:40:34 2015
@@ -21,8 +21,8 @@
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.hps.conditions.database.ConnectionParameters;
+import org.hps.rundb.RunDatabaseDaoFactory;
import org.hps.rundb.RunSummary;
-import org.hps.rundb.RunSummaryDaoImpl;
import org.hps.rundb.RunSummaryImpl;
import org.lcsim.util.log.DefaultLogFormatter;
import org.lcsim.util.log.LogUtil;
@@ -65,7 +65,8 @@
OPTIONS.addOption("r", "run", true, "add a run number to accept (when used others will be excluded)");
OPTIONS.addOption("t", "timestamp-file", true, "existing or new timestamp file name");
OPTIONS.addOption("w", "max-cache-wait", true, "total time to allow for file caching (seconds)");
- OPTIONS.addOption("u", "update", false, "allow replacement of existing data in the run db (not allowed by default)");
+ OPTIONS.addOption("u", "update", false,
+ "allow replacement of existing data in the run db (not allowed by default)");
OPTIONS.addOption("x", "max-depth", true, "max depth to crawl in the directory tree");
}
@@ -79,6 +80,34 @@
new Crawler().parse(args).run();
} catch (final Exception e) {
throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Process all the runs that were found.
+ *
+ * @param runs the run log containing the list of run summaries
+ * @throws Exception if there is an error processing one of the runs
+ */
+ static void processRuns(final JCacheManager cacheManager, final RunSummaryMap runs, final boolean useFileCache)
+ throws Exception {
+
+ // Process all of the runs that were found.
+ for (final RunSummary runSummary : runs.getRunSummaries()) {
+
+ // Clear the cache manager.
+ if (useFileCache) {
+ LOGGER.info("clearing file cache");
+ cacheManager.clear();
+ }
+
+ // Create a processor to process all the EVIO events in the run.
+ LOGGER.info("creating run processor for " + runSummary.getRun());
+ final RunProcessor runProcessor = new RunProcessor(cacheManager, (RunSummaryImpl) runSummary, useFileCache);
+
+ // Process all of the files from the run.
+ LOGGER.info("processing run " + runSummary.getRun());
+ runProcessor.processRun();
}
}
@@ -304,7 +333,7 @@
// Execute the run database update.
LOGGER.info("updating run database");
- this.updateRunDatabase(runs);
+ this.updateRunDatabase(runs);
LOGGER.getHandlers()[0].flush();
// Update the timestamp output file.
@@ -330,8 +359,10 @@
// Open a DB connection.
final Connection connection = config.connectionParameters().createConnection();
- // Insert all run summaries into the database.
- new RunSummaryDaoImpl(connection).insertFullRunSummaries(new ArrayList<RunSummary>(runs.getRunSummaries()),
+ final RunDatabaseDaoFactory dbFactory = new RunDatabaseDaoFactory(connection);
+
+ // Insert all run summaries into the database.
+ dbFactory.createRunSummaryDao().insertFullRunSummaries(new ArrayList<RunSummary>(runs.getRunSummaries()),
config.allowUpdates());
// Close the DB connection.
@@ -393,33 +424,5 @@
throw new RuntimeException("Error while walking the directory tree.", e);
}
}
-
- /**
- * Process all the runs that were found.
- *
- * @param runs the run log containing the list of run summaries
- * @throws Exception if there is an error processing one of the runs
- */
- static void processRuns(JCacheManager cacheManager, final RunSummaryMap runs, boolean useFileCache)
- throws Exception {
-
- // Process all of the runs that were found.
- for (final RunSummary runSummary : runs.getRunSummaries()) {
-
- // Clear the cache manager.
- if (useFileCache) {
- LOGGER.info("clearing file cache");
- cacheManager.clear();
- }
-
- // Create a processor to process all the EVIO events in the run.
- LOGGER.info("creating run processor for " + runSummary.getRun());
- final RunProcessor runProcessor = new RunProcessor(cacheManager, (RunSummaryImpl) runSummary, useFileCache);
-
- // Process all of the files from the run.
- LOGGER.info("processing run " + runSummary.getRun());
- runProcessor.processRun();
- }
- }
-
+
}
Modified: java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunProcessor.java
=============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunProcessor.java (original)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunProcessor.java Thu Aug 27 18:40:34 2015
@@ -13,7 +13,7 @@
import org.hps.record.evio.EvioLoop;
import org.hps.record.scalers.ScalersEvioProcessor;
import org.hps.record.triggerbank.TiTimeOffsetEvioProcessor;
-import org.hps.record.triggerbank.TriggerConfigInt;
+import org.hps.record.triggerbank.TriggerConfig;
import org.hps.record.triggerbank.TriggerConfigVariable;
import org.hps.rundb.RunSummaryImpl;
import org.lcsim.util.log.DefaultLogFormatter;
@@ -225,7 +225,7 @@
// Add trigger config from the trigger time processor.
LOGGER.info("updating trigger config");
- TriggerConfigInt triggerConfig = new TriggerConfigInt();
+ TriggerConfig triggerConfig = new TriggerConfig();
this.triggerTimeProcessor.updateTriggerConfig(triggerConfig);
LOGGER.info("tiTimeOffset: " + triggerConfig.get(TriggerConfigVariable.TI_TIME_OFFSET.name()));
System.out.println("tiTimeOffset: " + triggerConfig.get(TriggerConfigVariable.TI_TIME_OFFSET.name()));
Modified: java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TiTimeOffsetEvioProcessor.java
=============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TiTimeOffsetEvioProcessor.java (original)
+++ java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TiTimeOffsetEvioProcessor.java Thu Aug 27 18:40:34 2015
@@ -13,31 +13,31 @@
public class TiTimeOffsetEvioProcessor extends EvioEventProcessor {
private final IntBankDefinition headBankDefinition;
+ private long maxOffset = 0;
+
+ private final int maxOutliers = 10;
+ private final double maxRange = 1.1e9;
+ private long minOffset = 0;
+
+ private final double minRange = 0.99e9;
+ private int nOutliers = 0;
private final IntBankDefinition tiBankDefinition;
- private final double minRange = 0.99e9;
- private final double maxRange = 1.1e9;
- private final int maxOutliers = 10;
-
- private long minOffset = 0;
- private long maxOffset = 0;
- private int nOutliers = 0;
-
public TiTimeOffsetEvioProcessor() {
- headBankDefinition = new IntBankDefinition(HeadBankData.class, new int[]{0x2e, 0xe10f});
- tiBankDefinition = new IntBankDefinition(TIData.class, new int[]{0x2e, 0xe10a});
+ headBankDefinition = new IntBankDefinition(HeadBankData.class, new int[] {0x2e, 0xe10f});
+ tiBankDefinition = new IntBankDefinition(TIData.class, new int[] {0x2e, 0xe10a});
}
@Override
public void process(final EvioEvent evioEvent) {
- BaseStructure headBank = headBankDefinition.findBank(evioEvent);
- BaseStructure tiBank = tiBankDefinition.findBank(evioEvent);
+ final BaseStructure headBank = headBankDefinition.findBank(evioEvent);
+ final BaseStructure tiBank = tiBankDefinition.findBank(evioEvent);
if (headBank != null && tiBank != null) {
- int[] headData = headBank.getIntData();
- int thisTimestamp = headData[3];
- TIData tiData = new TIData(tiBank.getIntData());
+ final int[] headData = headBank.getIntData();
+ final int thisTimestamp = headData[3];
+ final TIData tiData = new TIData(tiBank.getIntData());
if (thisTimestamp != 0) {
- long offset = thisTimestamp * 1000000000L - tiData.getTime();
+ final long offset = thisTimestamp * 1000000000L - tiData.getTime();
if (minOffset == 0 || minOffset > offset) {
if (maxOffset - offset < maxRange) {
minOffset = offset;
@@ -56,12 +56,12 @@
}
}
- public void updateTriggerConfig(TriggerConfigInt triggerConfig) {
- long offsetRange = maxOffset - minOffset;
+ public void updateTriggerConfig(final TriggerConfig triggerConfig) {
+ final long offsetRange = maxOffset - minOffset;
if (offsetRange > minRange && nOutliers < maxOutliers) {
- triggerConfig.put(TriggerConfigVariable.TI_TIME_OFFSET.name(), minOffset);
+ triggerConfig.put(TriggerConfigVariable.TI_TIME_OFFSET, minOffset);
} else {
- triggerConfig.put(TriggerConfigVariable.TI_TIME_OFFSET.name(), 0L);
+ triggerConfig.put(TriggerConfigVariable.TI_TIME_OFFSET, 0L);
}
}
}
Copied: java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerConfig.java (from r3424, java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerConfigInt.java)
=============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerConfigInt.java (original)
+++ java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerConfig.java Thu Aug 27 18:40:34 2015
@@ -3,23 +3,22 @@
import java.util.HashMap;
/**
- * Trigger config information in the form of string keys and long values.
+ * Trigger config information in the form of variables with <code>long</code> values.
* <p>
- * This is not the "standard" interface using in LCSim to access trigger configuration.
- * It is used as a simplistic representation for the run database.
- *
+ * This is not the "standard" interface using in LCSim to access trigger configuration. It is used as a simplistic
+ * representation for the run database.
+ *
* @author Jeremy McCormick, SLAC
*/
@SuppressWarnings("serial")
-public class TriggerConfigInt extends HashMap<String, Long> {
-
+public class TriggerConfig extends HashMap<TriggerConfigVariable, Long> {
+
/**
- * Get a particular trigger config variable's value.
- *
- * @param variable the variable enum
- * @return the variable's value
+ * Get the TI time offset.
+ *
+ * @return the TI time offset
*/
- Long getValue(TriggerConfigVariable variable) {
- return this.get(variable.name());
+ public Long getTiTimeOffset() {
+ return this.get(TriggerConfigVariable.TI_TIME_OFFSET);
}
}
Modified: java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerConfigVariable.java
=============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerConfigVariable.java (original)
+++ java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerConfigVariable.java Thu Aug 27 18:40:34 2015
@@ -2,12 +2,22 @@
/**
* Enum for trigger config variables.
- *
+ *
* @author Jeremy McCormick, SLAC
*/
public enum TriggerConfigVariable {
+
/**
- * TI time offset
+ * TI time offset variable.
*/
- TI_TIME_OFFSET
+ TI_TIME_OFFSET;
+
+ /**
+ * Get the column name in the run database for the config variable (convenience method).
+ *
+ * @return the column name
+ */
+ public String getColumnName() {
+ return this.name().toLowerCase();
+ }
}
|