Fix for segfault if methods called in wrong order.
[u/mrichter/AliRoot.git] / PWG2 / EBYE / macros / runBalanceFunction.C
CommitLineData
d6cd3d13 1enum anaModes {kLocal,kLocalPAR,kPROOF,kInteractive,kGRID};
754d059d 2//kLocal: Analyze locally files in your computer using aliroot
3//kLocalPAR: Analyze locally files in your computer using root + PAR files
4//kPROOF: Analyze CAF files with PROOF
5
d6cd3d13 6void runBalanceFunction(Int_t analysisMode = kInteractive,
754d059d 7 Bool_t kMCAnalysis = kFALSE,
8 const char* dataMode = "ESD") {
5c33329d 9 TStopwatch timer;
10 timer.Start();
11
754d059d 12 //Load the libraries
13 LoadLibraries(analysisMode);
14
15 //Select the running mode and create the chain
16 if (analysisMode == kGRID) {
17 // Create and configure the alien handler plugin
18 gROOT->LoadMacro("CreateAlienHandler.C");
19 AliAnalysisGrid *alienHandler = CreateAlienHandler();
20 if (!alienHandler) return;
21 }
22 if (analysisMode==kLocal || analysisMode == kLocalPAR) {
23 TChain *chain = new TChain("esdTree");
d6cd3d13 24 chain->Add("../Set1/AliESDs.root");
25 chain->Add("../Set2/AliESDs.root");
754d059d 26 }
d6cd3d13 27 if(analysisMode == kInteractive) {
28 TGrid::Connect("alien://");
29 TChain *chain = new TChain("esdTree");
30 TString alienUrl;
754d059d 31
d6cd3d13 32 TAlienCollection *collection = TAlienCollection::Open("wn.xml");
33 TGridResult *gResult = collection->GetGridResult("",0,0);
34 Int_t nEntries = gResult->GetEntries();
35 for(Int_t i = 0; i < nEntries; i++) {
36 alienUrl = gResult->GetKey(i,"turl");
37 chain->Add(alienUrl.Data());
38 }
39 }
754d059d 40 //___________________________________________________//
41 // Create the analysis manager
42 AliAnalysisManager *mgr = new AliAnalysisManager("testAnalysis");
43 if (analysisMode == kGRID) {
44 // Connect plug-in to the analysis manager
45 mgr->SetGridHandler(alienHandler);
46 }
47
48 AliVEventHandler* esdH = new AliESDInputHandler();
49 mgr->SetInputEventHandler(esdH);
50
51 //Configure the BF object
52 gROOT->LoadMacro("AddTaskBalanceFunction.C");
53 AliAnalysisTaskBF *taskBF = AddTaskBalanceFunction();
54
55 // Task to check the offline trigger
d6cd3d13 56 if (analysisMode == kLocal || analysisMode == kGRID || analysisMode == kInteractive) {
754d059d 57 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); }
58 else if (analysisMode == kPROOF || analysisMode == kLocalPAR) {
59 gROOT->LoadMacro("AddTaskPhysicsSelection.C"); }
60 AliPhysicsSelectionTask* physicsSelTask = AddTaskPhysicsSelection();
61 if (kMCAnalysis) {physicsSelTask->GetPhysicsSelection()->SetAnalyzeMC();}
62
63 // Enable debug printouts
64 mgr->SetDebugLevel(2);
65 if (!mgr->InitAnalysis())
66 return;
67 mgr->PrintStatus();
68
d6cd3d13 69 if (analysisMode == kLocal || analysisMode == kLocalPAR || analysisMode == kInteractive) {
754d059d 70 mgr->StartAnalysis("local",chain);
71 }
72 else if (analysisMode == kPROOF) {
73 mgr->StartAnalysis("proof",dataDir,nRuns,offset);
74 }
75 else if (analysisMode == kGRID) {
76 mgr->StartAnalysis("grid");
77 }
78
5c33329d 79 timer.Stop();
80 timer.Print();
81}
82
d6cd3d13 83void SetupPar(char* pararchivename) {
84 //Load par files, create analysis libraries
85 //For testing, if par file already decompressed and modified
86 //classes then do not decompress.
87
88 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
89 TString parpar(Form("%s.par", pararchivename)) ;
90 if ( gSystem->AccessPathName(parpar.Data()) ) {
91 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
92 TString processline(Form(".! make %s", parpar.Data())) ;
93 gROOT->ProcessLine(processline.Data()) ;
94 gSystem->ChangeDirectory(cdir) ;
95 processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
96 gROOT->ProcessLine(processline.Data()) ;
97 }
98 if ( gSystem->AccessPathName(pararchivename) ) {
99 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
100 gROOT->ProcessLine(processline.Data());
101 }
102
103 TString ocwd = gSystem->WorkingDirectory();
104 gSystem->ChangeDirectory(pararchivename);
105
106 // check for BUILD.sh and execute
107 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
108 printf("*******************************\n");
109 printf("*** Building PAR archive ***\n");
110 cout<<pararchivename<<endl;
111 printf("*******************************\n");
112 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
113 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
114 return -1;
115 }
116 }
117 // check for SETUP.C and execute
118 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
119 printf("*******************************\n");
120 printf("*** Setup PAR archive ***\n");
121 cout<<pararchivename<<endl;
122 printf("*******************************\n");
123 gROOT->Macro("PROOF-INF/SETUP.C");
124 }
125
126 gSystem->ChangeDirectory(ocwd.Data());
127 printf("Current dir: %s\n", ocwd.Data());
128}
129
754d059d 130//__________________________________________________________//
5c33329d 131Int_t setupPar(const char* pararchivename) {
132 ///////////////////
133 // Setup PAR File//
134 ///////////////////
135 if (pararchivename) {
136 char processline[1024];
137 sprintf(processline,".! tar xvzf %s.par",pararchivename);
138 gROOT->ProcessLine(processline);
139 const char* ocwd = gSystem->WorkingDirectory();
140 gSystem->ChangeDirectory(pararchivename);
141
142 // check for BUILD.sh and execute
143 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
144 printf("*******************************\n");
145 printf("*** Building PAR archive ***\n");
146 printf("*******************************\n");
147
148 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
149 Error("runAnalysis","Cannot Build the PAR Archive! - Abort!");
150 return -1;
151 }
152 }
153 // check for SETUP.C and execute
154 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
155 printf("*******************************\n");
156 printf("*** Setup PAR archive ***\n");
157 printf("*******************************\n");
158 gROOT->Macro("PROOF-INF/SETUP.C");
159 }
160
161 gSystem->ChangeDirectory("../");
162 }
163 return 1;
164}
754d059d 165
166//__________________________________________________________//
167void LoadLibraries(const anaModes mode) {
168 //--------------------------------------
169 // Load the needed libraries most of them already loaded by aliroot
170 //--------------------------------------
171 //----------------------------------------------------------
172 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
173 //----------------------------------------------------------
d6cd3d13 174 if (mode==kLocal || mode==kGRID || mode==kInteractive) {
754d059d 175 //--------------------------------------------------------
176 // If you want to use already compiled libraries
177 // in the aliroot distribution
178 //--------------------------------------------------------
179 gSystem->Load("libSTEERBase.so");
180 gSystem->Load("libVMC.so");
181 gSystem->Load("libESD.so");
182 gSystem->Load("libAOD.so");
183 gSystem->Load("libANALYSIS.so");
184 gSystem->Load("libANALYSISalice.so");
d6cd3d13 185 if (mode==kLocal) {
186 Printf("Local: loading the libPWG2ebye.so");
754d059d 187 gSystem->Load("libPWG2ebye.so");
d6cd3d13 188 }
189 if (mode==kGRID || mode==kInteractive) {
190 //setupPar("PWG2ebye");
191 //Printf("GRID: loading the libPWG2ebye.so");
754d059d 192 gSystem->Load("libPWG2ebye.so");
193 }
194 }//local or GRID
195 else if (mode == kLocalPAR) {
196 //--------------------------------------------------------
197 //If you want to use root and par files from aliroot
198 //--------------------------------------------------------
199 gSystem->Load("libSTEERBase.so");
d6cd3d13 200 //setupPar("ESD");
754d059d 201 gSystem->Load("libVMC.so");
202 gSystem->Load("libESD.so");
d6cd3d13 203 //setupPar("AOD");
754d059d 204 gSystem->Load("libAOD.so");
d6cd3d13 205 //setupPar("ANALYSIS");
754d059d 206 gSystem->Load("libANALYSIS.so");
d6cd3d13 207 //setupPar("ANALYSISalice");
754d059d 208 gSystem->Load("libANALYSISalice.so");
d6cd3d13 209 Int_t setuparflag = setupPar("PWG2ebye");
210 Printf("localPar: loading the libPWG2ebye.so (%d)",setuparflag);
754d059d 211 gSystem->Load("libPWG2ebye.so");
212 }//local with par files
213
214 //---------------------------------------------------------
215 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
216 //---------------------------------------------------------
217 else if (mode==kPROOF) {
218 // Connect to proof
219 printf("*** Connect to PROOF ***\n");
220 gEnv->SetValue("XSec.GSI.DelegProxy","2");
221 TProof::Open("alice-caf.cern.ch");
222
223 // Upload the Packages
224 gProof->UploadPackage("STEERBase.par");
225 gProof->UploadPackage("ESD.par");
226 gProof->UploadPackage("AOD.par");
227 gProof->UploadPackage("ANALYSIS.par");
228 gProof->UploadPackage("ANALYSISalice.par");
229 gProof->UploadPackage("CORRFW.par");
230 gProof->UploadPackage("PWG2ebye.par");
231
232 // Enable the Packages
233 gProof->EnablePackage("STEERBase");
234 gProof->EnablePackage("ESD");
235 gProof->EnablePackage("AOD");
236 gProof->EnablePackage("ANALYSIS");
237 gProof->EnablePackage("ANALYSISalice");
238 gProof->EnablePackage("PWG2ebye");
239
240 // Show enables Packages
241 gProof->ShowEnabledPackages();
242 }
243
244}