1 //=============================================================================
3 // *** AliRsnAnalysis.C ***
5 // This macro contains all stuff which is required to run
6 // a resonance analysis in whatever environment.
7 // It contains a pool of macroes which do all the steps to set it up
8 // and run it with the appropriate configurations.
9 // All the possibilities are made available through enumerations,
10 // with the same style of the Config.C file used for simulation.
12 //=============================================================================
19 kTextFile, // text file with paths of all used files (local analysis)
20 kXMLCollection, // XML collection of files (local/AliEn analysis)
21 kDataset // CAF dataset
26 kLocal, // local analysis with a locally defined TXT list of files
27 kAlien, // AliEn analysis with an XML collection
28 kProof // CAF analysis with a DataSet
31 static Bool_t cleanPars = kFALSE;
32 static Bool_t cleanPWG2resonances = kFALSE;
33 static const char* pathPar = "/home/pulvir/ALICE/ALIROOT/par-files/afs_proof";
34 static const char* listPar = "STEERBase:ESD:AOD:ANALYSIS:ANALYSISalice:PWG2resonances";
35 static const char* proofConnection = "localhost";
37 // Uncomment these lines for an example run with a local list of local files
38 //static const char* inputSource = "local.txt";
39 //static Rsn_DataSource listType = kTextFile;
40 //static Rsn_Environment environment = kLocal;
42 // Uncomment these lines for an example run with PROOF
43 static const char* inputSource = "/COMMON/COMMON/LHC08c11_10TeV_0.5T";
44 static Rsn_DataSource listType = kDataset;
45 static Rsn_Environment environment = kProof;
47 // Uncomment these lines for an example run with AliEn XML collection
48 //static const char* inputSource = "wn.xml";
49 //static Rsn_DataSource listType = kXMLCollection;
50 //static Rsn_Environment environment = kAlien;
52 static Int_t nReadFiles = 5;
53 static Int_t nSkippedFiles = 0;
54 static TString treeName = "esdTree";
56 //_________________________________________________________________________________________________
60 // Check if the environment is PROOF
62 return (environment == kProof);
65 //_________________________________________________________________________________________________
69 // Check if the environment is Alien
71 return (environment == kAlien);
74 //_________________________________________________________________________________________________
75 Bool_t CleanPars(const char *pars)
78 // Cleans existing PAR library directories.
79 // The string argument must contain their names
80 // separated by colons (':').
81 // Returns kTRUE if everything went well, otherwise returns kFALSE.
85 TObjArray* array = list.Tokenize(":");
89 for (Int_t i = 0; i < array->GetEntriesFast(); i++)
91 ostr = (TObjString *) array->At(i);
92 str = ostr->GetString();
93 Info("", ">> Cleaning PARs: %s", str.Data());
96 Error("CleanPars", "gProof object not initialized");
99 gProof->ClearPackage(Form("%s.par", str.Data()));
102 gSystem->Exec(Form("rm -Rf %s/", str.Data()));
109 //_________________________________________________________________________________________________
110 Bool_t LoadPars(TString pars)
113 // Loads required PAR libraries.
114 // The string argument must contain their names
115 // separated by colons (':').
116 // Returns kTRUE if everything went well, otherwise returns kFALSE.
119 TObjArray *array = pars.Tokenize(":");
123 for (Int_t i = 0; i < array->GetEntriesFast(); i++) {
124 ostr = (TObjString *) array->At(i);
125 str = ostr->GetString();
126 Info("", ">> Creating PARs: %s", str.Data());
129 Error("CleanPars", "gProof object not initialized");
132 if (!str.CompareTo("PWG2resonances")) {
133 gProof->UploadPackage(Form("%s.par", str.Data()));
136 gProof->UploadPackage(Form("%s/%s.par", pathPar, str.Data()));
138 gProof->EnablePackage(str.Data());
141 // check that file exists...
142 if (gSystem->AccessPathName(Form("%s.par", str.Data()))) {
143 Error("", " !!! File not found");
146 // ...explode tar-ball...
147 gROOT->ProcessLine(Form(".! tar xzf %s.par", str.Data()));
148 // ...go to unpacked directory of PAR library...
149 TString ocwd = gSystem->WorkingDirectory();
150 gSystem->ChangeDirectory(Form("%s", str.Data()));
151 // ...checks for BUILD.sh and execute it...
152 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
153 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
154 Error("", " !!! Build error");
158 // ...check and execute SETUP.C...
159 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
160 if (gROOT->Macro("PROOF-INF/SETUP.C")) {
161 Error("", " !!! Set-up error");
165 // ...return to main dir and finish
166 gSystem->ChangeDirectory(ocwd);
173 //_________________________________________________________________________________________________
174 TChain* CreateChainFromTXT()
177 // Create a TChain of files to be analyzed from a text file.
178 // This text file must contain in each line the FULL PATH of an analyzed file.
179 // Last argument specifies the TTree name.
182 TChain *chain = new TChain(treeName.Data());
184 ifstream fileIn(inputSource);
185 Int_t count = 0, skip = nSkippedFiles;
188 while (fileIn.good()) {
190 if (line.IsNull()) continue;
195 if (nReadFiles > 0 && count++ >= nReadFiles) break;
196 chain->Add(Form("%s", line.Data()));
203 //_________________________________________________________________________________________________
204 TChain* CreateChainFromXML()
207 // Create a TChain of files to be analyzed from a XML file.
208 // Last argument specifies the TTree name.
212 Error("CreateChainFromXML", "gGrid object not instantiated");
216 TChain *chain = new TChain(treeName.Data());
217 TAlienCollection *myCollection = TAlienCollection::Open(inputSource);
220 Error("CreateChainFromXML", "Cannot create an AliEn collection from %s", collectionFile);
224 // initialize a counter to check the number of read files
225 Int_t nfiles = 0, skip = nSkippedFiles;
227 myCollection->Reset();
228 while (myCollection->Next())
230 if (skip > 0) { --skip; continue; }
231 if (nReadFiles > 0 && nfiles >= nReadFiles) break;
232 // char fileName[255];
233 // sprintf(fileName, "%s", myCollection->GetTURL(""));
234 filename = myCollection->GetTURL("");
235 chain->Add(filename.Data());
242 //_________________________________________________________________________________________________
243 TChain* CreateChainFromDataset()
246 // Create a TChain of files to be analyzed from a CAF dataset.
247 // Last argument specifies the TTree name.
251 Error("CreateChainFromDataset", "gProof object not initialized");
255 TFileCollection *fc = gProof->GetDataSet(inputSource)->GetStagedSubset();
256 TIter iter(fc->GetList());
258 TChain* target = new TChain(treeName.Data());
260 TFileInfo* fileInfo = 0;
261 Int_t nfiles = 0, skip = nSkippedFiles;
262 while ((fileInfo = dynamic_cast<TFileInfo*> (iter()))) {
263 if (fileInfo->GetFirstUrl()) {
264 if (skip > 0) { --skip; continue; }
265 if (nReadFiles > 0 && nfiles >= nReadFiles) break;
266 target->Add(fileInfo->GetFirstUrl()->GetUrl());
274 //_________________________________________________________________________________________________
275 Int_t AliRsnAnalysis(const char *addMacro = "AddRsnAnalysisTask.C")
278 // Main macro (named after the macro filename).
279 // It initializes the job, creates the AnalysisManager and calls the config macro which
280 // fills this AnalysisManager with all AnalysisTask objects for resonance analysis.
282 // The argument is the name of the macro used for configuration
285 // - 0 = successful execution
286 // - 1 = problem while cleanind PAR libraries
287 // - 2 = problem while loading PAR libraries
288 // - 3 = invalid TTree name (allowed: esdTree, aodTree)
289 // - 4 = data source not found
290 // - 5 = wrong definition of source type (allowed any member of enum Rsn_DataSource)
291 // - 6 = TChain initialization returned a NULL object
292 // - 7 = error while initializing AliAnalysisManager object
295 // connect to PROOF if required
296 if (IsProof()) TProof::Open(proofConnection);
297 else if (IsAlien()) TGrid::Connect("alien://");
300 // *** SETUP PAR LIBRARIES **********************************************************************
301 // - libraries are cleaned if requested
305 if (!CleanPars(listPar)) {
306 Error("AliRsnAnalysis", "Error while cleaning PAR libraries");
310 if (cleanPWG2resonances) CleanPars("PWG2resonances");
311 if (!LoadPars(listPar)) {
312 Error("AliRsnAnalysis", "Error while initializing PAR libraries");
317 AliLog::SetGlobalLogLevel(AliLog::kError);
319 // *** CREATE TChain OF INPUT EVENTS ************************************************************
321 // preliminary check #1: is the tree name OK?
322 if (treeName != "esdTree" && treeName != "aodTree") {
323 Error("AliRsnAnalysis", "Invalid tree name specified");
327 // preliminary check #2: does the input source exist?
328 // (valid only for local files and XML collections)
329 if (listType == kTextFile || listType == kXMLCollection) {
330 Long_t id, size, flags, modtime;
331 if (gSystem->GetPathInfo(inputSource, &id, &size, &flags, &modtime)) {
332 Error("AliRsnAnalysis", "Input source not found");
338 TChain *analysisChain = 0;
341 analysisChain = CreateChainFromTXT();
344 analysisChain = CreateChainFromXML();
347 analysisChain = CreateChainFromDataset();
350 Error("AliRsnAnalysis", "Input type not supported");
353 if (!analysisChain) {
354 Error("AliRsnAnalysis", "Analysis TChain not properly initialized");
359 // *** INITIALIZE ANALYSIS MANAGER **************************************************************
362 AliAnalysisManager *mgr = new AliAnalysisManager("ResonanceAnalysis");
364 Error("AliRsnAnalysis", "Error occurred while initializing AnalysisManager");
368 // set ESD and MC input handlers
369 AliESDInputHandler *esdHandler = new AliESDInputHandler();
370 AliAODInputHandler *aodHandler = new AliAODInputHandler();
371 AliMCEventHandler* mcHandler = new AliMCEventHandler();
372 esdHandler->SetInactiveBranches("FMD CaloCluster");
373 if (!treeName.CompareTo("esdTree")) {
374 mgr->SetInputEventHandler(esdHandler);
376 else if (!treeName.CompareTo("aodTree")) {
377 mgr->SetInputEventHandler(aodHandler);
380 Error("AliRsnAnalysis", "Input tree type not supported");
383 mgr->SetMCtruthEventHandler(mcHandler);
385 // load configuration macro and uses it to initialize this object
386 gROOT->LoadMacro(addMacro);
387 AddRsnAnalysisTask();
389 // initialize analysis and run it
390 TString strEnv = (IsProof() ? "proof" : "local");
394 mgr->StartAnalysis(strEnv.Data(), analysisChain);