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 {