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  November 2014

HPS-SVN November 2014

Subject:

r1526 - /java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java

From:

[log in to unmask]

Reply-To:

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

Date:

Fri, 14 Nov 2014 20:57:36 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (180 lines)

Author: [log in to unmask]
Date: Fri Nov 14 12:57:33 2014
New Revision: 1526

Log:
Choose an XML config based on run number in initialize.  Small modifications to log print outs.

Modified:
    java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java

Modified: java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java	(original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java	Fri Nov 14 12:57:33 2014
@@ -55,7 +55,9 @@
     protected Connection connection;
     protected boolean isConnected = false;
     protected ConditionsSeriesConverter conditionsSeriesConverter = new ConditionsSeriesConverter(this);
-    protected static final String DEFAULT_CONFIG = "/org/hps/conditions/config/conditions_dev.xml";
+    static final String DEFAULT_CONFIG = "/org/hps/conditions/config/conditions_dev.xml";
+    static final String TEST_RUN_CONFIG = "/org/hps/conditions/config/conditions_database_testrun_2012.xml";
+    protected static final int TEST_RUN_MAX_RUN = 1365;
     protected boolean isInitialized = false;
     protected String resourceConfig = null;
     protected File fileConfig = null;
@@ -77,17 +79,17 @@
             this.database = "hps_conditions";
             
             try {
-                // Are we running from inside the JAB network?
+                // Are we running inside the JLAB network?
                 if (InetAddress.getLocalHost().getHostName().contains("jlab.org")) {
-                    // Override the defaults and use parameters for the JLAB database.
+                    // Use the JLAB database.
                     this.hostname = "jmysql.jlab.org";                    
                 } 
             } catch (UnknownHostException e) {
-                // Something wrong with the user's host name, but just assume we can continue okay.
-                logger.log(Level.WARNING, e.getMessage());
+                // Something wrong with the user's host name, but try to continue anyways.
+                logger.log(Level.WARNING, e.getMessage(), e);
             }
             
-            // This user name and password are setup for read only access on both databases.
+            // This user name and password are setup for read-only access on both databases.
             this.user = "hpsuser";
             this.password = "darkphoton";
         }
@@ -97,6 +99,7 @@
      * Class constructor.
      */
     public DatabaseConditionsManager() {
+        logger.setLevel(Level.FINE);
         registerConditionsConverter(new DetectorConditionsConverter());
         setupConnectionFromSystemProperty();
         register();
@@ -144,7 +147,7 @@
         //logger.config("password " + connectionParameters.getPassword());
         logger.config("database " + connectionParameters.getDatabase());
         connection = connectionParameters.createConnection();
-        logger.config("created connection " + connectionParameters.getConnectionString());
+        logger.config("successfuly created connection");
         isConnected = true;
     }
 
@@ -158,7 +161,7 @@
                 if (!connection.isClosed()) {
                     connection.close();
                 } else {
-                    logger.config("connection was already closed");
+                    logger.info("connection was already closed");
                 }
             } catch (SQLException e) {
                 throw new RuntimeException(e);
@@ -215,8 +218,7 @@
         logger.finest("detector " + detectorName + " and run #" + runNumber);
         
         if (!isInitialized) {
-            logger.log(Level.CONFIG, "initializing " + getClass().getSimpleName());
-            initialize();
+            initialize(runNumber);
         }
         
         // Let the super class do whatever it think it needs to do.
@@ -227,10 +229,22 @@
      * Perform all necessary initialization, including setup of the XML
      * configuration and opening a connection to the database.
      */
-    protected void initialize() {
-        
+    protected void initialize(int runNumber) {
+
+        logger.log(Level.CONFIG, "initializing " + getClass().getSimpleName());
+
+        // Did the user not specify a config? 
         if (resourceConfig == null && fileConfig == null) {
-            this.resourceConfig = DatabaseConditionsManager.DEFAULT_CONFIG;
+            // We will try to pick a reasonable config based on the run number...
+            if (runNumber > 0 && runNumber <= TEST_RUN_MAX_RUN) {
+                // This looks like the Test Run so use the custom config for it.
+                this.resourceConfig = DatabaseConditionsManager.TEST_RUN_CONFIG;
+                logger.config("using test run XML config " + this.resourceConfig);
+            } else { 
+                // This is probably the Engineering Run or later so use the default config.
+                this.resourceConfig = DatabaseConditionsManager.DEFAULT_CONFIG;
+                logger.config("using default XML config " + this.resourceConfig);
+            }
         }
         
         if (resourceConfig != null && fileConfig != null) {
@@ -241,7 +255,7 @@
             this.configure(getClass().getResourceAsStream(this.resourceConfig));
         } else if (this.fileConfig != null) {
             try {
-                this.configure(new FileInputStream(fileConfig));
+                this.configure(new FileInputStream(this.fileConfig));
             } catch (FileNotFoundException e) {
                 throw new RuntimeException(e);
             }
@@ -254,6 +268,8 @@
         }
         
         this.isInitialized = true;
+
+        logger.config(getClass().getSimpleName() + " is initialized");
     }
 
     /**
@@ -271,7 +287,7 @@
      * @return The conditions or null if does not exist.
      */
     public <T> T getConditionsData(Class<T> type, String name) {
-        logger.finest("getting conditions " + name + " of type " + type.getSimpleName());
+        logger.fine("getting conditions " + name + " of type " + type.getSimpleName());
         return getCachedConditions(type, name).getCachedData();
     }
 
@@ -334,7 +350,7 @@
             e.printStackTrace();
             logger.warning(e.getMessage());
         }
-        logger.finest("new collection ID " + collectionId + " created for table " + tableName);
+        logger.fine("new collection ID " + collectionId + " created for table " + tableName);
         return collectionId;
     }
 
@@ -465,7 +481,7 @@
      */
     public ConditionsRecordCollection findConditionsRecords(String name) {
         ConditionsRecordCollection runConditionsRecords = getConditionsData(ConditionsRecordCollection.class, TableConstants.CONDITIONS_RECORD);
-        logger.fine("searching for condition " + name + " in " + runConditionsRecords.getObjects().size() + " records ...");
+        logger.fine("searching for condition " + name + " in " + runConditionsRecords.getObjects().size() + " records");
         ConditionsRecordCollection foundConditionsRecords = new ConditionsRecordCollection();
         for (ConditionsRecord record : runConditionsRecords.getObjects()) {
             if (record.getName().equals(name)) {
@@ -474,7 +490,7 @@
         }
         if (foundConditionsRecords.getObjects().size() > 0) {
             for (ConditionsRecord record : foundConditionsRecords.getObjects()) {
-                logger.fine("found ConditionsRecord with key " + name + " ..." + '\n' + record.toString());
+                logger.fine("found ConditionsRecord with key " + name + '\n' + record.toString());
             }
         }
         return foundConditionsRecords;
@@ -591,11 +607,9 @@
     }
 
     /**
-     * Setup the database connection from a file specified by Java system
-     * property setting. This is possible overridden by subsequent API calls to
-     * {@link #setConnectionProperties(File)} or
-     * {@link #setConnectionResource(String)}, as it is called in the class's
-     * constructor.
+     * Setup the database connection from a file specified by a Java system
+     * property setting. This is possibly overridden by subsequent, direct API calls to
+     * {@link #setConnectionProperties(File)} or {@link #setConnectionResource(String)}.
      */
     private void setupConnectionFromSystemProperty() {
         String systemPropertiesConnectionPath = (String) System.getProperties().get(connectionProperty);

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