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

HPS-SVN January 2015

Subject:

r1947 - /java/trunk/conditions/src/main/java/org/hps/conditions/beam/ImportBeamConditionsEngRun.java

From:

[log in to unmask]

Reply-To:

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

Date:

Fri, 16 Jan 2015 23:57:36 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (126 lines)

Author: [log in to unmask]
Date: Fri Jan 16 15:57:30 2015
New Revision: 1947

Log:
Add simple tool for importing beam conditions from text dump.

Added:
    java/trunk/conditions/src/main/java/org/hps/conditions/beam/ImportBeamConditionsEngRun.java

Added: java/trunk/conditions/src/main/java/org/hps/conditions/beam/ImportBeamConditionsEngRun.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/beam/ImportBeamConditionsEngRun.java	(added)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/beam/ImportBeamConditionsEngRun.java	Fri Jan 16 15:57:30 2015
@@ -0,0 +1,110 @@
+package org.hps.conditions.beam;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.logging.Level;
+
+import org.hps.conditions.api.ConditionsRecord;
+import org.hps.conditions.beam.BeamConditions.BeamConditionsCollection;
+import org.hps.conditions.database.DatabaseConditionsManager;
+
+/**
+ * <p>
+ * Import beam measurements into the database from a text file.
+ * <p>
+ * This has the format:<br/> 
+ * run current x y
+ * <p>
+ * The beam energy is hard-coded to 1.92 GeV for now, pending updates with better information.
+ *  
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public final class ImportBeamConditionsEngRun {
+
+    static double beamEnergy = 1.92;
+    static double nullValue = -999.0;
+    
+    private ImportBeamConditionsEngRun() {
+    }
+    
+    public static void main(String[] args) throws Exception {
+        
+        if (args.length == 0) {
+            throw new RuntimeException("missing file list argument");
+        }
+        
+        String fileName = args[0];
+        if (!new File(fileName).exists()) {
+            throw new IOException("The file " + fileName + " does not exist.");
+        }
+        
+        Map<Integer, BeamConditions> beamMap = new LinkedHashMap<Integer, BeamConditions>();
+                
+        BufferedReader reader = new BufferedReader(new FileReader(fileName));
+        String line;
+        while ((line = reader.readLine()) != null) {
+            
+            String[] values = line.split(" "); 
+            
+            BeamConditions beam = new BeamConditions();
+            
+            setValue(beam, "current", values[1]);
+            setValue(beam, "position_x", values[2]);
+            setValue(beam, "position_y", values[3]);
+                        
+            if (beam.getFieldValue("current") == null) {
+                // Use null value to indicate beam was not measured.
+                beam.setFieldValue("energy", null);
+            } else if (((Double)beam.getFieldValue("current")) == 0) {
+                // Use zero for no beam.
+                beam.setFieldValue("energy", 0);
+            } else {
+                // Use nominal beam energy from ECAL commissioning.
+                beam.setFieldValue("energy", beamEnergy);
+            }
+                       
+            beamMap.put(Integer.parseInt(values[0]), beam);
+        }
+        reader.close();
+        
+        System.out.println("printing beam conditions parsed from " + fileName + " ...");
+        System.out.println("run id current x y energy");
+        for (Entry<Integer, BeamConditions> entry : beamMap.entrySet()) {
+            System.out.print(entry.getKey() + " ");
+            System.out.println(entry.getValue() + " ");
+        }
+        
+        DatabaseConditionsManager manager = new DatabaseConditionsManager();
+        manager.setLogLevel(Level.ALL);
+        manager.openConnection();
+        
+        for (Entry<Integer, BeamConditions> entry : beamMap.entrySet()) {
+            int run = entry.getKey();
+            BeamConditions beam = entry.getValue();
+            int collectionId = manager.getNextCollectionID("beam");
+            ConditionsRecord record = 
+                    new ConditionsRecord(collectionId, run, run, "beam", "beam", "imported from HPS_Runs.pdf", "eng_run");
+            System.out.println(record);
+            System.out.println(beam);
+            BeamConditionsCollection collection = new BeamConditionsCollection();
+            collection.add(beam);
+            manager.insertCollection(collection);
+            record.insert();
+        }        
+        manager.closeConnection();
+    }    
+    
+    static void setValue(BeamConditions beam, String fieldName, String rawValue) {
+        double value = Double.parseDouble(rawValue);
+        if (value != nullValue) {                
+            beam.setFieldValue(fieldName, value);
+        } else {
+            beam.setFieldValue(fieldName, null);
+        }
+    }    
+}

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