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.16 by loizides, Mon Oct 6 17:01:21 2008 UTC

# Line 10 | Line 10
10   #include <TSystem.h>
11   #include <TProof.h>
12   #include <TROOT.h>
13 + #include <TBrowser.h>
14   #include "MitAna/DataUtil/interface/Debug.h"
15   #include "MitAna/DataTree/interface/Names.h"
16   #include "MitAna/TAM/interface/TAMVirtualLoader.h"
17   #include "MitAna/TAM/interface/TAModule.h"
18 < #include "MitAna/TAM/interface/TAMSelector.h"
18 > #include "MitAna/TreeMod/interface/Selector.h"
19 > #include "MitAna/TreeMod/interface/TreeLoader.h"
20 > #include "MitAna/TreeMod/interface/HLTFwkMod.h"
21 > #include "MitAna/Catalog/interface/Dataset.h"
22  
23   ClassImp(mithep::Analysis)
24  
25   using namespace mithep;
26  
27 < //__________________________________________________________________________________________________
28 < Analysis::Analysis(Bool_t up) :
29 <   fUseProof(up),
30 <   fHierachy(kTRUE),
31 <   fState(kPristine),
32 <   fNFriends(0),
33 <   fList(new TList),
34 <   fOutput(0),
35 <   fPackages(new TList),
36 <   fLoaders(new TList),
37 <   fSuperMod(0),
38 <   fSelector(0),
39 <   fChain(0),
40 <   fSet(0),
41 <   fDeleteList(new TList),
42 <   fTreeName(Names::gkMitTreeName),
43 <   fCompLevel(2),
44 <   fProof(0)
45 < {
46 <   // Default constructor.
47 <
48 <   fList->SetOwner();
49 <   fDeleteList->SetOwner();
50 <
51 <   /* default packages for PROOF upload */
52 <   fPackages->SetOwner();
53 <   // nothing to be done since we do not use par files (yet?)
27 > //--------------------------------------------------------------------------------------------------
28 > Analysis::Analysis(Bool_t useproof) :
29 >  fUseProof(useproof),
30 >  fUseHLT(kTRUE),
31 >  fHierarchy(kTRUE),
32 >  fDoProxy(kTRUE),
33 >  fState(kPristine),
34 >  fNFriends(0),
35 >  fList(new TList),
36 >  fOutput(0),
37 >  fPackages(new TList),
38 >  fLoaders(new TList),
39 >  fSuperMod(0),
40 >  fSelector(0),
41 >  fChain(0),
42 >  fSet(0),
43 >  fDeleteList(new TList),
44 >  fTreeName(Names::gkEvtTreeName),
45 >  fCompLevel(2),
46 >  fProof(0),
47 >  fDoNEvents(TChain::kBigNumber)
48 > {
49 >  // Default constructor.
50 >
51 >  fList->SetOwner();
52 >  fDeleteList->SetOwner();
53 >
54 >  /* default packages for PROOF upload */
55 >  fPackages->SetOwner();
56 >  // nothing to be done since we do not use par files (yet?)
57   }
58  
59 < //__________________________________________________________________________________________________
59 > //--------------------------------------------------------------------------------------------------
60   Analysis::~Analysis()
61   {
62 <   // Destructor.
62 >  // Destructor.
63  
64 <   if (fState == kInit || fState == kRun)
65 <      Terminate();
64 >  if (fState == kInit || fState == kRun)
65 >    Terminate();
66  
67 <   delete fList;
68 <   delete fDeleteList;
69 <   delete fLoaders;
70 <   delete fSelector;
71 <   delete fPackages;
72 <   fOutput   = 0;   // owned by TAM
73 <   fSuperMod = 0;   // owned by user
67 >  delete fList;
68 >  delete fPackages;
69 >  delete fLoaders;
70 >  delete fDeleteList;
71 >  delete fSelector;
72 >  fOutput   = 0;   // owned by TAM
73 >  fSuperMod = 0;   // owned by user
74  
75 <   delete fProof;
75 >  delete fProof;
76   }
77  
78 < //__________________________________________________________________________________________________
79 < Bool_t  Analysis::AddFile(const char *pname)
78 > //--------------------------------------------------------------------------------------------------
79 > Bool_t Analysis::AddFile(const char *pname)
80   {
81 <   // Add file with given name to the list of files to be processed.
82 <   // Using the token "|", you can specify an arbritray number
76 <   // of paths to tree files that will be concatenated as friend
77 <   // trees.
81 >  // Add file with given name to the list of files to be processed. Using the token "|", you can
82 >  // specify an arbritray number of paths to tree files that will be concatenated as friend trees.
83  
84 <   if (fState != kPristine) {
85 <      Error("AddFile", "Analysis already initialized");
86 <      return kFALSE;
87 <   }
84 >  if (fState != kPristine) {
85 >    Error("AddFile", "Analysis already initialized");
86 >    return kFALSE;
87 >  }
88  
89 <   TString pnamestr(pname);
90 <   TString tok("|");
91 <   TObjArray *arr = pnamestr.Tokenize(tok);
92 <   TString msg;
89 >  TString pnamestr(pname);
90 >  TString tok("|");
91 >  TObjArray *arr = pnamestr.Tokenize(tok);
92 >  TString msg;
93  
94 <   for(Int_t i=0; i<arr->GetEntries(); i++){
94 >  for(Int_t i=0; i<arr->GetEntries(); i++){
95        
96 <      TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i));
97 <      if(!dummy) continue;
96 >    TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i));
97 >    if(!dummy) continue;
98  
99 <      AddFile(dummy->GetName(),i);      
100 <      if(i==0) msg=dummy->GetName();
101 <      else {
102 <         Info("AddFile", "Add file %s as friend to %s",
103 <              dummy->GetName(), msg.Data());
104 <      }
105 <   }
106 <   delete arr;
99 >    AddFile(dummy->GetName(),i);      
100 >    if(i==0) msg=dummy->GetName();
101 >    else {
102 >      Info("AddFile", "Add file %s as friend to %s",
103 >           dummy->GetName(), msg.Data());
104 >    }
105 >  }
106 >  delete arr;
107  
108 <   return kTRUE;
108 >  return kTRUE;
109   }
110  
111 < //________________________________________________________________________
111 > //--------------------------------------------------------------------------------------------------
112   void Analysis::AddFile(const char *pname, Int_t eventlist)
113   {
114 <   // Add file name to the event list specified by eventlist. The lists
115 <   // are used to hold filenames of different types of events. In case
116 <   // you dont want friend trees, just give no eventlist argument (default 0).
114 >  // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
115 >  // different types of events. In case you dont want friend trees, just give no eventlist argument
116 >  // (default 0).
117  
118 <   MitAssert("AddFile", pname != 0);
118 >  MitAssert("AddFile", pname != 0);
119  
120 <   TList *l = 0;
121 <   if (eventlist >= 0 && eventlist < fNFriends) {
120 >  TList *l = 0;
121 >  if (eventlist >= 0 && eventlist < fNFriends) {
122        
123 <      l = dynamic_cast<TList*>(fList->At(eventlist));
124 <      if (!l) {
125 <         Fatal("AddFile", "Requested list %d not found!", eventlist);
126 <         return;
127 <      }
123 >    l = dynamic_cast<TList*>(fList->At(eventlist));
124 >    if (!l) {
125 >      Fatal("AddFile", "Requested list %d not found!", eventlist);
126 >      return;
127 >    }
128  
129 <   } else if (eventlist == fNFriends) {
129 >  } else if (eventlist == fNFriends) {
130        
131 <      l = new TList;
132 <      l->SetOwner();
133 <      fList->Add(l);
134 <      fNFriends++;
135 <
136 <   } else if (eventlist < 0 || eventlist > fNFriends) {
137 <      Error("AddFile", "Specified list %d not in [0,%d]", eventlist, fNFriends);
138 <      return;
139 <   }
131 >    l = new TList;
132 >    l->SetOwner();
133 >    fList->Add(l);
134 >    fNFriends++;
135 >
136 >  } else if (eventlist < 0 || eventlist > fNFriends) {
137 >    Error("AddFile", "Specified list %d not in [0,%d]", eventlist, fNFriends);
138 >    return;
139 >  }
140    
141 <   if(!IsValidName(pname)) return;
141 >  if(!IsValidName(pname)) return;
142  
143 <   l->Add(new TObjString(pname));
143 >  l->Add(new TObjString(pname));
144  
145 <   MDB(kAnalysis, 2)
146 <      Info("AddFile", "Added %s to list of files.", pname);
145 >  MDB(kAnalysis, 2)
146 >    Info("AddFile", "Added %s to list of files.", pname);
147   }
148  
149 < //__________________________________________________________________________________________________
149 > //--------------------------------------------------------------------------------------------------
150   void Analysis::AddFile(const TObject *oname, Int_t eventlist)
151   {
152 <   // Add file name to the event list specified by eventlist. The lists
153 <   // are used to hold filenames of  different types of events. In case
154 <   // you dont want mixing, just give no eventlist argument (default 0).
152 >  // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
153 >  // different types of events. In case you dont want mixing, just give no eventlist argument
154 >  // (default 0).
155 >
156 >  MitAssert("AddFile", oname != 0);
157 >
158 >  return AddFile(oname->GetName(), eventlist);
159 > }
160 >
161 > //________________________________________________________________________
162 > Bool_t Analysis::AddFiles(const char *pname, Int_t nmax)
163 > {
164 >  // Add files from text file with given name. If nmax>0, maximum nmax files will be added.
165 >
166 >  MitAssert("AddFiles", pname != 0);
167 >
168 >  ifstream in;
169 >  in.open(pname);
170 >  if (!in) {
171 >    Error("AddFiles", "Can not open file with name %s", pname);
172 >    return kFALSE;
173 >  }
174 >
175 >  Int_t fc = 0;
176 >  while (in) {
177 >    TString line;
178 >    line.ReadLine(in);
179 >    cout << line << endl;
180 >    if (!line.EndsWith(".root"))
181 >      continue;
182 >    cout << line << endl;
183 >
184 >    if (!AddFile(line)) {
185 >      Error("AddFiles", "Error adding file with name %s", line.Data());
186 >      return kFALSE;
187 >    }
188 >
189 >    ++fc;
190 >    if(nmax>0 && fc>=nmax) {
191 >      Info("AddFiles", "Maximal number (%d) of files added", nmax);
192 >      break;
193 >    }
194 >  }
195 >
196 >  return kTRUE;
197 > }
198 >
199 > //--------------------------------------------------------------------------------------------------
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 <   MitAssert("AddFile", oname != 0);
206 >  for (UInt_t i=0; i<dataset->NFiles(); i++)
207 >    status = (status && AddFile(dataset->FileUrl(i)));
208  
209 <   return AddFile(oname->GetName(), eventlist);
209 >  return status;
210   }
211  
212 < //__________________________________________________________________________________________________
212 > //--------------------------------------------------------------------------------------------------
213   void Analysis::AddList(TList *list, Int_t eventlist)
214   {
215 <   // Add file name to the event list specified by eventlist. The lists
216 <   // are used to hold filenames of  different types of events. In case
217 <   // you dont want mixing, just give no eventlist argument (default 0).
215 >  // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
216 >  // different types of events. In case you dont want mixing, just give no eventlist argument
217 >  // (default 0).
218  
219 <   MitAssert("AddList", list != 0);
219 >  MitAssert("AddList", list != 0);
220  
221 <   TIter next(list);                          
222 <   while (TObject *obj = next())                                
223 <      AddFile(obj->GetName(), eventlist);
221 >  TIter next(list);                          
222 >  while (TObject *obj = next())                                
223 >    AddFile(obj->GetName(), eventlist);
224   }
225  
226 < //__________________________________________________________________________________________________
226 > //--------------------------------------------------------------------------------------------------
227   void Analysis::AddLoader(TAMVirtualLoader *l)      
228   {
229 <   // Add loader to the list of loaders.
229 >  // Add loader to the list of loaders.
230  
231 <   fLoaders->Add(l);
231 >  fLoaders->Add(l);
232   }
233  
234 < //__________________________________________________________________________________________________
234 > //--------------------------------------------------------------------------------------------------
235   void Analysis::AddPackage(const char* name)
236   {
237 <   // Add package to the list of uploaded packages.
237 >  // Add package to the list of uploaded packages.
238  
239 <   MitAssert("AddPackage", name != 0);
240 <   fPackages->Add(new TObjString(name));
239 >  MitAssert("AddPackage", name != 0);
240 >  fPackages->Add(new TObjString(name));
241   }
242  
243 < //__________________________________________________________________________________________________
243 > //--------------------------------------------------------------------------------------------------
244   void Analysis::AddPackages(TList *list)
245   {
246 <   // Add list of packages to the list of uploaded packages.
246 >  // Add list of packages to the list of uploaded packages.
247  
248 <   MitAssert("AddPackage", list != 0);
248 >  MitAssert("AddPackage", list != 0);
249  
250 <   TIter next(list);
251 <   while (TObject *obj = next()) {
252 <      fPackages->Add(new TObjString(obj->GetName()));
253 <   }
250 >  TIter next(list);
251 >  while (TObject *obj = next()) {
252 >    fPackages->Add(new TObjString(obj->GetName()));
253 >  }
254   }
255  
256 < //__________________________________________________________________________________________________
256 > //--------------------------------------------------------------------------------------------------
257   Bool_t Analysis::Init()
258   {
259 <   // Setup the TDSet and TChain to be used for the analysis
260 <   // 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 <   }
259 >  // Setup the TDSet and TChain to be used for the analysis with or without PROOF. If more than one
260 >  // list of file names was given, friend trees are supported.
261  
262 <   if (fNFriends <= 0) {
263 <      Error("Init", "List of friend lists is empty!");
262 >  if (fState == kRun || fState == kInit) {
263 >    Error("Init", "Init in state %d is not possible! Call Terminate() first.",
264 >          Int_t(fState));
265 >    return kFALSE;
266 >  }
267 >
268 >  if (fNFriends <= 0) {
269 >    Error("Init", "List of friend lists is empty!");
270 >    return kFALSE;
271 >  }
272 >
273 >  if (!fSuperMod) {
274 >    Error("Init", "Top-level TAM module is NULL!");
275 >    return kFALSE;
276 >  }
277 >
278 >  if (fUseProof) { // first init our PROOF session
279 >    if (!InitProof()) return kFALSE;
280 >  }
281 >
282 >  // we do this here instead in Terminate() so that
283 >  // we can browse the output even after Terminate()
284 >  delete fSelector;
285 >  fSelector = 0;
286 >
287 >  fChain = new TChain(fTreeName);
288 >  fSet   = new TDSet("TTree",fTreeName);
289 >
290 >  for(Int_t i=0; i<fNFriends; i++){
291 >
292 >    TList *l = dynamic_cast<TList*>(fList->At(i));
293 >    if (!l) {
294 >      Fatal("Init", "List %d not found!", i);
295        return kFALSE;
296 <   }
296 >    }
297  
298 <   if (!fSuperMod) {
299 <      Error("Init", "Top-level TAM module is NULL!");
300 <      return kFALSE;
301 <   }
302 <
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;
298 >    if (i == 0) {
299 >      TIter next(l);                          
300 >      while ( TObjString *obj = dynamic_cast<TObjString*>(next()) ) {
301 >        fChain->Add(obj->GetName());
302 >        fSet->Add(obj->GetName());
303        }
304  
305 <      if (i == 0) {
305 >    } else {
306  
307 <         TIter next(l);                          
308 <         while ( TObjString *obj = dynamic_cast<TObjString*>(next()) ) {
247 <            fChain->Add(obj->GetName());
248 <            fSet->Add(obj->GetName());
249 <         }
307 >      TChain *chain = new TChain(fTreeName);
308 >      TDSet *set    = new TDSet("TTree",fTreeName);
309  
310 <      } else {
310 >      TIter next(l);                          
311 >      while (TObjString *obj = dynamic_cast<TObjString*>(next())) {
312 >        chain->Add(obj->GetName());
313 >        set->Add(obj->GetName());
314 >      }
315  
316 <         TChain *chain = new TChain(fTreeName);
317 <         TDSet *set    = new TDSet("TTree",fTreeName);
316 >      TString alias("TAMTREE_"); // aliases currently not used
317 >      alias+=i;
318  
319 <         TIter next(l);                          
320 <         while (TObjString *obj = dynamic_cast<TObjString*>(next())) {
258 <            chain->Add(obj->GetName());
259 <            set->Add(obj->GetName());
260 <         }
319 >      fChain->AddFriend(chain,alias.Data());
320 >      fSet->AddFriend(set,alias.Data());
321  
322 <         TString alias("TAMTREE_"); // aliases currently not used
323 <         alias+=i;
322 >      fDeleteList->Add(chain);
323 >      fDeleteList->Add(set);
324 >    }
325  
326 <         fChain->AddFriend(chain,alias.Data());
266 <         fSet->AddFriend(set,alias.Data());
326 >  }
327  
328 <         fDeleteList->Add(chain);
329 <         fDeleteList->Add(set);
330 <      }
328 >  // create our customized loader plugin for TAM
329 >  TreeLoader *bl = new TreeLoader;
330 >  fLoaders->Add(bl);
331 >  fDeleteList->Add(bl);
332  
333 <   }
333 >  // create our HLT framework module
334 >  HLTFwkMod *hltmod = 0;
335 >  if (fUseHLT) {
336 >    hltmod = new HLTFwkMod;
337 >    fDeleteList->Add(hltmod);
338 >  }
339  
340 <   // if we had our default TAM plugin we would create it here
275 <   //  TreeLoader *bl = new TreeLoader;
276 <   //  fLoaders->Add(bl);
277 <   //  fDeleteList->Add(bl);
340 >  if (fUseProof) {
341  
342 <   if (fUseProof) {
342 >    if (hltmod)
343 >      fProof->AddInput(hltmod);
344  
345 <      fProof->AddInput(fSuperMod);
346 <      fLoaders->SetName("TAM_LOADERS");
347 <      fProof->AddInput(fLoaders);      
345 >    fProof->AddInput(fSuperMod);
346 >    fLoaders->SetName("TAM_LOADERS");
347 >    fProof->AddInput(fLoaders);      
348  
349 <   } else {
349 >  } else {
350  
351 <      // when not running Proof, we must make a selector
352 <      fSelector = new TAMSelector;
353 <      fSelector->AddInput(fSuperMod);
354 <      MDB(kAnalysis, 2)
355 <         fSelector->SetVerbosity(1);
351 >    // when not running Proof, we must make a selector
352 >    fSelector = new Selector;
353 >    fSelector->SetDoProxy(fDoProxy);
354 >    if (hltmod)
355 >      fSelector->AddInput(hltmod);
356 >    fSelector->AddInput(fSuperMod);
357 >    MDB(kAnalysis, 2)
358 >      fSelector->SetVerbosity(1);
359  
360 <      // pass loaders to selector
361 <      TIter next(fLoaders);                          
362 <      while ( TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()) )
363 <         fSelector->AddLoader(l);
364 <   }
360 >    // pass loaders to selector
361 >    TIter next(fLoaders);                          
362 >    while ( TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()) )
363 >      fSelector->AddLoader(l);
364 >  }
365  
366 <   fState = kInit;
367 <   return kTRUE;
366 >  fState = kInit;
367 >  return kTRUE;
368   }
369  
370 < //__________________________________________________________________________________________________
370 > //--------------------------------------------------------------------------------------------------
371   Bool_t Analysis::InitProof()
372   {
373 <   // Initialize PROOF connection.
373 >  // Initialize PROOF connection.
374  
375 <   if(fProof && fProof->IsValid())
376 <      return kTRUE;
375 >  if(fProof && fProof->IsValid())
376 >    return kTRUE;
377  
378 <   delete fProof;
378 >  delete fProof;
379  
380 <   if (fMaster.Contains("rcf.bnl.gov")) {
381 <      for(Int_t i=0;i<5;i++) {
382 <         Warning("InitProof", "*** DID YOU RUN PROOF_KINIT? %d (5) ***", i);
383 <            gSystem->Sleep(1000);
384 <      }
385 <   }
380 >  if (fMaster.Contains("rcf.bnl.gov")) {
381 >    for(Int_t i=0;i<5;i++) {
382 >      Warning("InitProof", "*** DID YOU RUN PROOF_KINIT? %d (5) ***", i);
383 >      gSystem->Sleep(1000);
384 >    }
385 >  }
386  
387 <   MDB(kAnalysis, 1)
388 <      Info("InitProof", "Starting PROOF on master %s with config %s",
389 <           fMaster.Data(), fConfig.Data());
390 <
391 <   fProof = dynamic_cast<TProof*>(TProof::Open(fMaster, fConfig));
392 <   if (!fProof) {
393 <      Error("InitProof", "Could not start PROOF!");
394 <      return kFALSE;
395 <   }
387 >  MDB(kAnalysis, 1)
388 >    Info("InitProof", "Starting PROOF on master %s with config %s",
389 >         fMaster.Data(), fConfig.Data());
390 >
391 >  fProof = dynamic_cast<TProof*>(TProof::Open(fMaster, fConfig));
392 >  if (!fProof) {
393 >    Error("InitProof", "Could not start PROOF!");
394 >    return kFALSE;
395 >  }
396  
397 <   MDB(kAnalysis, 3)
398 <      gROOT->Print();
397 >  MDB(kAnalysis, 3)
398 >    gROOT->Print();
399  
400 <   //fProof->AddInput(new TNamed("PROOF_NewPacketizer",""));
400 >  //fProof->AddInput(new TNamed("PROOF_NewPacketizer",""));
401  
402 <   Bool_t ret=kTRUE;
403 <   if (fPackages) {
404 <      // tell Proof what additional libraries we will need on each worker computer
405 <      ret = UploadPackages(fPackages);
406 <   }
402 >  Bool_t ret=kTRUE;
403 >  if (fPackages) {
404 >    // tell Proof what additional libraries we will need on each worker computer
405 >    ret = UploadPackages(fPackages);
406 >  }
407  
408 <   return ret;
408 >  return ret;
409   }
410  
411 < //__________________________________________________________________________________________________
411 > //--------------------------------------------------------------------------------------------------
412   void Analysis::Run()
413   {
414 <   // Run the analysis on the created file set.
414 >  // Run the analysis on the created file set.
415  
416 <   if (fState == kPristine || fState == kRun) {
417 <      Error("Run", "Run in state %d is not possible! Call Init() first.",
418 <            Int_t(fState));
419 <   }
416 >  if (fState == kPristine || fState == kRun) {
417 >    Error("Run", "Run in state %d is not possible! Call Init() first.",
418 >          Int_t(fState));
419 >  }
420  
421 <   if (fUseProof) {
421 >  if (fUseProof) {
422  
423 <      MDB(kAnalysis, 1)
424 <         Info("Run", "Start processing with PROOF...");
423 >    MDB(kAnalysis, 1)
424 >      Info("Run", "Start processing with PROOF...");
425  
426 <      fSet->Process("TAMSelector");
426 >    fSet->Process("Selector","",fDoNEvents);
427  
428 <   } else {
428 >  } else {
429  
430 <      MDB(kAnalysis, 1)
431 <         Info("Run", "Start processing (no PROOF)...");
430 >    MDB(kAnalysis, 1)
431 >      Info("Run", "Start processing (no PROOF)...");
432  
433 <      fChain->Process(fSelector);
434 <   }
433 >    fChain->Process(fSelector,"",fDoNEvents);
434 >  }
435  
436 <   MDB(kAnalysis, 1)
437 <      Info("Run", "Processing complete!");
436 >  MDB(kAnalysis, 1)
437 >    Info("Run", "Processing complete!");
438  
439 <   fState = kRun;
439 >  fState = kRun;
440   }
441  
442 < //__________________________________________________________________________________________________
443 < void Analysis::Terminate()
442 > //--------------------------------------------------------------------------------------------------
443 > Bool_t Analysis::Run(Bool_t browse)
444   {
445 <   // Terminate current analysis run.
445 >  // Execute analysis and open TBrowser if requested.
446  
447 <   if (fState == kPristine || fState == kTerminate) {
448 <      Error("Terminate", "Terminate in state %d is not possible! Call Init() first.",
449 <            Int_t(fState));
450 <      return;
451 <   }
447 >  if (Init()) {
448 >    Run();
449 >    Terminate();
450 >    if (browse) {
451 >      new TBrowser;
452 >    }
453 >    return kTRUE;
454 >  }
455  
456 <   if (fState == kRun) {
456 >  Error("Execute", "Could not initialize analysis.");
457 >  return kFALSE;
458 > }
459  
460 <      if (fUseProof) {
461 <         // the output list from Proof can (in principal) contain other objects
462 <         // besides the module output hierarchy.
463 <         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 <         }
460 > //--------------------------------------------------------------------------------------------------
461 > void Analysis::Terminate()
462 > {
463 >  // Terminate current analysis run.
464  
465 +  if (fState == kPristine || fState == kTerminate) {
466 +    Error("Terminate", "Terminate in state %d is not possible! Call Init() first.",
467 +          Int_t(fState));
468 +    return;
469 +  }
470 +
471 +  if (fState == kRun) {
472 +
473 +    if (fUseProof) {
474 +      // the output list from Proof can (in principal) contain other objects
475 +      // besides the module output hierarchy.
476 +      TList* outputlist = fProof->GetOutputList();
477 +      TIter nextOut(outputlist);
478 +      while (TObject *obj = nextOut()) {
479 +        if (obj->InheritsFrom(TAMOutput::Class())) {
480 +          fOutput = dynamic_cast<TList*>(obj);
481 +          break;
482 +        }
483 +      }
484 +
485 +    } else {
486 +      fOutput = fSelector->GetModOutput();
487 +    }
488 +
489 +    if (fOutput && !fAnaOutput.IsNull()) {
490 +      TDirectory::TContext context(0); // automatically restore gDirectory
491 +
492 +      std::auto_ptr<TFile> outf(TFile::Open(fAnaOutput,"recreate","", fCompLevel));
493 +      if (outf.get() == 0) {
494 +        Error("Terminate", "Could not open file %s for output!", fAnaOutput.Data());
495        } else {
496 <         fOutput = fSelector->GetModOutput();
497 <      }
403 <
404 <      if (fOutput && !fAnaOutput.IsNull()) {
405 <         TDirectory::TContext context(0); // automatically restore gDirectory
496 >        MDB(kAnalysis, 1)
497 >          Info("Terminate", "Saving output to %s!", fAnaOutput.Data());
498  
499 <         std::auto_ptr<TFile> outf(TFile::Open(fAnaOutput,"recreate","", fCompLevel));
500 <         if (outf.get() == 0) {
501 <            Error("Terminate", "Could not open file %s for output!", fAnaOutput.Data());
502 <         } else {
411 <            MDB(kAnalysis, 1)
412 <               Info("Terminate", "Saving output to %s!", fAnaOutput.Data());
413 <
414 <            if (fHierachy)
415 <               fOutput->Write(fOutput->GetName(),TObject::kSingleKey);      
416 <            else
417 <               fOutput->Write();
499 >        if (fHierarchy)
500 >          fOutput->Write(fOutput->GetName(),TObject::kSingleKey);      
501 >        else
502 >          fOutput->Write();
503                
419         }
504        }
505 <   }
505 >    }
506 >  }
507  
508 <   delete fChain;
509 <   delete fSet;
510 <   fDeleteList->Delete();
426 <
427 <   fState = kTerminate;
508 >  delete fChain;
509 >  delete fSet;
510 >  fDeleteList->Delete();
511   }
512  
513 < //__________________________________________________________________________________________________
513 > //--------------------------------------------------------------------------------------------------
514   Bool_t Analysis::UploadPackages(TList *packages)
515   {
516 <   // Upload list of par files to the server.
434 <
435 <   MitAssert("UploadPackages", packages != 0);
516 >  // Upload list of par files to the server.
517  
518 <   for(Int_t i=0; i < packages->GetEntries(); i++) {
518 >  MitAssert("UploadPackages", packages != 0);
519  
520 <      TObject* objstr = packages->At(i);
440 <      if (!objstr){
441 <         Error("InitProof", "Problem at package number %d!", i);
442 <         return kFALSE;
443 <      }
520 >  for (Int_t i=0; i<packages->GetEntries(); i++) {
521  
522 <      TString packname = objstr->GetName();
523 <      Int_t en = 0;
524 <      if (packname.EndsWith("+")) {
525 <         en=1;
526 <         packname.Resize(packname.Length()-1);
450 <      }
522 >    TObject* objstr = packages->At(i);
523 >    if (!objstr) {
524 >      Error("InitProof", "Problem at package number %d!", i);
525 >      return kFALSE;
526 >    }
527  
528 <      ifstream ftest(gSystem->ExpandPathName(packname.Data()),ios_base::binary);
529 <      if (!ftest.good()){
530 <         Error("InitProof", "Could not open %s for upload!", packname.Data());
531 <         return kFALSE;
532 <      }
528 >    TString packname = objstr->GetName();
529 >    Int_t   en       = 0;
530 >    if (packname.EndsWith("+")) {
531 >      en=1;
532 >      packname.Resize(packname.Length()-1);
533 >    }
534 >
535 >    ifstream ftest(gSystem->ExpandPathName(packname.Data()),ios_base::binary);
536 >    if (!ftest.good()) {
537 >      Error("InitProof", "Could not open %s for upload!", packname.Data());
538 >      return kFALSE;
539 >    }
540  
541 <      if(fProof->UploadPackage(packname)<0) {
542 <         Error("UploadPackage", "Upload for %s failed!", packname.Data());
543 <         return kFALSE;
544 <      }
541 >    if (fProof->UploadPackage(packname)<0) {
542 >      Error("UploadPackage", "Upload for %s failed!", packname.Data());
543 >      return kFALSE;
544 >    }
545  
546 <      if (en == 1) {
547 <         Int_t pos=packname.Last('/')+1;
548 <         if (pos) packname.Remove(0,pos);
549 <         if(fProof->EnablePackage(packname)<0) {
550 <            Error("UploadPackage", "Enabling for %s failed!", packname.Data());
551 <            return kFALSE;
552 <         }
546 >    if (en == 1) {
547 >      Int_t pos=packname.Last('/')+1;
548 >      if (pos)
549 >        packname.Remove(0,pos);
550 >      if (fProof->EnablePackage(packname)<0) {
551 >        Error("UploadPackage", "Enabling for %s failed!", packname.Data());
552 >        return kFALSE;
553        }
554 <   }
554 >    }
555 >  }
556  
557 <   return kTRUE;
557 >  return kTRUE;
558   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines