10#include "AnalysisManager.h"
12#include "DataManager.h"
22#include "TriggerTask.h"
26#include <RtypesCore.h>
30 AnalysisManager::AnalysisManager() {}
34 if (fSource ==
nullptr) exit(0);
35 Bool_t initSource = fSource->
Init();
36 if (!initSource) {
Cout::PrintInfo(
"Can't init source!", EInfo::kCriticalError); }
42 if (fField ==
nullptr) { fField =
new MagField(); }
49 for (
auto task : fTriggers) {
50 Cout::PrintInfo(Form(
" Init trigger %s", task->ClassName()), EInfo::kDebugInfo);
51 Task::EInitFlag stat = task->Init();
53 case Task::EInitFlag::kERROR: {
54 Cout::PrintInfo(Form(
" Trigger %s go to passive mode", task->ClassName()), EInfo::kDebugInfo);
55 fPassiveTriggers.push_back(task);
57 case Task::EInitFlag::kSUCCESS: {
59 Cout::PrintInfo(Form(
" Trigger %s go to active mode", task->ClassName()), EInfo::kDebugInfo);
60 fActiveTriggers.push_back(task);
62 case Task::EInitFlag::kFATAL: {
63 Cout::PrintInfo(Form(
" Failed to init %s", task->ClassName()), EInfo::kError);
69 for (
auto task : fTasks) {
70 Task::EInitFlag stat = task->Init();
71 Cout::PrintInfo(Form(
" Init task %s", task->ClassName()), EInfo::kDebugInfo);
73 case Task::EInitFlag::kERROR: {
74 Cout::PrintInfo(Form(
" Task %s go to passive mode", task->ClassName()), EInfo::kDebugInfo);
75 fPassiveTasks.push_back(task);
77 case Task::EInitFlag::kSUCCESS: {
78 Cout::PrintInfo(Form(
" Task %s go to active mode", task->ClassName()), EInfo::kDebugInfo);
79 fActiveTasks.push_back(task);
81 case Task::EInitFlag::kFATAL: {
82 Cout::PrintInfo(Form(
" Failed to init %s", task->ClassName()), EInfo::kError);
87 if (fActiveTriggers.size() > 0) { fTriggersEnabled = kTRUE; }
93 if (start == -1 && end == -1) {
97 if (start < 0) start = 0;
100 Cout::PrintInfo(Form(
"Run from %i to %i events", start, end), EInfo::kInfo);
101 Int_t percent = (end - start) / 100;
102 if (percent == 0) percent = 1;
103 for (
int i = start; i < end; i++) {
114 void AnalysisManager::Finish() {
115 auto GoToDir = [](TString name) {
116 TDirectory* dir = (TDirectory*) gFile;
117 std::vector<TString> array = Hal::Std::ExplodeString(name,
'/');
118 for (
int i = 0; i < (int) array.size(); i++) {
119 TDirectory* newdir = (TDirectory*) dir->FindObject(array[i]);
120 if (!newdir) { dir->mkdir(array[i]); }
125 Package* metadata_new =
new Package();
126 metadata_new->SetName(
"RunInfo");
127 metadata_new->AddObject(
new ParameterString(
"Software ver", HAL_PHYSICALANALYSYS_VER));
128 metadata_new->AddObject(
new ParameterString(
"Date", Hal::Std::GetDate(),
'f'));
129 metadata_new->AddObject(
new ParameterString(
"Time", Hal::Std::GetTime(),
'f'));
130 metadata_new->AddObject(
new ParameterUInt(
"Processed_events", fProcessedEvents,
'+'));
131 metadata_new->AddObject(
new ParameterString(
"Input file", DataManager::Instance()->GetSourceName(),
'f'));
134 TList* trigList =
new TList();
135 trigList->SetName(
"EventTriggers");
137 for (
auto probeTask : fActiveTriggers) {
138 trigList->AddLast(probeTask->Report());
140 for (
auto probeTask : fPassiveTriggers) {
141 trigList->AddLast(probeTask->Report());
143 metadata_new->AddObject(trigList);
145 TList* list =
new TList();
146 list->SetName(
"Tasks");
147 for (
auto task : fTasks) {
148 TString name = task->ClassName();
149 TString label =
"Active";
150 for (
auto probeTask : fPassiveTasks) {
151 if (probeTask == task) label =
"Passive";
153 list->AddLast(
new ParameterString(name, label));
155 metadata_new->AddObject(list);
158 TDirectory* dir = (TDirectory*) gFile;
161 TDirectory* metadatata = (TDirectory*) dir->Get(
"HalInfo");
162 if (metadatata->Get(
"RunInfo")) {
165 metadata_new->Write(
"RunInfo");
168 for (
auto task : fActiveTasks) {
175 AnalysisManager::~AnalysisManager() {
178 for (
auto task : fTasks) {
181 for (
auto task : fTriggers) {
184 if (fField)
delete fField;
191 void AnalysisManager::DoStep(Int_t entry) {
192 if (fTriggersEnabled) {
194 for (
auto task : fActiveTriggers) {
196 if (!task->IsEventGood())
return;
200 for (
auto task : fActiveTasks) {
void AddTrigger(TriggerTask *trigger)
void AddReader(Reader *reader)
void Run(Int_t start=-1, Int_t end=-1)
static void PrintInfo(TString text, Hal::EInfo status)
static void ProgressBar(Double_t acutal, Double_t total)
void SetManager(IOManager *mngr)
virtual TList * GetBranchesList() const
virtual void CloseManager()
virtual void LockUnusedBranches()
virtual Int_t GetEntries() const =0
virtual void SetOutput(TString)
virtual Int_t GetEntry(Int_t i, Int_t flag)=0
virtual void SetField(MagField *field)
virtual void FillTree()=0
virtual IOManager * GetIOManager() const