From cd8e6910bfd144c4f090545f32b1793fea5d70aa Mon Sep 17 00:00:00 2001 From: "Stephen A. Wood" <saw@jlab.org> Date: Tue, 24 Oct 2017 15:40:54 -0400 Subject: [PATCH] Change behaviour for multiple ROCs with scalers. 1. If there are multiple ROCs with scalers (hardware, TI, FADC), then there will be multiple event 129s. In the case where analysis of these events is defered to the end of the analysis, all the event 129s will be analyzed as if a single event, resulting in one entry in the tree. 2. Scalers are read either when a given time interval has passed since the last scaler read (usually 2 seconds), or every time an event is tagged as a sync event. In the case of the "timed" reading of events, different ROCs with scalers are not guaranteed to read their scalers at the same event. But or sync event scaler reads, all ROCs read their scalers. This commit adds an option SetOnlyUseSyncEvents(Bool_t). If set, only scaler events triggered by the sync event will be analyzed. --- src/THcScalerEvtHandler.cxx | 33 ++++++++++++++++++++++----------- src/THcScalerEvtHandler.h | 6 ++++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/THcScalerEvtHandler.cxx b/src/THcScalerEvtHandler.cxx index ebafb21..dbdaf6c 100644 --- a/src/THcScalerEvtHandler.cxx +++ b/src/THcScalerEvtHandler.cxx @@ -75,7 +75,7 @@ static const UInt_t defaultDT = 4; THcScalerEvtHandler::THcScalerEvtHandler(const char *name, const char* description) : THaEvtTypeHandler(name,description), evcount(0), evcountR(0.0), ifound(0), fNormIdx(-1), dvars(0),dvars_prev_read(0), dvarsFirst(0), fScalerTree(0), fUseFirstEvent(kTRUE), - fDelayedType(-1), fOnlyBanks(kFALSE) + fOnlySyncEvents(kFALSE), fOnlyBanks(kFALSE), fDelayedType(-1) { fRocSet.clear(); fModuleSet.clear(); @@ -96,8 +96,12 @@ Int_t THcScalerEvtHandler::End( THaRunBase* r) for(std::vector<UInt_t*>::iterator it = fDelayedEvents.begin(); it != fDelayedEvents.end(); ++it) { UInt_t* rdata = *it; - AnalyzeBuffer(rdata); + AnalyzeBuffer(rdata,kFALSE); } + if (fDebugFile) *fDebugFile << "scaler tree ptr "<<fScalerTree<<endl; + + if (fScalerTree) fScalerTree->Fill(); + fDelayedEvents.clear(); // Does this free the arrays? if (fScalerTree) fScalerTree->Write(); @@ -220,11 +224,17 @@ Int_t THcScalerEvtHandler::Analyze(THaEvData *evdata) return 1; } else { // A normal event if (fDebugFile) *fDebugFile<<"\n\nTHcScalerEvtHandler :: Debugging event type "<<dec<<evdata->GetEvType()<<endl<<endl; - return AnalyzeBuffer(rdata); + Int_t ret; + if((ret=AnalyzeBuffer(rdata,fOnlySyncEvents))) { + if (fDebugFile) *fDebugFile << "scaler tree ptr "<<fScalerTree<<endl; + if (fScalerTree) fScalerTree->Fill(); + } + return ret; + } } -Int_t THcScalerEvtHandler::AnalyzeBuffer(UInt_t* rdata) +Int_t THcScalerEvtHandler::AnalyzeBuffer(UInt_t* rdata, Bool_t onlysync) { // Parse the data, load local data arrays. @@ -249,15 +259,20 @@ Int_t THcScalerEvtHandler::AnalyzeBuffer(UInt_t* rdata) // At any point in the bank where the word is not a matching // header, we stop. UInt_t tag = (*p>>16) & 0xffff; + UInt_t num = (*p) & 0xff; UInt_t *pnext = p+*(p-1); // Next bank p++; // First data word // Skip over banks that can't contain scalers // If SetOnlyBanks(kTRUE) called, fRocSet will be empty // so only bank tags matching module types will be considered. - if(fRocSet.find(tag)==fRocSet.end() - && fModuleSet.find(tag)==fModuleSet.end()) { - p = pnext; // Fall through to end of this else if + if(fModuleSet.find(tag)!=fModuleSet.end()) { + if(onlysync && num==0) { + ifound = 0; + return 0; + } + } else if (fRocSet.find(tag)==fRocSet.end()) { + p = pnext; // Fall through to end of the above else if } // Look for normalization scaler module first. @@ -496,10 +511,6 @@ Int_t THcScalerEvtHandler::AnalyzeBuffer(UInt_t* rdata) // for (size_t j=0; j<scalers.size(); j++) scalers[j]->Clear(""); - if (fDebugFile) *fDebugFile << "scaler tree ptr "<<fScalerTree<<endl; - - if (fScalerTree) fScalerTree->Fill(); - return 1; } diff --git a/src/THcScalerEvtHandler.h b/src/THcScalerEvtHandler.h index 5e151bd..0a406ae 100644 --- a/src/THcScalerEvtHandler.h +++ b/src/THcScalerEvtHandler.h @@ -35,13 +35,14 @@ public: virtual ~THcScalerEvtHandler(); Int_t Analyze(THaEvData *evdata); - Int_t AnalyzeBuffer(UInt_t *rdata); + Int_t AnalyzeBuffer(UInt_t *rdata, Bool_t onlysync); virtual EStatus Init( const TDatime& run_time); virtual Int_t ReadDatabase(const TDatime& date ); virtual Int_t End( THaRunBase* r=0 ); virtual void SetUseFirstEvent(Bool_t b = kFALSE) {fUseFirstEvent = b;} virtual void SetDelayedType(int evtype); virtual void SetOnlyBanks(Bool_t b = kFALSE) {fOnlyBanks = b;fRocSet.clear();} + virtual void SetOnlyUseSyncEvents(Bool_t b=kFALSE) {fOnlySyncEvents = b;} private: @@ -73,8 +74,9 @@ private: Double_t *dvarsFirst; TTree *fScalerTree; Bool_t fUseFirstEvent; - Int_t fDelayedType; + Bool_t fOnlySyncEvents; Bool_t fOnlyBanks; + Int_t fDelayedType; std::vector<UInt_t*> fDelayedEvents; std::set<UInt_t> fRocSet; std::set<UInt_t> fModuleSet; -- GitLab