--- DarthVader/src/R2-D2.cpp 2006/09/06 11:03:34 1.3 +++ DarthVader/src/R2-D2.cpp 2006/09/07 08:50:39 1.5 @@ -32,14 +32,14 @@ printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n"); printf("\n -idRun ID_RUN: ID number of the run \n"); printf("\n -filename output yoda filename \n"); - printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n"); - printf("\n -user username for the DB [default = anonymous] \n"); - printf("\n -psw password for the DB [default = \"\"]\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 -convert [ -tzone timezone -dbtime dbtime ] \n"); printf("\n convert the dbtime given in seconds (from the DB) to a string for\n"); printf("\n the given time zone (UTC,GMT,MSK,MSD,CET,CEST are accepted) \n"); - printf("\n -runat \"yyyy-mm-dd hh:mm:ss\" \n"); - printf("\n returns run number which contain the given date in MSK (if any)\n"); + printf("\n -runat [ -tzone timezone -time \"yyyy-mm-dd hh:mm:ss\" ] \n"); + printf("\n returns run number which contains the given date in the given time zone \n"); printf("\nExamples: \n"); printf("\n R2-D2 -idRun 1085 \n"); printf("\n R2-D2 -filename DW_050208_00900.root \n"); @@ -63,12 +63,28 @@ TString host = "mysql://localhost/pamelaprod"; TString user = "anonymous"; TString psw = ""; + // + const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); + const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); + const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); + if ( strcmp(pamdbhost,"") ) host = pamdbhost; + if ( strcmp(pamdbuser,"") ) user = pamdbuser; + if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; + // + printf(" host %s user %s psw %s \n",host.Data(),user.Data(),psw.Data()); + // TString tzone = "MSK"; + TString tzone2 = "MSK"; TString runtime = "1970-01-01 00:00:00"; UInt_t dbti = 0; Bool_t convert = false; Bool_t ruti = false; // + TSQLResult *pResult; + TSQLRow *Row; + int t; + int r; + stringstream myquery; // // Checking input parameters // @@ -119,15 +135,6 @@ psw = (TString)inps[i+1]; }; // - if ( !strcmp(inps[i],"-runat") ) { - ruti = true; - if ( numinp-1 < i+1 ){ - r2d2usage(); - exit(-3); - }; - runtime = (TString)inps[i+1]; - }; - // if ( !strcmp(inps[i],"-convert") ) { convert = true; if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){ @@ -160,6 +167,38 @@ }; }; // + if ( !strcmp(inps[i],"-runat") ) { + ruti = true; + if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){ + if ( numinp < i+2 ){ + r2d2usage(); + 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; + }; + }; + }; + }; + // i++; }; // @@ -190,13 +229,36 @@ // At which date correspond the DB time "dbti"? // if ( convert ){ - printf("\n 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.Data(),dbti).Data(),tzone.Data()); }; // // Which run contains the date "runtime"? // if ( ruti ){ - + // + TDatime *time = new TDatime(runtime.Data()); + UInt_t dbti = time->Convert(); + // + TString thetime = dbtime->UnConvertTime(tzone2.Data(),dbti); + // + TDatime *time2 = new TDatime(thetime.Data()); + UInt_t mytime = time2->Convert(); + // + myquery.str(""); + myquery << "select "; + myquery << " ID "; + myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND " + << " RUNTRAILER_TIME>=" << mytime << " ;"; + // printf("myquery is %s \n",myquery.str().c_str()); + pResult = dbc->Query(myquery.str().c_str()); + for( r=0; r < 1000; r++){ + Row = pResult->Next(); + if ( !r && !Row ){ + printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone2.Data(),mytime); + }; + if( Row == NULL ) break; + 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))); + }; }; // // To which file the run "run" belongs? @@ -220,11 +282,6 @@ // Which runs are contained in the file "filename"? // if ( strcmp(filename.Data(),"") ){ - TSQLResult *pResult; - TSQLRow *Row; - int t; - int r; - stringstream myquery; // ---------------- Int_t ID = 0; Int_t ID_RAW = 0; @@ -240,7 +297,6 @@ myquery << ",NAME"; myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";"; pResult = dbc->Query(myquery.str().c_str()); - if(!pResult->GetRowCount()) return (-51); for( r=0; r < 1000; r++){ Row = pResult->Next(); if( Row == NULL ) break; @@ -258,15 +314,14 @@ myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME "; myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; pResult = dbc->Query(myquery.str().c_str()); - if(!pResult->GetRowCount()) return (-51); for( r=0; r < 1000; r++){ Row = pResult->Next(); if ( !r && !Row ){ - printf(" No run associated to the file %s \n",filename.Data()); + printf("\n No run associated to the file %s \n",filename.Data()); }; if( Row == NULL ) break; - if ( !r ) printf("\n File %s contains the following runs: \n",filename.Data()); - printf(" => %i -> Start at %s UTC end at %s UTC \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()); + if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data()); + 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()); }; delete pResult; myquery.str(""); @@ -274,7 +329,6 @@ myquery << " PATH,NAME"; myquery << " from GL_RAW where ID=" << ID_RAW << ";"; pResult = dbc->Query(myquery.str().c_str()); - if(!pResult->GetRowCount()) return (-51); for( r=0; r < 1000; r++){ Row = pResult->Next(); if( Row == NULL ) break; @@ -284,7 +338,7 @@ }; }; delete pResult; - printf(" File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname); + printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname); }; }; //