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:

r2291 - in /java/trunk/conditions/src: main/java/org/hps/conditions/beam/ main/java/org/hps/conditions/database/ test/java/org/hps/conditions/ test/java/org/hps/conditions/beam/ test/java/org/hps/conditions/ecal/

From:

[log in to unmask]

Reply-To:

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

Date:

Fri, 6 Mar 2015 05:04:27 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (477 lines)

Author: [log in to unmask]
Date: Thu Mar  5 21:04:22 2015
New Revision: 2291

Log:
Remove unnecessary conditions API method.  Minor reorganization of DatabaseConditionsManager code.

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/test/java/org/hps/conditions/EngRunConditionsTest.java
    java/trunk/conditions/src/test/java/org/hps/conditions/beam/BeamConditionsTest.java
    java/trunk/conditions/src/test/java/org/hps/conditions/ecal/EcalHardwareConditionsTest.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	Thu Mar  5 21:04:22 2015
@@ -81,7 +81,6 @@
         
         DatabaseConditionsManager manager = new DatabaseConditionsManager();
         manager.setLogLevel(Level.ALL);
-        manager.openConnection();
         
         for (Entry<Integer, BeamConditions> entry : beamMap.entrySet()) {
             int run = entry.getKey();

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	Thu Mar  5 21:04:22 2015
@@ -59,7 +59,7 @@
  * @author Jeremy McCormick <[log in to unmask]>
  */
 @SuppressWarnings("rawtypes")
-public class DatabaseConditionsManager extends ConditionsManagerImplementation {
+public final class DatabaseConditionsManager extends ConditionsManagerImplementation {
 
     // Initialize logger.
     protected static Logger logger = LogUtil.create(DatabaseConditionsManager.class.getName(), new DefaultLogFormatter(), Level.INFO);
@@ -243,7 +243,8 @@
      */
     public 
     <ObjectType extends ConditionsObject, CollectionType extends ConditionsObjectCollection<ObjectType>> 
-    ConditionsSeries<ObjectType, CollectionType> getConditionsSeries(Class<CollectionType> collectionType, String tableName) {
+    ConditionsSeries<ObjectType, CollectionType> 
+    getConditionsSeries(Class<CollectionType> collectionType, String tableName) {
         
         TableMetaData metaData = tableRegistry.get(tableName);
         if (metaData == null) {
@@ -257,18 +258,7 @@
         ConditionsSeriesConverter<ObjectType, CollectionType> converter = new ConditionsSeriesConverter(objectType, collectionType);
         return converter.createSeries(tableName);
     }
-            
-    /**
-     * Get conditions data by class and name.
-     * @param type The class of the conditions.
-     * @param name The name of the conditions set.
-     * @return The conditions or null if does not exist.
-     */
-    public <T> T getConditionsData(Class<T> type, String name) {
-        logger.fine("getting conditions " + name + " of type " + type.getSimpleName());
-        return getCachedConditions(type, name).getCachedData();
-    }
-
+                
     /**
      * This method handles changes to the detector name and run number.
      * It is called every time an LCSim event is created, and so it has 
@@ -309,101 +299,6 @@
      */
     public boolean isTestRun() {
         return isTestRun;
-    }
-    
-    /**
-     * Perform all necessary initialization, including setup of the XML
-     * configuration and loading of conditions onto the Detector.
-     */
-    protected void initialize(String detectorName, int runNumber) throws ConditionsNotFoundException {
-        
-        logger.config("initializing with detector " + detectorName + " and run " + runNumber);
-        
-        // Is not configured yet?
-        if (!isConfigured) {
-            if (isTestRun(runNumber)) {
-                // This looks like the Test Run so use the custom configuration for it.
-                setXmlConfig(DatabaseConditionsManager.TEST_RUN_CONFIG);
-            } else if (runNumber > TEST_RUN_MAX_RUN) {
-                // Run numbers greater than max of Test Run assumed to be Eng Run (for now!).
-                setXmlConfig(DatabaseConditionsManager.ENGRUN_CONFIG);
-            } else if (runNumber == 0) {
-                // Use the default configuration because the run number is basically meaningless.
-                setXmlConfig(DatabaseConditionsManager.DEFAULT_CONFIG);
-            }
-        }
-
-        // Register the converters for this initialization.
-        logger.fine("registering converters");
-        registerConverters();
-    
-        // Enable or disable the setup of the SVT detector.
-        logger.fine("enabling SVT setup: " + setupSvtDetector);
-        svtSetup.setEnabled(setupSvtDetector);
-
-        // Open the database connection.
-        openConnection();
-        
-        // Call the super class's setDetector method to construct the detector object and activate conditions listeners.
-        logger.fine("activating default conditions manager");
-        super.setDetector(detectorName, runNumber);
-                        
-        // Should all conditions sets be cached?
-        if (cacheAllConditions) {
-            // Cache the conditions sets of all registered converters.
-            logger.fine("caching all conditions sets ...");
-            cacheConditionsSets();
-        }
-                
-        if (closeConnectionAfterInitialize) {
-            logger.fine("closing connection after initialization");
-            // Close the connection. 
-            closeConnection();
-        }
-        
-        // Should the conditions system be frozen now?
-        if (freezeAfterInitialize) {
-            // Freeze the conditions system so subsequent updates will be ignored.
-            freeze();
-            logger.config("system was frozen after initialization");
-        }
-        
-        isInitialized = true;
-        
-        logger.info("conditions system initialized successfully");
-        
-        // Flush logger after initialization.
-        logger.getHandlers()[0].flush();
-    }
-
-    /**
-     * Register the conditions converters with the manager.
-     */
-    private void registerConverters() {
-        if (svtConverter != null) {
-            // Remove old SVT converter.
-            removeConditionsConverter(svtConverter);
-        }
-        
-        if (ecalConverter != null) {
-            // Remove old ECAL converter.
-            registerConditionsConverter(ecalConverter);
-        }
-        
-        // Is configured for TestRun?
-        if (isTestRun()) {
-            // Load Test Run specific converters.
-            svtConverter = new TestRunSvtConditionsConverter();
-            ecalConverter = new TestRunEcalConditionsConverter();
-            logger.config("registering Test Run conditions converters");
-        } else {
-            // Load the default converters.
-            svtConverter = new SvtConditionsConverter();
-            ecalConverter = new EcalConditionsConverter();
-            logger.config("registering default conditions converters");
-        }
-        registerConditionsConverter(svtConverter);
-        registerConditionsConverter(ecalConverter);
     }
     
     /**
@@ -589,31 +484,7 @@
         logger.fine("found " + foundConditionsRecords.size() + " conditions records matching tag " + tag);
         return foundConditionsRecords;
     }
-    
-    /**
-     * True if the conditions record matches the current tag.
-     * @param record The conditions record.
-     * @return True if conditions record matches the currently used tag.
-     */
-    boolean matchesTag(ConditionsRecord record) {
-        if (this.tag == null) {
-            // If there is no tag set then all records pass.
-            return true;
-        }
-        String recordTag = record.getTag();
-        if (recordTag == null) {
-            // If there is a tag set but the record has no tag, it is rejected.
-            return false;
-        }
-        if (tag.equals(recordTag)) {
-            // If the tags match, the record is accepted.
-            return true;
-        } else {
-            // Tags do not match so record is rejected.
-            return false;
-        }
-    }
-    
+           
     /**
      * True if there is a conditions record with the given name.
      * @param name The conditions name.
@@ -627,7 +498,7 @@
      * Get a list of all the ConditionsRecord objects.
      * @return The list of all the ConditionsRecord objects.
      */
-    // FIXME: This should use a cache created in initialize rather than do a find every time.
+    // FIXME: This should use a cache that is created during initialization, rather than look these up every time.
     public ConditionsRecordCollection getConditionsRecords() {
         logger.finer("getting conditions records ...");
         ConditionsRecordCollection conditionsRecords = new ConditionsRecordCollection();
@@ -690,31 +561,7 @@
     public boolean isFrozen() {
         return isFrozen;
     }
-    
-    /**
-     * Set the name of the ECAL sub-detector.
-     * @param ecalName The name of the ECAL.
-     */
-    protected void setEcalName(String ecalName) {
-        if (ecalName == null) {
-            throw new IllegalArgumentException("The ecalName is null");
-        }
-        this.ecalName = ecalName;
-        logger.info("ECAL name set to " + ecalName);
-    }
-    
-    /**
-     * Set the name of the SVT sub-detector.
-     * @param svtName The name of the SVT.
-     */
-    protected void setSvtName(String svtName) {
-        if (svtName == null) {
-            throw new IllegalArgumentException("The svtName is null");
-        }
-        this.svtName = svtName;
-        logger.info("SVT name set to " + ecalName);
-    }
-    
+            
     /**
      * Set a tag used to filter ConditionsRecords.
      * @param tag The tag value used to filter ConditionsRecords.
@@ -730,7 +577,8 @@
      * @throws SQLException If there is a database error.
      * @throws ConditionsObjectException If there is a problem with the ConditionsObjects.
      */
-    public <ObjectType extends ConditionsObject> void insertCollection(ConditionsObjectCollection<ObjectType> collection) throws SQLException, ConditionsObjectException {
+    public <ObjectType extends ConditionsObject> 
+    void insertCollection(ConditionsObjectCollection<ObjectType> collection) throws SQLException, ConditionsObjectException {
                 
         if (collection == null) {
             throw new IllegalArgumentException("The collection is null.");
@@ -814,8 +662,6 @@
      * @return The Logger for this class.
      */
     public static Logger getLogger() {
-        //System.out.println("DatabaseConditionsManager.getLogger called from");
-        //new RuntimeException().printStackTrace();
         return logger;
     }
     
@@ -858,7 +704,150 @@
      * Private methods below here. *
      *******************************
      */
-                          
+    
+    /**
+     * Perform all necessary initialization, including setup of the XML
+     * configuration and loading of conditions onto the Detector.
+     */
+    private void initialize(String detectorName, int runNumber) throws ConditionsNotFoundException {
+        
+        logger.config("initializing with detector " + detectorName + " and run " + runNumber);
+        
+        // Is not configured yet?
+        if (!isConfigured) {
+            if (isTestRun(runNumber)) {
+                // This looks like the Test Run so use the custom configuration for it.
+                setXmlConfig(DatabaseConditionsManager.TEST_RUN_CONFIG);
+            } else if (runNumber > TEST_RUN_MAX_RUN) {
+                // Run numbers greater than max of Test Run assumed to be Eng Run (for now!).
+                setXmlConfig(DatabaseConditionsManager.ENGRUN_CONFIG);
+            } else if (runNumber == 0) {
+                // Use the default configuration because the run number is basically meaningless.
+                setXmlConfig(DatabaseConditionsManager.DEFAULT_CONFIG);
+            }
+        }
+
+        // Register the converters for this initialization.
+        logger.fine("registering converters");
+        registerConverters();
+    
+        // Enable or disable the setup of the SVT detector.
+        logger.fine("enabling SVT setup: " + setupSvtDetector);
+        svtSetup.setEnabled(setupSvtDetector);
+
+        // Open the database connection.
+        openConnection();
+        
+        // Call the super class's setDetector method to construct the detector object and activate conditions listeners.
+        logger.fine("activating default conditions manager");
+        super.setDetector(detectorName, runNumber);
+                        
+        // Should all conditions sets be cached?
+        if (cacheAllConditions) {
+            // Cache the conditions sets of all registered converters.
+            logger.fine("caching all conditions sets ...");
+            cacheConditionsSets();
+        }
+                
+        if (closeConnectionAfterInitialize) {
+            logger.fine("closing connection after initialization");
+            // Close the connection. 
+            closeConnection();
+        }
+        
+        // Should the conditions system be frozen now?
+        if (freezeAfterInitialize) {
+            // Freeze the conditions system so subsequent updates will be ignored.
+            freeze();
+            logger.config("system was frozen after initialization");
+        }
+        
+        isInitialized = true;
+        
+        logger.info("conditions system initialized successfully");
+        
+        // Flush logger after initialization.
+        logger.getHandlers()[0].flush();
+    }
+
+    /**
+     * Register the conditions converters with the manager.
+     */
+    private void registerConverters() {
+        if (svtConverter != null) {
+            // Remove old SVT converter.
+            removeConditionsConverter(svtConverter);
+        }
+        
+        if (ecalConverter != null) {
+            // Remove old ECAL converter.
+            registerConditionsConverter(ecalConverter);
+        }
+        
+        // Is configured for TestRun?
+        if (isTestRun()) {
+            // Load Test Run specific converters.
+            svtConverter = new TestRunSvtConditionsConverter();
+            ecalConverter = new TestRunEcalConditionsConverter();
+            logger.config("registering Test Run conditions converters");
+        } else {
+            // Load the default converters.
+            svtConverter = new SvtConditionsConverter();
+            ecalConverter = new EcalConditionsConverter();
+            logger.config("registering default conditions converters");
+        }
+        registerConditionsConverter(svtConverter);
+        registerConditionsConverter(ecalConverter);
+    }
+    
+    /**
+     * Set the name of the ECAL sub-detector.
+     * @param ecalName The name of the ECAL.
+     */
+    private void setEcalName(String ecalName) {
+        if (ecalName == null) {
+            throw new IllegalArgumentException("The ecalName is null");
+        }
+        this.ecalName = ecalName;
+        logger.info("ECAL name set to " + ecalName);
+    }
+    
+    /**
+     * Set the name of the SVT sub-detector.
+     * @param svtName The name of the SVT.
+     */
+    private void setSvtName(String svtName) {
+        if (svtName == null) {
+            throw new IllegalArgumentException("The svtName is null");
+        }
+        this.svtName = svtName;
+        logger.info("SVT name set to " + ecalName);
+    }
+    
+    /**
+     * True if the conditions record matches the current tag.
+     * @param record The conditions record.
+     * @return True if conditions record matches the currently used tag.
+     */
+    private boolean matchesTag(ConditionsRecord record) {
+        if (this.tag == null) {
+            // If there is no tag set then all records pass.
+            return true;
+        }
+        String recordTag = record.getTag();
+        if (recordTag == null) {
+            // If there is a tag set but the record has no tag, it is rejected.
+            return false;
+        }
+        if (tag.equals(recordTag)) {
+            // If the tags match, the record is accepted.
+            return true;
+        } else {
+            // Tags do not match so record is rejected.
+            return false;
+        }
+    }
+                              
     /**
      * Cache conditions sets for all known tables.
      */
@@ -919,7 +908,6 @@
      * Load configuration information from an XML document.
      * @param document The XML document.
      */
-    // TODO: Add detectorName and runNumber settings.
     private void loadConfiguration(Document document) {
         
         Element node = document.getRootElement().getChild("configuration");

Modified: java/trunk/conditions/src/test/java/org/hps/conditions/EngRunConditionsTest.java
 =============================================================================
--- java/trunk/conditions/src/test/java/org/hps/conditions/EngRunConditionsTest.java	(original)
+++ java/trunk/conditions/src/test/java/org/hps/conditions/EngRunConditionsTest.java	Thu Mar  5 21:04:22 2015
@@ -107,7 +107,7 @@
             //assertEquals("Wrong LEDs collection ID.", 2, timeShifts.getConditionsRecord().getCollectionId());
             //checkRunNumbers(timeShifts);
             
-            ecalConditions = conditionsManager.getConditionsData(EcalConditions.class, "ecal_conditions");
+            ecalConditions = conditionsManager.getCachedConditions(EcalConditions.class, "ecal_conditions").getCachedData();
             Set<EcalChannelConstants> channelConstants = new LinkedHashSet<EcalChannelConstants>();
             for (EcalChannel channel : ecalConditions.getChannelCollection().sortedByChannelId()) {
                 channelConstants.add(ecalConditions.getChannelConstants(channel));

Modified: java/trunk/conditions/src/test/java/org/hps/conditions/beam/BeamConditionsTest.java
 =============================================================================
--- java/trunk/conditions/src/test/java/org/hps/conditions/beam/BeamConditionsTest.java	(original)
+++ java/trunk/conditions/src/test/java/org/hps/conditions/beam/BeamConditionsTest.java	Thu Mar  5 21:04:22 2015
@@ -56,7 +56,7 @@
                 throw new RuntimeException(e);
             }
             BeamConditionsCollection beamCollection = 
-                    manager.getConditionsData(BeamConditionsCollection.class, "beam");
+                    manager.getCachedConditions(BeamConditionsCollection.class, "beam").getCachedData();
             BeamConditions beam = beamCollection.get(0);
             System.out.print(run + " ");
             System.out.print(beam.getRowId() + " ");

Modified: java/trunk/conditions/src/test/java/org/hps/conditions/ecal/EcalHardwareConditionsTest.java
 =============================================================================
--- java/trunk/conditions/src/test/java/org/hps/conditions/ecal/EcalHardwareConditionsTest.java	(original)
+++ java/trunk/conditions/src/test/java/org/hps/conditions/ecal/EcalHardwareConditionsTest.java	Thu Mar  5 21:04:22 2015
@@ -31,14 +31,14 @@
         manager.setLogLevel(Level.ALL);
         
         // Read hardware calibrations.
-        EcalCalibrationCollection calibrations = manager.getConditionsData(EcalCalibrationCollection.class, CALIBRATIONS_TABLE);
+        EcalCalibrationCollection calibrations = manager.getCachedConditions(EcalCalibrationCollection.class, CALIBRATIONS_TABLE).getCachedData();
         assertEquals("Wrong name in conditions record.", CALIBRATIONS_TABLE, calibrations.getConditionsRecord().getTableName());
         assertEquals("Wrong table name in conditions record.", CALIBRATIONS_TABLE, calibrations.getConditionsRecord().getTableName());
         assertEquals("Wrong number of records.", RECORD_COUNT, calibrations.size());
         System.out.println("successfully read " + calibrations.size() + " gain records from " + CALIBRATIONS_TABLE);
         
         // Read hardware gains.
-        EcalGainCollection gains = manager.getConditionsData(EcalGainCollection.class, GAINS_TABLE);
+        EcalGainCollection gains = manager.getCachedConditions(EcalGainCollection.class, GAINS_TABLE).getCachedData();
         assertEquals("Wrong name in conditions record.", GAINS_TABLE, gains.getConditionsRecord().getTableName());
         assertEquals("Wrong table name in conditions record.", GAINS_TABLE, gains.getConditionsRecord().getTableName());
         assertEquals("Wrong number of records.", RECORD_COUNT, gains.size());

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