ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/Analysis.cc
Revision: 1.43
Committed: Tue Mar 29 01:35:08 2011 UTC (14 years, 1 month ago) by paus
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_025c_branch2, Mit_025c_branch1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1
Branch point for: Mit_025c_branch
Changes since 1.42: +8 -8 lines
Log Message:
Bug fix in FileUrl -- found by Guillelmo et al.

File Contents

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