/[PAMELA software]/YodaProfiler/src/R2-D2.cpp
ViewVC logotype

Diff of /YodaProfiler/src/R2-D2.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by mocchiut, Tue Oct 31 15:36:05 2006 UTC revision 1.8 by mocchiut, Tue Nov 28 13:52:47 2006 UTC
# Line 9  Line 9 
9  // ROOT headers  // ROOT headers
10  //  //
11  #include <TString.h>  #include <TString.h>
12    #include <TTimeStamp.h>
13  #include <TSQLServer.h>  #include <TSQLServer.h>
14  #include <TFile.h>  #include <TFile.h>
15  #include <TSystem.h>  #include <TSystem.h>
# Line 27  using namespace std; Line 28  using namespace std;
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: print nothing on STDOUT]\n");
36    printf("\n -idRun run       ID_RUN: ID number of the run \n");    printf(" -idRun run       ID_RUN: ID number of the run \n");
37    printf("\n -filename file   output yoda filename \n");    printf(" -filename file   output yoda filename \n");
38    printf("\n -host            name for the host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n");    printf(" -host            name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n");
39    printf("\n -user            username for the DB [default = $PAM_DBUSER or \"anonymous\"] \n");    printf(" -user            username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n");
40    printf("\n -psw             password for the DB [default = $PAM_DBPSW or \"\"]\n");    printf(" -psw             password for the DB connection [default = $PAM_DBPSW or \"\"]\n");
41    printf("\n -tzone timezone  the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n");    printf(" -tzone timezone  the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n");
42    printf("\n -convert dbtime  convert the dbtime given in seconds (from the DB) to a string\n");    printf(" -convert dbtime  convert the dbtime given in seconds (from the DB) to a string\n");
43    printf("\n -runat date      returns run number which contains the given date,\n");    printf(" -runat date      returns run number which contains the given date,\n");
44    printf("\n                  for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n");    printf("                  for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n");
45    printf("\n -runatDB time    returns run number which contains the given DB time\n");    printf(" -runatDB time    returns run number which contains the given DB time\n");
46    printf("\n -tsfile file     yoda filename for the time sync (to be used with -obt)\n");    printf(" -tsfile file     yoda filename for the time sync (to be used with -obt)\n");
47    printf("\n -obt OBT         OBT in ms returns a date (to be used with -tsfile)\n");    printf(" -obt OBT         OBT in ms returns a date (to be used with -tsfile)\n");
48    printf("\n -dumpTLEfor date save into file tle.txt the TLE for the given date,\n");    printf(" -getRTime OBT    OBT in ms returns Resurs time (to be used with -tsfile)\n");
49    printf("\n                  for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n");    printf(" -dumpTLEfor date save into file tle.txt the TLE for the given date,\n");
50      printf("                  for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n");
51    printf("\nExamples: \n");    printf("\nExamples: \n");
52    printf("\n R2-D2 -idRun 1085 \n");    printf("      R2-D2 -idRun 1085 \n");
53    printf("\n R2-D2 -filename DW_050208_00900.root \n");    printf("      R2-D2 -filename DW_050208_00900.root \n");
54    printf("\n R2-D2 -idRun 1085 -filename DW_050208_00900.root \n");    printf("      R2-D2 -idRun 1085 -filename DW_050208_00900.root \n\n");
55  };  };
56  //  //
57  // Here the main  // Here the main
# Line 87  int main(int numinp, char *inps[]){ Line 89  int main(int numinp, char *inps[]){
89    TString tletime = "1970-01-01 00:00:00";    TString tletime = "1970-01-01 00:00:00";
90    UInt_t dbti = 0;    UInt_t dbti = 0;
91    Bool_t convert = false;    Bool_t convert = false;
92      Bool_t convres = false;
93    Bool_t ruti = false;    Bool_t ruti = false;
94    Bool_t dtle = false;    Bool_t dtle = false;
95    Bool_t ruti2 = false;    Bool_t ruti2 = false;
# Line 95  int main(int numinp, char *inps[]){ Line 98  int main(int numinp, char *inps[]){
98    //    //
99    UInt_t runtime2 = 0;    UInt_t runtime2 = 0;
100    UInt_t obt = 0;    UInt_t obt = 0;
101      UInt_t res = 0;
102    TString tsfile = "";    TString tsfile = "";
103    //    //
104    TSQLResult *pResult;    TSQLResult *pResult;
# Line 170  int main(int numinp, char *inps[]){ Line 174  int main(int numinp, char *inps[]){
174          obt = (UInt_t)atoll(inps[i+1]);          obt = (UInt_t)atoll(inps[i+1]);
175        };        };
176        //        //
177         if ( !strcmp(inps[i],"-getRTime") ) {
178            convres = true;
179            if ( numinp-1 < i+1 ){
180              r2d2usage();
181              exit(-3);
182            };
183            res = (UInt_t)atoll(inps[i+1]);
184          };
185          //
186        //        //
187        if ( !strcmp(inps[i],"-tzone") ) {        if ( !strcmp(inps[i],"-tzone") ) {
188          if ( numinp-1 < i+1 ){          if ( numinp-1 < i+1 ){
# Line 239  int main(int numinp, char *inps[]){ Line 252  int main(int numinp, char *inps[]){
252      exit(-1);      exit(-1);
253    };        };    
254    //    //
255      myquery.str("");
256      myquery << "SET time_zone='+0:00'";
257      dbc->Query(myquery.str().c_str());
258      //
259    GL_ROOT *glroot = new GL_ROOT();    GL_ROOT *glroot = new GL_ROOT();
260    GL_RUN *glrun = new GL_RUN();    GL_RUN *glrun = new GL_RUN();
261    GL_TIMESYNC *dbtime = new GL_TIMESYNC();    GL_TIMESYNC *dbtime = new GL_TIMESYNC();
# Line 249  int main(int numinp, char *inps[]){ Line 266  int main(int numinp, char *inps[]){
266      printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone,dbti).Data(),tzone.Data());      printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone,dbti).Data(),tzone.Data());
267    };    };
268    //    //
269    //    // convert OBT to date
270    //    //
271    if ( convobt && convobtts ){    if ( convobt && convobtts ){
272      UInt_t id = 0;      UInt_t id = 0;
# Line 265  int main(int numinp, char *inps[]){ Line 282  int main(int numinp, char *inps[]){
282          delete pResult;                delete pResult;      
283          GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc);          GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc);
284          UInt_t abtime = ctime->DBabsTime(obt);          UInt_t abtime = ctime->DBabsTime(obt);
         TString UTC="UTC";  
285          TString thetime = dbtime->ConvertTime(tzone,abtime);          TString thetime = dbtime->ConvertTime(tzone,abtime);
286          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());          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());
287          delete ctime;          delete ctime;
288        };        };
289      };      };
290    };    };
291    if ( (convobt && !convobtts) || (convobtts && !convobt) ){    if ( (convobt && !convobtts) ){
292      printf("\n To convert a OBT to a date you must provide both OBT and file to be used for time sync \n");      printf("\n To convert a OBT to a date you must provide both OBT and file to be used for time sync \n");
293    };    };
294    //    //
295      // convert OBT to Resurs seconds
296      //
297      if ( convres && convobtts ){
298        UInt_t id = 0;
299        myquery.str("");
300        myquery << "select ";
301        myquery << " ID";
302        myquery << " from GL_ROOT where NAME=\"" << tsfile.Data() << "\";";    
303        pResult = dbc->Query(myquery.str().c_str());
304        if ( pResult ){
305          Row = pResult->Next();      
306          if ( Row ){
307            id = (UInt_t)atoll(Row->GetField(0));
308            delete pResult;      
309            GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc);
310            UInt_t restime = ctime->ResursTime(res);
311            //UInt_t abtime = ctime->DBabsTime(obt);
312            //
313            //      TString thetime = dbtime->ConvertTime(tzone,abtime);
314            printf("\n OBT %u in the file %s corresponds to Resurs time %u  \n",res,tsfile.Data(),restime);
315            delete ctime;
316          };
317        };
318      };
319      if ( (convres && !convobtts) ){
320        printf("\n To convert a OBT to the Resurs time you must provide both OBT and file to be used for time sync \n");
321      };
322      //
323    // Which run contains the date "runtime"?    // Which run contains the date "runtime"?
324    //    //
325    if ( ruti ){    if ( ruti ){
326      //      //
327      TDatime *time = new TDatime(runtime.Data());      TDatime ti = TDatime(runtime.Data());
328      UInt_t dbti = time->Convert();      //
329        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);
330        //
331        UInt_t dbti = time->GetSec();
332      //      //
333      TString thetime = dbtime->UnConvertTime(tzone,dbti);      TString thetime = dbtime->UnConvertTime(tzone,dbti);
334      //      //
335      TDatime *time2 = new TDatime(thetime.Data());      ti = TDatime(thetime.Data());
336      UInt_t mytime = time2->Convert();      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);
337        //
338        UInt_t mytime = time2->GetSec();
339        //
340      Bool_t found = false;      Bool_t found = false;
341      //      //
342      myquery.str("");      myquery.str("");
# Line 326  int main(int numinp, char *inps[]){ Line 376  int main(int numinp, char *inps[]){
376    //    //
377    if ( dtle ){    if ( dtle ){
378      //      //
379      TDatime *time = new TDatime(tletime.Data());      //
380      UInt_t dbti = time->Convert();      TDatime ti = TDatime(tletime.Data());
381        //
382        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);
383        //
384        UInt_t dbti = time->GetSec();
385      //      //
386      TString thetime = dbtime->UnConvertTime(tzone,dbti);      TString thetime = dbtime->UnConvertTime(tzone,dbti);
387      //      //
388      TDatime *time2 = new TDatime(thetime.Data());      ti = TDatime(thetime.Data());
389      UInt_t mytime = time2->Convert();      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);
390        //
391        UInt_t mytime = time2->GetSec();
392      //      //
393      myquery.str("");      myquery.str("");
394      myquery << " select ID,TLE1,TLE2,TLE3 from GL_TLE where FROM_TIME<='" << time2->AsSQLString() << "' ORDER BY FROM_TIME DESC LIMIT 1;";      myquery << " select ID,TLE1,TLE2,TLE3 from GL_TLE where FROM_TIME<='" << time2->AsString("s") << "' ORDER BY FROM_TIME DESC LIMIT 1;";
395      //    myquery << " from GL_TLE where FROM_TIME>=" << mytime << " ORDER BY FROM_TIME ASC LIMIT 1;";      //    myquery << " from GL_TLE where FROM_TIME>=" << mytime << " ORDER BY FROM_TIME ASC LIMIT 1;";
396      //    printf("myquery is %s \n",myquery.str().c_str());      //    printf("myquery is %s \n",myquery.str().c_str());
397      pResult = dbc->Query(myquery.str().c_str());      pResult = dbc->Query(myquery.str().c_str());
# Line 413  int main(int numinp, char *inps[]){ Line 469  int main(int numinp, char *inps[]){
469          exit(-4);          exit(-4);
470        };        };
471        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());
472          filename = glroot->NAME;
473        found = true;        found = true;
474      };      };
475      //      //
# Line 465  int main(int numinp, char *inps[]){ Line 522  int main(int numinp, char *inps[]){
522      } else {      } else {
523        myquery.str("");        myquery.str("");
524        myquery << "select ";        myquery << "select ";
525        myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME ";        myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME,NEVENTS ";
526        myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";";            myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";";    
527        pResult = dbc->Query(myquery.str().c_str());        pResult = dbc->Query(myquery.str().c_str());
528        for( r=0; r < 1000; r++){        for( r=0; r < 1000; r++){
# Line 473  int main(int numinp, char *inps[]){ Line 530  int main(int numinp, char *inps[]){
530          if( Row == NULL ) break;          if( Row == NULL ) break;
531          found = true;          found = true;
532          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());
533          TString UTC="UTC";          TString UTC=tzone.Data();
534          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());          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)));
535        };        };
536        delete pResult;          delete pResult;  
537        myquery.str("");        myquery.str("");
# Line 486  int main(int numinp, char *inps[]){ Line 543  int main(int numinp, char *inps[]){
543          Row = pResult->Next();                Row = pResult->Next();      
544          if( Row == NULL ) break;          if( Row == NULL ) break;
545          if ( !r ) printf("\n File %s contains the following DELETED runs: \n\n",filename.Data());          if ( !r ) printf("\n File %s contains the following DELETED runs: \n\n",filename.Data());
546          TString UTC="UTC";          TString UTC=tzone.Data();
547          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());          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());
548        };        };
549        //        //
550        if ( !found ){        if ( !found ){

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.23