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
24 static Bool_t cleanPars = kFALSE;
25 static Bool_t cleanPWG2resonances = kFALSE;
26 static const char* listPar = "STEERBase:ESD:AOD:ANALYSIS:ANALYSISalice:PWG2resonances";
27 static const char* proofConnection = "pulvir@alicecaf.cern.ch";
29 static Bool_t isAlien = kTRUE;
30 static Bool_t isProof = kFALSE;
32 // Uncomment these two lines for an example run with a local list of local files
33 //static Rsn_DataSource listType = kTextFile;
34 //static const char* inputSource = "local.txt";
36 // Uncomment these two lines for an example run with PROOF
37 //static const char* inputSource = "/COMMON/COMMON/LHC08c11_10TeV_0.5T";
38 //static Rsn_DataSource listType = kDataset;
40 // Uncomment these two lines for an example run with AliEn XML collection
41 static const char* inputSource = "wn.xml";
42 static Rsn_DataSource listType = kXMLCollection;
44 static Int_t nReadFiles = 0;
45 static Int_t nSkippedFiles = 0;
46 static TString treeName = "esdTree";
48 //_________________________________________________________________________________________________
49 Bool_t CleanPars(const char *pars)
52 // Cleans existing PAR library directories.
53 // The string argument must contain their names
54 // separated by colons (':').
55 // Returns kTRUE if everything went well, otherwise returns kFALSE.
59 TObjArray* array = list.Tokenize(":");
63 for (Int_t i = 0; i < array->GetEntriesFast(); i++)
65 ostr = (TObjString *) array->At(i);
66 str = ostr->GetString();
67 Info("", ">> Cleaning PARs: %s", str.Data());
70 Error("CleanPars", "gProof object not initialized");
73 gProof->ClearPackage(Form("%s.par", str.Data()));
76 gSystem->Exec(Form("rm -Rf %s/", str.Data()));
83 //_________________________________________________________________________________________________
84 Bool_t LoadPars(TString pars)
87 // Loads required PAR libraries.
88 // The string argument must contain their names
89 // separated by colons (':').
90 // Returns kTRUE if everything went well, otherwise returns kFALSE.
93 TObjArray *array = pars.Tokenize(":");
97 for (Int_t i = 0; i < array->GetEntriesFast(); i++) {
98 ostr = (TObjString *) array->At(i);
99 str = ostr->GetString();
100 Info("", ">> Creating PARs: %s", str.Data());
103 Error("CleanPars", "gProof object not initialized");
106 gProof->UploadPackage(Form("%s.par", str.Data()));
107 gProof->EnablePackage(str.Data());
110 // check that file exists...
111 if (gSystem->AccessPathName(Form("%s.par", str.Data()))) {
112 Error("", " !!! File not found");
115 // ...explode tar-ball...
116 gROOT->ProcessLine(Form(".! tar xzf %s.par", str.Data()));
117 // ...go to unpacked directory of PAR library...
118 TString ocwd = gSystem->WorkingDirectory();
119 gSystem->ChangeDirectory(Form("%s", str.Data()));
120 // ...checks for BUILD.sh and execute it...
121 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
122 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
123 Error("", " !!! Build error");
127 // ...check and execute SETUP.C...
128 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
129 if (gROOT->Macro("PROOF-INF/SETUP.C")) {
130 Error("", " !!! Set-up error");
134 // ...return to main dir and finish
135 gSystem->ChangeDirectory(ocwd);
142 //_________________________________________________________________________________________________
143 TChain* CreateChainFromTXT()
146 // Create a TChain of files to be analyzed from a text file.
147 // This text file must contain in each line the FULL PATH of an analyzed file.
148 // Last argument specifies the TTree name.
151 TChain *chain = new TChain(treeName.Data());
153 ifstream fileIn(inputSource);
154 Int_t count = 0, skip = nSkippedFiles;
157 while (fileIn.good()) {
159 if (line.IsNull()) continue;
164 if (nReadFiles > 0 && count++ >= nReadFiles) break;
165 chain->Add(Form("%s", line.Data()));
172 //_________________________________________________________________________________________________
173 TChain* CreateChainFromXML()
176 // Create a TChain of files to be analyzed from a XML file.
177 // Last argument specifies the TTree name.
181 Error("CreateChainFromXML", "gGrid object not instantiated");
185 TChain *chain = new TChain(treeName.Data());
186 TAlienCollection *myCollection = TAlienCollection::Open(inputSource);
189 Error("CreateChainFromXML", "Cannot create an AliEn collection from %s", collectionFile);
193 // initialize a counter to check the number of read files
194 Int_t nfiles = 0, skip = nSkippedFiles;
196 myCollection->Reset();
197 while (myCollection->Next())
199 if (skip > 0) { --skip; continue; }
200 if (nReadFiles > 0 && nfiles >= nReadFiles) break;
201 // char fileName[255];
202 // sprintf(fileName, "%s", myCollection->GetTURL(""));
203 filename = myCollection->GetTURL("");
204 chain->Add(filename.Data());
211 //_________________________________________________________________________________________________
212 TChain* CreateChainFromDataset()
215 // Create a TChain of files to be analyzed from a CAF dataset.
216 // Last argument specifies the TTree name.
220 Error("CreateChainFromDataset", "gProof object not initialized");
224 TFileCollection *fc = gProof->GetDataSet(inputSource)->GetStagedSubset();
225 TIter iter(fc->GetList());
227 TChain* target = new TChain(treeName.Data());
229 TFileInfo* fileInfo = 0;
230 Int_t nfiles = 0, skip = nSkippedFiles;
231 while ((fileInfo = dynamic_cast<TFileInfo*> (iter()))) {
232 if (fileInfo->GetFirstUrl()) {
233 if (skip > 0) { --skip; continue; }
234 if (nReadFiles > 0 && nfiles >= nReadFiles) break;
235 target->Add(fileInfo->GetFirstUrl()->GetUrl());
243 //_________________________________________________________________________________________________
244 Int_t AliRsnAnalysis(const char *addMacro = "AddRsnAnalysisTask.C")
247 // Main macro (named after the macro filename).
248 // It initializes the job, creates the AnalysisManager and calls the config macro which
249 // fills this AnalysisManager with all AnalysisTask objects for resonance analysis.
251 // The argument is the name of the macro used for configuration
254 // - 0 = successful execution
255 // - 1 = problem while cleanind PAR libraries
256 // - 2 = problem while loading PAR libraries
257 // - 3 = invalid TTree name (allowed: esdTree, aodTree)
258 // - 4 = data source not found
259 // - 5 = wrong definition of source type (allowed any member of enum Rsn_DataSource)
260 // - 6 = TChain initialization returned a NULL object
261 // - 7 = error while initializing AliAnalysisManager object
264 // connect to PROOF if required
265 if (isProof) TProof::Open(proofConnection);
266 else if (isAlien) TGrid::Connect("alien://");
269 // *** SETUP PAR LIBRARIES **********************************************************************
270 // - libraries are cleaned if requested
274 if (!CleanPars(listPar)) {
275 Error("AliRsnAnalysis", "Error while cleaning PAR libraries");
279 if (cleanPWG2resonances) CleanPars("PWG2resonances");
280 if (!LoadPars(listPar)) {
281 Error("AliRsnAnalysis", "Error while initializing PAR libraries");
286 AliLog::SetGlobalLogLevel(AliLog::kError);
288 // *** CREATE TChain OF INPUT EVENTS ************************************************************
290 // preliminary check #1: is the tree name OK?
291 if (treeName != "esdTree" && treeName != "aodTree") {
292 Error("AliRsnAnalysis", "Invalid tree name specified");
296 // preliminary check #2: does the input source exist?
297 // (valid only for local files and XML collections)
298 if (listType == kTextFile || listType == kXMLCollection) {
299 Long_t id, size, flags, modtime;
300 if (gSystem->GetPathInfo(inputSource, &id, &size, &flags, &modtime)) {
301 Error("AliRsnAnalysis", "Input source not found");
307 TChain *analysisChain = 0;
310 analysisChain = CreateChainFromTXT();
313 analysisChain = CreateChainFromXML();
316 analysisChain = CreateChainFromDataset();
319 Error("AliRsnAnalysis", "Input type not supported");
322 if (!analysisChain) {
323 Error("AliRsnAnalysis", "Analysis TChain not properly initialized");
328 // *** INITIALIZE ANALYSIS MANAGER **************************************************************
331 AliAnalysisManager *mgr = new AliAnalysisManager("ResonanceAnalysis");
333 Error("AliRsnAnalysis", "Error occurred while initializing AnalysisManager");
337 // load configuration macro and uses it to initialize this object
338 gROOT->LoadMacro(addMacro);
339 AddRsnAnalysisTask(mgr);
341 // initialize analysis and run it
342 TString strEnv = (isProof ? "proof" : "local");
346 mgr->StartAnalysis(strEnv.Data(), analysisChain);