75 while(
TObject* obj = next_item() ) {
79 auto* item =
dynamic_cast<T*
>(obj);
82 auto it = std::find(ALL(
vec), item);
95 , fEpicsHandler(nullptr)
96 , fOdefFileName(kDefaultOdefFile)
100 , fMarkInterval(1000)
103 , fCountMode(kCountRaw)
105 , fPrevEvent(nullptr)
109 , fAnalysisStarted(false)
116 , fDoOtherEvents(true)
117 , fDoSlowControl(true)
118 , fFirstPhysics(true)
126 Error(
"THaAnalyzer",
"only one instance of THaAnalyzer allowed.");
163 const char*
const here =
"AddInterStage";
171 Error( Here(
here),
"Cannot add analysis modules while analysis "
172 "is in progress. Close() this analysis first." );
181 Error(Here(
here),
"fIsInit, but bad fRun?!?");
185 Int_t retval =
module->Init(run_time);
208 Error(
"AddPostProcess",
"Cannot add analysis modules while analysis "
209 "is in progress. Close() this analysis first." );
218 Error(
"AddPostProcess",
"fIsInit, but bad fRun?!?");
222 Int_t retval =
module->Init(run_time);
236 theCounter.count = 0;
353 Warning(
"GetDecoder",
"Decoder not yet set up. You need to "
354 "initialize the analyzer with Init(run) first." );
415 for(
auto& theStage :
fStages ) {
419 if( theStage.cut_list ) {
420 TString master_cut( theStage.name );
425 theStage.master_cut =
nullptr;
437 static const char*
const here =
"InitModules()";
441 auto* theModule = *it;
443 cout <<
"Initializing " << theModule->
GetName() << endl;
445 retval = theModule->Init( run_time );
447 catch(
const exception&
e ) {
448 Error(
here,
"Exception %s caught during initialization of module "
449 "%s (%s). Analyzer initialization failed.",
450 e.what(), theModule->GetName(), theModule->GetTitle() );
454 if( retval !=
kOK || !theModule->IsOK() ) {
455 Error(
here,
"Error %d initializing module %s (%s). "
456 "Analyzer initialization failed.",
457 retval, theModule->GetName(), theModule->GetTitle() );
474 if( !run )
return -1;
494 static const char*
const here =
"Init";
505 Error(
here,
"Failed to set CODA version %d for run. Call expert.",
510 bool run_init =
false;
512 cout <<
"Initializing run object" << endl;
514 retval = run->
Init();
528 Error(
here,
"Cannot change output file name after analysis has been "
529 "started. Close() first, then Init() or Process() again." );
537 Error(
here,
"Must specify an output file. Set it with SetOutFile()." );
543 Error(
here,
"Output file %s already exists. Choose a different "
544 "file name or enable overwriting with EnableOverwrite().",
548 cout <<
"Overwriting existing";
550 cout <<
"Creating new";
555 Error(
here,
"failed to create output file %s. Check file/directory "
565 auto openmode =
fOverwrite ? ios::out : ios::app;
568 Error(
here,
"Failed to open summary file %s. Check file/directory "
585 bool new_event =
false;
590 Error(
here,
"Cannot change event structure for continuing analysis. "
591 "Close() this analysis, then Init() again." );
619 bool new_output =
false;
627 bool new_decoder =
false;
633 Error(
here,
"Failed to create decoder object. "
634 "Something is very wrong..." );
647 bool new_run = ( !
fRun || *
fRun != *run );
648 bool need_init = ( !
fIsInit || new_event || new_output || new_run ||
649 new_decoder || run_init );
660 Warning(
here,
"You are analyzing the same run twice with "
661 "overlapping event ranges! prev: %d-%d, now: %d-%d",
664 if( !
gROOT->IsBatch() ) {
665 cout <<
"Are you sure (y/n)?" << endl;
667 while(
c !=
'y' &&
c !=
'n' &&
c != EOF ) {
670 if(
c !=
'y' &&
c !=
'Y' )
683 Error(
here,
"Failed to create copy of run object. "
684 "Something is very wrong...");
704 Error(
here,
"Failed to open summary file %s (after previous success). "
710 ofs <<
"Reading from ";
712 auto* cout_buf = cout.rdbuf();
713 cout.rdbuf(ofs.rdbuf());
715 cout.rdbuf(cout_buf);
749 cout <<
"Initializing analysis objects" << endl;
750 vector<THaAnalysisObject*> modulesToInit;
753 modulesToInit.insert(modulesToInit.end(), ALL(
fApps));
754 modulesToInit.insert(modulesToInit.end(), ALL(
fPhysics));
755 modulesToInit.insert(modulesToInit.end(), ALL(
fEvtHandlers));
756 modulesToInit.insert(modulesToInit.end(), ALL(
fInterStage));
787 cout <<
"Initializing output" << endl;
789 Error(
here,
"Error initializing THaOutput." );
790 }
else if( retval == 1 )
804 cout <<
"Initializing post processors" << endl;
806 retval = obj->Init(run_time);
814 Error(
here,
"Error initializing THaOutput for objects(again!)" );
836 static const char*
const here =
"InitOutput()";
840 theModule->InitOutput(
fOutput );
841 if( !theModule->IsOKOut() ) {
842 Error(
here,
"Error initializing output for %s (%s). "
843 "Analyzer initialization failed.",
844 theModule->GetName(), theModule->GetTitle() );
885 Error(
"THaAnalyzer::ReadEvent",
886 "Unsupported decoder return code %d. Call expert.", status);
963 for(
Int_t i = 0; i < ncounters; i++ ) {
970 for(
Int_t i = 0; i < ncounters; i++ ) {
974 cout <<
"Counter summary:" << endl;
991 cout <<
"Analysis ended.";
994 cout <<
"End of file.";
997 cout <<
"Event limit reached.";
1000 cout <<
"Fatal processing error.";
1003 cout <<
"Terminated during processing.";
1025 cout <<
"Cut summary:" << endl;
1035 vector<TString> names;
1037 cout <<
"Timing summary:" << endl;
1039 "Init",
"Begin",
"RawDecode",
"Decode",
"CoarseTracking",
1040 "CoarseReconstruct",
"Tracking",
"Reconstruct",
"Physics",
"End",
1044 names.emplace_back(
"Total");
1073 auto* cout_buf = cout.rdbuf();
1074 cout.rdbuf(ostr.rdbuf());
1084 cout.rdbuf(cout_buf);
1104 theModule->Begin(
fRun );
1125 theModule->End(
fRun );
1142 static const char*
const here =
"PhysicsAnalysis";
1149 if( fNev < fRun->GetFirstEvent() )
1165 const char* stage =
"";
1175 for(
auto* app :
fApps ) {
1180 if( mod->GetStage() ==
kDecode ) {
1198 stage =
"CoarseTracking";
1202 spectro->CoarseTrack();
1214 stage =
"CoarseReconstruct";
1216 for(
auto* app :
fApps ) {
1218 app->CoarseReconstruct();
1247 stage =
"Reconstruct";
1249 for(
auto* app :
fApps ) {
1277 if( mod->GetStage() ==
kPhysics ) {
1289 return (code ==
kOK) ?
kSkip : code;
1292 catch(
const exception&
e ) {
1293 TString module_name = (obj !=
nullptr) ? obj->
GetName() :
"unknown";
1295 Error(
here,
"Caught exception %s in module %s (%s) during %s analysis "
1296 "stage. Terminating analysis.",
e.what(), module_name.
Data(),
1297 module_desc.
Data(), stage );
1321 catch(
const exception&
e ) {
1322 Error(
here,
"Caught exception %s during output of event %u. "
1323 "Terminating analysis.",
e.what(),
fNev );
1389 static const char*
const here =
"MainAnalysis";
1396 bool rawfail =
false;
1407 catch(
const exception&
e) {
1413 bool evdone =
false;
1461 static const char*
const here =
"Process";
1482 Error(
here,
"Failed to re-open the input file. "
1483 "Make sure the file still exists.");
1500 cout <<
"Decoder: helicity "
1503 cout << endl <<
"Starting analysis" << endl;
1513 bool terminate =
false, fatal =
false;
1526 while ( !terminate &&
fNev < nlast &&
1531 terminate = fatal =
true;
1560 cout << dec <<
fNev << endl;
1579 fatal = terminate =
true;
1585 Error(
here,
"Unknown return code from MainAnalysis(): %d", err );
1586 terminate = fatal =
true;
1628 else if(
fNev == nlast )
1632 else if( terminate )
1645 if (vers != 2 && vers != 3) {
1646 Warning(
"THaAnalyzer::SetCodaVersion",
"Illegal CODA version = %d. "
1647 "Must be 2 or 3. Setting version to 2.", vers );
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char text
size_t ListToVector(TList *lst, vector< T * > &vec)
UInt_t IntDigits(Int_t n)
static const vector< ModuleDef > module_list
R__EXTERN class TList * gHaEvtHandlers
R__EXTERN class TList * gHaApps
R__EXTERN class THaRunBase * gHaRun
R__EXTERN class TList * gHaPhysics
R__EXTERN class TClass * gHaDecoder
R__EXTERN class THaCutList * gHaCuts
static const char *const here
R__EXTERN TSystem * gSystem
virtual void Stop(const char *name)
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
virtual Int_t GetSize() const
UInt_t Convert(Bool_t toGMT=kFALSE) const
const char * AsString() const
void Purge(Short_t nkeep=1) override
virtual void SetCompressionLevel(Int_t level=ROOT::RCompressionSetting::ELevel::kUseMin)
virtual void Clear(Option_t *="")
virtual void PrintRunSummary() const
virtual bool EvalStage(int n)
UInt_t GetCount(Int_t which) const
virtual void Print(Option_t *opt="") const
static const char *const kDefaultOdefFile
std::vector< THaApparatus * > fApps
virtual void PrintCounters() const
virtual Int_t PhysicsAnalysis(Int_t code)
virtual Int_t SetCountMode(Int_t mode)
void SetEpicsEvtType(Int_t itype)
std::vector< THaAnalysisObject * > fAnalysisModules
static THaAnalyzer * fgAnalyzer
virtual Int_t MainAnalysis()
virtual Int_t Process(THaRunBase *run=nullptr)
void EnableRunUpdate(Bool_t b=true)
std::vector< THaPhysicsModule * > fPhysics
virtual Int_t BeginAnalysis()
virtual Int_t ReadOneEvent()
std::vector< THaEvtTypeHandler * > fEvtHandlers
std::vector< Stage_t > fStages
virtual Int_t InitModules(const std::vector< THaAnalysisObject * > &module_list, TDatime &run_time)
void EnablePhysicsEvents(Bool_t b=true)
virtual void InitCounters()
virtual void PrepareModuleList()
void EnableOverwrite(Bool_t b=true)
std::vector< THaPostProcess * > fPostProcess
void SetCrateMapFileName(const char *name)
THaEvData * GetDecoder() const
virtual void PrintExitStatus(EExitStatus status) const
virtual Int_t Init(THaRunBase *run)
virtual void PrintSummary(EExitStatus exit_status) const
void SetCodaVersion(Int_t vers)
void EnableBenchmarks(Bool_t b=true)
virtual void PrintCutSummary() const
void EnableOtherEvents(Bool_t b=true)
virtual Int_t DoInit(THaRunBase *run)
std::vector< Podd::InterStageModule * > fInterStage
static const char *const kMasterCutName
virtual Int_t SlowControlAnalysis(Int_t code)
THaEpicsEvtHandler * fEpicsHandler
virtual void PrintTimingSummary() const
std::vector< THaSpectrometer * > fSpectrometers
virtual Int_t PostProcess(Int_t code)
virtual Int_t InitOutput(const std::vector< THaAnalysisObject * > &module_list)
void EnableHelicity(Bool_t b=true)
std::vector< Counter_t > fCounters
virtual Int_t AddInterStage(Podd::InterStageModule *module)
virtual Int_t AddPostProcess(THaPostProcess *module)
virtual void InitStages()
virtual Int_t EndAnalysis()
TString fLoadedCutFileName
void EnableSlowControl(Bool_t b=true)
virtual Int_t OtherAnalysis(Int_t code)
Bool_t HelicityEnabled() const
void AddEpicsEvtType(Int_t itype)
virtual void Begin(const char *name)
void PrintByName(const std::vector< TString > &names) const
virtual void Clear(Option_t *opt="")
virtual Int_t Load(const char *filename=kDefaultCutFile)
virtual Int_t EvalBlock(const char *block=kDefaultBlockName)
virtual void Print(Option_t *option="") const
THaNamedList * FindBlock(const char *block) const
THaCut * FindCut(const char *name) const
virtual void ClearAll(Option_t *opt="")
virtual Bool_t DataCached()
void SetDebug(Int_t level)
virtual ULong64_t GetEvTime() const
void SetVerbose(Int_t level)
virtual Int_t LoadEvent(const UInt_t *evbuffer)=0
Bool_t IsPhysicsTrigger() const
virtual void SetRunTime(ULong64_t tloc)
void SetRunInfo(UInt_t num, UInt_t type, ULong64_t tloc)
static void SetDefaultCrateMapName(const char *name)
virtual Int_t SetDataVersion(Int_t version)
Bool_t HelicityEnabled() const
void EnableHelicity(Bool_t enable=true)
void SetEpicsEvtType(UInt_t itype)
virtual Int_t GetHelicity() const
UInt_t GetTrigBits() const
UInt_t GetEvLength() const
THaEventHeader * GetHeader()
virtual void Reset(Option_t *opt="")
virtual void AddEvtType(UInt_t evtype)
virtual Bool_t IsMyEvent(UInt_t type) const
virtual UInt_t GetNumTypes()
virtual void SetEvtType(UInt_t evtype)
virtual UInt_t GetEvtType()
virtual Int_t Init(const char *filename="output.def")
virtual Int_t ProcEpics(THaEvData *ev, THaEpicsEvtHandler *han)
virtual TTree * GetTree() const
virtual Int_t Update(const THaEvData *evdata)
UInt_t GetFirstEvent() const
virtual Int_t ReadEvent()=0
const TDatime & GetDate() const
virtual void Print(Option_t *opt="") const
UInt_t GetLastEvent() const
virtual Int_t GetDataVersion()
virtual const UInt_t * GetEvBuffer() const =0
virtual Int_t SetDataVersion(Int_t version)
virtual Int_t Compare(const TObject *obj) const
void IncrNumAnalyzed(Int_t n=1)
const char * GetName() const override
const char * GetTitle() const override
TClass * IsA() const override
virtual void Warning(const char *method, const char *msgfmt,...) const
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
virtual void Error(const char *method, const char *msgfmt,...) const
virtual TClass * IsA() const
static Bool_t Initialized()
const char * Data() const
TString & Append(char c, Ssiz_t rep=1)
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
TFile * GetCurrentFile() const
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)