]>
Commit | Line | Data |
---|---|---|
e886738f | 1 | // #include <iostream> |
2 | // #include "AliAnalysisManager.h" | |
3 | // #include "AliESDInputHandler.h" | |
4 | // #include "AliMCEventHandler.h" | |
5 | // #include "AliAnalysisGrid.h" | |
6 | // #include "AliCentralitySelectionTask.h" | |
7 | // #include "AliAnalysisCentralitySelector.h" | |
8 | // #include "AliAnalysisTaskPerformanceStrange.h" | |
9 | // #include "TString.h" | |
10 | // #include "TChain.h" | |
11 | // #include "TAlienCollection.h" | |
12 | // #include <fstream> | |
13 | // #include "TObjString.h" | |
14 | // #include "TIterator.h" | |
15 | // #include "TGrid.h" | |
16 | // #include "TROOT.h" | |
17 | ||
18 | // #include "CreateAlienHandler.C" | |
19 | // #include | |
20 | ||
21 | using namespace std; | |
22 | ||
23 | enum { kMyRunModeLocal = 0, kMyRunModeCAF, kMyRunModeGRID}; | |
24 | ||
25 | TList * listToLoad = new TList(); // Additional classes to be loaded, see InitAndLoadLibs | |
26 | ||
27 | TChain * GetAnalysisChain(const char * incollection); | |
28 | void InitAndLoadLibs(Int_t runMode=kMyRunModeLocal, Int_t workers=0,Bool_t debug=0) ; | |
29 | ||
99c77a9a | 30 | void run(const char * data, const char * passOrPath, Long64_t nev = -1, Long64_t offset = 0, Bool_t debug = kFALSE, Int_t runMode = 2, Bool_t isMC = 0, Bool_t usePID = kTRUE, const char* option = "",TString customSuffix = "", Int_t workers = -1, const char * gridMode="full", Int_t binMin=0, Int_t binMax = 10) |
e886738f | 31 | { |
32 | // runMode: | |
33 | // | |
34 | // 0 local | |
35 | // 1 proof | |
36 | // 2 grid | |
37 | ||
38 | if (nev < 0) | |
71c90abf | 39 | // nev = 1234567890; |
40 | nev = 5000; | |
e886738f | 41 | InitAndLoadLibs(runMode,workers,debug); |
71c90abf | 42 | |
e886738f | 43 | // Create the analysis manager |
44 | AliAnalysisManager * mgr = new AliAnalysisManager; | |
45 | ||
46 | // Add ESD handler | |
47 | AliESDInputHandler* esdH = new AliESDInputHandler; | |
e886738f | 48 | mgr->SetInputEventHandler(esdH); |
49 | ||
50 | if(isMC) { | |
51 | AliMCEventHandler* handler = new AliMCEventHandler; | |
52 | handler->SetPreReadMode(AliMCEventHandler::kLmPreRead); | |
53 | mgr->SetMCtruthEventHandler(handler); | |
54 | } | |
55 | ||
56 | ||
57 | // If we are running on grid, we need the alien handler | |
58 | if (runMode == kMyRunModeGRID) { | |
59 | // Create and configure the alien handler plugin | |
60 | TGrid::Connect("alien://");// Why do I need this? Without a get a bus error... | |
cae0fd80 | 61 | gROOT->LoadMacro("CreateAlienHandler.C"); |
e886738f | 62 | AliAnalysisGrid *alienHandler = CreateAlienHandler(data, listToLoad, gridMode, isMC); |
63 | if (!alienHandler) { | |
64 | cout << "Cannot create alien handler" << endl; | |
65 | exit(1); | |
66 | } | |
67 | mgr->SetGridHandler(alienHandler); | |
68 | } | |
69 | ||
49d43670 | 70 | // PID task |
71 | gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C"); | |
71c90abf | 72 | AddTaskPIDResponse(isMC,kTRUE); |
49d43670 | 73 | //AddTaskPIDResponse(); |
e886738f | 74 | // Physics selection |
75 | gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); | |
71c90abf | 76 | AliPhysicsSelectionTask * physicsSelectionTask = AddTaskPhysicsSelection(isMC,kTRUE,0); |
e886738f | 77 | |
78 | // Centrality | |
1c06a186 | 79 | gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskCentrality.C"); |
e886738f | 80 | AliCentralitySelectionTask *taskCentrality = AddTaskCentrality(); |
8797f8b6 | 81 | //taskCentrality->SetPass(2); |
5da6bd6f | 82 | if(isMC) taskCentrality->SetMCInput(); |
e886738f | 83 | |
e886738f | 84 | // Parse option strings |
85 | TString optionStr(option); | |
86 | ||
87 | // remove SAVE option if set | |
88 | Bool_t doSave = kFALSE; | |
89 | ||
90 | if (optionStr.Contains("SAVE")) | |
91 | { | |
92 | optionStr = optionStr(0,optionStr.Index("SAVE")) + optionStr(optionStr.Index("SAVE")+4, optionStr.Length()); | |
93 | doSave = kTRUE; | |
94 | } | |
95 | TString pathsuffix = ""; | |
96 | // Not used, but may be useful | |
97 | Bool_t useMCKinematics = isMC; | |
98 | if (optionStr.Contains("NOMCKIN")) { | |
99 | cout << ">>>> Ignoring MC kinematics" << endl; | |
100 | useMCKinematics=kFALSE; | |
101 | pathsuffix+="_NOMCKIN"; | |
102 | } | |
103 | ||
104 | gROOT->ProcessLine(".L AddTaskLambdaK0PbPb.C"); | |
105 | Int_t nbin = 0; // will contain the number of centrality bins | |
0b33641a | 106 | AliAnalysisTaskPerformanceStrange ** task = AddTaskLambdaK0PbPb("lambdak0.root", nbin, binMin, binMax,isMC,1); |
c66bfacf | 107 | // AliAnalysisTaskPerformanceStrange ** task = AddTaskLambdaK0PbPb(); |
e886738f | 108 | |
c66bfacf | 109 | cout << nbin << endl; |
e886738f | 110 | // Init and run the analy |
111 | if (!mgr->InitAnalysis()) return; | |
112 | ||
113 | mgr->PrintStatus(); | |
114 | ||
115 | if (runMode == kMyRunModeLocal ) { | |
116 | // If running in local mode, create chain of ESD files | |
117 | cout << "RUNNING LOCAL, CHAIN" << endl; | |
118 | TChain * chain = GetAnalysisChain(data); | |
119 | // chain->Print(); | |
120 | mgr->StartAnalysis("local",chain,nev); | |
121 | } else if (runMode == kMyRunModeCAF) { | |
8797f8b6 | 122 | mgr->StartAnalysis("proof",TString(passOrPath)+data+"#esdTree",nev); |
e886738f | 123 | } else if (runMode == kMyRunModeGRID) { |
124 | mgr->StartAnalysis("grid"); | |
125 | } else { | |
126 | cout << "ERROR: unknown run mode" << endl; | |
127 | } | |
128 | ||
129 | pathsuffix += customSuffix; | |
130 | ||
71c90abf | 131 | if (doSave) MoveOutput(data, pathsuffix.Data()); |
e886738f | 132 | |
133 | ||
134 | } | |
135 | ||
136 | void MoveOutput(const char * data, const char * suffix = ""){ | |
137 | ||
49d43670 | 138 | // TString path("output10bins/"); |
139 | TString path("output10binsNew/"); | |
e886738f | 140 | path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix; |
141 | ||
142 | TString fileName = "lambdak0.root"; | |
143 | gSystem->mkdir(path, kTRUE); | |
144 | gSystem->Rename(fileName, path + "/" + fileName); | |
145 | for(Int_t ibin = 0; ibin < 20; ibin++){ | |
146 | TString fileBin = fileName; | |
147 | fileBin.ReplaceAll(".root",Form("_%2.2d.root",ibin)); | |
148 | gSystem->Rename(fileBin, path + "/" + fileBin); | |
149 | } | |
150 | ||
151 | gSystem->Rename("event_stat.root", path + "/event_stat.root"); | |
152 | gSystem->Rename("EventStat_temp.root", path + "/EventStat_temp.root"); | |
153 | Printf(">>>>> Moved files to %s", path.Data()); | |
154 | } | |
155 | ||
156 | ||
157 | ||
158 | TChain * GetAnalysisChain(const char * incollection){ | |
159 | // Builds a chain of esd files | |
160 | // incollection can be | |
161 | // - a single root file | |
162 | // - an xml collection of files on alien | |
163 | // - a ASCII containing a list of local root files | |
164 | ||
165 | TChain* analysisChain = 0; | |
166 | // chain | |
167 | analysisChain = new TChain("esdTree"); | |
168 | if (TString(incollection).Contains(".root")){ | |
169 | analysisChain->Add(incollection); | |
170 | } | |
171 | else if (TString(incollection).Contains("xml")){ | |
172 | TGrid::Connect("alien://"); | |
173 | TGridCollection * coll = TAlienCollection::Open (incollection); | |
174 | while(coll->Next()){ | |
175 | analysisChain->Add(TString("alien://")+coll->GetLFN()); | |
176 | } | |
177 | } else { | |
178 | ifstream file_collect(incollection); | |
179 | TString line; | |
180 | while (line.ReadLine(file_collect) ) { | |
181 | analysisChain->Add(line.Data()); | |
182 | } | |
183 | } | |
184 | analysisChain->GetListOfFiles()->Print(); | |
185 | ||
186 | return analysisChain; | |
187 | } | |
188 | ||
189 | ||
190 | void InitAndLoadLibs(Int_t runMode, Int_t workers,Bool_t debug) { | |
191 | // Loads libs and par files + custom task and classes (the order is important) | |
a7bbe8a5 | 192 | // listToLoad->Add(new TObjString("$ALICE_ROOT/STEER/AliCentrality.cxx")); // FIXME: why do I have to load it?!? |
e886738f | 193 | listToLoad->Add(new TObjString("AliAnalysisCentralitySelector.cxx")); |
194 | listToLoad->Add(new TObjString("AliAnalysisTaskPerformanceStrange.cxx")); | |
195 | ||
196 | if (runMode == kMyRunModeCAF) | |
197 | { | |
198 | cout << "Init in CAF mode" << endl; | |
199 | ||
200 | gEnv->SetValue("XSec.GSI.DelegProxy", "2"); | |
5a20f613 | 201 | Char_t* alienuser = gSystem->Getenv("alien_API_USER"); |
0b33641a | 202 | TProof * p = TProof::Open(alienuser!=0 ? Form("%s@alice-caf.cern.ch",alienuser) : "alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : ""); |
203 | // TProof * p = TProof::Open("skaf.saske.sk", workers>0 ? Form("workers=%d",workers) : ""); | |
204 | p->Exec("TObject *o = gEnv->GetTable()->FindObject(\"Proof.UseMergers\"); gEnv->GetTable()->Remove(o);", kTRUE); // avoid submerging | |
205 | gProof->EnablePackage("VO_ALICE@AliRoot::v5-04-40-AN"); | |
206 | gProof->GetManager()->SetROOTVersion("VO_ALICE@ROOT::v5-34-05"); | |
71c90abf | 207 | // gProof->EnablePackage("VO_ALICE@AliRoot::v5-02-04-AN"); |
208 | ||
e886738f | 209 | |
210 | // Enable the needed package | |
211 | // FIXME: what if I don't want to use par files? | |
212 | gSystem->AddIncludePath("-I${ALICE_ROOT}/include/"); | |
213 | gSystem->AddIncludePath("-I${ALICE_ROOT}/STEER/"); | |
5d317ae5 | 214 | // gProof->UploadPackage("$ALICE_ROOT/obj/STEERBase"); |
215 | // gProof->EnablePackage("$ALICE_ROOT/obj/STEERBase"); | |
216 | // gProof->UploadPackage("$ALICE_ROOT/obj/ESD"); | |
217 | // gProof->EnablePackage("$ALICE_ROOT/obj/ESD"); | |
218 | // gProof->UploadPackage("$ALICE_ROOT/obj/AOD"); | |
219 | // gProof->EnablePackage("$ALICE_ROOT/obj/AOD"); | |
220 | // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSIS"); | |
221 | // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSIS"); | |
222 | // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSISalice"); | |
223 | // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSISalice"); | |
224 | // gProof->UploadPackage("$ALICE_ROOT/obj/CORRFW"); | |
225 | // gProof->EnablePackage("$ALICE_ROOT/obj/CORRFW"); | |
226 | // gProof->UploadPackage("~/Desktop/OADB");//FIXME | |
227 | // gProof->EnablePackage("~/Desktop/OADB");//FIXME | |
e886738f | 228 | |
229 | } | |
230 | else | |
231 | { | |
232 | cout << "Init in Local or Grid mode" << endl; | |
71c90abf | 233 | Int_t ret=-1; |
234 | ||
235 | if ( gSystem->Load("libCore") < 0 ) return ret; ret--; | |
236 | if ( gSystem->Load("libTree") < 0 ) return ret; ret--; | |
237 | if ( gSystem->Load("libGeom") < 0 ) return ret; ret--; | |
238 | if ( gSystem->Load("libVMC") < 0 ) return ret; ret--; | |
239 | if ( gSystem->Load("libPhysics") < 0 ) return ret; ret--; | |
240 | if ( gSystem->Load("libMinuit") < 0 ) return ret; ret--; | |
241 | if ( gSystem->Load("libSTEERBase") < 0 ){ cout<<"libSTEERBase coul not be loaded!!!"<<endl; }//return ret; ret--;} | |
242 | if ( gSystem->Load("libESD") < 0 ) return ret; ret--; | |
243 | if ( gSystem->Load("libAOD") < 0 ) return ret; ret--; | |
244 | if ( gSystem->Load("libANALYSIS") < 0 ) return ret; ret--; | |
245 | if ( gSystem->Load("libANALYSISalice") < 0 ) return ret; ret--; | |
246 | ||
247 | ||
e886738f | 248 | gROOT->ProcessLine(".include $ALICE_ROOT/include"); |
249 | gROOT->ProcessLine(".include $ALICE_ROOT/STEER"); | |
71c90abf | 250 | cout<<"/////////////////////////////////////"<<endl; |
251 | cout<<endl<<"libraries loaded !"<<endl; | |
252 | cout<<"/////////////////////////////////////"<<endl; | |
e886738f | 253 | } |
254 | // Load helper classes | |
255 | TIterator * iter = listToLoad->MakeIterator(); | |
256 | TObjString * name = 0; | |
257 | while ((name = (TObjString *)iter->Next())) { | |
258 | gSystem->ExpandPathName(name->String()); | |
259 | cout << name->String().Data() << endl; | |
260 | if (runMode == kMyRunModeCAF) { | |
261 | gProof->Load(name->String()+(debug?"++g":"+")); | |
262 | } else { | |
263 | gROOT->LoadMacro(name->String()+(debug?"++g":"+")); | |
264 | } | |
265 | } | |
266 | ||
267 | } |