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

HPS-SVN June 2015

Subject:

r3156 - in /java/trunk/conditions/src/main/java/org/hps/conditions/svt: SvtBiasConditionsLoader.java SvtBiasMyaDumpReader.java

From:

[log in to unmask]

Reply-To:

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

Date:

Thu, 18 Jun 2015 19:38:36 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (269 lines)

Author: [log in to unmask]
Date: Thu Jun 18 12:38:24 2015
New Revision: 3156

Log:
Add useful functions to check for ranges and to check these in a driver.

Modified:
    java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtBiasConditionsLoader.java
    java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtBiasMyaDumpReader.java

Modified: java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtBiasConditionsLoader.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtBiasConditionsLoader.java	(original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtBiasConditionsLoader.java	Thu Jun 18 12:38:24 2015
@@ -106,7 +106,7 @@
      */
     private static boolean isValid(RunData data) {
         if(data.getStartDate() == null || data.getEndDate() == null || data.getStartDate().before(new Date(99,1,1))) {
-            logger.warning("This run data is not valid: " + data.toString());
+            logger.fine("This run data is not valid: " + data.toString());
             return false;
         } 
         if (data.getStartDate().after(data.getEndDate())) {
@@ -118,62 +118,30 @@
     //private static Options options = null;
     
     
-    /**
-     * Load SVT HV bias constants into the conditions database.
-     * 
-     * @param args the command line arguments (requires a CVS run log file and a MYA dump file.)
-     */
-    public static void main(String[] args) {
-
-        Options options = new Options();
-        options.addOption(new Option("c", true, "CVS run file"));
-        options.addOption(new Option("m", true, "MYA dump file"));
-        options.addOption(new Option("g", false, "Actually load stuff into DB"));
-        options.addOption(new Option("s", false, "Show plots"));
-        
-        final CommandLineParser parser = new PosixParser();
-        CommandLine cl = null;
-        try {
-            cl = parser.parse(options, args);
-        } catch (ParseException e) {
-            throw new RuntimeException("Cannot parse.", e);
-        }
-        
- 
-        // Setup plots
-        setupPlots(cl.hasOption("s")?true:false);
-
-        
+    public static RunMap getRunMapFromSpreadSheet(String path) {
         // Load in CSV records from the exported run spreadsheet.
-        final String path = cl.getOptionValue("c");
         logger.info(path);
         final RunSpreadsheet runSheet = new RunSpreadsheet(new File(path));
 
         // Find the run ranges that have the same fields values.
         final List<RunRange> ranges = RunRange.findRunRanges(runSheet, FIELDS);
         logger.info("Found " + ranges.size() + " ranges.");
-        for(RunRange range : ranges) logger.info(range.toString());
+        for(RunRange range : ranges) logger.fine(range.toString());
         // find the run records (has converted dates and stuff) for these ranges
         RunMap runmap  = runSheet.getRunMap(ranges);
         logger.info("Found " + runmap.size() + " runs in the run map.");
-        
-        
-        
-        // Load MYA dump
-        SvtBiasMyaDumpReader biasMyaReader = new SvtBiasMyaDumpReader(cl.getOptionValue("m"));
-        logger.info("Got " + biasMyaReader.getRanges().size() + " bias ranges");
-        
-        
-        // Combine them to run ranges when bias was on        
-        // each run may have multiple bias ranges
-        
+        return runmap;
+    }
+    
+    public static List<SvtBiasRunRange> getBiasRunRanges(RunMap runmap,
+            SvtBiasMyaDumpReader biasMyaReader) {
         List<SvtBiasRunRange> biasRunRanges = new ArrayList<SvtBiasRunRange>();
         // loop over runs from CSV        
         RunData prev = null;
         for(Entry<Integer,RunData> entry : runmap.entrySet()) {
             int run = entry.getKey();
             RunData data = entry.getValue();
-            logger.info("Processing " + run + " " + data.toString());
+            logger.fine("Processing " + run + " " + data.toString());
             
             //check that data is ok
             if (isValid(data)) {
@@ -197,6 +165,96 @@
 
             }
         }
+        return biasRunRanges;
+    }
+    
+    
+    /**
+     * Load SVT HV bias constants into the conditions database.
+     * 
+     * @param args the command line arguments (requires a CVS run log file and a MYA dump file.)
+     */
+    public static void main(String[] args) {
+
+        Options options = new Options();
+        options.addOption(new Option("c", true, "CVS run file"));
+        options.addOption(new Option("m", true, "MYA dump file"));
+        options.addOption(new Option("g", false, "Actually load stuff into DB"));
+        options.addOption(new Option("s", false, "Show plots"));
+        
+        final CommandLineParser parser = new PosixParser();
+        CommandLine cl = null;
+        try {
+            cl = parser.parse(options, args);
+        } catch (ParseException e) {
+            throw new RuntimeException("Cannot parse.", e);
+        }
+        
+       
+        
+ 
+        // Setup plots
+        setupPlots(cl.hasOption("s")?true:false);
+
+        
+        // Load in CSV records from the exported run spreadsheet.
+        final String path = cl.getOptionValue("c");
+        logger.info(path);
+        
+        RunMap runmap = getRunMapFromSpreadSheet(path);
+        
+//        final RunSpreadsheet runSheet = new RunSpreadsheet(new File(path));
+//
+//        // Find the run ranges that have the same fields values.
+//        final List<RunRange> ranges = RunRange.findRunRanges(runSheet, FIELDS);
+//        logger.info("Found " + ranges.size() + " ranges.");
+//        for(RunRange range : ranges) logger.info(range.toString());
+//        // find the run records (has converted dates and stuff) for these ranges
+//        RunMap runmap  = runSheet.getRunMap(ranges);
+//        logger.info("Found " + runmap.size() + " runs in the run map.");
+        
+        
+        
+        // Load MYA dump
+        SvtBiasMyaDumpReader biasMyaReader = new SvtBiasMyaDumpReader(cl.getOptionValue("m"));
+        logger.info("Got " + biasMyaReader.getRanges().size() + " bias ranges");
+        
+        
+        // Combine them to run ranges when bias was on        
+        // each run may have multiple bias ranges
+        
+        List<SvtBiasRunRange> biasRunRanges = getBiasRunRanges(runmap,biasMyaReader);
+        
+//        List<SvtBiasRunRange> biasRunRanges = new ArrayList<SvtBiasRunRange>();
+//        // loop over runs from CSV        
+//        RunData prev = null;
+//        for(Entry<Integer,RunData> entry : runmap.entrySet()) {
+//            int run = entry.getKey();
+//            RunData data = entry.getValue();
+//            logger.info("Processing " + run + " " + data.toString());
+//            
+//            //check that data is ok
+//            if (isValid(data)) {
+//                if(prev!=null) {
+//                    if(isValid(prev)) {
+//                        if(prev.getEndDate().after(data.getStartDate())) {
+//                            throw new RuntimeException("prev end date after run started?: " + prev.toString() + "   " + data.toString());
+//                        } else if(prev.getStartDate().after(data.getEndDate())) {
+//                            throw new RuntimeException("prev start date before run ended?: " + prev.toString() + "   " + data.toString());
+//                        }
+//                    }
+//                }
+//                
+//                // find the bias ranges applicable to this run
+//                SvtBiasMyaRanges overlaps = biasMyaReader.findOverlappingRanges(data.getStartDate(), data.getEndDate());
+//                logger.fine("Found " + overlaps.size() + " overlapping bias ranges");
+//                logger.fine(overlaps.toString());
+//
+//                biasRunRanges.add(new SvtBiasRunRange(data,overlaps));
+//                prev = data;
+//
+//            }
+//        }
         
         
         // fill graphs
@@ -229,6 +287,8 @@
         
     }
     
+    
+
     private final static SvtBiasConstantCollection findCollection(final List<SvtBiasConstantCollection> list, Date date) {
         for( SvtBiasConstantCollection collection : list) {
             if(collection.find(date) != null) {

Modified: java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtBiasMyaDumpReader.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtBiasMyaDumpReader.java	(original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtBiasMyaDumpReader.java	Thu Jun 18 12:38:24 2015
@@ -9,6 +9,7 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.TimeZone;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -33,6 +34,7 @@
     }
     
     private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    private static final TimeZone timeZone = TimeZone.getTimeZone("EST");
     private static final double BIASVALUEON = 178.0;
     private List<SvtBiasMyaEntry> myaEntries = new ArrayList<SvtBiasMyaEntry>();
     private SvtBiasMyaRanges biasRanges = new SvtBiasMyaRanges();
@@ -105,6 +107,7 @@
                     if(arr.length<3) {
                         throw new ParseException("this line is not correct.",0);
                     }
+                    DATE_FORMAT.setTimeZone(timeZone);
                     Date date = DATE_FORMAT.parse(arr[0] + " " + arr[1]);
                     double value = Double.parseDouble(arr[2]);
                     SvtBiasMyaEntry entry = new SvtBiasMyaEntry(file.getName(), date, value);
@@ -173,7 +176,7 @@
             return this.date;
         }
         public String toString() {
-            return name + " " + date.toString() + " value " + value;
+            return name + " " + date.toString() + " (epoch " + Long.toString(date.getTime()) + ")" + " value " + value;
         }
     }
 
@@ -200,6 +203,14 @@
             }
             return sb.toString();
         }
+        
+        public boolean includes(Date date) {
+            for(SvtBiasMyaRange r : this) {
+                if(r.includes(date)) return true;
+            }
+            return false;
+        }
+        
     }
     
     public static class SvtBiasMyaRange {
@@ -238,6 +249,13 @@
         public String toString() {
             return "START: " + start.toString() + "   END: " + end.toString();
         }
+        public boolean includes(Date date) {
+            if( date.before(getStartDate()) || date.after(getEndDate()) ) {
+                return false;
+            } else {
+                return true;
+            }
+        }
     }
     
     public static final class SvtBiasRunRange {

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