1 |
mocchiut |
1.1 |
// |
2 |
|
|
// C/C++ headers |
3 |
|
|
// |
4 |
|
|
#include <iostream> |
5 |
|
|
#include <iomanip> |
6 |
|
|
#include <fstream> |
7 |
|
|
#include <sstream> |
8 |
|
|
#include <string.h> |
9 |
|
|
// |
10 |
|
|
// ROOT headers |
11 |
|
|
// |
12 |
|
|
#include <TSQLServer.h> |
13 |
|
|
#include <TString.h> |
14 |
|
|
#include <TTimeStamp.h> |
15 |
|
|
#include <TFile.h> |
16 |
|
|
#include <TSystem.h> |
17 |
|
|
#include <TChain.h> |
18 |
|
|
#include <TH1.h> |
19 |
|
|
#include <TTree.h> |
20 |
|
|
#include <TKey.h> |
21 |
|
|
#include <Riostream.h> |
22 |
|
|
#include <TObjString.h> |
23 |
|
|
#include <TClass.h> |
24 |
|
|
// |
25 |
|
|
// Detector's package headers |
26 |
|
|
// |
27 |
|
|
#include <RunGlue.h> |
28 |
|
|
// |
29 |
|
|
using namespace std; |
30 |
|
|
// |
31 |
|
|
// |
32 |
|
|
// |
33 |
|
|
#include <PadmeAmidalaVerl2.h> |
34 |
|
|
// |
35 |
|
|
// |
36 |
|
|
// Usage subroutine |
37 |
|
|
// |
38 |
|
|
void amidalausage(){ |
39 |
|
|
printf("\nUsage:\n"); |
40 |
|
|
printf("\n Amidala [ options ]\n"); |
41 |
|
|
printf("\n Options are:\n\n"); |
42 |
|
|
printf(" --version print informations about compilation and exit\n"); |
43 |
|
|
printf(" -h | --help print this help and exit \n"); |
44 |
|
|
printf(" -g | --debug set debug flag\n"); |
45 |
|
|
printf(" -idRun run merge all runs in the directory which have the same date of run \"run\"\n"); |
46 |
|
|
printf(" -outdir dir output directory \"dir\"\n"); |
47 |
|
|
printf(" -dir dir merge all runs in the directory \"dir\"\n"); |
48 |
|
|
printf(" -d | -delete delete original DarthVader runs once merged\n"); |
49 |
|
|
printf(" -host name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); |
50 |
|
|
printf(" -user username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n"); |
51 |
|
|
printf(" -psw password for the DB connection [default = $PAM_DBPSW or \"\"]\n"); |
52 |
|
|
printf("\nExamples: \n"); |
53 |
|
|
printf(" Amidala -idRun 1085 \n"); |
54 |
|
|
printf(" Amidala -dir /home/pamela/level2/ \n\n"); |
55 |
|
|
}; |
56 |
|
|
// |
57 |
|
|
// Here the main |
58 |
|
|
// |
59 |
|
|
int main(int numinp, char *inps[]){ |
60 |
|
|
// |
61 |
|
|
// Variables booking |
62 |
|
|
// |
63 |
|
|
TString message; |
64 |
|
|
// |
65 |
|
|
UInt_t run = 0; |
66 |
|
|
// |
67 |
|
|
TString dir = ""; |
68 |
|
|
TString outdir = ""; |
69 |
|
|
TString dectlist = ""; |
70 |
|
|
// |
71 |
|
|
TSQLServer *dbc = 0; |
72 |
|
|
TString host = "mysql://localhost/pamelaprod"; |
73 |
|
|
TString user = "anonymous"; |
74 |
|
|
TString psw = ""; |
75 |
|
|
Bool_t debug = false; |
76 |
|
|
Bool_t delop = false; |
77 |
|
|
// |
78 |
|
|
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
79 |
|
|
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
80 |
|
|
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
81 |
|
|
if ( !pamdbhost ) pamdbhost = ""; |
82 |
|
|
if ( !pamdbuser ) pamdbuser = ""; |
83 |
|
|
if ( !pamdbpsw ) pamdbpsw = ""; |
84 |
|
|
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
85 |
|
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
86 |
|
|
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
87 |
|
|
// |
88 |
|
|
stringstream myquery; |
89 |
|
|
// |
90 |
|
|
// Checking input parameters |
91 |
|
|
// |
92 |
|
|
Int_t i = 0; |
93 |
|
|
if ( numinp > 1 ){ |
94 |
|
|
while ( i < numinp ){ |
95 |
|
|
if ( !strcmp(inps[i],"--version") ){ |
96 |
|
|
AmidalaInfo(true); |
97 |
|
|
exit(0); |
98 |
|
|
}; |
99 |
|
|
if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){ |
100 |
|
|
amidalausage(); |
101 |
|
|
exit(0); |
102 |
|
|
}; |
103 |
|
|
if ( !strcmp(inps[i],"-g") || !strcmp(inps[i],"--debug") ){ |
104 |
|
|
debug = true; |
105 |
|
|
}; |
106 |
|
|
if ( !strcmp(inps[i],"-d") || !strcmp(inps[i],"-delete") ){ |
107 |
|
|
delop = true; |
108 |
|
|
}; |
109 |
|
|
if ( !strcmp(inps[i],"-idRun") ) { |
110 |
|
|
if ( numinp-1 < i+1 ) { |
111 |
|
|
amidalausage(); |
112 |
|
|
exit(-3); |
113 |
|
|
}; |
114 |
|
|
run = (UInt_t)atoll(inps[i+1]); |
115 |
|
|
}; |
116 |
|
|
if ( !strcmp(inps[i],"-dir") ) { |
117 |
|
|
if ( numinp-1 < i+1 ){ |
118 |
|
|
amidalausage(); |
119 |
|
|
exit(-3); |
120 |
|
|
}; |
121 |
|
|
dir = (TString)inps[i+1]; |
122 |
|
|
}; |
123 |
|
|
if ( !strcmp(inps[i],"-outdir") ) { |
124 |
|
|
if ( numinp-1 < i+1 ){ |
125 |
|
|
amidalausage(); |
126 |
|
|
exit(-3); |
127 |
|
|
}; |
128 |
|
|
outdir = (TString)inps[i+1]; |
129 |
|
|
}; |
130 |
|
|
if ( !strcmp(inps[i],"-host") ) { |
131 |
|
|
if ( numinp-1 < i+1 ){ |
132 |
|
|
amidalausage(); |
133 |
|
|
exit(-3); |
134 |
|
|
}; |
135 |
|
|
host = (TString)inps[i+1]; |
136 |
|
|
}; |
137 |
|
|
if ( !strcmp(inps[i],"-user") ) { |
138 |
|
|
if ( numinp-1 < i+1 ){ |
139 |
|
|
amidalausage(); |
140 |
|
|
exit(-3); |
141 |
|
|
}; |
142 |
|
|
user = (TString)inps[i+1]; |
143 |
|
|
}; |
144 |
|
|
if ( !strcmp(inps[i],"-psw") ) { |
145 |
|
|
if ( numinp-1 < i+1 ){ |
146 |
|
|
amidalausage(); |
147 |
|
|
exit(-3); |
148 |
|
|
}; |
149 |
|
|
psw = (TString)inps[i+1]; |
150 |
|
|
}; |
151 |
|
|
// |
152 |
|
|
if ( !strcmp(inps[i],"-CAL") ) { |
153 |
|
|
dectlist +=" -CAL"; |
154 |
|
|
}; |
155 |
|
|
if ( !strcmp(inps[i],"-CAL1") ) { |
156 |
|
|
dectlist +=" -CAL1"; |
157 |
|
|
}; |
158 |
|
|
if ( !strcmp(inps[i],"-TRK") ) { |
159 |
|
|
dectlist +=" -TRK"; |
160 |
|
|
}; |
161 |
|
|
if ( !strcmp(inps[i],"-TRK1") ) { |
162 |
|
|
dectlist +=" -TRK1"; |
163 |
|
|
}; |
164 |
|
|
if ( !strcmp(inps[i],"-TRKh") ) { |
165 |
|
|
dectlist +=" -TRKh"; |
166 |
|
|
}; |
167 |
|
|
if ( !strcmp(inps[i],"-TOF") ) { |
168 |
|
|
dectlist +=" -TOF"; |
169 |
|
|
}; |
170 |
|
|
if ( !strcmp(inps[i],"-TRG") ) { |
171 |
|
|
dectlist +=" -TRG"; |
172 |
|
|
}; |
173 |
|
|
if ( !strcmp(inps[i],"-S4") ) { |
174 |
|
|
dectlist +=" -S4"; |
175 |
|
|
}; |
176 |
|
|
if ( !strcmp(inps[i],"-ND") ) { |
177 |
|
|
dectlist +=" -ND"; |
178 |
|
|
}; |
179 |
|
|
if ( !strcmp(inps[i],"-AC") ) { |
180 |
|
|
dectlist +=" -AC"; |
181 |
|
|
}; |
182 |
|
|
if ( !strcmp(inps[i],"-RUN") ) { |
183 |
|
|
dectlist +=" -RUN"; |
184 |
|
|
}; |
185 |
|
|
if ( !strcmp(inps[i],"-ORB") ) { |
186 |
|
|
dectlist +=" -ORB"; |
187 |
|
|
}; |
188 |
|
|
// |
189 |
|
|
if ( !strcmp(inps[i],"-all") || !strcmp(inps[i],"-ALL") ) { |
190 |
|
|
dectlist +=" -ALL"; |
191 |
|
|
}; |
192 |
|
|
// |
193 |
|
|
if ( !strcmp(inps[i],"+all") || !strcmp(inps[i],"+ALL") ) { |
194 |
|
|
dectlist +=" +ALL"; |
195 |
|
|
}; |
196 |
|
|
if ( !strcmp(inps[i],"+CAL") ) { |
197 |
|
|
dectlist +=" +CAL"; |
198 |
|
|
}; |
199 |
|
|
if ( !strcmp(inps[i],"+CAL1") ) { |
200 |
|
|
dectlist +=" +CAL1"; |
201 |
|
|
}; |
202 |
|
|
if ( !strcmp(inps[i],"+TRK") ) { |
203 |
|
|
dectlist +=" +TRK"; |
204 |
|
|
}; |
205 |
|
|
if ( !strcmp(inps[i],"+TRK1") ) { |
206 |
|
|
dectlist +=" +TRK1"; |
207 |
|
|
}; |
208 |
|
|
if ( !strcmp(inps[i],"+TRKh") ) { |
209 |
|
|
dectlist +=" +TRKh"; |
210 |
|
|
}; |
211 |
|
|
if ( !strcmp(inps[i],"+TOF") ) { |
212 |
|
|
dectlist +=" +TOF"; |
213 |
|
|
}; |
214 |
|
|
if ( !strcmp(inps[i],"+TRG") ) { |
215 |
|
|
dectlist +=" +TRG"; |
216 |
|
|
}; |
217 |
|
|
if ( !strcmp(inps[i],"+S4") ) { |
218 |
|
|
dectlist +=" +S4"; |
219 |
|
|
}; |
220 |
|
|
if ( !strcmp(inps[i],"+ND") ) { |
221 |
|
|
dectlist +=" +ND"; |
222 |
|
|
}; |
223 |
|
|
if ( !strcmp(inps[i],"+AC") ) { |
224 |
|
|
dectlist +=" +AC"; |
225 |
|
|
}; |
226 |
|
|
if ( !strcmp(inps[i],"+RUN") ) { |
227 |
|
|
dectlist +=" +RUN"; |
228 |
|
|
}; |
229 |
|
|
if ( !strcmp(inps[i],"+ORB") ) { |
230 |
|
|
dectlist +=" +ORB"; |
231 |
|
|
}; |
232 |
|
|
// |
233 |
|
|
i++; |
234 |
|
|
}; |
235 |
|
|
// |
236 |
|
|
} else { |
237 |
|
|
// |
238 |
|
|
// no input parameters exit with error, we need at least the run id. |
239 |
|
|
// |
240 |
|
|
amidalausage(); |
241 |
|
|
exit(-2); |
242 |
|
|
}; |
243 |
|
|
// |
244 |
|
|
if ( run && strcmp(dir.Data(),"") ){ |
245 |
|
|
amidalausage(); |
246 |
|
|
printf(" Cannot give as input both ID run and directory \n\n"); |
247 |
|
|
exit(-2); |
248 |
|
|
}; |
249 |
|
|
if ( !run && !strcmp(dir.Data(),"") ){ |
250 |
|
|
amidalausage(); |
251 |
|
|
printf(" You must give as input or an ID run or a directory \n\n"); |
252 |
|
|
exit(-2); |
253 |
|
|
}; |
254 |
|
|
// |
255 |
|
|
// Connect to the DB |
256 |
|
|
// |
257 |
|
|
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
258 |
|
|
if( !dbc ) throw -2; |
259 |
|
|
// |
260 |
|
|
bool connect = dbc->IsConnected(); |
261 |
|
|
// |
262 |
|
|
if( !connect ){ |
263 |
|
|
printf(" Error, not connected to DB\n"); |
264 |
|
|
exit(-1); |
265 |
|
|
}; |
266 |
|
|
// |
267 |
|
|
myquery.str(""); |
268 |
|
|
myquery << "SET time_zone='+0:00'"; |
269 |
|
|
dbc->Query(myquery.str().c_str()); |
270 |
|
|
// |
271 |
|
|
RunGlue *rg = new RunGlue(dbc,run,dir,outdir); |
272 |
|
|
// |
273 |
|
|
if ( debug ) rg->SetDebug(true); |
274 |
|
|
rg->SetDList(dectlist); |
275 |
|
|
// |
276 |
|
|
TList *l = 0; |
277 |
|
|
// |
278 |
|
|
TString treelist="+ALL"; |
279 |
|
|
// |
280 |
|
|
while ( !rg->End() ){ |
281 |
|
|
// |
282 |
|
|
l = rg->GetRunList(); |
283 |
|
|
// |
284 |
|
|
if ( l ){ |
285 |
|
|
// |
286 |
mocchiut |
1.2 |
// if ( rg->OpenFile() ){ |
287 |
|
|
if ( rg->FileIsOpen() ){ |
288 |
mocchiut |
1.1 |
// |
289 |
|
|
rg->MergeRootfile(l); |
290 |
|
|
// |
291 |
|
|
rg->UpdateDB(l); |
292 |
|
|
// |
293 |
|
|
if ( delop ) rg->DeleteRunFiles(l); |
294 |
|
|
// |
295 |
|
|
rg->Clean(); |
296 |
|
|
// |
297 |
|
|
}; |
298 |
|
|
}; |
299 |
|
|
delete l; |
300 |
|
|
// |
301 |
|
|
}; |
302 |
|
|
// |
303 |
|
|
delete rg; |
304 |
|
|
// |
305 |
|
|
// Close the DB connection |
306 |
|
|
// |
307 |
|
|
if ( dbc ) dbc->Close(); |
308 |
|
|
// |
309 |
|
|
printf("\n"); |
310 |
|
|
// |
311 |
|
|
exit(0); |
312 |
|
|
} |