Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
EventAnaChain.cxx
1/*
2 * EventAnaChain.cxx
3 *
4 * Created on: 26 sie 2016
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "EventAnaChain.h"
11
12#include "Cout.h"
13#include "Cut.h"
14#include "CutCollection.h"
15#include "CutContainer.h"
16#include "EventVirtualCut.h"
17#include "MemoryMapManager.h"
18#include "MultiTrackAna.h"
19#include "Package.h"
20#include "Parameter.h"
21#include "Std.h"
22#include "TrackAna.h"
23
24#include <TFile.h>
25#include <TString.h>
26
27
28namespace Hal {
29 EventAnaChain::EventAnaChain() : fTaskNo(0), fTask(NULL) {}
30
32 Package* pack = EventAna::Report();
33 for (int i = 0; i < fTaskNo; i++) {
34 pack->AddObject(new ParameterString(Form("Subtask %i name", i), fTask[i]->ClassName()));
35 }
36 return pack;
37 }
38
40 if (dynamic_cast<MultiTrackAna*>(ana)) {
41 Cout::PrintInfo("Tasks with track buffering cannot be processed vy this task", EInfo::kWarning);
42 return;
43 }
44 if (dynamic_cast<TrackAna*>(ana)) {
45 Cout::PrintInfo(Form("Task %s inherits from TrackAna, any features connected to "
46 "linking collections might not work correltly",
47 ana->ClassName()),
48 EInfo::kError);
49 return;
50 }
51 if (fTask == nullptr) {
52 ana->MarkAsInChain();
53 fTask = new EventAna*[1];
54 fTask[0] = ana;
55 fTaskNo++;
56 } else {
57 for (int i = 0; i < fTaskNo; i++) {
58 if (ana == fTask[i]) {
59 Cout::PrintInfo("Task already added", EInfo::kError);
60 return;
61 }
62 }
63 EventAna** temp = fTask;
64 fTask = new EventAna*[fTaskNo + 1];
65 for (int i = 0; i < fTaskNo; i++) {
66 fTask[i] = temp[i];
67 }
68 ana->MarkAsInChain();
69 fTask[fTaskNo] = ana;
70 fTaskNo++;
71 delete[] temp;
72 }
73 }
74
76 Package* pack = Report();
77 Package* metadata_new = new Package();
78 metadata_new->SetName("RunInfo");
79 metadata_new->AddObject(new ParameterString("Software ver", HAL_PHYSICALANALYSYS_VER));
80 metadata_new->AddObject(new ParameterString("Date", Hal::Std::GetDate(), 'f'));
81 metadata_new->AddObject(new ParameterString("Time", Hal::Std::GetTime(), 'f'));
82 metadata_new->AddObject(new ParameterUInt("Processed_events", fProcessedEvents, '+'));
83 metadata_new->AddObject(new ParameterString("Input file", GetInputFileName(), 'f'));
84 GoToDir("HalInfo");
85 TDirectory* dir = (TDirectory*) gFile;
86 TDirectory* metadatata = (TDirectory*) dir->Get("HalInfo");
87 if (metadatata->Get("RunInfo")) {
88 delete metadata_new;
89 } else {
90 metadata_new->Write("RunInfo");
91 }
92 GoToDir("HalPhysics");
93 pack->Write(Form("AnaPackage_%i", GetTaskID()));
94 if (pack) { delete pack; }
95 for (int i = 0; i < fTaskNo; i++) {
96 SynchronizeCutContainers(fTask[i], kFALSE);
97 Package* subtask_pack = fTask[i]->Report();
98 subtask_pack->Write(Form("AnaPackage_%i", fTask[i]->GetTaskID()));
99 delete subtask_pack;
100 fTask[i]->fMemoryMap = NULL;
101 }
102 gFile->cd();
103 Cout::PrintInfo(Form("%s done, writing results", this->ClassName()), EInfo::kInfo);
104 }
105
107 for (int i = 0; i < fTaskNo; i++) {
109 fTask[i]->ProcessEvent();
110 }
111 }
112
113 Task::EInitFlag EventAnaChain::Init() {
114 Task::EInitFlag stat = EventAna::Init();
115 if (stat == Task::EInitFlag::kSUCCESS) {
116 for (int i = 0; i < fTaskNo; i++) {
117 fTask[i]->SetFormat(fCurrentEvent);
118 fTask[i]->AddCut(EventVirtualCut(), Form("{%ix1}", fEventCollectionsNo));
119 SynchronizeCutContainers(fTask[i], kTRUE);
120 if (Task::EInitFlag::kFATAL == fTask[i]->Init()) {
121 RemoveTask(i);
122 continue;
123 }
124 LinkTask(fTask[i]);
125 }
126 return Task::EInitFlag::kSUCCESS;
127 }
128 return Task::EInitFlag::kFATAL;
129 }
130
140
142 EventAna** temp = fTask;
143 fTask = new EventAna*[fTaskNo - 1];
144 Int_t n = 0;
145 for (int i = 0; i < fTaskNo; i++) {
146 if (i == no) continue;
147 fTask[n] = temp[i];
148 n++;
149 }
150 delete temp[no];
151 fTaskNo--;
152 delete[] temp;
153 }
154
155 void EventAnaChain::GoToDir(TString name) {
156 TDirectory* dir = (TDirectory*) gFile;
157 TDirectory* target = (TDirectory*) dir->FindObject(name);
158 if (!target) { dir->mkdir(name); }
159 gFile->cd(name);
160 }
161
163 delete ana->fMemoryMap;
164 ana->fMemoryMap = fMemoryMap;
166 }
167
168 void EventAnaChain::UnlinkTask(EventAna* ana) const { ana->fMemoryMap = NULL; }
169
171 ana->fCutContainer->MakeDummyCopies(ECutUpdate::kEvent, fCutContainer, end);
172 }
173
174 EventAnaChain::~EventAnaChain() {
175 for (int i = 0; i < fTaskNo; i++) {
176 UnlinkTask(fTask[i]);
177 delete fTask[i];
178 }
179 delete[] fTask;
180 }
181} // namespace Hal
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
Bool_t PassEvent(Event *event, const Int_t collection)
void MakeDummyCopies(ECutUpdate update, CutContainer *other, Bool_t copy_link)
virtual void FinishTask()
virtual Task::EInitFlag Init()
virtual void AddAnalysis(EventAna *ana)
virtual void RemoveTask(Int_t no)
virtual void LinkTask(EventAna *ana) const
virtual void ProcessEvent()
virtual void SynchronizeCutContainers(EventAna *ana, Bool_t end) const
virtual void Exec(Option_t *opt)
virtual Package * Report() const
virtual void UnlinkTask(EventAna *ana) const
CutContainer * fCutContainer
Definition EventAna.h:78
Int_t fEventCollectionsNo
Definition EventAna.h:61
Int_t GetTaskID() const
Definition EventAna.h:155
void MarkAsInChain()
Definition EventAna.h:133
Event * fCurrentEvent
Definition EventAna.h:86
TString GetInputFileName() const
Definition EventAna.h:99
UInt_t fProcessedEvents
Definition EventAna.h:53
MemoryMapManager * fMemoryMap
Definition EventAna.h:82
virtual void AddCut(const Cut &cut, Option_t *opt="")
Definition EventAna.cxx:322
virtual Package * Report() const
Definition EventAna.cxx:259
Int_t fCurrentEventCollectionID
Definition EventAna.h:65
virtual void SetFormat(Event *format, EFormatDepth depth=EFormatDepth::kAll)
Definition EventAna.cxx:210
virtual void ProcessEvent()
Definition EventAna.h:163
virtual Task::EInitFlag Init()
Definition EventAna.cxx:66
void SetName(TString name)
Definition Package.cxx:298
void AddObject(TObject *object)
Definition Package.cxx:209