30 |
printf("\n --version print informations about compilation and exit\n"); |
printf("\n --version print informations about compilation and exit\n"); |
31 |
printf("\n -h | --help print this help and exit \n"); |
printf("\n -h | --help print this help and exit \n"); |
32 |
printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n"); |
printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n"); |
33 |
printf("\n -idRun ID_RUN: ID number of the run \n"); |
printf("\n -idRun run ID_RUN: ID number of the run \n"); |
34 |
printf("\n -filename output yoda filename \n"); |
printf("\n -filename file output yoda filename \n"); |
35 |
printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n"); |
printf("\n -host name for the host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); |
36 |
printf("\n -user username for the DB [default = anonymous] \n"); |
printf("\n -user username for the DB [default = $PAM_DBUSER or \"anonymous\"] \n"); |
37 |
printf("\n -psw password for the DB [default = \"\"]\n"); |
printf("\n -psw password for the DB [default = $PAM_DBPSW or \"\"]\n"); |
38 |
|
printf("\n -tzone timezone the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n"); |
39 |
|
printf("\n -convert dbtime convert the dbtime given in seconds (from the DB) to a string\n"); |
40 |
|
printf("\n -runat time returns run number which contains the given date,\n"); |
41 |
|
printf("\n for time use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); |
42 |
|
printf("\n -tsfile file yoda filename for the time sync (to be used with -obt)\n"); |
43 |
|
printf("\n -obt OBT OBT in ms returns a date (to be used with -tsfile)\n"); |
44 |
printf("\nExamples: \n"); |
printf("\nExamples: \n"); |
45 |
printf("\n R2-D2 -idRun 1085 \n"); |
printf("\n R2-D2 -idRun 1085 \n"); |
46 |
printf("\n R2-D2 -filename DW_050208_00900.root \n"); |
printf("\n R2-D2 -filename DW_050208_00900.root \n"); |
54 |
// Variables booking |
// Variables booking |
55 |
// |
// |
56 |
TString message; |
TString message; |
|
int nul = 0; |
|
57 |
Int_t error = 0; |
Int_t error = 0; |
58 |
// |
// |
59 |
ULong64_t run = 0ULL; |
UInt_t run = 0ULL; |
60 |
// |
// |
61 |
TString filename = ""; |
TString filename = ""; |
62 |
// |
// |
65 |
TString user = "anonymous"; |
TString user = "anonymous"; |
66 |
TString psw = ""; |
TString psw = ""; |
67 |
// |
// |
68 |
|
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
69 |
|
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
70 |
|
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
71 |
|
if ( !pamdbhost ) pamdbhost = ""; |
72 |
|
if ( !pamdbuser ) pamdbuser = ""; |
73 |
|
if ( !pamdbpsw ) pamdbpsw = ""; |
74 |
|
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
75 |
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
76 |
|
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
77 |
|
// |
78 |
|
// printf(" host %s user %s psw %s \n",host.Data(),user.Data(),psw.Data()); |
79 |
|
// |
80 |
|
TString tzone = "UTC"; |
81 |
|
TString runtime = "1970-01-01 00:00:00"; |
82 |
|
UInt_t dbti = 0; |
83 |
|
Bool_t convert = false; |
84 |
|
Bool_t ruti = false; |
85 |
|
Bool_t convobt = false; |
86 |
|
Bool_t convobtts = false; |
87 |
|
// |
88 |
|
UInt_t obt = 0; |
89 |
|
TString tsfile = ""; |
90 |
|
// |
91 |
|
TSQLResult *pResult; |
92 |
|
TSQLRow *Row; |
93 |
|
int t; |
94 |
|
int r; |
95 |
|
stringstream myquery; |
96 |
// |
// |
97 |
// Checking input parameters |
// Checking input parameters |
98 |
// |
// |
112 |
r2d2usage(); |
r2d2usage(); |
113 |
exit(-3); |
exit(-3); |
114 |
}; |
}; |
115 |
char *pEnd; |
run = (UInt_t)atoll(inps[i+1]); |
|
run = strtoull(inps[i+1],&pEnd,0); |
|
116 |
}; |
}; |
117 |
if ( !strcmp(inps[i],"-filename") ) { |
if ( !strcmp(inps[i],"-filename") ) { |
118 |
if ( numinp-1 < i+1 ){ |
if ( numinp-1 < i+1 ){ |
142 |
}; |
}; |
143 |
psw = (TString)inps[i+1]; |
psw = (TString)inps[i+1]; |
144 |
}; |
}; |
145 |
|
// |
146 |
|
if ( !strcmp(inps[i],"-tsfile") ) { |
147 |
|
convobtts = true; |
148 |
|
if ( numinp-1 < i+1 ){ |
149 |
|
r2d2usage(); |
150 |
|
exit(-3); |
151 |
|
}; |
152 |
|
tsfile = (TString)inps[i+1]; |
153 |
|
}; |
154 |
|
// |
155 |
|
if ( !strcmp(inps[i],"-obt") ) { |
156 |
|
convobt = true; |
157 |
|
if ( numinp-1 < i+1 ){ |
158 |
|
r2d2usage(); |
159 |
|
exit(-3); |
160 |
|
}; |
161 |
|
obt = (UInt_t)atoll(inps[i+1]); |
162 |
|
}; |
163 |
|
// |
164 |
|
// |
165 |
|
if ( !strcmp(inps[i],"-tzone") ) { |
166 |
|
if ( numinp-1 < i+1 ){ |
167 |
|
r2d2usage(); |
168 |
|
exit(-3); |
169 |
|
}; |
170 |
|
tzone = (TString)inps[i+1]; |
171 |
|
}; |
172 |
|
// |
173 |
|
if ( !strcmp(inps[i],"-convert") ) { |
174 |
|
convert = true; |
175 |
|
if ( numinp-1 < i+1 ){ |
176 |
|
r2d2usage(); |
177 |
|
exit(-3); |
178 |
|
}; |
179 |
|
dbti = (UInt_t)atoll(inps[i+1]); |
180 |
|
}; |
181 |
|
// |
182 |
|
if ( !strcmp(inps[i],"-runat") ) { |
183 |
|
ruti = true; |
184 |
|
if ( numinp-1 < i+1 ){ |
185 |
|
r2d2usage(); |
186 |
|
exit(-3); |
187 |
|
}; |
188 |
|
runtime = (TString)inps[i+1]; |
189 |
|
}; |
190 |
|
// |
191 |
i++; |
i++; |
192 |
}; |
}; |
193 |
// |
// |
213 |
// |
// |
214 |
GL_ROOT *glroot = new GL_ROOT(); |
GL_ROOT *glroot = new GL_ROOT(); |
215 |
GL_RUN *glrun = new GL_RUN(); |
GL_RUN *glrun = new GL_RUN(); |
216 |
|
GL_TIMESYNC *dbtime = new GL_TIMESYNC(); |
217 |
|
// |
218 |
|
// At which date correspond the DB time "dbti"? |
219 |
|
// |
220 |
|
if ( convert ){ |
221 |
|
printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone,dbti).Data(),tzone.Data()); |
222 |
|
}; |
223 |
|
// |
224 |
|
// |
225 |
|
// |
226 |
|
if ( convobt && convobtts ){ |
227 |
|
UInt_t id = 0; |
228 |
|
myquery.str(""); |
229 |
|
myquery << "select "; |
230 |
|
myquery << " ID"; |
231 |
|
myquery << " from GL_ROOT where NAME=\"" << tsfile.Data() << "\";"; |
232 |
|
pResult = dbc->Query(myquery.str().c_str()); |
233 |
|
if ( pResult ){ |
234 |
|
Row = pResult->Next(); |
235 |
|
if ( Row ){ |
236 |
|
id = (UInt_t)atoll(Row->GetField(0)); |
237 |
|
delete pResult; |
238 |
|
GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc); |
239 |
|
UInt_t abtime = ctime->DBabsTime(obt); |
240 |
|
TString UTC="UTC"; |
241 |
|
TString thetime = dbtime->ConvertTime(tzone,abtime); |
242 |
|
printf("\n OBT %u in the file %s corresponds to DBtime %u and date %s %s \n",obt,tsfile.Data(),abtime,thetime.Data(),tzone.Data()); |
243 |
|
delete ctime; |
244 |
|
}; |
245 |
|
}; |
246 |
|
}; |
247 |
|
if ( (convobt && !convobtts) || (convobtts && !convobt) ){ |
248 |
|
printf("\n To convert a OBT to a date you must provide both OBT and file to be used for time sync \n"); |
249 |
|
}; |
250 |
|
// |
251 |
|
// Which run contains the date "runtime"? |
252 |
|
// |
253 |
|
if ( ruti ){ |
254 |
|
// |
255 |
|
TDatime *time = new TDatime(runtime.Data()); |
256 |
|
UInt_t dbti = time->Convert(); |
257 |
|
// |
258 |
|
TString thetime = dbtime->UnConvertTime(tzone,dbti); |
259 |
|
// |
260 |
|
TDatime *time2 = new TDatime(thetime.Data()); |
261 |
|
UInt_t mytime = time2->Convert(); |
262 |
|
// |
263 |
|
myquery.str(""); |
264 |
|
myquery << "select "; |
265 |
|
myquery << " ID "; |
266 |
|
myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND " |
267 |
|
<< " RUNTRAILER_TIME>=" << mytime << " ;"; |
268 |
|
// printf("myquery is %s \n",myquery.str().c_str()); |
269 |
|
pResult = dbc->Query(myquery.str().c_str()); |
270 |
|
for( r=0; r < 1000; r++){ |
271 |
|
Row = pResult->Next(); |
272 |
|
if ( !r && !Row ){ |
273 |
|
printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone.Data(),mytime); |
274 |
|
}; |
275 |
|
if( Row == NULL ) break; |
276 |
|
printf("\n Date %s %s (DB time %u ) is contained in run %u \n",runtime.Data(),tzone.Data(),mytime,(UInt_t)atoll(Row->GetField(0))); |
277 |
|
}; |
278 |
|
}; |
279 |
// |
// |
280 |
if ( run != 0ULL ){ |
// To which file the run "run" belongs? |
281 |
|
// |
282 |
|
if ( run != 0 ){ |
283 |
|
glrun->Clear(); |
284 |
error = glrun->Query_GL_RUN(run,dbc); |
error = glrun->Query_GL_RUN(run,dbc); |
285 |
error = glroot->Query_GL_ROOT(glrun->ID_REG_RUN,dbc); |
glroot->Clear(); |
286 |
if ( error ){ |
error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc); |
287 |
printf(" Error querying the DB! \n"); |
if ( !glrun->ID_ROOT_L0 ){ |
288 |
exit(-4); |
printf("\n No run with ID=%u in the DB!\n",run); |
289 |
|
} else { |
290 |
|
if ( error ){ |
291 |
|
printf(" Error querying the DB! \n"); |
292 |
|
exit(-4); |
293 |
|
}; |
294 |
|
printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data()); |
295 |
}; |
}; |
|
printf("\n Run %llu belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data()); |
|
296 |
}; |
}; |
297 |
|
// |
298 |
|
// Which runs are contained in the file "filename"? |
299 |
|
// |
300 |
if ( strcmp(filename.Data(),"") ){ |
if ( strcmp(filename.Data(),"") ){ |
|
TSQLResult *pResult; |
|
|
TSQLRow *Row; |
|
|
int t; |
|
|
int r; |
|
|
stringstream myquery; |
|
301 |
// ---------------- |
// ---------------- |
302 |
Int_t ID = 0; |
Int_t ID = 0; |
303 |
Int_t ID_RAW = 0; |
Int_t ID_RAW = 0; |
304 |
// |
// |
305 |
const char *rawpath; |
const char *rawpath = ""; |
306 |
const char *rawname; |
const char *rawname = ""; |
307 |
// |
// |
308 |
myquery.str(""); |
myquery.str(""); |
309 |
myquery << "select "; |
myquery << "select "; |
313 |
myquery << ",NAME"; |
myquery << ",NAME"; |
314 |
myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";"; |
myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";"; |
315 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
|
if(!pResult->GetRowCount()) return (-51); |
|
316 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
317 |
Row = pResult->Next(); |
Row = pResult->Next(); |
318 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
322 |
}; |
}; |
323 |
}; |
}; |
324 |
delete pResult; |
delete pResult; |
325 |
printf("\n File %s contains the following runs: \n",filename.Data()); |
if ( !ID && !ID_RAW ){ |
326 |
myquery.str(""); |
printf("\n No file with name %s in the DB!\n",filename.Data()); |
327 |
myquery << "select "; |
} else { |
328 |
myquery << " ID"; |
myquery.str(""); |
329 |
myquery << " from GL_RUN where ID_REG_RUN=" << ID << ";"; |
myquery << "select "; |
330 |
pResult = dbc->Query(myquery.str().c_str()); |
myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME "; |
331 |
if(!pResult->GetRowCount()) return (-51); |
myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; |
332 |
for( r=0; r < 1000; r++){ |
pResult = dbc->Query(myquery.str().c_str()); |
333 |
Row = pResult->Next(); |
for( r=0; r < 1000; r++){ |
334 |
if( Row == NULL ) break; |
Row = pResult->Next(); |
335 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
if ( !r && !Row ){ |
336 |
if (t==0) printf(" => %i \n",atoi(Row->GetField(t))); |
printf("\n No run associated to the file %s \n",filename.Data()); |
337 |
|
}; |
338 |
|
if( Row == NULL ) break; |
339 |
|
if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data()); |
340 |
|
TString UTC="UTC"; |
341 |
|
printf(" => ID = %i _-_-_ the run started at %s UTC ended at %s UTC \n\n",(UInt_t)atoll(Row->GetField(0)),dbtime->ConvertTime(UTC,(UInt_t)atoll(Row->GetField(1))).Data(),dbtime->ConvertTime(UTC,(UInt_t)atoll(Row->GetField(2))).Data()); |
342 |
}; |
}; |
343 |
}; |
delete pResult; |
344 |
delete pResult; |
myquery.str(""); |
345 |
myquery.str(""); |
myquery << "select "; |
346 |
myquery << "select "; |
myquery << " PATH,NAME"; |
347 |
myquery << " PATH,NAME"; |
myquery << " from GL_RAW where ID=" << ID_RAW << ";"; |
348 |
myquery << " from GL_RAW where ID=" << ID_RAW << ";"; |
pResult = dbc->Query(myquery.str().c_str()); |
349 |
pResult = dbc->Query(myquery.str().c_str()); |
for( r=0; r < 1000; r++){ |
350 |
if(!pResult->GetRowCount()) return (-51); |
Row = pResult->Next(); |
351 |
for( r=0; r < 1000; r++){ |
if( Row == NULL ) break; |
352 |
Row = pResult->Next(); |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
353 |
if( Row == NULL ) break; |
if(t==0) rawpath = Row->GetField(t); |
354 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
if(t==1) rawname = Row->GetField(t); |
355 |
if(t==0) rawpath = Row->GetField(t); |
}; |
|
if(t==1) rawname = Row->GetField(t); |
|
356 |
}; |
}; |
357 |
|
delete pResult; |
358 |
|
printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname); |
359 |
}; |
}; |
|
delete pResult; |
|
|
printf(" and belongs to raw data file %s/%s \n",rawpath,rawname); |
|
360 |
}; |
}; |
361 |
// |
// |
362 |
// Close the DB connection |
// Close the DB connection |