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 2016

HPS-SVN March 2016

Subject:

r4305 - /java/trunk/users/src/main/java/org/hps/users/meeg/SvtChargeIntegrator.java

From:

[log in to unmask]

Reply-To:

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

Date:

Fri, 18 Mar 2016 02:00:25 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (187 lines)

Author: [log in to unmask]
Date: Thu Mar 17 19:00:23 2016
New Revision: 4305

Log:
option to read header error file

Modified:
    java/trunk/users/src/main/java/org/hps/users/meeg/SvtChargeIntegrator.java

Modified: java/trunk/users/src/main/java/org/hps/users/meeg/SvtChargeIntegrator.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/meeg/SvtChargeIntegrator.java	(original)
+++ java/trunk/users/src/main/java/org/hps/users/meeg/SvtChargeIntegrator.java	Thu Mar 17 19:00:23 2016
@@ -6,17 +6,19 @@
 import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.TimeZone;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.PosixParser;
 import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
 import org.apache.commons.csv.CSVFormat;
 import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVRecord;
@@ -49,6 +51,7 @@
         options.addOption(new Option("r", false, "use per-run CSV log file (default is per-file)"));
         options.addOption(new Option("t", false, "use TI timestamp instead of Unix time (higher precision, but requires TI time offset in run DB)"));
         options.addOption(new Option("c", false, "get TI time offset from CSV log file instead of run DB"));
+        options.addOption(new Option("e", true, "header error file"));
 
         final CommandLineParser parser = new PosixParser();
         CommandLine cl = null;
@@ -62,6 +65,26 @@
         boolean useTI = cl.hasOption("t");
         boolean useCrawlerTI = cl.hasOption("c");
 
+        Map<Integer, Long> runErrorMap = new HashMap<Integer, Long>();
+        if (cl.hasOption("e")) {
+            try {
+                BufferedReader br = new BufferedReader(new FileReader(cl.getOptionValue("e")));
+                String line;
+                System.err.println("header error file header: " + br.readLine()); //discard the first line
+                while ((line = br.readLine()) != null) {
+                    String arr[] = line.split(" +");
+                    int run = Integer.parseInt(arr[1]);
+                    long errorTime = Long.parseLong(arr[4]);
+                    runErrorMap.put(run, errorTime);
+//                    System.out.format("%d %d\n", run, errorTime);
+                }
+            } catch (FileNotFoundException ex) {
+                Logger.getLogger(SvtChargeIntegrator.class.getName()).log(Level.SEVERE, null, ex);
+            } catch (IOException ex) {
+                Logger.getLogger(SvtChargeIntegrator.class.getName()).log(Level.SEVERE, null, ex);
+            }
+        }
+
         if (cl.getArgs().length != 2) {
             printUsage(options);
             return;
@@ -89,9 +112,9 @@
             String line;
             System.err.println("myaData header: " + br.readLine()); //discard the first line
             if (perRun) {
-                System.out.println("run_num\tnominal_position\tnEvents\ttotalQ\ttotalQ_withbias\ttotalQ_atnom\tgatedQ\tgatedQ_withbias\tgatedQ_atnom\tgoodQ\tgoodQ_withbias\tgoodQ_atnom");
+                System.out.println("run_num\tnominal_position\tnEvents\ttotalQ\ttotalQ_withbias\ttotalQ_atnom\ttotalQ_noerror\tgatedQ\tgatedQ_withbias\tgatedQ_atnom\tgatedQ_noerror\tgoodQ\tgoodQ_withbias\tgoodQ_atnom\tgoodQ_noerror");
             } else {
-                System.out.println("run_num\tfile_num\tnominal_position\tnEvents\ttotalQ\ttotalQ_withbias\ttotalQ_atnom\tgatedQ\tgatedQ_withbias\tgatedQ_atnom\tgoodQ\tgoodQ_withbias\tgoodQ_atnom");
+                System.out.println("run_num\tfile_num\tnominal_position\tnEvents\ttotalQ\ttotalQ_withbias\ttotalQ_atnom\ttotalQ_noerror\tgatedQ\tgatedQ_withbias\tgatedQ_atnom\tgatedQ_noerror\tgoodQ\tgoodQ_withbias\tgoodQ_atnom\tgoodQ_noerror");
             }
 
             int currentRun = 0;
@@ -129,9 +152,6 @@
                         if (tiTimeOffset == 0) {
                             continue;
                         }
-                        if (tiTimeOffset == 0) {
-                            continue;
-                        }
                     }
 
                     try {
@@ -212,25 +232,40 @@
                     if (firstTI == 0 || lastTI == 0) {
                         continue;
                     }
-                    startDate = new Date((long) ((firstTI + tiTimeOffset) / 1e6));
-                    endDate = new Date((long) ((lastTI + tiTimeOffset) / 1e6));
+                    startDate = new Date((firstTI + tiTimeOffset) / 1000000);
+                    endDate = new Date((lastTI + tiTimeOffset) / 1000000);
                 } else {
                     if (firstTime == 0 || lastTime == 0) {
                         continue;
                     }
                     startDate = new Date(firstTime * 1000);
                     endDate = new Date(lastTime * 1000);
+                }
+
+                Long errorTime = runErrorMap.get(runNum);
+                Date errorDate = null;
+                if (errorTime != null) {
+                    errorDate = new Date(errorTime / 1000000);
+                    boolean isGood = Math.abs(errorDate.getTime() - startDate.getTime()) < 10 * 60 * 60 * 1000; //10 hours
+                    if (!isGood && useTI) {
+                        errorDate = new Date((errorTime + tiTimeOffset) / 1000000);
+//                        boolean isPlusOffsetGood = Math.abs(errorDatePlusOffset.getTime() - startDate.getTime()) < 10 * 60 * 60 * 1000; //10 hours
+//                        System.out.format("%d, %d, %d: %s (good: %b), %s (good: %b)\n", runNum, errorTime, tiTimeOffset, errorDate, isGood, errorDatePlusOffset, isPlusOffsetGood);
+                    }
                 }
 
                 double totalCharge = 0;
                 double totalChargeWithBias = 0;
                 double totalChargeWithBiasAtNominal = 0;
+                double totalChargeWithBiasAtNominalNoError = 0;
                 double totalGatedCharge = 0;
                 double totalGatedChargeWithBias = 0;
                 double totalGatedChargeWithBiasAtNominal = 0;
+                double totalGatedChargeWithBiasAtNominalNoError = 0;
                 double totalGoodCharge = 0;
                 double totalGoodChargeWithBias = 0;
                 double totalGoodChargeWithBiasAtNominal = 0;
+                double totalGoodChargeWithBiasAtNominalNoError = 0;
                 br.mark(1000);
 
                 while ((line = br.readLine()) != null) {
@@ -289,14 +324,23 @@
                         long dtStart = Math.max(startDate.getTime(), lastDate.getTime());
                         long dtEnd = Math.min(date.getTime(), endDate.getTime());
                         double dt = (dtEnd - dtStart) / 1000.0;
+                        double errorDt = 0;
                         if (biasConstant != null) {
                             long biasStart = Math.max(dtStart, biasConstant.getStart());
                             long biasEnd = Math.min(dtEnd, biasConstant.getEnd());
-                            biasDt = (biasEnd - biasStart) / 1000.0;
+                            biasDt = Math.max(0, biasEnd - biasStart) / 1000.0;
                             if (positionConstant != null) {
                                 long positionStart = Math.max(biasStart, positionConstant.getStart());
                                 long positionEnd = Math.min(biasEnd, positionConstant.getEnd());
-                                positionDt = (positionEnd - positionStart) / 1000.0;
+                                positionDt = Math.max(0, positionEnd - positionStart) / 1000.0;
+
+                                long errorEnd = positionStart;
+                                if (errorDate == null) {
+                                    errorEnd = positionEnd;
+                                } else if (errorDate.getTime() > dtStart) {
+                                    errorEnd = Math.min(positionEnd, errorDate.getTime());
+                                }
+                                errorDt = Math.max(0, errorEnd - positionStart) / 1000.0;
                             }
                         }
 //                        System.out.format("start %d end %d date %d lastDate %d current %f dt %f\n", startDate.getTime(), endDate.getTime(), date.getTime(), lastDate.getTime(), current, dt);
@@ -311,6 +355,10 @@
                                 totalChargeWithBiasAtNominal += positionDt * current;
                                 totalGatedChargeWithBiasAtNominal += positionDt * current * livetime;
                                 totalGoodChargeWithBiasAtNominal += positionDt * current * livetime * efficiency;
+
+                                totalChargeWithBiasAtNominalNoError += errorDt * current;
+                                totalGatedChargeWithBiasAtNominalNoError += errorDt * current * livetime;
+                                totalGoodChargeWithBiasAtNominalNoError += errorDt * current * livetime * efficiency;
                             }
                         }
                     }
@@ -326,11 +374,11 @@
                 }
                 if (perRun) {
                     int nEvents = Integer.parseInt(record.get(9));
-                    System.out.format("%d\t%s\t%d\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\n", runNum, nominalPosition, nEvents, totalCharge, totalChargeWithBias, totalChargeWithBiasAtNominal, totalGatedCharge, totalGatedChargeWithBias, totalGatedChargeWithBiasAtNominal, totalGoodCharge, totalGoodChargeWithBias, totalGoodChargeWithBiasAtNominal);
+                    System.out.format("%d\t%s\t%d\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\n", runNum, nominalPosition, nEvents, totalCharge, totalChargeWithBias, totalChargeWithBiasAtNominal, totalChargeWithBiasAtNominalNoError, totalGatedCharge, totalGatedChargeWithBias, totalGatedChargeWithBiasAtNominal, totalGatedChargeWithBiasAtNominalNoError, totalGoodCharge, totalGoodChargeWithBias, totalGoodChargeWithBiasAtNominal, totalGoodChargeWithBiasAtNominalNoError);
                 } else {
                     int fileNum = Integer.parseInt(record.get(1));
                     int nEvents = Integer.parseInt(record.get(2));
-                    System.out.format("%d\t%d\t%s\t%d\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\n", runNum, fileNum, nominalPosition, nEvents, totalCharge, totalChargeWithBias, totalChargeWithBiasAtNominal, totalGatedCharge, totalGatedChargeWithBias, totalGatedChargeWithBiasAtNominal, totalGoodCharge, totalGoodChargeWithBias, totalGoodChargeWithBiasAtNominal);
+                    System.out.format("%d\t%d\t%s\t%d\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\n", runNum, fileNum, nominalPosition, nEvents, totalCharge, totalChargeWithBias, totalChargeWithBiasAtNominal, totalChargeWithBiasAtNominalNoError, totalGatedCharge, totalGatedChargeWithBias, totalGatedChargeWithBiasAtNominal, totalGatedChargeWithBiasAtNominalNoError, totalGoodCharge, totalGoodChargeWithBias, totalGoodChargeWithBiasAtNominal, totalGoodChargeWithBiasAtNominalNoError);
                 }
             }
         } catch (Exception ex) {

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