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.10 by loizides, Tue Jun 24 14:07:21 2008 UTC vs.
Revision 1.23 by loizides, Thu Dec 11 15:53:26 2008 UTC

# Line 16 | Line 16
16   #include "MitAna/TAM/interface/TAMVirtualLoader.h"
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)
26  
27   using namespace mithep;
28  
29 < //__________________________________________________________________________________________________
29 > //--------------------------------------------------------------------------------------------------
30   Analysis::Analysis(Bool_t useproof) :
31    fUseProof(useproof),
32 <  fHierachy(kTRUE),
32 >  fUseHLT(kTRUE),
33 >  fHierarchy(kTRUE),
34 >  fDoProxy(kTRUE),
35    fState(kPristine),
36    fNFriends(0),
37    fList(new TList),
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),
# Line 51 | Line 58 | Analysis::Analysis(Bool_t useproof) :
58    // nothing to be done since we do not use par files (yet?)
59   }
60  
61 < //__________________________________________________________________________________________________
61 > //--------------------------------------------------------------------------------------------------
62   Analysis::~Analysis()
63   {
64    // Destructor.
# Line 64 | Line 71 | Analysis::~Analysis()
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 < //__________________________________________________________________________________________________
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
# Line 82 | Line 102 | Bool_t Analysis::AddFile(const char *pna
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());
99 <    }
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  
128    return kTRUE;
129   }
130  
131 < //__________________________________________________________________________________________________
131 > //--------------------------------------------------------------------------------------------------
132   void Analysis::AddFile(const char *pname, Int_t eventlist)
133   {
134    // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
# Line 126 | Line 151 | void Analysis::AddFile(const char *pname
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  
# Line 141 | Line 166 | void Analysis::AddFile(const char *pname
166      Info("AddFile", "Added %s to list of files.", pname);
167   }
168  
169 < //__________________________________________________________________________________________________
169 > //--------------------------------------------------------------------------------------------------
170   void Analysis::AddFile(const TObject *oname, Int_t eventlist)
171   {
172    // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
# Line 182 | Line 207 | Bool_t Analysis::AddFiles(const char *pn
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      }
# Line 191 | Line 216 | Bool_t Analysis::AddFiles(const char *pn
216    return kTRUE;
217   }
218  
219 < //__________________________________________________________________________________________________
219 > //--------------------------------------------------------------------------------------------------
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
# Line 205 | Line 230 | void Analysis::AddList(TList *list, Int_
230      AddFile(obj->GetName(), eventlist);
231   }
232  
233 < //__________________________________________________________________________________________________
233 > //--------------------------------------------------------------------------------------------------
234   void Analysis::AddLoader(TAMVirtualLoader *l)      
235   {
236    // Add loader to the list of loaders.
# Line 213 | Line 238 | void Analysis::AddLoader(TAMVirtualLoade
238    fLoaders->Add(l);
239   }
240  
241 < //__________________________________________________________________________________________________
241 > //--------------------------------------------------------------------------------------------------
242   void Analysis::AddPackage(const char* name)
243   {
244    // Add package to the list of uploaded packages.
# Line 222 | Line 247 | void Analysis::AddPackage(const char* na
247    fPackages->Add(new TObjString(name));
248   }
249  
250 < //__________________________________________________________________________________________________
250 > //--------------------------------------------------------------------------------------------------
251   void Analysis::AddPackages(TList *list)
252   {
253    // Add list of packages to the list of uploaded packages.
# Line 235 | Line 260 | void Analysis::AddPackages(TList *list)
260    }
261   }
262  
263 < //__________________________________________________________________________________________________
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
# Line 247 | Line 337 | Bool_t Analysis::Init()
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
# Line 269 | Line 364 | Bool_t Analysis::Init()
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) {
# Line 279 | Line 374 | Bool_t Analysis::Init()
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        }
# Line 307 | Line 402 | Bool_t Analysis::Init()
402  
403    }
404  
405 <  // if we had our default TAM plugin we would create it here
406 <  //  TreeLoader *bl = new TreeLoader;
407 <  //  fLoaders->Add(bl);
408 <  //  fDeleteList->Add(bl);
405 >  // create our customized loader plugin for TAM
406 >  TreeLoader *bl = new TreeLoader;
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) {
417 >    hltmod = new HLTFwkMod;
418 >    fDeleteList->Add(hltmod);
419 >  }
420  
421    if (fUseProof) {
422  
423 <    fProof->AddInput(fSuperMod);
423 >    fProof->AddInput(anamod);
424 >    if (hltmod)
425 >      fProof->AddInput(hltmod);
426 >
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  
# Line 322 | Line 438 | Bool_t Analysis::Init()
438  
439      // when not running Proof, we must make a selector
440      fSelector = new Selector;
441 <    fSelector->AddInput(fSuperMod);
441 >    fSelector->SetDoProxy(fDoProxy);
442 >
443 >    fSelector->AddInput(anamod);
444 >
445 >    if (hltmod)
446 >      fSelector->AddInput(hltmod);
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  
# Line 336 | Line 465 | Bool_t Analysis::Init()
465    return kTRUE;
466   }
467  
468 < //__________________________________________________________________________________________________
468 > //--------------------------------------------------------------------------------------------------
469   Bool_t Analysis::InitProof()
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      }
# Line 377 | Line 506 | Bool_t Analysis::InitProof()
506    return ret;
507   }
508  
509 < //__________________________________________________________________________________________________
509 > //--------------------------------------------------------------------------------------------------
510   void Analysis::Run()
511   {
512    // Run the analysis on the created file set.
# Line 408 | Line 537 | void Analysis::Run()
537    fState = kRun;
538   }
539  
540 < //__________________________________________________________________________________________________
540 > //--------------------------------------------------------------------------------------------------
541   Bool_t Analysis::Run(Bool_t browse)
542   {
543    // Execute analysis and open TBrowser if requested.
# Line 426 | Line 555 | Bool_t Analysis::Run(Bool_t browse)
555    return kFALSE;
556   }
557  
558 < //__________________________________________________________________________________________________
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.
# Line 455 | Line 592 | void Analysis::Terminate()
592        fOutput = fSelector->GetModOutput();
593      }
594  
595 +    
596 +
597      if (fOutput && !fAnaOutput.IsNull()) {
598        TDirectory::TContext context(0); // automatically restore gDirectory
599  
# Line 465 | Line 604 | void Analysis::Terminate()
604          MDB(kAnalysis, 1)
605            Info("Terminate", "Saving output to %s!", fAnaOutput.Data());
606  
607 <        if (fHierachy)
608 <          fOutput->Write(fOutput->GetName(),TObject::kSingleKey);      
607 >        if (fHierarchy)
608 >          fOutput->Write(0,-99);
609          else
610            fOutput->Write();
472              
611        }
612      }
613 +    // set state to terminate
614 +    fState = kTerminate;
615    }
616  
617    delete fChain;
618    delete fSet;
619    fDeleteList->Delete();
480
481  fState = kTerminate;
620   }
621  
622 < //__________________________________________________________________________________________________
622 > //--------------------------------------------------------------------------------------------------
623   Bool_t Analysis::UploadPackages(TList *packages)
624   {
625    // Upload list of par files to the server.
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) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines