17 |
|
#include "MitAna/TAM/interface/TAModule.h" |
18 |
|
#include "MitAna/TreeMod/interface/Selector.h" |
19 |
|
#include "MitAna/TreeMod/interface/TreeLoader.h" |
20 |
+ |
#include "MitAna/TreeMod/interface/AnaFwkMod.h" |
21 |
|
#include "MitAna/TreeMod/interface/HLTFwkMod.h" |
22 |
+ |
#include "MitAna/Catalog/interface/Catalog.h" |
23 |
|
#include "MitAna/Catalog/interface/Dataset.h" |
24 |
|
|
25 |
|
ClassImp(mithep::Analysis) |
38 |
|
fOutput(0), |
39 |
|
fPackages(new TList), |
40 |
|
fLoaders(new TList), |
41 |
< |
fSuperMod(0), |
41 |
> |
fSuperMods(new TList), |
42 |
|
fSelector(0), |
43 |
|
fChain(0), |
44 |
|
fSet(0), |
71 |
|
delete fLoaders; |
72 |
|
delete fDeleteList; |
73 |
|
delete fSelector; |
74 |
< |
fOutput = 0; // owned by TAM |
75 |
< |
fSuperMod = 0; // owned by user |
74 |
> |
delete fSuperMods; |
75 |
> |
fOutput = 0; // owned by TAM |
76 |
|
|
77 |
|
delete fProof; |
78 |
|
} |
79 |
|
|
80 |
|
//-------------------------------------------------------------------------------------------------- |
81 |
+ |
Bool_t Analysis::AddDataset(const Dataset *dataset) |
82 |
+ |
{ |
83 |
+ |
// Add a full dataset to the analysis. |
84 |
+ |
|
85 |
+ |
Bool_t status = true; |
86 |
+ |
|
87 |
+ |
for (UInt_t i=0; i<dataset->NFiles(); ++i) |
88 |
+ |
status = (status && AddFile(dataset->FileUrl(i))); |
89 |
+ |
|
90 |
+ |
return status; |
91 |
+ |
} |
92 |
+ |
|
93 |
+ |
//-------------------------------------------------------------------------------------------------- |
94 |
|
Bool_t Analysis::AddFile(const char *pname) |
95 |
|
{ |
96 |
|
// Add file with given name to the list of files to be processed. Using the token "|", you can |
102 |
|
} |
103 |
|
|
104 |
|
TString pnamestr(pname); |
105 |
+ |
if (pnamestr.IsNull()) |
106 |
+ |
return kFALSE; |
107 |
+ |
|
108 |
|
TString tok("|"); |
109 |
|
TObjArray *arr = pnamestr.Tokenize(tok); |
110 |
< |
TString msg; |
110 |
> |
if (!arr) |
111 |
> |
return kFALSE; |
112 |
|
|
113 |
< |
for(Int_t i=0; i<arr->GetEntries(); i++){ |
114 |
< |
|
113 |
> |
TString msg; |
114 |
> |
for (Int_t i=0; i<arr->GetEntries(); ++i) { |
115 |
> |
|
116 |
|
TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i)); |
117 |
< |
if(!dummy) continue; |
117 |
> |
if (!dummy) |
118 |
> |
continue; |
119 |
|
|
120 |
|
AddFile(dummy->GetName(),i); |
121 |
< |
if(i==0) msg=dummy->GetName(); |
122 |
< |
else { |
123 |
< |
Info("AddFile", "Add file %s as friend to %s", |
124 |
< |
dummy->GetName(), msg.Data()); |
104 |
< |
} |
121 |
> |
if (i==0) |
122 |
> |
msg=dummy->GetName(); |
123 |
> |
else |
124 |
> |
Info("AddFile", "Add file %s as friend to %s", dummy->GetName(), msg.Data()); |
125 |
|
} |
126 |
|
delete arr; |
127 |
|
|
151 |
|
l = new TList; |
152 |
|
l->SetOwner(); |
153 |
|
fList->Add(l); |
154 |
< |
fNFriends++; |
154 |
> |
++fNFriends; |
155 |
|
|
156 |
|
} else if (eventlist < 0 || eventlist > fNFriends) { |
157 |
|
Error("AddFile", "Specified list %d not in [0,%d]", eventlist, fNFriends); |
158 |
|
return; |
159 |
|
} |
160 |
|
|
161 |
< |
if(!IsValidName(pname)) return; |
161 |
> |
if (!IsValidName(pname)) return; |
162 |
|
|
163 |
|
l->Add(new TObjString(pname)); |
164 |
|
|
207 |
|
} |
208 |
|
|
209 |
|
++fc; |
210 |
< |
if(nmax>0 && fc>=nmax) { |
210 |
> |
if (nmax>0 && fc>=nmax) { |
211 |
|
Info("AddFiles", "Maximal number (%d) of files added", nmax); |
212 |
|
break; |
213 |
|
} |
217 |
|
} |
218 |
|
|
219 |
|
//-------------------------------------------------------------------------------------------------- |
200 |
– |
Bool_t Analysis::AddDataset(const Dataset *dataset) |
201 |
– |
{ |
202 |
– |
// Add a full dataset to the analysis. |
203 |
– |
|
204 |
– |
Bool_t status = true; |
205 |
– |
|
206 |
– |
for (UInt_t i=0; i<dataset->NFiles(); i++) |
207 |
– |
status = (status && AddFile(dataset->FileUrl(i))); |
208 |
– |
|
209 |
– |
return status; |
210 |
– |
} |
211 |
– |
|
212 |
– |
//-------------------------------------------------------------------------------------------------- |
220 |
|
void Analysis::AddList(TList *list, Int_t eventlist) |
221 |
|
{ |
222 |
|
// Add file name to the event list specified by eventlist. The lists are used to hold filenames of |
261 |
|
} |
262 |
|
|
263 |
|
//-------------------------------------------------------------------------------------------------- |
264 |
+ |
void Analysis::AddSuperModule(TAModule *mod) |
265 |
+ |
{ |
266 |
+ |
// Add a top-level module to list of top-level (super) modules. |
267 |
+ |
|
268 |
+ |
fSuperMods->Add(mod); |
269 |
+ |
} |
270 |
+ |
|
271 |
+ |
//-------------------------------------------------------------------------------------------------- |
272 |
+ |
void Analysis::FileInputFromEnv() |
273 |
+ |
{ |
274 |
+ |
// Attempt to get list of filesets/files from environment. |
275 |
+ |
|
276 |
+ |
TString catalog(gSystem->Getenv("MIT_CATALOG")); |
277 |
+ |
TString book(gSystem->Getenv("MIT_BOOK")); |
278 |
+ |
TString dataset(gSystem->Getenv("MIT_DATASET")); |
279 |
+ |
TString filesets(gSystem->Getenv("MIT_FILESETS")); |
280 |
+ |
TString files(gSystem->Getenv("MIT_FILES")); |
281 |
+ |
|
282 |
+ |
if ((catalog.IsNull() || book.IsNull() || dataset.IsNull()) && files.IsNull()) { |
283 |
+ |
Warning("FileInputFromEnv", "Called to get file info from environment, but did not get" |
284 |
+ |
" consistent set of variables:\n\tMIT_CATALOG=%s\n\tMIT_BOOK=%s\n\t" |
285 |
+ |
"MIT_DATASET=%s\n\tMIT_FILESETS=%s\n\tMIT_FILES=%s\n", |
286 |
+ |
catalog.Data(), book.Data(), dataset.Data(), filesets.Data(), files.Data()); |
287 |
+ |
return; |
288 |
+ |
} |
289 |
+ |
|
290 |
+ |
|
291 |
+ |
if (!files.IsNull()) { // add local files |
292 |
+ |
Info("FileInputFromEnv", "Got from environment:\n" |
293 |
+ |
"\n\tMIT_FILES=%s\n", files.Data()); |
294 |
+ |
TString tok(";"); |
295 |
+ |
TObjArray *arr = files.Tokenize(tok); |
296 |
+ |
if (arr) { |
297 |
+ |
for (Int_t i=0; i<arr->GetEntries(); ++i) { |
298 |
+ |
TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i)); |
299 |
+ |
if (!dummy) continue; |
300 |
+ |
AddFile(dummy->GetName(),0); |
301 |
+ |
} |
302 |
+ |
delete arr; |
303 |
+ |
} |
304 |
+ |
return; |
305 |
+ |
} |
306 |
+ |
|
307 |
+ |
Info("FileInputFromEnv", "Got from environment:\n" |
308 |
+ |
"\tMIT_CATALOG=%s\n\tMIT_BOOK=%s\n\tMIT_DATASET=%s\n\tMIT_FILESETS=%s\n", |
309 |
+ |
catalog.Data(), book.Data(), dataset.Data(), filesets.Data()); |
310 |
+ |
|
311 |
+ |
Catalog cat(catalog); |
312 |
+ |
TString tok(";"); |
313 |
+ |
TObjArray *arr = filesets.Tokenize(tok); |
314 |
+ |
if (arr) { |
315 |
+ |
for (Int_t i=0; i<arr->GetEntries(); ++i) { |
316 |
+ |
TObjString *fileset = dynamic_cast<TObjString*>(arr->At(i)); |
317 |
+ |
if (!fileset) continue; |
318 |
+ |
Dataset *d = cat.FindDataset(book, dataset, fileset->String()); |
319 |
+ |
if (!d) |
320 |
+ |
continue; |
321 |
+ |
AddDataset(d); |
322 |
+ |
delete d; |
323 |
+ |
} |
324 |
+ |
delete arr; |
325 |
+ |
} |
326 |
+ |
} |
327 |
+ |
|
328 |
+ |
//-------------------------------------------------------------------------------------------------- |
329 |
|
Bool_t Analysis::Init() |
330 |
|
{ |
331 |
|
// Setup the TDSet and TChain to be used for the analysis with or without PROOF. If more than one |
337 |
|
return kFALSE; |
338 |
|
} |
339 |
|
|
340 |
+ |
// check if we should attempt to get filesets/filenames from environment |
341 |
+ |
if (fNFriends == 0) |
342 |
+ |
FileInputFromEnv(); |
343 |
+ |
|
344 |
|
if (fNFriends <= 0) { |
345 |
|
Error("Init", "List of friend lists is empty!"); |
346 |
|
return kFALSE; |
347 |
|
} |
348 |
|
|
349 |
< |
if (!fSuperMod) { |
349 |
> |
if (!fSuperMods->First()) { |
350 |
|
Error("Init", "Top-level TAM module is NULL!"); |
351 |
|
return kFALSE; |
352 |
|
} |
353 |
|
|
354 |
|
if (fUseProof) { // first init our PROOF session |
355 |
< |
if (!InitProof()) return kFALSE; |
355 |
> |
if (!InitProof()) |
356 |
> |
return kFALSE; |
357 |
|
} |
358 |
|
|
359 |
|
// we do this here instead in Terminate() so that |
364 |
|
fChain = new TChain(fTreeName); |
365 |
|
fSet = new TDSet("TTree",fTreeName); |
366 |
|
|
367 |
< |
for(Int_t i=0; i<fNFriends; i++){ |
367 |
> |
for (Int_t i=0; i<fNFriends; ++i) { |
368 |
|
|
369 |
|
TList *l = dynamic_cast<TList*>(fList->At(i)); |
370 |
|
if (!l) { |
374 |
|
|
375 |
|
if (i == 0) { |
376 |
|
TIter next(l); |
377 |
< |
while ( TObjString *obj = dynamic_cast<TObjString*>(next()) ) { |
377 |
> |
while (TObjString *obj = dynamic_cast<TObjString*>(next())) { |
378 |
|
fChain->Add(obj->GetName()); |
379 |
|
fSet->Add(obj->GetName()); |
380 |
|
} |
407 |
|
fLoaders->Add(bl); |
408 |
|
fDeleteList->Add(bl); |
409 |
|
|
410 |
+ |
// create our ana framework module |
411 |
+ |
AnaFwkMod *anamod = new AnaFwkMod; |
412 |
+ |
fDeleteList->Add(anamod); |
413 |
+ |
|
414 |
|
// create our HLT framework module |
415 |
|
HLTFwkMod *hltmod = 0; |
416 |
|
if (fUseHLT) { |
420 |
|
|
421 |
|
if (fUseProof) { |
422 |
|
|
423 |
+ |
fProof->AddInput(anamod); |
424 |
|
if (hltmod) |
425 |
|
fProof->AddInput(hltmod); |
426 |
|
|
427 |
< |
fProof->AddInput(fSuperMod); |
427 |
> |
TIter iter(fSuperMods->MakeIterator()); |
428 |
> |
while (1) { |
429 |
> |
TAModule *next = dynamic_cast<TAModule*>(iter.Next()); |
430 |
> |
if (!next) break; |
431 |
> |
fProof->AddInput(next); |
432 |
> |
} |
433 |
> |
|
434 |
|
fLoaders->SetName("TAM_LOADERS"); |
435 |
|
fProof->AddInput(fLoaders); |
436 |
|
|
439 |
|
// when not running Proof, we must make a selector |
440 |
|
fSelector = new Selector; |
441 |
|
fSelector->SetDoProxy(fDoProxy); |
442 |
+ |
|
443 |
+ |
fSelector->AddInput(anamod); |
444 |
+ |
|
445 |
|
if (hltmod) |
446 |
|
fSelector->AddInput(hltmod); |
447 |
< |
fSelector->AddInput(fSuperMod); |
447 |
> |
|
448 |
> |
TIter iter(fSuperMods->MakeIterator()); |
449 |
> |
while (1) { |
450 |
> |
TAModule *next = dynamic_cast<TAModule*>(iter.Next()); |
451 |
> |
if (!next) break; |
452 |
> |
fSelector->AddInput(next); |
453 |
> |
} |
454 |
> |
|
455 |
|
MDB(kAnalysis, 2) |
456 |
|
fSelector->SetVerbosity(1); |
457 |
|
|
458 |
|
// pass loaders to selector |
459 |
|
TIter next(fLoaders); |
460 |
< |
while ( TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()) ) |
460 |
> |
while (TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next())) |
461 |
|
fSelector->AddLoader(l); |
462 |
|
} |
463 |
|
|
470 |
|
{ |
471 |
|
// Initialize PROOF connection. |
472 |
|
|
473 |
< |
if(fProof && fProof->IsValid()) |
473 |
> |
if (fProof && fProof->IsValid()) |
474 |
|
return kTRUE; |
475 |
|
|
476 |
|
delete fProof; |
477 |
|
|
478 |
|
if (fMaster.Contains("rcf.bnl.gov")) { |
479 |
< |
for(Int_t i=0;i<5;i++) { |
479 |
> |
for (Int_t i=0; i<5; ++i) { |
480 |
|
Warning("InitProof", "*** DID YOU RUN PROOF_KINIT? %d (5) ***", i); |
481 |
|
gSystem->Sleep(1000); |
482 |
|
} |
556 |
|
} |
557 |
|
|
558 |
|
//-------------------------------------------------------------------------------------------------- |
559 |
+ |
void Analysis::SetSuperModule(TAModule *mod) |
560 |
+ |
{ |
561 |
+ |
// Set the first top-level module in the list of top-level (super) modules. |
562 |
+ |
|
563 |
+ |
fSuperMods->AddFirst(mod); |
564 |
+ |
} |
565 |
+ |
|
566 |
+ |
//-------------------------------------------------------------------------------------------------- |
567 |
|
void Analysis::Terminate() |
568 |
|
{ |
569 |
|
// Terminate current analysis run. |
592 |
|
fOutput = fSelector->GetModOutput(); |
593 |
|
} |
594 |
|
|
595 |
+ |
|
596 |
+ |
|
597 |
|
if (fOutput && !fAnaOutput.IsNull()) { |
598 |
|
TDirectory::TContext context(0); // automatically restore gDirectory |
599 |
|
|
605 |
|
Info("Terminate", "Saving output to %s!", fAnaOutput.Data()); |
606 |
|
|
607 |
|
if (fHierarchy) |
608 |
< |
fOutput->Write(fOutput->GetName(),TObject::kSingleKey); |
608 |
> |
fOutput->Write(0,-99); |
609 |
|
else |
610 |
|
fOutput->Write(); |
503 |
– |
|
611 |
|
} |
612 |
|
} |
613 |
+ |
// set state to terminate |
614 |
+ |
fState = kTerminate; |
615 |
|
} |
616 |
|
|
617 |
|
delete fChain; |
626 |
|
|
627 |
|
MitAssert("UploadPackages", packages != 0); |
628 |
|
|
629 |
< |
for (Int_t i=0; i<packages->GetEntries(); i++) { |
629 |
> |
for (Int_t i=0; i<packages->GetEntries(); ++i) { |
630 |
|
|
631 |
|
TObject* objstr = packages->At(i); |
632 |
|
if (!objstr) { |