From 1694ab37b97836a84abe73fac52aac4f6efa7741 Mon Sep 17 00:00:00 2001 From: Chao Peng <thor1009@gmail.com> Date: Wed, 1 Jan 2020 15:42:57 -0600 Subject: [PATCH] add logger to THcHelicityScaler class --- src/THcHelicityScaler.cxx | 47 +++++++++++++++++---------------------- src/THcHelicityScaler.h | 3 ++- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/THcHelicityScaler.cxx b/src/THcHelicityScaler.cxx index 32db496..fb59d2b 100644 --- a/src/THcHelicityScaler.cxx +++ b/src/THcHelicityScaler.cxx @@ -32,7 +32,6 @@ #include <iostream> #include <sstream> #include <map> -#include <bitset> #include <iterator> #include "THaVarList.h" #include "VarDef.h" @@ -51,7 +50,7 @@ static const UInt_t MAXCHAN = 32; static const UInt_t defaultDT = 4; THcHelicityScaler::THcHelicityScaler(const char *name, const char* description) - : THaEvtTypeHandler(name, description), + : hcana::ConfigLogging<THaEvtTypeHandler>(name,description), fBankID(9801), fUseFirstEvent(kTRUE), fDelayedType(-1) @@ -80,17 +79,16 @@ THcHelicityScaler::~THcHelicityScaler() Int_t THcHelicityScaler::End( THaRunBase* ) { // Process any delayed events in order received - - cout << "THcHelicityScaler::End Analyzing " << fDelayedEvents.size() << " delayed helicity scaler events" << endl; - for(std::vector<UInt_t*>::iterator it = fDelayedEvents.begin(); - it != fDelayedEvents.end(); ++it) { + const static char* const here = "THcHelicityScaler::End"; + _param_logger->info("{} Analyzing {} delayed helicity scaler events", here, fDelayedEvents.size()); + for(auto it = fDelayedEvents.begin(); it != fDelayedEvents.end(); ++it) { UInt_t* rdata = *it; AnalyzeBuffer(rdata); } - for( vector<UInt_t*>::iterator it = fDelayedEvents.begin(); - it != fDelayedEvents.end(); ++it ) + for(auto it = fDelayedEvents.begin(); it != fDelayedEvents.end(); ++it) { delete [] *it; + } fDelayedEvents.clear(); // cout << " -- Helicity Scalers -- " << endl; @@ -123,7 +121,7 @@ Int_t THcHelicityScaler::End( THaRunBase* ) Double_t clockfreq=1000000.0; Double_t pclock = fHScalers[0][clockindex]; Double_t mclock = fHScalers[1][clockindex]; - cout << " -- Beam Charge Asymmetries -- " << endl; + _param_logger->info("{}: -- Beam Charge Asymmetries -- ", here); for(Int_t i=0;i<fNumBCMs;i++) { if(bcmindex.find(fBCM_Name[i]) != bcmindex.end()) { Int_t index=bcmindex[fBCM_Name[i]]; @@ -142,7 +140,7 @@ Int_t THcHelicityScaler::End( THaRunBase* ) } else { fChargeAsymmetry[i] = 0.0; } - printf("%6s %12.2f %12.8f\n",fBCM_Name[i].c_str(),fCharge[i],fChargeAsymmetry[i]); + _param_logger->info("{:10} {:12.2f} uC {:12.2f} ppm", fBCM_Name[i], fCharge[i], fChargeAsymmetry[i]*1e6); } } fTime = (pclock+mclock)/clockfreq; @@ -151,13 +149,13 @@ Int_t THcHelicityScaler::End( THaRunBase* ) } else { fTimeAsymmetry = 0.0; } - printf("TIME(s)%12.2f %12.8f\n",fTime,fTimeAsymmetry); + _param_logger->info("{:10} {:12.2f} uC {:12.8f} ppm", "TIME(s)", fTime, fTimeAsymmetry); if(fNTriggersPlus+fNTriggersMinus > 0) { fTriggerAsymmetry = ((Double_t) (fNTriggersPlus-fNTriggersMinus))/(fNTriggersPlus+fNTriggersMinus); } else { fTriggerAsymmetry = 0.0; } - cout << " ----------------------------- " << endl; + _param_logger->info("{}: -- Beam Charge Asymmetries End --", here); return 0; } @@ -179,8 +177,8 @@ Int_t THcHelicityScaler::ReadDatabase(const TDatime& date ) fBCM_Gain.resize(fNumBCMs); fBCM_Offset.resize(fNumBCMs); DBRequest list2[]={ - {"BCM_Gain", &fBCM_Gain[0], kDouble, (UInt_t) fNumBCMs}, - {"BCM_Offset", &fBCM_Offset[0], kDouble, (UInt_t) fNumBCMs}, + {"BCM_Gain", &fBCM_Gain[0], kDouble, (UInt_t) fNumBCMs}, + {"BCM_Offset", &fBCM_Offset[0], kDouble, (UInt_t) fNumBCMs}, {0} }; gHcParms->LoadParmValues((DBRequest*)&list2, prefix); @@ -234,6 +232,7 @@ Int_t THcHelicityScaler::Analyze(THaEvData *evdata) Int_t THcHelicityScaler::AnalyzeBuffer(UInt_t* rdata) { fNTrigsInBuf = 0; + const static char* const here = "THcHelicityScaler::AnalyzeBuffer"; // Parse the data, load local data arrays. UInt_t *p = (UInt_t*) rdata; @@ -288,7 +287,7 @@ Int_t THcHelicityScaler::AnalyzeBuffer(UInt_t* rdata) Int_t nevents = (banklen-2)/fNScalerChannels; //cout << "# of helicity events in bank:" << " " << nevents << endl; if (nevents > 100) { - cout << "Error! Beam off for too long" << endl; + _param_logger->error("{}: Error! Beam off for too long.", here); } fNTrigsInBuf = 0; @@ -335,6 +334,7 @@ Int_t THcHelicityScaler::AnalyzeBuffer(UInt_t* rdata) Int_t THcHelicityScaler::AnalyzeHelicityScaler(UInt_t *p) { + const static char* const here = "THcHelicityScaler::AnalyzeHelicityScaler"; Int_t hbits = (p[0]>>30) & 0x3; // quartet and helcity bits in scaler word Bool_t isquartet = (hbits&2) != 0; Int_t ispos = hbits&1; @@ -350,19 +350,16 @@ Int_t THcHelicityScaler::AnalyzeHelicityScaler(UInt_t *p) fRingSeed_reported = ((fRingSeed_reported<<1) | ispos) & 0x3FFFFFFF; // Check if ringseed_predicted agrees with reported if(fNBits>=30) if(fNBits >= 30 && predicted != fRingSeed_reported) { - cout << "THcHelicityScaler: Helicity Prediction Failed" << endl; - cout << "Reported " << bitset<32>(fRingSeed_reported) << endl; - cout << "Predicted " << bitset<32>(predicted) << endl; + _param_logger->warn("{}: Helicity Prediction Failed, Reported {:32b}, Predicted {:32b}", + here, fRingSeed_reported, predicted); } fNBits++; if(fNBits==30) { - cout << "THcHelicityScaler: A " << bitset<32>(fRingSeed_reported) << - " found at cycle " << fNTriggers << endl; + _param_logger->info("{}: A {:32b} found at cycle {}", here, fRingSeed_reported, fNTriggers); } } else if (quartetphase == 3) { if(!isquartet) { - cout << "THcHelicityScaler: Quartet bit expected but not set (" << - fNTriggers << ")" << endl; + _param_logger->warn("{}: Quartet bit expected but not set ({})", here, fNTriggers); fNBits = 0; fRingSeed_reported = 0; fRingSeed_actual = 0; @@ -377,8 +374,7 @@ Int_t THcHelicityScaler::AnalyzeHelicityScaler(UInt_t *p) fRingSeed_reported = ((fRingSeed_reported<<1) | ispos) & 0x3FFFFFFF; fNBits++; if(fNBits==30) { - cout << "THcHelicityScaler: B " << bitset<32>(fRingSeed_reported) << - " found at cycle " << fNTriggers << endl; + _param_logger->info("{}: B {:32b} fount at cycle {}", here, fRingSeed_reported, fNTriggers); } } } @@ -448,8 +444,7 @@ THaAnalysisObject::EStatus THcHelicityScaler::Init(const TDatime& date) delete [] *it; fDelayedEvents.clear(); - cout << "Howdy ! We are initializing THcHelicityScaler !! name = " - << fName << endl; + _param_logger->info("Howdy! We are initializing THcHelicityScaler !! name = {}", fName.Data()); if(eventtypes.size()==0) { eventtypes.push_back(0); // Default Event Type diff --git a/src/THcHelicityScaler.h b/src/THcHelicityScaler.h index c01ba1d..f39b2b7 100644 --- a/src/THcHelicityScaler.h +++ b/src/THcHelicityScaler.h @@ -17,10 +17,11 @@ #include "TTree.h" #include "TString.h" #include <cstring> +#include "hcana/Logger.h" class THcHelicity; -class THcHelicityScaler : public THaEvtTypeHandler { +class THcHelicityScaler : public hcana::ConfigLogging<THaEvtTypeHandler> { public: -- GitLab