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:

r3449 - in /java/trunk/record-util/src/main/java/org/hps/record/scalers: ScalerData.java ScalerUtilities.java ScalersEvioProcessor.java ScalersGenericObject.java package-info.java

From:

[log in to unmask]

Reply-To:

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

Date:

Fri, 28 Aug 2015 22:25:36 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (284 lines)

Author: [log in to unmask]
Date: Fri Aug 28 15:25:34 2015
New Revision: 3449

Log:
Add timestamp to scaler data interface; other minor changes.  HPSJAVA-593

Modified:
    java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalerData.java
    java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalerUtilities.java
    java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalersEvioProcessor.java
    java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalersGenericObject.java
    java/trunk/record-util/src/main/java/org/hps/record/scalers/package-info.java

Modified: java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalerData.java
 =============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalerData.java	(original)
+++ java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalerData.java	Fri Aug 28 15:25:34 2015
@@ -1,16 +1,19 @@
 package org.hps.record.scalers;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.lcsim.event.EventHeader;
+import org.lcsim.event.EventHeader.LCMetaData;
 import org.lcsim.event.GenericObject;
 
 /**
  * This class encapsulates EVIO scaler data which is simply an array of integer values. The exact meaning of each of
  * these integer words is defined externally to this class.
  *
- * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
+ * @author Jeremy McCormick, SLAC
  */
 public final class ScalerData {
 
@@ -23,6 +26,21 @@
      * Default name of scaler data collection in LCSim events.
      */
     private static final String DEFAULT_COLLECTION_NAME = "ScalerData";
+
+    /**
+     * Dummy float parameters to make LCIO persistency work.
+     */
+    private static final Map<String, float[]> DUMMY_FLOAT_MAP = new HashMap<String, float[]>();
+
+    /**
+     * Dummy int parameters to make LCIO persistency work.
+     */
+    private static final Map<String, String[]> DUMMY_STRING_MAP = new HashMap<String, String[]>();
+
+    /**
+     * Name of timestamp field in collection parameters.
+     */
+    private static final String TIMESTAMP = "TIMESTAMP";
 
     /**
      * Create a new <code>ScalerData</code> object from an LCIO event, using the default collection name.
@@ -43,11 +61,22 @@
     public static ScalerData read(final EventHeader event, final String collectionName) {
         ScalerData data = null;
         if (event.hasCollection(GenericObject.class, collectionName)) {
-            // System.out.println("ScalerData - found collection");
+
+            // Read from generic object.
             final List<GenericObject> objects = event.get(GenericObject.class, collectionName);
             data = new ScalerData();
             data.fromGenericObject(objects.get(0));
-            data.setEventId(event.getEventNumber());
+
+            // Set event ID.
+            data.eventId = event.getEventNumber();
+
+            // Read timestamp.
+            final LCMetaData metadata = event.getMetaData(objects);
+            try {
+                data.timestamp = metadata.getIntegerParameters().get(TIMESTAMP)[0];
+            } catch (final Exception e) {
+                throw new RuntimeException("Scaler data is missing timestamp parameter.", e);
+            }
         }
         return data;
     }
@@ -63,6 +92,11 @@
     private Integer eventId;
 
     /**
+     * The timestamp of the scaler event.
+     */
+    private Integer timestamp;
+
+    /**
      * This is the no argument constructor which is for package internal use only.
      */
     ScalerData() {
@@ -73,10 +107,11 @@
      *
      * @param data the scaler data
      */
-    public ScalerData(final int[] data, final int eventId) {
+    public ScalerData(final int[] data, final int eventId, final int timestamp) {
         this.data = new int[data.length];
         System.arraycopy(data, 0, this.data, 0, data.length);
         this.eventId = eventId;
+        this.timestamp = timestamp;
     }
 
     /**
@@ -101,6 +136,15 @@
     public Integer getEventId() {
         // Null value will be returned here to indicate not set.
         return this.eventId;
+    }
+
+    /**
+     * Get the scaler data's Unix timestamp.
+     *
+     * @return the scaler data's Unix timestamp
+     */
+    public int getTimestamp() {
+        return this.timestamp;
     }
 
     /**
@@ -184,8 +228,17 @@
      * @param collectionName the name of the output collection
      */
     private void write(final EventHeader event, final String collectionName) {
+
+        // Create generic object collection.
         final List<GenericObject> collection = new ArrayList<GenericObject>();
         collection.add(this.toGenericObject());
-        event.put(collectionName, collection, GenericObject.class, 0);
-    }    
+
+        // Add collection parameter with timestamp.
+        final Map<String, int[]> timestampParameter = new HashMap<String, int[]>();
+        timestampParameter.put(TIMESTAMP, new int[] {timestamp});
+
+        // Put collection into event.
+        event.put(collectionName, collection, GenericObject.class, 0, timestampParameter, DUMMY_FLOAT_MAP,
+                DUMMY_STRING_MAP);
+    }
 }

Modified: java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalerUtilities.java
 =============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalerUtilities.java	(original)
+++ java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalerUtilities.java	Fri Aug 28 15:25:34 2015
@@ -5,7 +5,7 @@
  * <p>
  * Currently this is used only for computing live time measurements from standard scaler data.
  *
- * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
+ * @author Jeremy McCormick, SLAC
  */
 public final class ScalerUtilities {
 

Modified: java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalersEvioProcessor.java
 =============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalersEvioProcessor.java	(original)
+++ java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalersEvioProcessor.java	Fri Aug 28 15:25:34 2015
@@ -18,7 +18,7 @@
 /**
  * This is an EVIO event processor for creating a {@link ScalerData} object from scaler bank data.
  *
- * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
+ * @author Jeremy McCormick, SLAC
  */
 public class ScalersEvioProcessor extends EvioEventProcessor {
 
@@ -29,16 +29,29 @@
      * Currently cached ScalerData object which was created by the process method.
      */
     private ScalerData currentScalerData;
+
+    /**
+     * Set to <code>true</code> if cached data object should be reset between every event even if scaler data is not
+     * present.
+     */
     private boolean resetEveryEvent = true;
 
+    /**
+     * The complete set of scaler data found in the job.
+     */
     private Set<ScalerData> scalerDataSet = new LinkedHashSet<ScalerData>();
 
+    /**
+     * Get the current cached scaler data object.
+     *
+     * @return the current scaler data object
+     */
     public ScalerData getCurrentScalerData() {
         return this.currentScalerData;
     }
 
     /**
-     * Get the current scaler data or null if there was none in the last event processed.
+     * Get the list of scaler data found in the job.
      *
      * @return the current scaler data or <code>null</code> if none exists
      */
@@ -46,6 +59,12 @@
         return new ArrayList<ScalerData>(this.scalerDataSet);
     }
 
+    /**
+     * Get scaler data from the EVIO event.
+     *
+     * @param evioEvent the EVIO event
+     * @return the scaler data or <code>null</code> if none exists
+     */
     private ScalerData getScalerData(final EvioEvent evioEvent) {
         ScalerData scalerData = null;
         // Proceed if sync bit checking is not enabled or sync bit is on.
@@ -60,9 +79,14 @@
                             LOGGER.fine("found scaler data in bank " + subBank.getHeader().getTag()
                                     + " and EVIO event " + evioEvent.getEventNumber());
 
-                            // Scaler data exists in event so create object and stop processing.
-                            scalerData = new ScalerData(subBank.getIntData(),
-                                    EvioEventUtilities.getEventIdData(evioEvent)[0]);
+                            // Get event ID.
+                            final int eventId = EvioEventUtilities.getEventIdData(evioEvent)[0];
+
+                            // Get event's timestamp.
+                            final int timestamp = EvioEventUtilities.getHeadBankData(evioEvent)[3];
+
+                            // Create scaler data.
+                            scalerData = new ScalerData(subBank.getIntData(), eventId, timestamp);
 
                             break outerBankLoop;
                         }
@@ -93,10 +117,18 @@
         }
     }
 
+    /**
+     * Set to <code>true</code> to reset scaler data object between every EVIO event.
+     *
+     * @param resetEveryEvent <code>true</code> to reset scaler data between every EVIO event
+     */
     public void setResetEveryEvent(final boolean resetEveryEvent) {
         this.resetEveryEvent = resetEveryEvent;
     }
 
+    /**
+     * Start of job hook which resets collecton of cached scaler data.
+     */
     @Override
     public void startJob() {
         this.scalerDataSet = new LinkedHashSet<ScalerData>();

Modified: java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalersGenericObject.java
 =============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalersGenericObject.java	(original)
+++ java/trunk/record-util/src/main/java/org/hps/record/scalers/ScalersGenericObject.java	Fri Aug 28 15:25:34 2015
@@ -6,7 +6,7 @@
  * This is the LCIO {@link org.lcsim.event.GenericObject} binding for EVIO scaler data. This should not be used
  * directly. Rather the {@link ScalerData} class should be used for loading data from LCIO events.
  *
- * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
+ * @author Jeremy McCormick, SLAC
  */
 final class ScalersGenericObject implements GenericObject {
 

Modified: java/trunk/record-util/src/main/java/org/hps/record/scalers/package-info.java
 =============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/scalers/package-info.java	(original)
+++ java/trunk/record-util/src/main/java/org/hps/record/scalers/package-info.java	Fri Aug 28 15:25:34 2015
@@ -1,6 +1,6 @@
 /**
  * Classes for converting scaler data from EVIO to LCSim.
  *
- * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
+ * @author Jeremy McCormick, SLAC
  */
 package org.hps.record.scalers;

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