9 |
// ROOT headers |
// ROOT headers |
10 |
// |
// |
11 |
#include <TString.h> |
#include <TString.h> |
12 |
|
#include <TTimeStamp.h> |
13 |
#include <TSQLServer.h> |
#include <TSQLServer.h> |
14 |
#include <TFile.h> |
#include <TFile.h> |
15 |
#include <TSystem.h> |
#include <TSystem.h> |
45 |
printf("\n -runatDB time returns run number which contains the given DB time\n"); |
printf("\n -runatDB time returns run number which contains the given DB time\n"); |
46 |
printf("\n -tsfile file yoda filename for the time sync (to be used with -obt)\n"); |
printf("\n -tsfile file yoda filename for the time sync (to be used with -obt)\n"); |
47 |
printf("\n -obt OBT OBT in ms returns a date (to be used with -tsfile)\n"); |
printf("\n -obt OBT OBT in ms returns a date (to be used with -tsfile)\n"); |
48 |
|
printf("\n -getRTime OBT OBT in ms returns Resurs time (to be used with -tsfile)\n"); |
49 |
printf("\n -dumpTLEfor date save into file tle.txt the TLE for the given date,\n"); |
printf("\n -dumpTLEfor date save into file tle.txt the TLE for the given date,\n"); |
50 |
printf("\n for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); |
printf("\n for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); |
51 |
printf("\nExamples: \n"); |
printf("\nExamples: \n"); |
89 |
TString tletime = "1970-01-01 00:00:00"; |
TString tletime = "1970-01-01 00:00:00"; |
90 |
UInt_t dbti = 0; |
UInt_t dbti = 0; |
91 |
Bool_t convert = false; |
Bool_t convert = false; |
92 |
|
Bool_t convres = false; |
93 |
Bool_t ruti = false; |
Bool_t ruti = false; |
94 |
Bool_t dtle = false; |
Bool_t dtle = false; |
95 |
Bool_t ruti2 = false; |
Bool_t ruti2 = false; |
98 |
// |
// |
99 |
UInt_t runtime2 = 0; |
UInt_t runtime2 = 0; |
100 |
UInt_t obt = 0; |
UInt_t obt = 0; |
101 |
|
UInt_t res = 0; |
102 |
TString tsfile = ""; |
TString tsfile = ""; |
103 |
// |
// |
104 |
TSQLResult *pResult; |
TSQLResult *pResult; |
174 |
obt = (UInt_t)atoll(inps[i+1]); |
obt = (UInt_t)atoll(inps[i+1]); |
175 |
}; |
}; |
176 |
// |
// |
177 |
|
if ( !strcmp(inps[i],"-getRTime") ) { |
178 |
|
convres = true; |
179 |
|
if ( numinp-1 < i+1 ){ |
180 |
|
r2d2usage(); |
181 |
|
exit(-3); |
182 |
|
}; |
183 |
|
res = (UInt_t)atoll(inps[i+1]); |
184 |
|
}; |
185 |
|
// |
186 |
// |
// |
187 |
if ( !strcmp(inps[i],"-tzone") ) { |
if ( !strcmp(inps[i],"-tzone") ) { |
188 |
if ( numinp-1 < i+1 ){ |
if ( numinp-1 < i+1 ){ |
252 |
exit(-1); |
exit(-1); |
253 |
}; |
}; |
254 |
// |
// |
255 |
|
myquery.str(""); |
256 |
|
myquery << "SET time_zone='+0:00'"; |
257 |
|
dbc->Query(myquery.str().c_str()); |
258 |
|
// |
259 |
GL_ROOT *glroot = new GL_ROOT(); |
GL_ROOT *glroot = new GL_ROOT(); |
260 |
GL_RUN *glrun = new GL_RUN(); |
GL_RUN *glrun = new GL_RUN(); |
261 |
GL_TIMESYNC *dbtime = new GL_TIMESYNC(); |
GL_TIMESYNC *dbtime = new GL_TIMESYNC(); |
266 |
printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone,dbti).Data(),tzone.Data()); |
printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone,dbti).Data(),tzone.Data()); |
267 |
}; |
}; |
268 |
// |
// |
269 |
// |
// convert OBT to date |
270 |
// |
// |
271 |
if ( convobt && convobtts ){ |
if ( convobt && convobtts ){ |
272 |
UInt_t id = 0; |
UInt_t id = 0; |
282 |
delete pResult; |
delete pResult; |
283 |
GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc); |
GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc); |
284 |
UInt_t abtime = ctime->DBabsTime(obt); |
UInt_t abtime = ctime->DBabsTime(obt); |
|
TString UTC="UTC"; |
|
285 |
TString thetime = dbtime->ConvertTime(tzone,abtime); |
TString thetime = dbtime->ConvertTime(tzone,abtime); |
286 |
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()); |
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()); |
287 |
delete ctime; |
delete ctime; |
288 |
}; |
}; |
289 |
}; |
}; |
290 |
}; |
}; |
291 |
if ( (convobt && !convobtts) || (convobtts && !convobt) ){ |
if ( (convobt && !convobtts) ){ |
292 |
printf("\n To convert a OBT to a date you must provide both OBT and file to be used for time sync \n"); |
printf("\n To convert a OBT to a date you must provide both OBT and file to be used for time sync \n"); |
293 |
}; |
}; |
294 |
// |
// |
295 |
|
// convert OBT to Resurs seconds |
296 |
|
// |
297 |
|
if ( convres && convobtts ){ |
298 |
|
UInt_t id = 0; |
299 |
|
myquery.str(""); |
300 |
|
myquery << "select "; |
301 |
|
myquery << " ID"; |
302 |
|
myquery << " from GL_ROOT where NAME=\"" << tsfile.Data() << "\";"; |
303 |
|
pResult = dbc->Query(myquery.str().c_str()); |
304 |
|
if ( pResult ){ |
305 |
|
Row = pResult->Next(); |
306 |
|
if ( Row ){ |
307 |
|
id = (UInt_t)atoll(Row->GetField(0)); |
308 |
|
delete pResult; |
309 |
|
GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc); |
310 |
|
UInt_t restime = ctime->ResursTime(res); |
311 |
|
//UInt_t abtime = ctime->DBabsTime(obt); |
312 |
|
// |
313 |
|
// TString thetime = dbtime->ConvertTime(tzone,abtime); |
314 |
|
printf("\n OBT %u in the file %s corresponds to Resurs time %u \n",res,tsfile.Data(),restime); |
315 |
|
delete ctime; |
316 |
|
}; |
317 |
|
}; |
318 |
|
}; |
319 |
|
if ( (convres && !convobtts) ){ |
320 |
|
printf("\n To convert a OBT to the Resurs time you must provide both OBT and file to be used for time sync \n"); |
321 |
|
}; |
322 |
|
// |
323 |
// Which run contains the date "runtime"? |
// Which run contains the date "runtime"? |
324 |
// |
// |
325 |
if ( ruti ){ |
if ( ruti ){ |
326 |
// |
// |
327 |
TDatime *time = new TDatime(runtime.Data()); |
TDatime ti = TDatime(runtime.Data()); |
328 |
UInt_t dbti = time->Convert(); |
// |
329 |
|
TTimeStamp *time = new TTimeStamp((UInt_t)ti.GetYear(),(UInt_t)ti.GetMonth(),(UInt_t)ti.GetDay(),(UInt_t)ti.GetHour(),(UInt_t)ti.GetMinute(),(UInt_t)ti.GetSecond(),0,true,0); |
330 |
|
// |
331 |
|
UInt_t dbti = time->GetSec(); |
332 |
// |
// |
333 |
TString thetime = dbtime->UnConvertTime(tzone,dbti); |
TString thetime = dbtime->UnConvertTime(tzone,dbti); |
334 |
// |
// |
335 |
TDatime *time2 = new TDatime(thetime.Data()); |
ti = TDatime(thetime.Data()); |
336 |
UInt_t mytime = time2->Convert(); |
TTimeStamp *time2 = new TTimeStamp((UInt_t)ti.GetYear(),(UInt_t)ti.GetMonth(),(UInt_t)ti.GetDay(),(UInt_t)ti.GetHour(),(UInt_t)ti.GetMinute(),(UInt_t)ti.GetSecond(),0,true,0); |
337 |
|
// |
338 |
|
UInt_t mytime = time2->GetSec(); |
339 |
|
// |
340 |
Bool_t found = false; |
Bool_t found = false; |
341 |
// |
// |
342 |
myquery.str(""); |
myquery.str(""); |
376 |
// |
// |
377 |
if ( dtle ){ |
if ( dtle ){ |
378 |
// |
// |
379 |
TDatime *time = new TDatime(tletime.Data()); |
// |
380 |
UInt_t dbti = time->Convert(); |
TDatime ti = TDatime(tletime.Data()); |
381 |
|
// |
382 |
|
TTimeStamp *time = new TTimeStamp((UInt_t)ti.GetYear(),(UInt_t)ti.GetMonth(),(UInt_t)ti.GetDay(),(UInt_t)ti.GetHour(),(UInt_t)ti.GetMinute(),(UInt_t)ti.GetSecond(),0,true,0); |
383 |
|
// |
384 |
|
UInt_t dbti = time->GetSec(); |
385 |
// |
// |
386 |
TString thetime = dbtime->UnConvertTime(tzone,dbti); |
TString thetime = dbtime->UnConvertTime(tzone,dbti); |
387 |
// |
// |
388 |
TDatime *time2 = new TDatime(thetime.Data()); |
ti = TDatime(thetime.Data()); |
389 |
UInt_t mytime = time2->Convert(); |
TTimeStamp *time2 = new TTimeStamp((UInt_t)ti.GetYear(),(UInt_t)ti.GetMonth(),(UInt_t)ti.GetDay(),(UInt_t)ti.GetHour(),(UInt_t)ti.GetMinute(),(UInt_t)ti.GetSecond(),0,true,0); |
390 |
|
// |
391 |
|
UInt_t mytime = time2->GetSec(); |
392 |
// |
// |
393 |
myquery.str(""); |
myquery.str(""); |
394 |
myquery << " select ID,TLE1,TLE2,TLE3 from GL_TLE where FROM_TIME<='" << time2->AsSQLString() << "' ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " select ID,TLE1,TLE2,TLE3 from GL_TLE where FROM_TIME<='" << time2->AsString("s") << "' ORDER BY FROM_TIME DESC LIMIT 1;"; |
395 |
// myquery << " from GL_TLE where FROM_TIME>=" << mytime << " ORDER BY FROM_TIME ASC LIMIT 1;"; |
// myquery << " from GL_TLE where FROM_TIME>=" << mytime << " ORDER BY FROM_TIME ASC LIMIT 1;"; |
396 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
397 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
469 |
exit(-4); |
exit(-4); |
470 |
}; |
}; |
471 |
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()); |
472 |
|
filename = glroot->NAME; |
473 |
found = true; |
found = true; |
474 |
}; |
}; |
475 |
// |
// |
522 |
} else { |
} else { |
523 |
myquery.str(""); |
myquery.str(""); |
524 |
myquery << "select "; |
myquery << "select "; |
525 |
myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME "; |
myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME,NEVENTS "; |
526 |
myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; |
myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; |
527 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
528 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
530 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
531 |
found = true; |
found = true; |
532 |
if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data()); |
if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data()); |
533 |
TString UTC="UTC"; |
TString UTC=tzone.Data(); |
534 |
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()); |
printf(" => ID = %i --> the run started at %s %s ended at %s %s NEV = %u \n\n",(UInt_t)atoll(Row->GetField(0)),dbtime->ConvertTime(UTC,(UInt_t)atoll(Row->GetField(1))).Data(),tzone.Data(),dbtime->ConvertTime(UTC,(UInt_t)atoll(Row->GetField(2))).Data(),tzone.Data(),(UInt_t)atoll(Row->GetField(3))); |
535 |
}; |
}; |
536 |
delete pResult; |
delete pResult; |
537 |
myquery.str(""); |
myquery.str(""); |
543 |
Row = pResult->Next(); |
Row = pResult->Next(); |
544 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
545 |
if ( !r ) printf("\n File %s contains the following DELETED runs: \n\n",filename.Data()); |
if ( !r ) printf("\n File %s contains the following DELETED runs: \n\n",filename.Data()); |
546 |
TString UTC="UTC"; |
TString UTC=tzone.Data(); |
547 |
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()); |
printf(" => ID = %i --> the run started at %s %s ended at %s %s \n\n",(UInt_t)atoll(Row->GetField(0)),dbtime->ConvertTime(UTC,(UInt_t)atoll(Row->GetField(1))).Data(),tzone.Data(),dbtime->ConvertTime(UTC,(UInt_t)atoll(Row->GetField(2))).Data(),tzone.Data()); |
548 |
}; |
}; |
549 |
// |
// |
550 |
if ( !found ){ |
if ( !found ){ |