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.3 by loizides, Thu Jun 5 07:54:21 2008 UTC vs.
Revision 1.38 by bendavid, Sun Jan 24 21:00:19 2010 UTC

# Line 1 | Line 1
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>
# Line 10 | Line 11
11   #include <TSystem.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"
19   #include "MitAna/TAM/interface/TAModule.h"
20 < #include "MitAna/TAM/interface/TAMSelector.h"
20 > #include "MitAna/TreeMod/interface/Selector.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)
28  
29   using namespace mithep;
30  
31 < //__________________________________________________________________________________________________
32 < Analysis::Analysis(Bool_t up) :
33 <   fUseProof(up),
34 <   fHierachy(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),
42 <   fSelector(0),
43 <   fChain(0),
44 <   fSet(0),
45 <   fDeleteList(new TList),
46 <   fTreeName(Names::gkMitTreeName),
47 <   fCompLevel(2),
48 <   fProof(0)
49 < {
50 <   // Default constructor.
51 <
52 <   fList->SetOwner();
53 <   fDeleteList->SetOwner();
54 <
55 <   /* default packages for PROOF upload */
56 <   fPackages->SetOwner();
57 <   // nothing to be done since we do not use par files (yet?)
31 > //--------------------------------------------------------------------------------------------------
32 > Analysis::Analysis(Bool_t useproof) :
33 >  fUseProof(useproof),
34 >  fUseHLT(kTRUE),
35 >  fHierarchy(kTRUE),
36 >  fDoProxy(kFALSE),
37 >  fDoObjTabClean(kTRUE),
38 >  fParallel(kFALSE),
39 >  fState(kPristine),
40 >  fNFriends(0),
41 >  fList(new TList),
42 >  fOutput(0),
43 >  fPackages(new TList),
44 >  fLoaders(new TList),
45 >  fSuperMods(new TList),
46 >  fSelector(0),
47 >  fChain(0),
48 >  fSet(0),
49 >  fDeleteList(new TList),
50 >  fCompLevel(7),
51 >  fProof(0),
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 >
69 >  fList->SetOwner();
70 >  fDeleteList->SetOwner();
71 >
72 >  /* default packages for PROOF upload */
73 >  fPackages->SetOwner();
74 >  // nothing to be done since we do not use par files (yet?)
75   }
76  
77 < //__________________________________________________________________________________________________
77 > //--------------------------------------------------------------------------------------------------
78   Analysis::~Analysis()
79   {
80 <   // Destructor.
80 >  // Destructor.
81  
82 <   if (fState == kInit || fState == kRun)
83 <      Terminate();
82 >  if (fState == kInit || fState == kRun)
83 >    Terminate();
84  
85 <   delete fList;
86 <   delete fDeleteList;
87 <   delete fLoaders;
88 <   delete fSelector;
89 <   delete fPackages;
90 <   fOutput   = 0;   // owned by TAM
91 <   fSuperMod = 0;   // owned by user
85 >  delete fList;
86 >  delete fPackages;
87 >  delete fLoaders;
88 >  delete fDeleteList;
89 >  delete fSelector;
90 >  delete fSuperMods;
91 >  fOutput = 0;   // owned by TAM
92  
93 <   delete fProof;
93 >  delete fProof;
94   }
95  
96 < //__________________________________________________________________________________________________
97 < Bool_t  Analysis::AddFile(const char *pname)
96 > //--------------------------------------------------------------------------------------------------
97 > Bool_t Analysis::AddDataset(const Dataset *dataset)
98   {
99 <   // Add file with given name to the list of files to be processed.
75 <   // Using the token "|", you can specify an arbritray number
76 <   // of paths to tree files that will be concatenated as friend
77 <   // trees.
99 >  // Add a full dataset to the analysis.
100  
101 <   if (fState != kPristine) {
80 <      Error("AddFile", "Analysis already initialized");
81 <      return kFALSE;
82 <   }
101 >  Bool_t status = true;
102  
103 <   TString pnamestr(pname);
104 <   TString tok("|");
86 <   TObjArray *arr = pnamestr.Tokenize(tok);
87 <   TString msg;
103 >  for (UInt_t i=0; i<dataset->NFiles(); ++i)
104 >    status = (status && AddFile(dataset->FileUrl(i)));
105  
106 <   for(Int_t i=0; i<arr->GetEntries(); i++){
107 <      
91 <      TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i));
92 <      if(!dummy) continue;
106 >  return status;
107 > }
108  
109 <      AddFile(dummy->GetName(),i);      
110 <      if(i==0) msg=dummy->GetName();
111 <      else {
112 <         Info("AddFile", "Add file %s as friend to %s",
113 <              dummy->GetName(), msg.Data());
114 <      }
115 <   }
116 <   delete arr;
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
113 >  // specify an arbritray number of paths to tree files that will be concatenated as friend trees.
114 >
115 >  if (fState != kPristine) {
116 >    Error("AddFile", "Analysis already initialized");
117 >    return kFALSE;
118 >  }
119 >
120 >  TString pnamestr(pname);
121 >  if (pnamestr.IsNull())
122 >    return kFALSE;
123 >
124 >  TString tok("|");
125 >  TObjArray *arr = pnamestr.Tokenize(tok);
126 >  if (!arr)
127 >    return kFALSE;
128 >
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)
134 >      continue;
135 >
136 >    AddFile(dummy->GetName(),i);      
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  
144 <   return kTRUE;
144 >  return kTRUE;
145   }
146  
147 < //________________________________________________________________________
147 > //--------------------------------------------------------------------------------------------------
148   void Analysis::AddFile(const char *pname, Int_t eventlist)
149   {
150 <   // Add file name to the event list specified by eventlist. The lists
151 <   // are used to hold filenames of different types of events. In case
152 <   // you dont want friend trees, just give no eventlist argument (default 0).
150 >  // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
151 >  // different types of events. In case you dont want friend trees, just give no eventlist argument
152 >  // (default 0).
153  
154 <   MitAssert("AddFile", pname != 0);
154 >  MitAssert("AddFile", pname != 0);
155  
156 <   TList *l = 0;
157 <   if (eventlist >= 0 && eventlist < fNFriends) {
156 >  TList *l = 0;
157 >  if (eventlist >= 0 && eventlist < fNFriends) {
158        
159 <      l = dynamic_cast<TList*>(fList->At(eventlist));
160 <      if (!l) {
161 <         Fatal("AddFile", "Requested list %d not found!", eventlist);
162 <         return;
163 <      }
159 >    l = dynamic_cast<TList*>(fList->At(eventlist));
160 >    if (!l) {
161 >      Fatal("AddFile", "Requested list %d not found!", eventlist);
162 >      return;
163 >    }
164  
165 <   } else if (eventlist == fNFriends) {
165 >  } else if (eventlist == fNFriends) {
166        
167 <      l = new TList;
168 <      l->SetOwner();
169 <      fList->Add(l);
170 <      fNFriends++;
171 <
172 <   } else if (eventlist < 0 || eventlist > fNFriends) {
173 <      Error("AddFile", "Specified list %d not in [0,%d]", eventlist, fNFriends);
174 <      return;
175 <   }
167 >    l = new TList;
168 >    l->SetOwner();
169 >    fList->Add(l);
170 >    ++fNFriends;
171 >
172 >  } else if (eventlist < 0 || eventlist > fNFriends) {
173 >    Error("AddFile", "Specified list %d not in [0,%d]", eventlist, fNFriends);
174 >    return;
175 >  }
176    
177 <   if(!IsValidName(pname)) return;
177 >  if (!IsValidName(pname)) return;
178  
179 <   l->Add(new TObjString(pname));
179 >  l->Add(new TObjString(pname));
180  
181 <   MDB(kAnalysis, 2)
182 <      Info("AddFile", "Added %s to list of files.", pname);
181 >  MDB(kAnalysis, 2)
182 >    Info("AddFile", "Added %s to list of files.", pname);
183   }
184  
185 < //__________________________________________________________________________________________________
185 > //--------------------------------------------------------------------------------------------------
186   void Analysis::AddFile(const TObject *oname, Int_t eventlist)
187   {
188 <   // Add file name to the event list specified by eventlist. The lists
189 <   // are used to hold filenames of  different types of events. In case
190 <   // you dont want mixing, just give no eventlist argument (default 0).
188 >  // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
189 >  // different types of events. In case you dont want mixing, just give no eventlist argument
190 >  // (default 0).
191  
192 <   MitAssert("AddFile", oname != 0);
192 >  MitAssert("AddFile", oname != 0);
193  
194 <   return AddFile(oname->GetName(), eventlist);
194 >  return AddFile(oname->GetName(), eventlist);
195   }
196  
197 < //__________________________________________________________________________________________________
197 > //________________________________________________________________________
198 > Bool_t Analysis::AddFiles(const char *pname, Int_t nmax)
199 > {
200 >  // Add files from text file with given name. If nmax>0, maximum nmax files will be added.
201 >
202 >  MitAssert("AddFiles", pname != 0);
203 >
204 >  ifstream in;
205 >  in.open(pname);
206 >  if (!in) {
207 >    Error("AddFiles", "Cannot open file with name %s", pname);
208 >    return kFALSE;
209 >  }
210 >
211 >  Int_t fc = 0;
212 >  while (in) {
213 >    TString line;
214 >    line.ReadLine(in);
215 >    if (!line.EndsWith(".root"))
216 >      continue;
217 >
218 >    if (!AddFile(line)) {
219 >      Error("AddFiles", "Error adding file with name %s", line.Data());
220 >      return kFALSE;
221 >    }
222 >
223 >    ++fc;
224 >    if (nmax>0 && fc>=nmax) {
225 >      Info("AddFiles", "Maximal number (%d) of files added", nmax);
226 >      break;
227 >    }
228 >  }
229 >
230 >  return kTRUE;
231 > }
232 >
233 > //--------------------------------------------------------------------------------------------------
234   void Analysis::AddList(TList *list, Int_t eventlist)
235   {
236 <   // Add file name to the event list specified by eventlist. The lists
237 <   // are used to hold filenames of  different types of events. In case
238 <   // you dont want mixing, just give no eventlist argument (default 0).
236 >  // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
237 >  // different types of events. In case you dont want mixing, just give no eventlist argument
238 >  // (default 0).
239  
240 <   MitAssert("AddList", list != 0);
240 >  MitAssert("AddList", list != 0);
241  
242 <   TIter next(list);                          
243 <   while (TObject *obj = next())                                
244 <      AddFile(obj->GetName(), eventlist);
242 >  TIter next(list);                          
243 >  while (TObject *obj = next())                                
244 >    AddFile(obj->GetName(), eventlist);
245   }
246  
247 < //__________________________________________________________________________________________________
247 > //--------------------------------------------------------------------------------------------------
248   void Analysis::AddLoader(TAMVirtualLoader *l)      
249   {
250 <   // Add loader to the list of loaders.
250 >  // Add loader to the list of loaders.
251  
252 <   fLoaders->Add(l);
252 >  fLoaders->Add(l);
253   }
254  
255 < //__________________________________________________________________________________________________
255 > //--------------------------------------------------------------------------------------------------
256   void Analysis::AddPackage(const char* name)
257   {
258 <   // Add package to the list of uploaded packages.
258 >  // Add package to the list of uploaded packages.
259  
260 <   MitAssert("AddPackage", name != 0);
261 <   fPackages->Add(new TObjString(name));
260 >  MitAssert("AddPackage", name != 0);
261 >  fPackages->Add(new TObjString(name));
262   }
263  
264 < //__________________________________________________________________________________________________
264 > //--------------------------------------------------------------------------------------------------
265   void Analysis::AddPackages(TList *list)
266   {
267 <   // Add list of packages to the list of uploaded packages.
267 >  // Add list of packages to the list of uploaded packages.
268  
269 <   MitAssert("AddPackage", list != 0);
269 >  MitAssert("AddPackage", list != 0);
270  
271 <   TIter next(list);
272 <   while (TObject *obj = next()) {
273 <      fPackages->Add(new TObjString(obj->GetName()));
274 <   }
271 >  TIter next(list);
272 >  while (TObject *obj = next()) {
273 >    fPackages->Add(new TObjString(obj->GetName()));
274 >  }
275   }
276  
277 < //__________________________________________________________________________________________________
278 < Bool_t Analysis::Init()
279 < {
280 <   // Setup the TDSet and TChain to be used for the analysis
204 <   // with or without PROOF. If more than one list of
205 <   // file names was given, friend trees are supported.
206 <
207 <   if (fState == kRun || fState == kInit) {
208 <      Error("Init", "Init in state %d is not possible! Call Terminate() first.",
209 <            Int_t(fState));
210 <      return kFALSE;
211 <   }
212 <
213 <   if (fNFriends <= 0) {
214 <      Error("Init", "List of friend lists is empty!");
215 <      return kFALSE;
216 <   }
217 <
218 <   if (!fSuperMod) {
219 <      Error("Init", "Top-level TAM module is NULL!");
220 <      return kFALSE;
221 <   }
222 <
223 <   if (fUseProof) { // first init our PROOF session
224 <      if (!InitProof()) return kFALSE;
225 <   }
226 <
227 <   // we do this here instead in Terminate() so that
228 <   // we can browse the output even after Terminate()
229 <   delete fSelector;
230 <   fSelector = 0;
231 <
232 <   fChain = new TChain(fTreeName);
233 <   fSet   = new TDSet("TTree",fTreeName);
234 <
235 <   for(Int_t i=0; i<fNFriends; i++){
236 <
237 <      TList *l = dynamic_cast<TList*>(fList->At(i));
238 <      if (!l) {
239 <         Fatal("Init", "List %d not found!", i);
240 <         return kFALSE;
241 <      }
242 <
243 <      if (i == 0) {
244 <
245 <         TIter next(l);                          
246 <         while ( TObjString *obj = dynamic_cast<TObjString*>(next()) ) {
247 <            fChain->Add(obj->GetName());
248 <            fSet->Add(obj->GetName());
249 <         }
250 <
251 <      } else {
252 <
253 <         TChain *chain = new TChain(fTreeName);
254 <         TDSet *set    = new TDSet("TTree",fTreeName);
255 <
256 <         TIter next(l);                          
257 <         while (TObjString *obj = dynamic_cast<TObjString*>(next())) {
258 <            chain->Add(obj->GetName());
259 <            set->Add(obj->GetName());
260 <         }
277 > //--------------------------------------------------------------------------------------------------
278 > void Analysis::AddSuperModule(TAModule *mod)
279 > {
280 >  // Add a top-level module to list of top-level (super) modules.
281  
282 <         TString alias("TAMTREE_"); // aliases currently not used
283 <         alias+=i;
282 >  fSuperMods->Add(mod);      
283 > }
284  
285 <         fChain->AddFriend(chain,alias.Data());
286 <         fSet->AddFriend(set,alias.Data());
285 > //--------------------------------------------------------------------------------------------------
286 > void Analysis::FileInputFromEnv()
287 > {
288 >  // Attempt to get list of filesets/files from environment.
289  
290 <         fDeleteList->Add(chain);
291 <         fDeleteList->Add(set);
292 <      }
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 <   }
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 we had our default TAM plugin we would create it here
305 <   //  TreeLoader *bl = new TreeLoader;
306 <   //  fLoaders->Add(bl);
307 <   //  fDeleteList->Add(bl);
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 <   if (fUseProof) {
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
353 >  // list of file names was given, friend trees are supported.
354  
355 <      fProof->AddInput(fSuperMod);
356 <      fLoaders->SetName("TAM_LOADERS");
357 <      fProof->AddInput(fLoaders);      
355 >  if (fState == kRun || fState == kInit) {
356 >    Error("Init", "Init in state %d is not possible! Call Terminate() first.",
357 >          Int_t(fState));
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;
368 >  }
369 >
370 >  if (!fSuperMods->First()) {
371 >    Error("Init", "Top-level TAM module is NULL!");
372 >    return kFALSE;
373 >  }
374  
375 <   } else {
375 >  if (fUseProof) { // first init our PROOF session
376 >    if (!InitProof())
377 >      return kFALSE;
378 >  }
379  
380 <      // when not running Proof, we must make a selector
381 <      fSelector = new TAMSelector;
382 <      fSelector->AddInput(fSuperMod);
383 <      MDB(kAnalysis, 2)
384 <         fSelector->SetVerbosity(1);
380 >  // we do this here instead in Terminate() so that
381 >  // we can browse the output even after Terminate()
382 >  delete fSelector;
383 >  fSelector = 0;
384 >
385 >  fChain = new TChain(fTreeName);
386 >  fSet   = new TDSet("TTree",fTreeName);
387 >
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);
392 >      return kFALSE;
393 >    }
394  
395 <      // pass loaders to selector
396 <      TIter next(fLoaders);                          
397 <      while ( TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()) )
398 <         fSelector->AddLoader(l);
399 <   }
395 >    if (i == 0) {
396 >      TIter next(l);                          
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 >      }
403 >    } else {
404 >      TChain *chain = new TChain(fTreeName);
405 >      TDSet *set    = new TDSet("TTree",fTreeName);
406 >
407 >      TIter next(l);                          
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
416 >      alias+=i;
417 >
418 >      fChain->AddFriend(chain,alias.Data());
419 >      fSet->AddFriend(set,alias.Data());
420 >
421 >      fDeleteList->Add(chain);
422 >      fDeleteList->Add(set);
423 >    }
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);
435 >  fDeleteList->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 >
452 >  if (fUseProof) {
453 >
454 >    fProof->AddInput(anamod);
455 >    if (hltmod)
456 >      fProof->AddInput(hltmod);
457 >
458 >    TIter iter(fSuperMods->MakeIterator());
459 >    while (1) {
460 >      TAModule *next = dynamic_cast<TAModule*>(iter.Next());
461 >      if (!next) break;
462 >      fProof->AddInput(next);
463 >    }
464 >
465 >    fLoaders->SetName("TAM_LOADERS");
466 >    fProof->AddInput(fLoaders);      
467 >
468 >  } else {
469 >
470 >    // when not running Proof, we must make a selector
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);
487 >
488 >    TIter iter(fSuperMods->MakeIterator());
489 >    while (1) {
490 >      TAModule *next = dynamic_cast<TAModule*>(iter.Next());
491 >      if (!next) break;
492 >      fSelector->AddInput(next);
493 >    }
494 >
495 >    MDB(kAnalysis, 2)
496 >      fSelector->SetVerbosity(1);
497 >
498 >    // pass loaders to selector
499 >    TIter next(fLoaders);                          
500 >    while (TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()))
501 >      fSelector->AddLoader(l);
502 >  }
503  
504 <   fState = kInit;
505 <   return kTRUE;
504 >  fState = kInit;
505 >  return kTRUE;
506   }
507  
508 < //__________________________________________________________________________________________________
508 > //--------------------------------------------------------------------------------------------------
509   Bool_t Analysis::InitProof()
510   {
511 <   // Initialize PROOF connection.
511 >  // Initialize PROOF connection.
512  
513 <   if(fProof && fProof->IsValid())
514 <      return kTRUE;
513 >  if (fProof && fProof->IsValid())
514 >    return kTRUE;
515  
516 <   delete fProof;
516 >  delete fProof;
517  
518 <   if (fMaster.Contains("rcf.bnl.gov")) {
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 <      }
523 <   }
518 >  if (fMaster.Contains("rcf.bnl.gov")) {
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 >    }
523 >  }
524  
525 <   MDB(kAnalysis, 1)
526 <      Info("InitProof", "Starting PROOF on master %s with config %s",
527 <           fMaster.Data(), fConfig.Data());
528 <
529 <   fProof = dynamic_cast<TProof*>(TProof::Open(fMaster, fConfig));
530 <   if (!fProof) {
531 <      Error("InitProof", "Could not start PROOF!");
532 <      return kFALSE;
533 <   }
525 >  MDB(kAnalysis, 1)
526 >    Info("InitProof", "Starting PROOF on master %s with config %s",
527 >         fMaster.Data(), fConfig.Data());
528 >
529 >  fProof = dynamic_cast<TProof*>(TProof::Open(fMaster, fConfig));
530 >  if (!fProof) {
531 >    Error("InitProof", "Could not start PROOF!");
532 >    return kFALSE;
533 >  }
534  
535 <   MDB(kAnalysis, 3)
536 <      gROOT->Print();
535 >  MDB(kAnalysis, 3)
536 >    gROOT->Print();
537  
538 <   //fProof->AddInput(new TNamed("PROOF_NewPacketizer",""));
538 >  //fProof->AddInput(new TNamed("PROOF_NewPacketizer",""));
539  
540 <   Bool_t ret=kTRUE;
541 <   if (fPackages) {
542 <      // tell Proof what additional libraries we will need on each worker computer
543 <      ret = UploadPackages(fPackages);
544 <   }
540 >  Bool_t ret=kTRUE;
541 >  if (fPackages) {
542 >    // tell Proof what additional libraries we will need on each worker computer
543 >    ret = UploadPackages(fPackages);
544 >  }
545  
546 <   return ret;
546 >  return ret;
547   }
548  
549 < //__________________________________________________________________________________________________
549 > //--------------------------------------------------------------------------------------------------
550   void Analysis::Run()
551   {
552 <   // Run the analysis on the created file set.
552 >  // Run the analysis on the created file set.
553  
554 <   if (fState == kPristine || fState == kRun) {
555 <      Error("Run", "Run in state %d is not possible! Call Init() first.",
556 <            Int_t(fState));
557 <   }
554 >  if (fState == kPristine || fState == kRun) {
555 >    Error("Run", "Run in state %d is not possible! Call Init() first.",
556 >          Int_t(fState));
557 >  }
558  
559 <   if (fUseProof) {
559 >  if (fUseProof) {
560  
561 <      MDB(kAnalysis, 1)
562 <         Info("Run", "Start processing with PROOF...");
561 >    MDB(kAnalysis, 1)
562 >      Info("Run", "Start processing with PROOF...");
563  
564 <      fSet->Process("TAMSelector");
564 >    fSet->Process("Selector","",fDoNEvents);
565  
566 <   } else {
566 >  } else {
567  
568 <      MDB(kAnalysis, 1)
569 <         Info("Run", "Start processing (no PROOF)...");
568 >    MDB(kAnalysis, 1)
569 >      Info("Run", "Start processing (no PROOF)...");
570  
571 <      fChain->Process(fSelector);
572 <   }
571 >    fChain->Process(fSelector,"",fDoNEvents);
572 >  }
573  
574 <   MDB(kAnalysis, 1)
575 <      Info("Run", "Processing complete!");
574 >  MDB(kAnalysis, 1)
575 >    Info("Run", "Processing complete!");
576  
577 <   fState = kRun;
577 >  fState = kRun;
578   }
579  
580 < //__________________________________________________________________________________________________
581 < void Analysis::Terminate()
580 > //--------------------------------------------------------------------------------------------------
581 > Bool_t Analysis::Run(Bool_t browse)
582   {
583 <   // Terminate current analysis run.
583 >  // Execute analysis and open TBrowser if requested.
584  
585 <   if (fState == kPristine || fState == kTerminate) {
586 <      Error("Terminate", "Terminate in state %d is not possible! Call Init() first.",
587 <            Int_t(fState));
588 <      return;
589 <   }
585 >  if (Init()) {
586 >    Run();
587 >    Terminate();
588 >    if (browse) {
589 >      new TBrowser;
590 >    }
591 >    return kTRUE;
592 >  }
593  
594 <   if (fState == kRun) {
594 >  Error("Execute", "Could not initialize analysis.");
595 >  return kFALSE;
596 > }
597  
598 <      if (fUseProof) {
599 <         // the output list from Proof can (in principal) contain other objects
600 <         // besides the module output hierarchy.
601 <         TList* outputlist = fProof->GetOutputList();
392 <         TIter nextOut(outputlist);
393 <         while (TObject *obj = nextOut()) {
394 <            if (obj->InheritsFrom(TAMOutput::Class())) {
395 <               fOutput = dynamic_cast<TList*>(obj);
396 <               break;
397 <            }
398 <         }
598 > //--------------------------------------------------------------------------------------------------
599 > void Analysis::SetSuperModule(TAModule *mod)
600 > {
601 >  // Set the first top-level module in the list of top-level (super) modules.
602  
603 <      } else {
604 <         fOutput = fSelector->GetModOutput();
402 <      }
603 >  fSuperMods->AddFirst(mod);      
604 > }
605  
606 <      if (fOutput && !fAnaOutput.IsNull()) {
607 <         TDirectory::TContext context(0); // automatically restore gDirectory
606 > //--------------------------------------------------------------------------------------------------
607 > void Analysis::Terminate()
608 > {
609 >  // Terminate current analysis run.
610  
611 <         std::auto_ptr<TFile> outf(TFile::Open(fAnaOutput,"recreate","", fCompLevel));
612 <         if (outf.get() == 0) {
613 <            Error("Terminate", "Could not open file %s for output!", fAnaOutput.Data());
614 <         } else {
615 <            MDB(kAnalysis, 1)
616 <               Info("Terminate", "Saving output to %s!", fAnaOutput.Data());
617 <
618 <            if (fHierachy)
619 <               fOutput->Write(fOutput->GetName(),TObject::kSingleKey);      
620 <            else
621 <               fOutput->Write();
622 <              
623 <         }
624 <      }
625 <   }
611 >  if (fState == kPristine || fState == kTerminate) {
612 >    Error("Terminate", "Terminate in state %d is not possible! Call Init() first.",
613 >          Int_t(fState));
614 >    return;
615 >  }
616 >
617 >  if (fState == kRun) {
618 >
619 >    if (fUseProof) {
620 >      // the output list from Proof can (in principal) contain other objects
621 >      // besides the module output hierarchy.
622 >      TList* outputlist = fProof->GetOutputList();
623 >      TIter nextOut(outputlist);
624 >      while (TObject *obj = nextOut()) {
625 >        if (obj->InheritsFrom(TAMOutput::Class())) {
626 >          fOutput = dynamic_cast<TList*>(obj);
627 >          break;
628 >        }
629 >      }
630 >
631 >    } else {
632 >      fOutput = fSelector->GetModOutput();
633 >    }
634 >
635 >    
636 >
637 >    if (fOutput && !fAnaOutput.IsNull()) {
638 >      TDirectory::TContext context(0); // automatically restore gDirectory
639 >
640 >      std::auto_ptr<TFile> outf(TFile::Open(fAnaOutput,"recreate","", fCompLevel));
641 >      if (outf.get() == 0) {
642 >        Error("Terminate", "Could not open file %s for output!", fAnaOutput.Data());
643 >      } else {
644 >        MDB(kAnalysis, 1)
645 >          Info("Terminate", "Saving output to %s!", fAnaOutput.Data());
646  
647 <   delete fChain;
648 <   delete fSet;
649 <   fDeleteList->Delete();
647 >        if (fHierarchy)
648 >          fOutput->Write(0,-99);
649 >        else
650 >          fOutput->Write();
651 >      }
652 >    }
653 >    // set state to terminate
654 >    fState = kTerminate;
655 >  }
656  
657 <   fState = kTerminate;
657 >  delete fChain;
658 >  delete fSet;
659 >  fDeleteList->Delete();
660   }
661  
662 < //__________________________________________________________________________________________________
662 > //--------------------------------------------------------------------------------------------------
663   Bool_t Analysis::UploadPackages(TList *packages)
664   {
665 <   // Upload list of par files to the server.
434 <
435 <   MitAssert("UploadPackages", packages != 0);
665 >  // Upload list of par files to the server.
666  
667 <   for(Int_t i=0; i < packages->GetEntries(); i++) {
667 >  MitAssert("UploadPackages", packages != 0);
668  
669 <      TObject* objstr = packages->At(i);
440 <      if (!objstr){
441 <         Error("InitProof", "Problem at package number %d!", i);
442 <         return kFALSE;
443 <      }
669 >  for (Int_t i=0; i<packages->GetEntries(); ++i) {
670  
671 <      TString packname = objstr->GetName();
672 <      Int_t en = 0;
673 <      if (packname.EndsWith("+")) {
674 <         en=1;
675 <         packname.Resize(packname.Length()-1);
450 <      }
671 >    TObject* objstr = packages->At(i);
672 >    if (!objstr) {
673 >      Error("InitProof", "Problem at package number %d!", i);
674 >      return kFALSE;
675 >    }
676  
677 <      ifstream ftest(gSystem->ExpandPathName(packname.Data()),ios_base::binary);
678 <      if (!ftest.good()){
679 <         Error("InitProof", "Could not open %s for upload!", packname.Data());
680 <         return kFALSE;
681 <      }
677 >    TString packname = objstr->GetName();
678 >    Int_t   en       = 0;
679 >    if (packname.EndsWith("+")) {
680 >      en=1;
681 >      packname.Resize(packname.Length()-1);
682 >    }
683 >
684 >    ifstream ftest(gSystem->ExpandPathName(packname.Data()),ios_base::binary);
685 >    if (!ftest.good()) {
686 >      Error("InitProof", "Could not open %s for upload!", packname.Data());
687 >      return kFALSE;
688 >    }
689  
690 <      if(fProof->UploadPackage(packname)<0) {
691 <         Error("UploadPackage", "Upload for %s failed!", packname.Data());
692 <         return kFALSE;
693 <      }
690 >    if (fProof->UploadPackage(packname)<0) {
691 >      Error("UploadPackage", "Upload for %s failed!", packname.Data());
692 >      return kFALSE;
693 >    }
694  
695 <      if (en == 1) {
696 <         Int_t pos=packname.Last('/')+1;
697 <         if (pos) packname.Remove(0,pos);
698 <         if(fProof->EnablePackage(packname)<0) {
699 <            Error("UploadPackage", "Enabling for %s failed!", packname.Data());
700 <            return kFALSE;
701 <         }
695 >    if (en == 1) {
696 >      Int_t pos=packname.Last('/')+1;
697 >      if (pos)
698 >        packname.Remove(0,pos);
699 >      if (fProof->EnablePackage(packname)<0) {
700 >        Error("UploadPackage", "Enabling for %s failed!", packname.Data());
701 >        return kFALSE;
702        }
703 <   }
703 >    }
704 >  }
705  
706 <   return kTRUE;
706 >  return kTRUE;
707   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines