deb602c0d5a2d8d3b0ca37fba377fb2097d87167
[u/mrichter/AliRoot.git] / PWGCF / EBYE / macros / runLRCAnalysis.C
1 runLRCAnalysis(const char* mode = "GRID", const char* inputName= "wn.xml",Bool_t LoadTaskLocal=kTRUE) {
2 // This macro runs AliAnalysisTaskLRC in three modes : "Local" , "Interactive", "PROOF", "GRID" 
3 // ESD-only
4 // inputName refers to :
5 // "Local" - file with plane-text list of filenames 
6 // "Intaractive","GRID" - XML collection name
7 // "PROOF" - dataset name 
8 //  ---------------------------------------------------------
9 // This macro needs AliRoot-v4-17 or later 
10 // and macro AddTaskLRC.C in workdir
11
12 // For PROOF run PARS(ANALYSISalice.par  ANALYSIS.par  AOD.par  ESD.par  PWGCFebye.par  
13 // STEERBase.par ) are to be in workdir.
14
15
16 // Author : Andrey Ivanov , St.Peterburg State University
17 // Email: Andrey.Ivanov@cern.ch
18
19 // Version line : 3.6
20 // Version 3.6.6
21
22
23 if(mode!="Local" && mode!="Interactive" && mode!="PROOF" && mode!="GRID")
24 {
25 cout<<" ! Mode must be : Local , Interactive, PROOF, GRID \n";
26 cout<<" ! Unknown mode :"<<mode<< " \n";
27 return;
28 }
29
30 if(mode=="Local")runLRCLocal(inputName,LoadTaskLocal);
31 if(mode=="PROOF")runLRCProof(inputName,LoadTaskLocal);
32 if(mode=="Interactive")runLRCInteractive(inputName,LoadTaskLocal);
33 if(mode=="GRID")runLRCInteractive(inputName,LoadTaskLocal);
34
35
36 }
37
38 void LoadAnalysisLibs(Bool_t LoadTaskLocal=kFALSE)
39 {
40   cout<<"  # Loadnig libs...\n";
41  
42
43  gSystem->Load("libSTEERBase");
44   gSystem->Load("libESD");
45   gSystem->Load("libAOD");
46   gSystem->Load("libANALYSIS");
47   gSystem->Load("libANALYSISalice");
48   if(!LoadTaskLocal){
49         gSystem->Load("libEventMixing");
50         gSystem->Load("libPWGCFebye");
51   }
52   
53   //___________Compile analysis task using AClic____________//
54  
55   if(LoadTaskLocal){
56         gROOT->ProcessLine(".include $ALICE_ROOT/include");
57         cout<<"  # Compiling AliLRCBase\n";
58         gROOT->LoadMacro("AliLRCBase.cxx+g");   
59         cout<<"  # Compiling AliLRCProcess\n";
60         gROOT->LoadMacro("AliLRCProcess.cxx+g");
61         gROOT->LoadMacro("AliRidgeAnalyser.cxx+g");
62         cout<<"  # Compiling LRC analysis task\n";
63         gROOT->LoadMacro("AliAnalysisTaskLRC.cxx+g");
64         }
65
66 }
67
68 Bool_t CreateLRCManager(char* name="LRCmanager",Bool_t runKine=kFALSE,Bool_t runAOD=kFALSE)
69 {
70   //____________________________________________//
71   // Make the analysis manager
72   AliAnalysisManager *mgr = new AliAnalysisManager(name);
73   AliESDInputHandler* esdH = new AliESDInputHandler();
74   mgr->SetInputEventHandler(esdH);  
75   if(runKine){
76         AliMCEventHandler* handler = new AliMCEventHandler;
77         mgr->SetMCtruthEventHandler(handler);
78   }
79   
80   AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain1",TChain::Class(),AliAnalysisManager::kInputContainer);
81   
82   mgr->SetCommonFileName("Test.LRC.root");
83   
84   
85
86  return kTRUE;
87
88 }
89
90 void runLRCLocal(const char* inputName= "ESDs.lst",Bool_t LoadTaskLocal=kFALSE,Bool_t runKine=kFALSE,Bool_t runAOD=kFALSE) {
91   printf("  ------------------------------------------\n");
92   printf("  # LRC local run manager \n");
93   cout<<"  # Task from :"<<gSystem->pwd()<<"\n";
94   cout<<"  # Input list :"<<inputName<<"\n";
95   
96   
97   TStopwatch timer;
98   timer.Start();
99   
100   LoadAnalysisLibs(LoadTaskLocal);
101  
102   if (!CreateLRCManager("LocalLRCTest",runKine,runAOD)) return;
103   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
104   AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
105
106   gROOT->LoadMacro("AddTaskLRC.C");
107   AddTaskLRC(runKine);
108   
109  
110   
111   gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
112   TChain* chain = CreateESDChain(inputName);
113   
114   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
115   
116   if (!mgr->InitAnalysis()) return;
117   mgr->PrintStatus();
118   
119   mgr->StartAnalysis("local",chain);
120
121   timer.Stop();
122   timer.Print();
123 }
124
125 void runLRCProof(const char* inputName= "/COMMON/COMMON/tutorial_small",Bool_t LoadTaskLocal=kFALSE,const char* proofLink="anivanov@alice-caf.cern.ch",Bool_t runKine=kFALSE,Bool_t runAOD=kFALSE)
126 {
127   printf("  ------------------------------------------\n");
128   printf(" # LRC PROOF run manager \n");
129   cout<<"  # Task from :"<<gSystem->pwd()<<"\n";
130   cout<<"  # Dataset :"<<inputName<<"\n";
131
132
133         TProof::Open(proofLink);
134         //TProof::Open("anivanov@localhost");.
135
136         
137   cout<<"  # Loadnig libs...\n";
138
139
140
141 gProof->EnablePackage("VO_ALICE@AliRoot::v4-20-13-AN");
142
143   // Use AliRoot includes to compile our task
144   if(LoadTaskLocal){
145  //     gROOT->ProcessLine(".include $ALICE_ROOT/include");
146         cout<<"  # Compiling AliLRCBase\n";
147         gProof->Load("AliLRCBase.cxx+g");       
148         cout<<"  # Compiling AliLRCProcess\n";
149         gProof->Load("AliLRCProcess.cxx+g");
150         gProof->Load("AliLRCAnalyser.cxx+g");
151         cout<<"  # Compiling analysis task\n";
152         gProof->Load("AliAnalysisTaskLRC.cxx+g");   
153   }
154
155   if (!CreateLRCManager("ProofLRCTest",runKine,runAOD)) return;
156   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
157   AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
158    
159   gROOT->LoadMacro("AddTaskLRC.C");
160   AddTaskLRC(runKine);
161
162   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
163   if (!mgr->InitAnalysis()) return;
164   mgr->PrintStatus();
165   mgr->StartAnalysis("proof", inputName);
166 };
167
168 void runLRCInteractive(const char* inputName= "wn.xml",Bool_t LoadTaskLocal=kFALSE,Bool_t runKine=kFALSE,Bool_t runAOD=kFALSE) {
169   
170   printf("  ------------------------------------------\n");
171   printf(" # LRC local-interactive/GRID run manager \n");
172   cout<<"  # Task from :"<<gSystem->pwd()<<"\n";
173   cout<<"  # Collection :"<<inputName<<"\n";
174
175   TStopwatch timer;
176   timer.Start();
177   
178   cout<<"*** Connect to AliEn ***\n";
179   TGrid::Connect("alien://","anivanov");
180
181   LoadAnalysisLibs(LoadTaskLocal);
182   
183   if (!CreateLRCManager("IntLRCTest",runKine,runAOD)) return;
184   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
185   AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
186  
187   
188   gROOT->LoadMacro("AddTaskLRC.C");
189   AddTaskLRC(runKine);
190
191      TAlienCollection * myCollection = 
192         new TAlienCollection("wn.xml",100000) ; 
193     if (!myCollection) { 
194         cout << "XML collection file: " << xmlFileName << " not found" << endl;
195         return;
196     }
197
198     TChain* chain = new TChain("esdTree");
199     
200     cout << "Preparing the file list" << endl; 
201     myCollection->Reset() ; 
202     while ( myCollection->Next() ) {
203         cout << "Adding ESD file: " << myCollection->GetTURL("") << endl; 
204         chain->Add(myCollection->GetTURL("")) ; 
205     }
206     
207   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
208   if (!mgr->InitAnalysis()) return;
209   mgr->PrintStatus();
210   mgr->StartAnalysis("local",chain);
211
212   timer.Stop();
213   timer.Print();
214 }
215
216 Int_t SetupPar(const char* pararchivename) {
217   ///////////////////
218   // Setup PAR File//
219   ///////////////////
220   if (pararchivename) {
221     char processline[1024];
222     TString base = gSystem->BaseName(pararchivename);
223     TString dir  = gSystem->DirName(pararchivename);
224     TString ocwd = gSystem->WorkingDirectory();
225     // Move to dir where the par files are and unpack
226     gSystem->ChangeDirectory(dir.Data());
227     sprintf(processline,".! tar xvzf %s.par",base.Data());
228     gROOT->ProcessLine(processline);
229     // Move to par folder
230     gSystem->ChangeDirectory(base.Data());
231                                                                                                                                                
232     // check for BUILD.sh and execute
233     if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
234       printf("*******************************\n");
235       printf("*** Building PAR archive    ***\n");
236       printf("*******************************\n");
237                                                                                                                                                
238       if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
239         Error("runAnalysis","Cannot Build the PAR Archive! - Abort!");
240         return -1;
241       }
242     }
243     // check for SETUP.C and execute
244     if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
245       printf("*******************************\n");
246       printf("*** Setup PAR archive       ***\n");
247       printf("*******************************\n");
248       // If dir not empty, set the full include path
249       if (dir.Length()) {
250          sprintf(processline, ".include %s", pararchivename);
251          gROOT->ProcessLine(processline); 
252       }   
253       gROOT->Macro("PROOF-INF/SETUP.C");
254     }
255                                                                                                                                                
256     gSystem->ChangeDirectory(ocwd.Data());
257   }                                                                                                                                               
258   return 1;
259 }