]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FLOW/macros/mergeOutputOnGrid.C
cleanup of structure
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / mergeOutputOnGrid.C
CommitLineData
57340a27 1// Macro mergeOutputOnGrid.C is used to merge output files "AnalysisResults.root"
2// from the AliEn file catalog. It produces the merged, larged statistics file
3// "mergedAnalysisResults.root". To get the final flow estimates for the large
4// statistics file use macro redoFinish.C (see comments in macro mergeOutput.C
5// for more details).
6
7void mergeOutputOnGrid(const char* gridPath = "/alice/cern.ch/user/a/abilandz/flowAnalysisOnGrid/output*")
8{
9 // Name of the output files to be merged:
10 TString outputFileName = "AnalysisResults.root";
11 // Name of the merged, large statistics file:
12 TString mergedFileName = "mergedAnalysisResults.root";
13 // Load needed flow libraries:
14 gSystem->AddIncludePath("-I$ROOTSYS/include");
15 gSystem->AddIncludePath("-I$ALICE_ROOT/include");
16 gSystem->Load("libPWG2flowCommon");
17 cerr<<"Library \"libPWG2flowCommon\" loaded ...."<<endl;
18 // Connect to the GRID:
19 TGrid::Connect("alien://");
20 // Query the file catalog and get a TGridResult:
21 TString queryPattern = outputFileName;
22 TGridResult *result = gGrid->Query(gridPath,queryPattern.Data());
23 Int_t nEntries = result->GetEntries();
24 Printf("\nFound %d files %s in %s ....\n",nEntries,outputFileName.Data(),gridPath);
25 // Create a TFileMerger:
26 TFileMerger *fileMerger = new TFileMerger();
27 // For a large number of output files merging is done in cycles
28 // and this is the cycle period:
29 const Int_t cycle = 500;
30 if(cycle>500)
31 {
32 cout<<"WARNING: Cycle is too big !!!!"<<endl;
33 cout<<" Set \"const Int_t cycle\" to smaller value in the macro."<<endl;
34 exit(0);
35 }
36 Int_t fileCounter = 0;
37 TString *baseDirPath = new TString(gSystem->pwd());
38 // Loop over the TGridResult's entries and add the files to the TFileMerger:
39 TString alienUrl;
40 for(Int_t i=0;i<nEntries;i++)
41 {
42 alienUrl = result->GetKey(i,"turl");
43 //Printf("%s",alienUrl.Data());
44 fileMerger->AddFile(alienUrl.Data());
45 fileCounter++;
46 // Merging in cycles:
47 if(fileCounter % cycle == 0)
48 {
49 // If the merged output from previous cycle exists add it to TFileMerger:
50 TString *mergedFileForPreviousCycle = new TString("mergedCycle");
51 (*mergedFileForPreviousCycle)+=(fileCounter/cycle - 1);
52 (*mergedFileForPreviousCycle)+=".root";
53 if(!(gSystem->AccessPathName(mergedFileForPreviousCycle->Data(),kFileExists)))
54 {
55 fileMerger->AddFile(mergedFileForPreviousCycle->Data());
56 // Delete merged output from previous cycle:
57 TSystemFile *file = new TSystemFile(mergedFileForPreviousCycle->Data(),baseDirPath->Data());
58 file->Delete();
59 delete file;
60 }
61 // Create merged output for current cycle:
62 TString *mergedFileForCurrentCycle = new TString("mergedCycle");
63 (*mergedFileForCurrentCycle)+=(fileCounter/cycle);
64 (*mergedFileForCurrentCycle)+=".root";
65 fileMerger->OutputFile(mergedFileForCurrentCycle->Data());
66 fileMerger->Merge();
67 fileMerger->Reset();
68 delete mergedFileForPreviousCycle;
69 delete mergedFileForCurrentCycle;
70 } // end of if(fileCounter % cycle == 0)
71 } // end of for(Int_t i=0;i<nEntries;i++)
72
73
74 //=================================================================================================
75
76
77 // Final merging at the end of the day (3 distinct cases):
78 gSystem->cd(baseDirPath->Data());
79 if(fileCounter < cycle)
80 {
81 fileMerger->OutputFile(mergedFileName.Data());
82 fileMerger->Merge();
83 } else if(fileCounter % cycle == 0)
84 {
85 TString *mergedFileForPreviousCycle = new TString("mergedCycle");
86 (*mergedFileForPreviousCycle)+=(fileCounter/cycle);
87 (*mergedFileForPreviousCycle)+=".root";
88 if(!(gSystem->AccessPathName(mergedFileForPreviousCycle->Data(),kFileExists)))
89 {
90 gSystem->Rename(mergedFileForPreviousCycle->Data(),mergedFileName.Data());
91 }
92 } else
93 {
94 TString *mergedFileForPreviousCycle = new TString("mergedCycle");
95 (*mergedFileForPreviousCycle)+=((Int_t)fileCounter/cycle);
96 (*mergedFileForPreviousCycle)+=".root";
97 fileMerger->AddFile(mergedFileForPreviousCycle->Data());
98 // Delete merged output from previous cycle:
99 TSystemFile *file = new TSystemFile(mergedFileForPreviousCycle->Data(),baseDirPath->Data());
100 file->Delete();
101 delete file;
102 fileMerger->OutputFile(mergedFileName.Data());
103 fileMerger->Merge();
104 delete mergedFileForPreviousCycle;
105 }
106 delete fileMerger;
107 delete baseDirPath;
108}