| 1 | // | 
| 2 | // C/C++ headers | 
| 3 | // | 
| 4 | #include <iostream> | 
| 5 | #include <iomanip> | 
| 6 | #include <fstream> | 
| 7 | #include <sstream> | 
| 8 | // | 
| 9 | // ROOT headers | 
| 10 | // | 
| 11 | #include <TString.h> | 
| 12 | #include <TTimeStamp.h> | 
| 13 | #include <TSQLServer.h> | 
| 14 | #include <TFile.h> | 
| 15 | #include <TSystem.h> | 
| 16 | // | 
| 17 | // Detector's package headers | 
| 18 | // | 
| 19 | #include <GLTables.h> | 
| 20 | // | 
| 21 | using namespace std; | 
| 22 | // | 
| 23 | // | 
| 24 | // | 
| 25 | #include <YodaProfilerVerl2.h> | 
| 26 | // | 
| 27 | // Usage subroutine | 
| 28 | // | 
| 29 | void r2d2usage(){ | 
| 30 | printf("\nUsage:\n"); | 
| 31 | printf("\n R2-D2 [ options ]\n"); | 
| 32 | printf("\n Options are:\n\n"); | 
| 33 | printf(" --version        print informations about compilation and exit\n"); | 
| 34 | printf(" -h | --help      print this help and exit \n"); | 
| 35 | printf(" -v | --verbose   be verbose [default]\n"); | 
| 36 | printf(" -n | --neat      used with '-filename' returns only the run ID number\n"); | 
| 37 | printf(" -idRun run       ID_RUN: ID number of the run \n"); | 
| 38 | printf(" -filename file   output yoda filename \n"); | 
| 39 | printf(" -l2filename file output amidala filename \n"); | 
| 40 | printf(" -host            name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); | 
| 41 | printf(" -user            username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n"); | 
| 42 | printf(" -psw             password for the DB connection [default = $PAM_DBPSW or \"\"]\n"); | 
| 43 | printf(" -tzone timezone  the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n"); | 
| 44 | printf(" -convert dbtime  convert the dbtime given in seconds (from the DB) to a string\n"); | 
| 45 | printf(" -runat date      returns run number which contains the given date,\n"); | 
| 46 | printf("                  for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); | 
| 47 | printf(" -runatDB time    returns run number which contains the given DB time\n"); | 
| 48 | printf(" -tsfile file     yoda filename for the time sync (to be used with -obt)\n"); | 
| 49 | printf(" -obt OBT         OBT in ms returns a date (to be used with -tsfile)\n"); | 
| 50 | 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"); | 
| 54 | printf("      R2-D2 -idRun 1085 \n"); | 
| 55 | printf("      R2-D2 -filename DW_050208_00900.root \n"); | 
| 56 | printf("      R2-D2 -idRun 1085 -filename DW_050208_00900.root \n\n"); | 
| 57 | }; | 
| 58 | // | 
| 59 | // Here the main | 
| 60 | // | 
| 61 | int main(int numinp, char *inps[]){ | 
| 62 | // | 
| 63 | // Variables booking | 
| 64 | // | 
| 65 | TString message; | 
| 66 | Int_t error = 0; | 
| 67 | // | 
| 68 | UInt_t run = 0ULL; | 
| 69 | // | 
| 70 | TString filename = ""; | 
| 71 | TString l2filename = ""; | 
| 72 | // | 
| 73 | TSQLServer *dbc = 0; | 
| 74 | TString host = "mysql://localhost/pamelaprod"; | 
| 75 | TString user = "anonymous"; | 
| 76 | TString psw = ""; | 
| 77 | // | 
| 78 | const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); | 
| 79 | const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); | 
| 80 | const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); | 
| 81 | if ( !pamdbhost ) pamdbhost = ""; | 
| 82 | if ( !pamdbuser ) pamdbuser = ""; | 
| 83 | if ( !pamdbpsw ) pamdbpsw = ""; | 
| 84 | if ( strcmp(pamdbhost,"") ) host = pamdbhost; | 
| 85 | if ( strcmp(pamdbuser,"") ) user = pamdbuser; | 
| 86 | if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; | 
| 87 | // | 
| 88 | //  printf(" host %s user %s psw %s \n",host.Data(),user.Data(),psw.Data()); | 
| 89 | // | 
| 90 | TString tzone = "UTC"; | 
| 91 | TString runtime = "1970-01-01 00:00:00"; | 
| 92 | TString tletime = "1970-01-01 00:00:00"; | 
| 93 | UInt_t dbti = 0; | 
| 94 | Bool_t convert = false; | 
| 95 | Bool_t convres = false; | 
| 96 | Bool_t ruti = false; | 
| 97 | Bool_t dtle = false; | 
| 98 | Bool_t ruti2 = false; | 
| 99 | Bool_t convobt = false; | 
| 100 | Bool_t convobtts = false; | 
| 101 | Bool_t neat = false; | 
| 102 | // | 
| 103 | UInt_t runtime2 = 0; | 
| 104 | UInt_t obt = 0; | 
| 105 | UInt_t res = 0; | 
| 106 | TString tsfile = ""; | 
| 107 | // | 
| 108 | TSQLResult *pResult; | 
| 109 | TSQLRow *Row; | 
| 110 | int t; | 
| 111 | int r; | 
| 112 | stringstream myquery; | 
| 113 | // | 
| 114 | // Checking input parameters | 
| 115 | // | 
| 116 | Int_t i = 0; | 
| 117 | if ( numinp > 1 ){ | 
| 118 | while ( i < numinp ){ | 
| 119 | if ( !strcmp(inps[i],"--version") ){ | 
| 120 | YodaProfilerInfo(true); | 
| 121 | exit(0); | 
| 122 | }; | 
| 123 | if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){ | 
| 124 | r2d2usage(); | 
| 125 | exit(0); | 
| 126 | }; | 
| 127 | if ( !strcmp(inps[i],"-n") || !strcmp(inps[i],"--neat") ){ | 
| 128 | neat = true; | 
| 129 | }; | 
| 130 | if ( !strcmp(inps[i],"-idRun") ) { | 
| 131 | if ( numinp-1 < i+1 ) { | 
| 132 | r2d2usage(); | 
| 133 | exit(-3); | 
| 134 | }; | 
| 135 | run = (UInt_t)atoll(inps[i+1]); | 
| 136 | }; | 
| 137 | if ( !strcmp(inps[i],"-filename") ) { | 
| 138 | if ( numinp-1 < i+1 ){ | 
| 139 | r2d2usage(); | 
| 140 | exit(-3); | 
| 141 | }; | 
| 142 | 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") ) { | 
| 152 | if ( numinp-1 < i+1 ){ | 
| 153 | r2d2usage(); | 
| 154 | exit(-3); | 
| 155 | }; | 
| 156 | host = (TString)inps[i+1]; | 
| 157 | }; | 
| 158 | if ( !strcmp(inps[i],"-user") ) { | 
| 159 | if ( numinp-1 < i+1 ){ | 
| 160 | r2d2usage(); | 
| 161 | exit(-3); | 
| 162 | }; | 
| 163 | user = (TString)inps[i+1]; | 
| 164 | }; | 
| 165 | if ( !strcmp(inps[i],"-psw") ) { | 
| 166 | if ( numinp-1 < i+1 ){ | 
| 167 | r2d2usage(); | 
| 168 | exit(-3); | 
| 169 | }; | 
| 170 | psw = (TString)inps[i+1]; | 
| 171 | }; | 
| 172 | // | 
| 173 | if ( !strcmp(inps[i],"-tsfile") ) { | 
| 174 | convobtts = true; | 
| 175 | if ( numinp-1 < i+1 ){ | 
| 176 | r2d2usage(); | 
| 177 | exit(-3); | 
| 178 | }; | 
| 179 | tsfile = (TString)inps[i+1]; | 
| 180 | }; | 
| 181 | // | 
| 182 | if ( !strcmp(inps[i],"-obt") ) { | 
| 183 | convobt = true; | 
| 184 | if ( numinp-1 < i+1 ){ | 
| 185 | r2d2usage(); | 
| 186 | exit(-3); | 
| 187 | }; | 
| 188 | obt = (UInt_t)atoll(inps[i+1]); | 
| 189 | }; | 
| 190 | // | 
| 191 | if ( !strcmp(inps[i],"-getRTime") ) { | 
| 192 | convres = true; | 
| 193 | if ( numinp-1 < i+1 ){ | 
| 194 | r2d2usage(); | 
| 195 | exit(-3); | 
| 196 | }; | 
| 197 | res = (UInt_t)atoll(inps[i+1]); | 
| 198 | }; | 
| 199 | // | 
| 200 | // | 
| 201 | if ( !strcmp(inps[i],"-tzone") ) { | 
| 202 | if ( numinp-1 < i+1 ){ | 
| 203 | r2d2usage(); | 
| 204 | exit(-3); | 
| 205 | }; | 
| 206 | tzone = (TString)inps[i+1]; | 
| 207 | }; | 
| 208 | // | 
| 209 | if ( !strcmp(inps[i],"-convert") ) { | 
| 210 | convert = true; | 
| 211 | if ( numinp-1 < i+1 ){ | 
| 212 | r2d2usage(); | 
| 213 | exit(-3); | 
| 214 | }; | 
| 215 | dbti = (UInt_t)atoll(inps[i+1]); | 
| 216 | }; | 
| 217 | // | 
| 218 | if ( !strcmp(inps[i],"-runat") ) { | 
| 219 | ruti = true; | 
| 220 | if ( numinp-1 < i+1 ){ | 
| 221 | r2d2usage(); | 
| 222 | exit(-3); | 
| 223 | }; | 
| 224 | runtime = (TString)inps[i+1]; | 
| 225 | }; | 
| 226 | // | 
| 227 | if ( !strcmp(inps[i],"-dumpTLEfor") ) { | 
| 228 | dtle = true; | 
| 229 | if ( numinp-1 < i+1 ){ | 
| 230 | r2d2usage(); | 
| 231 | exit(-3); | 
| 232 | }; | 
| 233 | tletime = (TString)inps[i+1]; | 
| 234 | }; | 
| 235 | // | 
| 236 | // | 
| 237 | if ( !strcmp(inps[i],"-runatDB") ) { | 
| 238 | ruti2 = true; | 
| 239 | if ( numinp-1 < i+1 ){ | 
| 240 | r2d2usage(); | 
| 241 | exit(-3); | 
| 242 | }; | 
| 243 | runtime2 = (UInt_t)atoll(inps[i+1]); | 
| 244 | }; | 
| 245 | // | 
| 246 | i++; | 
| 247 | }; | 
| 248 | // | 
| 249 | } else { | 
| 250 | // | 
| 251 | // no input parameters exit with error, we need at least the run id. | 
| 252 | // | 
| 253 | r2d2usage(); | 
| 254 | exit(-2); | 
| 255 | }; | 
| 256 | // | 
| 257 | // Connect to the DB | 
| 258 | // | 
| 259 | dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); | 
| 260 | if( !dbc ) throw -2; | 
| 261 | // | 
| 262 | bool connect = dbc->IsConnected(); | 
| 263 | // | 
| 264 | if( !connect ){ | 
| 265 | printf(" Error, not connected to DB\n"); | 
| 266 | exit(-1); | 
| 267 | }; | 
| 268 | // | 
| 269 | myquery.str(""); | 
| 270 | myquery << "SET time_zone='+0:00'"; | 
| 271 | dbc->Query(myquery.str().c_str()); | 
| 272 | // | 
| 273 | GL_ROOT *glroot = new GL_ROOT(); | 
| 274 | GL_RUN *glrun = new GL_RUN(); | 
| 275 | 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"? | 
| 280 | // | 
| 281 | if ( convert ){ | 
| 282 | printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone,dbti).Data(),tzone.Data()); | 
| 283 | }; | 
| 284 | // | 
| 285 | // convert OBT to date | 
| 286 | // | 
| 287 | if ( convobt && convobtts ){ | 
| 288 | UInt_t id = 0; | 
| 289 | myquery.str(""); | 
| 290 | myquery << "select "; | 
| 291 | myquery << " ID"; | 
| 292 | myquery << " from GL_ROOT where NAME=\"" << tsfile.Data() << "\";"; | 
| 293 | pResult = dbc->Query(myquery.str().c_str()); | 
| 294 | if ( pResult ){ | 
| 295 | Row = pResult->Next(); | 
| 296 | if ( Row ){ | 
| 297 | id = (UInt_t)atoll(Row->GetField(0)); | 
| 298 | delete pResult; | 
| 299 | GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc); | 
| 300 | UInt_t abtime = ctime->DBabsTime(obt); | 
| 301 | TString thetime = dbtime->ConvertTime(tzone,abtime); | 
| 302 | 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()); | 
| 303 | delete ctime; | 
| 304 | }; | 
| 305 | }; | 
| 306 | }; | 
| 307 | if ( (convobt && !convobtts) ){ | 
| 308 | printf("\n To convert a OBT to a date you must provide both OBT and file to be used for time sync \n"); | 
| 309 | }; | 
| 310 | // | 
| 311 | // convert OBT to Resurs seconds | 
| 312 | // | 
| 313 | if ( convres && convobtts ){ | 
| 314 | UInt_t id = 0; | 
| 315 | myquery.str(""); | 
| 316 | myquery << "select "; | 
| 317 | myquery << " ID"; | 
| 318 | myquery << " from GL_ROOT where NAME=\"" << tsfile.Data() << "\";"; | 
| 319 | pResult = dbc->Query(myquery.str().c_str()); | 
| 320 | if ( pResult ){ | 
| 321 | Row = pResult->Next(); | 
| 322 | if ( Row ){ | 
| 323 | id = (UInt_t)atoll(Row->GetField(0)); | 
| 324 | delete pResult; | 
| 325 | GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc); | 
| 326 | UInt_t restime = ctime->ResursTime(res); | 
| 327 | //UInt_t abtime = ctime->DBabsTime(obt); | 
| 328 | // | 
| 329 | //      TString thetime = dbtime->ConvertTime(tzone,abtime); | 
| 330 | printf("\n OBT %u in the file %s corresponds to Resurs time %u  \n",res,tsfile.Data(),restime); | 
| 331 | delete ctime; | 
| 332 | }; | 
| 333 | }; | 
| 334 | }; | 
| 335 | if ( (convres && !convobtts) ){ | 
| 336 | printf("\n To convert a OBT to the Resurs time you must provide both OBT and file to be used for time sync \n"); | 
| 337 | }; | 
| 338 | // | 
| 339 | // Which run contains the date "runtime"? | 
| 340 | // | 
| 341 | if ( ruti ){ | 
| 342 | // | 
| 343 | TDatime ti = TDatime(runtime.Data()); | 
| 344 | // | 
| 345 | 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); | 
| 346 | // | 
| 347 | UInt_t dbti = time->GetSec(); | 
| 348 | // | 
| 349 | TString thetime = dbtime->UnConvertTime(tzone,dbti); | 
| 350 | // | 
| 351 | ti = TDatime(thetime.Data()); | 
| 352 | 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); | 
| 353 | // | 
| 354 | UInt_t mytime = time2->GetSec(); | 
| 355 | // | 
| 356 | Bool_t found = false; | 
| 357 | // | 
| 358 | myquery.str(""); | 
| 359 | myquery << "select "; | 
| 360 | myquery << " ID "; | 
| 361 | myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND " | 
| 362 | << " RUNTRAILER_TIME>=" << mytime  << " ;"; | 
| 363 | //    printf("myquery is %s \n",myquery.str().c_str()); | 
| 364 | pResult = dbc->Query(myquery.str().c_str()); | 
| 365 | for( r=0; r < 1000; r++){ | 
| 366 | Row = pResult->Next(); | 
| 367 | if( Row == NULL ) break; | 
| 368 | found = true; | 
| 369 | 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))); | 
| 370 | }; | 
| 371 | myquery.str(""); | 
| 372 | myquery << "select "; | 
| 373 | myquery << " ID "; | 
| 374 | myquery << " from GL_RUN_TRASH where BELONGED_TO='GL_RUN' AND RUNHEADER_TIME<=" << mytime << " AND " | 
| 375 | << " RUNTRAILER_TIME>=" << mytime  << " ;"; | 
| 376 | //    printf("myquery is %s \n",myquery.str().c_str()); | 
| 377 | pResult = dbc->Query(myquery.str().c_str()); | 
| 378 | for( r=0; r < 1000; r++){ | 
| 379 | Row = pResult->Next(); | 
| 380 | if( Row == NULL ) break; | 
| 381 | printf("\n Date %s %s (DB time %u ) is contained in run %u in the GL_RUN_TRASH table \n",runtime.Data(),tzone.Data(),mytime,(UInt_t)atoll(Row->GetField(0))); | 
| 382 | found = true; | 
| 383 | }; | 
| 384 | // | 
| 385 | if ( !found ){ | 
| 386 | printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone.Data(),mytime); | 
| 387 | }; | 
| 388 | // | 
| 389 | }; | 
| 390 | // | 
| 391 | // Which tle must be used for the date "tletime"? | 
| 392 | // | 
| 393 | if ( dtle ){ | 
| 394 | // | 
| 395 | // | 
| 396 | TDatime ti = TDatime(tletime.Data()); | 
| 397 | // | 
| 398 | 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); | 
| 399 | // | 
| 400 | UInt_t dbti = time->GetSec(); | 
| 401 | // | 
| 402 | TString thetime = dbtime->UnConvertTime(tzone,dbti); | 
| 403 | // | 
| 404 | ti = TDatime(thetime.Data()); | 
| 405 | 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); | 
| 406 | // | 
| 407 | UInt_t mytime = time2->GetSec(); | 
| 408 | // | 
| 409 | myquery.str(""); | 
| 410 | myquery << " select ID,TLE1,TLE2,TLE3 from GL_TLE where FROM_TIME<='" << time2->AsString("s") << "' ORDER BY FROM_TIME DESC LIMIT 1;"; | 
| 411 | //    myquery << " from GL_TLE where FROM_TIME>=" << mytime << " ORDER BY FROM_TIME ASC LIMIT 1;"; | 
| 412 | //    printf("myquery is %s \n",myquery.str().c_str()); | 
| 413 | pResult = dbc->Query(myquery.str().c_str()); | 
| 414 | Row = pResult->Next(); | 
| 415 | if ( !Row ){ | 
| 416 | printf("\n No TLE in the DB for date %s %s (DB time %u )\n",tletime.Data(),tzone.Data(),mytime); | 
| 417 | }; | 
| 418 | printf("\n Date %s %s (DB time %u ) is contained in TLE %u \n",tletime.Data(),tzone.Data(),mytime,(UInt_t)atoll(Row->GetField(0))); | 
| 419 | printf("\n%s\n",Row->GetField(1)); | 
| 420 | printf("%s\n",Row->GetField(2)); | 
| 421 | printf("%s\n",Row->GetField(3)); | 
| 422 | // | 
| 423 | FILE *tlefile; | 
| 424 | tlefile = fopen("tle.txt","w"); | 
| 425 | fprintf(tlefile,"%s\n",Row->GetField(1)); | 
| 426 | fprintf(tlefile,"%s\n",Row->GetField(2)); | 
| 427 | fprintf(tlefile,"%s\n",Row->GetField(3)); | 
| 428 | fclose (tlefile); | 
| 429 | // | 
| 430 | printf("\n TLE has been dumped in file tle.txt \n"); | 
| 431 | }; | 
| 432 | // | 
| 433 | // Which run contains the dbtime "runtime2"? | 
| 434 | // | 
| 435 | if ( ruti2 ){ | 
| 436 | // | 
| 437 | UInt_t mytime = runtime2; | 
| 438 | // | 
| 439 | Bool_t found = false; | 
| 440 | myquery.str(""); | 
| 441 | myquery << "select "; | 
| 442 | myquery << " ID "; | 
| 443 | myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND " | 
| 444 | << " RUNTRAILER_TIME>=" << mytime  << " ;"; | 
| 445 | //    printf("myquery is %s \n",myquery.str().c_str()); | 
| 446 | pResult = dbc->Query(myquery.str().c_str()); | 
| 447 | for( r=0; r < 1000; r++){ | 
| 448 | Row = pResult->Next(); | 
| 449 | if( Row == NULL ) break; | 
| 450 | printf("\n DB time %u is contained in run %u \n",mytime,(UInt_t)atoll(Row->GetField(0))); | 
| 451 | found = true; | 
| 452 | }; | 
| 453 | // | 
| 454 | myquery.str(""); | 
| 455 | myquery << "select "; | 
| 456 | myquery << " ID "; | 
| 457 | myquery << " from GL_RUN_TRASH where BELONGED_TO='GL_RUN' AND RUNHEADER_TIME<=" << mytime << " AND " | 
| 458 | << " RUNTRAILER_TIME>=" << mytime  << " ;"; | 
| 459 | //    printf("myquery is %s \n",myquery.str().c_str()); | 
| 460 | pResult = dbc->Query(myquery.str().c_str()); | 
| 461 | for( r=0; r < 1000; r++){ | 
| 462 | Row = pResult->Next(); | 
| 463 | if( Row == NULL ) break; | 
| 464 | printf("\n DB time %u is contained in run %u in the GL_RUN_TRASH table \n",mytime,(UInt_t)atoll(Row->GetField(0))); | 
| 465 | found = true; | 
| 466 | }; | 
| 467 | // | 
| 468 | if ( !found ){ | 
| 469 | printf("\n No run contains DB time %u \n",mytime); | 
| 470 | }; | 
| 471 | // | 
| 472 | }; | 
| 473 | // | 
| 474 | // To which file the run "run" belongs? | 
| 475 | // | 
| 476 | if ( run != 0 ){ | 
| 477 | Bool_t found = false; | 
| 478 | glrun->Clear(); | 
| 479 | error = glrun->Query_GL_RUN(run,dbc); | 
| 480 | glroot->Clear(); | 
| 481 | error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc); | 
| 482 | if ( glrun->ID_ROOT_L0 ){ | 
| 483 | if ( error ){ | 
| 484 | printf(" Error querying the DB! \n"); | 
| 485 | exit(-4); | 
| 486 | }; | 
| 487 | printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data()); | 
| 488 | //filename = glroot->NAME; | 
| 489 | found = true; | 
| 490 | }; | 
| 491 | // | 
| 492 | myquery.str(""); | 
| 493 | myquery << "select "; | 
| 494 | myquery << " ID,FILENAMEL0,FILENAMEL2 "; | 
| 495 | myquery << " from GL_RUN_TRASH where BELONGED_TO='GL_RUN' AND ID=" << run << "; "; | 
| 496 | pResult = dbc->Query(myquery.str().c_str()); | 
| 497 | for( r=0; r < 1000; r++){ | 
| 498 | Row = pResult->Next(); | 
| 499 | if( Row == NULL ) break; | 
| 500 | printf("\n RUN %u has been deleted and now is contained in the GL_RUN_TRASH table \n",run); | 
| 501 | printf("\n RUN %u belonged to L0 file %s and L2 file %s \n",run,Row->GetField(1),Row->GetField(2)); | 
| 502 | found = true; | 
| 503 | }; | 
| 504 | // | 
| 505 | if ( !found ) printf("\n No run with ID=%u in the DB!\n",run); | 
| 506 | }; | 
| 507 | // | 
| 508 | // Which runs are contained in the file "filename"? | 
| 509 | // | 
| 510 | if ( strcmp(filename.Data(),"") ){ | 
| 511 | // ---------------- | 
| 512 | Bool_t found = false; | 
| 513 | Int_t ID = 0; | 
| 514 | Int_t ID_RAW = 0; | 
| 515 | // | 
| 516 | const char *rawpath = ""; | 
| 517 | const char *rawname = ""; | 
| 518 | // | 
| 519 | myquery.str(""); | 
| 520 | myquery << "select "; | 
| 521 | myquery << " ID"; | 
| 522 | myquery << ",ID_RAW"; | 
| 523 | myquery << ",PATH"; | 
| 524 | myquery << ",NAME"; | 
| 525 | myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";"; | 
| 526 | pResult = dbc->Query(myquery.str().c_str()); | 
| 527 | for( r=0; r < 1000; r++){ | 
| 528 | Row = pResult->Next(); | 
| 529 | if( Row == NULL ) break; | 
| 530 | for( t = 0; t < pResult->GetFieldCount(); t++){ | 
| 531 | if(t==0) ID     = atoi(Row->GetField(t)); | 
| 532 | if(t==1) ID_RAW = atoi(Row->GetField(t)); | 
| 533 | }; | 
| 534 | }; | 
| 535 | delete pResult; | 
| 536 | if ( !ID && !ID_RAW ){ | 
| 537 | if ( !neat ) printf("\n No file with name %s in the DB!\n",filename.Data()); | 
| 538 | } else { | 
| 539 | myquery.str(""); | 
| 540 | myquery << "select "; | 
| 541 | myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME,NEVENTS "; | 
| 542 | myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; | 
| 543 | pResult = dbc->Query(myquery.str().c_str()); | 
| 544 | for( r=0; r < 1000; r++){ | 
| 545 | Row = pResult->Next(); | 
| 546 | if( Row == NULL ) break; | 
| 547 | found = true; | 
| 548 | if ( !r && !neat ) printf("\n File %s contains the following runs: \n\n",filename.Data()); | 
| 549 | TString UTC=tzone.Data(); | 
| 550 | 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; | 
| 554 | myquery.str(""); | 
| 555 | myquery << "select "; | 
| 556 | myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME "; | 
| 557 | myquery << " from GL_RUN_TRASH where BELONGED_TO='GL_RUN' AND FILENAMEL0='" << filename.Data() << "' ;"; | 
| 558 | pResult = dbc->Query(myquery.str().c_str()); | 
| 559 | for( r=0; r < 1000; r++){ | 
| 560 | Row = pResult->Next(); | 
| 561 | if( Row == NULL ) break; | 
| 562 | if ( !r && !neat ) printf("\n File %s contains the following DELETED runs: \n\n",filename.Data()); | 
| 563 | TString UTC=tzone.Data(); | 
| 564 | 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 ){ | 
| 568 | if ( !neat ) printf("\n No run associated to the file %s \n",filename.Data()); | 
| 569 | }; | 
| 570 | myquery.str(""); | 
| 571 | myquery << "select "; | 
| 572 | myquery << " PATH,NAME"; | 
| 573 | myquery << " from GL_RAW where ID=" << ID_RAW << ";"; | 
| 574 | pResult = dbc->Query(myquery.str().c_str()); | 
| 575 | for( r=0; r < 1000; r++){ | 
| 576 | Row = pResult->Next(); | 
| 577 | if( Row == NULL ) break; | 
| 578 | for( t = 0; t < pResult->GetFieldCount(); t++){ | 
| 579 | if(t==0) rawpath = Row->GetField(t); | 
| 580 | if(t==1) rawname = Row->GetField(t); | 
| 581 | }; | 
| 582 | }; | 
| 583 | delete pResult; | 
| 584 | 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 | // | 
| 665 | // Close the DB connection | 
| 666 | // | 
| 667 | if ( dbc ) dbc->Close(); | 
| 668 | // | 
| 669 | if ( !neat ) printf("\n"); | 
| 670 | // | 
| 671 | exit(0); | 
| 672 | } |