2 // This is an example steering macro for running RSN analysis task
3 // locally with a collection of files specified in a text file:
6 // - nReadFiles = number of files to process from the list
7 // - nSkipFiles = how many lines to be skipped when reading the list
8 // - addTaskName = name of the macro to add the RSN analysis task
9 // (assumed to have inside it a function named like the file)
10 // - inputSource = name of the file containing all the inputs
11 // ---> to run on a local collection, the collection file
12 // must contain on each line the full path
13 // of one input file and it must have the ".txt" extension
14 // ---> to run on an AliEn collection, the collection file must be an XML
15 // file collection like those built from the "find -x" method in aliensh.
16 // - dataLabel = a label which is used to know what kind of data are being read
17 // (it is propagated to the 'addTask' macro for eventual setting up of something
18 // - outName = name for the file with RSN package outputs (without ROOT extension)
21 // - in case the source is an ESD, and if inputs are a MC production
22 // the MC input handler is created by default
25 // In principle, the user should never modify this macro.
31 const char *addTaskName = "AddAnalysisTaskRsnTest.C",
32 const char *inputSource = "/home/pulvir/analysis/resonances/LHC2010-7TeV-phi/rsn-package/sim.txt",
33 const char *dataLabel = "7TeV_pass2_sim_ESD",
34 const char *outName = "rsn-test"
38 // convert the last argument into a BOOL variable
39 TString strDataLabel(dataLabel);
40 Bool_t isESD = strDataLabel.Contains("ESD");
41 Bool_t isAOD = strDataLabel.Contains("AOD");
42 Bool_t isSim = strDataLabel.Contains("sim");
44 //AliLog::SetGlobalDebugLevel(AliLog::kDebug+1);
45 //AliLog::SetClassDebugLevel("AliRsnCutPID", AliLog::kDebug+2);
46 //AliLog::SetClassDebugLevel("AliRsnPair", AliLog::kDebug+2);
47 //AliLog::SetClassDebugLevel("AliRsnPairFunctions", AliLog::kDebug+2);
48 //AliLog::SetClassDebugLevel("AliRsnValue", AliLog::kDebug+4);
50 // check extension of input to distinguish between XML and TXT
51 TString sInput(inputSource);
53 Bool_t isTXT = (!strcmp(sInput(sInput.Length() - 3, 3).Data(), "txt"));
54 cout << "Input = " << (isTXT ? "TXT" : "XML") << endl;
56 // load compiled libraries (for aliroot session)
57 gSystem->Load("libANALYSIS.so");
58 gSystem->Load("libANALYSISalice.so");
59 gSystem->Load("libCORRFW.so");
60 gSystem->Load("libPWG2resonances.so");
62 // if input is XML, connect to AliEn
63 if (!isTXT) TGrid::Connect("alien://");
65 // create analysis manager
66 AliAnalysisManager *mgr = new AliAnalysisManager("taskRsnTest");
67 mgr->SetCommonFileName(Form("%s.root", outName));
69 // create input handler
72 AliESDInputHandler *esdHandler = new AliESDInputHandler();
73 mgr->SetInputEventHandler(esdHandler);
74 // if possible, create also MC handler
77 AliMCEventHandler *mcHandler = new AliMCEventHandler();
78 mgr->SetMCtruthEventHandler(mcHandler);
83 AliAODInputHandler *aodHandler = new AliAODInputHandler();
84 mgr->SetInputEventHandler(aodHandler);
88 ::Error("Required an ESD or AOD input data set");
92 // add event selection for data
93 //gROOT->LoadMacro("$(ALICE_ROOT)/ANALYSIS/macros/AddTaskPhysicsSelection.C");
94 //AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(isSim);
96 // add event selection for data
97 //gROOT->LoadMacro("AddTaskAnalysisPhi7TeV.C");
98 //AddTaskAnalysisPhi7TeV(dataLabel);
100 gROOT->LoadMacro("AddTaskAnalysisMonitor.C");
101 AddTaskAnalysisMonitor(dataLabel);
104 //gROOT->ProcessLine(Form(".x %s(\"%s\")", addTaskName, dataLabel));
106 // create TChain of input events
107 TChain *analysisChain = 0x0;
108 if (isTXT) analysisChain = CreateChainFromText(inputSource, "esdTree", nReadFiles, nSkipFiles);
109 else analysisChain = CreateChainFromXML (inputSource, "esdTree", nReadFiles, nSkipFiles);
114 Error("runLocal", "Analysis chain not properly initialized");
119 if (isTXT) mgr->StartAnalysis("local", analysisChain);
120 else mgr->StartAnalysis("alien", analysisChain);
123 //_________________________________________________________________________________________________
124 Bool_t LoadPars(const char *parList, const char *path)
127 // Load PAR libraries locally
130 // - parList = list of PARs without extension, separated by ':'
131 // - path = path where PARs are stored
134 // store position of working directory
135 TString ocwd = gSystem->WorkingDirectory();
138 TString pars(parList);
139 TObjArray *array = pars.Tokenize(":");
144 Char_t parName[200], parFile[200];
145 for (Int_t i = 0; i < array->GetEntriesFast(); i++)
147 ostr = (TObjString*) array->At(i);
148 str = ostr->GetString();
149 sprintf(parName, "%s", str.Data());
150 sprintf(parFile, "%s/%s.par", path, str.Data());
152 // check that file exists
153 if (!gSystem->AccessPathName(parFile))
155 // explode tar-ball and enter it
156 gROOT->ProcessLine(Form(".! tar xzf %s", parFile));
157 gSystem->ChangeDirectory(Form("%s", parName));
158 // checks for BUILD.sh and execute it
159 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh"))
161 ::Info("", ">> Building PARs: %s", parName);
162 if (gSystem->Exec("PROOF-INF/BUILD.sh"))
164 ::Error("LoadPars", Form("BUILD.sh error for '%s'", parFile));
165 gSystem->ChangeDirectory(ocwd);
169 // check and execute SETUP.C
170 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C"))
172 ::Info("", ">> Setting up PARs: %s", parName);
173 if (gROOT->Macro("PROOF-INF/SETUP.C"))
175 Error("LoadPars", Form("SETUP.C error for '%s'", parFile));
176 gSystem->ChangeDirectory(ocwd);
183 Error("LoadParsLocal", Form("File '%s' not found", parFile));
188 gSystem->ChangeDirectory(ocwd);
192 //_________________________________________________________________________________________________
193 TChain* CreateChainFromXML
194 (const char *xmlFileName, const char *treeName, Int_t nread, Int_t nskip)
197 // Create a TChain with all required files listed into an XML collection.
198 // Necessary to run analysis in AliEn jobs.
201 // - xmlFileName = input list
202 // - treeName = "esdTree" or "aodTree"
203 // - nread = how many files to read (0 = all)
204 // - nskip = how many files to skip from beginning
207 // if nread argument is 0, it is disabled
208 if (nread == 0) nread = 1000000000;
210 // initialize output object
211 TChain *chain = new TChain(treeName);
213 // initialize the AliEn collection
214 TAlienCollection *myCollection = TAlienCollection::Open(xmlFileName);
217 Error("CreateChainFromXML", "Cannot create an AliEn collection from %s", xmlFileName);
221 // loop on collection
222 myCollection->Reset();
223 while (myCollection->Next())
225 // skip until reached required number of offset
226 if (nskip > 0) {--nskip; continue;}
228 // stop if required number of read files is reached
229 // otherwise update the counter
230 if (nread <= 0) break;
233 // recovery file and add it
234 Info("CreateChainFromXML", Form("Adding: %s", myCollection->GetTURL("")));
235 chain->Add(myCollection->GetTURL(""));
241 //_________________________________________________________________________________________________
242 TChain* CreateChainFromText(const char *fileName, const char *treeName, Int_t nread, Int_t nskip)
245 // Create a TChain with all required files listed into a text file.
246 // Necessary to run analysis in local jobs.
249 // - xmlFileName = input file list
250 // - treeName = "esdTree" or "aodTree"
251 // - nread = how many files to read (0 = all)
252 // - nskip = how many files to skip from beginning
255 // if third argument is 0, it is interpreted
256 // as "read all lines"
257 Bool_t readAll = (nread <= 0);
259 // initialize output object
260 TChain* target = new TChain(treeName);
263 ifstream fileIn(fileName);
265 // loop on collection
267 while (fileIn.good())
270 if (line.IsNull()) continue;
272 // skip until reached required number of offset
273 if (nskip > 0) {--nskip; continue;}
275 // stop if required number of read files is reached
276 // otherwise update the counter
277 if (!readAll && nread <= 0) break;
281 Info("CreateChainFromText", "Adding '%s'", line.Data());
282 target->Add(line.Data());