Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
TrackAnaChain.cxx
1/*
2 * TrackAnaChain.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 "TrackAnaChain.h"
11
12#include "Cout.h"
13#include "CutCollection.h"
14#include "CutContainer.h"
15#include "Event.h"
16#include "EventAna.h"
17#include "EventVirtualCut.h"
18#include "MemoryMapManager.h"
19#include "MultiTrackAna.h"
20#include "Package.h"
21#include "Parameter.h"
22#include "Std.h"
23#include "TrackVirtualCut.h"
24
25#include <TFile.h>
26#include <TString.h>
27
28
29namespace Hal {
30 TrackAnaChain::TrackAnaChain() : fTaskNo(0), fTask(NULL) {}
31
32 void TrackAnaChain::ProcessEvent() {
33 CutCollection* cont = fCutContainer->GetEventCollection(fCurrentEventCollectionID);
34 for (int i = 0; i < fTaskNo; i++) {
35 fTask[i]->fCurrentEventCollectionID = fCurrentEventCollectionID;
36 }
37 for (int i = 0; i < fMemoryMap->GetTemporaryTotalTracksNo(); i++) {
38 for (int j = 0; j < cont->GetNextNo(); j++) {
39 fCurrentTrackCollectionID = cont->GetNextAddr(j);
40 fCurrentTrack = fCurrentEvent->GetTrack(i);
41 if (fCutContainer->PassTrack(fCurrentTrack, fCurrentTrackCollectionID)) {
42 fMemoryMap->AddTrackToMapTrack(fCurrentEventCollectionID,
43 fCurrentTrackCollectionID,
44 i); // load track into memory map - may be usefull at finish event
45 for (int k = 0; k < fTaskNo; k++) {
46 fTask[k]->fCurrentTrackCollectionID = fCurrentTrackCollectionID;
47 fTask[k]->ProcessTrack();
48 }
49 }
50 }
51 }
52 }
53
54 Task::EInitFlag TrackAnaChain::Init() {
55 Task::EInitFlag stat = TrackAna::Init();
56 if (stat == Task::EInitFlag::kSUCCESS) {
57 fTrackCollectionsNo = fCutContainer->GetTrackCollectionsNo();
58 for (int i = 0; i < fTaskNo; i++) {
59 fTask[i]->SetFormat(fCurrentEvent);
60 SynchronizeCutContainers(fTask[i], kTRUE);
61 if (Task::EInitFlag::kFATAL == fTask[i]->Init()) {
62 RemoveTask(i);
63 continue;
64 }
65 LinkTask(fTask[i]);
66 }
67 return Task::EInitFlag::kSUCCESS;
68 }
69 return Task::EInitFlag::kFATAL;
70 }
71
72 void TrackAnaChain::RemoveTask(Int_t no) {
73 TrackAna** temp = fTask;
74 fTask = new TrackAna*[fTaskNo - 1];
75 Int_t n = 0;
76 for (int i = 0; i < fTaskNo; i++) {
77 if (i == no) continue;
78 fTask[n] = temp[i];
79 n++;
80 }
81 delete temp[no];
82 fTaskNo--;
83 delete[] temp;
84 }
85
86 Package* TrackAnaChain::Report() const {
87 Package* pack = EventAna::Report();
88 for (int i = 0; i < fTaskNo; i++) {
89 pack->AddObject(new ParameterString("Subtask name", fTask[i]->ClassName()));
90 }
91 return pack;
92 }
93
94 void TrackAnaChain::Exec(Option_t* /*opt*/) {
95 fProcessedEvents++;
96 fCurrentEvent = fMemoryMap->GetTemporaryEvent();
97 for (fCurrentEventCollectionID = 0; fCurrentEventCollectionID < fEventCollectionsNo; fCurrentEventCollectionID++) {
98 if (fCutContainer->PassEvent(fCurrentEvent, fCurrentEventCollectionID)) { ProcessEvent(); }
99 }
100 }
101
102 void TrackAnaChain::AddAnalysis(TrackAna* ana) {
103 if (!dynamic_cast<TrackAna*>(ana)) return;
104 if (fTask == NULL) {
105 fTask = new TrackAna*[1];
106 ana->MarkAsInChain();
107 fTask[0] = ana;
108 fTaskNo++;
109 } else {
110 for (int i = 0; i < fTaskNo; i++) {
111 if (ana == fTask[i]) {
112 Cout::PrintInfo("Task already added", EInfo::kError);
113 return;
114 }
115 }
116 if (dynamic_cast<MultiTrackAna*>(ana)) {
117 Cout::PrintInfo("Tasks with track buffering cannot be processed vy this task", EInfo::kError);
118 }
119 TrackAna** temp = fTask;
120 fTask = new TrackAna*[fTaskNo + 1];
121 for (int i = 0; i < fTaskNo; i++) {
122 fTask[i] = temp[i];
123 }
124 ana->MarkAsInChain();
125 fTask[fTaskNo] = ana;
126 fTaskNo++;
127 delete[] temp;
128 }
129 }
130
131 void TrackAnaChain::FinishTask() {
132 Package* pack = Report();
133 Package* metadata_new = new Package();
134 metadata_new->SetName("RunInfo");
135 metadata_new->AddObject(new ParameterString("Software ver", HAL_PHYSICALANALYSYS_VER));
136 metadata_new->AddObject(new ParameterString("Date", Hal::Std::GetDate(), 'f'));
137 metadata_new->AddObject(new ParameterString("Time", Hal::Std::GetTime(), 'f'));
138 metadata_new->AddObject(new ParameterUInt("Processed_events", fProcessedEvents, '+'));
139 metadata_new->AddObject(new ParameterString("Input file", GetInputFileName(), 'f'));
140 GoToDir("HalInfo");
141 TDirectory* dir = (TDirectory*) gFile;
142 dir->Cd("HalInfo");
143 TDirectory* metadatata = (TDirectory*) dir->Get("HalInfo");
144 if (metadatata->Get("RunInfo")) {
145 delete metadata_new;
146 } else {
147 metadata_new->Write("RunInfo");
148 }
149 GoToDir("HalPhysics");
150 pack->Write(Form("AnaPackage_%i", GetTaskID()));
151 if (pack) { delete pack; }
152 for (int i = 0; i < fTaskNo; i++) {
153 SynchronizeCutContainers(fTask[i], kFALSE);
154 Package* subtask_pack = fTask[i]->Report();
155 subtask_pack->Write(Form("AnaPackage_%i", fTask[i]->GetTaskID()));
156 fTask[i]->fCurrentTrack = NULL;
157 fTask[i]->fCurrentEvent = NULL;
158 delete subtask_pack;
159 }
160 gFile->cd();
161 Cout::PrintInfo(Form("%s done, writing results", this->ClassName()), EInfo::kInfo);
162 }
163
164 void TrackAnaChain::GoToDir(TString name) {
165 TDirectory* dir = (TDirectory*) gFile;
166 TDirectory* target = (TDirectory*) dir->FindObject(name);
167 if (!target) { dir->mkdir(name); }
168 gFile->cd(name);
169 }
170
171 void TrackAnaChain::LinkTask(TrackAna* ana) const {
172 delete ana->fMemoryMap;
173 ana->fMemoryMap = fMemoryMap;
174 ana->fCurrentEvent = fCurrentEvent;
175 ana->fCurrentTrack = fCurrentTrack;
176 }
177
178 void TrackAnaChain::UnlinkTask(TrackAna* ana) const {
179 ana->fMemoryMap = nullptr;
180 ana->fCurrentEvent = nullptr;
181 ana->fCurrentTrack = nullptr;
182 }
183
184 void TrackAnaChain::SynchronizeCutContainers(TrackAna* ana, Bool_t end) const {
185 ana->AddCut(EventVirtualCut(), Form("{%ix1}", fEventCollectionsNo));
186 ana->fCutContainer->MakeDummyCopies(ECutUpdate::kEvent, fCutContainer, kTRUE);
187 ana->AddCut(TrackVirtualCut(), Form("{%ix1}", fTrackCollectionsNo));
188 ana->fCutContainer->MakeDummyCopies(ECutUpdate::kTrack, fCutContainer, end);
189 }
190
191 TrackAnaChain::~TrackAnaChain() {
192 for (int i = 0; i < fTaskNo; i++) {
193 UnlinkTask(fTask[i]);
194 SynchronizeCutContainers(fTask[i], kFALSE);
195 delete fTask[i];
196 }
197 delete[] fTask;
198 }
199} // namespace Hal
Int_t GetNextNo() const
Int_t GetNextAddr(Int_t index) const
void MakeDummyCopies(ECutUpdate update, CutContainer *other, Bool_t copy_link)
CutContainer * fCutContainer
Definition EventAna.h:78
void MarkAsInChain()
Definition EventAna.h:133
Event * fCurrentEvent
Definition EventAna.h:86
MemoryMapManager * fMemoryMap
Definition EventAna.h:82
virtual void AddCut(const Cut &cut, Option_t *opt="")
Definition EventAna.cxx:322
Package * Report() const
Definition Package.cxx:129
void SetName(TString name)
Definition Package.cxx:298
void AddObject(TObject *object)
Definition Package.cxx:209
Track * fCurrentTrack
Definition TrackAna.h:42