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:

r2871 - /java/trunk/users/src/main/java/org/hps/users/jeremym/EvioFileScanner.java

From:

[log in to unmask]

Reply-To:

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

Date:

Fri, 1 May 2015 18:05:03 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (228 lines)

Author: [log in to unmask]
Date: Fri May  1 11:04:54 2015
New Revision: 2871

Log:
Sync changes from laptop.

Modified:
    java/trunk/users/src/main/java/org/hps/users/jeremym/EvioFileScanner.java

Modified: java/trunk/users/src/main/java/org/hps/users/jeremym/EvioFileScanner.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/EvioFileScanner.java	(original)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/EvioFileScanner.java	Fri May  1 11:04:54 2015
@@ -22,7 +22,9 @@
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
+import org.hps.record.evio.EvioEventConstants;
 import org.hps.record.evio.EvioEventUtilities;
+import org.jlab.coda.jevio.BaseStructure;
 import org.jlab.coda.jevio.EvioEvent;
 import org.jlab.coda.jevio.EvioException;
 import org.jlab.coda.jevio.EvioReader;
@@ -37,7 +39,11 @@
 // -end date (from END)
 // -total number of events
 //
+// -get trigger config
+// -get SVT config
+//
 // Command line args:
+
 // -start and end run number filter (outside range will be excluded)
 // -list of run numbers (not in list will be excluded)
 // -output timestamp file (when dir walk ends)
@@ -48,11 +54,33 @@
     static class EvioFileList extends ArrayList<File> {
 
         public File first() {
-            return get(0);
+            return this.get(0);
+        }
+
+        public int getTotalEvents() {
+            int totalEvents = 0;
+            for (final File file : this) {
+                EvioReader reader = null;
+                try {
+                    reader = new EvioReader(file, false);
+                    totalEvents += reader.getEventCount();
+                } catch (EvioException | IOException e) {
+                    throw new RuntimeException(e);
+                } finally {
+                    if (reader != null) {
+                        try {
+                            reader.close();
+                        } catch (final IOException e) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
+            }
+            return totalEvents;
         }
 
         public File last() {
-            return get(size() - 1);
+            return this.get(this.size() - 1);
         }
 
         public void sort() {
@@ -126,8 +154,8 @@
         }
 
         void sortFiles() {
-            for (final Integer run : keySet()) {
-                get(run).sort();
+            for (final Integer run : this.keySet()) {
+                this.get(run).sort();
             }
         }
     }
@@ -153,7 +181,8 @@
 
     static Integer getRunNumber(final File file) {
         final String name = file.getName();
-        return Integer.parseInt(name.substring(0, name.indexOf(".")).replace("hps_", ""));
+        // FIXME: Better way would be opening the file and getting the PRESTART or head bank value of run.
+        return Integer.parseInt(name.substring(0, name.indexOf(".")).replace("hps_", "").replace("cosmic_", ""));
     }
 
     static Integer getSequenceNumber(final File file) {
@@ -169,19 +198,23 @@
 
     File rootDir = new File(System.getProperty("user.dir"));
 
-    Date getRunEnd(final File file) {
+    Date getDate(final File file, final int eventTag, final int gotoEvent) {
         Date date = null;
         EvioReader reader = null;
         try {
             reader = new EvioReader(file.getPath(), false);
             EvioEvent event;
+            if (gotoEvent > 0) {
+                reader.gotoEventNumber(gotoEvent);
+            } else if (gotoEvent < 0) {
+                reader.gotoEventNumber(reader.getEventCount() + gotoEvent);
+            }
             while ((event = reader.parseNextEvent()) != null) {
-                if (EvioEventUtilities.isEndEvent(event)) {
+                if (event.getHeader().getTag() == eventTag) {
                     final int[] data = EvioEventUtilities.getControlEventData(event);
-                    long seconds = (long)data[0];
-                    //System.out.printf("END control: %d %d %d", data[0], data[1], data[2]);
+                    final long seconds = data[0];
+                    System.out.printf("control: %d %d %d %n", data[0], data[1], data[2]);
                     date = new Date(seconds * MILLISECONDS);
-                    //System.out.println("END date: " + date);
                     break;
                 }
             }
@@ -199,30 +232,69 @@
         return date;
     }
 
+    Date getHeadBankDate(final EvioEvent event) {
+        Date date = null;
+        final BaseStructure headBank = EvioEventUtilities.getHeadBank(event);
+        if (headBank != null) {
+            final int[] data = headBank.getIntData();
+            final long time = data[3];
+            System.out.printf("head bank: %d %d %d %d %d%n", data[0], data[1], data[2], data[3], data[4]);
+            System.out.println("time from head bank: " + time);
+            date = new Date(time);
+        }
+        return date;
+    }
+
+    Date getRunEnd(final File file) {
+        System.out.println("getRunEnd");
+        Date date = this.getDate(file, EvioEventConstants.END_EVENT_TAG, -10);
+        if (date == null) {
+            System.out.println("END tag not found; looking at last event ...");
+            EvioReader reader = null;
+            try {
+                reader = new EvioReader(file.getPath(), false);
+                System.out.println("event count: " + reader.getEventCount());
+                final EvioEvent lastEvent = reader.getEvent(reader.getEventCount() - 1);
+                reader.parseEvent(lastEvent);
+                System.out.println("getting date from last event " + lastEvent.getEventNumber());
+                date = this.getHeadBankDate(lastEvent);
+            } catch (EvioException | IOException e) {
+                throw new RuntimeException(e);
+            } finally {
+                if (reader != null) {
+                    try {
+                        reader.close();
+                    } catch (final IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+        return date;
+    }
+
     Date getRunStart(final File file) {
-        Date date = null;
-        EvioReader reader = null;
-        try {
-            reader = new EvioReader(file.getPath(), false);
-            EvioEvent event;
-            while ((event = reader.parseNextEvent()) != null) {
-                if (EvioEventUtilities.isPreStartEvent(event)) {
-                    final int[] data = EvioEventUtilities.getControlEventData(event);
-                    //System.out.printf("PRESTART control: %d %d %d%n", data[0], data[1], data[2]);
-                    long seconds = (long)data[0];
-                    date = new Date(seconds * MILLISECONDS);
-                    //System.out.println("PRESTART date: " + date);
-                    break;
-                }
-            }
-        } catch (EvioException | IOException e) {
-            throw new RuntimeException(e);
-        } finally {
-            if (reader != null) {
-                try {
-                    reader.close();
-                } catch (final IOException e) {
-                    e.printStackTrace();
+        System.out.println("getRunStart");
+        Date date = this.getDate(file, EvioEventConstants.PRESTART_EVENT_TAG, 0);
+        if (date == null) {
+            System.out.println("PRESTART not found; looking at first event ...");
+            EvioReader reader = null;
+            try {
+                reader = new EvioReader(file.getPath(), false);
+                EvioEvent event = null;
+                while (!EvioEventUtilities.isPhysicsEvent(event = reader.parseNextEvent())) {
+                }
+                System.out.println("looking at head bank of event " + event.getEventNumber());
+                date = this.getHeadBankDate(event);
+            } catch (EvioException | IOException e) {
+                throw new RuntimeException(e);
+            } finally {
+                if (reader != null) {
+                    try {
+                        reader.close();
+                    } catch (final IOException e) {
+                        e.printStackTrace();
+                    }
                 }
             }
         }
@@ -269,8 +341,9 @@
             final EvioFileList files = runMap.get(run);
             System.out.println("first file " + files.first());
             System.out.println("last file " + files.last());
-            System.out.println("started at " + getRunStart(files.first()));
-            System.out.println("ended at " + getRunEnd(files.last()));
+            System.out.println("started at " + this.getRunStart(files.first()));
+            System.out.println("ended at " + this.getRunEnd(files.last()));
+            System.out.println("total events: " + files.getTotalEvents());
         }
     }
 }

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