1 // Macro mergeOutput.C is used to merge output files "AnalysisResults.root" locally.
2 // (To merge output files "AnalysisResults.root" on Grid use macro mergeOutputOnGrid.C.)
3 // Its usage relies on the following directory structure and naming conventions:
4 // 1.) In directory <dir> there are subdirectories <subdir1>, <subdir2>, ...;
5 // 2.) In subdirectory <subdir*> there is a file named "AnalysisResults.root";
6 // 3.) Copy macro mergeOutput.C in directory <dir> and launch it. It will automatically
7 // access from each subdirectory a file "AnalysisResults.root" and by making use of
8 // TFileMerger utility it will produce a merged file "mergedAnalysisResults.root"
9 // and save it in directory <dir>;
10 // 4.) IMPORTANT: Macro mergeOutput.C must be used in a combination with macro redoFinish.C
11 // in order to get the analysis done on merged, large statistics sample. In particular,
12 // after you got the file "mergedAnalysisResults.root", copy macro redoFinish.C in
13 // directory <dir> and launch it. This macro will access "mergedAnalysisResults.root"
14 // and produce the output file "AnalysisResults.root" in directory <dir>. This file will
15 // hold the final results for merged, large statistics sample.
16 // 5.) REMARK: To see plots for some of the results use macro compareFlowResults.C. This macro
17 // accesses file "AnalysisResults.root" and produces couple of predefined example plots.
19 enum libModes {mLocal,mLocalSource};
21 void mergeOutput(Int_t mode=mLocal)
23 // mode: if mode = mLocal: analyze data on your computer using aliroot
24 // if mode = mLocalSource: analyze data on your computer using root + source files
25 // Name of the output files to be merged:
26 TString outputFileName = "AnalysisResults.root";
27 // Name of the merged, large statistics file:
28 TString mergedFileName = "mergedAnalysisResults.root";
29 // For a large number of output files merging is done in cycles
30 // and this is the cycle period:
31 const Int_t cycle = 500;
34 cout<<"WARNING: Cycle is too big !!!!"<<endl;
35 cout<<" Set \"const Int_t cycle\" to smaller value in the macro."<<endl;
38 // Load needed flow libraries:
39 LoadLibrariesMO(mode);
41 TString *baseDirPath = new TString(gSystem->pwd());
42 TSystemDirectory *baseDir = new TSystemDirectory(".",baseDirPath->Data());
43 TList *listOfFilesInBaseDir = baseDir->GetListOfFiles();
46 // listOfFilesInBaseDir->Print();
47 Int_t nFiles = listOfFilesInBaseDir->GetEntries();
48 // loop over all files and from each subdirectory add file AnalysisResults.root to TFileMerger:
49 Int_t fileCounter = 0;
50 TFileMerger *fileMerger = new TFileMerger();
51 for(Int_t iFile=0;iFile<nFiles;iFile++)
53 TSystemFile *currentFile = (TSystemFile*)listOfFilesInBaseDir->At(iFile);
54 // Consider only subdirectories:
56 !currentFile->IsDirectory() ||
57 strcmp(currentFile->GetName(), ".") == 0 ||
58 strcmp(currentFile->GetName(), "..") == 0) continue;
59 // Accessing the output file "AnalysisResults.root" in current subdirectory:
60 TString currentSubDirName = baseDirPath->Data();
61 (currentSubDirName+="/")+=currentFile->GetName();
62 currentSubDirName+="/";
63 TString fileName = currentSubDirName;
64 fileName+=outputFileName.Data();
65 if(!(gSystem->AccessPathName(fileName.Data(),kFileExists)))
68 fileMerger->AddFile(fileName.Data());
70 if(fileCounter % cycle == 0)
72 // If the merged output from previous cycle exists add it to TFileMerger:
73 TString *mergedFileForPreviousCycle = new TString("mergedCycle");
74 (*mergedFileForPreviousCycle)+=(fileCounter/cycle - 1);
75 (*mergedFileForPreviousCycle)+=".root";
76 if(!(gSystem->AccessPathName(mergedFileForPreviousCycle->Data(),kFileExists)))
78 fileMerger->AddFile(mergedFileForPreviousCycle->Data());
79 // Delete merged output from previous cycle:
80 TSystemFile *file = new TSystemFile(mergedFileForPreviousCycle->Data(),baseDirPath->Data());
84 // Create merged output for current cycle:
85 TString *mergedFileForCurrentCycle = new TString("mergedCycle");
86 (*mergedFileForCurrentCycle)+=(fileCounter/cycle);
87 (*mergedFileForCurrentCycle)+=".root";
88 fileMerger->OutputFile(mergedFileForCurrentCycle->Data());
91 delete mergedFileForPreviousCycle;
92 delete mergedFileForCurrentCycle;
93 } // end of if(fileCounter % cycle == 0)
94 } // end of if(!(gSystem->AccessPathName(fileName.Data(),kFileExists)))
95 } // end of for(Int_t iFile=0;iFile<nFiles;iFile++)
98 //=================================================================================================
101 // Final merging at the end of the day (3 distinct cases):
105 cout<<"Merger wasn't lucky: Couldn't find a single file "<<outputFileName.Data()<<" to merge"<<endl;
106 cout<<"in subdirectories of directory "<<baseDirPath->Data()<<endl;
110 gSystem->cd(baseDirPath->Data());
111 if(fileCounter < cycle)
113 fileMerger->OutputFile(mergedFileName.Data());
115 } else if(fileCounter % cycle == 0)
117 TString *mergedFileForPreviousCycle = new TString("mergedCycle");
118 (*mergedFileForPreviousCycle)+=(fileCounter/cycle);
119 (*mergedFileForPreviousCycle)+=".root";
120 if(!(gSystem->AccessPathName(mergedFileForPreviousCycle->Data(),kFileExists)))
122 gSystem->Rename(mergedFileForPreviousCycle->Data(),mergedFileName.Data());
126 TString *mergedFileForPreviousCycle = new TString("mergedCycle");
127 (*mergedFileForPreviousCycle)+=((Int_t)fileCounter/cycle);
128 (*mergedFileForPreviousCycle)+=".root";
129 fileMerger->AddFile(mergedFileForPreviousCycle->Data());
130 // Delete merged output from previous cycle:
131 TSystemFile *file = new TSystemFile(mergedFileForPreviousCycle->Data(),baseDirPath->Data());
134 fileMerger->OutputFile(mergedFileName.Data());
136 delete mergedFileForPreviousCycle;
146 if(!(gSystem->AccessPathName(mergedFileName.Data(),kFileExists)))
148 cout<<"Merging went successfully: "<<fileCounter<<" files "<<outputFileName.Data()<<" were"<<endl;
149 cout<<"merged into the newly created file "<<mergedFileName.Data()<<"."<<endl;
151 cout<<"Launch now macro redoFinish.C to get the correct final results."<<endl;
154 cout<<"WARNING: Merging failed !!!!"<<endl;
157 } // End of void mergeOutput(Int_t mode=mLocal)
160 void LoadLibrariesMO(const libModes mode) {
162 //--------------------------------------
163 // Load the needed libraries most of them already loaded by aliroot
164 //--------------------------------------
165 //gSystem->Load("libTree");
166 gSystem->Load("libGeom");
167 gSystem->Load("libVMC");
168 gSystem->Load("libXMLIO");
169 gSystem->Load("libPhysics");
171 //----------------------------------------------------------
172 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
173 //----------------------------------------------------------
175 //--------------------------------------------------------
176 // If you want to use already compiled libraries
177 // in the aliroot distribution
178 //--------------------------------------------------------
180 //==================================================================================
181 //load needed libraries:
182 gSystem->AddIncludePath("-I$ROOTSYS/include");
183 //gSystem->Load("libTree");
186 gSystem->AddIncludePath("-I$ALICE_ROOT/include");
187 gSystem->Load("libANALYSIS");
188 gSystem->Load("libPWG2flowCommon");
189 //cerr<<"libPWG2flowCommon loaded ..."<<endl;
193 else if (mode==mLocalSource) {
195 // In root inline compile
198 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonConstants.cxx+");
199 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZConstants.cxx+");
200 gROOT->LoadMacro("AliFlowCommon/AliFlowCumuConstants.cxx+");
203 gROOT->LoadMacro("AliFlowCommon/AliFlowVector.cxx+");
204 gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimple.cxx+");
205 gROOT->LoadMacro("AliFlowCommon/AliFlowEventSimple.cxx+");
208 gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimpleCuts.cxx+");
210 // Output histosgrams
211 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHist.cxx+");
212 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHistResults.cxx+");
213 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist1.cxx+");
214 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist2.cxx+");
216 cout << "finished loading macros!" << endl;
218 } // end of else if (mode==mLocalSource)
220 } // end of void LoadLibrariesMO(const libModes mode)