11#include "MemoryMapManager.h"
15#include "CutContainer.h"
16#include "CutsAndMonitors.h"
17#include "DataFormatManager.h"
18#include "DataManager.h"
20#include "EventVirtualCut.h"
27#include <TCollection.h>
28#include <TDatabasePDG.h>
32#include <TObjString.h>
42 fEventCollectionsNo(0),
43 fCurrentEventCollectionID(0),
48 fCurrentEvent(nullptr),
54 fDataFormatManager(nullptr) {
61#ifdef _HAL_CLEAR_BUFFER_
67#ifdef _HAL_CLEAR_BUFFER_
72 fPDG = TDatabasePDG::Instance();
80 return Task::EInitFlag::kFATAL;
84 if (stat == Task::EInitFlag::kFATAL) {
86 return Task::EInitFlag::kFATAL;
90 if (!this->InheritsFrom(
"Hal::TrackAna") && !this->InheritsFrom(
"Hal::MultiTrackAna")) {
95 return Task::EInitFlag::kSUCCESS;
98#ifdef _HAL_CLEAR_BUFFER_
99 void EventAna::ClearMemory() {
110#ifdef _HAL_CLEAR_BUFFER_
116 TString option = opt;
117 if (option.Contains(
"+")) {
118 std::vector<TString> arr = Hal::Std::ExplodeString(option,
'+');
119 for (
int i = 0; i < (int) arr.size(); i++) {
123 Cout::PrintInfo(Form(
"Invalid SetOption %s for class %s", option.Data(), this->ClassName()), EInfo::kLowWarning);
130 Cout::PrintInfo(
"Null Cut Container, building ...", EInfo::kDebugInfo);
144 if (empty_cont == NULL) {
146 return Task::EInitFlag::kFATAL;
153 if (empty_cont == NULL) {
155 return Task::EInitFlag::kFATAL;
162 if (empty_cont == NULL) {
164 return Task::EInitFlag::kFATAL;
171 if (empty_cont == NULL) {
172 Cout::PrintInfo(
"NULL subcontainer for background pairs", EInfo::kError);
173 return Task::EInitFlag::kFATAL;
187 return Task::EInitFlag::kSUCCESS;
218 fFormatOption(ana.fFormatOption),
219 fProcessedEvents(ana.fProcessedEvents),
220 fMixSize(ana.fMixSize),
221 fEventCollectionsNo(ana.fEventCollectionsNo),
229 fInChain(ana.fInChain),
230 fInFileName(ana.fInFileName),
231 fDataFormatManager(ana.fDataFormatManager) {
232 if (ana.
fInit) { Cout::PrintInfo(
"This object has been initialized, this may result in crash", EInfo::kWarning); }
233 if (ana.
fCutContainer) { fCutContainer = new CutContainer(*ana.fCutContainer); }
236 if (fDataFormatManager->
GetFormat(ana.fTaskID)) { SetFormat(fDataFormatManager->GetFormat(ana.fTaskID)->GetNewEvent()); }
240 if (main_pack == NULL) {
241 Cout::PrintInfo(
"cannot call AddToMetadata if main_pack argument is NULL", EInfo::kLowWarning);
245 if (metadata_pack == NULL) {
246 Cout::PrintInfo(
"cannot add object in AddToMetadata package don't contain any Metadata object", EInfo::kLowWarning);
256 fDataFormatManager =
nullptr;
263 ana_metadata->
SetName(
"Metadata");
280 TList* tagList =
new TList();
281 tagList->SetName(
"Tags");
282 for (
auto str : fTagList) {
283 tagList->AddLast(
new TObjString(str));
294 pack->Write(Form(
"AnaPackage_%i",
GetTaskID()));
295 if (pack) {
delete pack; }
297 Cout::PrintInfo(Form(
"%s done, writing results", this->ClassName()), EInfo::kDebugInfo);
305 if (tag.BeginsWith(
" ")) {
307 }
else if (tag.Contains(
" ")) {
308 Int_t begin = tag.First(
' ');
309 Int_t lenght = tag.Length();
310 TString first_part(tag(0, begin));
312 TString second_part(tag(begin + 1, lenght));
315 for (
auto str : fTagList) {
316 if (str.EqualTo(tag))
return;
318 fTagList.push_back(tag);
342 case EFormatOption::kNoReaderAcces: {
373 DataManager* datamanager = DataManager::Instance();
376 Cout::PrintInfo(
"Format is not set, switching to reader", EInfo::kError);
380 Event*
event =
nullptr;
381 event =
dynamic_cast<Hal::Event*
>(datamanager->GetObject(
"HalEvent."));
384 formatManager->
SetFormat(event->GetNewEvent(),
GetTaskID(), EFormatDepth::kNonBuffered, kTRUE);
386 formatManager->
SetFormat(event->GetNewEvent(),
GetTaskID(), EFormatDepth::kBuffered, kTRUE);
388 return Task::EInitFlag::kSUCCESS;
392 TString branchName = formatManager->
GetFormat(
GetTaskID(), EFormatDepth::kNonBuffered)->ClassName();
393 std::vector<TString> patterns;
394 patterns.push_back(branchName);
395 patterns.push_back(branchName +
".");
396 Bool_t foundFormat = kFALSE;
397 for (
auto name : patterns) {
401 formatManager->
SetFormat(event->GetNewEvent(),
GetTaskID(), EFormatDepth::kNonBuffered, kTRUE);
403 formatManager->
SetFormat(event->GetNewEvent(),
GetTaskID(), EFormatDepth::kBuffered, kTRUE);
409 Cout::PrintInfo(Form(
"Could not find direct access format %s", branchName.Data()), EInfo::kError);
410 return Task::EInitFlag::kFATAL;
415 Cout::PrintInfo(
"The format is present but does not exist in the tree!", EInfo::kError);
416 return Task::EInitFlag::kFATAL;
420 return Task::EInitFlag::kSUCCESS;
429 std::vector<TString> brName;
431 brName.push_back(
"HalEvent.");
432 }
else if (TESTBIT(
fFormatOption, eBitFormat::kDirectAcesss)) {
434 brName.push_back(Form(
"%s.", evName.Data()));
435 brName.push_back(evName);
441 for (
int iCut = 0; iCut < monCuts.
GetNCuts(); iCut++) {
451 Cout::PrintInfo(Form(
"Cannot assign %s to %s, different tiers no", this->ClassName(), other.ClassName()), EInfo::kError);
454 if (
this != &other) {
477 fInChain = other.fInChain;
478 fTagList = other.fTagList;
479 fInFileName = other.fInFileName;
480 fDataFormatManager = other.fDataFormatManager;
481 if (
fInit == kTRUE) {
Cout::PrintInfo(Form(
"Copying initialized task %s", this->ClassName()), EInfo::kWarning); }
static void PrintInfo(TString text, Hal::EInfo status)
CutCollection * GetTwoTrackBackgroundCollection(Int_t collection) const
Bool_t PassEvent(Event *event, const Int_t collection)
Int_t GetTwoTrackCollectionsBackgroundNo() const
CutCollection * GetTwoTrackCollection(Int_t collection) const
virtual Package * Report() const
Int_t GetTwoTrackCollectionsNo() const
void AddMonitor(const CutMonitor &monitor, Option_t *opt=" ")
void AddCut(const Cut &cut, Option_t *opt=" ")
void Init(const Int_t task_id=0)
Int_t GetEventCollectionsNo() const
CutCollection * GetTrackCollection(Int_t collection) const
CutCollection * GetEventCollection(Int_t collection) const
Int_t GetTrackCollectionsNo() const
void SetCollectionID(Int_t i)
Int_t GetNCutMonitors() const
TString GetCutOption(Int_t i) const
const CutMonitor * GetMonitor(Int_t i) const
const Cut * GetCut(Int_t i) const
TString GetCutMonitorOption(Int_t i) const
CutContainer * fCutContainer
virtual Task::EInitFlag CheckFormat()
Int_t fEventCollectionsNo
virtual void LinkCollections()
Task::EInitFlag InitCutContainer()
virtual void AddCutMonitor(const CutMonitor &mon, Option_t *opt="")
virtual void CheckCutContainerCollections()
virtual void SetOption(Option_t *opt)
void SetInputFileName(TString name)
virtual void InitNewCutContainer()
void SetFormatOption(EFormatOption option)
void AddToAnaMetadata(Package *main_pack, TObject *obj) const
virtual void InitMemoryMap()
virtual void SetComment(TString comment)
MemoryMapManager * fMemoryMap
EventAna & operator=(const EventAna &other)
virtual void AddCut(const Cut &cut, Option_t *opt="")
virtual Package * Report() const
virtual void FinishTask()
Int_t fCurrentEventCollectionID
virtual void Exec(Option_t *opt)
virtual void AddCutsAndMonitors(const CutsAndMonitors &monCuts)
virtual void SetFormat(Event *format, EFormatDepth depth=EFormatDepth::kAll)
virtual void ProcessEvent()
virtual Task::EInitFlag Init()
virtual void AddTags(TString tag)
virtual Package * Report() const
virtual Bool_t ExistInTree() const
void Init(Int_t event_factor, Int_t task_id, Bool_t compress, std::vector< TString > direct)
Event * GetTemporaryEvent()
void SetMixSize(Int_t mix_size)
TObject * GetObjectByName(TString name, Int_t index=0, Bool_t quited=kFALSE) const
void SetComment(TString name)
void SetName(TString name)
void AddObject(TObject *object)
void GoToDir(TString name)