ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/Analysis.cc
(Generate patch)

Comparing UserCode/MitAna/TreeMod/src/Analysis.cc (file contents):
Revision 1.17 by loizides, Wed Nov 5 17:23:47 2008 UTC vs.
Revision 1.35 by loizides, Mon Jul 13 20:05:31 2009 UTC

# Line 11 | Line 11
11   #include <TProof.h>
12   #include <TROOT.h>
13   #include <TBrowser.h>
14 + #include <TTreeCacheUnzip.h>
15   #include "MitAna/DataUtil/interface/Debug.h"
16   #include "MitAna/DataTree/interface/Names.h"
17   #include "MitAna/TAM/interface/TAMVirtualLoader.h"
18   #include "MitAna/TAM/interface/TAModule.h"
19   #include "MitAna/TreeMod/interface/Selector.h"
20   #include "MitAna/TreeMod/interface/TreeLoader.h"
21 + #include "MitAna/TreeMod/interface/AnaFwkMod.h"
22   #include "MitAna/TreeMod/interface/HLTFwkMod.h"
23 + #include "MitAna/Catalog/interface/Catalog.h"
24   #include "MitAna/Catalog/interface/Dataset.h"
25  
26   ClassImp(mithep::Analysis)
# Line 29 | Line 32 | Analysis::Analysis(Bool_t useproof) :
32    fUseProof(useproof),
33    fUseHLT(kTRUE),
34    fHierarchy(kTRUE),
35 <  fDoProxy(kTRUE),
35 >  fDoProxy(kFALSE),
36 >  fDoObjTabClean(kTRUE),
37 >  fParallel(kFALSE),
38    fState(kPristine),
39    fNFriends(0),
40    fList(new TList),
41    fOutput(0),
42    fPackages(new TList),
43    fLoaders(new TList),
44 <  fSuperMod(0),
44 >  fSuperMods(new TList),
45    fSelector(0),
46    fChain(0),
47    fSet(0),
48    fDeleteList(new TList),
49    fTreeName(Names::gkEvtTreeName),
50 <  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   {
57    // Default constructor.
58  
# Line 69 | Line 77 | Analysis::~Analysis()
77    delete fLoaders;
78    delete fDeleteList;
79    delete fSelector;
80 <  fOutput   = 0;   // owned by TAM
81 <  fSuperMod = 0;   // owned by user
80 >  delete fSuperMods;
81 >  fOutput    = 0;   // owned by TAM
82  
83    delete fProof;
84   }
85  
86   //--------------------------------------------------------------------------------------------------
87 + Bool_t Analysis::AddDataset(const Dataset *dataset)
88 + {
89 +  // Add a full dataset to the analysis.
90 +
91 +  Bool_t status = true;
92 +
93 +  for (UInt_t i=0; i<dataset->NFiles(); ++i)
94 +    status = (status && AddFile(dataset->FileUrl(i)));
95 +
96 +  return status;
97 + }
98 +
99 + //--------------------------------------------------------------------------------------------------
100   Bool_t Analysis::AddFile(const char *pname)
101   {
102    // Add file with given name to the list of files to be processed. Using the token "|", you can
# Line 87 | Line 108 | Bool_t Analysis::AddFile(const char *pna
108    }
109  
110    TString pnamestr(pname);
111 +  if (pnamestr.IsNull())
112 +    return kFALSE;
113 +
114    TString tok("|");
115    TObjArray *arr = pnamestr.Tokenize(tok);
116 <  TString msg;
116 >  if (!arr)
117 >    return kFALSE;
118  
119 <  for(Int_t i=0; i<arr->GetEntries(); i++){
120 <      
119 >  TString msg;
120 >  for (Int_t i=0; i<arr->GetEntries(); ++i) {
121 >  
122      TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i));
123 <    if(!dummy) continue;
123 >    if (!dummy)
124 >      continue;
125  
126      AddFile(dummy->GetName(),i);      
127 <    if(i==0) msg=dummy->GetName();
128 <    else {
129 <      Info("AddFile", "Add file %s as friend to %s",
130 <           dummy->GetName(), msg.Data());
104 <    }
127 >    if (i==0)
128 >      msg=dummy->GetName();
129 >    else
130 >      Info("AddFile", "Add file %s as friend to %s", dummy->GetName(), msg.Data());
131    }
132    delete arr;
133  
# Line 131 | Line 157 | void Analysis::AddFile(const char *pname
157      l = new TList;
158      l->SetOwner();
159      fList->Add(l);
160 <    fNFriends++;
160 >    ++fNFriends;
161  
162    } else if (eventlist < 0 || eventlist > fNFriends) {
163      Error("AddFile", "Specified list %d not in [0,%d]", eventlist, fNFriends);
164      return;
165    }
166    
167 <  if(!IsValidName(pname)) return;
167 >  if (!IsValidName(pname)) return;
168  
169    l->Add(new TObjString(pname));
170  
# Line 168 | Line 194 | Bool_t Analysis::AddFiles(const char *pn
194    ifstream in;
195    in.open(pname);
196    if (!in) {
197 <    Error("AddFiles", "Can not open file with name %s", pname);
197 >    Error("AddFiles", "Cannot open file with name %s", pname);
198      return kFALSE;
199    }
200  
# Line 187 | Line 213 | Bool_t Analysis::AddFiles(const char *pn
213      }
214  
215      ++fc;
216 <    if(nmax>0 && fc>=nmax) {
216 >    if (nmax>0 && fc>=nmax) {
217        Info("AddFiles", "Maximal number (%d) of files added", nmax);
218        break;
219      }
# Line 197 | Line 223 | Bool_t Analysis::AddFiles(const char *pn
223   }
224  
225   //--------------------------------------------------------------------------------------------------
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 //--------------------------------------------------------------------------------------------------
226   void Analysis::AddList(TList *list, Int_t eventlist)
227   {
228    // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
# Line 254 | Line 267 | void Analysis::AddPackages(TList *list)
267   }
268  
269   //--------------------------------------------------------------------------------------------------
270 + void Analysis::AddSuperModule(TAModule *mod)
271 + {
272 +  // Add a top-level module to list of top-level (super) modules.
273 +
274 +  fSuperMods->Add(mod);      
275 + }
276 +
277 + //--------------------------------------------------------------------------------------------------
278 + void Analysis::FileInputFromEnv()
279 + {
280 +  // Attempt to get list of filesets/files from environment.
281 +
282 +  TString catalog(gSystem->Getenv("MIT_CATALOG"));
283 +  TString book(gSystem->Getenv("MIT_BOOK"));
284 +  TString dataset(gSystem->Getenv("MIT_DATASET"));
285 +  TString filesets(gSystem->Getenv("MIT_FILESETS"));
286 +  TString files(gSystem->Getenv("MIT_FILES"));
287 +
288 +  if ((catalog.IsNull() || book.IsNull() || dataset.IsNull()) && files.IsNull()) {
289 +      Warning("FileInputFromEnv", "Called to get file info from environment, but did not get"
290 +              " consistent set of variables:\n\tMIT_CATALOG=%s\n\tMIT_BOOK=%s\n\t"
291 +              "MIT_DATASET=%s\n\tMIT_FILESETS=%s\n\tMIT_FILES=%s\n",
292 +              catalog.Data(), book.Data(), dataset.Data(), filesets.Data(), files.Data());
293 +      return;
294 +  }
295 +
296 +  if (!files.IsNull()) { // add local files
297 +    Info("FileInputFromEnv", "Got from environment:\n"
298 +         "\n\tMIT_FILES=%s\n", files.Data());
299 +    TString tok(";");
300 +    TObjArray *arr = files.Tokenize(tok);
301 +    if (arr) {
302 +      for (Int_t i=0; i<arr->GetEntries(); ++i) {
303 +        TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i));
304 +        if (!dummy) continue;
305 +        AddFile(dummy->GetName(),0);      
306 +      }
307 +      delete arr;
308 +    }
309 +    return;
310 +  }
311 +
312 +  Info("FileInputFromEnv", "Got from environment:\n"
313 +       "\tMIT_CATALOG=%s\n\tMIT_BOOK=%s\n\tMIT_DATASET=%s\n\tMIT_FILESETS=%s\n",
314 +       catalog.Data(), book.Data(), dataset.Data(), filesets.Data());
315 +
316 +  Catalog cat(catalog);
317 +  if (filesets.IsNull()) {
318 +    Dataset *d = cat.FindDataset(book, dataset);
319 +    if (d) {
320 +      AddDataset(d);
321 +      delete d;
322 +    }
323 +  } else {
324 +    TString tok(";");
325 +    TObjArray *arr = filesets.Tokenize(tok);
326 +    if (arr) {
327 +      for (Int_t i=0; i<arr->GetEntries(); ++i) {
328 +        TObjString *fileset = dynamic_cast<TObjString*>(arr->At(i));
329 +        if (!fileset) continue;
330 +        Dataset *d = cat.FindDataset(book, dataset, fileset->String());
331 +        if (!d)
332 +          continue;
333 +        AddDataset(d);
334 +        delete d;
335 +      }
336 +      delete arr;
337 +    }
338 +  }
339 + }
340 +
341 + //--------------------------------------------------------------------------------------------------
342   Bool_t Analysis::Init()
343   {
344    // Setup the TDSet and TChain to be used for the analysis with or without PROOF. If more than one
# Line 265 | Line 350 | Bool_t Analysis::Init()
350      return kFALSE;
351    }
352  
353 +  // check if we should attempt to get filesets/filenames from environment
354 +  if (fNFriends == 0)
355 +    FileInputFromEnv();
356 +
357    if (fNFriends <= 0) {
358      Error("Init", "List of friend lists is empty!");
359      return kFALSE;
360    }
361  
362 <  if (!fSuperMod) {
362 >  if (!fSuperMods->First()) {
363      Error("Init", "Top-level TAM module is NULL!");
364      return kFALSE;
365    }
366  
367    if (fUseProof) { // first init our PROOF session
368 <    if (!InitProof()) return kFALSE;
368 >    if (!InitProof())
369 >      return kFALSE;
370    }
371  
372    // we do this here instead in Terminate() so that
# Line 287 | Line 377 | Bool_t Analysis::Init()
377    fChain = new TChain(fTreeName);
378    fSet   = new TDSet("TTree",fTreeName);
379  
380 <  for(Int_t i=0; i<fNFriends; i++){
291 <
380 >  for (Int_t i=0; i<fNFriends; ++i) {
381      TList *l = dynamic_cast<TList*>(fList->At(i));
382      if (!l) {
383        Fatal("Init", "List %d not found!", i);
# Line 297 | Line 386 | Bool_t Analysis::Init()
386  
387      if (i == 0) {
388        TIter next(l);                          
389 <      while ( TObjString *obj = dynamic_cast<TObjString*>(next()) ) {
389 >      while (TObjString *obj = dynamic_cast<TObjString*>(next())) {
390          fChain->Add(obj->GetName());
391          fSet->Add(obj->GetName());
392 +        if (fCacheSize<0 && obj->GetString().Contains("/castor/"))
393 +          fCacheSize = 64*1024*1024;
394        }
304
395      } else {
306
396        TChain *chain = new TChain(fTreeName);
397        TDSet *set    = new TDSet("TTree",fTreeName);
398  
# Line 311 | Line 400 | Bool_t Analysis::Init()
400        while (TObjString *obj = dynamic_cast<TObjString*>(next())) {
401          chain->Add(obj->GetName());
402          set->Add(obj->GetName());
403 +        if (fCacheSize<0 && obj->GetString().Contains("/castor/"))
404 +          fCacheSize = 64*1024*1024;
405        }
406  
407        TString alias("TAMTREE_"); // aliases currently not used
# Line 322 | Line 413 | Bool_t Analysis::Init()
413        fDeleteList->Add(chain);
414        fDeleteList->Add(set);
415      }
325
416    }
417  
418 +  if (fParallel)
419 +    TTreeCacheUnzip::SetParallelUnzip(TTreeCacheUnzip::kEnable);
420 +
421 +  if (fCacheSize>=0)
422 +    fChain->SetCacheSize(fCacheSize);
423 +
424    // create our customized loader plugin for TAM
425    TreeLoader *bl = new TreeLoader;
426    fLoaders->Add(bl);
427    fDeleteList->Add(bl);
428  
429 +  // create our ana framework module
430 +  AnaFwkMod *anamod = new AnaFwkMod;
431 +  anamod->SetSkipNEvents(fSkipNEvents);
432 +  anamod->SetPrintScale(fPrintScale);
433 +  fDeleteList->Add(anamod);
434 +
435    // create our HLT framework module
436    HLTFwkMod *hltmod = 0;
437    if (fUseHLT) {
# Line 339 | Line 441 | Bool_t Analysis::Init()
441  
442    if (fUseProof) {
443  
444 +    fProof->AddInput(anamod);
445      if (hltmod)
446        fProof->AddInput(hltmod);
447  
448 <    fProof->AddInput(fSuperMod);
448 >    TIter iter(fSuperMods->MakeIterator());
449 >    while (1) {
450 >      TAModule *next = dynamic_cast<TAModule*>(iter.Next());
451 >      if (!next) break;
452 >      fProof->AddInput(next);
453 >    }
454 >
455      fLoaders->SetName("TAM_LOADERS");
456      fProof->AddInput(fLoaders);      
457  
# Line 351 | Line 460 | Bool_t Analysis::Init()
460      // when not running Proof, we must make a selector
461      fSelector = new Selector;
462      fSelector->SetDoProxy(fDoProxy);
463 +    fSelector->SetDoObjTabClean(fDoObjTabClean);
464 +
465 +    fSelector->AddInput(anamod);
466 +
467      if (hltmod)
468        fSelector->AddInput(hltmod);
469 <    fSelector->AddInput(fSuperMod);
469 >
470 >    TIter iter(fSuperMods->MakeIterator());
471 >    while (1) {
472 >      TAModule *next = dynamic_cast<TAModule*>(iter.Next());
473 >      if (!next) break;
474 >      fSelector->AddInput(next);
475 >    }
476 >
477      MDB(kAnalysis, 2)
478        fSelector->SetVerbosity(1);
479  
480      // pass loaders to selector
481      TIter next(fLoaders);                          
482 <    while ( TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()) )
482 >    while (TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()))
483        fSelector->AddLoader(l);
484    }
485  
# Line 372 | Line 492 | Bool_t Analysis::InitProof()
492   {
493    // Initialize PROOF connection.
494  
495 <  if(fProof && fProof->IsValid())
495 >  if (fProof && fProof->IsValid())
496      return kTRUE;
497  
498    delete fProof;
499  
500    if (fMaster.Contains("rcf.bnl.gov")) {
501 <    for(Int_t i=0;i<5;i++) {
501 >    for (Int_t i=0; i<5; ++i) {
502        Warning("InitProof", "*** DID YOU RUN PROOF_KINIT? %d (5) ***", i);
503        gSystem->Sleep(1000);
504      }
# Line 458 | Line 578 | Bool_t Analysis::Run(Bool_t browse)
578   }
579  
580   //--------------------------------------------------------------------------------------------------
581 + void Analysis::SetSuperModule(TAModule *mod)
582 + {
583 +  // Set the first top-level module in the list of top-level (super) modules.
584 +
585 +  fSuperMods->AddFirst(mod);      
586 + }
587 +
588 + //--------------------------------------------------------------------------------------------------
589   void Analysis::Terminate()
590   {
591    // Terminate current analysis run.
# Line 486 | Line 614 | void Analysis::Terminate()
614        fOutput = fSelector->GetModOutput();
615      }
616  
617 +    
618 +
619      if (fOutput && !fAnaOutput.IsNull()) {
620        TDirectory::TContext context(0); // automatically restore gDirectory
621  
# Line 497 | Line 627 | void Analysis::Terminate()
627            Info("Terminate", "Saving output to %s!", fAnaOutput.Data());
628  
629          if (fHierarchy)
630 <          fOutput->Write(fOutput->GetName(),TObject::kSingleKey);      
630 >          fOutput->Write(0,-99);
631          else
632            fOutput->Write();
503              
633        }
634      }
635      // set state to terminate
# Line 519 | Line 648 | Bool_t Analysis::UploadPackages(TList *p
648  
649    MitAssert("UploadPackages", packages != 0);
650  
651 <  for (Int_t i=0; i<packages->GetEntries(); i++) {
651 >  for (Int_t i=0; i<packages->GetEntries(); ++i) {
652  
653      TObject* objstr = packages->At(i);
654      if (!objstr) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines