ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/Analysis.cc
Revision: 1.45
Committed: Sat Sep 29 11:26:40 2012 UTC (12 years, 7 months ago) by ceballos
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a
Changes since 1.44: +7 -3 lines
Log Message:
using root://castorcms

File Contents

# User Rev Content
1 ceballos 1.45 // $Id: Analysis.cc,v 1.44 2012/07/23 15:47:24 ceballos 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 ceballos 1.45 //if ( theFile.BeginsWith("castor:") )
189     // theFile.ReplaceAll("castor:","rfio:");
190     //if ( theFile.BeginsWith("/castor/"))
191     // theFile.ReplaceAll("/castor/","rfio:/castor/");
192 bendavid 1.39 if ( theFile.BeginsWith("castor:") )
193 ceballos 1.45 theFile.ReplaceAll("castor:","root://castorcms/");
194 bendavid 1.39 if ( theFile.BeginsWith("/castor/"))
195 ceballos 1.45 theFile.Prepend("root://castorcms/");
196 bendavid 1.39 printf("Adding file with path: %s\n",theFile.Data());
197 paus 1.41 l->Add(new TObjString(theFile.Data()));
198 loizides 1.1
199 loizides 1.4 MDB(kAnalysis, 2)
200     Info("AddFile", "Added %s to list of files.", pname);
201 loizides 1.1 }
202    
203 loizides 1.12 //--------------------------------------------------------------------------------------------------
204 loizides 1.1 void Analysis::AddFile(const TObject *oname, Int_t eventlist)
205     {
206 paus 1.7 // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
207     // different types of events. In case you dont want mixing, just give no eventlist argument
208     // (default 0).
209 loizides 1.1
210 loizides 1.4 MitAssert("AddFile", oname != 0);
211 loizides 1.1
212 loizides 1.4 return AddFile(oname->GetName(), eventlist);
213 loizides 1.1 }
214    
215 loizides 1.5 //________________________________________________________________________
216     Bool_t Analysis::AddFiles(const char *pname, Int_t nmax)
217     {
218 paus 1.7 // Add files from text file with given name. If nmax>0, maximum nmax files will be added.
219 loizides 1.5
220     MitAssert("AddFiles", pname != 0);
221    
222     ifstream in;
223     in.open(pname);
224     if (!in) {
225 loizides 1.31 Error("AddFiles", "Cannot open file with name %s", pname);
226 loizides 1.5 return kFALSE;
227     }
228    
229     Int_t fc = 0;
230     while (in) {
231     TString line;
232     line.ReadLine(in);
233     if (!line.EndsWith(".root"))
234     continue;
235    
236     if (!AddFile(line)) {
237     Error("AddFiles", "Error adding file with name %s", line.Data());
238     return kFALSE;
239     }
240    
241     ++fc;
242 loizides 1.19 if (nmax>0 && fc>=nmax) {
243 loizides 1.5 Info("AddFiles", "Maximal number (%d) of files added", nmax);
244     break;
245     }
246     }
247    
248     return kTRUE;
249     }
250    
251 loizides 1.12 //--------------------------------------------------------------------------------------------------
252 loizides 1.1 void Analysis::AddList(TList *list, Int_t eventlist)
253     {
254 paus 1.7 // Add file name to the event list specified by eventlist. The lists are used to hold filenames of
255     // different types of events. In case you dont want mixing, just give no eventlist argument
256     // (default 0).
257 loizides 1.4
258     MitAssert("AddList", list != 0);
259    
260     TIter next(list);
261     while (TObject *obj = next())
262     AddFile(obj->GetName(), eventlist);
263 loizides 1.1 }
264    
265 loizides 1.12 //--------------------------------------------------------------------------------------------------
266 loizides 1.1 void Analysis::AddLoader(TAMVirtualLoader *l)
267     {
268 loizides 1.4 // Add loader to the list of loaders.
269 loizides 1.1
270 loizides 1.4 fLoaders->Add(l);
271 loizides 1.1 }
272    
273 loizides 1.12 //--------------------------------------------------------------------------------------------------
274 loizides 1.1 void Analysis::AddPackage(const char* name)
275     {
276 loizides 1.4 // Add package to the list of uploaded packages.
277 loizides 1.1
278 loizides 1.4 MitAssert("AddPackage", name != 0);
279     fPackages->Add(new TObjString(name));
280 loizides 1.1 }
281    
282 loizides 1.12 //--------------------------------------------------------------------------------------------------
283 loizides 1.1 void Analysis::AddPackages(TList *list)
284     {
285 loizides 1.4 // Add list of packages to the list of uploaded packages.
286 loizides 1.1
287 loizides 1.4 MitAssert("AddPackage", list != 0);
288 loizides 1.1
289 loizides 1.4 TIter next(list);
290     while (TObject *obj = next()) {
291     fPackages->Add(new TObjString(obj->GetName()));
292     }
293 loizides 1.1 }
294    
295 loizides 1.12 //--------------------------------------------------------------------------------------------------
296 loizides 1.21 void Analysis::AddSuperModule(TAModule *mod)
297     {
298     // Add a top-level module to list of top-level (super) modules.
299    
300     fSuperMods->Add(mod);
301     }
302    
303     //--------------------------------------------------------------------------------------------------
304 loizides 1.22 void Analysis::FileInputFromEnv()
305     {
306     // Attempt to get list of filesets/files from environment.
307    
308 paus 1.41 TString catalog (gSystem->Getenv("MIT_CATALOG"));
309     TString book (gSystem->Getenv("MIT_BOOK"));
310     TString dataset (gSystem->Getenv("MIT_DATASET"));
311 loizides 1.22 TString filesets(gSystem->Getenv("MIT_FILESETS"));
312 paus 1.41 TString files (gSystem->Getenv("MIT_FILES"));
313 loizides 1.22
314     if ((catalog.IsNull() || book.IsNull() || dataset.IsNull()) && files.IsNull()) {
315     Warning("FileInputFromEnv", "Called to get file info from environment, but did not get"
316 loizides 1.23 " consistent set of variables:\n\tMIT_CATALOG=%s\n\tMIT_BOOK=%s\n\t"
317 loizides 1.22 "MIT_DATASET=%s\n\tMIT_FILESETS=%s\n\tMIT_FILES=%s\n",
318     catalog.Data(), book.Data(), dataset.Data(), filesets.Data(), files.Data());
319     return;
320     }
321    
322     if (!files.IsNull()) { // add local files
323     Info("FileInputFromEnv", "Got from environment:\n"
324     "\n\tMIT_FILES=%s\n", files.Data());
325     TString tok(";");
326     TObjArray *arr = files.Tokenize(tok);
327     if (arr) {
328     for (Int_t i=0; i<arr->GetEntries(); ++i) {
329     TObjString *dummy = dynamic_cast<TObjString*>(arr->At(i));
330     if (!dummy) continue;
331     AddFile(dummy->GetName(),0);
332     }
333     delete arr;
334     }
335     return;
336     }
337    
338     Info("FileInputFromEnv", "Got from environment:\n"
339 loizides 1.23 "\tMIT_CATALOG=%s\n\tMIT_BOOK=%s\n\tMIT_DATASET=%s\n\tMIT_FILESETS=%s\n",
340 loizides 1.22 catalog.Data(), book.Data(), dataset.Data(), filesets.Data());
341    
342     Catalog cat(catalog);
343 loizides 1.25 if (filesets.IsNull()) {
344     Dataset *d = cat.FindDataset(book, dataset);
345     if (d) {
346 loizides 1.22 AddDataset(d);
347     delete d;
348     }
349 loizides 1.25 } else {
350     TString tok(";");
351     TObjArray *arr = filesets.Tokenize(tok);
352     if (arr) {
353     for (Int_t i=0; i<arr->GetEntries(); ++i) {
354     TObjString *fileset = dynamic_cast<TObjString*>(arr->At(i));
355     if (!fileset) continue;
356     Dataset *d = cat.FindDataset(book, dataset, fileset->String());
357     if (!d)
358     continue;
359     AddDataset(d);
360     delete d;
361     }
362     delete arr;
363     }
364 loizides 1.22 }
365     }
366    
367     //--------------------------------------------------------------------------------------------------
368 loizides 1.1 Bool_t Analysis::Init()
369     {
370 paus 1.7 // Setup the TDSet and TChain to be used for the analysis with or without PROOF. If more than one
371     // list of file names was given, friend trees are supported.
372 loizides 1.4
373     if (fState == kRun || fState == kInit) {
374     Error("Init", "Init in state %d is not possible! Call Terminate() first.",
375     Int_t(fState));
376     return kFALSE;
377     }
378    
379 loizides 1.22 // check if we should attempt to get filesets/filenames from environment
380     if (fNFriends == 0)
381     FileInputFromEnv();
382    
383 loizides 1.4 if (fNFriends <= 0) {
384     Error("Init", "List of friend lists is empty!");
385     return kFALSE;
386     }
387    
388 loizides 1.21 if (!fSuperMods->First()) {
389 loizides 1.4 Error("Init", "Top-level TAM module is NULL!");
390     return kFALSE;
391     }
392    
393     if (fUseProof) { // first init our PROOF session
394 loizides 1.22 if (!InitProof())
395     return kFALSE;
396 loizides 1.4 }
397    
398     // we do this here instead in Terminate() so that
399     // we can browse the output even after Terminate()
400     delete fSelector;
401     fSelector = 0;
402    
403     fChain = new TChain(fTreeName);
404     fSet = new TDSet("TTree",fTreeName);
405    
406 loizides 1.22 for (Int_t i=0; i<fNFriends; ++i) {
407 loizides 1.4 TList *l = dynamic_cast<TList*>(fList->At(i));
408     if (!l) {
409     Fatal("Init", "List %d not found!", i);
410 loizides 1.1 return kFALSE;
411 loizides 1.4 }
412    
413     if (i == 0) {
414     TIter next(l);
415 loizides 1.22 while (TObjString *obj = dynamic_cast<TObjString*>(next())) {
416 loizides 1.4 fChain->Add(obj->GetName());
417     fSet->Add(obj->GetName());
418 loizides 1.32 if (fCacheSize<0 && obj->GetString().Contains("/castor/"))
419 loizides 1.30 fCacheSize = 64*1024*1024;
420 loizides 1.4 }
421     } else {
422     TChain *chain = new TChain(fTreeName);
423     TDSet *set = new TDSet("TTree",fTreeName);
424 loizides 1.1
425 loizides 1.4 TIter next(l);
426     while (TObjString *obj = dynamic_cast<TObjString*>(next())) {
427     chain->Add(obj->GetName());
428     set->Add(obj->GetName());
429 loizides 1.32 if (fCacheSize<0 && obj->GetString().Contains("/castor/"))
430 loizides 1.30 fCacheSize = 64*1024*1024;
431 loizides 1.1 }
432    
433 loizides 1.4 TString alias("TAMTREE_"); // aliases currently not used
434     alias+=i;
435 loizides 1.1
436 loizides 1.4 fChain->AddFriend(chain,alias.Data());
437     fSet->AddFriend(set,alias.Data());
438 loizides 1.1
439 loizides 1.4 fDeleteList->Add(chain);
440     fDeleteList->Add(set);
441     }
442 loizides 1.30 }
443 loizides 1.1
444 loizides 1.35 if (fParallel)
445     TTreeCacheUnzip::SetParallelUnzip(TTreeCacheUnzip::kEnable);
446    
447 paus 1.42 //if (fCacheSize>=0)
448     // fChain->SetCacheSize(fCacheSize);
449 loizides 1.1
450 loizides 1.11 // create our customized loader plugin for TAM
451     TreeLoader *bl = new TreeLoader;
452     fLoaders->Add(bl);
453     fDeleteList->Add(bl);
454 loizides 1.1
455 loizides 1.18 // create our ana framework module
456     AnaFwkMod *anamod = new AnaFwkMod;
457 loizides 1.30 anamod->SetSkipNEvents(fSkipNEvents);
458 loizides 1.33 anamod->SetPrintScale(fPrintScale);
459 loizides 1.18 fDeleteList->Add(anamod);
460    
461 loizides 1.15 // create our HLT framework module
462     HLTFwkMod *hltmod = 0;
463     if (fUseHLT) {
464     hltmod = new HLTFwkMod;
465 loizides 1.36 hltmod->SetHLTObjsName(GetHLTObjsName());
466     hltmod->SetHLTTreeName(GetHLTTreeName());
467 loizides 1.15 fDeleteList->Add(hltmod);
468     }
469    
470 loizides 1.4 if (fUseProof) {
471 loizides 1.1
472 loizides 1.18 fProof->AddInput(anamod);
473 loizides 1.15 if (hltmod)
474     fProof->AddInput(hltmod);
475    
476 loizides 1.21 TIter iter(fSuperMods->MakeIterator());
477     while (1) {
478     TAModule *next = dynamic_cast<TAModule*>(iter.Next());
479     if (!next) break;
480     fProof->AddInput(next);
481     }
482    
483 loizides 1.4 fLoaders->SetName("TAM_LOADERS");
484     fProof->AddInput(fLoaders);
485 loizides 1.1
486 loizides 1.4 } else {
487 loizides 1.1
488 loizides 1.4 // when not running Proof, we must make a selector
489 loizides 1.36 Selector *sel = new Selector;
490 paus 1.42 sel->SetCacheSize(fCacheSize);
491 loizides 1.36 sel->SetDoProxy(fDoProxy);
492     sel->SetDoObjTabClean(fDoObjTabClean);
493     sel->SetDoRunInfo(kTRUE);
494     sel->SetAllEvtHdrBrn(GetAllEvtHdrBrn());
495     sel->SetAllEvtTreeName(GetAllEvtTreeName());
496     sel->SetEvtHdrName(GetEvtHdrName());
497     sel->SetLAHdrName(GetLAHdrName());
498     sel->SetLATreeName(GetLATreeName());
499     sel->SetRunInfoName(GetRunInfoName());
500     sel->SetRunTreeName(GetRunTreeName());
501     sel->AddInput(anamod);
502     fSelector = sel;
503 loizides 1.18
504 loizides 1.15 if (hltmod)
505     fSelector->AddInput(hltmod);
506 loizides 1.21
507     TIter iter(fSuperMods->MakeIterator());
508     while (1) {
509     TAModule *next = dynamic_cast<TAModule*>(iter.Next());
510     if (!next) break;
511     fSelector->AddInput(next);
512     }
513    
514 loizides 1.4 MDB(kAnalysis, 2)
515     fSelector->SetVerbosity(1);
516 loizides 1.1
517 loizides 1.4 // pass loaders to selector
518     TIter next(fLoaders);
519 loizides 1.22 while (TAMVirtualLoader *l = dynamic_cast<TAMVirtualLoader*>(next()))
520 loizides 1.4 fSelector->AddLoader(l);
521     }
522 loizides 1.1
523 loizides 1.4 fState = kInit;
524     return kTRUE;
525 loizides 1.1 }
526    
527 loizides 1.12 //--------------------------------------------------------------------------------------------------
528 loizides 1.1 Bool_t Analysis::InitProof()
529     {
530 loizides 1.4 // Initialize PROOF connection.
531 loizides 1.1
532 loizides 1.19 if (fProof && fProof->IsValid())
533 loizides 1.4 return kTRUE;
534 loizides 1.1
535 loizides 1.4 delete fProof;
536 loizides 1.1
537 loizides 1.4 if (fMaster.Contains("rcf.bnl.gov")) {
538 loizides 1.22 for (Int_t i=0; i<5; ++i) {
539 loizides 1.4 Warning("InitProof", "*** DID YOU RUN PROOF_KINIT? %d (5) ***", i);
540     gSystem->Sleep(1000);
541     }
542     }
543    
544     MDB(kAnalysis, 1)
545     Info("InitProof", "Starting PROOF on master %s with config %s",
546     fMaster.Data(), fConfig.Data());
547    
548     fProof = dynamic_cast<TProof*>(TProof::Open(fMaster, fConfig));
549     if (!fProof) {
550     Error("InitProof", "Could not start PROOF!");
551     return kFALSE;
552     }
553    
554     MDB(kAnalysis, 3)
555     gROOT->Print();
556    
557     //fProof->AddInput(new TNamed("PROOF_NewPacketizer",""));
558    
559     Bool_t ret=kTRUE;
560     if (fPackages) {
561     // tell Proof what additional libraries we will need on each worker computer
562     ret = UploadPackages(fPackages);
563     }
564 loizides 1.1
565 loizides 1.4 return ret;
566 loizides 1.1 }
567    
568 loizides 1.12 //--------------------------------------------------------------------------------------------------
569 loizides 1.1 void Analysis::Run()
570     {
571 loizides 1.4 // Run the analysis on the created file set.
572 loizides 1.1
573 loizides 1.4 if (fState == kPristine || fState == kRun) {
574     Error("Run", "Run in state %d is not possible! Call Init() first.",
575     Int_t(fState));
576     }
577 loizides 1.1
578 loizides 1.4 if (fUseProof) {
579 loizides 1.1
580 loizides 1.4 MDB(kAnalysis, 1)
581     Info("Run", "Start processing with PROOF...");
582 loizides 1.1
583 loizides 1.9 fSet->Process("Selector","",fDoNEvents);
584 loizides 1.1
585 loizides 1.4 } else {
586 loizides 1.1
587 loizides 1.4 MDB(kAnalysis, 1)
588     Info("Run", "Start processing (no PROOF)...");
589 loizides 1.1
590 loizides 1.29 fChain->Process(fSelector,"",fDoNEvents);
591 loizides 1.4 }
592 loizides 1.1
593 loizides 1.4 MDB(kAnalysis, 1)
594     Info("Run", "Processing complete!");
595 loizides 1.1
596 loizides 1.4 fState = kRun;
597 loizides 1.1 }
598    
599 loizides 1.12 //--------------------------------------------------------------------------------------------------
600 loizides 1.4 Bool_t Analysis::Run(Bool_t browse)
601 loizides 1.1 {
602 loizides 1.4 // Execute analysis and open TBrowser if requested.
603 loizides 1.1
604 loizides 1.4 if (Init()) {
605     Run();
606     Terminate();
607 paus 1.7 if (browse) {
608 loizides 1.4 new TBrowser;
609     }
610     return kTRUE;
611     }
612 loizides 1.1
613 loizides 1.4 Error("Execute", "Could not initialize analysis.");
614     return kFALSE;
615     }
616 loizides 1.1
617 loizides 1.12 //--------------------------------------------------------------------------------------------------
618 loizides 1.21 void Analysis::SetSuperModule(TAModule *mod)
619     {
620     // Set the first top-level module in the list of top-level (super) modules.
621    
622     fSuperMods->AddFirst(mod);
623     }
624    
625     //--------------------------------------------------------------------------------------------------
626 loizides 1.4 void Analysis::Terminate()
627     {
628     // Terminate current analysis run.
629 loizides 1.1
630 loizides 1.4 if (fState == kPristine || fState == kTerminate) {
631     Error("Terminate", "Terminate in state %d is not possible! Call Init() first.",
632     Int_t(fState));
633     return;
634     }
635    
636     if (fState == kRun) {
637    
638     if (fUseProof) {
639     // the output list from Proof can (in principal) contain other objects
640     // besides the module output hierarchy.
641     TList* outputlist = fProof->GetOutputList();
642     TIter nextOut(outputlist);
643     while (TObject *obj = nextOut()) {
644     if (obj->InheritsFrom(TAMOutput::Class())) {
645     fOutput = dynamic_cast<TList*>(obj);
646     break;
647     }
648     }
649    
650     } else {
651     fOutput = fSelector->GetModOutput();
652     }
653    
654 loizides 1.20
655    
656 loizides 1.4 if (fOutput && !fAnaOutput.IsNull()) {
657     TDirectory::TContext context(0); // automatically restore gDirectory
658    
659     std::auto_ptr<TFile> outf(TFile::Open(fAnaOutput,"recreate","", fCompLevel));
660     if (outf.get() == 0) {
661     Error("Terminate", "Could not open file %s for output!", fAnaOutput.Data());
662 loizides 1.1 } else {
663 loizides 1.4 MDB(kAnalysis, 1)
664     Info("Terminate", "Saving output to %s!", fAnaOutput.Data());
665 loizides 1.1
666 loizides 1.16 if (fHierarchy)
667 loizides 1.20 fOutput->Write(0,-99);
668 loizides 1.4 else
669     fOutput->Write();
670 loizides 1.1 }
671 loizides 1.4 }
672 loizides 1.17 // set state to terminate
673     fState = kTerminate;
674 loizides 1.4 }
675 loizides 1.1
676 loizides 1.4 delete fChain;
677     delete fSet;
678     fDeleteList->Delete();
679 loizides 1.1 }
680    
681 loizides 1.12 //--------------------------------------------------------------------------------------------------
682 loizides 1.1 Bool_t Analysis::UploadPackages(TList *packages)
683     {
684 loizides 1.4 // Upload list of par files to the server.
685 loizides 1.1
686 loizides 1.4 MitAssert("UploadPackages", packages != 0);
687 loizides 1.1
688 loizides 1.22 for (Int_t i=0; i<packages->GetEntries(); ++i) {
689 loizides 1.1
690 loizides 1.4 TObject* objstr = packages->At(i);
691 paus 1.7 if (!objstr) {
692 loizides 1.4 Error("InitProof", "Problem at package number %d!", i);
693     return kFALSE;
694     }
695 loizides 1.1
696 loizides 1.4 TString packname = objstr->GetName();
697 paus 1.7 Int_t en = 0;
698 loizides 1.4 if (packname.EndsWith("+")) {
699     en=1;
700     packname.Resize(packname.Length()-1);
701     }
702    
703     ifstream ftest(gSystem->ExpandPathName(packname.Data()),ios_base::binary);
704 paus 1.7 if (!ftest.good()) {
705 loizides 1.4 Error("InitProof", "Could not open %s for upload!", packname.Data());
706     return kFALSE;
707     }
708 loizides 1.1
709 paus 1.7 if (fProof->UploadPackage(packname)<0) {
710 loizides 1.4 Error("UploadPackage", "Upload for %s failed!", packname.Data());
711     return kFALSE;
712     }
713 loizides 1.1
714 loizides 1.4 if (en == 1) {
715     Int_t pos=packname.Last('/')+1;
716 paus 1.7 if (pos)
717     packname.Remove(0,pos);
718     if (fProof->EnablePackage(packname)<0) {
719 loizides 1.4 Error("UploadPackage", "Enabling for %s failed!", packname.Data());
720     return kFALSE;
721 loizides 1.1 }
722 loizides 1.4 }
723     }
724 loizides 1.1
725 loizides 1.4 return kTRUE;
726 loizides 1.1 }