1 |
loizides |
1.1 |
//
|
2 |
bendavid |
1.8 |
// $Id: TAMSelector.cxx,v 1.7 2008/10/07 04:13:54 loizides Exp $
|
3 |
loizides |
1.1 |
//
|
4 |
|
|
|
5 |
|
|
#include "TAMSelector.h"
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
#ifndef ROOT_RVersion
|
9 |
|
|
#include <RVersion.h>
|
10 |
|
|
#endif
|
11 |
|
|
#ifndef ROOT_TFile
|
12 |
|
|
#include "TFile.h"
|
13 |
|
|
#endif
|
14 |
|
|
#ifndef ROOT_TTree
|
15 |
|
|
#include "TTree.h"
|
16 |
|
|
#endif
|
17 |
|
|
#ifndef ROOT_TError
|
18 |
|
|
#include "TError.h"
|
19 |
|
|
#endif
|
20 |
|
|
#ifndef ROOT_TROOT
|
21 |
|
|
#include "TROOT.h"
|
22 |
|
|
#endif
|
23 |
|
|
#ifndef ROOT_TList
|
24 |
|
|
#include "TList.h"
|
25 |
|
|
#endif
|
26 |
|
|
#ifndef ROOT_TClass
|
27 |
|
|
#include "TClass.h"
|
28 |
|
|
#endif
|
29 |
|
|
#ifndef ROOT_TProcessID
|
30 |
|
|
#include "TProcessID.h"
|
31 |
|
|
#endif
|
32 |
|
|
#if ROOT_VERSION_CODE >= ROOT_VERSION(5,0,0) && \
|
33 |
|
|
ROOT_VERSION_CODE < ROOT_VERSION(5,11,2)
|
34 |
|
|
#ifndef ROOT_TUrl
|
35 |
|
|
#include "TUrl.h"
|
36 |
|
|
#endif
|
37 |
|
|
#endif
|
38 |
loizides |
1.6 |
#ifndef ROOT_TRefTable
|
39 |
|
|
#include <TRefTable.h>
|
40 |
|
|
#endif
|
41 |
|
|
#ifndef ROOT_TBranchRef
|
42 |
|
|
#include <TBranchRef.h>
|
43 |
|
|
#endif
|
44 |
|
|
#ifndef ROOT_TFriendElement
|
45 |
|
|
#include "TFriendElement.h"
|
46 |
|
|
#endif
|
47 |
loizides |
1.1 |
#ifndef TAM_TAModule
|
48 |
|
|
#include "TAModule.h"
|
49 |
|
|
#endif
|
50 |
|
|
#ifndef TAM_TAMOutput
|
51 |
|
|
#include "TAMOutput.h"
|
52 |
|
|
#endif
|
53 |
|
|
#ifndef TAM_TAMVirtualLoader
|
54 |
|
|
#include "TAMVirtualLoader.h"
|
55 |
|
|
#endif
|
56 |
|
|
#ifndef TAM_TAMVirtualBranchLoader
|
57 |
|
|
#include "TAMVirtualBranchLoader.h"
|
58 |
|
|
#endif
|
59 |
|
|
#ifndef TAM_TAMTreeLoader
|
60 |
|
|
#include "TAMTreeLoader.h"
|
61 |
|
|
#endif
|
62 |
|
|
|
63 |
|
|
//////////////////////////////////////////////////////////////////////////
|
64 |
|
|
// //
|
65 |
|
|
// TAMSelector //
|
66 |
|
|
// //
|
67 |
|
|
// A selector class for modular processing of a tree (or chain). //
|
68 |
|
|
// Processing is done by TAModule(s). //
|
69 |
|
|
// //
|
70 |
|
|
// Each TAModule contains pointers to the objects that will be read //
|
71 |
|
|
// in from the tree. For each such pointer, it will call //
|
72 |
|
|
// ReqBranch(name, pointer) to request that the branch be available for //
|
73 |
|
|
// processing by the module. The module's pointer would then be //
|
74 |
|
|
// automatically set to point to the object for the current event by //
|
75 |
|
|
// the TAMSelector, whenever the module calls LoadBranch. //
|
76 |
|
|
// //
|
77 |
|
|
// TAMSelector provides (and hides) all interaction with the tree //
|
78 |
|
|
// for the TAModule(s). //
|
79 |
|
|
// //
|
80 |
|
|
// Author : Corey Reed 07/20/2004 //
|
81 |
|
|
// Maarten Ballintijn 12/06/2005 //
|
82 |
|
|
// Constantin Loizides 12/06/2005 //
|
83 |
|
|
// //
|
84 |
|
|
//////////////////////////////////////////////////////////////////////////
|
85 |
|
|
|
86 |
|
|
ClassImp(TAMSelector)
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
#if ROOT_VERSION_CODE < ROOT_VERSION(5,11,3)
|
90 |
|
|
#define R__ASSERT(e) \
|
91 |
|
|
if (!(e)) Fatal("", kAssertMsg, _QUOTE_(e), __LINE__, __FILE__)
|
92 |
|
|
#endif
|
93 |
|
|
|
94 |
loizides |
1.6 |
//______________________________________________________________________________
|
95 |
|
|
TAMSelector::TAMAutoLoadProxy::TAMAutoLoadProxy(TAMSelector *sel, Bool_t e) :
|
96 |
|
|
fSel(sel),
|
97 |
|
|
fOrig(0),
|
98 |
|
|
fFake(0),
|
99 |
loizides |
1.7 |
fCurEntry(-1)
|
100 |
loizides |
1.6 |
{
|
101 |
|
|
// Default constructor.
|
102 |
|
|
|
103 |
|
|
fFake = new TRefTable(this, 10);
|
104 |
|
|
if (e) Enable();
|
105 |
loizides |
1.7 |
|
106 |
|
|
memset(fBrRead, 0, 1024*sizeof(Bool_t));
|
107 |
loizides |
1.6 |
}
|
108 |
|
|
|
109 |
|
|
//______________________________________________________________________________
|
110 |
|
|
TAMSelector::TAMAutoLoadProxy::~TAMAutoLoadProxy()
|
111 |
|
|
{
|
112 |
|
|
// Destructor.
|
113 |
|
|
|
114 |
|
|
Disable();
|
115 |
|
|
delete fFake;
|
116 |
|
|
fFake = 0;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
//______________________________________________________________________________
|
120 |
|
|
void TAMSelector::TAMAutoLoadProxy::Disable()
|
121 |
|
|
{
|
122 |
|
|
// Disable the proxy.
|
123 |
|
|
|
124 |
|
|
if (fOrig)
|
125 |
|
|
TRefTable::SetRefTable(fOrig);
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
//______________________________________________________________________________
|
129 |
|
|
void TAMSelector::TAMAutoLoadProxy::Enable()
|
130 |
|
|
{
|
131 |
|
|
// Enable the proxy.
|
132 |
bendavid |
1.8 |
|
133 |
|
|
TBranchRef *bref = fSel->GetTree()->GetTree()->GetBranchRef();
|
134 |
|
|
if (bref) {
|
135 |
|
|
fOrig = bref->GetRefTable();
|
136 |
|
|
TRefTable::SetRefTable(fFake);
|
137 |
|
|
}
|
138 |
|
|
|
139 |
loizides |
1.6 |
}
|
140 |
|
|
|
141 |
|
|
//______________________________________________________________________________
|
142 |
|
|
Bool_t TAMSelector::TAMAutoLoadProxy::Notify()
|
143 |
|
|
{
|
144 |
|
|
// Notification received from TRefTable::Notify. Originally this would
|
145 |
|
|
// have been address to the TBranchRef owner of the TRefTable, but
|
146 |
|
|
// we intercept this call.
|
147 |
|
|
|
148 |
|
|
TBranchRef *br = dynamic_cast<TBranchRef*>(fOrig->GetOwner());
|
149 |
|
|
if (!br)
|
150 |
|
|
return kFALSE;
|
151 |
|
|
|
152 |
|
|
UInt_t uid = fFake->GetUID();
|
153 |
|
|
TProcessID *pid = fFake->GetUIDContext();
|
154 |
|
|
fOrig->SetUID(uid,pid);
|
155 |
|
|
|
156 |
|
|
if (0) { // this essentially is what ROOT would have done
|
157 |
loizides |
1.7 |
Bool_t ret = br->Notify();
|
158 |
|
|
Enable();
|
159 |
|
|
return ret;
|
160 |
loizides |
1.6 |
}
|
161 |
|
|
|
162 |
|
|
// read entry for this event
|
163 |
loizides |
1.7 |
Long64_t readentry = br->GetReadEntry();
|
164 |
|
|
Long64_t tamentry = fSel->fCurEvt;
|
165 |
|
|
if (readentry!=tamentry) {
|
166 |
|
|
Fatal("Notify",
|
167 |
|
|
"Entries from BranchRef (%d) differs from TAM current entry (%d)",
|
168 |
|
|
readentry, tamentry);
|
169 |
|
|
}
|
170 |
loizides |
1.6 |
|
171 |
|
|
// read branchref if needed
|
172 |
loizides |
1.7 |
if (fCurEntry != readentry) {
|
173 |
loizides |
1.6 |
Int_t bytes = br->GetEntry(readentry);
|
174 |
|
|
if (bytes<0) {
|
175 |
|
|
Fatal("Notify", "Could not get entry %d from %s branch",
|
176 |
|
|
readentry, br->GetName());
|
177 |
|
|
}
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
// get branch from RefTable
|
181 |
|
|
TBranch *branch = dynamic_cast<TBranch*>(fOrig->GetParent(uid, pid));
|
182 |
|
|
|
183 |
|
|
if (!branch) { //scan for possible friend Trees
|
184 |
|
|
TList *friends = fSel->GetTree()->GetListOfFriends();
|
185 |
|
|
if (friends) {
|
186 |
loizides |
1.7 |
|
187 |
|
|
// reset branch read flags if new entry to be read
|
188 |
|
|
if (fCurEntry != readentry)
|
189 |
|
|
memset(fBrRead, 0, 1024*sizeof(Bool_t));
|
190 |
|
|
|
191 |
loizides |
1.6 |
TObjLink *lnk = friends->FirstLink();
|
192 |
loizides |
1.7 |
Int_t nfriend = 0;
|
193 |
loizides |
1.6 |
while (lnk) {
|
194 |
|
|
TFriendElement *elem =
|
195 |
|
|
static_cast<TFriendElement*>(lnk->GetObject());
|
196 |
|
|
TBranchRef *bref = elem->GetTree()->GetBranchRef();
|
197 |
|
|
if (bref) {
|
198 |
loizides |
1.7 |
if (!fBrRead[nfriend]) {
|
199 |
loizides |
1.6 |
bref->GetEntry(readentry);
|
200 |
loizides |
1.7 |
fBrRead[nfriend] = kTRUE;
|
201 |
|
|
}
|
202 |
loizides |
1.6 |
TBranch *branch = dynamic_cast<TBranch*>
|
203 |
|
|
(bref->GetRefTable()->GetParent(uid, pid));
|
204 |
|
|
if (branch)
|
205 |
|
|
break; // found branch
|
206 |
|
|
}
|
207 |
|
|
lnk = lnk->Next();
|
208 |
loizides |
1.7 |
++nfriend;
|
209 |
|
|
R__ASSERT(nfriend<1024);
|
210 |
loizides |
1.6 |
}
|
211 |
|
|
}
|
212 |
|
|
}
|
213 |
|
|
|
214 |
loizides |
1.7 |
// cache last branch read attempt
|
215 |
|
|
fCurEntry = readentry;
|
216 |
|
|
|
217 |
loizides |
1.6 |
if (!branch) {
|
218 |
|
|
return kFALSE;
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
TBranch *readbranch = branch->GetMother();
|
222 |
|
|
if (!readbranch) {
|
223 |
|
|
return kFALSE;
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
const char *brname = readbranch->GetName();
|
227 |
|
|
TObject *brInfo = fSel->fBranchTable.FindObject(brname);
|
228 |
bendavid |
1.8 |
TAMBranchInfo *branchInfo;
|
229 |
loizides |
1.6 |
if (brInfo==0) {
|
230 |
bendavid |
1.8 |
branchInfo = new TAMBranchInfo(brname);
|
231 |
|
|
fSel->fBranchTable.Add(branchInfo);
|
232 |
loizides |
1.6 |
}
|
233 |
bendavid |
1.8 |
else
|
234 |
|
|
branchInfo = dynamic_cast<TAMBranchInfo*>(brInfo);
|
235 |
loizides |
1.6 |
|
236 |
bendavid |
1.8 |
fSel->LoadBranch(branchInfo);
|
237 |
loizides |
1.6 |
|
238 |
|
|
return kTRUE;
|
239 |
|
|
}
|
240 |
|
|
|
241 |
loizides |
1.1 |
|
242 |
|
|
//______________________________________________________________________________
|
243 |
|
|
TAMSelector::TAMSelector() :
|
244 |
|
|
fTree(0),
|
245 |
loizides |
1.6 |
fProxy(new TAMAutoLoadProxy(this)),
|
246 |
loizides |
1.5 |
fBranchTable(TCollection::kInitHashTableCapacity, 1),
|
247 |
|
|
fEventObjs(TCollection::kInitHashTableCapacity, 1),
|
248 |
loizides |
1.1 |
fAModules(new TAModule("TAMTopModule",
|
249 |
|
|
"Top-most module containing all other modules.")),
|
250 |
|
|
fCurEvt(-1),
|
251 |
|
|
fOwnInput(0),
|
252 |
|
|
fAnalysisAborted(kFALSE),
|
253 |
|
|
fModAborted(kFALSE),
|
254 |
|
|
fEventAborted(kFALSE),
|
255 |
|
|
fActNotify(kFALSE),
|
256 |
|
|
fObjCounter(0),
|
257 |
|
|
fVerbosity(0),
|
258 |
loizides |
1.6 |
fDoProxy(kFALSE),
|
259 |
loizides |
1.1 |
fLoaders()
|
260 |
|
|
{
|
261 |
|
|
// Default constructor.
|
262 |
|
|
|
263 |
|
|
fBranchTable.SetOwner(kTRUE);
|
264 |
|
|
fEventObjs.SetOwner(kTRUE);
|
265 |
|
|
gROOT->GetListOfBrowsables()->Add(fAModules,"Analysis Modules");
|
266 |
|
|
fLoaders.SetName("TAM_LOADERS");
|
267 |
|
|
}
|
268 |
|
|
|
269 |
|
|
|
270 |
|
|
//______________________________________________________________________________
|
271 |
|
|
TAMSelector::~TAMSelector()
|
272 |
|
|
{
|
273 |
|
|
// Destructor.
|
274 |
|
|
|
275 |
|
|
gROOT->GetListOfBrowsables()->Remove(fAModules);
|
276 |
|
|
TList *submods = fAModules->GetListOfTasks();
|
277 |
|
|
if (submods!=0) submods->Clear("nodelete");
|
278 |
|
|
delete fAModules;
|
279 |
|
|
delete fOwnInput;
|
280 |
|
|
}
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
//______________________________________________________________________________
|
284 |
|
|
void TAMSelector::AbortAnalysis()
|
285 |
|
|
{
|
286 |
|
|
// Aborts the analysis by aborting all modules and never executing
|
287 |
|
|
// further module funtions.
|
288 |
|
|
|
289 |
|
|
// no way known to propagate the stop of analysis in PROOF from
|
290 |
|
|
// one slave to the other slaves (and master).
|
291 |
|
|
Fatal("AbortAnalysis", "Analysis aborted!");
|
292 |
|
|
|
293 |
|
|
fAModules->DeactivateAll();
|
294 |
|
|
fAnalysisAborted = kTRUE;
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
|
298 |
|
|
//______________________________________________________________________________
|
299 |
|
|
void TAMSelector::AbortEvent()
|
300 |
|
|
{
|
301 |
|
|
// Aborts the current event by setting all modules inactive.
|
302 |
|
|
|
303 |
|
|
fAModules->DeactivateAll();
|
304 |
|
|
fEventAborted = kTRUE;
|
305 |
|
|
}
|
306 |
|
|
|
307 |
|
|
|
308 |
|
|
//______________________________________________________________________________
|
309 |
|
|
void TAMSelector::AbortModule(TAModule *mod)
|
310 |
|
|
{
|
311 |
|
|
// Abort the specified module by setting it (and its sub modules) inactive.
|
312 |
|
|
|
313 |
|
|
mod->DeactivateAll();
|
314 |
|
|
fModAborted = kTRUE;
|
315 |
|
|
}
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
//______________________________________________________________________________
|
319 |
|
|
void TAMSelector::AddInput(TAModule *mod)
|
320 |
|
|
{
|
321 |
|
|
// Adds the module to the top-most module in the hierarchy.
|
322 |
|
|
// The "misnomer" on the function name is intentional:
|
323 |
|
|
// This allows users to call gProof->AddInput(myMod) when
|
324 |
|
|
// using proof and mySelector->AddInput(myMod) when not
|
325 |
|
|
// using proof.
|
326 |
|
|
|
327 |
|
|
fAModules->Add(mod);
|
328 |
|
|
}
|
329 |
|
|
|
330 |
|
|
//______________________________________________________________________________
|
331 |
|
|
Bool_t TAMSelector::AddObjThisEvt(TObject *obj)
|
332 |
|
|
{
|
333 |
|
|
// Add this object to the list of objects stored for this event.
|
334 |
|
|
// See further description below.
|
335 |
|
|
|
336 |
paus |
1.4 |
if (obj)
|
337 |
loizides |
1.1 |
return AddObjThisEvt(obj,obj->GetName());
|
338 |
|
|
else {
|
339 |
paus |
1.4 |
Error("AddObjThisEvt","Can not add null object to event.");
|
340 |
loizides |
1.1 |
return kFALSE;
|
341 |
|
|
}
|
342 |
|
|
}
|
343 |
|
|
|
344 |
|
|
|
345 |
|
|
//______________________________________________________________________________
|
346 |
|
|
Bool_t TAMSelector::AddObjThisEvt(TObject *obj, const char *name)
|
347 |
|
|
{
|
348 |
|
|
// Add this object to the list of objects stored for this event.
|
349 |
|
|
// NOTE:
|
350 |
|
|
// - The object must have a unique name.
|
351 |
|
|
// - The object must be on the heap.
|
352 |
|
|
// - The object will be owned by the selector and deleted at the
|
353 |
|
|
// end of the processing of the current event.
|
354 |
|
|
//
|
355 |
|
|
// Returns true iff the object meets the requirements and is added to
|
356 |
|
|
// the list successfully.
|
357 |
|
|
|
358 |
|
|
if (obj!=0) {
|
359 |
|
|
if (FindObjThisEvt(name)==0) {
|
360 |
|
|
if (obj->IsOnHeap()) {
|
361 |
|
|
fEventObjs.Add(new TAMEvtObj(obj,name));
|
362 |
loizides |
1.5 |
return kTRUE;
|
363 |
loizides |
1.1 |
} else {
|
364 |
|
|
Error("AddObjThisEvt",
|
365 |
|
|
"Object [%s] does not appear to be on heap. "
|
366 |
|
|
"Can not add object.",
|
367 |
|
|
name);
|
368 |
|
|
}
|
369 |
|
|
} else {
|
370 |
|
|
Error("AddObjThisEvt",
|
371 |
|
|
"Object with name [%s] already added to this event.",
|
372 |
|
|
name);
|
373 |
|
|
}
|
374 |
|
|
} else {
|
375 |
|
|
Error("AddObjThisEvt",
|
376 |
|
|
"Can not add null object to event.");
|
377 |
|
|
}
|
378 |
|
|
return kFALSE;
|
379 |
|
|
}
|
380 |
|
|
|
381 |
|
|
|
382 |
|
|
//______________________________________________________________________________
|
383 |
|
|
void TAMSelector::AddNewOutputLists()
|
384 |
|
|
{
|
385 |
|
|
// Make a new hierarchy of TAMOutput objects and add it to
|
386 |
|
|
// the output of this selector. Note that this should only be called
|
387 |
|
|
// ONCE (by SlaveBegin())!!
|
388 |
|
|
|
389 |
|
|
fAModules->NewOutputList(GetOutputList());
|
390 |
|
|
}
|
391 |
|
|
|
392 |
|
|
|
393 |
|
|
//______________________________________________________________________________
|
394 |
|
|
void TAMSelector::Begin(TTree */*tree*/)
|
395 |
|
|
{
|
396 |
|
|
// The Begin() function is called at the start of the query.
|
397 |
|
|
// When running with PROOF Begin() is only called on the client.
|
398 |
|
|
// The tree argument is deprecated (on PROOF 0 is passed).
|
399 |
|
|
// It checks the tree of modules to be sure each module is set
|
400 |
|
|
// up to use this selector.
|
401 |
|
|
// Adds the tree of modules to the input list of this selector.
|
402 |
|
|
// Builds the hierarchy of TAMOutput objects in the output list.
|
403 |
|
|
// Then calls Begin() on the TAModule(s). At the end, it adds the
|
404 |
|
|
// list of loaders to the input list.
|
405 |
|
|
|
406 |
|
|
if (fAnalysisAborted) {
|
407 |
|
|
return;
|
408 |
|
|
} else {
|
409 |
|
|
if (fInput==0) {
|
410 |
|
|
fOwnInput = new TList;
|
411 |
|
|
SetInputList(fOwnInput);
|
412 |
|
|
}
|
413 |
|
|
CopyModsFromInput();
|
414 |
|
|
fAModules->SetSelector(this);
|
415 |
|
|
if (fAModules->CheckSelectors(this)) {
|
416 |
|
|
if (fModAborted) {
|
417 |
|
|
fAModules->ResetAllActiveFlags();
|
418 |
|
|
fModAborted = kFALSE;
|
419 |
|
|
}
|
420 |
|
|
fAModules->ExecuteTask(&TAModule::kExecBegin);
|
421 |
|
|
if (fEventObjs.IsEmpty()==kFALSE) fEventObjs.Delete();
|
422 |
|
|
} else {
|
423 |
|
|
Error("Begin",
|
424 |
|
|
"One or more module is not set up to use this selector.");
|
425 |
|
|
R__ASSERT(0);
|
426 |
|
|
}
|
427 |
|
|
}
|
428 |
|
|
|
429 |
|
|
fInput->AddLast(&fLoaders);
|
430 |
|
|
}
|
431 |
|
|
|
432 |
|
|
|
433 |
|
|
//______________________________________________________________________________
|
434 |
|
|
void TAMSelector::ClearAllLoaders()
|
435 |
|
|
{
|
436 |
|
|
// Go through the list of requested branches and clear the
|
437 |
|
|
// loaders that were used.
|
438 |
|
|
|
439 |
|
|
TIter nextBr(fBranchTable.MakeIterator());
|
440 |
paus |
1.4 |
while (TAMBranchInfo *br = dynamic_cast<TAMBranchInfo*>(nextBr())) {
|
441 |
loizides |
1.1 |
|
442 |
|
|
if (!br->fIsLoaded) continue;
|
443 |
|
|
// don't bother with branches that weren't loaded
|
444 |
|
|
|
445 |
|
|
TAMVirtualBranchLoader *l = br->GetLoader();
|
446 |
|
|
if (l) {
|
447 |
|
|
l->Clear();
|
448 |
|
|
} else {
|
449 |
|
|
Error("ClearAllLoaders",
|
450 |
|
|
"Could not get loader for [%s]. Unable to "
|
451 |
|
|
"try to clear loader for this branch.",
|
452 |
|
|
br->GetName());
|
453 |
|
|
}
|
454 |
|
|
}
|
455 |
|
|
}
|
456 |
|
|
|
457 |
|
|
|
458 |
|
|
//______________________________________________________________________________
|
459 |
|
|
void TAMSelector::CopyModsFromInput()
|
460 |
|
|
{
|
461 |
|
|
// Find all TAModules in the input list and copy them to fAModules.
|
462 |
|
|
|
463 |
|
|
R__ASSERT(fInput!=0);
|
464 |
|
|
|
465 |
|
|
if (fInput->IsEmpty()) return;
|
466 |
|
|
|
467 |
|
|
TObject *obj=fInput->First(), *tobj=0;
|
468 |
|
|
while (obj!=0) {
|
469 |
|
|
tobj = fInput->After(obj);
|
470 |
|
|
if (obj->InheritsFrom(TAModule::Class())) {
|
471 |
|
|
AddInput(dynamic_cast<TAModule*>(obj));
|
472 |
|
|
}
|
473 |
|
|
obj = tobj;
|
474 |
|
|
}
|
475 |
|
|
}
|
476 |
|
|
|
477 |
|
|
|
478 |
|
|
//______________________________________________________________________________
|
479 |
|
|
Bool_t TAMSelector::FindLoader(TAMBranchInfo *brInfo)
|
480 |
|
|
{
|
481 |
|
|
// Find the loader responsible for the given branch info. Return kFALSE
|
482 |
|
|
// if none could be found in the list of loaders.
|
483 |
|
|
|
484 |
|
|
const char *bname = brInfo->GetName();
|
485 |
|
|
TIter next(&fLoaders);
|
486 |
|
|
|
487 |
|
|
while( TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()) ) {
|
488 |
|
|
TAMVirtualBranchLoader *bl = l->CreateBranchLoader(fTree, brInfo);
|
489 |
|
|
if (bl != 0) {
|
490 |
|
|
Info("FindLoader","branch '%s' use loader %s",
|
491 |
|
|
bname, bl->IsA()->GetName());
|
492 |
|
|
brInfo->SetLoader(bl);
|
493 |
|
|
return kTRUE;
|
494 |
|
|
}
|
495 |
|
|
}
|
496 |
|
|
|
497 |
|
|
Error("FindLoader","No loader found for branch '%s'", bname);
|
498 |
|
|
return kFALSE;
|
499 |
|
|
}
|
500 |
|
|
|
501 |
|
|
|
502 |
|
|
//______________________________________________________________________________
|
503 |
|
|
TAMOutput *TAMSelector::FindModOutput(const TAModule *mod)
|
504 |
|
|
{
|
505 |
|
|
// Find the TAMOutput object corresponding to the given module.
|
506 |
|
|
|
507 |
|
|
TAMOutput *obj=0, *tobj=0;
|
508 |
|
|
TIter nextObj(GetOutputList());
|
509 |
|
|
while ( (obj = dynamic_cast<TAMOutput*>(nextObj())) ) {
|
510 |
|
|
tobj = obj->FindModOutput(mod); // search mod and sub mods
|
511 |
|
|
if (tobj!=0) return tobj;
|
512 |
|
|
}
|
513 |
|
|
return 0;
|
514 |
|
|
}
|
515 |
|
|
|
516 |
|
|
|
517 |
|
|
//______________________________________________________________________________
|
518 |
|
|
TObject *TAMSelector::FindObjThisEvt(const Char_t *name) const
|
519 |
|
|
{
|
520 |
|
|
// Looks for the object with the specified name that was added to
|
521 |
|
|
// this event. If not found, returns zero.
|
522 |
|
|
|
523 |
|
|
TAMEvtObj *eo = dynamic_cast<TAMEvtObj*>(fEventObjs.FindObject(name));
|
524 |
|
|
if (eo!=0) {
|
525 |
|
|
return eo->fObj;
|
526 |
|
|
}
|
527 |
|
|
return 0;
|
528 |
|
|
}
|
529 |
|
|
|
530 |
|
|
|
531 |
|
|
//______________________________________________________________________________
|
532 |
|
|
TObject *TAMSelector::FindPublicObj(const Char_t *name) const
|
533 |
|
|
{
|
534 |
|
|
// Looks for the public object with the specified name. If not found,
|
535 |
|
|
// returns zero.
|
536 |
|
|
// Note: TAModules are not public objects and will not be found by this
|
537 |
|
|
// function.
|
538 |
|
|
|
539 |
|
|
if (fInput!=0) {
|
540 |
|
|
TIter nextObj(fInput);
|
541 |
|
|
TObject *obj=0;
|
542 |
|
|
TString nm(name);
|
543 |
|
|
while ( (obj = nextObj()) ) {
|
544 |
|
|
if ( (nm.CompareTo(obj->GetName())==0) &&
|
545 |
|
|
(obj->InheritsFrom(TAModule::Class())==kFALSE) ) {
|
546 |
|
|
return obj;
|
547 |
|
|
}
|
548 |
|
|
}
|
549 |
|
|
} else {
|
550 |
|
|
Error("FindPublicObj",
|
551 |
|
|
"Input list is null. No public objects exist.");
|
552 |
|
|
}
|
553 |
|
|
return 0;
|
554 |
|
|
}
|
555 |
|
|
|
556 |
|
|
|
557 |
|
|
//______________________________________________________________________________
|
558 |
loizides |
1.5 |
const TFile *TAMSelector::GetCurrentFile() const
|
559 |
|
|
{
|
560 |
|
|
// Returns the current file that the tree is in.
|
561 |
|
|
|
562 |
|
|
return (fTree) ? (const_cast<const TFile *>(fTree->GetCurrentFile())) : 0;
|
563 |
|
|
}
|
564 |
|
|
|
565 |
|
|
|
566 |
|
|
//______________________________________________________________________________
|
567 |
|
|
TFile *TAMSelector::GetCurrentFile()
|
568 |
loizides |
1.1 |
{
|
569 |
|
|
// Returns the current file that the tree is in.
|
570 |
|
|
|
571 |
|
|
return (fTree) ? (fTree->GetCurrentFile()) : 0;
|
572 |
|
|
}
|
573 |
|
|
|
574 |
|
|
|
575 |
|
|
//______________________________________________________________________________
|
576 |
|
|
const TAMOutput *TAMSelector::GetModOutput() const
|
577 |
|
|
{
|
578 |
|
|
// Return the top-most module output object.
|
579 |
|
|
|
580 |
|
|
return fAModules->GetModOutput();
|
581 |
|
|
}
|
582 |
|
|
|
583 |
|
|
|
584 |
|
|
//______________________________________________________________________________
|
585 |
|
|
TAMOutput *TAMSelector::GetModOutput()
|
586 |
|
|
{
|
587 |
|
|
// Return the top-most module output object.
|
588 |
|
|
|
589 |
|
|
return fAModules->GetModOutput();
|
590 |
|
|
}
|
591 |
|
|
|
592 |
|
|
|
593 |
|
|
//______________________________________________________________________________
|
594 |
|
|
void TAMSelector::Init(TTree *tree) {
|
595 |
|
|
// Set the tree for this selector. The Init() function is called
|
596 |
|
|
// when the selector needs to initialize a new tree (or chain).
|
597 |
|
|
// It will be called many times when running with PROOF. The
|
598 |
|
|
// list of requested branches must been constructed
|
599 |
|
|
// already.
|
600 |
|
|
|
601 |
|
|
if (tree==0) {
|
602 |
|
|
Error("Init", "Specified tree is null.");
|
603 |
|
|
AbortAnalysis();
|
604 |
|
|
}
|
605 |
|
|
|
606 |
|
|
fTree = tree;
|
607 |
|
|
|
608 |
|
|
TIter nextBranch(fBranchTable.MakeIterator());
|
609 |
|
|
while ( TAMBranchInfo *brInfo =
|
610 |
|
|
dynamic_cast<TAMBranchInfo*>(nextBranch()) ) {
|
611 |
|
|
brInfo->Init();
|
612 |
|
|
}
|
613 |
|
|
}
|
614 |
|
|
|
615 |
|
|
//______________________________________________________________________________
|
616 |
bendavid |
1.8 |
void TAMSelector::LoadBranch(const Char_t *bname)
|
617 |
loizides |
1.1 |
{
|
618 |
bendavid |
1.8 |
|
619 |
|
|
// Loads branch by name, getting the pointer to the corresponding
|
620 |
|
|
// TAMBranchInfo and then calling the other LoadBranch function
|
621 |
|
|
|
622 |
loizides |
1.1 |
if(fCurEvt==-1) {
|
623 |
|
|
Error("LoadBranch",
|
624 |
loizides |
1.2 |
"Can not load branch with name [%s] at this point (fCurEvt==-1).",
|
625 |
loizides |
1.1 |
bname);
|
626 |
|
|
AbortAnalysis();
|
627 |
|
|
}
|
628 |
|
|
|
629 |
|
|
TAMBranchInfo *brInfo =
|
630 |
|
|
dynamic_cast<TAMBranchInfo*>( fBranchTable.FindObject(bname) );
|
631 |
|
|
|
632 |
|
|
if (brInfo==0) {
|
633 |
|
|
Error("LoadBranch",
|
634 |
|
|
"Could not find branch with name [%s] in requested branch list.",
|
635 |
|
|
bname);
|
636 |
|
|
AbortAnalysis();
|
637 |
bendavid |
1.8 |
}
|
638 |
|
|
|
639 |
|
|
LoadBranch(brInfo);
|
640 |
|
|
}
|
641 |
|
|
|
642 |
|
|
//______________________________________________________________________________
|
643 |
|
|
void TAMSelector::LoadBranch(TAMBranchInfo* brInfo)
|
644 |
|
|
{
|
645 |
|
|
// Loads the selected branch and get the current entry (number fCurEvt)
|
646 |
|
|
// if the branch has not yet been loaded for this event. It then makes
|
647 |
|
|
// sure each module's pointer to the branch object point to the address
|
648 |
|
|
// of this branch.
|
649 |
loizides |
1.1 |
|
650 |
loizides |
1.6 |
if (brInfo->IsLoaded())
|
651 |
loizides |
1.1 |
return;
|
652 |
|
|
|
653 |
|
|
// find loader for branch info if needed and notify
|
654 |
|
|
if (brInfo->GetLoader() == 0) {
|
655 |
|
|
|
656 |
|
|
if ( !FindLoader(brInfo) ) {
|
657 |
|
|
Error("LoadBranch","Branch [%s] FindLoader() failed in file [%s].",
|
658 |
|
|
brInfo->GetName(),
|
659 |
|
|
(GetCurrentFile()!=0) ? (GetCurrentFile()->GetName()) : "null");
|
660 |
|
|
|
661 |
|
|
AbortAnalysis();
|
662 |
|
|
}
|
663 |
|
|
|
664 |
|
|
if ( !brInfo->Notify(fTree) )
|
665 |
|
|
Error("LoadBranch","Branch [%s] Notify() failed in file [%s].",
|
666 |
|
|
brInfo->GetName(),
|
667 |
|
|
(GetCurrentFile()!=0) ? (GetCurrentFile()->GetName()) : "null");
|
668 |
|
|
|
669 |
|
|
// have to reset our object counter to take care of objects
|
670 |
|
|
// created in the notify of the loader
|
671 |
loizides |
1.6 |
//fObjCounter=TProcessID::GetObjectCount();
|
672 |
|
|
}
|
673 |
loizides |
1.1 |
|
674 |
|
|
// load the entry
|
675 |
|
|
Int_t ret = brInfo->GetEntry(fCurEvt);
|
676 |
|
|
if(ret<0) {
|
677 |
|
|
Error("LoadBranch",
|
678 |
|
|
"Error in file [%s] when accessing branch with name [%s] in "
|
679 |
|
|
"requested branch list.",
|
680 |
|
|
(GetCurrentFile()!=0) ? (GetCurrentFile()->GetName())
|
681 |
bendavid |
1.8 |
: "null", brInfo->GetName());
|
682 |
loizides |
1.1 |
|
683 |
|
|
AbortAnalysis();
|
684 |
|
|
}
|
685 |
loizides |
1.6 |
|
686 |
|
|
// make sure autoload proxy is enabled
|
687 |
loizides |
1.7 |
if (fDoProxy)
|
688 |
|
|
fProxy->Enable();
|
689 |
loizides |
1.1 |
}
|
690 |
|
|
|
691 |
|
|
|
692 |
|
|
//______________________________________________________________________________
|
693 |
|
|
Bool_t TAMSelector::Notify()
|
694 |
|
|
{
|
695 |
|
|
// Sets the branch pointers, checks that the types of the module's
|
696 |
|
|
// pointers correspond to what is in the tree and calls SetBranchAddress
|
697 |
|
|
// if necessary. Finally, it also notifies the modules.
|
698 |
|
|
// The Notify() function is called when a new file is opened. This
|
699 |
|
|
// can be either for a new TTree in a TChain or when a new TTree
|
700 |
|
|
// is started when using PROOF.
|
701 |
|
|
|
702 |
loizides |
1.6 |
// we are just in Notify(), therefore we ignore this call
|
703 |
loizides |
1.1 |
if(fActNotify) return kTRUE;
|
704 |
|
|
fActNotify = kTRUE; //"lock" to protect for recursive calls
|
705 |
|
|
|
706 |
|
|
#if ROOT_VERSION_CODE >= ROOT_VERSION(5,0,0) && \
|
707 |
|
|
ROOT_VERSION_CODE < ROOT_VERSION(5,11,2)
|
708 |
|
|
|
709 |
loizides |
1.6 |
// workaround for older ROOT: give file name to
|
710 |
loizides |
1.1 |
// TFile that accidentally stripped the protocol
|
711 |
loizides |
1.6 |
const TUrl *url = (GetCurrentFile()!=0)
|
712 |
|
|
? GetCurrentFile()->GetEndpointUrl() : 0;
|
713 |
loizides |
1.1 |
|
714 |
loizides |
1.6 |
if (url==0) {
|
715 |
|
|
Warning("Notify","Could not get URL for file [%s].",
|
716 |
|
|
(GetCurrentFile()!=0) ? (GetCurrentFile()->GetName())
|
717 |
|
|
: "null");
|
718 |
|
|
} else {
|
719 |
loizides |
1.1 |
|
720 |
loizides |
1.6 |
if(GetCurrentFile()!=0)
|
721 |
|
|
GetCurrentFile()->SetName((const_cast<TUrl*>(url)->GetUrl()));
|
722 |
|
|
// the const_cast is for some version of
|
723 |
|
|
// 5.08.00 that didn't have GetUrl const.
|
724 |
|
|
}
|
725 |
loizides |
1.1 |
#endif
|
726 |
|
|
|
727 |
|
|
if (fVerbosity>0) {
|
728 |
|
|
Info("Notify","Opening file [%s] at current event [%d].",
|
729 |
|
|
(GetCurrentFile()!=0) ? (GetCurrentFile()->GetName()) : "null",
|
730 |
|
|
fCurEvt);
|
731 |
|
|
}
|
732 |
|
|
|
733 |
loizides |
1.6 |
// status (return value) of notify
|
734 |
loizides |
1.1 |
Bool_t notifyStat = kTRUE;
|
735 |
|
|
|
736 |
|
|
// no event yet processed eg, no loaders assigned,
|
737 |
|
|
// so that the notify is being delayed to LoadBranch()
|
738 |
|
|
if(fCurEvt>=0) {
|
739 |
|
|
|
740 |
|
|
TIter nextBranch(fBranchTable.MakeIterator());
|
741 |
|
|
|
742 |
|
|
while ( TAMBranchInfo *brInfo =
|
743 |
|
|
dynamic_cast<TAMBranchInfo*>(nextBranch()) ) {
|
744 |
|
|
|
745 |
|
|
// notify the branchinfo and its corresponding loader
|
746 |
|
|
notifyStat &= brInfo->Notify(fTree);
|
747 |
|
|
|
748 |
|
|
// have to reset our object counter to take care of objects
|
749 |
|
|
// created in the notify of the loader
|
750 |
loizides |
1.6 |
//fObjCounter=TProcessID::GetObjectCount();;
|
751 |
loizides |
1.1 |
|
752 |
|
|
if (notifyStat==kFALSE) {
|
753 |
|
|
Error("Notify","Branch [%s] Notify() failed in file [%s].",
|
754 |
|
|
brInfo->GetName(),
|
755 |
|
|
(GetCurrentFile()!=0) ? (GetCurrentFile()->GetName())
|
756 |
|
|
: "null");
|
757 |
|
|
|
758 |
|
|
AbortAnalysis();
|
759 |
|
|
}
|
760 |
|
|
}
|
761 |
|
|
}
|
762 |
|
|
|
763 |
|
|
if (notifyStat && (fAnalysisAborted==kFALSE)) {
|
764 |
|
|
notifyStat &= fAModules->NotifyAll();
|
765 |
|
|
}
|
766 |
|
|
|
767 |
|
|
//release "lock" on notify
|
768 |
|
|
fActNotify = kFALSE;
|
769 |
|
|
|
770 |
|
|
return notifyStat;
|
771 |
|
|
}
|
772 |
|
|
|
773 |
|
|
|
774 |
|
|
//______________________________________________________________________________
|
775 |
|
|
Bool_t TAMSelector::Process(Long64_t entry)
|
776 |
|
|
{
|
777 |
|
|
// Zero's all TAModule(s)'s branch addresses and calls Process()
|
778 |
|
|
// on the TAModule(s). Then clear any requested clones arrays and
|
779 |
|
|
// clear the list of event-stored objects.
|
780 |
|
|
//
|
781 |
|
|
// The Process() function is called for each entry in the tree (or possibly
|
782 |
|
|
// keyed object in the case of PROOF) to be processed.
|
783 |
|
|
|
784 |
|
|
if (fAnalysisAborted) {
|
785 |
|
|
// There is currently no reliable way to exit cleanly back to the
|
786 |
|
|
// interpreter, so simply return immediately.
|
787 |
|
|
return kFALSE;
|
788 |
loizides |
1.2 |
}
|
789 |
loizides |
1.1 |
|
790 |
loizides |
1.6 |
// prepare for event
|
791 |
loizides |
1.2 |
fCurEvt = entry;
|
792 |
|
|
ZeroAllBranches();
|
793 |
|
|
if (fModAborted) {
|
794 |
|
|
fAModules->ResetAllActiveFlags();
|
795 |
|
|
fModAborted = kFALSE;
|
796 |
|
|
} else if (fEventAborted) {
|
797 |
|
|
fAModules->ResetAllActiveFlags();
|
798 |
|
|
fEventAborted = kFALSE;
|
799 |
|
|
}
|
800 |
loizides |
1.1 |
|
801 |
loizides |
1.6 |
// store object counter for run boundaries
|
802 |
loizides |
1.2 |
if (BeginRun()) {
|
803 |
|
|
fObjCounterRun=TProcessID::GetObjectCount();;
|
804 |
|
|
fAModules->ExecuteTask(&TAModule::kExecBeginRun);
|
805 |
|
|
}
|
806 |
loizides |
1.1 |
|
807 |
loizides |
1.6 |
// store object counter and process event
|
808 |
loizides |
1.2 |
fObjCounter=TProcessID::GetObjectCount();;
|
809 |
|
|
if (fVerbosity>9) {
|
810 |
|
|
if ((entry % 100)==0) {
|
811 |
|
|
fprintf(stderr,"Processing entry %lld... \r",
|
812 |
|
|
entry);
|
813 |
|
|
}
|
814 |
|
|
}
|
815 |
loizides |
1.6 |
|
816 |
loizides |
1.2 |
fAModules->ExecuteTask(&TAModule::kExecProcess);
|
817 |
|
|
|
818 |
loizides |
1.6 |
// update object counter on run boundaries
|
819 |
loizides |
1.2 |
if (EndRun()) {
|
820 |
|
|
fAModules->ExecuteTask(&TAModule::kExecEndRun);
|
821 |
|
|
fObjCounter=fObjCounterRun;
|
822 |
|
|
}
|
823 |
|
|
|
824 |
loizides |
1.6 |
// cleanup
|
825 |
loizides |
1.2 |
ClearAllLoaders();
|
826 |
|
|
if (fEventObjs.IsEmpty()==kFALSE)
|
827 |
|
|
fEventObjs.Delete();
|
828 |
loizides |
1.1 |
|
829 |
loizides |
1.2 |
// restore object counter
|
830 |
|
|
TProcessID::SetObjectCount(fObjCounter);
|
831 |
loizides |
1.1 |
|
832 |
|
|
return kTRUE;
|
833 |
|
|
}
|
834 |
|
|
|
835 |
|
|
|
836 |
|
|
//______________________________________________________________________________
|
837 |
|
|
Bool_t TAMSelector::PublishObj(TObject *obj)
|
838 |
|
|
{
|
839 |
|
|
// Adds an object to a list of objects which is outside the module
|
840 |
|
|
// hierarchy. This can be used to pass objects (for example, calibrations)
|
841 |
|
|
// between modules. Objects in this list are available before Begin
|
842 |
|
|
// until the end of SlaveTerminate. They are not guaranteed to be available
|
843 |
|
|
// during or after Terminate.
|
844 |
|
|
// Checks (by name) if the object is already in the list. If it is, returns
|
845 |
|
|
// kFALSE and does not publish the object.
|
846 |
|
|
// NOTE: These objects are NOT owned by the list! Whatever creates these
|
847 |
|
|
// objects must take care to (1) remove the object from the list using
|
848 |
|
|
// RetractObj() and (2) delete the object.
|
849 |
|
|
// Also NOTE: This will not publish TAModule objects.
|
850 |
|
|
|
851 |
|
|
if (obj!=0) {
|
852 |
|
|
TObject *ob = FindPublicObj(obj->GetName());
|
853 |
|
|
if (ob==0) {
|
854 |
|
|
if (obj->InheritsFrom(TAModule::Class())) {
|
855 |
|
|
// Disallow publishing of TAModules since it breaks the assumption
|
856 |
|
|
// that all TAModules in the input list were added by AddInput and
|
857 |
|
|
// are intended to be executed. (Such modules would be found by
|
858 |
|
|
// TakeModsFromInput and CopyModsFromInput.)
|
859 |
|
|
Warning("PublishObj",
|
860 |
|
|
"Can not publish a TAModule. Object named [%s] not "
|
861 |
|
|
"published.",
|
862 |
|
|
obj->GetName());
|
863 |
|
|
} else {
|
864 |
|
|
if (fInput!=0) {
|
865 |
|
|
fInput->Add(obj);
|
866 |
|
|
return kTRUE;
|
867 |
|
|
} else {
|
868 |
|
|
Error("PublishObj",
|
869 |
|
|
"Input list is null. Could not publish object named [%s].",
|
870 |
|
|
obj->GetName());
|
871 |
|
|
}
|
872 |
|
|
}
|
873 |
|
|
} else {
|
874 |
|
|
Warning("PublishObj",
|
875 |
|
|
"Public object named [%s] already exists.",
|
876 |
|
|
obj->GetName());
|
877 |
|
|
}
|
878 |
|
|
} else {
|
879 |
|
|
Error("PublishObj",
|
880 |
|
|
"Can not publish null object.");
|
881 |
|
|
}
|
882 |
|
|
return kFALSE;
|
883 |
|
|
}
|
884 |
|
|
|
885 |
|
|
|
886 |
|
|
//______________________________________________________________________________
|
887 |
|
|
TObject *TAMSelector::RemoveObjThisEvt(const Char_t *name)
|
888 |
|
|
{
|
889 |
|
|
// Finds the object with the specified name and removes it from
|
890 |
|
|
// the list of objects added to this event.
|
891 |
|
|
// Returns the object that was removed.
|
892 |
|
|
|
893 |
|
|
TAMEvtObj *eo = dynamic_cast<TAMEvtObj*>(fEventObjs.FindObject(name));
|
894 |
|
|
if (eo!=0) {
|
895 |
|
|
fEventObjs.Remove(eo);
|
896 |
|
|
TObject *obj = eo->fObj;
|
897 |
|
|
eo->fObj = 0; // so it won't delete the object
|
898 |
|
|
delete eo;
|
899 |
|
|
return obj;
|
900 |
|
|
}
|
901 |
|
|
return 0;
|
902 |
|
|
}
|
903 |
|
|
|
904 |
|
|
|
905 |
|
|
//______________________________________________________________________________
|
906 |
|
|
TObject *TAMSelector::RetractObj(const Char_t *name)
|
907 |
|
|
{
|
908 |
|
|
// Finds the public object with the specified name and removes it from
|
909 |
|
|
// the list of public objects.
|
910 |
|
|
// Returns the object that was retracted.
|
911 |
|
|
// Note: TAmodules are not public objects and will not be removed by this
|
912 |
|
|
// function.
|
913 |
|
|
|
914 |
|
|
TObject *obj = FindPublicObj(name);
|
915 |
|
|
if (obj!=0) {
|
916 |
|
|
return fInput->Remove(obj);
|
917 |
|
|
}
|
918 |
|
|
return 0;
|
919 |
|
|
}
|
920 |
|
|
|
921 |
|
|
|
922 |
|
|
//______________________________________________________________________________
|
923 |
|
|
void TAMSelector::SlaveBegin(TTree *tree)
|
924 |
|
|
{
|
925 |
|
|
// Inits the tree and calls SlaveBegin() on the TAModule(s)
|
926 |
|
|
//
|
927 |
|
|
// The SlaveBegin() function is called after the Begin() function.
|
928 |
|
|
// When running with PROOF SlaveBegin() is called on each slave server.
|
929 |
|
|
// The tree argument is deprecated (on PROOF 0 is passed).
|
930 |
|
|
|
931 |
|
|
if (fAnalysisAborted) {
|
932 |
|
|
return;
|
933 |
|
|
} else {
|
934 |
|
|
// call SlaveBegin first so the modules can call ReqBranch and
|
935 |
|
|
// build the fBranchTable
|
936 |
|
|
if (fModAborted) {
|
937 |
|
|
fAModules->ResetAllActiveFlags();
|
938 |
|
|
fModAborted = kFALSE;
|
939 |
|
|
}
|
940 |
|
|
// remove the modules from the input list and put them in the top-most
|
941 |
|
|
// module of this selector. make sure they use this selector
|
942 |
|
|
TakeLoadersFromInput();
|
943 |
|
|
TakeModsFromInput();
|
944 |
|
|
fAModules->SetSelector(this);
|
945 |
|
|
if (fAModules->CheckSelectors(this)) {
|
946 |
|
|
// build the module output hierarchy
|
947 |
|
|
AddNewOutputLists();
|
948 |
|
|
// set up the module's output members
|
949 |
|
|
if (fAModules->fOutput != 0) {
|
950 |
|
|
fAModules->fOutput->SetAllOutputMembers(kFALSE);
|
951 |
|
|
}
|
952 |
|
|
|
953 |
|
|
fAModules->ExecuteTask(&TAModule::kExecSlaveBegin);
|
954 |
|
|
} else {
|
955 |
|
|
Error("SlaveBegin",
|
956 |
|
|
"One or more module is not set up to use this selector.");
|
957 |
|
|
R__ASSERT(0);
|
958 |
|
|
}
|
959 |
|
|
|
960 |
|
|
// init requires fBranchTable to be built already
|
961 |
|
|
// in Proof, this is called automatically when a new tree is loaded
|
962 |
loizides |
1.6 |
if (tree)
|
963 |
|
|
Init(tree);
|
964 |
|
|
if (fEventObjs.IsEmpty()==kFALSE)
|
965 |
|
|
fEventObjs.Delete();
|
966 |
loizides |
1.1 |
}
|
967 |
|
|
}
|
968 |
|
|
|
969 |
|
|
|
970 |
|
|
//______________________________________________________________________________
|
971 |
|
|
void TAMSelector::SlaveTerminate()
|
972 |
|
|
{
|
973 |
|
|
// Calls SlaveTerminate() on the TAModule(s)
|
974 |
|
|
// The SlaveTerminate() function is called after all entries or objects
|
975 |
|
|
// have been processed. When running with PROOF SlaveTerminate() is called
|
976 |
|
|
// on each slave server.
|
977 |
|
|
|
978 |
|
|
if (fAnalysisAborted) {
|
979 |
|
|
return;
|
980 |
|
|
} else {
|
981 |
|
|
if (fModAborted) {
|
982 |
|
|
fAModules->ResetAllActiveFlags();
|
983 |
|
|
fModAborted = kFALSE;
|
984 |
|
|
}
|
985 |
|
|
fAModules->ExecuteTask(&TAModule::kExecSlaveTerminate);
|
986 |
|
|
if (fEventObjs.IsEmpty()==kFALSE) fEventObjs.Delete();
|
987 |
|
|
}
|
988 |
|
|
}
|
989 |
|
|
|
990 |
|
|
|
991 |
|
|
//______________________________________________________________________________
|
992 |
|
|
void TAMSelector::TakeModsFromInput()
|
993 |
|
|
{
|
994 |
|
|
// Find all TAModules in the input list and move them to fAModules.
|
995 |
|
|
|
996 |
|
|
R__ASSERT(fInput!=0);
|
997 |
|
|
|
998 |
|
|
if (fInput->IsEmpty()==kFALSE) {
|
999 |
|
|
TObject *obj=fInput->First(), *tobj=0;
|
1000 |
|
|
while (obj!=0) {
|
1001 |
|
|
tobj = fInput->After(obj);
|
1002 |
|
|
if (obj->InheritsFrom(TAModule::Class())) {
|
1003 |
|
|
AddInput(dynamic_cast<TAModule*>(obj));
|
1004 |
|
|
fInput->Remove(obj);
|
1005 |
|
|
}
|
1006 |
|
|
obj = tobj;
|
1007 |
|
|
}
|
1008 |
|
|
}
|
1009 |
|
|
}
|
1010 |
|
|
|
1011 |
|
|
|
1012 |
|
|
//______________________________________________________________________________
|
1013 |
|
|
void TAMSelector::TakeLoadersFromInput()
|
1014 |
|
|
{
|
1015 |
|
|
// Find all TAModules in the input list and copy them to fAModules.
|
1016 |
|
|
|
1017 |
|
|
R__ASSERT(fInput!=0);
|
1018 |
|
|
|
1019 |
|
|
TList *loaders = dynamic_cast<TList*>(fInput->FindObject("TAM_LOADERS"));
|
1020 |
|
|
if (loaders != 0) {
|
1021 |
|
|
TIter next(loaders);
|
1022 |
|
|
while ( TAMVirtualLoader *l =
|
1023 |
|
|
dynamic_cast<TAMVirtualLoader*>(next()) ) {
|
1024 |
|
|
if (loaders != &fLoaders) fLoaders.AddLast(l);
|
1025 |
|
|
}
|
1026 |
|
|
}
|
1027 |
|
|
|
1028 |
|
|
fLoaders.AddLast(new TAMTreeLoader());
|
1029 |
|
|
}
|
1030 |
|
|
|
1031 |
|
|
|
1032 |
|
|
//______________________________________________________________________________
|
1033 |
|
|
void TAMSelector::Terminate()
|
1034 |
|
|
{
|
1035 |
|
|
// Calls Terminate() on the TAModule(s).
|
1036 |
|
|
// When running under Proof, will copy the TAMOutput object
|
1037 |
|
|
// from the fOutput list to the top most TAModule object. Assumes
|
1038 |
|
|
// that the only TAMOutput object in fOutput is the one belonging
|
1039 |
|
|
// to the top most module.
|
1040 |
|
|
// The Terminate() function is the last function to be called during
|
1041 |
|
|
// a query. It always runs on the client, it can be used to present
|
1042 |
|
|
// the results graphically or save the results to file.
|
1043 |
|
|
|
1044 |
|
|
if (fAnalysisAborted) {
|
1045 |
|
|
return;
|
1046 |
|
|
}
|
1047 |
|
|
|
1048 |
|
|
if (fModAborted) {
|
1049 |
|
|
fAModules->ResetAllActiveFlags();
|
1050 |
|
|
fModAborted = kFALSE;
|
1051 |
|
|
}
|
1052 |
|
|
|
1053 |
|
|
if (fAModules->GetModOutput()==0) {
|
1054 |
|
|
// When running under Proof, copy the module output hierarchy to
|
1055 |
|
|
// this selector's top most module.
|
1056 |
|
|
TIter nextObj(GetOutputList());
|
1057 |
|
|
TAMOutput *tout=0;
|
1058 |
|
|
TObject *obj=0;
|
1059 |
|
|
Bool_t alreadySet=kFALSE;
|
1060 |
|
|
while ( (obj = nextObj()) ) {
|
1061 |
|
|
if (obj->InheritsFrom(TAMOutput::Class())) {
|
1062 |
|
|
tout = dynamic_cast<TAMOutput*>(obj);
|
1063 |
|
|
if (alreadySet) {
|
1064 |
|
|
Warning("Terminate",
|
1065 |
|
|
"Found more than one TAMOutput object in the "
|
1066 |
|
|
"output list. Assuming the first one is from the "
|
1067 |
|
|
"top-most module. The output list contains:");
|
1068 |
|
|
GetOutputList()->ls();
|
1069 |
|
|
} else {
|
1070 |
|
|
// copy module output hierarchy
|
1071 |
|
|
fAModules->SetAllModOutput(tout);
|
1072 |
|
|
// try to set module's pointers to their output objects
|
1073 |
|
|
tout->SetAllOutputMembers(kTRUE);
|
1074 |
|
|
alreadySet=kTRUE;
|
1075 |
|
|
}
|
1076 |
|
|
}
|
1077 |
|
|
}
|
1078 |
|
|
if (alreadySet==kFALSE) {
|
1079 |
|
|
Error("Terminate",
|
1080 |
|
|
"Did not find TAMOutput object in the output list! "
|
1081 |
|
|
"The output list contains:");
|
1082 |
|
|
GetOutputList()->ls();
|
1083 |
|
|
}
|
1084 |
|
|
}
|
1085 |
|
|
|
1086 |
|
|
// move output objs from current objects to stored objects
|
1087 |
|
|
// incase the module wants to write output to a file
|
1088 |
|
|
if (fAModules->GetModOutput()!=0) {
|
1089 |
|
|
fAModules->GetModOutput()->StoreAllOutputObjs();
|
1090 |
|
|
} else {
|
1091 |
|
|
Error("Terminate",
|
1092 |
|
|
"Could not store output objects from this process run.");
|
1093 |
|
|
}
|
1094 |
|
|
|
1095 |
|
|
fAModules->ExecuteTask(&TAModule::kExecTerminate);
|
1096 |
|
|
if (fEventObjs.IsEmpty()==kFALSE) fEventObjs.Delete();
|
1097 |
|
|
|
1098 |
|
|
// store output objects again, in case a module added any output
|
1099 |
|
|
// objects during terminate
|
1100 |
|
|
if (fAModules->GetModOutput()!=0) {
|
1101 |
|
|
fAModules->GetModOutput()->StoreAllOutputObjs();
|
1102 |
|
|
} else {
|
1103 |
|
|
Error("Terminate",
|
1104 |
|
|
"Could not store output objects after terminate.");
|
1105 |
|
|
}
|
1106 |
|
|
}
|
1107 |
|
|
|
1108 |
|
|
|
1109 |
|
|
//______________________________________________________________________________
|
1110 |
|
|
void TAMSelector::ZeroAllBranches()
|
1111 |
|
|
{
|
1112 |
|
|
// Loops through all branches in fBranchTable and sets all user addresses
|
1113 |
|
|
// for each branch to zero.
|
1114 |
|
|
|
1115 |
|
|
TIter nextBranch(fBranchTable.MakeIterator());
|
1116 |
paus |
1.4 |
while (TAMBranchInfo *brInfo =
|
1117 |
|
|
dynamic_cast<TAMBranchInfo*>(nextBranch())) {
|
1118 |
loizides |
1.1 |
brInfo->ZeroUsrAddrs();
|
1119 |
|
|
}
|
1120 |
|
|
}
|