LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  March 2015

HPS-SVN March 2015

Subject:

r2379 - /java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsLoader.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Mon, 9 Mar 2015 21:25:01 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (177 lines)

Author: [log in to unmask]
Date: Mon Mar  9 14:24:55 2015
New Revision: 2379

Log:
Command line tool used to load SVT conditions into the conditions database.

Added:
    java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsLoader.java   (with props)

Added: java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsLoader.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsLoader.java	(added)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsLoader.java	Mon Mar  9 14:24:55 2015
@@ -0,0 +1,161 @@
+package org.hps.conditions.svt;
+
+import java.io.File;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+
+import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+import org.lcsim.util.log.DefaultLogFormatter;
+import org.lcsim.util.log.LogUtil;
+
+import org.hps.conditions.api.ConditionsRecord;
+import org.hps.conditions.database.DatabaseConditionsManager;
+import org.hps.conditions.database.TableMetaData;
+import org.hps.conditions.svt.SvtConditionsReader;
+import org.hps.conditions.svt.SvtDaqMapping.SvtDaqMappingCollection;
+
+/**
+ *  Command line tool used to load SVT conditions into the conditions database.
+ * 
+ *  @author Omar Moreno <[log in to unmask]>
+ */
+public class SvtConditionsLoader {
+
+    // Initialize the logger
+    private static Logger logger = LogUtil.create(SvtConditionsLoader.class.getSimpleName(), 
+            new DefaultLogFormatter(), Level.INFO);
+    
+    //-----------------//
+    //--- Constants ---//
+    //-----------------//
+    
+    // Default detector
+    public static final String DETECTOR = "HPS-Proposal2014-v9-2pt2";
+    
+    // Table names
+    public static final String DAQ_MAP_TABLE_NAME = "svt_daq_map";
+
+    //-----------------//
+    //-----------------//
+   
+	public static void main(String[] args) {
+	
+	   // Set up the command line options
+	   Options options = setupCommandLineOptions(); 
+	   
+	   // Parse the command line arguments
+	   CommandLineParser parser = new PosixParser();
+	   CommandLine commandLine = null;
+	   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;
+	   }
+	   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
+	   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")) { 
+	       File inputFile = new File(commandLine.getOptionValue("c"));
+	       try { 
+	           reader.parseCalibrations(inputFile);
+	       } 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")) { 
+	       File daqMapFile = new File(commandLine.getOptionValue("d"));
+	       logger.info("Loading DAQ map from file " + daqMapFile.getAbsolutePath());
+	       try { 
+	          
+	           // Parse the DAQ map file
+	           SvtDaqMappingCollection daqMapping = reader.parseDaqMap(daqMapFile);
+	           
+	           // 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();
+	           
+	       } 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() { 
+	    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;
+	}
+}

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use