Print

Print


Commit in hps-java/src/main/java/org/lcsim/hps/conditions on MAIN
ConnectionParameters.java+3-21.5 -> 1.6
DatabaseConditionsConverter.java-121.2 -> 1.3
DatabaseConditionsReader.java+85-371.4 -> 1.5
+88-51
3 modified files
use conditions_dev table format to replace conditions_test; corresponding changes to code

hps-java/src/main/java/org/lcsim/hps/conditions
ConnectionParameters.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- ConnectionParameters.java	19 Sep 2013 18:56:35 -0000	1.5
+++ ConnectionParameters.java	20 Sep 2013 21:56:24 -0000	1.6
@@ -11,7 +11,7 @@
  * return a Connection object based on these parameters.
  * 
  * @author jeremym
- * @version $Id: ConnectionParameters.java,v 1.5 2013/09/19 18:56:35 jeremy Exp $
+ * @version $Id: ConnectionParameters.java,v 1.6 2013/09/20 21:56:24 jeremy Exp $
  */
 public final class ConnectionParameters {
     
@@ -21,7 +21,8 @@
     private int port = 3306;
     private String hostname = "mysql-node03.slac.stanford.edu";
     private String database = "rd_hps_cond";
-    private String conditionsTable = "conditions_test";
+    //private String conditionsTable = "conditions_test";
+    private String conditionsTable = "conditions_dev";
 
     /**
      * No argument constructor that uses the defaults.

hps-java/src/main/java/org/lcsim/hps/conditions
DatabaseConditionsConverter.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- DatabaseConditionsConverter.java	19 Sep 2013 01:28:05 -0000	1.2
+++ DatabaseConditionsConverter.java	20 Sep 2013 21:56:24 -0000	1.3
@@ -3,16 +3,4 @@
 import org.lcsim.conditions.ConditionsConverter;
 
 public abstract class DatabaseConditionsConverter<T> implements ConditionsConverter<T> {
-    
-    /*
-    ConnectionParameters connectionParameters = null;    
-    
-    protected DatabaseConditionsConverter(ConnectionParameters parameters) {
-        this.connectionParameters = parameters;
-    }
-        
-    public ConnectionParameters getConnectionParameters() {
-        return this.connectionParameters;
-    } 
-    */          
 }
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/conditions
DatabaseConditionsReader.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- DatabaseConditionsReader.java	19 Sep 2013 01:28:05 -0000	1.4
+++ DatabaseConditionsReader.java	20 Sep 2013 21:56:24 -0000	1.5
@@ -10,6 +10,11 @@
 import java.sql.Statement;
 import java.util.HashMap;
 import java.util.Properties;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
 
 import org.lcsim.conditions.ConditionsManager;
 import org.lcsim.conditions.ConditionsReader;
@@ -28,18 +33,15 @@
  * 
  *     java -Dhps.conditions.db.configuration=/path/to/my/config.prop [...]
  * 
- * Currently, this class should "know" about all the converters that are needed for loading
- * conditions data.  The SVT is the only example currently, but more will be added as they
- * are created.
+ * Currently, this class should "know" directly about all the converters that are needed for loading
+ * conditions data via the <code>registerConditionsConverters</code> method.  The SVT is the only example 
+ * currently, but more will be added as they are created.
  * 
  * @author jeremym
- * @version $Id: DatabaseConditionsReader.java,v 1.4 2013/09/19 01:28:05 jeremy Exp $ 
+ * @version $Id: DatabaseConditionsReader.java,v 1.5 2013/09/20 21:56:24 jeremy Exp $ 
  */
 public class DatabaseConditionsReader extends ConditionsReader {
-    
-    /** Database connection parameters. */
-    //private static ConnectionParameters connectionParameters = new ConnectionParameters();
-    
+        
     /** Database connection. */
     private Connection connection = null;    
     
@@ -57,6 +59,9 @@
 
     /** This maps conditions types to their table, field, and set id. */
     private final HashMap<String, byte[]> propertyCache = new HashMap<String, byte[]>();
+    
+    /** The logger for printing messages. */
+    static Logger logger = null;
 
     /**
      * Class constructor taking a ConditionsReader.  This constructor is automatically called 
@@ -66,18 +71,52 @@
      * @param reader The basic ConditionsReader allowing access to the detector.
      */
     public DatabaseConditionsReader(ConditionsReader reader) {
-        this.reader = reader;
+        this.reader = reader;        
+        
+        setupLogger();
+    }
+    
+    /**
+     * Setup the logger.
+     */
+    private final void setupLogger() {
+        if (logger == null) {
+            logger = Logger.getLogger(this.getClass().getSimpleName());
+            logger.setUseParentHandlers(false);
+            logger.setLevel(Level.ALL);
+            ConsoleHandler handler = new ConsoleHandler();
+            handler.setFormatter(new ConditionsFormatter());
+            logger.addHandler(handler);
+        }
+    }
+    
+    /**
+     * Simple log formatter for this class.
+     */
+    private static final class ConditionsFormatter extends Formatter {
+        
+        public String format(LogRecord record) {
+            StringBuilder sb = new StringBuilder();
+            sb.append(record.getLoggerName() + " [ " + record.getLevel() + " ] " + record.getMessage() + '\n');
+            return sb.toString();
+        }
     }
     
     /**
      * Update conditions for possibly new detector and run number.  This will cache the 
      * conditions meta data but will not automatically do any conversion.
+     * @param manager The current conditions manager.
+     * @param detectorName The detector name.
+     * @param run The run number.
      */
     public boolean update(ConditionsManager manager, String detectorName, int run) throws IOException {
 
+        logger.info("update");
+        
         // Setup detector.
         if (this.detectorName == null) {
             this.detectorName = detectorName;
+            logger.info("set detector name: " + this.detectorName);
         } else {
             if (!this.detectorName.equals(detectorName))
                 throw new IllegalArgumentException();
@@ -142,42 +181,49 @@
      */
     private final void cacheDataIdent(int run) throws SQLException, IOException {
         
+        logger.info("cacheDataIdent");
+        
         String db = ConnectionManager.getConnectionParameters().getDatabase();
         String table = ConnectionManager.getConnectionParameters().getConditionsTable();
-        
-        // Query for fetching the validity records matching this run.
-        String query = "SELECT data_ident, run_start, run_end, calib_type FROM " 
-                + db + "." + table 
+                
+        String query = "SELECT run_start, run_end, name, table_name, field_name, field_value FROM " 
+                + db + "." + table                       
                 + " WHERE "
                 + "run_start <= "
                 + run
                 + " AND run_end >= "
-                + run
-                + " AND level = 'PROD'";
+                + run;
+        
+        logger.info("query: " + query);
 
         Statement statement = null;
-        String data = null;
         try {
             statement = connection.createStatement();
             ResultSet resultSet = statement.executeQuery(query);
             
             // Iterate over conditions records.
             while (resultSet.next()) {
-                
-                // The data_ident field.
-                data = resultSet.getString(1);
-                
+                                
                 // The minimum run number.
-                minRun = resultSet.getInt(2);
+                minRun = resultSet.getInt(1);
                 
                 // The maximum run number.
-                maxRun = resultSet.getInt(3);
+                maxRun = resultSet.getInt(2);
+                                
+                // The name of the conditions used as a key for lookup.
+                String name = resultSet.getString(3);
+                
+                // The name of the table containing the actual data.
+                String tableName = resultSet.getString(4);
                 
-                // The type of the calibration.
-                String calibrationType = resultSet.getString(4);
+                // The field used to ID the data set.
+                String fieldName = resultSet.getString(5);
                 
-                // Cache the data_ident by condition type for later use by converters.
-                addProperty(calibrationType, data);
+                // The value of the ID field.
+                int fieldValue = resultSet.getInt(6);
+                                
+                // Cache the meta data for later use by converters.
+                addDataKey(name, tableName, fieldName, fieldValue);
             }
         } finally {
             if (statement != null) {
@@ -189,9 +235,9 @@
             }
         }            
     }
-
+   
     /**
-     * Register data_ident properties for a certain condition type.  
+     * Register meta data properties for a certain condition type.  
      * This includes table name, column name, and the id field.  
      * The information is later used by the converters to create the application 
      * data objects from SQL queries.
@@ -199,18 +245,20 @@
      * @param data The raw string data from the data_ident field in the database.
      * @throws IOException if the data format is wrong.
      */
-    private void addProperty(String key, String data) throws IOException {
+    private void addDataKey(String key, String tableName, String columnName, int value) {
+        
+        logger.info("addDataKey: " + key + " => " + tableName + ":" + columnName + ":" + value);
+        
         Properties p = new Properties();
-        String[] d = data.trim().split(":");
+        p.put("table", tableName);
+        p.put("column", columnName);
+        p.put("id", new Integer(value).toString());
+        ByteArrayOutputStream stream = new ByteArrayOutputStream();
         try {
-            p.put("table", d[0]);
-            p.put("column", d[1]);
-            p.put("id", d[2]);
-        } catch (IndexOutOfBoundsException x) {
-            throw new IOException("Illegal data_ident format", x);
+            p.store(stream, null);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
         }
-        ByteArrayOutputStream stream = new ByteArrayOutputStream();
-        p.store(stream, null);
         propertyCache.put(key, stream.toByteArray());
     }
             
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1