| 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 = $PAM_DBHOST or 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 = $PAM_DBUSER or \"anonymous\"] \n"); |
printf("\n -user username for the DB [default = $PAM_DBUSER or \"anonymous\"] \n"); |
| 37 |
printf("\n -psw password for the DB [default = $PAM_DBPSW or \"\"]\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 [ -tzone timezone -time \"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 contains the given date in the given time zone \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"); |
| 68 |
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
| 69 |
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
| 70 |
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
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; |
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
| 75 |
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
| 76 |
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
| 77 |
// |
// |
| 78 |
printf(" host %s user %s psw %s \n",host.Data(),user.Data(),psw.Data()); |
// printf(" host %s user %s psw %s \n",host.Data(),user.Data(),psw.Data()); |
| 79 |
// |
// |
| 80 |
TString tzone = "MSK"; |
TString tzone = "UTC"; |
|
TString tzone2 = "MSK"; |
|
| 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; |
TSQLResult *pResult; |
| 92 |
TSQLRow *Row; |
TSQLRow *Row; |
| 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") ) { |
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") ) { |
if ( !strcmp(inps[i],"-runat") ) { |
| 183 |
ruti = true; |
ruti = true; |
| 184 |
if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){ |
if ( numinp-1 < i+1 ){ |
| 185 |
if ( numinp < i+2 ){ |
r2d2usage(); |
| 186 |
r2d2usage(); |
exit(-3); |
|
throw -3; |
|
|
}; |
|
|
i += 2; |
|
|
while ( strcmp(inps[i],"]") ){ |
|
|
if ( !strcmp(inps[i],"-tzone") ) { |
|
|
if ( numinp-1 < i+1 ){ |
|
|
r2d2usage(); |
|
|
exit(-3); |
|
|
}; |
|
|
tzone2 = (TString)inps[i+1]; |
|
|
}; |
|
|
if ( !strcmp(inps[i],"-time") ) { |
|
|
if ( numinp-1 < i+1 ){ |
|
|
r2d2usage(); |
|
|
exit(-3); |
|
|
}; |
|
|
runtime = (TString)inps[i+1]; |
|
|
}; |
|
|
i++; |
|
|
if ( i > numinp-1 ){ |
|
|
r2d2usage(); |
|
|
throw -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 DB 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"? |
| 255 |
TDatime *time = new TDatime(runtime.Data()); |
TDatime *time = new TDatime(runtime.Data()); |
| 256 |
UInt_t dbti = time->Convert(); |
UInt_t dbti = time->Convert(); |
| 257 |
// |
// |
| 258 |
TString thetime = dbtime->UnConvertTime(tzone2.Data(),dbti); |
TString thetime = dbtime->UnConvertTime(tzone,dbti); |
| 259 |
// |
// |
| 260 |
TDatime *time2 = new TDatime(thetime.Data()); |
TDatime *time2 = new TDatime(thetime.Data()); |
| 261 |
UInt_t mytime = time2->Convert(); |
UInt_t mytime = time2->Convert(); |
| 270 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 271 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 272 |
if ( !r && !Row ){ |
if ( !r && !Row ){ |
| 273 |
printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone2.Data(),mytime); |
printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone.Data(),mytime); |
| 274 |
}; |
}; |
| 275 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 276 |
printf("\n Date %s %s (DB time %u ) is contained in run %u \n",runtime.Data(),tzone2.Data(),mytime,(UInt_t)atoll(Row->GetField(0))); |
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 |
// |
// |
| 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 |
}; |
}; |
| 337 |
}; |
}; |
| 338 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 339 |
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()); |
| 340 |
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()); |
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(""); |