Author: [log in to unmask]
Date: Tue Apr 21 17:42:47 2015
New Revision: 2779
Log:
Replace old method for getting collection ID from conditions manager.
Modified:
java/trunk/conditions/src/main/java/org/hps/conditions/beam/ImportBeamConditionsEngRun.java
java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java
java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsLoader.java
Modified: java/trunk/conditions/src/main/java/org/hps/conditions/beam/ImportBeamConditionsEngRun.java
=============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/beam/ImportBeamConditionsEngRun.java (original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/beam/ImportBeamConditionsEngRun.java Tue Apr 21 17:42:47 2015
@@ -37,13 +37,8 @@
private static final double NULL_VALUE = -999.0;
/**
- * Class should not be instantiated.
- */
- private ImportBeamConditionsEngRun() {
- }
-
- /**
* Import the Eng Run beam conditions from a text file.
+ *
* @param args the argument list
* @throws Exception if there is an error importing the text file
*/
@@ -75,7 +70,7 @@
if (beam.getFieldValue("current") == null) {
// Use null value to indicate beam was not measured.
beam.setFieldValue("energy", null);
- } else if (((Double) beam.getFieldValue("current")) == 0) {
+ } else if ((Double) beam.getFieldValue("current") == 0) {
// Use zero for no beam.
beam.setFieldValue("energy", 0);
} else {
@@ -89,7 +84,7 @@
System.out.println("printing beam conditions parsed from " + fileName + " ...");
System.out.println("run id current x y energy");
- for (Entry<Integer, BeamConditions> entry : beamMap.entrySet()) {
+ for (final Entry<Integer, BeamConditions> entry : beamMap.entrySet()) {
System.out.print(entry.getKey() + " ");
System.out.println(entry.getValue() + " ");
}
@@ -97,12 +92,13 @@
final DatabaseConditionsManager manager = DatabaseConditionsManager.getInstance();
manager.setLogLevel(Level.ALL);
- for (Entry<Integer, BeamConditions> entry : beamMap.entrySet()) {
+ for (final Entry<Integer, BeamConditions> entry : beamMap.entrySet()) {
final int run = entry.getKey();
final BeamConditions beam = entry.getValue();
- final int collectionId = manager.getNextCollectionID("beam");
- final ConditionsRecord record = new ConditionsRecord(
- collectionId, run, run, "beam", "beam", "imported from HPS_Runs.pdf", "eng_run");
+ final int collectionId = manager.addCollection("beam", "ImportBeamConditionsEngRun created collection by "
+ + System.getProperty("user.name"), null);
+ final ConditionsRecord record = new ConditionsRecord(collectionId, run, run, "beam", "beam",
+ "imported from HPS_Runs.pdf", "eng_run");
System.out.println(record);
System.out.println(beam);
final BeamConditionsCollection collection = new BeamConditionsCollection();
@@ -115,6 +111,7 @@
/**
* Set the value of the beam current.
+ *
* @param beam the beam conditions object
* @param fieldName the name of the field
* @param rawValue the raw value from the text file
@@ -127,4 +124,10 @@
beam.setFieldValue(fieldName, null);
}
}
+
+ /**
+ * Class should not be instantiated.
+ */
+ private ImportBeamConditionsEngRun() {
+ }
}
Modified: java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java
=============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java (original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java Tue Apr 21 17:42:47 2015
@@ -571,28 +571,6 @@
}
/**
- * Get the next collection ID for a database conditions table.
- *
- * @param tableName the name of the table
- * @return the next collection ID
- */
- public synchronized int getNextCollectionID(final String tableName) {
- final boolean openedConnection = this.openConnection();
- final ResultSet resultSet = this.selectQuery("SELECT MAX(collection_id)+1 FROM " + tableName);
- int collectionId = 1;
- try {
- resultSet.next();
- collectionId = resultSet.getInt(1);
- } catch (final SQLException e) {
- e.printStackTrace();
- logger.warning(e.getMessage());
- }
- logger.fine("new collection ID " + collectionId + " created for table " + tableName);
- this.closeConnection(openedConnection);
- return collectionId;
- }
-
- /**
* Get the combined SVT conditions for this run.
*
* @return the combined SVT conditions
@@ -744,7 +722,8 @@
}
if (collection.getCollectionId() == -1) {
try {
- collection.setCollectionId(this.getNextCollectionID(tableMetaData.getTableName()));
+ collection.setCollectionId(this.addCollection(tableMetaData.getTableName(),
+ "DatabaseConditionsManager created collection by " + System.getProperty("user.name"), null));
} catch (final ConditionsObjectException e) {
throw new RuntimeException(e);
}
Modified: java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsLoader.java
=============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsLoader.java (original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsLoader.java Tue Apr 21 17:42:47 2015
@@ -28,215 +28,204 @@
public final class SvtConditionsLoader {
/**
+ * Calibrations table name.
+ */
+ public static final String CALIBRATIONS_TABLE_NAME = "svt_calibrations";
+
+ /**
+ * SVT DAQ map table name.
+ */
+ public static final String DAQ_MAP_TABLE_NAME = "svt_daq_map";
+
+ /**
+ * Default detector name.
+ */
+ public static final String DETECTOR = "HPS-Proposal2014-v9-2pt2";
+
+ /**
* Initialize the logger.
*/
- private static Logger logger = LogUtil.create(SvtConditionsLoader.class.getName(),
- new DefaultLogFormatter(), Level.INFO);
-
- /**
- * Default detector name.
- */
- public static final String DETECTOR = "HPS-Proposal2014-v9-2pt2";
-
- /**
- * SVT DAQ map table name.
- */
- public static final String DAQ_MAP_TABLE_NAME = "svt_daq_map";
-
- /**
- * Calibrations table name.
- */
- public static final String CALIBRATIONS_TABLE_NAME = "svt_calibrations";
+ private static Logger logger = LogUtil.create(SvtConditionsLoader.class.getName(), new DefaultLogFormatter(),
+ Level.INFO);
/**
* SVT channels table name.
*/
public static final String SVT_CHANNELS_TABLE_NAME = "svt_channels";
-
+
+ /**
+ * Run this class from the command line.
+ *
+ * @param args The command line arguments.
+ */
+ public static void main(final String[] args) {
+
+ // Set up the command line options
+ final Options options = setupCommandLineOptions();
+
+ // Parse the command line arguments
+ final CommandLineParser parser = new PosixParser();
+ final CommandLine commandLine;
+ try {
+ commandLine = parser.parse(options, args);
+ } catch (final ParseException e) {
+ throw new RuntimeException("Unable to parse command line arguments.", e);
+ }
+
+ // Get the run number. If a run number hasn't been set, warn the user and exit.
+ if (!commandLine.hasOption("r")) {
+ System.out.println("\nPlease specify a run number to associate with the conditions set.\n");
+ return;
+ }
+ final int runNumber = Integer.valueOf(commandLine.getOptionValue("r"));
+ logger.info("Run number set to " + runNumber);
+
+ // Initialize the conditions system and load the conditions onto the
+ // detector object
+ try {
+
+ // If a user has specified the connection properties, set them, otherwise use the default values.
+ if (commandLine.hasOption("p")) {
+ DatabaseConditionsManager.getInstance().setConnectionProperties(
+ new File(commandLine.getOptionValue("p")));
+ }
+ DatabaseConditionsManager.getInstance().setDetector(SvtConditionsLoader.DETECTOR, runNumber);
+ } catch (final ConditionsNotFoundException e) {
+ throw new RuntimeException("Could not initialize the conditions system.", e);
+ }
+
+ // Instantiate the SVT conditions reader
+ final SvtConditionsReader reader;
+ try {
+ reader = new SvtConditionsReader();
+ } catch (final Exception e) {
+ throw new RuntimeException("Couldn't open SvtConditionsReader.", e);
+ }
+
+ // If a calibrations file has been specified, parse it and load them
+ // to the conditions database.
+ if (commandLine.hasOption("c")) {
+ final File calibrationFile = new File(commandLine.getOptionValue("c"));
+ logger.info("Loading calibrations from file " + calibrationFile.getAbsolutePath());
+ try {
+
+ // Parse the calibration file and retrieve the calibrations collection.
+ reader.parseCalibrations(calibrationFile);
+ final SvtCalibrationCollection calibrations = reader.getSvtCalibrationCollection();
+
+ // Set the table meta data
+ final TableMetaData tableMetaData = DatabaseConditionsManager.getInstance().findTableMetaData(
+ SvtConditionsLoader.CALIBRATIONS_TABLE_NAME);
+ calibrations.setTableMetaData(tableMetaData);
+
+ // Set the collection ID.
+ final int collectionID = DatabaseConditionsManager.getInstance().addCollection(
+ SvtConditionsLoader.CALIBRATIONS_TABLE_NAME,
+ "added with SvtConditionsLoader by " + System.getProperty("user.name"), null);
+ calibrations.setCollectionId(collectionID);
+ logger.info("Using collection ID " + collectionID);
+
+ // Load the calibrations
+ calibrations.insert();
+ logger.info("A total of " + calibrations.size()
+ + " SvtCalibrations were loaded successfully into the database.");
+
+ // Create a conditions record associated with the set of conditions that were just loaded.
+ final ConditionsRecord conditionsRecord = new ConditionsRecord(calibrations.getCollectionId(),
+ runNumber, 99999, SvtConditionsLoader.CALIBRATIONS_TABLE_NAME,
+ SvtConditionsLoader.CALIBRATIONS_TABLE_NAME,
+ "Pedestals and noise. Loaded using SvtConditionsLoader.", "eng_run");
+ conditionsRecord.insert();
+
+ } catch (final Exception e) {
+ throw new RuntimeException("Couldn't parse calibration file.", e);
+ }
+ }
+
+ // If a DAQ map file has been specified, parse it and load them to the
+ // conditions database.
+ if (commandLine.hasOption("d")) {
+ final File daqMapFile = new File(commandLine.getOptionValue("d"));
+ logger.info("Loading DAQ map from file " + daqMapFile.getAbsolutePath());
+ try {
+
+ // Parse the DAQ map file
+ reader.parseDaqMap(daqMapFile);
+ final SvtDaqMappingCollection daqMapping = reader.getDaqMapCollection();
+
+ // Set the table meta data
+ TableMetaData tableMetaData = DatabaseConditionsManager.getInstance().findTableMetaData(
+ SvtConditionsLoader.DAQ_MAP_TABLE_NAME);
+ daqMapping.setTableMetaData(tableMetaData);
+
+ // Set the collection ID
+ int collectionID = DatabaseConditionsManager.getInstance().addCollection(
+ SvtConditionsLoader.DAQ_MAP_TABLE_NAME,
+ "added with SvtConditionsLoader by " + System.getProperty("user.name"), null);
+ daqMapping.setCollectionId(collectionID);
+ logger.info("Using collection ID " + collectionID);
+
+ // Load the DAQ map
+ daqMapping.insert();
+ logger.info("DAQ map has been loaded successfully");
+ logger.fine(daqMapping.toString());
+
+ // Create a conditions record associated with the set of
+ // conditions that were just loaded.
+ ConditionsRecord conditionsRecord = new ConditionsRecord(daqMapping.getCollectionId(), runNumber,
+ 99999, SvtConditionsLoader.DAQ_MAP_TABLE_NAME, SvtConditionsLoader.DAQ_MAP_TABLE_NAME,
+ "Engineering run DAQ map. Loaded using SvtConditionsLoader.", "eng_run");
+ conditionsRecord.insert();
+
+ logger.info("Loading the collection of SvtChannel's");
+ final SvtChannelCollection svtChannels = reader.getSvtChannelCollection();
+
+ // Set the table meta data
+ tableMetaData = DatabaseConditionsManager.getInstance().findTableMetaData(
+ SvtConditionsLoader.SVT_CHANNELS_TABLE_NAME);
+ svtChannels.setTableMetaData(tableMetaData);
+
+ // Set the collection ID
+ collectionID = DatabaseConditionsManager.getInstance().addCollection(
+ SvtConditionsLoader.SVT_CHANNELS_TABLE_NAME,
+ "added with SvtConditionsLoader by " + System.getProperty("user.name"), null);
+ svtChannels.setCollectionId(collectionID);
+ logger.info("Using collection ID " + collectionID);
+
+ svtChannels.insert();
+ logger.info("A total of " + svtChannels.size()
+ + " SvtChannels were successfully loaded into the database.");
+
+ // Create a conditions record associated with the set of
+ // conditions that were just loaded.
+ conditionsRecord = new ConditionsRecord(svtChannels.getCollectionId(), runNumber, 99999,
+ SvtConditionsLoader.SVT_CHANNELS_TABLE_NAME, SvtConditionsLoader.SVT_CHANNELS_TABLE_NAME,
+ "Engineering run SVT channel IDs. Loaded using SvtConditionsLoader.", "eng_run");
+ conditionsRecord.insert();
+ } catch (final Exception e) {
+ throw new RuntimeException("Couldn't parse DAQ map file.", e);
+ }
+ }
+ }
+
+ /**
+ * Method used to setup all command line options.
+ *
+ * @return a set of options
+ */
+ private static Options setupCommandLineOptions() {
+ final Options options = new Options();
+ options.addOption(new Option("r", true, "Run number"));
+ options.addOption(new Option("p", true, "Path to properties file"));
+ options.addOption(new Option("c", true, "Calibration file"));
+ options.addOption(new Option("d", true, "DAQ map file"));
+ return options;
+ }
+
/**
* Do not allow instantiation.
*/
private SvtConditionsLoader() {
throw new UnsupportedOperationException("Do not instantiate this class.");
}
-
- /**
- * Run this class from the command line.
- * @param args The command line arguments.
- */
- public static void main(final String[] args) {
-
- // Set up the command line options
- final Options options = setupCommandLineOptions();
-
- // Parse the command line arguments
- final CommandLineParser parser = new PosixParser();
- final CommandLine commandLine;
- try {
- commandLine = parser.parse(options, args);
- } catch (ParseException e) {
- throw new RuntimeException("Unable to parse command line arguments.", e);
- }
-
- // Get the run number. If a run number hasn't been set, warn the user and exit.
- if (!commandLine.hasOption("r")) {
- System.out.println("\nPlease specify a run number to associate with the conditions set.\n");
- return;
- }
- final int runNumber = Integer.valueOf(commandLine.getOptionValue("r"));
- logger.info("Run number set to " + runNumber);
-
- // Initialize the conditions system and load the conditions onto the
- // detector object
- try {
-
- // If a user has specified the connection properties, set them, otherwise use the default values.
- if (commandLine.hasOption("p")) {
- DatabaseConditionsManager.getInstance()
- .setConnectionProperties(new File(commandLine.getOptionValue("p")));
- }
- DatabaseConditionsManager.getInstance()
- .setDetector(SvtConditionsLoader.DETECTOR, runNumber);
- } catch (ConditionsNotFoundException e) {
- throw new RuntimeException("Could not initialize the conditions system.", e);
- }
-
- // Instantiate the SVT conditions reader
- final SvtConditionsReader reader;
- try {
- reader = new SvtConditionsReader();
- } catch (Exception e) {
- throw new RuntimeException("Couldn't open SvtConditionsReader.", e);
- }
-
- // If a calibrations file has been specified, parse it and load them
- // to the conditions database.
- if (commandLine.hasOption("c")) {
- final File calibrationFile = new File(commandLine.getOptionValue("c"));
- logger.info("Loading calibrations from file " + calibrationFile.getAbsolutePath());
- try {
-
- // Parse the calibration file and retrieve the calibrations collection.
- reader.parseCalibrations(calibrationFile);
- final SvtCalibrationCollection calibrations = reader.getSvtCalibrationCollection();
-
- // Set the table meta data
- final TableMetaData tableMetaData = DatabaseConditionsManager.getInstance()
- .findTableMetaData(SvtConditionsLoader.CALIBRATIONS_TABLE_NAME);
- calibrations.setTableMetaData(tableMetaData);
-
- // Set the collection ID.
- final int collectionID = DatabaseConditionsManager.getInstance()
- .getNextCollectionID(SvtConditionsLoader.CALIBRATIONS_TABLE_NAME);
- calibrations.setCollectionId(collectionID);
- logger.info("Using collection ID " + collectionID);
-
- // Load the calibrations
- calibrations.insert();
- logger.info("A total of " + calibrations.size()
- + " SvtCalibrations were loaded successfully into the database.");
-
- // Create a conditions record associated with the set of conditions that were just loaded.
- final ConditionsRecord conditionsRecord = new ConditionsRecord(
- calibrations.getCollectionId(),
- runNumber,
- 99999,
- SvtConditionsLoader.CALIBRATIONS_TABLE_NAME,
- SvtConditionsLoader.CALIBRATIONS_TABLE_NAME,
- "Pedestals and noise. Loaded using SvtConditionsLoader.",
- "eng_run");
- conditionsRecord.insert();
-
- } catch (Exception e) {
- throw new RuntimeException("Couldn't parse calibration file.", e);
- }
- }
-
- // If a DAQ map file has been specified, parse it and load them to the
- // conditions database.
- if (commandLine.hasOption("d")) {
- final File daqMapFile = new File(commandLine.getOptionValue("d"));
- logger.info("Loading DAQ map from file " + daqMapFile.getAbsolutePath());
- try {
-
- // Parse the DAQ map file
- reader.parseDaqMap(daqMapFile);
- final SvtDaqMappingCollection daqMapping = reader.getDaqMapCollection();
-
- // Set the table meta data
- TableMetaData tableMetaData = DatabaseConditionsManager.getInstance().findTableMetaData(
- SvtConditionsLoader.DAQ_MAP_TABLE_NAME);
- daqMapping.setTableMetaData(tableMetaData);
-
- // Set the collection ID
- int collectionID = DatabaseConditionsManager.getInstance().getNextCollectionID(
- SvtConditionsLoader.DAQ_MAP_TABLE_NAME);
- daqMapping.setCollectionId(collectionID);
- logger.info("Using collection ID " + collectionID);
-
- // Load the DAQ map
- daqMapping.insert();
- logger.info("DAQ map has been loaded successfully");
- logger.fine(daqMapping.toString());
-
- // Create a conditions record associated with the set of
- // conditions that were just loaded.
- ConditionsRecord conditionsRecord = new ConditionsRecord(
- daqMapping.getCollectionId(),
- runNumber,
- 99999,
- SvtConditionsLoader.DAQ_MAP_TABLE_NAME,
- SvtConditionsLoader.DAQ_MAP_TABLE_NAME,
- "Engineering run DAQ map. Loaded using SvtConditionsLoader.",
- "eng_run");
- conditionsRecord.insert();
-
- logger.info("Loading the collection of SvtChannel's");
- final SvtChannelCollection svtChannels = reader.getSvtChannelCollection();
-
- // Set the table meta data
- tableMetaData = DatabaseConditionsManager.getInstance().findTableMetaData(
- SvtConditionsLoader.SVT_CHANNELS_TABLE_NAME);
- svtChannels.setTableMetaData(tableMetaData);
-
- // Set the collection ID
- collectionID = DatabaseConditionsManager.getInstance().getNextCollectionID(
- SvtConditionsLoader.SVT_CHANNELS_TABLE_NAME);
- svtChannels.setCollectionId(collectionID);
- logger.info("Using collection ID " + collectionID);
-
- svtChannels.insert();
- logger.info("A total of " + svtChannels.size()
- + " SvtChannels were successfully loaded into the database.");
-
- // Create a conditions record associated with the set of
- // conditions that were just loaded.
- conditionsRecord = new ConditionsRecord(
- svtChannels.getCollectionId(),
- runNumber,
- 99999,
- SvtConditionsLoader.SVT_CHANNELS_TABLE_NAME,
- SvtConditionsLoader.SVT_CHANNELS_TABLE_NAME,
- "Engineering run SVT channel IDs. Loaded using SvtConditionsLoader.",
- "eng_run");
- conditionsRecord.insert();
- } catch (Exception e) {
- throw new RuntimeException("Couldn't parse DAQ map file.", e);
- }
- }
- }
-
- /**
- * Method used to setup all command line options.
- *
- * @return a set of options
- */
- private static Options setupCommandLineOptions() {
- final Options options = new Options();
- options.addOption(new Option("r", true, "Run number"));
- options.addOption(new Option("p", true, "Path to properties file"));
- options.addOption(new Option("c", true, "Calibration file"));
- options.addOption(new Option("d", true, "DAQ map file"));
- return options;
- }
}
|