Skip to content
Snippets Groups Projects
Commit 297b52cc authored by Stephen A. Wood's avatar Stephen A. Wood Committed by Stephen Wood
Browse files

Option to delay analysis of end triggered scaler events to end of run.

  In the end method of the Hall C rocs, the scalers are read for a final
  time and a user event 129 is created with the scaler counts.
  These events do not always appear at the end of the coda file, leading to
  the risk that triggered scaler reads will appear after the event 129s.

  If the event type of these final scaler reads is passed to the scaler
  object with the SetDelayedType(int evtype) method, then the scaler analyis
  will cache these events and analyze them at the end of the analysis.
parent f607f36a
No related branches found
No related tags found
No related merge requests found
...@@ -65,7 +65,8 @@ static const UInt_t defaultDT = 4; ...@@ -65,7 +65,8 @@ static const UInt_t defaultDT = 4;
THcScalerEvtHandler::THcScalerEvtHandler(const char *name, const char* description) THcScalerEvtHandler::THcScalerEvtHandler(const char *name, const char* description)
: THaEvtTypeHandler(name,description), evcount(0), ifound(0), fNormIdx(-1), : THaEvtTypeHandler(name,description), evcount(0), ifound(0), fNormIdx(-1),
dvars(0), dvarsFirst(0), fScalerTree(0), fUseFirstEvent(kFALSE) dvars(0), dvarsFirst(0), fScalerTree(0), fUseFirstEvent(kFALSE),
fDelayedType(-1)
{ {
} }
...@@ -78,10 +79,30 @@ THcScalerEvtHandler::~THcScalerEvtHandler() ...@@ -78,10 +79,30 @@ THcScalerEvtHandler::~THcScalerEvtHandler()
Int_t THcScalerEvtHandler::End( THaRunBase* r) Int_t THcScalerEvtHandler::End( THaRunBase* r)
{ {
// Process any delayed events in order received
cout << "THcScalerEvtHandler::End Analyzing " << fDelayedEvents.size() << " delayed scaler events" << endl;
for(UInt_t* rdata : fDelayedEvents) {
AnalyzeBuffer(rdata);
}
fDelayedEvents.clear(); // Does this free the arrays?
if (fScalerTree) fScalerTree->Write(); if (fScalerTree) fScalerTree->Write();
return 0; return 0;
} }
void THcScalerEvtHandler::SetDelayedType(int evtype) {
/**
* \brief Delay analysis of this event type to end.
*
* Final scaler events generated in readout list end routines may not
* come in order in the data stream. If the event type of a end routine
* scaler event is set, then the event contents will be saved and analyzed
* at the end of the analysis so that time ordering of scaler events is preserved.
*/
fDelayedType = evtype;
}
Int_t THcScalerEvtHandler::Analyze(THaEvData *evdata) Int_t THcScalerEvtHandler::Analyze(THaEvData *evdata)
{ {
Int_t lfirst=1; Int_t lfirst=1;
...@@ -124,13 +145,26 @@ Int_t THcScalerEvtHandler::Analyze(THaEvData *evdata) ...@@ -124,13 +145,26 @@ Int_t THcScalerEvtHandler::Analyze(THaEvData *evdata)
} // if (lfirst && !fScalerTree) } // if (lfirst && !fScalerTree)
// Parse the data, load local data arrays.
UInt_t *rdata = (UInt_t*) evdata->GetRawDataBuffer(); UInt_t *rdata = (UInt_t*) evdata->GetRawDataBuffer();
if (fDebugFile) *fDebugFile<<"\n\nTHcScalerEvtHandler :: Debugging event type "<<dec<<evdata->GetEvType()<<endl<<endl; if( evdata->GetEvType() == fDelayedType) { // Save this event for processing later
Int_t evlen = evdata->GetEvLength();
UInt_t *datacopy = new UInt_t[evlen];
fDelayedEvents.push_back(datacopy);
for(Int_t i=0;i<evlen;i++) {
datacopy[i] = rdata[i];
}
return 1;
} else { // A normal event
if (fDebugFile) *fDebugFile<<"\n\nTHcScalerEvtHandler :: Debugging event type "<<dec<<evdata->GetEvType()<<endl<<endl;
return AnalyzeBuffer(rdata);
}
}
Int_t THcScalerEvtHandler::AnalyzeBuffer(UInt_t* rdata)
{
// Parse the data, load local data arrays.
UInt_t *p = (UInt_t*) rdata; UInt_t *p = (UInt_t*) rdata;
UInt_t *plast = p+*p; // Index to last word in the bank UInt_t *plast = p+*p; // Index to last word in the bank
...@@ -271,6 +305,8 @@ THaAnalysisObject::EStatus THcScalerEvtHandler::Init(const TDatime& date) ...@@ -271,6 +305,8 @@ THaAnalysisObject::EStatus THcScalerEvtHandler::Init(const TDatime& date)
fStatus = kOK; fStatus = kOK;
fNormIdx = -1; fNormIdx = -1;
fDelayedEvents.clear();
cout << "Howdy ! We are initializing THcScalerEvtHandler !! name = " cout << "Howdy ! We are initializing THcScalerEvtHandler !! name = "
<< fName << endl; << fName << endl;
......
...@@ -34,9 +34,11 @@ public: ...@@ -34,9 +34,11 @@ public:
virtual ~THcScalerEvtHandler(); virtual ~THcScalerEvtHandler();
Int_t Analyze(THaEvData *evdata); Int_t Analyze(THaEvData *evdata);
Int_t AnalyzeBuffer(UInt_t *rdata);
virtual EStatus Init( const TDatime& run_time); virtual EStatus Init( const TDatime& run_time);
virtual Int_t End( THaRunBase* r=0 ); virtual Int_t End( THaRunBase* r=0 );
virtual void SetUseFirstEvent(Bool_t b = kFALSE) {fUseFirstEvent = b;} virtual void SetUseFirstEvent(Bool_t b = kFALSE) {fUseFirstEvent = b;}
virtual void SetDelayedType(int evtype);
private: private:
...@@ -47,12 +49,13 @@ private: ...@@ -47,12 +49,13 @@ private:
std::vector<Decoder::GenScaler*> scalers; std::vector<Decoder::GenScaler*> scalers;
std::vector<HCScalerLoc*> scalerloc; std::vector<HCScalerLoc*> scalerloc;
Double_t evcount; Double_t evcount;
std::vector<Int_t> index;
Int_t Nvars, ifound, fNormIdx, nscalers; Int_t Nvars, ifound, fNormIdx, nscalers;
Double_t *dvars; Double_t *dvars;
Double_t *dvarsFirst; Double_t *dvarsFirst;
TTree *fScalerTree; TTree *fScalerTree;
Bool_t fUseFirstEvent; Bool_t fUseFirstEvent;
Int_t fDelayedType;
std::vector<UInt_t*> fDelayedEvents;
THcScalerEvtHandler(const THcScalerEvtHandler& fh); THcScalerEvtHandler(const THcScalerEvtHandler& fh);
THcScalerEvtHandler& operator=(const THcScalerEvtHandler& fh); THcScalerEvtHandler& operator=(const THcScalerEvtHandler& fh);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment