Lines getting the matched track moved to a method in AliCalorimeterUtils. Lines copie...
[u/mrichter/AliRoot.git] / PWG2 / FEMTOSCOPY / AliFemto / AliFemtoManager.cxx
CommitLineData
d0e92d9a 1///////////////////////////////////////////////////////////////////////////
2// //
3// AliFemtoManager: main class managing femtoscopic analysis //
4// The Manager is the top-level object that coordinates activities //
5// and performs event, particle, and pair loops, and checks the //
6// various Cuts of the Analyses in its AnalysisCollection //
7// //
8///////////////////////////////////////////////////////////////////////////
9
10#include "AliFemtoManager.h"
11//#include "AliFemtoParticleCollection.h"
12//#include "AliFemtoTrackCut.h"
13//#include "AliFemtoV0Cut.h"
14#include <cstdio>
15
16#ifdef __ROOT__
17ClassImp(AliFemtoManager)
18#endif
19
20
21
22//____________________________
23AliFemtoManager::AliFemtoManager():
24 fAnalysisCollection(0),
25 fEventReader(0),
26 fEventWriterCollection(0)
27{
28 // default constructor
29 fAnalysisCollection = new AliFemtoAnalysisCollection;
30 fEventWriterCollection = new AliFemtoEventWriterCollection;
31 fEventReader = 0;
32}
33//____________________________
34AliFemtoManager::AliFemtoManager(const AliFemtoManager& aManager) :
35 fAnalysisCollection(0),
36 fEventReader(0),
37 fEventWriterCollection(0)
38{
39 // copy constructor
40 fEventReader = aManager.fEventReader;
a5b23aa6 41 AliFemtoSimpleAnalysisIterator tAnalysisIter;
d0e92d9a 42 fAnalysisCollection = new AliFemtoAnalysisCollection;
43 for (tAnalysisIter=aManager.fAnalysisCollection->begin();tAnalysisIter!=aManager.fAnalysisCollection->end();tAnalysisIter++){
44 fAnalysisCollection->push_back(*tAnalysisIter);
45 }
46 AliFemtoEventWriterIterator tEventWriterIter;
47 fEventWriterCollection = new AliFemtoEventWriterCollection;
48 for (tEventWriterIter=aManager.fEventWriterCollection->begin();tEventWriterIter!=aManager.fEventWriterCollection->end();tEventWriterIter++){
49 fEventWriterCollection->push_back(*tEventWriterIter);
50 }
51}
52
53//____________________________
54AliFemtoManager::~AliFemtoManager(){
55 // destructor
56 delete fEventReader;
57 // now delete each Analysis in the Collection, and then the Collection itself
a5b23aa6 58 AliFemtoSimpleAnalysisIterator tAnalysisIter;
d0e92d9a 59 for (tAnalysisIter=fAnalysisCollection->begin();tAnalysisIter!=fAnalysisCollection->end();tAnalysisIter++){
60 delete *tAnalysisIter;
61 *tAnalysisIter = 0;
62 }
63 delete fAnalysisCollection;
64 // now delete each EventWriter in the Collection, and then the Collection itself
65 AliFemtoEventWriterIterator tEventWriterIter;
66 for (tEventWriterIter=fEventWriterCollection->begin();tEventWriterIter!=fEventWriterCollection->end();tEventWriterIter++){
67 delete *tEventWriterIter;
68 *tEventWriterIter = 0;
69 }
70 delete fEventWriterCollection;
71}
72//____________________________
73AliFemtoManager& AliFemtoManager::operator=(const AliFemtoManager& aManager)
74{
75 // assignment operator
76 if (this == &aManager)
77 return *this;
78
79 fEventReader = aManager.fEventReader;
a5b23aa6 80 AliFemtoSimpleAnalysisIterator tAnalysisIter;
d0e92d9a 81 if (fAnalysisCollection) {
82 for (tAnalysisIter=fAnalysisCollection->begin();tAnalysisIter!=fAnalysisCollection->end();tAnalysisIter++){
83 delete *tAnalysisIter;
84 *tAnalysisIter = 0;
85 }
86 delete fAnalysisCollection;
87 }
88 // now delete each EventWriter in the Collection, and then the Collection itself
89 AliFemtoEventWriterIterator tEventWriterIter;
90 if (fEventWriterCollection) {
91 for (tEventWriterIter=fEventWriterCollection->begin();tEventWriterIter!=fEventWriterCollection->end();tEventWriterIter++){
92 delete *tEventWriterIter;
93 *tEventWriterIter = 0;
94 }
95 delete fEventWriterCollection;
96 }
97
98 fAnalysisCollection = new AliFemtoAnalysisCollection;
99 for (tAnalysisIter=aManager.fAnalysisCollection->begin();tAnalysisIter!=aManager.fAnalysisCollection->end();tAnalysisIter++){
100 fAnalysisCollection->push_back(*tAnalysisIter);
101 }
102
103 fEventWriterCollection = new AliFemtoEventWriterCollection;
104 for (tEventWriterIter=aManager.fEventWriterCollection->begin();tEventWriterIter!=aManager.fEventWriterCollection->end();tEventWriterIter++){
105 fEventWriterCollection->push_back(*tEventWriterIter);
106 }
107 return *this;
108}
109
110//____________________________
111int AliFemtoManager::Init(){
112 // Execute initialization procedures
113 AliFemtoString readerMessage;
114 readerMessage += "*** *** *** *** *** *** *** *** *** *** *** *** \n";
115 // EventReader
116 if (fEventReader) {
117 if (fEventReader->Init("r",readerMessage)){
118 cout << " AliFemtoManager::Init() - Reader initialization failed " << endl;
119 return (1);
120 }
121 readerMessage += fEventReader->Report();
122 }
123 // EventWriters
124 AliFemtoEventWriterIterator tEventWriterIter;
125 for (tEventWriterIter=fEventWriterCollection->begin();tEventWriterIter!=fEventWriterCollection->end();tEventWriterIter++){
126 //cout << "*EventWriterIter " << *EventWriterIter << endl;
127 // The message (AliFemtoString) passed into Init will be at the file header.
128 // for that reason take the readerReport, add my own report and pass as message
129 AliFemtoString writerMessage = readerMessage;
130 writerMessage += "*** *** *** *** *** *** *** *** *** *** *** *** \n";
131 writerMessage += (*tEventWriterIter)->Report();
132 if (*tEventWriterIter) {
133 if ( (*tEventWriterIter)->Init("w",writerMessage)){ // yes, the message from the reader is passed into the writer
134 cout << " AliFemtoManager::Init() - Writer initialization failed " << endl;
135 return (1);
136 }
137 }
138 }
139
140
141 return (0);
142}
143//____________________________
144void AliFemtoManager::Finish(){
145 // Initialize finish procedures
146 // EventReader
147 if (fEventReader) fEventReader->Finish();
148 // EventWriters
149 AliFemtoEventWriterIterator tEventWriterIter;
150 AliFemtoEventWriter* currentEventWriter;
151 for (tEventWriterIter=fEventWriterCollection->begin();tEventWriterIter!=fEventWriterCollection->end();tEventWriterIter++){
152 currentEventWriter = *tEventWriterIter;
153 currentEventWriter->Finish();
154 }
155 // Analyses
a5b23aa6 156 AliFemtoSimpleAnalysisIterator tAnalysisIter;
157 AliFemtoAnalysis* currentAnalysis;
d0e92d9a 158 for (tAnalysisIter=fAnalysisCollection->begin();tAnalysisIter!=fAnalysisCollection->end();tAnalysisIter++){
159 currentAnalysis = *tAnalysisIter;
160 currentAnalysis->Finish();
161 }
162}
163//____________________________
164AliFemtoString AliFemtoManager::Report(){
165 // Construct a report from all the classes
166 string stemp;
167 char ctemp[100];
168 // EventReader
169 stemp = fEventReader->Report();
170 // EventWriters
3be563bf 171 snprintf(ctemp , 100, "\nAliFemtoManager Reporting %u EventWriters\n",(unsigned int) fEventWriterCollection->size());
d0e92d9a 172 stemp += ctemp;
173 AliFemtoEventWriterIterator tEventWriterIter;
174 AliFemtoEventWriter* currentEventWriter;
175 for (tEventWriterIter=fEventWriterCollection->begin();tEventWriterIter!=fEventWriterCollection->end();tEventWriterIter++){
e7155bf6 176 // cout << "AliFemtoManager - asking for EventWriter Report" << endl;
d0e92d9a 177 currentEventWriter = *tEventWriterIter;
178 stemp+=currentEventWriter->Report();
179 }
180 // Analyses
3be563bf 181 snprintf(ctemp , 100, "\nAliFemtoManager Reporting %u Analyses\n",(unsigned int) fAnalysisCollection->size());
d0e92d9a 182 stemp += ctemp;
a5b23aa6 183 AliFemtoSimpleAnalysisIterator tAnalysisIter;
184 AliFemtoAnalysis* currentAnalysis;
d0e92d9a 185 for (tAnalysisIter=fAnalysisCollection->begin();tAnalysisIter!=fAnalysisCollection->end();tAnalysisIter++){
e7155bf6 186 // cout << "AliFemtoManager - asking for Analysis Report" << endl;
d0e92d9a 187 currentAnalysis = *tAnalysisIter;
188 stemp+=currentAnalysis->Report();
189 }
190
191 AliFemtoString returnThis = stemp;
192 return returnThis;
193}
194//____________________________
a5b23aa6 195AliFemtoAnalysis* AliFemtoManager::Analysis( int n ){ // return pointer to n-th analysis
d0e92d9a 196 // return analysis number n
197 if ( n<0 || n > (int) fAnalysisCollection->size() )
198 return NULL;
a5b23aa6 199 AliFemtoSimpleAnalysisIterator iter = fAnalysisCollection->begin();
d0e92d9a 200 for (int i=0; i<n ;i++){
201 iter++;
202 }
203 return *iter;
204}
205//____________________________
206AliFemtoEventWriter* AliFemtoManager::EventWriter( int n ){ // return pointer to n-th analysis
207 // return event writern number n
208 if ( n<0 || n > (int) fEventWriterCollection->size() )
209 return NULL;
210 AliFemtoEventWriterIterator iter = fEventWriterCollection->begin();
211 for (int i=0; i<n ;i++){
212 iter++;
213 }
214 return *iter;
215}
216 //____________________________
217int AliFemtoManager::ProcessEvent(){
218 // process a single event by reading it and passing it to each
219 // analysis and event writer
e7155bf6 220 // cout << "AliFemtoManager::ProcessEvent" << endl;
d0e92d9a 221 // NOTE - this ReturnHbtEvent makes a *new* AliFemtoEvent - delete it when done!
222 AliFemtoEvent* currentHbtEvent = fEventReader->ReturnHbtEvent();
e7155bf6 223 // cout << "Event reader has returned control to manager" << endl;
d0e92d9a 224
225 // if no HbtEvent is returned, then we abort processing.
226 // the question is now: do we try again next time (i.e. there may be an HbtEvent next time)
227 // or are we at EOF or something? If Reader says Status=0, then that means try again later.
228 // so, we just return the Reader's Status.
229 if (!currentHbtEvent){
230 cout << "AliFemtoManager::ProcessEvent() - Reader::ReturnHbtEvent() has returned null pointer\n";
231 return fEventReader->Status();
232 }
233
234 // loop over all the EventWriters
235 AliFemtoEventWriterIterator tEventWriterIter;
236 for (tEventWriterIter=fEventWriterCollection->begin();tEventWriterIter!=fEventWriterCollection->end();tEventWriterIter++){
237#ifdef STHBRDEBUG
238 cout << " *tEventWriterIter " << *tEventWriterIter << endl;
239#endif
240 (*tEventWriterIter)->WriteHbtEvent(currentHbtEvent);
241 }
242
243 // loop over all the Analysis
a5b23aa6 244 AliFemtoSimpleAnalysisIterator tAnalysisIter;
d0e92d9a 245 for (tAnalysisIter=fAnalysisCollection->begin();tAnalysisIter!=fAnalysisCollection->end();tAnalysisIter++){
246 (*tAnalysisIter)->ProcessEvent(currentHbtEvent);
247 }
248
249 if (currentHbtEvent) delete currentHbtEvent;
250#ifdef STHBRDEBUG
251 cout << "AliFemtoManager::ProcessEvent() - return to caller ... " << endl;
252#endif
253 return 0; // 0 = "good return"
254} // ProcessEvent