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

HPS-SVN May 2015

Subject:

r3031 - in /java/trunk/conditions/src/main/java/org/hps/conditions/run: ./ RunSpreadsheet.java

From:

[log in to unmask]

Reply-To:

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

Date:

Wed, 27 May 2015 18:30:09 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (138 lines)

Author: [log in to unmask]
Date: Wed May 27 11:29:58 2015
New Revision: 3031

Log:
Add simple Java class to read data from a CSV export of the run spreadsheet.

Added:
    java/trunk/conditions/src/main/java/org/hps/conditions/run/
    java/trunk/conditions/src/main/java/org/hps/conditions/run/RunSpreadsheet.java

Added: java/trunk/conditions/src/main/java/org/hps/conditions/run/RunSpreadsheet.java
 =============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/run/RunSpreadsheet.java	(added)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/run/RunSpreadsheet.java	Wed May 27 11:29:58 2015
@@ -0,0 +1,121 @@
+package org.hps.conditions.run;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVParser;
+import org.apache.commons.csv.CSVRecord;
+
+/**
+ * A simple representation of the 2015 run spreadsheet (runs from 3/28 to 5/19) read from an exported CSV file as a list of records.
+ * <p>
+ * Master copy of the spreadsheet is located at 
+ * <a href="https://docs.google.com/spreadsheets/d/1l1NurPpsmpgZKgr1qoQpLQBBLz1sszLz4xZF-So4xs8/edit#gid=43855609">HPS_Runs_2015</a>.
+ * <p>
+ * The rows are accessible as raw CSV data through the Apache Commons CSV library, and this data must be manually cleaned up and converted 
+ * to the correct data type before being inserted into the conditions database.
+ *
+ * @author Jeremy McCormick
+ */
+public final class RunSpreadsheet {
+
+    /**
+     * The column headers.
+     */
+    private static String[] HEADERS = {"run", "date", "start_time", "end_time", "to_tape", "n_events", "trigger_rate", "target", "beam_current",
+        "beam_x", "beam_y", "trigger_config", "ecal_fadc_mode", "ecal_fadc_thresh", "ecal_fadc_window", "ecal_cluster_thresh_seed", "ecal_cluster_thresh_cluster",
+        "ecal_cluster_window_hits", "ecal_cluster_window_pairs", "ecal_scalers_fadc", "ecal_scalers_dsc", "svt_y_position", "svt_offset_phase", "svt_offset_time",
+        "ecal_temp", "ecal_lv_current", "notes"};
+
+    /**
+     * Read the CSV file from the command line and print the data to the terminal (just a basic test).
+     *
+     * @param args the command line arguments
+     */
+    public static void main(final String args[]) {
+        final RunSpreadsheet runSpreadsheet = new RunSpreadsheet(new File(args[0]));
+        for (final CSVRecord record : runSpreadsheet.getRecords()) {
+            System.out.println(record);
+        }
+    }
+
+    /**
+     * The input CSV file.
+     */
+    private final File file;
+
+    /**
+     * The list of records read from the CSV file.
+     */
+    private List<CSVRecord> records;
+
+    /**
+     * Read the data from a CSV export of the run spreadsheet.
+     *
+     * @param file the CSV file
+     */
+    public RunSpreadsheet(final File file) {
+        this.file = file;
+        try {
+            this.fromCsv(this.file);
+        } catch (final Exception e) {
+            throw new RuntimeException();
+        }
+    }
+
+    /**
+     * Find the record for a run in the list of records.
+     *
+     * @param run the run number
+     * @return the <code>CSVRecord</code> or <code>null</code> if not found
+     */
+    public CSVRecord findRun(final int run) {
+        for (final CSVRecord record : records) {
+            try {
+                if (run == Integer.parseInt(record.get("run_number"))) {
+                    return record;
+                }
+            } catch (final NumberFormatException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Read all the records from the CSV file.
+     *
+     * @param file the CSV file
+     * @throws FileNotFoundException if file does not exist
+     * @throws IOException if there is an IO error
+     */
+    private void fromCsv(final File file) throws FileNotFoundException, IOException {
+
+        final FileReader reader = new FileReader(file);
+        final CSVFormat format = CSVFormat.DEFAULT.withHeader(HEADERS);
+
+        final CSVParser parser = new CSVParser(reader, format);
+
+        records = parser.getRecords();
+
+        // Remove first three rows of headers.
+        records.remove(0);
+        records.remove(0);
+        records.remove(0);
+
+        parser.close();
+    }
+
+    /**
+     * Get the list of records read from the CSV file.
+     *
+     * @return the list of records read from the CSV file
+     */
+    public List<CSVRecord> getRecords() {
+        return records;
+    }
+}

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