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  May 2015

HPS-SVN May 2015

Subject:

r3051 - in /java/trunk/conditions/src: main/java/org/hps/conditions/svt/SvtTimingConstants.java main/java/org/hps/conditions/svt/SvtTimingConstantsLoader.java test/java/org/hps/conditions/svt/SvtTimingConstantsTest.java

From:

[log in to unmask]

Reply-To:

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

Date:

Thu, 28 May 2015 19:04:04 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (365 lines)

Author: [log in to unmask]
Date: Thu May 28 12:03:52 2015
New Revision: 3051

Log:
Change offset time to a double.  HPSJAVA-513

Modified:
    java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtTimingConstants.java
    java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtTimingConstantsLoader.java
    java/trunk/conditions/src/test/java/org/hps/conditions/svt/SvtTimingConstantsTest.java

Modified: java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtTimingConstants.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtTimingConstants.java	(original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtTimingConstants.java	Thu May 28 12:03:52 2015
@@ -11,28 +11,28 @@
  * Conditions object for SVT timing configuration constants, including offset phase and time (in nanoseconds).
  * <p>
  * There will generally be only one of these records per run.
- * 
+ *
  * @author Jeremy McCormick
  */
 @Table(names = {"svt_timing_constants"})
 @Converter(multipleCollectionsAction = MultipleCollectionsAction.LAST_CREATED)
 public final class SvtTimingConstants extends BaseConditionsObject {
-    
+
     /**
      * The collection implementation for {@link SvtTimingConstants}.
      */
     @SuppressWarnings("serial")
     public static class SvtTimingConstantsCollection extends BaseConditionsObjectCollection<SvtTimingConstants> {
-        
+
         /**
          * Find timing constants by offset phase and time.
-         * 
+         *
          * @param offsetPhase the offset phase
          * @param offsetTime the offset time
          * @return the constants that match the params or <code>null</code> if not found
          */
-        public SvtTimingConstants find(int offsetPhase, int offsetTime) {
-            for (SvtTimingConstants constants : this) {
+        public SvtTimingConstants find(final int offsetPhase, final double offsetTime) {
+            for (final SvtTimingConstants constants : this) {
                 if (constants.getOffsetPhase().equals(offsetPhase) && constants.getOffsetTime().equals(offsetTime)) {
                     return constants;
                 }
@@ -40,24 +40,24 @@
             return null;
         }
     }
-    
-    /**
-     * The SVT offset time (ns).
-     * 
-     * @return the SVT offset time (ns)
-     */
-    @Field(names = {"offset_time"})
-    public Integer getOffsetTime() {
-        return this.getFieldValue("offset_time");
-    }
-    
+
     /**
      * The SVT offset phase (ns).
-     *  
+     *
      * @return the SVT offset phase
      */
     @Field(names = {"offset_phase"})
     public Integer getOffsetPhase() {
         return this.getFieldValue("offset_phase");
     }
+
+    /**
+     * The SVT offset time (ns).
+     *
+     * @return the SVT offset time (ns)
+     */
+    @Field(names = {"offset_time"})
+    public Double getOffsetTime() {
+        return this.getFieldValue("offset_time");
+    }
 }

Modified: java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtTimingConstantsLoader.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtTimingConstantsLoader.java	(original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtTimingConstantsLoader.java	Thu May 28 12:03:52 2015
@@ -1,4 +1,4 @@
-package org.    hps.conditions.svt;
+package org.hps.conditions.svt;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -18,89 +18,127 @@
 /**
  * Load SVT timing constant data from the run spreadsheet and insert into the conditions database.
  * <p>
- * Be very careful about running this, because it will create many new conditions records that may 
- * already be present in the database.  In fact, don't run this at all without talking to me first. :-) 
- * 
+ * Be very careful about running this, because it will create many new conditions records that may already be present in the database. In fact, don't
+ * run this at all without talking to me first. :-)
+ *
  * @author Jeremy McCormick
  */
 public final class SvtTimingConstantsLoader {
-    
-    /**
-     * Setup conditions.     
-     */
-    private static final DatabaseConditionsManager MANAGER = DatabaseConditionsManager.getInstance();
-    
+
     /**
      * The fields from the run spreadsheet for SVT timing constants.
      */
     private static final Set<String> FIELDS = new HashSet<String>();
+
+    /**
+     * Setup conditions.
+     */
+    private static final DatabaseConditionsManager MANAGER = DatabaseConditionsManager.getInstance();
     static {
         FIELDS.add("svt_offset_phase");
         FIELDS.add("svt_offset_time");
     }
-    
+
+    /**
+     * Create the conditions collections from the unique values found in the spreadsheet.
+     *
+     * @param uniqueValues the list of unique raw values
+     * @return the new conditions collections
+     */
+    private static List<SvtTimingConstantsCollection> createCollections(final List<Collection<String>> uniqueValues) {
+        final List<SvtTimingConstantsCollection> collections = new ArrayList<SvtTimingConstantsCollection>();
+        for (final Collection<String> values : uniqueValues) {
+
+            final SvtTimingConstants timing = new SvtTimingConstants();
+            final Iterator<String> it = values.iterator();
+            final Integer offsetPhase = Integer.parseInt(it.next());
+            final Float offsetTime = Float.parseFloat(it.next());
+
+            timing.setFieldValue("offset_phase", offsetPhase);
+            timing.setFieldValue("offset_time", offsetTime);
+
+            final SvtTimingConstantsCollection collection = new SvtTimingConstantsCollection();
+            collection.add(timing);
+            collections.add(collection);
+        }
+        return collections;
+    }
+
+    /**
+     * Find a timing constants collection from offset phase and time.
+     * <p>
+     * Each collection has a single object in it.
+     *
+     * @param timingConstantsList the list of collections
+     * @param offsetPhase the offset phase
+     * @param offsetTime the offset time
+     * @return the matching collection or <code>null</code> if not found
+     */
+    private static SvtTimingConstantsCollection findCollection(final List<SvtTimingConstantsCollection> timingConstantsList, final int offsetPhase,
+            final double offsetTime) {
+        for (final SvtTimingConstantsCollection collection : timingConstantsList) {
+            if (collection.find(offsetPhase, offsetTime) != null) {
+                return collection;
+            }
+        }
+        return null;
+    }
+
     /**
      * Load the SVT timing constants for time and phase offsets into the conditions database.
-     * 
+     *
      * @param args the command line arguments (requires one argument which is CSV file name)
      */
-    public static void main(String[] args) {
-        
+    public static void main(final String[] args) {
+
         // Load in CSV records from the exported run spreadsheet.
-        String path = args[0];
-        RunSpreadsheet runSheet = new RunSpreadsheet(new File(path));
-        
+        final String path = args[0];
+        final RunSpreadsheet runSheet = new RunSpreadsheet(new File(path));
+
         // Find the run ranges that have the same fields values.
-        List<RunRange> ranges = RunRange.findRunRanges(runSheet, FIELDS);
-        
+        final List<RunRange> ranges = RunRange.findRunRanges(runSheet, FIELDS);
+
         // Get the unique field values for inserting new conditions collections.
-        List<Collection<String>> uniqueValues = RunRange.getUniqueValues(ranges);
-        
+        final List<Collection<String>> uniqueValues = RunRange.getUniqueValues(ranges);
+
         /*
-        System.out.println("unique values ...");
-        for (Collection<String> collection : uniqueValues) {
-            for (String value : collection) {
-                System.out.print(value + " ");                
-            }
-            System.out.println();
-        } 
-        */      
-               
+         * System.out.println("unique values ..."); for (Collection<String> collection : uniqueValues) { for (String value : collection) {
+         * System.out.print(value + " "); } System.out.println(); }
+         */
+
         // Create a new collection for each unique combination set of timing constants.
-        List<SvtTimingConstantsCollection> collections = createCollections(uniqueValues); 
-        
+        final List<SvtTimingConstantsCollection> collections = createCollections(uniqueValues);
+
         // Create a new collection for each of the unique combinations of values.
-        for (SvtTimingConstantsCollection collection : collections) {
+        for (final SvtTimingConstantsCollection collection : collections) {
             int collectionId = 0;
             try {
-                collectionId = MANAGER.addCollection(
-                        "svt_timing_constants",
-                        "SVT timing constants added by " + System.getProperty("user.name"),
+                collectionId = MANAGER.addCollection("svt_timing_constants", "SVT timing constants added by " + System.getProperty("user.name"),
                         "timing constants from run spreadsheet");
                 collection.setCollectionId(collectionId);
                 collection.insert();
-            } catch (Exception e) {
+            } catch (final Exception e) {
                 throw new RuntimeException(e);
-            }            
-        } 
-                
+            }
+        }
+
         // Create the conditions records for the run ranges.
-        for (RunRange range : ranges) {
-            
+        for (final RunRange range : ranges) {
+
             System.out.println(range);
-            
+
             // Get the data values from the run range.
-            int offsetPhase = Integer.parseInt(range.getValue("svt_offset_phase"));
-            int offsetTime = Integer.parseInt(range.getValue("svt_offset_time"));
+            final int offsetPhase = Integer.parseInt(range.getValue("svt_offset_phase"));
+            final double offsetTime = Float.parseFloat(range.getValue("svt_offset_time"));
 
             // Find the matching timing constants collection to use.
-            SvtTimingConstantsCollection collection = findCollection(collections, offsetPhase, offsetTime);
+            final SvtTimingConstantsCollection collection = findCollection(collections, offsetPhase, offsetTime);
             if (collection != null) {
                 System.out.println("offset_phase : " + collection.get(0).getOffsetPhase() + ", offset_time: " + collection.get(0).getOffsetTime());
             }
-                        
+
             // Create a new conditions record with the run range.
-            ConditionsRecord condi = new ConditionsRecord();
+            final ConditionsRecord condi = new ConditionsRecord();
             condi.setFieldValue("run_start", range.getRunStart());
             condi.setFieldValue("run_end", range.getRunEnd());
             condi.setFieldValue("name", "svt_timing_constants");
@@ -108,61 +146,17 @@
             condi.setFieldValue("notes", "timing constants from run spreadsheet");
             condi.setFieldValue("created", new Date());
             condi.setFieldValue("created_by", System.getProperty("user.name"));
-            
+
             condi.setFieldValue("collection_id", collection.getCollectionId());
 
             try {
                 condi.insert();
-            } catch (Exception e) {
+            } catch (final Exception e) {
                 throw new RuntimeException(e);
-            }            
-            
-            System.out.print(condi);            
+            }
+
+            System.out.print(condi);
             System.out.println();
         }
     }
-    
-    /**
-     * Create the conditions collections from the unique values found in the spreadsheet.
-     * 
-     * @param uniqueValues the list of unique raw values
-     * @return the new conditions collections
-     */
-    private static List<SvtTimingConstantsCollection> createCollections(List<Collection<String>> uniqueValues) {
-        List<SvtTimingConstantsCollection> collections = new ArrayList<SvtTimingConstantsCollection>();        
-        for (Collection<String> values : uniqueValues) {
-            
-            SvtTimingConstants timing = new SvtTimingConstants();
-            Iterator<String> it = values.iterator();            
-            Integer offsetPhase = Integer.parseInt(it.next());
-            Integer offsetTime = Integer.parseInt(it.next());
-            
-            timing.setFieldValue("offset_phase", offsetPhase);
-            timing.setFieldValue("offset_time", offsetTime);
-            
-            SvtTimingConstantsCollection collection = new SvtTimingConstantsCollection();
-            collection.add(timing);
-            collections.add(collection);
-        }
-        return collections;
-    }
-     
-    /**
-     * Find a timing constants collection from offset phase and time. 
-     * <p>
-     * Each collection has a single object in it.
-     * 
-     * @param timingConstantsList the list of collections
-     * @param offsetPhase the offset phase
-     * @param offsetTime the offset time
-     * @return the matching collection or <code>null</code> if not found
-     */
-    private static SvtTimingConstantsCollection findCollection(List<SvtTimingConstantsCollection> timingConstantsList, int offsetPhase, int offsetTime) {
-        for (SvtTimingConstantsCollection collection : timingConstantsList) {
-            if (collection.find(offsetPhase, offsetTime) != null) {
-                return collection;
-            }
-        }
-        return null;
-    }
 }

Modified: java/trunk/conditions/src/test/java/org/hps/conditions/svt/SvtTimingConstantsTest.java
 =============================================================================
--- java/trunk/conditions/src/test/java/org/hps/conditions/svt/SvtTimingConstantsTest.java	(original)
+++ java/trunk/conditions/src/test/java/org/hps/conditions/svt/SvtTimingConstantsTest.java	Thu May 28 12:03:52 2015
@@ -24,8 +24,8 @@
      * This is a list of run start values to check.
      */
     private static final int[] RUNS = new int[] {4871, 5038, 5076, 5139, 5174, 5218, 5236, 5251, 5263, 5299, 5310, 5375, 5400, 5533, 5558, 5575,
-        5596, 5601, 5603, 5610, 4871, 5038, 5076, 5139, 5174, 5218, 5236, 5251, 5263, 5299, 5310, 5375, 5400, 5533, 5558, 5575, 5596, 5601, 5603,
-        5610, 5640, 5641, 5642, 5686, 5722, 5779};
+            5596, 5601, 5603, 5610, 4871, 5038, 5076, 5139, 5174, 5218, 5236, 5251, 5263, 5299, 5310, 5375, 5400, 5533, 5558, 5575, 5596, 5601, 5603,
+            5610, 5640, 5641, 5642, 5686, 5722, 5779};
 
     /**
      * Load SVT timing constants and print them out by run range.
@@ -44,6 +44,5 @@
             System.out.println("run_start: " + condi.getRunStart() + ", run_end: " + condi.getRunEnd() + ", offset_phase: "
                     + collection.get(0).getOffsetPhase() + ", offset_time: " + collection.get(0).getOffsetTime());
         }
-
     }
 }

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