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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines