]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/mergeOutput.C
replace empty file
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / mergeOutput.C
1 enum libModes {mLocal,mLocalSource};
2
3 void mergeOutput(TString type="", Int_t nRuns=-1, Int_t mode=mLocal)
4 {
5  // type:  type of analysis can be ESD, AOD, MC, ESDMC0, ESDMC1
6  //        (if type="" output files are from MC simulation (default))
7  // nRuns: specify here how many output .root files will be merged 
8  //        (if nRuns = -1 all of them will be merged)
9  // mode:  if mode=mLocal analyze data on your computer using aliroot
10  //        if mode=mLocalSource analyze data on your computer using root + source files
11  
12  // load needed libraries:                       
13  LoadSpreadLibrariesMO(mode);  
14  
15  // access the path of current directory:
16  TString pwd(gSystem->pwd());
17  pwd+="/";
18     
19  // file mergers for the output file of each method separately: 
20  // MCEP:                       
21  TFileMerger *mcepFileMerger = new TFileMerger();
22  TString mergedFileNameMCEP("mergedMCEPanalysis");
23  (mergedFileNameMCEP+=(type.Data()))+=(".root");
24  TString pwdMCEP=pwd.Data();
25  if(!(gSystem->AccessPathName((pwdMCEP+=mergedFileNameMCEP).Data(),kFileExists)))
26  {
27   cout<<"WARNING: You already have a merged output for MCEP !!!!"<<endl;
28   break;
29  }
30  mcepFileMerger->OutputFile(mergedFileNameMCEP);
31  
32  // SP:                       
33  TFileMerger *spFileMerger = new TFileMerger();
34  TString mergedFileNameSP("mergedSPanalysis");
35  (mergedFileNameSP+=(type.Data()))+=(".root");
36  TString pwdSP=pwd.Data(); 
37  if(!(gSystem->AccessPathName((pwdSP+=mergedFileNameSP).Data(),kFileExists)))
38  {
39   cout<<"WARNING: You already have a merged output for SP !!!!"<<endl;
40   break;
41  }
42  spFileMerger->OutputFile(mergedFileNameSP);
43  
44  // GFC:                       
45  TFileMerger *gfcFileMerger = new TFileMerger();
46  TString mergedFileNameGFC("mergedGFCanalysis");
47  (mergedFileNameGFC+=(type.Data()))+=(".root");
48  TString pwdGFC=pwd.Data(); 
49  if(!(gSystem->AccessPathName((pwdGFC+=mergedFileNameGFC).Data(),kFileExists)))
50  {
51   cout<<"WARNING: You already have a merged output for GFC !!!!"<<endl;
52   break;
53  }
54  gfcFileMerger->OutputFile(mergedFileNameGFC);
55  
56  // QC:                       
57  TFileMerger *qcFileMerger = new TFileMerger();
58  TString mergedFileNameQC("mergedQCanalysis");
59  (mergedFileNameQC+=(type.Data()))+=(".root");
60  TString pwdQC=pwd.Data(); 
61  if(!(gSystem->AccessPathName((pwdQC+=mergedFileNameQC).Data(),kFileExists)))
62  {
63   cout<<"WARNING: You already have a merged output for QC !!!!"<<endl;
64   break;
65  }
66  qcFileMerger->OutputFile(mergedFileNameQC);
67  
68  // FQD:                       
69  TFileMerger *fqdFileMerger = new TFileMerger();
70  TString mergedFileNameFQD("mergedFQDanalysis");
71  (mergedFileNameFQD+=(type.Data()))+=(".root");
72  TString pwdFQD=pwd.Data(); 
73  if(!(gSystem->AccessPathName((pwdFQD+=mergedFileNameFQD).Data(),kFileExists)))
74  {
75   cout<<"WARNING: You already have a merged output for FQD !!!!"<<endl;
76   break;
77  }
78  fqdFileMerger->OutputFile(mergedFileNameFQD);
79  
80  // LYZ1:                       
81  TFileMerger *lyz1FileMerger = new TFileMerger();
82  TString mergedFileNameLYZ1("mergedLYZ1analysis");
83  (mergedFileNameLYZ1+=(type.Data()))+=(".root");
84  TString pwdLYZ1=pwd.Data(); 
85  if(!(gSystem->AccessPathName((pwdLYZ1+=mergedFileNameLYZ1).Data(),kFileExists)))
86  {
87   cout<<"WARNING: You already have a merged output for LYZ1 !!!!"<<endl;
88   break;
89  }
90  lyz1FileMerger->OutputFile(mergedFileNameLYZ1);
91  
92  // LYZ2:                       
93  TFileMerger *lyz2FileMerger = new TFileMerger();
94  TString mergedFileNameLYZ2("mergedLYZ2analysis");
95  (mergedFileNameLYZ2+=(type.Data()))+=(".root");
96  TString pwdLYZ2=pwd.Data(); 
97  if(!(gSystem->AccessPathName((pwdLYZ2+=mergedFileNameLYZ2).Data(),kFileExists)))
98  {
99   cout<<"WARNING: You already have a merged output for LYZ2 !!!!"<<endl;
100   break;
101  }
102  lyz2FileMerger->OutputFile(mergedFileNameLYZ2);
103  
104  // LYZEP:                       
105  TFileMerger *lyzepFileMerger = new TFileMerger();
106  TString mergedFileNameLYZEP("mergedLYZEPanalysis");
107  (mergedFileNameLYZEP+=(type.Data()))+=(".root");
108  TString pwdLYZEP=pwd.Data(); 
109  if(!(gSystem->AccessPathName((pwdLYZEP+=mergedFileNameLYZEP).Data(),kFileExists)))
110  {
111   cout<<"WARNING: You already have a merged output for LYZEP !!!!"<<endl;
112   break;
113  }
114  lyzepFileMerger->OutputFile(mergedFileNameLYZEP);
115  
116  // standard magic:
117  TString execDir(gSystem->pwd());  
118  TSystemDirectory* baseDir = new TSystemDirectory(".",execDir.Data());          
119  TList* dirList = baseDir->GetListOfFiles();
120  Int_t nDirs = dirList->GetEntries();
121  gSystem->cd(execDir);          
122
123  Int_t counter = 0;
124   
125  for(Int_t iDir=0;iDir<nDirs;++iDir)
126  {
127   TSystemFile* presentDir = (TSystemFile*)dirList->At(iDir);
128   if(!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || 
129      strcmp(presentDir->GetName(), "..") == 0) continue; 
130    
131   if(nRuns != -1)
132   {               
133    if (counter >= nRuns) break;       
134   } 
135                        
136   TString presentDirName(gSystem->pwd()); 
137   presentDirName += "/";
138   presentDirName += presentDir->GetName();
139   presentDirName += "/";
140    
141   // accessing the output .root files from independent analysis for each method:
142   // MCEP:     
143   TString fileNameMCEP = presentDirName;   
144   ((fileNameMCEP+="outputMCEPanalysis")+=type.Data())+=".root";
145   if(!(gSystem->AccessPathName(fileNameMCEP.Data(),kFileExists)))
146   {
147    mcepFileMerger->AddFile(fileNameMCEP.Data());
148   } else 
149     {
150      cout<<"WARNING: Couldn't find a file "<<fileNameMCEP.Data()<<". Merging will continue without this file."<<endl;
151     }  
152     
153   // SP:     
154   TString fileNameSP = presentDirName;   
155   ((fileNameSP+="outputSPanalysis")+=type.Data())+=".root";
156   if(!(gSystem->AccessPathName(fileNameSP.Data(),kFileExists)))
157   {
158    spFileMerger->AddFile(fileNameSP.Data());
159   } else 
160     {
161      cout<<"WARNING: Couldn't find a file "<<fileNameSP.Data()<<". Merging will continue without this file."<<endl;
162     }  
163     
164   // GFC:     
165   TString fileNameGFC = presentDirName;   
166   ((fileNameGFC+="outputGFCanalysis")+=type.Data())+=".root";
167   if(!(gSystem->AccessPathName(fileNameGFC.Data(),kFileExists)))
168   {
169    gfcFileMerger->AddFile(fileNameGFC.Data());
170   } else 
171     {
172      cout<<"WARNING: Couldn't find a file "<<fileNameGFC.Data()<<". Merging will continue without this file."<<endl;
173     }    
174         
175   // QC:     
176   TString fileNameQC = presentDirName;   
177   ((fileNameQC+="outputQCanalysis")+=type.Data())+=".root";
178   if(!(gSystem->AccessPathName(fileNameQC.Data(),kFileExists)))
179   {
180    qcFileMerger->AddFile(fileNameQC.Data());
181   } else 
182     {
183      cout<<"WARNING: Couldn't find a file "<<fileNameQC.Data()<<". Merging will continue without this file."<<endl;
184     }   
185     
186   // FQD:     
187   TString fileNameFQD = presentDirName;   
188   ((fileNameFQD+="outputFQDanalysis")+=type.Data())+=".root";
189   if(!(gSystem->AccessPathName(fileNameFQD.Data(),kFileExists)))
190   {
191    fqdFileMerger->AddFile(fileNameFQD.Data());
192   } else 
193     {
194      cout<<"WARNING: Couldn't find a file "<<fileNameFQD.Data()<<". Merging will continue without this file."<<endl;
195     }   
196   
197   // LYZ1:     
198   TString fileNameLYZ1 = presentDirName;   
199   ((fileNameLYZ1+="outputLYZ1analysis")+=type.Data())+=".root";
200   if(!(gSystem->AccessPathName(fileNameLYZ1.Data(),kFileExists)))
201   {
202    lyz1FileMerger->AddFile(fileNameLYZ1.Data());
203   } else 
204     {
205      cout<<"WARNING: Couldn't find a file "<<fileNameLYZ1.Data()<<". Merging will continue without this file."<<endl;
206     }   
207     
208   // LYZ2:     
209   TString fileNameLYZ2 = presentDirName;   
210   ((fileNameLYZ2+="outputLYZ2analysis")+=type.Data())+=".root";
211   if(!(gSystem->AccessPathName(fileNameLYZ2.Data(),kFileExists)))
212   {
213    lyz2FileMerger->AddFile(fileNameLYZ2.Data());
214   } else 
215     {
216      cout<<"WARNING: Couldn't find a file "<<fileNameLYZ2.Data()<<". Merging will continue without this file."<<endl;
217     }     
218     
219   // LYZEP:     
220   TString fileNameLYZEP = presentDirName;   
221   ((fileNameLYZEP+="outputLYZEPanalysis")+=type.Data())+=".root";
222   if(!(gSystem->AccessPathName(fileNameLYZEP.Data(),kFileExists)))
223   {
224    lyzepFileMerger->AddFile(fileNameLYZEP.Data());
225   } else 
226     {
227      cout<<"WARNING: Couldn't find a file "<<fileNameLYZEP.Data()<<". Merging will continue without this file."<<endl;
228     }       
229    
230   counter++;
231   
232  } // end of for(Int_t iDir=0;iDir<nDirs;++iDir)
233  
234  // merge everything:
235  if(mcepFileMerger)
236  {
237   cout<<endl;
238   cout<<" ---- Starting to merge MCEP files ----"<<endl;
239   mcepFileMerger->Merge();
240  } 
241  if(spFileMerger)
242  {
243   cout<<endl;
244   cout<<" ---- Starting to merge SP files ----"<<endl;
245   spFileMerger->Merge();
246  }
247  if(gfcFileMerger)
248  {
249   cout<<endl;
250   cout<<" ---- Starting to merge GFC files ----"<<endl;
251   gfcFileMerger->Merge();
252  }
253  if(qcFileMerger)
254  {
255   cout<<endl;
256   cout<<" ---- Starting to merge QC files ----"<<endl;
257   qcFileMerger->Merge();
258  }
259  if(fqdFileMerger)
260  {
261   cout<<endl;
262   cout<<" ---- Starting to merge FQD files ----"<<endl;
263   fqdFileMerger->Merge();
264  }
265  if(lyz1FileMerger)
266  {
267   cout<<endl;
268   cout<<" ---- Starting to merge LYZ1 files ----"<<endl;
269   lyz1FileMerger->Merge();
270  }
271  if(lyz2FileMerger)
272  {
273   cout<<endl;
274   cout<<" ---- Starting to merge LYZ2 files ----"<<endl;
275   lyz2FileMerger->Merge();
276  }
277  if(lyzepFileMerger)
278  {
279   cout<<endl;
280   cout<<" ---- Starting to merge LYZEP files ----"<<endl;
281   lyzepFileMerger->Merge();
282  }
283  
284 } // end of void mergeOutput(TString type="", const Int_t nRuns=-1, Int_t mode=mLocal)
285
286 void LoadSpreadLibrariesMO(const libModes mode) {
287   
288   //--------------------------------------
289   // Load the needed libraries most of them already loaded by aliroot
290   //--------------------------------------
291   gSystem->Load("libTree.so");
292   gSystem->Load("libGeom.so");
293   gSystem->Load("libVMC.so");
294   gSystem->Load("libXMLIO.so");
295   gSystem->Load("libPhysics.so");
296   
297   //----------------------------------------------------------
298   // >>>>>>>>>>> Local mode <<<<<<<<<<<<<< 
299   //----------------------------------------------------------
300   if (mode==mLocal) {
301     //--------------------------------------------------------
302     // If you want to use already compiled libraries 
303     // in the aliroot distribution
304     //--------------------------------------------------------
305
306   //==================================================================================  
307   //load needed libraries:
308   gSystem->AddIncludePath("-I$ROOTSYS/include");
309   gSystem->Load("libTree.so");
310
311   // for AliRoot
312   gSystem->AddIncludePath("-I$ALICE_ROOT/include");
313   gSystem->Load("libANALYSIS.so");
314   gSystem->Load("libPWG2flowCommon.so");
315   cerr<<"libPWG2flowCommon.so loaded ..."<<endl;
316   
317   }
318   
319   else if (mode==mLocalSource) {
320  
321     // In root inline compile
322   
323     // Constants  
324     gROOT->LoadMacro("AliFlowCommon/AliFlowCommonConstants.cxx+");
325     gROOT->LoadMacro("AliFlowCommon/AliFlowLYZConstants.cxx+");
326     gROOT->LoadMacro("AliFlowCommon/AliFlowCumuConstants.cxx+");
327     
328     // Flow event
329     gROOT->LoadMacro("AliFlowCommon/AliFlowVector.cxx+"); 
330     gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimple.cxx+");    
331     gROOT->LoadMacro("AliFlowCommon/AliFlowEventSimple.cxx+");
332     
333     // Cuts
334     gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimpleCuts.cxx+");    
335     
336     // Output histosgrams
337     gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHist.cxx+");
338     gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHistResults.cxx+");
339     gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist1.cxx+");
340     gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist2.cxx+");
341        
342     cout << "finished loading macros!" << endl;  
343     
344   } // end of else if (mode==mLocalSource) 
345   
346 } // end of void LoadSpreadLibrariesMO(const libModes mode)
347
348