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]\n"); |
36 |
printf("\n -idRun run ID_RUN: ID number of the run \n"); |
printf(" -n | --neat used with '-filename' returns only the run ID number\n"); |
37 |
printf("\n -filename file output yoda filename \n"); |
printf(" -idRun run ID_RUN: ID number of the run \n"); |
38 |
printf("\n -host name for the host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); |
printf(" -filename file output yoda filename \n"); |
39 |
printf("\n -user username for the DB [default = $PAM_DBUSER or \"anonymous\"] \n"); |
printf(" -l2filename file output amidala filename \n"); |
40 |
printf("\n -psw password for the DB [default = $PAM_DBPSW or \"\"]\n"); |
printf(" -host name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); |
41 |
printf("\n -tzone timezone the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n"); |
printf(" -user username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n"); |
42 |
printf("\n -convert dbtime convert the dbtime given in seconds (from the DB) to a string\n"); |
printf(" -psw password for the DB connection [default = $PAM_DBPSW or \"\"]\n"); |
43 |
printf("\n -runat date returns run number which contains the given date,\n"); |
printf(" -tzone timezone the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n"); |
44 |
printf("\n for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); |
printf(" -convert dbtime convert the dbtime given in seconds (from the DB) to a string\n"); |
45 |
printf("\n -runatDB time returns run number which contains the given DB time\n"); |
printf(" -runat date returns run number which contains the given date,\n"); |
46 |
printf("\n -tsfile file yoda filename for the time sync (to be used with -obt)\n"); |
printf(" for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); |
47 |
printf("\n -obt OBT OBT in ms returns a date (to be used with -tsfile)\n"); |
printf(" -runatDB time returns run number which contains the given DB time\n"); |
48 |
printf("\n -getRTime OBT OBT in ms returns Resurs time (to be used with -tsfile)\n"); |
printf(" -tsfile file yoda filename for the time sync (to be used with -obt)\n"); |
49 |
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"); |
50 |
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"); |
51 |
|
printf(" -dumpTLEfor date save into file tle.txt the TLE for the given date,\n"); |
52 |
|
printf(" for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); |
53 |
printf("\nExamples: \n"); |
printf("\nExamples: \n"); |
54 |
printf("\n R2-D2 -idRun 1085 \n"); |
printf(" R2-D2 -idRun 1085 \n"); |
55 |
printf("\n R2-D2 -filename DW_050208_00900.root \n"); |
printf(" R2-D2 -filename DW_050208_00900.root \n"); |
56 |
printf("\n R2-D2 -idRun 1085 -filename DW_050208_00900.root \n"); |
printf(" R2-D2 -idRun 1085 -filename DW_050208_00900.root \n\n"); |
57 |
}; |
}; |
58 |
// |
// |
59 |
// Here the main |
// Here the main |
68 |
UInt_t run = 0ULL; |
UInt_t run = 0ULL; |
69 |
// |
// |
70 |
TString filename = ""; |
TString filename = ""; |
71 |
|
TString l2filename = ""; |
72 |
// |
// |
73 |
TSQLServer *dbc = 0; |
TSQLServer *dbc = 0; |
74 |
TString host = "mysql://localhost/pamelaprod"; |
TString host = "mysql://localhost/pamelaprod"; |
98 |
Bool_t ruti2 = false; |
Bool_t ruti2 = false; |
99 |
Bool_t convobt = false; |
Bool_t convobt = false; |
100 |
Bool_t convobtts = false; |
Bool_t convobtts = false; |
101 |
|
Bool_t neat = false; |
102 |
// |
// |
103 |
UInt_t runtime2 = 0; |
UInt_t runtime2 = 0; |
104 |
UInt_t obt = 0; |
UInt_t obt = 0; |
124 |
r2d2usage(); |
r2d2usage(); |
125 |
exit(0); |
exit(0); |
126 |
}; |
}; |
127 |
|
if ( !strcmp(inps[i],"-n") || !strcmp(inps[i],"--neat") ){ |
128 |
|
neat = true; |
129 |
|
}; |
130 |
if ( !strcmp(inps[i],"-idRun") ) { |
if ( !strcmp(inps[i],"-idRun") ) { |
131 |
if ( numinp-1 < i+1 ) { |
if ( numinp-1 < i+1 ) { |
132 |
r2d2usage(); |
r2d2usage(); |
141 |
}; |
}; |
142 |
filename = (TString)inps[i+1]; |
filename = (TString)inps[i+1]; |
143 |
}; |
}; |
144 |
|
if ( !strcmp(inps[i],"-l2filename") ) { |
145 |
|
if ( numinp-1 < i+1 ){ |
146 |
|
r2d2usage(); |
147 |
|
exit(-3); |
148 |
|
}; |
149 |
|
l2filename = (TString)inps[i+1]; |
150 |
|
}; |
151 |
if ( !strcmp(inps[i],"-host") ) { |
if ( !strcmp(inps[i],"-host") ) { |
152 |
if ( numinp-1 < i+1 ){ |
if ( numinp-1 < i+1 ){ |
153 |
r2d2usage(); |
r2d2usage(); |
273 |
GL_ROOT *glroot = new GL_ROOT(); |
GL_ROOT *glroot = new GL_ROOT(); |
274 |
GL_RUN *glrun = new GL_RUN(); |
GL_RUN *glrun = new GL_RUN(); |
275 |
GL_TIMESYNC *dbtime = new GL_TIMESYNC(); |
GL_TIMESYNC *dbtime = new GL_TIMESYNC(); |
276 |
|
UInt_t nr = 0; |
277 |
|
UInt_t rlist[500]; |
278 |
// |
// |
279 |
// At which date correspond the DB time "dbti"? |
// At which date correspond the DB time "dbti"? |
280 |
// |
// |
485 |
exit(-4); |
exit(-4); |
486 |
}; |
}; |
487 |
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()); |
488 |
filename = glroot->NAME; |
//filename = glroot->NAME; |
489 |
found = true; |
found = true; |
490 |
}; |
}; |
491 |
// |
// |
534 |
}; |
}; |
535 |
delete pResult; |
delete pResult; |
536 |
if ( !ID && !ID_RAW ){ |
if ( !ID && !ID_RAW ){ |
537 |
printf("\n No file with name %s in the DB!\n",filename.Data()); |
if ( !neat ) printf("\n No file with name %s in the DB!\n",filename.Data()); |
538 |
} else { |
} else { |
539 |
myquery.str(""); |
myquery.str(""); |
540 |
myquery << "select "; |
myquery << "select "; |
545 |
Row = pResult->Next(); |
Row = pResult->Next(); |
546 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
547 |
found = true; |
found = true; |
548 |
if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data()); |
if ( !r && !neat ) printf("\n File %s contains the following runs: \n\n",filename.Data()); |
549 |
TString UTC=tzone.Data(); |
TString UTC=tzone.Data(); |
550 |
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))); |
if ( !neat ) printf(" => ID = %u --> 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))); |
551 |
|
if ( neat ) printf("%u\n",(UInt_t)atoll(Row->GetField(0))); |
552 |
}; |
}; |
553 |
delete pResult; |
delete pResult; |
554 |
myquery.str(""); |
myquery.str(""); |
559 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
560 |
Row = pResult->Next(); |
Row = pResult->Next(); |
561 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
562 |
if ( !r ) printf("\n File %s contains the following DELETED runs: \n\n",filename.Data()); |
if ( !r && !neat ) printf("\n File %s contains the following DELETED runs: \n\n",filename.Data()); |
563 |
TString UTC=tzone.Data(); |
TString UTC=tzone.Data(); |
564 |
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()); |
if ( !neat ) 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()); |
565 |
}; |
}; |
566 |
// |
// |
567 |
if ( !found ){ |
if ( !found ){ |
568 |
printf("\n No run associated to the file %s \n",filename.Data()); |
if ( !neat ) printf("\n No run associated to the file %s \n",filename.Data()); |
569 |
}; |
}; |
570 |
myquery.str(""); |
myquery.str(""); |
571 |
myquery << "select "; |
myquery << "select "; |
581 |
}; |
}; |
582 |
}; |
}; |
583 |
delete pResult; |
delete pResult; |
584 |
printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname); |
if ( !neat ) printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname); |
585 |
|
}; |
586 |
|
}; |
587 |
|
// |
588 |
|
// Which runs are contained in the file "l2filename"? |
589 |
|
// |
590 |
|
if ( strcmp(l2filename.Data(),"") ){ |
591 |
|
// ---------------- |
592 |
|
Bool_t found = false; |
593 |
|
Int_t ID = 0; |
594 |
|
Int_t ID_RAW = 0; |
595 |
|
// |
596 |
|
const char *rawpath = ""; |
597 |
|
const char *rawname = ""; |
598 |
|
// |
599 |
|
myquery.str(""); |
600 |
|
myquery << "select "; |
601 |
|
myquery << " ID"; |
602 |
|
myquery << ",ID_RAW"; |
603 |
|
myquery << ",PATH"; |
604 |
|
myquery << ",NAME"; |
605 |
|
myquery << " from GL_ROOT where NAME=\"" << l2filename.Data() << "\" order by INSERT_TIME desc limit 1;"; |
606 |
|
pResult = dbc->Query(myquery.str().c_str()); |
607 |
|
for( r=0; r < 1000; r++){ |
608 |
|
Row = pResult->Next(); |
609 |
|
if( Row == NULL ) break; |
610 |
|
for( t = 0; t < pResult->GetFieldCount(); t++){ |
611 |
|
if(t==0) ID = atoi(Row->GetField(t)); |
612 |
|
if(t==1) ID_RAW = atoi(Row->GetField(t)); |
613 |
|
}; |
614 |
|
}; |
615 |
|
delete pResult; |
616 |
|
if ( !ID ){ |
617 |
|
printf("\n No file with name %s in the DB!\n",l2filename.Data()); |
618 |
|
} else { |
619 |
|
nr = 0; |
620 |
|
rlist[0] = 0; |
621 |
|
myquery.str(""); |
622 |
|
myquery << "select "; |
623 |
|
myquery << " ID,ID_ROOT_L0 "; |
624 |
|
myquery << " from GL_RUN where ID_ROOT_L2=" << ID << ";"; |
625 |
|
pResult = dbc->Query(myquery.str().c_str()); |
626 |
|
for( r=0; r < pResult->GetRowCount(); r++){ |
627 |
|
Row = pResult->Next(); |
628 |
|
if( Row == NULL ) break; |
629 |
|
found = true; |
630 |
|
if ( !r ) printf("\n File %s contains the following runs: \n\n",l2filename.Data()); |
631 |
|
printf(" %u ",(UInt_t)atoll(Row->GetField(0))); |
632 |
|
if ( r < (pResult->GetRowCount()-1) ){ |
633 |
|
printf("-"); |
634 |
|
} else { |
635 |
|
printf("\n\n"); |
636 |
|
}; |
637 |
|
if ( (UInt_t)atoll(Row->GetField(1)) != rlist[nr] ){ |
638 |
|
nr++; |
639 |
|
rlist[nr] = (UInt_t)atoll(Row->GetField(1)); |
640 |
|
}; |
641 |
|
}; |
642 |
|
delete pResult; |
643 |
|
// |
644 |
|
printf("\n File %s contains runs from L0 files: \n\n",l2filename.Data()); |
645 |
|
for (UInt_t l=1; l<nr+1; l++){ |
646 |
|
myquery.str(""); |
647 |
|
myquery << "select "; |
648 |
|
myquery << " PATH,NAME"; |
649 |
|
myquery << " from GL_ROOT where ID=" << rlist[l] << ";"; |
650 |
|
pResult = dbc->Query(myquery.str().c_str()); |
651 |
|
for( r=0; r < pResult->GetRowCount(); r++){ |
652 |
|
Row = pResult->Next(); |
653 |
|
if( Row == NULL ) break; |
654 |
|
for( t = 0; t < pResult->GetFieldCount(); t++){ |
655 |
|
if(t==0) rawpath = Row->GetField(t); |
656 |
|
if(t==1) rawname = Row->GetField(t); |
657 |
|
}; |
658 |
|
printf(" %s/%s \n",rawpath,rawname); |
659 |
|
}; |
660 |
|
delete pResult; |
661 |
|
}; |
662 |
}; |
}; |
663 |
}; |
}; |
664 |
// |
// |
666 |
// |
// |
667 |
if ( dbc ) dbc->Close(); |
if ( dbc ) dbc->Close(); |
668 |
// |
// |
669 |
printf("\n"); |
if ( !neat ) printf("\n"); |
670 |
// |
// |
671 |
exit(0); |
exit(0); |
672 |
} |
} |