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 //=============================================================================
18 kTextFile, // text file with paths of all used files (local analysis)
19 kXMLCollection, // XML collection of files (local/AliEn analysis)
20 kDataset // CAF dataset
23 static Bool_t cleanPars = kTRUE;
24 static Bool_t cleanPWG2resonances = kFALSE;
25 static const char* listPar = "STEERBase:ESD:AOD:ANALYSIS:ANALYSISalice:PWG2resonances";
26 static const char* proofConnection = "pulvir@alicecaf.cern.ch";
28 static Bool_t isProof = kFALSE;
29 static Rsn_DataSource listType = kTextFile;
31 static const char* inputSource = "local.txt";
32 static Int_t nReadFiles = 2;
33 static Int_t nSkippedFiles = 0;
34 static TString treeName = "esdTree";
36 //_________________________________________________________________________________________________
37 Bool_t CleanPars(const char *pars)
40 // Cleans existing PAR library directories.
41 // The string argument must contain their names
42 // separated by colons (':').
43 // Returns kTRUE if everything went well, otherwise returns kFALSE.
47 TObjArray* array = list.Tokenize(":");
51 for (Int_t i = 0; i < array->GetEntriesFast(); i++)
53 ostr = (TObjString *) array->At(i);
54 str = ostr->GetString();
55 Info("", ">> Cleaning PARs: %s", str.Data());
58 Error("CleanPars", "gProof object not initialized");
61 gProof->ClearPackage(Form("%s.par", str.Data()));
64 gSystem->Exec(Form("rm -Rf %s/", str.Data()));
71 //_________________________________________________________________________________________________
72 Bool_t LoadPars(TString pars)
75 // Loads required PAR libraries.
76 // The string argument must contain their names
77 // separated by colons (':').
78 // Returns kTRUE if everything went well, otherwise returns kFALSE.
81 TObjArray *array = pars.Tokenize(":");
85 for (Int_t i = 0; i < array->GetEntriesFast(); i++) {
86 ostr = (TObjString *) array->At(i);
87 str = ostr->GetString();
88 Info("", ">> Creating PARs: %s", str.Data());
91 Error("CleanPars", "gProof object not initialized");
94 gProof->UploadPackage(Form("%s.par", str.Data()));
95 gProof->EnablePackage(str.Data());
98 // check that file exists...
99 if (gSystem->AccessPathName(Form("%s.par", str.Data()))) {
100 Error("", " !!! File not found");
103 // ...explode tar-ball...
104 gROOT->ProcessLine(Form(".! tar xzf %s.par", str.Data()));
105 // ...go to unpacked directory of PAR library...
106 TString ocwd = gSystem->WorkingDirectory();
107 gSystem->ChangeDirectory(Form("%s", str.Data()));
108 // ...checks for BUILD.sh and execute it...
109 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
110 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
111 Error("", " !!! Build error");
115 // ...check and execute SETUP.C...
116 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
117 if (gROOT->Macro("PROOF-INF/SETUP.C")) {
118 Error("", " !!! Set-up error");
122 // ...return to main dir and finish
123 gSystem->ChangeDirectory(ocwd);
130 //_________________________________________________________________________________________________
131 TChain* CreateChainFromTXT()
134 // Create a TChain of files to be analyzed from a text file.
135 // This text file must contain in each line the FULL PATH of an analyzed file.
136 // Last argument specifies the TTree name.
139 TChain *chain = new TChain(treeName.Data());
141 ifstream fileIn(inputSource);
142 Int_t count = 0, skip = nSkippedFiles;
145 while (fileIn.good()) {
147 if (line.IsNull()) continue;
152 if (nReadFiles > 0 && count++ >= nReadFiles) break;
153 chain->Add(Form("%s", line.Data()));
160 //_________________________________________________________________________________________________
161 TChain* CreateChainFromXML
162 (const char *fileName, Int_t nread = 0, Int_t nskip = 0, const char *treeName = "esdTree")
165 // Create a TChain of files to be analyzed from a XML file.
166 // Last argument specifies the TTree name.
169 TChain *chain = new TChain(treeName.Data());
170 TAlienCollection *myCollection = TAlienCollection::Open(inputSource);
173 Error("CreateChainFromXML", "Cannot create an AliEn collection from %s", collectionFile);
177 // initialize a counter to check the number of read files
178 Int_t nfiles = 0, skip = nSkippedFiles;
180 myCollection->Reset();
181 while (myCollection->Next())
183 if (skip > 0) { --skip; continue; }
184 if (nReadFiles > 0 && nfiles >= nReadFiles) break;
185 // char fileName[255];
186 // sprintf(fileName, "%s", myCollection->GetTURL(""));
187 filename = myCollection->GetTURL("");
188 chain->Add(filename.Data());
195 //_________________________________________________________________________________________________
196 TChain* CreateChainFromDataset()
199 // Create a TChain of files to be analyzed from a CAF dataset.
200 // Last argument specifies the TTree name.
204 Error("CreateChainFromDataset", "gProof object not initialized");
208 TFileCollection *fc = gProof->GetDataSet(inputSource)->GetStagedSubset();
209 TIter iter(fc->GetList());
211 TChain* target = new TChain(treeName.Data());
213 TFileInfo* fileInfo = 0;
214 Int_t nfiles = 0, skip = nSkippedFiles;
215 while ((fileInfo = dynamic_cast<TFileInfo*> (iter()))) {
216 if (fileInfo->GetFirstUrl()) {
217 if (skip > 0) { --skip; continue; }
218 if (nReadFiles > 0 && nfiles >= nReadFiles) break;
219 target->Add(fileInfo->GetFirstUrl()->GetUrl());
227 //_________________________________________________________________________________________________
228 Int_t AliRsnAnalysis(const char *addMacro = "AddRsnAnalysisTask.C")
231 // Main macro (named after the macro filename).
232 // It initializes the job, creates the AnalysisManager and calls the config macro which
233 // fills this AnalysisManager with all AnalysisTask objects for resonance analysis.
235 // The argument is the name of the macro used for configuration
238 // - 0 = successful execution
239 // - 1 = problem while cleanind PAR libraries
240 // - 2 = problem while loading PAR libraries
241 // - 3 = invalid TTree name (allowed: esdTree, aodTree)
242 // - 4 = data source not found
243 // - 5 = wrong definition of source type (allowed any member of enum Rsn_DataSource)
244 // - 6 = TChain initialization returned a NULL object
245 // - 7 = error while initializing AliAnalysisManager object
248 // connect to PROOF if required
249 if (isProof) TProof::Open(proofConnection);
252 // *** SETUP PAR LIBRARIES **********************************************************************
253 // - libraries are cleaned if requested
257 if (!CleanPars(listPar)) {
258 Error("AliRsnAnalysis", "Error while cleaning PAR libraries");
262 if (cleanPWG2resonances) CleanPars("PWG2resonances");
263 if (!LoadPars(listPar)) {
264 Error("AliRsnAnalysis", "Error while initializing PAR libraries");
269 AliLog::SetGlobalLogLevel(AliLog::kError);
271 // *** CREATE TChain OF INPUT EVENTS ************************************************************
273 // preliminary check #1: is the tree name OK?
274 if (treeName != "esdTree" && treeName != "aodTree") {
275 Error("AliRsnAnalysis", "Invalid tree name specified");
279 // preliminary check #2: does the input source exist?
280 // (valid only for local files and XML collections)
281 if (listType == kTextFile || listType == kXMLCollection) {
282 Long_t id, size, flags, modtime;
283 if (gSystem->GetPathInfo(inputSource, &id, &size, &flags, &modtime)) {
284 Error("AliRsnAnalysis", "Input source not found");
290 TChain *analysisChain = 0;
293 analysisChain = CreateChainFromTXT();
296 analysisChain = CreateChainFromXML();
299 analysisChain = CreateChainFromDataset();
302 Error("AliRsnAnalysis", "Input type not supported");
305 if (!analysisChain) {
306 Error("AliRsnAnalysis", "Analysis TChain not properly initialized");
311 // *** INITIALIZE ANALYSIS MANAGER **************************************************************
314 AliAnalysisManager *mgr = new AliAnalysisManager("ResonanceAnalysis");
316 Error("AliRsnAnalysis", "Error occurred while initializing AnalysisManager");
320 // load configuration macro and uses it to initialize this object
321 gROOT->LoadMacro(addMacro);
322 AddRsnAnalysisTask(mgr);
324 // initialize analysis and run it
325 TString strEnv = (isProof ? "proof" : "local");
329 mgr->StartAnalysis(strEnv.Data(), analysisChain);