1 |
|
// $Id$ |
2 |
|
|
3 |
|
#include "MitAna/TreeMod/interface/Analysis.h" |
4 |
+ |
#include <memory> |
5 |
|
#include <Riostream.h> |
6 |
|
#include <TFile.h> |
7 |
|
#include <TList.h> |
12 |
|
#include <TProof.h> |
13 |
|
#include <TROOT.h> |
14 |
|
#include <TBrowser.h> |
15 |
+ |
#include <TTreeCacheUnzip.h> |
16 |
|
#include "MitAna/DataUtil/interface/Debug.h" |
17 |
|
#include "MitAna/DataTree/interface/Names.h" |
18 |
|
#include "MitAna/TAM/interface/TAMVirtualLoader.h" |
21 |
|
#include "MitAna/TreeMod/interface/TreeLoader.h" |
22 |
|
#include "MitAna/TreeMod/interface/AnaFwkMod.h" |
23 |
|
#include "MitAna/TreeMod/interface/HLTFwkMod.h" |
24 |
+ |
#include "MitAna/Catalog/interface/Catalog.h" |
25 |
|
#include "MitAna/Catalog/interface/Dataset.h" |
26 |
|
|
27 |
|
ClassImp(mithep::Analysis) |
33 |
|
fUseProof(useproof), |
34 |
|
fUseHLT(kTRUE), |
35 |
|
fHierarchy(kTRUE), |
36 |
< |
fDoProxy(kTRUE), |
36 |
> |
fDoProxy(kFALSE), |
37 |
> |
fDoObjTabClean(kTRUE), |
38 |
> |
fParallel(kFALSE), |
39 |
|
fState(kPristine), |
40 |
|
fNFriends(0), |
41 |
|
fList(new TList), |
47 |
|
fChain(0), |
48 |
|
fSet(0), |
49 |
|
fDeleteList(new TList), |
50 |
< |
fTreeName(Names::gkEvtTreeName), |
46 |
< |
fCompLevel(2), |
50 |
> |
fCompLevel(7), |
51 |
|
fProof(0), |
52 |
< |
fDoNEvents(TChain::kBigNumber) |
52 |
> |
fDoNEvents(TChain::kBigNumber), |
53 |
> |
fSkipNEvents(0), |
54 |
> |
fPrintScale(1), |
55 |
> |
fCacheSize(-1), |
56 |
> |
fTreeName(Names::gkEvtTreeName), |
57 |
> |
fEvtHdrName(Names::gkEvtHeaderBrn), |
58 |
> |
fRunTreeName(Names::gkRunTreeName), |
59 |
> |
fRunInfoName(Names::gkRunInfoBrn), |
60 |
> |
fAllEvtHdrBrn(Names::gkAllEvtHeaderBrn), |
61 |
> |
fLATreeName(Names::gkLATreeName), |
62 |
> |
fLAHdrName(Names::gkLAHeaderBrn), |
63 |
> |
fHLTTreeName(Names::gkHltTreeName), |
64 |
> |
fAllEvtTreeName(Names::gkAllEvtTreeName), |
65 |
> |
fHLTObjsName(Names::gkHltObjBrn) |
66 |
|
{ |
67 |
|
// Default constructor. |
68 |
|
|
88 |
|
delete fDeleteList; |
89 |
|
delete fSelector; |
90 |
|
delete fSuperMods; |
91 |
< |
fOutput = 0; // owned by TAM |
91 |
> |
fOutput = 0; // owned by TAM |
92 |
|
|
93 |
|
delete fProof; |
94 |
|
} |
95 |
|
|
96 |
|
//-------------------------------------------------------------------------------------------------- |
97 |
+ |
Bool_t Analysis::AddDataset(const Dataset *dataset) |
98 |
+ |
{ |
99 |
+ |
// Add a full dataset to the analysis. |
100 |
+ |
|
101 |
+ |
Bool_t status = true; |
102 |
+ |
|
103 |
+ |
for (UInt_t i=0; i<dataset->NFiles(); ++i) |
104 |
+ |
status = (status && AddFile(dataset->FileUrl(i))); |
105 |
+ |
|
106 |
+ |
return status; |
107 |
+ |
} |
108 |
+ |
|
109 |
+ |
//-------------------------------------------------------------------------------------------------- |
110 |
|
Bool_t Analysis::AddFile(const char *pname) |
111 |
|
{ |
112 |
|
// Add file with given name to the list of files to be processed. Using the token "|", you can |
118 |
|
} |
119 |
|
|
120 |
|
TString pnamestr(pname); |
121 |
+ |
if (pnamestr.IsNull()) |
122 |
+ |
return kFALSE; |
123 |
+ |
|
124 |
|
TString tok("|"); |
125 |
|
TObjArray *arr = pnamestr.Tokenize(tok); |
126 |
< |
TString msg; |
126 |
> |
if (!arr) |
127 |
> |
return kFALSE; |
128 |
|
|
129 |
< |
for(Int_t i=0; i<arr->GetEntries(); i++){ |
130 |
< |
|
129 |
> |
TString msg; |
130 |
> |
for (Int_t i=0; i<arr->GetEntries(); ++i) { |
131 |
> |
|
132 |
|
TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i)); |
133 |
< |
if (!dummy) continue; |
133 |
> |
if (!dummy) |
134 |
> |
continue; |
135 |
|
|
136 |
|
AddFile(dummy->GetName(),i); |
137 |
< |
if (i==0) msg=dummy->GetName(); |
138 |
< |
else { |
139 |
< |
Info("AddFile", "Add file %s as friend to %s", |
140 |
< |
dummy->GetName(), msg.Data()); |
105 |
< |
} |
137 |
> |
if (i==0) |
138 |
> |
msg=dummy->GetName(); |
139 |
> |
else |
140 |
> |
Info("AddFile", "Add file %s as friend to %s", dummy->GetName(), msg.Data()); |
141 |
|
} |
142 |
|
delete arr; |
143 |
|
|
167 |
|
l = new TList; |
168 |
|
l->SetOwner(); |
169 |
|
fList->Add(l); |
170 |
< |
fNFriends++; |
170 |
> |
++fNFriends; |
171 |
|
|
172 |
|
} else if (eventlist < 0 || eventlist > fNFriends) { |
173 |
|
Error("AddFile", "Specified list %d not in [0,%d]", eventlist, fNFriends); |
204 |
|
ifstream in; |
205 |
|
in.open(pname); |
206 |
|
if (!in) { |
207 |
< |
Error("AddFiles", "Can not open file with name %s", pname); |
207 |
> |
Error("AddFiles", "Cannot open file with name %s", pname); |
208 |
|
return kFALSE; |
209 |
|
} |
210 |
|
|
212 |
|
while (in) { |
213 |
|
TString line; |
214 |
|
line.ReadLine(in); |
180 |
– |
cout << line << endl; |
215 |
|
if (!line.EndsWith(".root")) |
216 |
|
continue; |
183 |
– |
cout << line << endl; |
217 |
|
|
218 |
|
if (!AddFile(line)) { |
219 |
|
Error("AddFiles", "Error adding file with name %s", line.Data()); |
231 |
|
} |
232 |
|
|
233 |
|
//-------------------------------------------------------------------------------------------------- |
201 |
– |
Bool_t Analysis::AddDataset(const Dataset *dataset) |
202 |
– |
{ |
203 |
– |
// Add a full dataset to the analysis. |
204 |
– |
|
205 |
– |
Bool_t status = true; |
206 |
– |
|
207 |
– |
for (UInt_t i=0; i<dataset->NFiles(); i++) |
208 |
– |
status = (status && AddFile(dataset->FileUrl(i))); |
209 |
– |
|
210 |
– |
return status; |
211 |
– |
} |
212 |
– |
|
213 |
– |
//-------------------------------------------------------------------------------------------------- |
234 |
|
void Analysis::AddList(TList *list, Int_t eventlist) |
235 |
|
{ |
236 |
|
// Add file name to the event list specified by eventlist. The lists are used to hold filenames of |
283 |
|
} |
284 |
|
|
285 |
|
//-------------------------------------------------------------------------------------------------- |
286 |
+ |
void Analysis::FileInputFromEnv() |
287 |
+ |
{ |
288 |
+ |
// Attempt to get list of filesets/files from environment. |
289 |
+ |
|
290 |
+ |
TString catalog(gSystem->Getenv("MIT_CATALOG")); |
291 |
+ |
TString book(gSystem->Getenv("MIT_BOOK")); |
292 |
+ |
TString dataset(gSystem->Getenv("MIT_DATASET")); |
293 |
+ |
TString filesets(gSystem->Getenv("MIT_FILESETS")); |
294 |
+ |
TString files(gSystem->Getenv("MIT_FILES")); |
295 |
+ |
|
296 |
+ |
if ((catalog.IsNull() || book.IsNull() || dataset.IsNull()) && files.IsNull()) { |
297 |
+ |
Warning("FileInputFromEnv", "Called to get file info from environment, but did not get" |
298 |
+ |
" consistent set of variables:\n\tMIT_CATALOG=%s\n\tMIT_BOOK=%s\n\t" |
299 |
+ |
"MIT_DATASET=%s\n\tMIT_FILESETS=%s\n\tMIT_FILES=%s\n", |
300 |
+ |
catalog.Data(), book.Data(), dataset.Data(), filesets.Data(), files.Data()); |
301 |
+ |
return; |
302 |
+ |
} |
303 |
+ |
|
304 |
+ |
if (!files.IsNull()) { // add local files |
305 |
+ |
Info("FileInputFromEnv", "Got from environment:\n" |
306 |
+ |
"\n\tMIT_FILES=%s\n", files.Data()); |
307 |
+ |
TString tok(";"); |
308 |
+ |
TObjArray *arr = files.Tokenize(tok); |
309 |
+ |
if (arr) { |
310 |
+ |
for (Int_t i=0; i<arr->GetEntries(); ++i) { |
311 |
+ |
TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i)); |
312 |
+ |
if (!dummy) continue; |
313 |
+ |
AddFile(dummy->GetName(),0); |
314 |
+ |
} |
315 |
+ |
delete arr; |
316 |
+ |
} |
317 |
+ |
return; |
318 |
+ |
} |
319 |
+ |
|
320 |
+ |
Info("FileInputFromEnv", "Got from environment:\n" |
321 |
+ |
"\tMIT_CATALOG=%s\n\tMIT_BOOK=%s\n\tMIT_DATASET=%s\n\tMIT_FILESETS=%s\n", |
322 |
+ |
catalog.Data(), book.Data(), dataset.Data(), filesets.Data()); |
323 |
+ |
|
324 |
+ |
Catalog cat(catalog); |
325 |
+ |
if (filesets.IsNull()) { |
326 |
+ |
Dataset *d = cat.FindDataset(book, dataset); |
327 |
+ |
if (d) { |
328 |
+ |
AddDataset(d); |
329 |
+ |
delete d; |
330 |
+ |
} |
331 |
+ |
} else { |
332 |
+ |
TString tok(";"); |
333 |
+ |
TObjArray *arr = filesets.Tokenize(tok); |
334 |
+ |
if (arr) { |
335 |
+ |
for (Int_t i=0; i<arr->GetEntries(); ++i) { |
336 |
+ |
TObjString *fileset = dynamic_cast<TObjString*>(arr->At(i)); |
337 |
+ |
if (!fileset) continue; |
338 |
+ |
Dataset *d = cat.FindDataset(book, dataset, fileset->String()); |
339 |
+ |
if (!d) |
340 |
+ |
continue; |
341 |
+ |
AddDataset(d); |
342 |
+ |
delete d; |
343 |
+ |
} |
344 |
+ |
delete arr; |
345 |
+ |
} |
346 |
+ |
} |
347 |
+ |
} |
348 |
+ |
|
349 |
+ |
//-------------------------------------------------------------------------------------------------- |
350 |
|
Bool_t Analysis::Init() |
351 |
|
{ |
352 |
|
// Setup the TDSet and TChain to be used for the analysis with or without PROOF. If more than one |
358 |
|
return kFALSE; |
359 |
|
} |
360 |
|
|
361 |
+ |
// check if we should attempt to get filesets/filenames from environment |
362 |
+ |
if (fNFriends == 0) |
363 |
+ |
FileInputFromEnv(); |
364 |
+ |
|
365 |
|
if (fNFriends <= 0) { |
366 |
|
Error("Init", "List of friend lists is empty!"); |
367 |
|
return kFALSE; |
373 |
|
} |
374 |
|
|
375 |
|
if (fUseProof) { // first init our PROOF session |
376 |
< |
if (!InitProof()) return kFALSE; |
376 |
> |
if (!InitProof()) |
377 |
> |
return kFALSE; |
378 |
|
} |
379 |
|
|
380 |
|
// we do this here instead in Terminate() so that |
385 |
|
fChain = new TChain(fTreeName); |
386 |
|
fSet = new TDSet("TTree",fTreeName); |
387 |
|
|
388 |
< |
for(Int_t i=0; i<fNFriends; i++){ |
300 |
< |
|
388 |
> |
for (Int_t i=0; i<fNFriends; ++i) { |
389 |
|
TList *l = dynamic_cast<TList*>(fList->At(i)); |
390 |
|
if (!l) { |
391 |
|
Fatal("Init", "List %d not found!", i); |
394 |
|
|
395 |
|
if (i == 0) { |
396 |
|
TIter next(l); |
397 |
< |
while ( TObjString *obj = dynamic_cast<TObjString*>(next()) ) { |
397 |
> |
while (TObjString *obj = dynamic_cast<TObjString*>(next())) { |
398 |
|
fChain->Add(obj->GetName()); |
399 |
|
fSet->Add(obj->GetName()); |
400 |
+ |
if (fCacheSize<0 && obj->GetString().Contains("/castor/")) |
401 |
+ |
fCacheSize = 64*1024*1024; |
402 |
|
} |
313 |
– |
|
403 |
|
} else { |
315 |
– |
|
404 |
|
TChain *chain = new TChain(fTreeName); |
405 |
|
TDSet *set = new TDSet("TTree",fTreeName); |
406 |
|
|
408 |
|
while (TObjString *obj = dynamic_cast<TObjString*>(next())) { |
409 |
|
chain->Add(obj->GetName()); |
410 |
|
set->Add(obj->GetName()); |
411 |
+ |
if (fCacheSize<0 && obj->GetString().Contains("/castor/")) |
412 |
+ |
fCacheSize = 64*1024*1024; |
413 |
|
} |
414 |
|
|
415 |
|
TString alias("TAMTREE_"); // aliases currently not used |
421 |
|
fDeleteList->Add(chain); |
422 |
|
fDeleteList->Add(set); |
423 |
|
} |
334 |
– |
|
424 |
|
} |
425 |
|
|
426 |
+ |
if (fParallel) |
427 |
+ |
TTreeCacheUnzip::SetParallelUnzip(TTreeCacheUnzip::kEnable); |
428 |
+ |
|
429 |
+ |
if (fCacheSize>=0) |
430 |
+ |
fChain->SetCacheSize(fCacheSize); |
431 |
+ |
|
432 |
|
// create our customized loader plugin for TAM |
433 |
|
TreeLoader *bl = new TreeLoader; |
434 |
|
fLoaders->Add(bl); |
436 |
|
|
437 |
|
// create our ana framework module |
438 |
|
AnaFwkMod *anamod = new AnaFwkMod; |
439 |
+ |
anamod->SetSkipNEvents(fSkipNEvents); |
440 |
+ |
anamod->SetPrintScale(fPrintScale); |
441 |
|
fDeleteList->Add(anamod); |
442 |
|
|
443 |
|
// create our HLT framework module |
444 |
|
HLTFwkMod *hltmod = 0; |
445 |
|
if (fUseHLT) { |
446 |
|
hltmod = new HLTFwkMod; |
447 |
+ |
hltmod->SetHLTObjsName(GetHLTObjsName()); |
448 |
+ |
hltmod->SetHLTTreeName(GetHLTTreeName()); |
449 |
|
fDeleteList->Add(hltmod); |
450 |
|
} |
451 |
|
|
468 |
|
} else { |
469 |
|
|
470 |
|
// when not running Proof, we must make a selector |
471 |
< |
fSelector = new Selector; |
472 |
< |
fSelector->SetDoProxy(fDoProxy); |
473 |
< |
|
474 |
< |
fSelector->AddInput(anamod); |
471 |
> |
Selector *sel = new Selector; |
472 |
> |
sel->SetDoProxy(fDoProxy); |
473 |
> |
sel->SetDoObjTabClean(fDoObjTabClean); |
474 |
> |
sel->SetDoRunInfo(kTRUE); |
475 |
> |
sel->SetAllEvtHdrBrn(GetAllEvtHdrBrn()); |
476 |
> |
sel->SetAllEvtTreeName(GetAllEvtTreeName()); |
477 |
> |
sel->SetEvtHdrName(GetEvtHdrName()); |
478 |
> |
sel->SetLAHdrName(GetLAHdrName()); |
479 |
> |
sel->SetLATreeName(GetLATreeName()); |
480 |
> |
sel->SetRunInfoName(GetRunInfoName()); |
481 |
> |
sel->SetRunTreeName(GetRunTreeName()); |
482 |
> |
sel->AddInput(anamod); |
483 |
> |
fSelector = sel; |
484 |
|
|
485 |
|
if (hltmod) |
486 |
|
fSelector->AddInput(hltmod); |
497 |
|
|
498 |
|
// pass loaders to selector |
499 |
|
TIter next(fLoaders); |
500 |
< |
while ( TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()) ) |
500 |
> |
while (TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next())) |
501 |
|
fSelector->AddLoader(l); |
502 |
|
} |
503 |
|
|
516 |
|
delete fProof; |
517 |
|
|
518 |
|
if (fMaster.Contains("rcf.bnl.gov")) { |
519 |
< |
for(Int_t i=0;i<5;i++) { |
519 |
> |
for (Int_t i=0; i<5; ++i) { |
520 |
|
Warning("InitProof", "*** DID YOU RUN PROOF_KINIT? %d (5) ***", i); |
521 |
|
gSystem->Sleep(1000); |
522 |
|
} |
666 |
|
|
667 |
|
MitAssert("UploadPackages", packages != 0); |
668 |
|
|
669 |
< |
for (Int_t i=0; i<packages->GetEntries(); i++) { |
669 |
> |
for (Int_t i=0; i<packages->GetEntries(); ++i) { |
670 |
|
|
671 |
|
TObject* objstr = packages->At(i); |
672 |
|
if (!objstr) { |