]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliMultiInputEventHandler.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / ANALYSIS / AliMultiInputEventHandler.cxx
1 //
2 // Class AliMultiInputEventHandler
3 //
4 // Multi input event handler
5 // TODO example
6 // author:
7 //        Martin Vala (martin.vala@cern.ch)
8 //
9
10 #include "AliLog.h"
11 #include "AliMCEventHandler.h"
12
13 #include "AliMultiInputEventHandler.h"
14
15 ClassImp(AliMultiInputEventHandler)
16
17 static Option_t *gCurrentMultiDataType = "ESD";
18
19 //_____________________________________________________________________________
20 AliMultiInputEventHandler::AliMultiInputEventHandler(const Int_t size, const char *name) :
21    AliInputEventHandler(name, name),
22    fBufferSize(size),
23    fInputHandlers(),
24    fAnalysisType(0)
25 {
26 //
27 // Default constructor.
28 //
29    AliDebug(AliLog::kDebug + 10, "<-");
30    fInputHandlers.SetOwner(kTRUE);
31    AliDebug(AliLog::kDebug + 10, "->");
32 }
33
34 //_____________________________________________________________________________
35 AliMultiInputEventHandler::~AliMultiInputEventHandler()
36 {
37    //
38    // Destructor
39    //
40    AliDebug(AliLog::kDebug + 10, "<-");
41    AliDebug(AliLog::kDebug + 10, "->");
42 }
43
44
45 //_____________________________________________________________________________
46 AliVEventHandler *AliMultiInputEventHandler::InputEventHandler(const Int_t index)
47 {
48    //
49    // Returns input handler
50    //
51    AliDebug(AliLog::kDebug + 5, Form("<-"));
52    if ((index >= 0) && (index < fBufferSize)) {
53       return (AliVEventHandler *) fInputHandlers.At(index);
54    }
55    AliDebug(AliLog::kDebug + 5, Form("->"));
56    return 0;
57 }
58
59 //_____________________________________________________________________________
60 void AliMultiInputEventHandler::AddInputEventHandler(AliVEventHandler*inHandler)
61 {
62    //
63    // Create N (fBufferSize) copies of input handler
64    //
65    if (inHandler->InheritsFrom("AliESDInputHandler")) gCurrentMultiDataType = "ESD";
66    if (inHandler->InheritsFrom("AliAODInputHandler")) gCurrentMultiDataType = "AOD";
67    AliDebug(AliLog::kDebug + 5, Form("<-"));
68    AliDebug(AliLog::kDebug + 5, Form("Creating %d input event handlers ...", fBufferSize));
69    AliDebug(AliLog::kDebug + 5, Form("Adding input handler with index %d ...", fBufferSize));
70    fInputHandlers.Add(inHandler);
71    fBufferSize++;
72    AliDebug(AliLog::kDebug + 5, Form("->"));
73 }
74
75 //_____________________________________________________________________________
76 Bool_t AliMultiInputEventHandler::Init(Option_t *opt)
77 {
78    //
79    // Init() is called for all mix input handlers.
80    //
81    fAnalysisType = opt;
82    AliDebug(AliLog::kDebug + 5, Form("<- \"%s\"", opt));
83    AliInputEventHandler *eh = 0;
84    TObjArrayIter next(&fInputHandlers);
85    while ((eh = (AliInputEventHandler *) next())) {
86       eh->Init(fAnalysisType);
87    }
88    AliDebug(AliLog::kDebug + 5, Form("->"));
89    return AliInputEventHandler::Init(opt);
90 }
91 //_____________________________________________________________________________
92 Bool_t AliMultiInputEventHandler::Init(TTree *tree, Option_t *opt)
93 {
94    //
95    // Init(const char*path) is called for all mix input handlers.
96    // Create event pool if needed
97    //
98    fAnalysisType = opt;
99    AliDebug(AliLog::kDebug + 5, Form("<- %p %s", (void *) tree, tree->GetName()));
100    if (!tree) {
101       AliError(Form("-> tree is null"));
102       return kFALSE;
103    }
104    AliInputEventHandler *eh = 0;
105    TObjArrayIter next(&fInputHandlers);
106    while ((eh = (AliInputEventHandler *) next())) {
107       // using mixing input hadnler from Base class
108       // for me fParentHandler would be better name
109       eh->SetParentHandler(this);
110       eh->Init(tree, fAnalysisType);
111    }
112    AliDebug(AliLog::kDebug + 5, Form("->"));
113    return AliInputEventHandler::Init(tree, opt);
114 }
115 //_____________________________________________________________________________
116 Bool_t AliMultiInputEventHandler::Notify()
117 {
118    //
119    // Notify() is called for all mix input handlers
120    //
121    AliDebug(AliLog::kDebug + 5, Form("<-"));
122    AliInputEventHandler *eh = 0;
123    TObjArrayIter next(&fInputHandlers);
124    while ((eh = (AliInputEventHandler *) next())) {
125       eh->Notify();
126    }
127    AliDebug(AliLog::kDebug + 5, Form("->"));
128    return AliInputEventHandler::Notify();
129 }
130
131 //_____________________________________________________________________________
132 Bool_t AliMultiInputEventHandler::Notify(const char *path)
133 {
134    //
135    // Notify(const char*path) is called for all mix input handlers
136    //
137    AliDebug(AliLog::kDebug + 5, Form("<- %s", path));
138    AliInputEventHandler *eh = 0;
139    TObjArrayIter next(&fInputHandlers);
140    while ((eh = (AliInputEventHandler *) next())) {
141       eh->Notify(path);
142    }
143    AliDebug(AliLog::kDebug + 5, Form("->"));
144 //   return AliInputEventHandler::Notify(path);
145    return AliInputEventHandler::Notify(path);
146 }
147 //_____________________________________________________________________________
148 Bool_t AliMultiInputEventHandler::BeginEvent(Long64_t entry)
149 {
150    //
151    // BeginEvent(Long64_t entry) is called for all mix input handlers
152    //
153    AliDebug(AliLog::kDebug + 5, Form("<- %lld", entry));
154    AliInputEventHandler *eh = 0;
155    TObjArrayIter next(&fInputHandlers);
156    while ((eh = (AliInputEventHandler *) next())) {
157       eh->BeginEvent(entry);
158    }
159    GetEntry();
160    AliDebug(AliLog::kDebug + 5, Form("->"));
161    return AliInputEventHandler::BeginEvent(entry);
162 }
163
164
165 //_____________________________________________________________________________
166 Bool_t AliMultiInputEventHandler::GetEntry()
167 {
168    //
169    // Sets correct events to every mix events
170    //
171    AliDebug(AliLog::kDebug + 5, Form("<-"));
172    AliInputEventHandler *eh = 0;
173    TObjArrayIter next(&fInputHandlers);
174    while ((eh = (AliInputEventHandler *) next())) {
175       eh->GetEntry();
176    }
177    AliDebug(AliLog::kDebug + 5, Form("->"));
178    return AliInputEventHandler::GetEntry();
179 }
180 //_____________________________________________________________________________
181 Bool_t AliMultiInputEventHandler::FinishEvent()
182 {
183    //
184    // FinishEvent() is called for all mix input handlers
185    //
186    AliDebug(AliLog::kDebug + 5, Form("<-"));
187    AliInputEventHandler *eh = 0;
188    TObjArrayIter next(&fInputHandlers);
189    while ((eh = (AliInputEventHandler *) next())) {
190       eh->FinishEvent();
191    }
192    AliDebug(AliLog::kDebug + 5, Form("->"));
193    return AliInputEventHandler::FinishEvent();
194 }
195
196 AliInputEventHandler *AliMultiInputEventHandler::GetFirstInputEventHandler()
197 {
198    //
199    // Return first InputEventHandler
200    //
201    AliDebug(AliLog::kDebug + 5, Form("<-"));
202    AliVEventHandler *eh = 0;
203    AliInputEventHandler *handler = 0;
204    TObjArrayIter next(&fInputHandlers);
205    while ((eh = (AliVEventHandler *) next())) {
206       handler = dynamic_cast<AliInputEventHandler *>(eh);
207       if (handler) return handler;
208    }
209    AliDebug(AliLog::kDebug + 5, Form("->"));
210    return 0;
211 }
212 AliMCEventHandler *AliMultiInputEventHandler::GetFirstMCEventHandler()
213 {
214    //
215    // Return first MCEventHandler
216    //
217    AliDebug(AliLog::kDebug + 5, Form("<-"));
218    AliVEventHandler *eh = 0;
219    AliMCEventHandler *handler = 0;
220    TObjArrayIter next(&fInputHandlers);
221    while ((eh = (AliVEventHandler *) next())) {
222       handler = dynamic_cast<AliMCEventHandler *>(eh);
223       if (handler) return handler;
224    }
225    AliDebug(AliLog::kDebug + 5, Form("->"));
226    return 0;
227 }
228
229 AliMultiInputEventHandler *AliMultiInputEventHandler::GetFirstMultiInputHandler()
230 {
231    //
232    // Return first MultiInputHandler
233    //
234    AliDebug(AliLog::kDebug + 5, Form("<-"));
235    AliVEventHandler *eh = 0;
236    AliMultiInputEventHandler *handler = 0;
237    TObjArrayIter next(&fInputHandlers);
238    while ((eh = (AliVEventHandler *) next())) {
239       handler = dynamic_cast<AliMultiInputEventHandler *>(eh);
240       if (handler) return handler;
241    }
242    AliDebug(AliLog::kDebug + 5, Form("->"));
243    return 0;
244 }
245
246 //______________________________________________________________________________
247 Option_t *AliMultiInputEventHandler::GetDataType() const
248 {
249    // Returns handled data type.
250    return gCurrentMultiDataType;
251 }
252
253 //______________________________________________________________________________
254 UInt_t  AliMultiInputEventHandler::IsEventSelected() 
255 {
256   // returns if event is selected
257   
258   AliInputEventHandler *firstIH = dynamic_cast<AliInputEventHandler*> (GetFirstInputEventHandler());
259   if (firstIH) {
260     return firstIH->IsEventSelected();
261   }
262   
263   return fIsSelectedResult;
264 }
265
266 //______________________________________________________________________________
267 AliPIDResponse* AliMultiInputEventHandler::GetPIDResponse()
268 {
269    // retrieve PID response
270    
271    AliInputEventHandler *firstIH = dynamic_cast<AliInputEventHandler*> (GetFirstInputEventHandler());
272    if (firstIH) {
273       return firstIH->GetPIDResponse();
274    }
275    
276    return 0x0;
277 }
278    
279 //______________________________________________________________________________
280 void AliMultiInputEventHandler::CreatePIDResponse(Bool_t isMC)
281 {
282    // create PID response
283    AliInputEventHandler *firstIH = dynamic_cast<AliInputEventHandler*> (GetFirstInputEventHandler());
284    if (firstIH) {
285       firstIH->CreatePIDResponse(isMC);
286    }
287 }