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.27 by loizides, Mon Mar 2 12:35:29 2009 UTC

# Line 17 | Line 17
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)
# Line 29 | Line 31 | Analysis::Analysis(Bool_t useproof) :
31    fUseProof(useproof),
32    fUseHLT(kTRUE),
33    fHierarchy(kTRUE),
34 <  fDoProxy(kTRUE),
34 >  fDoProxy(kFALSE),
35 >  fDoObjTabClean(kTRUE),
36    fState(kPristine),
37    fNFriends(0),
38    fList(new TList),
39    fOutput(0),
40    fPackages(new TList),
41    fLoaders(new TList),
42 <  fSuperMod(0),
42 >  fSuperMods(new TList),
43    fSelector(0),
44    fChain(0),
45    fSet(0),
# Line 44 | Line 47 | Analysis::Analysis(Bool_t useproof) :
47    fTreeName(Names::gkEvtTreeName),
48    fCompLevel(2),
49    fProof(0),
50 <  fDoNEvents(TChain::kBigNumber)
50 >  fDoNEvents(TChain::kBigNumber),
51 >  fCacheSize(134217728)
52   {
53    // Default constructor.
54  
# Line 69 | Line 73 | Analysis::~Analysis()
73    delete fLoaders;
74    delete fDeleteList;
75    delete fSelector;
76 <  fOutput   = 0;   // owned by TAM
77 <  fSuperMod = 0;   // owned by user
76 >  delete fSuperMods;
77 >  fOutput    = 0;   // owned by TAM
78  
79    delete fProof;
80   }
81  
82   //--------------------------------------------------------------------------------------------------
83 + Bool_t Analysis::AddDataset(const Dataset *dataset)
84 + {
85 +  // Add a full dataset to the analysis.
86 +
87 +  Bool_t status = true;
88 +
89 +  for (UInt_t i=0; i<dataset->NFiles(); ++i)
90 +    status = (status && AddFile(dataset->FileUrl(i)));
91 +
92 +  return status;
93 + }
94 +
95 + //--------------------------------------------------------------------------------------------------
96   Bool_t Analysis::AddFile(const char *pname)
97   {
98    // Add file with given name to the list of files to be processed. Using the token "|", you can
# Line 87 | Line 104 | Bool_t Analysis::AddFile(const char *pna
104    }
105  
106    TString pnamestr(pname);
107 +  if (pnamestr.IsNull())
108 +    return kFALSE;
109 +
110    TString tok("|");
111    TObjArray *arr = pnamestr.Tokenize(tok);
112 <  TString msg;
112 >  if (!arr)
113 >    return kFALSE;
114  
115 <  for(Int_t i=0; i<arr->GetEntries(); i++){
116 <      
115 >  TString msg;
116 >  for (Int_t i=0; i<arr->GetEntries(); ++i) {
117 >  
118      TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i));
119 <    if(!dummy) continue;
119 >    if (!dummy)
120 >      continue;
121  
122      AddFile(dummy->GetName(),i);      
123 <    if(i==0) msg=dummy->GetName();
124 <    else {
125 <      Info("AddFile", "Add file %s as friend to %s",
126 <           dummy->GetName(), msg.Data());
104 <    }
123 >    if (i==0)
124 >      msg=dummy->GetName();
125 >    else
126 >      Info("AddFile", "Add file %s as friend to %s", dummy->GetName(), msg.Data());
127    }
128    delete arr;
129  
# Line 131 | Line 153 | void Analysis::AddFile(const char *pname
153      l = new TList;
154      l->SetOwner();
155      fList->Add(l);
156 <    fNFriends++;
156 >    ++fNFriends;
157  
158    } else if (eventlist < 0 || eventlist > fNFriends) {
159      Error("AddFile", "Specified list %d not in [0,%d]", eventlist, fNFriends);
160      return;
161    }
162    
163 <  if(!IsValidName(pname)) return;
163 >  if (!IsValidName(pname)) return;
164  
165    l->Add(new TObjString(pname));
166  
# Line 187 | Line 209 | Bool_t Analysis::AddFiles(const char *pn
209      }
210  
211      ++fc;
212 <    if(nmax>0 && fc>=nmax) {
212 >    if (nmax>0 && fc>=nmax) {
213        Info("AddFiles", "Maximal number (%d) of files added", nmax);
214        break;
215      }
# Line 197 | Line 219 | Bool_t Analysis::AddFiles(const char *pn
219   }
220  
221   //--------------------------------------------------------------------------------------------------
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 //--------------------------------------------------------------------------------------------------
222   void Analysis::AddList(TList *list, Int_t eventlist)
223   {
224    // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
# Line 254 | Line 263 | void Analysis::AddPackages(TList *list)
263   }
264  
265   //--------------------------------------------------------------------------------------------------
266 + void Analysis::AddSuperModule(TAModule *mod)
267 + {
268 +  // Add a top-level module to list of top-level (super) modules.
269 +
270 +  fSuperMods->Add(mod);      
271 + }
272 +
273 + //--------------------------------------------------------------------------------------------------
274 + void Analysis::FileInputFromEnv()
275 + {
276 +  // Attempt to get list of filesets/files from environment.
277 +
278 +  TString catalog(gSystem->Getenv("MIT_CATALOG"));
279 +  TString book(gSystem->Getenv("MIT_BOOK"));
280 +  TString dataset(gSystem->Getenv("MIT_DATASET"));
281 +  TString filesets(gSystem->Getenv("MIT_FILESETS"));
282 +  TString files(gSystem->Getenv("MIT_FILES"));
283 +
284 +  if ((catalog.IsNull() || book.IsNull() || dataset.IsNull()) && files.IsNull()) {
285 +      Warning("FileInputFromEnv", "Called to get file info from environment, but did not get"
286 +              " consistent set of variables:\n\tMIT_CATALOG=%s\n\tMIT_BOOK=%s\n\t"
287 +              "MIT_DATASET=%s\n\tMIT_FILESETS=%s\n\tMIT_FILES=%s\n",
288 +              catalog.Data(), book.Data(), dataset.Data(), filesets.Data(), files.Data());
289 +      return;
290 +  }
291 +
292 +  if (!files.IsNull()) { // add local files
293 +    Info("FileInputFromEnv", "Got from environment:\n"
294 +         "\n\tMIT_FILES=%s\n", files.Data());
295 +    TString tok(";");
296 +    TObjArray *arr = files.Tokenize(tok);
297 +    if (arr) {
298 +      for (Int_t i=0; i<arr->GetEntries(); ++i) {
299 +        TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i));
300 +        if (!dummy) continue;
301 +        AddFile(dummy->GetName(),0);      
302 +      }
303 +      delete arr;
304 +    }
305 +    return;
306 +  }
307 +
308 +  Info("FileInputFromEnv", "Got from environment:\n"
309 +       "\tMIT_CATALOG=%s\n\tMIT_BOOK=%s\n\tMIT_DATASET=%s\n\tMIT_FILESETS=%s\n",
310 +       catalog.Data(), book.Data(), dataset.Data(), filesets.Data());
311 +
312 +  Catalog cat(catalog);
313 +  if (filesets.IsNull()) {
314 +    Dataset *d = cat.FindDataset(book, dataset);
315 +    if (d) {
316 +      AddDataset(d);
317 +      delete d;
318 +    }
319 +  } else {
320 +    TString tok(";");
321 +    TObjArray *arr = filesets.Tokenize(tok);
322 +    if (arr) {
323 +      for (Int_t i=0; i<arr->GetEntries(); ++i) {
324 +        TObjString *fileset = dynamic_cast<TObjString*>(arr->At(i));
325 +        if (!fileset) continue;
326 +        Dataset *d = cat.FindDataset(book, dataset, fileset->String());
327 +        if (!d)
328 +          continue;
329 +        AddDataset(d);
330 +        delete d;
331 +      }
332 +      delete arr;
333 +    }
334 +  }
335 + }
336 +
337 + //--------------------------------------------------------------------------------------------------
338   Bool_t Analysis::Init()
339   {
340    // Setup the TDSet and TChain to be used for the analysis with or without PROOF. If more than one
# Line 265 | Line 346 | Bool_t Analysis::Init()
346      return kFALSE;
347    }
348  
349 +  // check if we should attempt to get filesets/filenames from environment
350 +  if (fNFriends == 0)
351 +    FileInputFromEnv();
352 +
353    if (fNFriends <= 0) {
354      Error("Init", "List of friend lists is empty!");
355      return kFALSE;
356    }
357  
358 <  if (!fSuperMod) {
358 >  if (!fSuperMods->First()) {
359      Error("Init", "Top-level TAM module is NULL!");
360      return kFALSE;
361    }
362  
363    if (fUseProof) { // first init our PROOF session
364 <    if (!InitProof()) return kFALSE;
364 >    if (!InitProof())
365 >      return kFALSE;
366    }
367  
368    // we do this here instead in Terminate() so that
# Line 286 | Line 372 | Bool_t Analysis::Init()
372  
373    fChain = new TChain(fTreeName);
374    fSet   = new TDSet("TTree",fTreeName);
375 +  
376 +  fChain->SetCacheSize(fCacheSize);
377  
378 <  for(Int_t i=0; i<fNFriends; i++){
378 >  for (Int_t i=0; i<fNFriends; ++i) {
379  
380      TList *l = dynamic_cast<TList*>(fList->At(i));
381      if (!l) {
# Line 297 | Line 385 | Bool_t Analysis::Init()
385  
386      if (i == 0) {
387        TIter next(l);                          
388 <      while ( TObjString *obj = dynamic_cast<TObjString*>(next()) ) {
388 >      while (TObjString *obj = dynamic_cast<TObjString*>(next())) {
389          fChain->Add(obj->GetName());
390          fSet->Add(obj->GetName());
391        }
# Line 330 | Line 418 | Bool_t Analysis::Init()
418    fLoaders->Add(bl);
419    fDeleteList->Add(bl);
420  
421 +  // create our ana framework module
422 +  AnaFwkMod *anamod = new AnaFwkMod;
423 +  fDeleteList->Add(anamod);
424 +
425    // create our HLT framework module
426    HLTFwkMod *hltmod = 0;
427    if (fUseHLT) {
# Line 339 | Line 431 | Bool_t Analysis::Init()
431  
432    if (fUseProof) {
433  
434 +    fProof->AddInput(anamod);
435      if (hltmod)
436        fProof->AddInput(hltmod);
437  
438 <    fProof->AddInput(fSuperMod);
438 >    TIter iter(fSuperMods->MakeIterator());
439 >    while (1) {
440 >      TAModule *next = dynamic_cast<TAModule*>(iter.Next());
441 >      if (!next) break;
442 >      fProof->AddInput(next);
443 >    }
444 >
445      fLoaders->SetName("TAM_LOADERS");
446      fProof->AddInput(fLoaders);      
447  
# Line 351 | Line 450 | Bool_t Analysis::Init()
450      // when not running Proof, we must make a selector
451      fSelector = new Selector;
452      fSelector->SetDoProxy(fDoProxy);
453 +    fSelector->SetDoObjTabClean(fDoObjTabClean);
454 +
455 +    fSelector->AddInput(anamod);
456 +
457      if (hltmod)
458        fSelector->AddInput(hltmod);
459 <    fSelector->AddInput(fSuperMod);
459 >
460 >    TIter iter(fSuperMods->MakeIterator());
461 >    while (1) {
462 >      TAModule *next = dynamic_cast<TAModule*>(iter.Next());
463 >      if (!next) break;
464 >      fSelector->AddInput(next);
465 >    }
466 >
467      MDB(kAnalysis, 2)
468        fSelector->SetVerbosity(1);
469  
470      // pass loaders to selector
471      TIter next(fLoaders);                          
472 <    while ( TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()) )
472 >    while (TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()))
473        fSelector->AddLoader(l);
474    }
475  
# Line 372 | Line 482 | Bool_t Analysis::InitProof()
482   {
483    // Initialize PROOF connection.
484  
485 <  if(fProof && fProof->IsValid())
485 >  if (fProof && fProof->IsValid())
486      return kTRUE;
487  
488    delete fProof;
489  
490    if (fMaster.Contains("rcf.bnl.gov")) {
491 <    for(Int_t i=0;i<5;i++) {
491 >    for (Int_t i=0; i<5; ++i) {
492        Warning("InitProof", "*** DID YOU RUN PROOF_KINIT? %d (5) ***", i);
493        gSystem->Sleep(1000);
494      }
# Line 458 | Line 568 | Bool_t Analysis::Run(Bool_t browse)
568   }
569  
570   //--------------------------------------------------------------------------------------------------
571 + void Analysis::SetSuperModule(TAModule *mod)
572 + {
573 +  // Set the first top-level module in the list of top-level (super) modules.
574 +
575 +  fSuperMods->AddFirst(mod);      
576 + }
577 +
578 + //--------------------------------------------------------------------------------------------------
579   void Analysis::Terminate()
580   {
581    // Terminate current analysis run.
# Line 486 | Line 604 | void Analysis::Terminate()
604        fOutput = fSelector->GetModOutput();
605      }
606  
607 +    
608 +
609      if (fOutput && !fAnaOutput.IsNull()) {
610        TDirectory::TContext context(0); // automatically restore gDirectory
611  
# Line 497 | Line 617 | void Analysis::Terminate()
617            Info("Terminate", "Saving output to %s!", fAnaOutput.Data());
618  
619          if (fHierarchy)
620 <          fOutput->Write(fOutput->GetName(),TObject::kSingleKey);      
620 >          fOutput->Write(0,-99);
621          else
622            fOutput->Write();
503              
623        }
624      }
625      // set state to terminate
# Line 519 | Line 638 | Bool_t Analysis::UploadPackages(TList *p
638  
639    MitAssert("UploadPackages", packages != 0);
640  
641 <  for (Int_t i=0; i<packages->GetEntries(); i++) {
641 >  for (Int_t i=0; i<packages->GetEntries(); ++i) {
642  
643      TObject* objstr = packages->At(i);
644      if (!objstr) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines