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

HPS-SVN August 2015

Subject:

r3354 - in /java/trunk/users/src/main/java/org/hps/users/spaul: GetChargeFromScalersMultirun.java timinginfo.txt

From:

[log in to unmask]

Reply-To:

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

Date:

Fri, 7 Aug 2015 22:18:22 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (191 lines)

Author: [log in to unmask]
Date: Fri Aug  7 15:18:20 2015
New Revision: 3354

Log:
added stuff for integrating current

Added:
    java/trunk/users/src/main/java/org/hps/users/spaul/GetChargeFromScalersMultirun.java
    java/trunk/users/src/main/java/org/hps/users/spaul/timinginfo.txt

Added: java/trunk/users/src/main/java/org/hps/users/spaul/GetChargeFromScalersMultirun.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/spaul/GetChargeFromScalersMultirun.java	(added)
+++ java/trunk/users/src/main/java/org/hps/users/spaul/GetChargeFromScalersMultirun.java	Fri Aug  7 15:18:20 2015
@@ -0,0 +1,161 @@
+package org.hps.users.spaul;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Scanner;
+/**
+ * sums up the charge from multiple runs.  
+ * @author sebouhpaul
+ *
+ */
+public class GetChargeFromScalersMultirun {
+	private static ArrayList<String> runs;
+	private static ArrayList<Date> starts;
+	private static ArrayList<Date> ends;
+
+	public static void main(String[] arg) throws FileNotFoundException, ParseException{
+		String inputFile = arg[0];
+		String timingInfoFile = arg[1];
+		String outputFile = arg[2];
+		
+		
+		readTimingInfoFile(timingInfoFile);
+		
+		Map map = getCharges(runs, starts, ends, inputFile);
+		mergeBiasIntervals(map);
+		
+		ArrayList<String> keys = new ArrayList(map.keySet());
+		Collections.sort(keys);
+		
+		
+		PrintWriter pw = new PrintWriter(new File(outputFile));
+		for(String s : keys){
+			pw.println(s + "\t" + map.get(s));
+			System.out.println(s + "\t" + map.get(s));
+		}
+		pw.close();
+	}
+
+	static void readTimingInfoFile(String s) throws FileNotFoundException, ParseException{
+		Scanner scanner = new Scanner(new File(s));
+		scanner.useDelimiter("[\n\t]");
+		runs = new ArrayList();
+		starts = new ArrayList();
+		ends = new ArrayList();
+		DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z");
+		
+		while(scanner.hasNext()){
+			runs.add(scanner.next());
+			String n = scanner.next();
+			if(n.matches("\\d+"))
+				starts.add(new Date(Long.parseLong(n)));
+			else 
+				starts.add(df.parse(n));
+			n = scanner.next();
+			if(n.matches("\\d+"))
+				ends.add(new Date(Long.parseLong(n)));
+			else 
+				ends.add(df.parse(n));
+			
+		}
+		scanner.close();
+	}
+	
+	
+	
+	
+	
+	/**
+	 * returns charge in microCoulombs
+	 * @param runs names of the runs   
+	 * @param starts starting times of the runs
+	 * @param ends ending times of the runs
+	 * @param file the mya file that we need to use
+	 * @return a map relating the runs to the charges (uC).  
+	 * @throws FileNotFoundException
+	 */
+	
+	static Map<String, Double> getCharges(ArrayList<String> runs, ArrayList<Date> starts, ArrayList<Date> ends, String file) throws FileNotFoundException{
+		Scanner s = new Scanner(new File(file));
+		HashMap<String, Double> map = new HashMap();
+		long prev = 0;
+		long time = 0;
+		for(int i = 0; i< runs.size(); i++){
+			long endt = ends.get(i).getTime();
+			long startt = starts.get(i).getTime();
+			
+			double charge = 0;
+			boolean started = false;
+			double prevval = 0;
+			if(time > endt){
+				s.close();
+				s = new Scanner(new File(file));
+			}
+			inner : while(s.hasNext()){
+				String var = s.next();
+				prev = time;
+				time = s.nextLong()*1000; //convert from s to ms
+
+				double val = s.nextDouble();
+				if(!var.equals("scaler_calc1"))
+					continue;
+				
+				if(!started && time> startt){ //first sample in the run
+					charge += (val)/2.*(time-startt);
+					started= true;
+				}
+				
+				else if(time > startt && endt > time){ //middle samples in the run
+					charge += (val/*+prevval*/)/*/2.*/*(time-prev);
+					
+				}
+				
+				if(endt < time){ //last sample that is in the run
+					charge += (/*prev*/val)/2.*(endt-prev);
+					break inner;
+				}
+				prevval = val;
+			}
+			charge/=1e6;
+			map.put(runs.get(i), charge);
+		}
+		s.close();
+		return map;
+
+	}
+	
+	/**
+	 * If the subsections of the runs in which the bias is on are labeled according to a scheme,
+	they will be added together.  
+	for instance, 5779a, 5779b, 5779c, etc. will be added up as 5779bias.   
+	 * @param map the map of run names (and portions of runs that have bias labeled as [run number][a,b,c,d...],
+	 * corresponding to the total charge in that run (or piece of a run).  
+	 */
+	static void mergeBiasIntervals(Map<String, Double> map){
+		Map<String, Double> map2 = new HashMap();
+		for(Map.Entry<String, Double> entry : map.entrySet()){
+			String key1 = entry.getKey();
+			if(!entry.getKey().matches("\\d+a"))
+					continue;
+			double charge = entry.getValue();
+			for(Map.Entry<String, Double> entry2 : map.entrySet()){
+				if(entry2.getKey().matches(key1.substring(0, 4) + "[b-z]"))
+						charge += entry2.getValue();
+			}
+			map2.put(key1.substring(0, 4) + "bias", charge);
+			
+		}
+		for(Map.Entry<String, Double> e : map2.entrySet()){
+			map.put(e.getKey(), e.getValue());
+		}
+	}
+}

Added: java/trunk/users/src/main/java/org/hps/users/spaul/timinginfo.txt
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/spaul/timinginfo.txt	(added)
+++ java/trunk/users/src/main/java/org/hps/users/spaul/timinginfo.txt	Fri Aug  7 15:18:20 2015
@@ -0,0 +1,7 @@
+5779a	05/17/2015 13:18:41 EDT	05/17/2015 13:20:03 EDT
+5779b	05/17/2015 13:21:29 EDT	05/17/2015 13:32:03 EDT
+5779c	05/17/2015 13:33:59 EDT	05/17/2015 13:49:32 EDT
+5781a	05/17/2015 14:00:09 EDT	05/17/2015 14:29:12 EDT
+5781b	05/17/2015 14:30:04 EDT	05/17/2015 14:33:39 EDT
+5779	05/17/2015 13:18:41 EDT	05/17/2015 13:49:32 EDT
+5781	05/17/2015 14:00:09 EDT	05/17/2015 14:33:39 EDT

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