]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/PHOSTasks/PHOS_PbPb/macros/QA/FillMerge.C
8ea890e9a55bb25db5ca5a755c204ba8456a41c6
[u/mrichter/AliRoot.git] / PWGGA / PHOSTasks / PHOS_PbPb / macros / QA / FillMerge.C
1 #include "TFileMerger.h"
2 #include "TSystem.h"
3
4 #include <map>
5 #include <iostream>
6 #include <fstream>
7 #include <string>
8
9 std::map<int, int> runToFill; // maps: run -> fill
10 std::map<int, TFileMerger*> fillToMerger;
11
12 void makeFillMap()
13 {
14 }
15
16 void FillMerge(const TString filelist="filelist.txt",
17                const TString runlist="runlist.txt",
18                const TString runFillFile = "run_fill.txt")
19 {
20   // Use to merge run files to fill files
21   // For some reason, it does not work without compiling:
22   // .L FillMerge.C+g
23   // FillMerge()
24   //
25   // run_fill.txt must be a two column txt file, 
26   // column 1 being run and column 2 being fill.
27
28   //TGrid::Connect("alien://");
29   
30
31   // Make runToFill map
32   std::ifstream rfin;
33   rfin.open(runFillFile.Data());
34   
35   while (1) {
36     int run=0, fill=0;
37     rfin >> run >> fill;
38     if (!rfin.good()) break;
39     runToFill[run] = fill;
40   }
41
42
43   // Make FillMergers and add run files to them.
44   std::ifstream in;
45   in.open(filelist.Data());
46   std::ifstream inRuns;
47   inRuns.open(runlist.Data());
48   char rootFileName[256];
49   Int_t runNumber=0;
50   while (1) {
51     in >> rootFileName;
52     if (!in.good()) break;
53     inRuns >> runNumber;
54     if (!inRuns.good()) break;
55     
56     if(169094 == runNumber ) 
57       continue;
58
59     if( ! runToFill.count(runNumber) ) {
60       Printf("can't map run %d to fill, not in file %s", runNumber, runFillFile.Data());
61       continue;
62     }
63     
64     int fill = runToFill[runNumber];
65     
66     if( ! fillToMerger.count( fill ) ) { // if no merger for fill
67       fillToMerger[fill] = new TFileMerger(); // create merger
68       gSystem->mkdir("fillMerge");
69       fillToMerger[fill]->OutputFile(Form("fillMerge/%d.root", fill));
70     }
71     
72     fillToMerger[fill]->AddFile(rootFileName);
73   }
74
75   std::ofstream fls("fillList.txt");
76   std::ofstream ffls("fillFileList.txt");
77
78   
79   // Merge:
80   std::map<int, TFileMerger*>::iterator it;
81   for( it = fillToMerger.begin(); it != fillToMerger.end(); ++it ) {
82     TFileMerger* fm = (*it).second;
83     Printf("merging %s", fm->GetOutputFileName());
84     fm->Merge();
85     fls << (*it).first << std::endl;
86     ffls << fm->GetOutputFileName() << std::endl;
87     delete fm;
88   }
89
90 }