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.7 by paus, Wed Jun 18 13:23:13 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines