]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FLOW/macros/mergeOutput.C
cleanup of structure
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / mergeOutput.C
CommitLineData
57340a27 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:
ad87ae62 4// 1.) In directory <dir> there are subdirectories <subdir1>, <subdir2>, ...;
57340a27 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>;
ad87ae62 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.
18
23965fa2 19enum libModes {mLocal,mLocalSource};
20
21void mergeOutput(Int_t mode=mLocal)
fe11f681 22{
23965fa2 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
57340a27 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";
57340a27 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;
32 if(cycle>500)
fe11f681 33 {
9455e15e 34 cout<<"WARNING: Cycle is too big !!!!"<<endl;
57340a27 35 cout<<" Set \"const Int_t cycle\" to smaller value in the macro."<<endl;
9455e15e 36 exit(0);
fe11f681 37 }
23965fa2 38 // Load needed flow libraries:
39 LoadLibrariesMO(mode);
57340a27 40 // Standard magic:
9455e15e 41 TString *baseDirPath = new TString(gSystem->pwd());
ad87ae62 42 TSystemDirectory *baseDir = new TSystemDirectory(".",baseDirPath->Data());
43 TList *listOfFilesInBaseDir = baseDir->GetListOfFiles();
57340a27 44 TStopwatch timer;
45 timer.Start();
9455e15e 46 // listOfFilesInBaseDir->Print();
47 Int_t nFiles = listOfFilesInBaseDir->GetEntries();
57340a27 48 // loop over all files and from each subdirectory add file AnalysisResults.root to TFileMerger:
ad87ae62 49 Int_t fileCounter = 0;
57340a27 50 TFileMerger *fileMerger = new TFileMerger();
9455e15e 51 for(Int_t iFile=0;iFile<nFiles;iFile++)
fe11f681 52 {
57340a27 53 TSystemFile *currentFile = (TSystemFile*)listOfFilesInBaseDir->At(iFile);
54 // Consider only subdirectories:
55 if(!currentFile ||
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;
ad87ae62 64 fileName+=outputFileName.Data();
ad87ae62 65 if(!(gSystem->AccessPathName(fileName.Data(),kFileExists)))
947cc449 66 {
ad87ae62 67 fileCounter++;
68 fileMerger->AddFile(fileName.Data());
57340a27 69 // Merging in cycles:
ad87ae62 70 if(fileCounter % cycle == 0)
9455e15e 71 {
57340a27 72 // If the merged output from previous cycle exists add it to TFileMerger:
73 TString *mergedFileForPreviousCycle = new TString("mergedCycle");
ad87ae62 74 (*mergedFileForPreviousCycle)+=(fileCounter/cycle - 1);
75 (*mergedFileForPreviousCycle)+=".root";
ad87ae62 76 if(!(gSystem->AccessPathName(mergedFileForPreviousCycle->Data(),kFileExists)))
9455e15e 77 {
ad87ae62 78 fileMerger->AddFile(mergedFileForPreviousCycle->Data());
57340a27 79 // Delete merged output from previous cycle:
80 TSystemFile *file = new TSystemFile(mergedFileForPreviousCycle->Data(),baseDirPath->Data());
9455e15e 81 file->Delete();
82 delete file;
57340a27 83 }
84 // Create merged output for current cycle:
85 TString *mergedFileForCurrentCycle = new TString("mergedCycle");
ad87ae62 86 (*mergedFileForCurrentCycle)+=(fileCounter/cycle);
57340a27 87 (*mergedFileForCurrentCycle)+=".root";
ad87ae62 88 fileMerger->OutputFile(mergedFileForCurrentCycle->Data());
89 fileMerger->Merge();
57340a27 90 fileMerger->Reset();
ad87ae62 91 delete mergedFileForPreviousCycle;
92 delete mergedFileForCurrentCycle;
93 } // end of if(fileCounter % cycle == 0)
94 } // end of if(!(gSystem->AccessPathName(fileName.Data(),kFileExists)))
9455e15e 95 } // end of for(Int_t iFile=0;iFile<nFiles;iFile++)
fe11f681 96
9455e15e 97
98 //=================================================================================================
99
100
57340a27 101 // Final merging at the end of the day (3 distinct cases):
102 if(fileCounter==0)
103 {
104 cout<<endl;
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;
107 cout<<endl;
108 exit(0);
109 }
9455e15e 110 gSystem->cd(baseDirPath->Data());
ad87ae62 111 if(fileCounter < cycle)
112 {
57340a27 113 fileMerger->OutputFile(mergedFileName.Data());
ad87ae62 114 fileMerger->Merge();
57340a27 115 } else if(fileCounter % cycle == 0)
ad87ae62 116 {
57340a27 117 TString *mergedFileForPreviousCycle = new TString("mergedCycle");
ad87ae62 118 (*mergedFileForPreviousCycle)+=(fileCounter/cycle);
119 (*mergedFileForPreviousCycle)+=".root";
120 if(!(gSystem->AccessPathName(mergedFileForPreviousCycle->Data(),kFileExists)))
121 {
57340a27 122 gSystem->Rename(mergedFileForPreviousCycle->Data(),mergedFileName.Data());
123 }
9455e15e 124 } else
125 {
57340a27 126 TString *mergedFileForPreviousCycle = new TString("mergedCycle");
ad87ae62 127 (*mergedFileForPreviousCycle)+=((Int_t)fileCounter/cycle);
57340a27 128 (*mergedFileForPreviousCycle)+=".root";
ad87ae62 129 fileMerger->AddFile(mergedFileForPreviousCycle->Data());
57340a27 130 // Delete merged output from previous cycle:
131 TSystemFile *file = new TSystemFile(mergedFileForPreviousCycle->Data(),baseDirPath->Data());
9455e15e 132 file->Delete();
133 delete file;
57340a27 134 fileMerger->OutputFile(mergedFileName.Data());
ad87ae62 135 fileMerger->Merge();
ad87ae62 136 delete mergedFileForPreviousCycle;
9455e15e 137 }
ad87ae62 138 delete fileMerger;
9455e15e 139 delete baseDirPath;
140 delete baseDir;
fe11f681 141
57340a27 142 cout<<endl;
143 timer.Stop();
144 timer.Print();
145 cout<<endl;
146 if(!(gSystem->AccessPathName(mergedFileName.Data(),kFileExists)))
147 {
148 cout<<"Merging went successfully: "<<fileCounter<<" files "<<outputFileName.Data()<<" were"<<endl;
149 cout<<"merged into the newly created file "<<mergedFileName.Data()<<"."<<endl;
150 cout<<endl;
151 cout<<"Launch now macro redoFinish.C to get the correct final results."<<endl;
152 } else
153 {
154 cout<<"WARNING: Merging failed !!!!"<<endl;
155 }
156 cout<<endl;
23965fa2 157} // End of void mergeOutput(Int_t mode=mLocal)
158
159
160void LoadLibrariesMO(const libModes mode) {
161
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");
170
171 //----------------------------------------------------------
172 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
173 //----------------------------------------------------------
174 if (mode==mLocal) {
175 //--------------------------------------------------------
176 // If you want to use already compiled libraries
177 // in the aliroot distribution
178 //--------------------------------------------------------
179
180 //==================================================================================
181 //load needed libraries:
182 gSystem->AddIncludePath("-I$ROOTSYS/include");
183 //gSystem->Load("libTree");
184
185 // for AliRoot
186 gSystem->AddIncludePath("-I$ALICE_ROOT/include");
187 gSystem->Load("libANALYSIS");
188 gSystem->Load("libPWG2flowCommon");
189 //cerr<<"libPWG2flowCommon loaded ..."<<endl;
190
191 }
192
193 else if (mode==mLocalSource) {
194
195 // In root inline compile
196
197 // Constants
198 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonConstants.cxx+");
199 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZConstants.cxx+");
23965fa2 200
201 // Flow event
202 gROOT->LoadMacro("AliFlowCommon/AliFlowVector.cxx+");
5062cb0f 203 gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimple.cxx+");
23965fa2 204 gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimpleCuts.cxx+");
5062cb0f 205 gROOT->LoadMacro("AliFlowCommon/AliFlowEventSimple.cxx+");
23965fa2 206
207 // Output histosgrams
208 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHist.cxx+");
209 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHistResults.cxx+");
210 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist1.cxx+");
211 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist2.cxx+");
212
213 cout << "finished loading macros!" << endl;
214
215 } // end of else if (mode==mLocalSource)
216
217} // end of void LoadLibrariesMO(const libModes mode)
218