Example of Using Scaler Classes to Read a CODA File

Robert Michaels, rom@jlab.org, Jefferson Lab Hall A, May 2001

This file:     hallaweb.jlab.org/equipment/daq/tscalfile_main.html


The following example shows how to use the hana_scaler package to read from a CODA file and print out some stuff about triggers and charge. One must initialize the THaScaler object with the time. Default time is "now" if the time argument is left out.

//--------------------------------------------------------
//  tscalfile_main.C
//
//  Test of scaler class, for reading a CODA file
// 
//  R. Michaels, May 2001
//--------------------------------------------------------

#include < iostream >
#include < string >
#include "THaScaler.h"
#include "THaCodaFile.h"

int main(int argc, char* argv[]) {
   THaScaler *scaler;
   scaler = new THaScaler;
   TString filename = "run.dat";

   if (argc < 2) {
     cout << "Usage:  " << argv[0] << " bank" << endl;
     cout << "where bank = 'Right', 'Left', or 'RCS'" << endl;
     return 1;
   }
   string bank = argv[1];   
   cout << "Bank = " << bank << endl << flush;

   if (scaler->Init("7-4-1999",bank) == -1) {  // Init MUST be done once
      cout << "Error initializing scaler " << endl;
      return 1;
   }

   int status = 1;
   while (status) {
     status = scaler->LoadDataCodaFile(filename);   // load data for 'filename'
     if (!status) break;
     scaler->Print();     // raw diagnostic printout
     cout << "\n-------------------------------------------------\n" << endl;
     cout << "Time    bcm_u3     bcm_d3     bcm_u10     bcm_d10   ";
     cout << "  trigger-1     trigger-3    trigger-5" << endl;
     cout << "(sec)   (arb)      (arb)      (arb)       (arb)     ";
     cout << " counts  Hz     counts  Hz   counts  Hz" << endl;
     Double_t time = scaler->GetPulser("clock")/1024;
     cout << time << " " <GetBcm("bcm_u3") << "   " << scaler->GetBcm("bcm_d3");
     cout << "  " << scaler->GetBcm("bcm_u10") << "  " << scaler->GetBcm("bcm_d10");
     cout << "  " << scaler->GetTrig(1) << "  " << scaler->GetTrigRate(1);
     cout << "  " << scaler->GetTrig(3) << "  " << scaler->GetTrigRate(3);
     cout << "  " << scaler->GetTrig(5) << "  " << scaler->GetTrigRate(5) << endl;
   }

   return 0;
}