]>
Commit | Line | Data |
---|---|---|
0309ed6a | 1 | /* |
2 | Merge calibration entry macro: | |
3 | ||
4 | Example usage: | |
5 | ||
6 | .L $ALICE_ROOT/ANALYSIS/macros/mergeCalibObjects.C | |
7 | mergeCalibObjects() | |
8 | ||
9 | */ | |
10 | ||
11 | #if !defined(__CINT__) || defined(__MAKECINT__) | |
12 | ||
13 | #include <fstream> | |
14 | #include "TSystem.h" | |
15 | #include "TFile.h" | |
16 | #include "TObjArray.h" | |
17 | #include "AliSysInfo.h" | |
18 | #include "AliTPCcalibBase.h" | |
19 | #include "TH1F.h" | |
20 | #include "TMethodCall.h" | |
21 | ||
22 | #endif | |
23 | ||
24 | void IterTXT( const char * fileList="calib.list",Bool_t separate); | |
25 | void Merge(TFile* fileIn, TObjArray * array); | |
26 | void StoreResults(TObjArray * array); | |
27 | ||
28 | ||
29 | void mergeCalibObjects( const char * fileList="calib.list",Bool_t separate=kFALSE){ | |
30 | ||
31 | // main function | |
32 | ||
33 | IterTXT(fileList,separate ); | |
34 | } | |
35 | ||
36 | void LoadLib(){ | |
37 | ||
38 | // Loading the necessary libraries | |
39 | ||
40 | gSystem->Load("libANALYSIS"); | |
41 | gSystem->Load("libTPCcalib"); | |
42 | TH1::AddDirectory(0); | |
43 | } | |
44 | ||
45 | ||
46 | void IterXML(){ | |
47 | ||
48 | // iterating over the files coming from an XML collection | |
49 | // to be implemented | |
50 | ||
51 | LoadLib(); | |
52 | } | |
53 | ||
54 | void IterTXT( const char * fileList, Bool_t separate){ | |
55 | ||
56 | // Merge the files indicated in the list - fileList | |
57 | // ASCII file opition example: | |
58 | // find `pwd`/ | grep AliESDfriends_v1.root > calib.list | |
59 | ||
60 | LoadLib(); | |
61 | TObjArray * mergeArray= new TObjArray; | |
62 | ||
63 | // Open the input stream | |
64 | ||
65 | ifstream in; | |
66 | in.open(fileList); | |
67 | // Read the input list of files | |
68 | TString objfile; | |
69 | Int_t counter=0; | |
70 | while(in.good()) { | |
71 | in >> objfile; | |
72 | if (!objfile.Contains("root")) continue; // protection | |
73 | printf("Open file:Counter\t%d\tMerging file %s\n",counter++,objfile.Data()); | |
74 | TFile currentFile(objfile.Data()); | |
75 | Merge(¤tFile, mergeArray); | |
76 | } | |
77 | if (separate) | |
78 | StoreSeparateResults(mergeArray); | |
79 | else | |
80 | StoreResults(mergeArray); | |
81 | delete mergeArray; | |
82 | } | |
83 | ||
84 | void StoreResults(TObjArray * array){ | |
85 | ||
86 | // Storing the results in one single file | |
87 | ||
88 | TFile *f = new TFile("CalibObjects.root","recreate"); | |
89 | for (Int_t i=0; i<array->GetEntries(); i++){ | |
90 | TObject *object0 = array->At(i); | |
91 | if (!object0) continue; | |
92 | object0->Write(); | |
93 | } | |
94 | f->Close(); | |
95 | delete f; | |
96 | } | |
97 | ||
98 | ||
99 | void StoreSeparateResults(TObjArray * array){ | |
100 | ||
101 | // Store the results in separate files (one per object) | |
102 | ||
103 | for (Int_t i=0; i<array->GetEntries(); i++){ | |
104 | TObject *object0 = array->At(i); | |
105 | if (!object0) continue; | |
106 | TFile *f = new TFile(Form("CalibObjects_%s.root",object0->GetName()),"recreate"); | |
107 | object0->Write(); | |
108 | f->Close(); | |
109 | delete f; | |
110 | } | |
111 | } | |
112 | ||
113 | ||
114 | ||
115 | void Merge(TFile* fileIn, TObjArray * array){ | |
116 | ||
117 | // Merging procedure | |
118 | ||
119 | TObjArray *carray = new TObjArray; //array of the objects inside current file | |
120 | carray->SetOwner(kTRUE); | |
121 | ||
122 | // load all objects to memory | |
123 | ||
124 | TList *farr = fileIn->GetListOfKeys(); | |
125 | if (!farr) return; | |
126 | for (Int_t ical=0; ical<farr->GetEntries(); ical++){ | |
127 | if (!farr->At(ical)) continue; | |
128 | TObject *obj = fileIn->Get(farr->At(ical)->GetName()); | |
129 | if (obj) carray->AddLast(obj); | |
130 | AliSysInfo::AddStamp(farr->At(ical)->GetName(),1,ical); | |
131 | } | |
132 | ||
133 | if (carray->GetEntries()==0) return; | |
134 | TMethodCall callEnv; | |
135 | ||
136 | for (Int_t i=0; i<carray->GetEntries(); i++){ | |
137 | ||
138 | TObjArray *templist = new TObjArray(1); | |
139 | templist->SetOwner(kFALSE); | |
140 | TObject *currentObject = carray->At(i); | |
141 | if (!currentObject) continue; | |
142 | printf("%s\n",currentObject->GetName()); | |
143 | callEnv.InitWithPrototype(currentObject->IsA(), "Merge", "TCollection*"); | |
144 | if (!callEnv.IsValid()) {continue;} | |
145 | ||
146 | TObject *mergedObject = array->FindObject(currentObject->GetName()); | |
147 | if (!mergedObject) { | |
148 | array->AddLast(currentObject); | |
149 | carray->RemoveAt(i); | |
150 | continue; | |
151 | } | |
152 | templist->AddLast(currentObject); | |
153 | callEnv.SetParam((Long_t) templist); | |
154 | callEnv.Execute(mergedObject); | |
155 | delete templist; | |
156 | } | |
157 | delete carray; | |
158 | } |