--- YodaProfiler/src/R2-D2.cpp 2006/11/07 12:17:45 1.2 +++ YodaProfiler/src/R2-D2.cpp 2006/11/28 13:31:59 1.7 @@ -28,29 +28,30 @@ // void r2d2usage(){ printf("\nUsage:\n"); - printf("\n R2-D2 [-h | --help] [--version] [-idRun ID_RUN] [-filename filename]\n"); - printf("\n [-host host] [-user username] [-psw password] \n"); - printf("\n --version print informations about compilation and exit\n"); - printf("\n -h | --help print this help and exit \n"); - printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n"); - printf("\n -idRun run ID_RUN: ID number of the run \n"); - printf("\n -filename file output yoda filename \n"); - printf("\n -host name for the host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); - printf("\n -user username for the DB [default = $PAM_DBUSER or \"anonymous\"] \n"); - printf("\n -psw password for the DB [default = $PAM_DBPSW or \"\"]\n"); - printf("\n -tzone timezone the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n"); - printf("\n -convert dbtime convert the dbtime given in seconds (from the DB) to a string\n"); - printf("\n -runat date returns run number which contains the given date,\n"); - printf("\n for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); - printf("\n -runatDB time returns run number which contains the given DB time\n"); - printf("\n -tsfile file yoda filename for the time sync (to be used with -obt)\n"); - printf("\n -obt OBT OBT in ms returns a date (to be used with -tsfile)\n"); - printf("\n -dumpTLEfor date save into file tle.txt the TLE for the given date,\n"); - printf("\n for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); + printf("\n R2-D2 [ options ]\n"); + printf("\n Options are:\n\n"); + printf(" --version print informations about compilation and exit\n"); + printf(" -h | --help print this help and exit \n"); + printf(" -v | --verbose be verbose [default: print nothing on STDOUT]\n"); + printf(" -idRun run ID_RUN: ID number of the run \n"); + printf(" -filename file output yoda filename \n"); + printf(" -host name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); + printf(" -user username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n"); + printf(" -psw password for the DB connection [default = $PAM_DBPSW or \"\"]\n"); + printf(" -tzone timezone the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n"); + printf(" -convert dbtime convert the dbtime given in seconds (from the DB) to a string\n"); + printf(" -runat date returns run number which contains the given date,\n"); + printf(" for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); + printf(" -runatDB time returns run number which contains the given DB time\n"); + printf(" -tsfile file yoda filename for the time sync (to be used with -obt)\n"); + printf(" -obt OBT OBT in ms returns a date (to be used with -tsfile)\n"); + printf(" -getRTime OBT OBT in ms returns Resurs time (to be used with -tsfile)\n"); + printf(" -dumpTLEfor date save into file tle.txt the TLE for the given date,\n"); + printf(" for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); printf("\nExamples: \n"); - printf("\n R2-D2 -idRun 1085 \n"); - printf("\n R2-D2 -filename DW_050208_00900.root \n"); - printf("\n R2-D2 -idRun 1085 -filename DW_050208_00900.root \n"); + printf(" R2-D2 -idRun 1085 \n"); + printf(" R2-D2 -filename DW_050208_00900.root \n"); + printf(" R2-D2 -idRun 1085 -filename DW_050208_00900.root \n"); }; // // Here the main @@ -88,6 +89,7 @@ TString tletime = "1970-01-01 00:00:00"; UInt_t dbti = 0; Bool_t convert = false; + Bool_t convres = false; Bool_t ruti = false; Bool_t dtle = false; Bool_t ruti2 = false; @@ -96,6 +98,7 @@ // UInt_t runtime2 = 0; UInt_t obt = 0; + UInt_t res = 0; TString tsfile = ""; // TSQLResult *pResult; @@ -171,6 +174,15 @@ obt = (UInt_t)atoll(inps[i+1]); }; // + if ( !strcmp(inps[i],"-getRTime") ) { + convres = true; + if ( numinp-1 < i+1 ){ + r2d2usage(); + exit(-3); + }; + res = (UInt_t)atoll(inps[i+1]); + }; + // // if ( !strcmp(inps[i],"-tzone") ) { if ( numinp-1 < i+1 ){ @@ -254,7 +266,7 @@ printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone,dbti).Data(),tzone.Data()); }; // - // + // convert OBT to date // if ( convobt && convobtts ){ UInt_t id = 0; @@ -270,17 +282,44 @@ delete pResult; GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc); UInt_t abtime = ctime->DBabsTime(obt); - TString UTC="UTC"; TString thetime = dbtime->ConvertTime(tzone,abtime); 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()); delete ctime; }; }; }; - if ( (convobt && !convobtts) || (convobtts && !convobt) ){ + if ( (convobt && !convobtts) ){ printf("\n To convert a OBT to a date you must provide both OBT and file to be used for time sync \n"); }; // + // convert OBT to Resurs seconds + // + if ( convres && convobtts ){ + UInt_t id = 0; + myquery.str(""); + myquery << "select "; + myquery << " ID"; + myquery << " from GL_ROOT where NAME=\"" << tsfile.Data() << "\";"; + pResult = dbc->Query(myquery.str().c_str()); + if ( pResult ){ + Row = pResult->Next(); + if ( Row ){ + id = (UInt_t)atoll(Row->GetField(0)); + delete pResult; + GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc); + UInt_t restime = ctime->ResursTime(res); + //UInt_t abtime = ctime->DBabsTime(obt); + // + // TString thetime = dbtime->ConvertTime(tzone,abtime); + printf("\n OBT %u in the file %s corresponds to Resurs time %u \n",res,tsfile.Data(),restime); + delete ctime; + }; + }; + }; + if ( (convres && !convobtts) ){ + printf("\n To convert a OBT to the Resurs time you must provide both OBT and file to be used for time sync \n"); + }; + // // Which run contains the date "runtime"? // if ( ruti ){ @@ -338,7 +377,7 @@ if ( dtle ){ // // - TDatime ti = TDatime(runtime.Data()); + TDatime ti = TDatime(tletime.Data()); // 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); // @@ -430,6 +469,7 @@ exit(-4); }; printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data()); + filename = glroot->NAME; found = true; }; // @@ -482,7 +522,7 @@ } else { myquery.str(""); myquery << "select "; - myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME "; + myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME,NEVENTS "; myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; pResult = dbc->Query(myquery.str().c_str()); for( r=0; r < 1000; r++){ @@ -490,8 +530,8 @@ if( Row == NULL ) break; found = true; if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data()); - TString UTC="UTC"; - 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=tzone.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))); }; delete pResult; myquery.str(""); @@ -503,8 +543,8 @@ Row = pResult->Next(); if( Row == NULL ) break; if ( !r ) printf("\n File %s contains the following DELETED runs: \n\n",filename.Data()); - TString UTC="UTC"; - 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=tzone.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()); }; // if ( !found ){