ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/Analysis.cc
Revision: 1.37
Committed: Mon Oct 26 11:04:03 2009 UTC (15 years, 6 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012
Changes since 1.36: +1 -3 lines
Log Message:
Removed spurious printout

File Contents

# User Rev Content
1 loizides 1.37 // $Id: Analysis.cc,v 1.36 2009/08/11 15:24:39 loizides Exp $
2 loizides 1.1
3 loizides 1.9 #include "MitAna/TreeMod/interface/Analysis.h"
4 loizides 1.1 #include <Riostream.h>
5     #include <TFile.h>
6     #include <TList.h>
7     #include <TDSet.h>
8     #include <TChain.h>
9     #include <TObjString.h>
10     #include <TSystem.h>
11     #include <TProof.h>
12     #include <TROOT.h>
13 loizides 1.4 #include <TBrowser.h>
14 loizides 1.35 #include <TTreeCacheUnzip.h>
15 loizides 1.1 #include "MitAna/DataUtil/interface/Debug.h"
16 loizides 1.2 #include "MitAna/DataTree/interface/Names.h"
17 loizides 1.1 #include "MitAna/TAM/interface/TAMVirtualLoader.h"
18     #include "MitAna/TAM/interface/TAModule.h"
19 loizides 1.9 #include "MitAna/TreeMod/interface/Selector.h"
20 loizides 1.11 #include "MitAna/TreeMod/interface/TreeLoader.h"
21 loizides 1.18 #include "MitAna/TreeMod/interface/AnaFwkMod.h"
22 loizides 1.15 #include "MitAna/TreeMod/interface/HLTFwkMod.h"
23 loizides 1.22 #include "MitAna/Catalog/interface/Catalog.h"
24 paus 1.13 #include "MitAna/Catalog/interface/Dataset.h"
25 loizides 1.1
26     ClassImp(mithep::Analysis)
27    
28     using namespace mithep;
29    
30 loizides 1.12 //--------------------------------------------------------------------------------------------------
31 loizides 1.5 Analysis::Analysis(Bool_t useproof) :
32     fUseProof(useproof),
33 loizides 1.15 fUseHLT(kTRUE),
34 loizides 1.16 fHierarchy(kTRUE),
35 loizides 1.27 fDoProxy(kFALSE),
36     fDoObjTabClean(kTRUE),
37 loizides 1.35 fParallel(kFALSE),
38 loizides 1.5 fState(kPristine),
39     fNFriends(0),
40     fList(new TList),
41     fOutput(0),
42     fPackages(new TList),
43     fLoaders(new TList),
44 loizides 1.21 fSuperMods(new TList),
45 loizides 1.5 fSelector(0),
46     fChain(0),
47     fSet(0),
48     fDeleteList(new TList),
49 loizides 1.28 fCompLevel(7),
50 loizides 1.5 fProof(0),
51 bendavid 1.24 fDoNEvents(TChain::kBigNumber),
52 loizides 1.30 fSkipNEvents(0),
53 loizides 1.34 fPrintScale(1),
54 loizides 1.36 fCacheSize(-1),
55     fTreeName(Names::gkEvtTreeName),
56     fEvtHdrName(Names::gkEvtHeaderBrn),
57     fRunTreeName(Names::gkRunTreeName),
58     fRunInfoName(Names::gkRunInfoBrn),
59     fAllEvtHdrBrn(Names::gkAllEvtHeaderBrn),
60     fLATreeName(Names::gkLATreeName),
61     fLAHdrName(Names::gkLAHeaderBrn),
62     fHLTTreeName(Names::gkHltTreeName),
63     fAllEvtTreeName(Names::gkAllEvtTreeName),
64     fHLTObjsName(Names::gkHltObjBrn)
65 loizides 1.4 {
66     // Default constructor.
67    
68     fList->SetOwner();
69     fDeleteList->SetOwner();
70    
71     /* default packages for PROOF upload */
72     fPackages->SetOwner();
73     // nothing to be done since we do not use par files (yet?)
74 loizides 1.1 }
75    
76 loizides 1.12 //--------------------------------------------------------------------------------------------------
77 loizides 1.1 Analysis::~Analysis()
78     {
79 loizides 1.4 // Destructor.
80 loizides 1.1
81 loizides 1.4 if (fState == kInit || fState == kRun)
82     Terminate();
83 loizides 1.1
84 loizides 1.4 delete fList;
85 paus 1.7 delete fPackages;
86     delete fLoaders;
87 loizides 1.4 delete fDeleteList;
88     delete fSelector;
89 loizides 1.21 delete fSuperMods;
90 loizides 1.36 fOutput = 0; // owned by TAM
91 loizides 1.1
92 loizides 1.4 delete fProof;
93 loizides 1.1 }
94    
95 loizides 1.12 //--------------------------------------------------------------------------------------------------
96 loizides 1.22 Bool_t Analysis::AddDataset(const Dataset *dataset)
97     {
98     // Add a full dataset to the analysis.
99    
100     Bool_t status = true;
101    
102     for (UInt_t i=0; i<dataset->NFiles(); ++i)
103     status = (status && AddFile(dataset->FileUrl(i)));
104    
105     return status;
106     }
107    
108     //--------------------------------------------------------------------------------------------------
109 loizides 1.5 Bool_t Analysis::AddFile(const char *pname)
110 loizides 1.1 {
111 paus 1.7 // Add file with given name to the list of files to be processed. Using the token "|", you can
112     // specify an arbritray number of paths to tree files that will be concatenated as friend trees.
113 loizides 1.4
114     if (fState != kPristine) {
115     Error("AddFile", "Analysis already initialized");
116     return kFALSE;
117     }
118    
119     TString pnamestr(pname);
120 loizides 1.22 if (pnamestr.IsNull())
121     return kFALSE;
122    
123 loizides 1.4 TString tok("|");
124     TObjArray *arr = pnamestr.Tokenize(tok);
125 loizides 1.22 if (!arr)
126     return kFALSE;
127    
128 loizides 1.4 TString msg;
129 loizides 1.22 for (Int_t i=0; i<arr->GetEntries(); ++i) {
130    
131 loizides 1.4 TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i));
132 loizides 1.22 if (!dummy)
133     continue;
134 loizides 1.1
135 loizides 1.4 AddFile(dummy->GetName(),i);
136 loizides 1.22 if (i==0)
137     msg=dummy->GetName();
138     else
139     Info("AddFile", "Add file %s as friend to %s", dummy->GetName(), msg.Data());
140 loizides 1.4 }
141     delete arr;
142 loizides 1.1
143 loizides 1.4 return kTRUE;
144 loizides 1.1 }
145    
146 loizides 1.12 //--------------------------------------------------------------------------------------------------
147 loizides 1.1 void Analysis::AddFile(const char *pname, Int_t eventlist)
148     {
149 paus 1.7 // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
150     // different types of events. In case you dont want friend trees, just give no eventlist argument
151     // (default 0).
152 loizides 1.1
153 loizides 1.4 MitAssert("AddFile", pname != 0);
154 loizides 1.1
155 loizides 1.4 TList *l = 0;
156     if (eventlist >= 0 && eventlist < fNFriends) {
157 loizides 1.1
158 loizides 1.4 l = dynamic_cast<TList*>(fList->At(eventlist));
159     if (!l) {
160     Fatal("AddFile", "Requested list %d not found!", eventlist);
161     return;
162     }
163 loizides 1.1
164 loizides 1.4 } else if (eventlist == fNFriends) {
165 loizides 1.1
166 loizides 1.4 l = new TList;
167     l->SetOwner();
168     fList->Add(l);
169 loizides 1.22 ++fNFriends;
170 loizides 1.4
171     } else if (eventlist < 0 || eventlist > fNFriends) {
172     Error("AddFile", "Specified list %d not in [0,%d]", eventlist, fNFriends);
173     return;
174     }
175 loizides 1.1
176 loizides 1.19 if (!IsValidName(pname)) return;
177 loizides 1.1
178 loizides 1.4 l->Add(new TObjString(pname));
179 loizides 1.1
180 loizides 1.4 MDB(kAnalysis, 2)
181     Info("AddFile", "Added %s to list of files.", pname);
182 loizides 1.1 }
183    
184 loizides 1.12 //--------------------------------------------------------------------------------------------------
185 loizides 1.1 void Analysis::AddFile(const TObject *oname, Int_t eventlist)
186     {
187 paus 1.7 // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
188     // different types of events. In case you dont want mixing, just give no eventlist argument
189     // (default 0).
190 loizides 1.1
191 loizides 1.4 MitAssert("AddFile", oname != 0);
192 loizides 1.1
193 loizides 1.4 return AddFile(oname->GetName(), eventlist);
194 loizides 1.1 }
195    
196 loizides 1.5 //________________________________________________________________________
197     Bool_t Analysis::AddFiles(const char *pname, Int_t nmax)
198     {
199 paus 1.7 // Add files from text file with given name. If nmax>0, maximum nmax files will be added.
200 loizides 1.5
201     MitAssert("AddFiles", pname != 0);
202    
203     ifstream in;
204     in.open(pname);
205     if (!in) {
206 loizides 1.31 Error("AddFiles", "Cannot open file with name %s", pname);
207 loizides 1.5 return kFALSE;
208     }
209    
210     Int_t fc = 0;
211     while (in) {
212     TString line;
213     line.ReadLine(in);
214     if (!line.EndsWith(".root"))
215     continue;
216    
217     if (!AddFile(line)) {
218     Error("AddFiles", "Error adding file with name %s", line.Data());
219     return kFALSE;
220     }
221    
222     ++fc;
223 loizides 1.19 if (nmax>0 && fc>=nmax) {
224 loizides 1.5 Info("AddFiles", "Maximal number (%d) of files added", nmax);
225     break;
226     }
227     }
228    
229     return kTRUE;
230     }
231    
232 loizides 1.12 //--------------------------------------------------------------------------------------------------
233 loizides 1.1 void Analysis::AddList(TList *list, Int_t eventlist)
234     {
235 paus 1.7 // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
236     // different types of events. In case you dont want mixing, just give no eventlist argument
237     // (default 0).
238 loizides 1.4
239     MitAssert("AddList", list != 0);
240    
241     TIter next(list);
242     while (TObject *obj = next())
243     AddFile(obj->GetName(), eventlist);
244 loizides 1.1 }
245    
246 loizides 1.12 //--------------------------------------------------------------------------------------------------
247 loizides 1.1 void Analysis::AddLoader(TAMVirtualLoader *l)
248     {
249 loizides 1.4 // Add loader to the list of loaders.
250 loizides 1.1
251 loizides 1.4 fLoaders->Add(l);
252 loizides 1.1 }
253    
254 loizides 1.12 //--------------------------------------------------------------------------------------------------
255 loizides 1.1 void Analysis::AddPackage(const char* name)
256     {
257 loizides 1.4 // Add package to the list of uploaded packages.
258 loizides 1.1
259 loizides 1.4 MitAssert("AddPackage", name != 0);
260     fPackages->Add(new TObjString(name));
261 loizides 1.1 }
262    
263 loizides 1.12 //--------------------------------------------------------------------------------------------------
264 loizides 1.1 void Analysis::AddPackages(TList *list)
265     {
266 loizides 1.4 // Add list of packages to the list of uploaded packages.
267 loizides 1.1
268 loizides 1.4 MitAssert("AddPackage", list != 0);
269 loizides 1.1
270 loizides 1.4 TIter next(list);
271     while (TObject *obj = next()) {
272     fPackages->Add(new TObjString(obj->GetName()));
273     }
274 loizides 1.1 }
275    
276 loizides 1.12 //--------------------------------------------------------------------------------------------------
277 loizides 1.21 void Analysis::AddSuperModule(TAModule *mod)
278     {
279     // Add a top-level module to list of top-level (super) modules.
280    
281     fSuperMods->Add(mod);
282     }
283    
284     //--------------------------------------------------------------------------------------------------
285 loizides 1.22 void Analysis::FileInputFromEnv()
286     {
287     // Attempt to get list of filesets/files from environment.
288    
289     TString catalog(gSystem->Getenv("MIT_CATALOG"));
290     TString book(gSystem->Getenv("MIT_BOOK"));
291     TString dataset(gSystem->Getenv("MIT_DATASET"));
292     TString filesets(gSystem->Getenv("MIT_FILESETS"));
293     TString files(gSystem->Getenv("MIT_FILES"));
294    
295     if ((catalog.IsNull() || book.IsNull() || dataset.IsNull()) && files.IsNull()) {
296     Warning("FileInputFromEnv", "Called to get file info from environment, but did not get"
297 loizides 1.23 " consistent set of variables:\n\tMIT_CATALOG=%s\n\tMIT_BOOK=%s\n\t"
298 loizides 1.22 "MIT_DATASET=%s\n\tMIT_FILESETS=%s\n\tMIT_FILES=%s\n",
299     catalog.Data(), book.Data(), dataset.Data(), filesets.Data(), files.Data());
300     return;
301     }
302    
303     if (!files.IsNull()) { // add local files
304     Info("FileInputFromEnv", "Got from environment:\n"
305     "\n\tMIT_FILES=%s\n", files.Data());
306     TString tok(";");
307     TObjArray *arr = files.Tokenize(tok);
308     if (arr) {
309     for (Int_t i=0; i<arr->GetEntries(); ++i) {
310     TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i));
311     if (!dummy) continue;
312     AddFile(dummy->GetName(),0);
313     }
314     delete arr;
315     }
316     return;
317     }
318    
319     Info("FileInputFromEnv", "Got from environment:\n"
320 loizides 1.23 "\tMIT_CATALOG=%s\n\tMIT_BOOK=%s\n\tMIT_DATASET=%s\n\tMIT_FILESETS=%s\n",
321 loizides 1.22 catalog.Data(), book.Data(), dataset.Data(), filesets.Data());
322    
323     Catalog cat(catalog);
324 loizides 1.25 if (filesets.IsNull()) {
325     Dataset *d = cat.FindDataset(book, dataset);
326     if (d) {
327 loizides 1.22 AddDataset(d);
328     delete d;
329     }
330 loizides 1.25 } else {
331     TString tok(";");
332     TObjArray *arr = filesets.Tokenize(tok);
333     if (arr) {
334     for (Int_t i=0; i<arr->GetEntries(); ++i) {
335     TObjString *fileset = dynamic_cast<TObjString*>(arr->At(i));
336     if (!fileset) continue;
337     Dataset *d = cat.FindDataset(book, dataset, fileset->String());
338     if (!d)
339     continue;
340     AddDataset(d);
341     delete d;
342     }
343     delete arr;
344     }
345 loizides 1.22 }
346     }
347    
348     //--------------------------------------------------------------------------------------------------
349 loizides 1.1 Bool_t Analysis::Init()
350     {
351 paus 1.7 // Setup the TDSet and TChain to be used for the analysis with or without PROOF. If more than one
352     // list of file names was given, friend trees are supported.
353 loizides 1.4
354     if (fState == kRun || fState == kInit) {
355     Error("Init", "Init in state %d is not possible! Call Terminate() first.",
356     Int_t(fState));
357     return kFALSE;
358     }
359    
360 loizides 1.22 // check if we should attempt to get filesets/filenames from environment
361     if (fNFriends == 0)
362     FileInputFromEnv();
363    
364 loizides 1.4 if (fNFriends <= 0) {
365     Error("Init", "List of friend lists is empty!");
366     return kFALSE;
367     }
368    
369 loizides 1.21 if (!fSuperMods->First()) {
370 loizides 1.4 Error("Init", "Top-level TAM module is NULL!");
371     return kFALSE;
372     }
373    
374     if (fUseProof) { // first init our PROOF session
375 loizides 1.22 if (!InitProof())
376     return kFALSE;
377 loizides 1.4 }
378    
379     // we do this here instead in Terminate() so that
380     // we can browse the output even after Terminate()
381     delete fSelector;
382     fSelector = 0;
383    
384     fChain = new TChain(fTreeName);
385     fSet = new TDSet("TTree",fTreeName);
386    
387 loizides 1.22 for (Int_t i=0; i<fNFriends; ++i) {
388 loizides 1.4 TList *l = dynamic_cast<TList*>(fList->At(i));
389     if (!l) {
390     Fatal("Init", "List %d not found!", i);
391 loizides 1.1 return kFALSE;
392 loizides 1.4 }
393    
394     if (i == 0) {
395     TIter next(l);
396 loizides 1.22 while (TObjString *obj = dynamic_cast<TObjString*>(next())) {
397 loizides 1.4 fChain->Add(obj->GetName());
398     fSet->Add(obj->GetName());
399 loizides 1.32 if (fCacheSize<0 && obj->GetString().Contains("/castor/"))
400 loizides 1.30 fCacheSize = 64*1024*1024;
401 loizides 1.4 }
402     } else {
403     TChain *chain = new TChain(fTreeName);
404     TDSet *set = new TDSet("TTree",fTreeName);
405 loizides 1.1
406 loizides 1.4 TIter next(l);
407     while (TObjString *obj = dynamic_cast<TObjString*>(next())) {
408     chain->Add(obj->GetName());
409     set->Add(obj->GetName());
410 loizides 1.32 if (fCacheSize<0 && obj->GetString().Contains("/castor/"))
411 loizides 1.30 fCacheSize = 64*1024*1024;
412 loizides 1.1 }
413    
414 loizides 1.4 TString alias("TAMTREE_"); // aliases currently not used
415     alias+=i;
416 loizides 1.1
417 loizides 1.4 fChain->AddFriend(chain,alias.Data());
418     fSet->AddFriend(set,alias.Data());
419 loizides 1.1
420 loizides 1.4 fDeleteList->Add(chain);
421     fDeleteList->Add(set);
422     }
423 loizides 1.30 }
424 loizides 1.1
425 loizides 1.35 if (fParallel)
426     TTreeCacheUnzip::SetParallelUnzip(TTreeCacheUnzip::kEnable);
427    
428     if (fCacheSize>=0)
429 loizides 1.30 fChain->SetCacheSize(fCacheSize);
430 loizides 1.1
431 loizides 1.11 // create our customized loader plugin for TAM
432     TreeLoader *bl = new TreeLoader;
433     fLoaders->Add(bl);
434     fDeleteList->Add(bl);
435 loizides 1.1
436 loizides 1.18 // create our ana framework module
437     AnaFwkMod *anamod = new AnaFwkMod;
438 loizides 1.30 anamod->SetSkipNEvents(fSkipNEvents);
439 loizides 1.33 anamod->SetPrintScale(fPrintScale);
440 loizides 1.18 fDeleteList->Add(anamod);
441    
442 loizides 1.15 // create our HLT framework module
443     HLTFwkMod *hltmod = 0;
444     if (fUseHLT) {
445     hltmod = new HLTFwkMod;
446 loizides 1.36 hltmod->SetHLTObjsName(GetHLTObjsName());
447     hltmod->SetHLTTreeName(GetHLTTreeName());
448 loizides 1.15 fDeleteList->Add(hltmod);
449     }
450    
451 loizides 1.4 if (fUseProof) {
452 loizides 1.1
453 loizides 1.18 fProof->AddInput(anamod);
454 loizides 1.15 if (hltmod)
455     fProof->AddInput(hltmod);
456    
457 loizides 1.21 TIter iter(fSuperMods->MakeIterator());
458     while (1) {
459     TAModule *next = dynamic_cast<TAModule*>(iter.Next());
460     if (!next) break;
461     fProof->AddInput(next);
462     }
463    
464 loizides 1.4 fLoaders->SetName("TAM_LOADERS");
465     fProof->AddInput(fLoaders);
466 loizides 1.1
467 loizides 1.4 } else {
468 loizides 1.1
469 loizides 1.4 // when not running Proof, we must make a selector
470 loizides 1.36 Selector *sel = new Selector;
471     sel->SetDoProxy(fDoProxy);
472     sel->SetDoObjTabClean(fDoObjTabClean);
473     sel->SetDoRunInfo(kTRUE);
474     sel->SetAllEvtHdrBrn(GetAllEvtHdrBrn());
475     sel->SetAllEvtTreeName(GetAllEvtTreeName());
476     sel->SetEvtHdrName(GetEvtHdrName());
477     sel->SetLAHdrName(GetLAHdrName());
478     sel->SetLATreeName(GetLATreeName());
479     sel->SetRunInfoName(GetRunInfoName());
480     sel->SetRunTreeName(GetRunTreeName());
481     sel->AddInput(anamod);
482     fSelector = sel;
483 loizides 1.18
484 loizides 1.15 if (hltmod)
485     fSelector->AddInput(hltmod);
486 loizides 1.21
487     TIter iter(fSuperMods->MakeIterator());
488     while (1) {
489     TAModule *next = dynamic_cast<TAModule*>(iter.Next());
490     if (!next) break;
491     fSelector->AddInput(next);
492     }
493    
494 loizides 1.4 MDB(kAnalysis, 2)
495     fSelector->SetVerbosity(1);
496 loizides 1.1
497 loizides 1.4 // pass loaders to selector
498     TIter next(fLoaders);
499 loizides 1.22 while (TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()))
500 loizides 1.4 fSelector->AddLoader(l);
501     }
502 loizides 1.1
503 loizides 1.4 fState = kInit;
504     return kTRUE;
505 loizides 1.1 }
506    
507 loizides 1.12 //--------------------------------------------------------------------------------------------------
508 loizides 1.1 Bool_t Analysis::InitProof()
509     {
510 loizides 1.4 // Initialize PROOF connection.
511 loizides 1.1
512 loizides 1.19 if (fProof && fProof->IsValid())
513 loizides 1.4 return kTRUE;
514 loizides 1.1
515 loizides 1.4 delete fProof;
516 loizides 1.1
517 loizides 1.4 if (fMaster.Contains("rcf.bnl.gov")) {
518 loizides 1.22 for (Int_t i=0; i<5; ++i) {
519 loizides 1.4 Warning("InitProof", "*** DID YOU RUN PROOF_KINIT? %d (5) ***", i);
520     gSystem->Sleep(1000);
521     }
522     }
523    
524     MDB(kAnalysis, 1)
525     Info("InitProof", "Starting PROOF on master %s with config %s",
526     fMaster.Data(), fConfig.Data());
527    
528     fProof = dynamic_cast<TProof*>(TProof::Open(fMaster, fConfig));
529     if (!fProof) {
530     Error("InitProof", "Could not start PROOF!");
531     return kFALSE;
532     }
533    
534     MDB(kAnalysis, 3)
535     gROOT->Print();
536    
537     //fProof->AddInput(new TNamed("PROOF_NewPacketizer",""));
538    
539     Bool_t ret=kTRUE;
540     if (fPackages) {
541     // tell Proof what additional libraries we will need on each worker computer
542     ret = UploadPackages(fPackages);
543     }
544 loizides 1.1
545 loizides 1.4 return ret;
546 loizides 1.1 }
547    
548 loizides 1.12 //--------------------------------------------------------------------------------------------------
549 loizides 1.1 void Analysis::Run()
550     {
551 loizides 1.4 // Run the analysis on the created file set.
552 loizides 1.1
553 loizides 1.4 if (fState == kPristine || fState == kRun) {
554     Error("Run", "Run in state %d is not possible! Call Init() first.",
555     Int_t(fState));
556     }
557 loizides 1.1
558 loizides 1.4 if (fUseProof) {
559 loizides 1.1
560 loizides 1.4 MDB(kAnalysis, 1)
561     Info("Run", "Start processing with PROOF...");
562 loizides 1.1
563 loizides 1.9 fSet->Process("Selector","",fDoNEvents);
564 loizides 1.1
565 loizides 1.4 } else {
566 loizides 1.1
567 loizides 1.4 MDB(kAnalysis, 1)
568     Info("Run", "Start processing (no PROOF)...");
569 loizides 1.1
570 loizides 1.29 fChain->Process(fSelector,"",fDoNEvents);
571 loizides 1.4 }
572 loizides 1.1
573 loizides 1.4 MDB(kAnalysis, 1)
574     Info("Run", "Processing complete!");
575 loizides 1.1
576 loizides 1.4 fState = kRun;
577 loizides 1.1 }
578    
579 loizides 1.12 //--------------------------------------------------------------------------------------------------
580 loizides 1.4 Bool_t Analysis::Run(Bool_t browse)
581 loizides 1.1 {
582 loizides 1.4 // Execute analysis and open TBrowser if requested.
583 loizides 1.1
584 loizides 1.4 if (Init()) {
585     Run();
586     Terminate();
587 paus 1.7 if (browse) {
588 loizides 1.4 new TBrowser;
589     }
590     return kTRUE;
591     }
592 loizides 1.1
593 loizides 1.4 Error("Execute", "Could not initialize analysis.");
594     return kFALSE;
595     }
596 loizides 1.1
597 loizides 1.12 //--------------------------------------------------------------------------------------------------
598 loizides 1.21 void Analysis::SetSuperModule(TAModule *mod)
599     {
600     // Set the first top-level module in the list of top-level (super) modules.
601    
602     fSuperMods->AddFirst(mod);
603     }
604    
605     //--------------------------------------------------------------------------------------------------
606 loizides 1.4 void Analysis::Terminate()
607     {
608     // Terminate current analysis run.
609 loizides 1.1
610 loizides 1.4 if (fState == kPristine || fState == kTerminate) {
611     Error("Terminate", "Terminate in state %d is not possible! Call Init() first.",
612     Int_t(fState));
613     return;
614     }
615    
616     if (fState == kRun) {
617    
618     if (fUseProof) {
619     // the output list from Proof can (in principal) contain other objects
620     // besides the module output hierarchy.
621     TList* outputlist = fProof->GetOutputList();
622     TIter nextOut(outputlist);
623     while (TObject *obj = nextOut()) {
624     if (obj->InheritsFrom(TAMOutput::Class())) {
625     fOutput = dynamic_cast<TList*>(obj);
626     break;
627     }
628     }
629    
630     } else {
631     fOutput = fSelector->GetModOutput();
632     }
633    
634 loizides 1.20
635    
636 loizides 1.4 if (fOutput && !fAnaOutput.IsNull()) {
637     TDirectory::TContext context(0); // automatically restore gDirectory
638    
639     std::auto_ptr<TFile> outf(TFile::Open(fAnaOutput,"recreate","", fCompLevel));
640     if (outf.get() == 0) {
641     Error("Terminate", "Could not open file %s for output!", fAnaOutput.Data());
642 loizides 1.1 } else {
643 loizides 1.4 MDB(kAnalysis, 1)
644     Info("Terminate", "Saving output to %s!", fAnaOutput.Data());
645 loizides 1.1
646 loizides 1.16 if (fHierarchy)
647 loizides 1.20 fOutput->Write(0,-99);
648 loizides 1.4 else
649     fOutput->Write();
650 loizides 1.1 }
651 loizides 1.4 }
652 loizides 1.17 // set state to terminate
653     fState = kTerminate;
654 loizides 1.4 }
655 loizides 1.1
656 loizides 1.4 delete fChain;
657     delete fSet;
658     fDeleteList->Delete();
659 loizides 1.1 }
660    
661 loizides 1.12 //--------------------------------------------------------------------------------------------------
662 loizides 1.1 Bool_t Analysis::UploadPackages(TList *packages)
663     {
664 loizides 1.4 // Upload list of par files to the server.
665 loizides 1.1
666 loizides 1.4 MitAssert("UploadPackages", packages != 0);
667 loizides 1.1
668 loizides 1.22 for (Int_t i=0; i<packages->GetEntries(); ++i) {
669 loizides 1.1
670 loizides 1.4 TObject* objstr = packages->At(i);
671 paus 1.7 if (!objstr) {
672 loizides 1.4 Error("InitProof", "Problem at package number %d!", i);
673     return kFALSE;
674     }
675 loizides 1.1
676 loizides 1.4 TString packname = objstr->GetName();
677 paus 1.7 Int_t en = 0;
678 loizides 1.4 if (packname.EndsWith("+")) {
679     en=1;
680     packname.Resize(packname.Length()-1);
681     }
682    
683     ifstream ftest(gSystem->ExpandPathName(packname.Data()),ios_base::binary);
684 paus 1.7 if (!ftest.good()) {
685 loizides 1.4 Error("InitProof", "Could not open %s for upload!", packname.Data());
686     return kFALSE;
687     }
688 loizides 1.1
689 paus 1.7 if (fProof->UploadPackage(packname)<0) {
690 loizides 1.4 Error("UploadPackage", "Upload for %s failed!", packname.Data());
691     return kFALSE;
692     }
693 loizides 1.1
694 loizides 1.4 if (en == 1) {
695     Int_t pos=packname.Last('/')+1;
696 paus 1.7 if (pos)
697     packname.Remove(0,pos);
698     if (fProof->EnablePackage(packname)<0) {
699 loizides 1.4 Error("UploadPackage", "Enabling for %s failed!", packname.Data());
700     return kFALSE;
701 loizides 1.1 }
702 loizides 1.4 }
703     }
704 loizides 1.1
705 loizides 1.4 return kTRUE;
706 loizides 1.1 }