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:

r3103 - /java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtBiasMyaDumpReader.java

From:

[log in to unmask]

Reply-To:

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

Date:

Sat, 6 Jun 2015 00:18:04 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (199 lines)

Author: [log in to unmask]
Date: Fri Jun  5 17:17:55 2015
New Revision: 3103

Log:
Read, format and find bias run ranges from MYA. 

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

Added: java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtBiasMyaDumpReader.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtBiasMyaDumpReader.java	(added)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtBiasMyaDumpReader.java	Fri Jun  5 17:17:55 2015
@@ -0,0 +1,183 @@
+package org.hps.conditions.svt;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+
+
+public class SvtBiasMyaDumpReader {
+
+    
+    public static void main(String[] args) {
+        
+        SvtBiasMyaDumpReader dumpReader = new SvtBiasMyaDumpReader();
+        
+        for( int i=0; i<args.length; ++i) {
+            dumpReader.addEntries(readMyaDump(new File(args[i])));
+        }
+       System.out.println("Got " + dumpReader.getAllEntries().size() + " entries");
+       
+       dumpReader.buildRanges();
+       
+       dumpReader.printRanges();
+      
+        
+    }
+    
+    
+    
+    
+
+
+
+    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    private static final double BIASVALUEON = 178.0;
+    private List<SvtBiasMyaEntry> myaEntries = new ArrayList<SvtBiasMyaEntry>();
+    private List<SvtBiasMyaRange> myaBiasOnRanges = new ArrayList<SvtBiasMyaRange>();
+    
+    public SvtBiasMyaDumpReader() {
+        // TODO Auto-generated constructor stub
+    }
+
+    public void addEntry(SvtBiasMyaEntry e) {
+        this.myaEntries.add(e);
+    }
+
+    public void addEntries(List<SvtBiasMyaEntry> e) {
+        this.myaEntries.addAll(e);
+    }
+
+    public List<SvtBiasMyaEntry> getAllEntries() {
+        return this.myaEntries;
+    }
+
+    private void printRanges() {
+        for( SvtBiasMyaRange r : myaBiasOnRanges) {
+            System.out.println(r.toString());
+        }
+     }
+    
+    
+    private static List<SvtBiasMyaEntry> readMyaDump(File file) {
+
+        List<SvtBiasMyaEntry> myaEntries = new ArrayList<SvtBiasMyaEntry>();
+        try {
+
+            BufferedReader br = new BufferedReader(new FileReader(file));
+            String line;
+            while ((line = br.readLine()) != null) {
+                //System.out.println(line);
+                String arr[] = line.split(" ");
+                try {
+                    
+                    if(arr.length<3) {
+                        throw new ParseException("this line is not correct.",0);
+                    }
+                    Date date = DATE_FORMAT.parse(arr[0] + " " + arr[1]);
+                    double value = Double.parseDouble(arr[2]);
+                    SvtBiasMyaEntry entry = new SvtBiasMyaEntry(file.getName(), date, value);
+                    myaEntries.add(entry);
+                } catch (ParseException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
+            br.close();
+
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return myaEntries;
+
+    }
+    
+    public void buildRanges() {
+        SvtBiasMyaRange range = null;
+        SvtBiasMyaEntry eprev = null;
+        for(SvtBiasMyaEntry e : this.myaEntries) {
+            
+            //System.out.println(e.toString());
+            
+            if(eprev!=null) {
+                if(e.getDate().before(eprev.getDate())) {
+                    throw new RuntimeException("date list is not ordered.");
+                }
+            }
+            
+            if( e.getValue() > BIASVALUEON) {
+                if (range==null) {
+                    System.out.println("BIAS ON: " + e.toString());
+                    range = new SvtBiasMyaRange();
+                    range.setStart(e);
+                } 
+            } else {
+                //close it
+                if (range!=null) {
+                    System.out.println("BIAS TURNED OFF: " + e.toString());
+                    range.setEnd(eprev);
+                    this.myaBiasOnRanges.add(range);
+                    range = null;
+                }
+            }            
+            eprev = e;
+        }
+        System.out.println("Built " + this.myaBiasOnRanges.size() + " ranges");
+        
+    }
+    
+    
+    public static final class SvtBiasMyaEntry {
+        private Date date;
+        private String name;
+        private double value;
+        public SvtBiasMyaEntry(String name, Date date, double value) {
+            this.date = date;
+            this.name = name;
+            this.value = value;
+        }
+        public double getValue() {
+            return value;
+        }
+        public Date getDate() {
+            return this.date;
+        }
+        public String toString() {
+            return name + " " + date.toString() + " value " + value;
+        }
+    }
+
+   
+    
+    public static final class SvtBiasMyaRange {
+        private SvtBiasMyaEntry start;
+        private SvtBiasMyaEntry end;
+        public SvtBiasMyaRange() {}
+        public SvtBiasMyaRange(SvtBiasMyaEntry start) {
+            this.start = start;
+        }
+        public SvtBiasMyaEntry getEnd() {
+            return end;
+        }
+        public void setEnd(SvtBiasMyaEntry end) {
+            this.end = end;
+        }
+        public SvtBiasMyaEntry getStart() {
+            return start;
+        }
+        public void setStart(SvtBiasMyaEntry start) {
+            this.start = start;
+        }
+        public String toString() {
+            return "START: " + start.toString() + "   END: " + end.toString();
+        }
+    }
+
+}

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