Commit in hps-java/src/main/java/org/lcsim/hps/util on MAIN
RingBuffer.java+47added 1.1
Add ring buffer for ECal and tracker time evolution

hps-java/src/main/java/org/lcsim/hps/util
RingBuffer.java added at 1.1
diff -N RingBuffer.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ RingBuffer.java	19 Aug 2011 16:24:12 -0000	1.1
@@ -0,0 +1,47 @@
+package org.lcsim.hps.util;
+
+/**
+ * Ring buffer for storing ECal (and possibly SVT) samples for trigger and readout
+ *
+ * @author Sho Uemura <[log in to unmask]>
+ */
+public class RingBuffer {
+
+    private double[] array;
+    private int size;
+    private int ptr;
+
+    public RingBuffer(int size) {
+        this.size = size;
+        array = new double[size]; //initialized to 0
+        ptr = 0;
+    }
+    
+    /**
+     * 
+     * @return value stored at current cell
+     */
+    public double currentValue() {
+        return array[ptr];
+    }
+     
+    /**
+     * Clear value at current cell and step to the next one
+     */
+    public void step() {
+        array[ptr]=0;
+        ptr++;
+        if (ptr==size) ptr = 0;
+    }
+    
+    /**
+     * Add given value to specified cell
+     * @param pos Target position relative to current cell (pos=0 for current cell)
+     * @param val 
+     */
+    public void addToCell(int pos, double val) {
+        array[(ptr+pos)%size]+=val;
+    }
+    
+    
+}
CVSspam 0.2.8