28 |
// |
// |
29 |
void r2d2usage(){ |
void r2d2usage(){ |
30 |
printf("\nUsage:\n"); |
printf("\nUsage:\n"); |
31 |
printf("\n R2-D2 [-h | --help] [--version] [-idRun ID_RUN] [-filename filename]\n"); |
printf("\n R2-D2 [ options ]\n"); |
32 |
printf("\n [-host host] [-user username] [-psw password] \n"); |
printf("\n Options are:\n\n"); |
33 |
printf("\n --version print informations about compilation and exit\n"); |
printf(" --version print informations about compilation and exit\n"); |
34 |
printf("\n -h | --help print this help and exit \n"); |
printf(" -h | --help print this help and exit \n"); |
35 |
printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n"); |
printf(" -v | --verbose be verbose [default: print nothing on STDOUT]\n"); |
36 |
printf("\n -idRun run ID_RUN: ID number of the run \n"); |
printf(" -idRun run ID_RUN: ID number of the run \n"); |
37 |
printf("\n -filename file output yoda filename \n"); |
printf(" -filename file output yoda filename \n"); |
38 |
printf("\n -host name for the host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); |
printf(" -l2filename file output amidala filename \n"); |
39 |
printf("\n -user username for the DB [default = $PAM_DBUSER or \"anonymous\"] \n"); |
printf(" -host name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); |
40 |
printf("\n -psw password for the DB [default = $PAM_DBPSW or \"\"]\n"); |
printf(" -user username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n"); |
41 |
printf("\n -tzone timezone the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n"); |
printf(" -psw password for the DB connection [default = $PAM_DBPSW or \"\"]\n"); |
42 |
printf("\n -convert dbtime convert the dbtime given in seconds (from the DB) to a string\n"); |
printf(" -tzone timezone the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n"); |
43 |
printf("\n -runat date returns run number which contains the given date,\n"); |
printf(" -convert dbtime convert the dbtime given in seconds (from the DB) to a string\n"); |
44 |
printf("\n for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); |
printf(" -runat date returns run number which contains the given date,\n"); |
45 |
printf("\n -runatDB time returns run number which contains the given DB time\n"); |
printf(" for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); |
46 |
printf("\n -tsfile file yoda filename for the time sync (to be used with -obt)\n"); |
printf(" -runatDB time returns run number which contains the given DB time\n"); |
47 |
printf("\n -obt OBT OBT in ms returns a date (to be used with -tsfile)\n"); |
printf(" -tsfile file yoda filename for the time sync (to be used with -obt)\n"); |
48 |
printf("\n -dumpTLEfor date save into file tle.txt the TLE for the given date,\n"); |
printf(" -obt OBT OBT in ms returns a date (to be used with -tsfile)\n"); |
49 |
printf("\n for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); |
printf(" -getRTime OBT OBT in ms returns Resurs time (to be used with -tsfile)\n"); |
50 |
|
printf(" -dumpTLEfor date save into file tle.txt the TLE for the given date,\n"); |
51 |
|
printf(" for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); |
52 |
printf("\nExamples: \n"); |
printf("\nExamples: \n"); |
53 |
printf("\n R2-D2 -idRun 1085 \n"); |
printf(" R2-D2 -idRun 1085 \n"); |
54 |
printf("\n R2-D2 -filename DW_050208_00900.root \n"); |
printf(" R2-D2 -filename DW_050208_00900.root \n"); |
55 |
printf("\n R2-D2 -idRun 1085 -filename DW_050208_00900.root \n"); |
printf(" R2-D2 -idRun 1085 -filename DW_050208_00900.root \n\n"); |
56 |
}; |
}; |
57 |
// |
// |
58 |
// Here the main |
// Here the main |
67 |
UInt_t run = 0ULL; |
UInt_t run = 0ULL; |
68 |
// |
// |
69 |
TString filename = ""; |
TString filename = ""; |
70 |
|
TString l2filename = ""; |
71 |
// |
// |
72 |
TSQLServer *dbc = 0; |
TSQLServer *dbc = 0; |
73 |
TString host = "mysql://localhost/pamelaprod"; |
TString host = "mysql://localhost/pamelaprod"; |
91 |
TString tletime = "1970-01-01 00:00:00"; |
TString tletime = "1970-01-01 00:00:00"; |
92 |
UInt_t dbti = 0; |
UInt_t dbti = 0; |
93 |
Bool_t convert = false; |
Bool_t convert = false; |
94 |
|
Bool_t convres = false; |
95 |
Bool_t ruti = false; |
Bool_t ruti = false; |
96 |
Bool_t dtle = false; |
Bool_t dtle = false; |
97 |
Bool_t ruti2 = false; |
Bool_t ruti2 = false; |
100 |
// |
// |
101 |
UInt_t runtime2 = 0; |
UInt_t runtime2 = 0; |
102 |
UInt_t obt = 0; |
UInt_t obt = 0; |
103 |
|
UInt_t res = 0; |
104 |
TString tsfile = ""; |
TString tsfile = ""; |
105 |
// |
// |
106 |
TSQLResult *pResult; |
TSQLResult *pResult; |
136 |
}; |
}; |
137 |
filename = (TString)inps[i+1]; |
filename = (TString)inps[i+1]; |
138 |
}; |
}; |
139 |
|
if ( !strcmp(inps[i],"-l2filename") ) { |
140 |
|
if ( numinp-1 < i+1 ){ |
141 |
|
r2d2usage(); |
142 |
|
exit(-3); |
143 |
|
}; |
144 |
|
l2filename = (TString)inps[i+1]; |
145 |
|
}; |
146 |
if ( !strcmp(inps[i],"-host") ) { |
if ( !strcmp(inps[i],"-host") ) { |
147 |
if ( numinp-1 < i+1 ){ |
if ( numinp-1 < i+1 ){ |
148 |
r2d2usage(); |
r2d2usage(); |
183 |
obt = (UInt_t)atoll(inps[i+1]); |
obt = (UInt_t)atoll(inps[i+1]); |
184 |
}; |
}; |
185 |
// |
// |
186 |
|
if ( !strcmp(inps[i],"-getRTime") ) { |
187 |
|
convres = true; |
188 |
|
if ( numinp-1 < i+1 ){ |
189 |
|
r2d2usage(); |
190 |
|
exit(-3); |
191 |
|
}; |
192 |
|
res = (UInt_t)atoll(inps[i+1]); |
193 |
|
}; |
194 |
|
// |
195 |
// |
// |
196 |
if ( !strcmp(inps[i],"-tzone") ) { |
if ( !strcmp(inps[i],"-tzone") ) { |
197 |
if ( numinp-1 < i+1 ){ |
if ( numinp-1 < i+1 ){ |
268 |
GL_ROOT *glroot = new GL_ROOT(); |
GL_ROOT *glroot = new GL_ROOT(); |
269 |
GL_RUN *glrun = new GL_RUN(); |
GL_RUN *glrun = new GL_RUN(); |
270 |
GL_TIMESYNC *dbtime = new GL_TIMESYNC(); |
GL_TIMESYNC *dbtime = new GL_TIMESYNC(); |
271 |
|
UInt_t nr = 0; |
272 |
|
UInt_t rlist[500]; |
273 |
// |
// |
274 |
// At which date correspond the DB time "dbti"? |
// At which date correspond the DB time "dbti"? |
275 |
// |
// |
277 |
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()); |
278 |
}; |
}; |
279 |
// |
// |
280 |
// |
// convert OBT to date |
281 |
// |
// |
282 |
if ( convobt && convobtts ){ |
if ( convobt && convobtts ){ |
283 |
UInt_t id = 0; |
UInt_t id = 0; |
293 |
delete pResult; |
delete pResult; |
294 |
GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc); |
GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc); |
295 |
UInt_t abtime = ctime->DBabsTime(obt); |
UInt_t abtime = ctime->DBabsTime(obt); |
|
TString UTC="UTC"; |
|
296 |
TString thetime = dbtime->ConvertTime(tzone,abtime); |
TString thetime = dbtime->ConvertTime(tzone,abtime); |
297 |
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()); |
298 |
delete ctime; |
delete ctime; |
299 |
}; |
}; |
300 |
}; |
}; |
301 |
}; |
}; |
302 |
if ( (convobt && !convobtts) || (convobtts && !convobt) ){ |
if ( (convobt && !convobtts) ){ |
303 |
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"); |
304 |
}; |
}; |
305 |
// |
// |
306 |
|
// convert OBT to Resurs seconds |
307 |
|
// |
308 |
|
if ( convres && convobtts ){ |
309 |
|
UInt_t id = 0; |
310 |
|
myquery.str(""); |
311 |
|
myquery << "select "; |
312 |
|
myquery << " ID"; |
313 |
|
myquery << " from GL_ROOT where NAME=\"" << tsfile.Data() << "\";"; |
314 |
|
pResult = dbc->Query(myquery.str().c_str()); |
315 |
|
if ( pResult ){ |
316 |
|
Row = pResult->Next(); |
317 |
|
if ( Row ){ |
318 |
|
id = (UInt_t)atoll(Row->GetField(0)); |
319 |
|
delete pResult; |
320 |
|
GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc); |
321 |
|
UInt_t restime = ctime->ResursTime(res); |
322 |
|
//UInt_t abtime = ctime->DBabsTime(obt); |
323 |
|
// |
324 |
|
// TString thetime = dbtime->ConvertTime(tzone,abtime); |
325 |
|
printf("\n OBT %u in the file %s corresponds to Resurs time %u \n",res,tsfile.Data(),restime); |
326 |
|
delete ctime; |
327 |
|
}; |
328 |
|
}; |
329 |
|
}; |
330 |
|
if ( (convres && !convobtts) ){ |
331 |
|
printf("\n To convert a OBT to the Resurs time you must provide both OBT and file to be used for time sync \n"); |
332 |
|
}; |
333 |
|
// |
334 |
// Which run contains the date "runtime"? |
// Which run contains the date "runtime"? |
335 |
// |
// |
336 |
if ( ruti ){ |
if ( ruti ){ |
388 |
if ( dtle ){ |
if ( dtle ){ |
389 |
// |
// |
390 |
// |
// |
391 |
TDatime ti = TDatime(runtime.Data()); |
TDatime ti = TDatime(tletime.Data()); |
392 |
// |
// |
393 |
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); |
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); |
394 |
// |
// |
480 |
exit(-4); |
exit(-4); |
481 |
}; |
}; |
482 |
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()); |
483 |
|
//filename = glroot->NAME; |
484 |
found = true; |
found = true; |
485 |
}; |
}; |
486 |
// |
// |
533 |
} else { |
} else { |
534 |
myquery.str(""); |
myquery.str(""); |
535 |
myquery << "select "; |
myquery << "select "; |
536 |
myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME "; |
myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME,NEVENTS "; |
537 |
myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; |
myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; |
538 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
539 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
541 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
542 |
found = true; |
found = true; |
543 |
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()); |
544 |
TString UTC="UTC"; |
TString UTC=tzone.Data(); |
545 |
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))); |
546 |
}; |
}; |
547 |
delete pResult; |
delete pResult; |
548 |
myquery.str(""); |
myquery.str(""); |
554 |
Row = pResult->Next(); |
Row = pResult->Next(); |
555 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
556 |
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()); |
557 |
TString UTC="UTC"; |
TString UTC=tzone.Data(); |
558 |
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()); |
559 |
}; |
}; |
560 |
// |
// |
561 |
if ( !found ){ |
if ( !found ){ |
579 |
}; |
}; |
580 |
}; |
}; |
581 |
// |
// |
582 |
|
// Which runs are contained in the file "l2filename"? |
583 |
|
// |
584 |
|
if ( strcmp(l2filename.Data(),"") ){ |
585 |
|
// ---------------- |
586 |
|
Bool_t found = false; |
587 |
|
Int_t ID = 0; |
588 |
|
Int_t ID_RAW = 0; |
589 |
|
// |
590 |
|
const char *rawpath = ""; |
591 |
|
const char *rawname = ""; |
592 |
|
// |
593 |
|
myquery.str(""); |
594 |
|
myquery << "select "; |
595 |
|
myquery << " ID"; |
596 |
|
myquery << ",ID_RAW"; |
597 |
|
myquery << ",PATH"; |
598 |
|
myquery << ",NAME"; |
599 |
|
myquery << " from GL_ROOT where NAME=\"" << l2filename.Data() << "\";"; |
600 |
|
pResult = dbc->Query(myquery.str().c_str()); |
601 |
|
for( r=0; r < 1000; r++){ |
602 |
|
Row = pResult->Next(); |
603 |
|
if( Row == NULL ) break; |
604 |
|
for( t = 0; t < pResult->GetFieldCount(); t++){ |
605 |
|
if(t==0) ID = atoi(Row->GetField(t)); |
606 |
|
if(t==1) ID_RAW = atoi(Row->GetField(t)); |
607 |
|
}; |
608 |
|
}; |
609 |
|
delete pResult; |
610 |
|
if ( !ID ){ |
611 |
|
printf("\n No file with name %s in the DB!\n",l2filename.Data()); |
612 |
|
} else { |
613 |
|
nr = 0; |
614 |
|
rlist[0] = 0; |
615 |
|
myquery.str(""); |
616 |
|
myquery << "select "; |
617 |
|
myquery << " ID,ID_ROOT_L0 "; |
618 |
|
myquery << " from GL_RUN where ID_ROOT_L2=" << ID << ";"; |
619 |
|
pResult = dbc->Query(myquery.str().c_str()); |
620 |
|
for( r=0; r < pResult->GetRowCount(); r++){ |
621 |
|
Row = pResult->Next(); |
622 |
|
if( Row == NULL ) break; |
623 |
|
found = true; |
624 |
|
if ( !r ) printf("\n File %s contains the following runs: \n\n",l2filename.Data()); |
625 |
|
printf(" %u ",(UInt_t)atoll(Row->GetField(0))); |
626 |
|
if ( r < (pResult->GetRowCount()-1) ){ |
627 |
|
printf("-"); |
628 |
|
} else { |
629 |
|
printf("\n\n"); |
630 |
|
}; |
631 |
|
if ( (UInt_t)atoll(Row->GetField(1)) != rlist[nr] ){ |
632 |
|
nr++; |
633 |
|
rlist[nr] = (UInt_t)atoll(Row->GetField(1)); |
634 |
|
}; |
635 |
|
}; |
636 |
|
delete pResult; |
637 |
|
// |
638 |
|
printf("\n File %s contains runs from L0 files: \n\n",l2filename.Data()); |
639 |
|
for (UInt_t l=1; l<nr+1; l++){ |
640 |
|
myquery.str(""); |
641 |
|
myquery << "select "; |
642 |
|
myquery << " PATH,NAME"; |
643 |
|
myquery << " from GL_ROOT where ID=" << rlist[l] << ";"; |
644 |
|
pResult = dbc->Query(myquery.str().c_str()); |
645 |
|
for( r=0; r < pResult->GetRowCount(); r++){ |
646 |
|
Row = pResult->Next(); |
647 |
|
if( Row == NULL ) break; |
648 |
|
for( t = 0; t < pResult->GetFieldCount(); t++){ |
649 |
|
if(t==0) rawpath = Row->GetField(t); |
650 |
|
if(t==1) rawname = Row->GetField(t); |
651 |
|
}; |
652 |
|
printf(" %s/%s \n",rawpath,rawname); |
653 |
|
}; |
654 |
|
delete pResult; |
655 |
|
}; |
656 |
|
}; |
657 |
|
}; |
658 |
|
// |
659 |
// Close the DB connection |
// Close the DB connection |
660 |
// |
// |
661 |
if ( dbc ) dbc->Close(); |
if ( dbc ) dbc->Close(); |