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 -convert [ -tzone timezone -dbtime dbtime ] \n"); |
printf("\n -tzone timezone the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n"); |
39 |
printf("\n convert the dbtime given in seconds (from the DB) to a string for\n"); |
printf("\n -convert dbtime convert the dbtime given in seconds (from the DB) to a string\n"); |
40 |
printf("\n the given time zone (UTC,GMT,MSK,MSD,CET,CEST are accepted) \n"); |
printf("\n -runat time returns run number which contains the given date,\n"); |
41 |
printf("\n -runat \"yyyy-mm-dd hh:mm:ss\" \n"); |
printf("\n for time use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); |
42 |
printf("\n returns run number which contain the given date in MSK (if any)\n"); |
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"); |
64 |
TString host = "mysql://localhost/pamelaprod"; |
TString host = "mysql://localhost/pamelaprod"; |
65 |
TString user = "anonymous"; |
TString user = "anonymous"; |
66 |
TString psw = ""; |
TString psw = ""; |
67 |
TString tzone = "MSK"; |
// |
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"; |
TString runtime = "1970-01-01 00:00:00"; |
82 |
UInt_t dbti = 0; |
UInt_t dbti = 0; |
83 |
Bool_t convert = false; |
Bool_t convert = false; |
84 |
Bool_t ruti = false; |
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 |
// |
// |
143 |
psw = (TString)inps[i+1]; |
psw = (TString)inps[i+1]; |
144 |
}; |
}; |
145 |
// |
// |
146 |
if ( !strcmp(inps[i],"-runat") ) { |
if ( !strcmp(inps[i],"-tsfile") ) { |
147 |
ruti = true; |
convobtts = true; |
148 |
if ( numinp-1 < i+1 ){ |
if ( numinp-1 < i+1 ){ |
149 |
r2d2usage(); |
r2d2usage(); |
150 |
exit(-3); |
exit(-3); |
151 |
}; |
}; |
152 |
runtime = (TString)inps[i+1]; |
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") ) { |
if ( !strcmp(inps[i],"-convert") ) { |
174 |
convert = true; |
convert = true; |
175 |
if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){ |
if ( numinp-1 < i+1 ){ |
176 |
if ( numinp < i+2 ){ |
r2d2usage(); |
177 |
r2d2usage(); |
exit(-3); |
|
throw -3; |
|
|
}; |
|
|
i += 2; |
|
|
while ( strcmp(inps[i],"]") ){ |
|
|
if ( !strcmp(inps[i],"-tzone") ) { |
|
|
if ( numinp-1 < i+1 ){ |
|
|
r2d2usage(); |
|
|
exit(-3); |
|
|
}; |
|
|
tzone = (TString)inps[i+1]; |
|
|
}; |
|
|
if ( !strcmp(inps[i],"-dbtime") ) { |
|
|
if ( numinp-1 < i+1 ){ |
|
|
r2d2usage(); |
|
|
exit(-3); |
|
|
}; |
|
|
dbti = (UInt_t)atoll(inps[i+1]); |
|
|
}; |
|
|
i++; |
|
|
if ( i > numinp-1 ){ |
|
|
r2d2usage(); |
|
|
throw -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++; |
218 |
// At which date correspond the DB time "dbti"? |
// At which date correspond the DB time "dbti"? |
219 |
// |
// |
220 |
if ( convert ){ |
if ( convert ){ |
221 |
printf("\n Time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone.Data(),dbti).Data(),tzone.Data()); |
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"? |
// Which run contains the date "runtime"? |
252 |
// |
// |
253 |
if ( ruti ){ |
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 |
// To which file the run "run" belongs? |
// To which file the run "run" belongs? |
284 |
error = glrun->Query_GL_RUN(run,dbc); |
error = glrun->Query_GL_RUN(run,dbc); |
285 |
glroot->Clear(); |
glroot->Clear(); |
286 |
error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc); |
error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc); |
287 |
if ( error ){ |
if ( !glrun->ID_ROOT_L0 ){ |
|
printf(" Error querying the DB! \n"); |
|
|
exit(-4); |
|
|
}; |
|
|
if ( !glrun->ID ){ |
|
288 |
printf("\n No run with ID=%u in the DB!\n",run); |
printf("\n No run with ID=%u in the DB!\n",run); |
289 |
} else { |
} 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()); |
printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data()); |
295 |
}; |
}; |
296 |
}; |
}; |
298 |
// Which runs are contained in the file "filename"? |
// 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; |
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; |
330 |
myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME "; |
myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME "; |
331 |
myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; |
myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; |
332 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
|
if(!pResult->GetRowCount()) return (-51); |
|
333 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
334 |
Row = pResult->Next(); |
Row = pResult->Next(); |
335 |
if ( !r && !Row ){ |
if ( !r && !Row ){ |
336 |
printf(" No run associated to the file %s \n",filename.Data()); |
printf("\n No run associated to the file %s \n",filename.Data()); |
337 |
}; |
}; |
338 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
339 |
if ( !r ) printf("\n File %s contains the following runs: \n",filename.Data()); |
if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data()); |
340 |
printf(" => %i -> Start at %s UTC end at %s UTC \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()); |
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; |
delete pResult; |
344 |
myquery.str(""); |
myquery.str(""); |
346 |
myquery << " PATH,NAME"; |
myquery << " PATH,NAME"; |
347 |
myquery << " from GL_RAW where ID=" << ID_RAW << ";"; |
myquery << " from GL_RAW where ID=" << ID_RAW << ";"; |
348 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
|
if(!pResult->GetRowCount()) return (-51); |
|
349 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
350 |
Row = pResult->Next(); |
Row = pResult->Next(); |
351 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
355 |
}; |
}; |
356 |
}; |
}; |
357 |
delete pResult; |
delete pResult; |
358 |
printf(" File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname); |
printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname); |
359 |
}; |
}; |
360 |
}; |
}; |
361 |
// |
// |