@@ -26,10 +26,10 @@ public class DaqScalersSequence implements Comparator<DaqScalers> {
2626 public static final double TI_CLOCK_FREQ = 250e6 ; // Hz
2727
2828 protected final List <DaqScalers > scalers =new ArrayList <>();
29-
29+ protected final List <DaqScalersSequence > subsequences =new ArrayList <>();
30+
3031 private Bank runConfigBank =null ;
3132 private Bank runScalerBank =null ;
32- private Bank rawScalerBank =null ;
3333
3434 static final Logger logger = Logger .getLogger (DaqScalersSequence .class .getName ());
3535
@@ -102,8 +102,14 @@ public DaqScalersSequence(SchemaFactory schema) {
102102 runScalerBank =new Bank (schema .getSchema ("RUN::scaler" ));
103103 }
104104
105+ public DaqScalersSequence (List <DaqScalers > inputScalers ) {
106+ for (DaqScalers inputScaler : inputScalers )
107+ this .add (inputScaler );
108+ }
109+
105110 public void clear () {
106111 scalers .clear ();
112+ subsequences .clear ();
107113 }
108114
109115 protected boolean add (DaqScalers ds ) {
@@ -293,7 +299,41 @@ public static DaqScalersSequence rebuildSequence(int tags, ConstantsManager conm
293299 }
294300 return seq ;
295301 }
296-
302+
303+ /**
304+ * Sample this sequence, keeping every nth scaler readout as a subsequence of samples.
305+ * Methods such as `getInterval` will only consider scaler readouts in this sample subsequence.
306+ * The n _original_ scaler readouts between each sample are preserved as subsequences.
307+ * @param n keep every nth scaler readout, including the zeroth and the last. `n` should be `>1`.
308+ */
309+ public void downsample (int n ) {
310+ if (this .scalers .isEmpty () || n <=1 )
311+ return ;
312+ subsequences .clear ();
313+ List <Integer > keep = new ArrayList <>();
314+ keep .add (0 );
315+ for (int i =0 ; i <this .scalers .size (); i +=n ) {
316+ int end = Math .min (i +n , this .scalers .size ()); // the last sample may be smaller
317+ subsequences .add (new DaqScalersSequence (this .scalers .subList (i , end )));
318+ keep .add (end );
319+ }
320+ for (int i =this .scalers .size ()-1 ; i >=0 ; i --)
321+ if (!keep .contains (i ))
322+ this .scalers .remove (i );
323+ }
324+
325+ public double getBeamChargeProxy () {
326+ return 0 ; // FIXME
327+ }
328+
329+ public DaqScalersSequence getSubsequence (long timestamp ) {
330+ return this .subsequences .get (this .findIndex (timestamp )); // FIXME: catch exception
331+ }
332+
333+ public List <DaqScalersSequence > getSubsequences () {
334+ return subsequences ;
335+ }
336+
297337 public static void main (String [] args ) {
298338
299339 final String dir ="/Users/baltzell/data/CLAS12/rg-a/decoded/6b.2.0/" ;
@@ -348,6 +388,14 @@ public static void main(String[] args) {
348388 System .out .println ("DaqScalersSequence: bad/good/badPercent: "
349389 +bad +" " +good +" " +100 *((float )bad )/(bad +good )+"%" );
350390
391+ // QADB usage
392+ long timestamp = 1000 ;
393+ seq .downsample (2000 );
394+ for (DaqScalersSequence subseq : seq .getSubsequences ())
395+ System .out .println (subseq .getBeamChargeProxy ());
396+ System .out .println (seq .getSubsequence (timestamp ).getBeamChargeProxy ());
397+ System .out .println (seq .getInterval (timestamp ).getBeamChargeGated ());
398+
351399 reader .close ();
352400
353401 }
0 commit comments