/[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.12 by mocchiut, Tue Feb 12 19:35:58 2008 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]\n");
36    printf("\n -idRun run       ID_RUN: ID number of the run \n");    printf(" -n | --neat      used with '-filename' returns only the run ID number\n");
37    printf("\n -filename file   output yoda filename \n");    printf(" -idRun run       ID_RUN: ID number of the run \n");
38    printf("\n -host            name for the host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n");    printf(" -filename file   output yoda filename \n");
39    printf("\n -user            username for the DB [default = $PAM_DBUSER or \"anonymous\"] \n");    printf(" -l2filename file output amidala filename \n");
40    printf("\n -psw             password for the DB [default = $PAM_DBPSW or \"\"]\n");    printf(" -host            name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n");
41    printf("\n -tzone timezone  the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n");    printf(" -user            username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n");
42    printf("\n -convert dbtime  convert the dbtime given in seconds (from the DB) to a string\n");    printf(" -psw             password for the DB connection [default = $PAM_DBPSW or \"\"]\n");
43    printf("\n -runat date      returns run number which contains the given date,\n");    printf(" -tzone timezone  the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n");
44    printf("\n                  for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n");    printf(" -convert dbtime  convert the dbtime given in seconds (from the DB) to a string\n");
45    printf("\n -runatDB time    returns run number which contains the given DB time\n");    printf(" -runat date      returns run number which contains the given date,\n");
46    printf("\n -tsfile file     yoda filename for the time sync (to be used with -obt)\n");    printf("                  for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n");
47    printf("\n -obt OBT         OBT in ms returns a date (to be used with -tsfile)\n");    printf(" -runatDB time    returns run number which contains the given DB time\n");
48    printf("\n -dumpTLEfor date save into file tle.txt the TLE for the given date,\n");    printf(" -tsfile file     yoda filename for the time sync (to be used with -obt)\n");
49    printf("\n                  for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n");    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");    printf("\nExamples: \n");
54    printf("\n R2-D2 -idRun 1085 \n");    printf("      R2-D2 -idRun 1085 \n");
55    printf("\n R2-D2 -filename DW_050208_00900.root \n");    printf("      R2-D2 -filename DW_050208_00900.root \n");
56    printf("\n R2-D2 -idRun 1085 -filename DW_050208_00900.root \n");    printf("      R2-D2 -idRun 1085 -filename DW_050208_00900.root \n\n");
57  };  };
58  //  //
59  // Here the main  // Here the main
# Line 64  int main(int numinp, char *inps[]){ Line 68  int main(int numinp, char *inps[]){
68    UInt_t run = 0ULL;    UInt_t run = 0ULL;
69    //    //
70    TString filename = "";    TString filename = "";
71      TString l2filename = "";
72    //    //
73    TSQLServer *dbc = 0;    TSQLServer *dbc = 0;
74    TString host = "mysql://localhost/pamelaprod";    TString host = "mysql://localhost/pamelaprod";
# Line 87  int main(int numinp, char *inps[]){ Line 92  int main(int numinp, char *inps[]){
92    TString tletime = "1970-01-01 00:00:00";    TString tletime = "1970-01-01 00:00:00";
93    UInt_t dbti = 0;    UInt_t dbti = 0;
94    Bool_t convert = false;    Bool_t convert = false;
95      Bool_t convres = false;
96    Bool_t ruti = false;    Bool_t ruti = false;
97    Bool_t dtle = false;    Bool_t dtle = false;
98    Bool_t ruti2 = false;    Bool_t ruti2 = false;
99    Bool_t convobt = false;    Bool_t convobt = false;
100    Bool_t convobtts = false;    Bool_t convobtts = false;
101      Bool_t neat = false;
102    //    //
103    UInt_t runtime2 = 0;    UInt_t runtime2 = 0;
104    UInt_t obt = 0;    UInt_t obt = 0;
105      UInt_t res = 0;
106    TString tsfile = "";    TString tsfile = "";
107    //    //
108    TSQLResult *pResult;    TSQLResult *pResult;
# Line 116  int main(int numinp, char *inps[]){ Line 124  int main(int numinp, char *inps[]){
124          r2d2usage();          r2d2usage();
125          exit(0);          exit(0);
126        };        };
127          if ( !strcmp(inps[i],"-n") || !strcmp(inps[i],"--neat") ){
128            neat = true;
129          };
130        if ( !strcmp(inps[i],"-idRun") ) {        if ( !strcmp(inps[i],"-idRun") ) {
131          if ( numinp-1 < i+1 ) {          if ( numinp-1 < i+1 ) {
132            r2d2usage();            r2d2usage();
# Line 130  int main(int numinp, char *inps[]){ Line 141  int main(int numinp, char *inps[]){
141          };          };
142          filename = (TString)inps[i+1];            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") ) {        if ( !strcmp(inps[i],"-host") ) {
152          if ( numinp-1 < i+1 ){          if ( numinp-1 < i+1 ){
153            r2d2usage();            r2d2usage();
# Line 170  int main(int numinp, char *inps[]){ Line 188  int main(int numinp, char *inps[]){
188          obt = (UInt_t)atoll(inps[i+1]);          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") ) {        if ( !strcmp(inps[i],"-tzone") ) {
202          if ( numinp-1 < i+1 ){          if ( numinp-1 < i+1 ){
# Line 239  int main(int numinp, char *inps[]){ Line 266  int main(int numinp, char *inps[]){
266      exit(-1);      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();    GL_ROOT *glroot = new GL_ROOT();
274    GL_RUN *glrun = new GL_RUN();    GL_RUN *glrun = new GL_RUN();
275    GL_TIMESYNC *dbtime = new GL_TIMESYNC();    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"?    // At which date correspond the DB time "dbti"?
280    //    //
# Line 249  int main(int numinp, char *inps[]){ Line 282  int main(int numinp, char *inps[]){
282      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());
283    };    };
284    //    //
285    //    // convert OBT to date
286    //    //
287    if ( convobt && convobtts ){    if ( convobt && convobtts ){
288      UInt_t id = 0;      UInt_t id = 0;
# Line 265  int main(int numinp, char *inps[]){ Line 298  int main(int numinp, char *inps[]){
298          delete pResult;                delete pResult;      
299          GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc);          GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc);
300          UInt_t abtime = ctime->DBabsTime(obt);          UInt_t abtime = ctime->DBabsTime(obt);
         TString UTC="UTC";  
301          TString thetime = dbtime->ConvertTime(tzone,abtime);          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());          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;          delete ctime;
304        };        };
305      };      };
306    };    };
307    if ( (convobt && !convobtts) || (convobtts && !convobt) ){    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");      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"?    // Which run contains the date "runtime"?
340    //    //
341    if ( ruti ){    if ( ruti ){
342      //      //
343      TDatime *time = new TDatime(runtime.Data());      TDatime ti = TDatime(runtime.Data());
344      UInt_t dbti = time->Convert();      //
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);      TString thetime = dbtime->UnConvertTime(tzone,dbti);
350      //      //
351      TDatime *time2 = new TDatime(thetime.Data());      ti = TDatime(thetime.Data());
352      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);
353        //
354        UInt_t mytime = time2->GetSec();
355        //
356      Bool_t found = false;      Bool_t found = false;
357      //      //
358      myquery.str("");      myquery.str("");
# Line 326  int main(int numinp, char *inps[]){ Line 392  int main(int numinp, char *inps[]){
392    //    //
393    if ( dtle ){    if ( dtle ){
394      //      //
395      TDatime *time = new TDatime(tletime.Data());      //
396      UInt_t dbti = time->Convert();      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);      TString thetime = dbtime->UnConvertTime(tzone,dbti);
403      //      //
404      TDatime *time2 = new TDatime(thetime.Data());      ti = TDatime(thetime.Data());
405      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);
406        //
407        UInt_t mytime = time2->GetSec();
408      //      //
409      myquery.str("");      myquery.str("");
410      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;";
411      //    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;";
412      //    printf("myquery is %s \n",myquery.str().c_str());      //    printf("myquery is %s \n",myquery.str().c_str());
413      pResult = dbc->Query(myquery.str().c_str());      pResult = dbc->Query(myquery.str().c_str());
# Line 413  int main(int numinp, char *inps[]){ Line 485  int main(int numinp, char *inps[]){
485          exit(-4);          exit(-4);
486        };        };
487        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());
488          //filename = glroot->NAME;
489        found = true;        found = true;
490      };      };
491      //      //
# Line 461  int main(int numinp, char *inps[]){ Line 534  int main(int numinp, char *inps[]){
534      };      };
535      delete pResult;        delete pResult;  
536      if ( !ID && !ID_RAW ){      if ( !ID && !ID_RAW ){
537        printf("\n No file with name %s in the DB!\n",filename.Data());        if ( !neat ) printf("\n No file with name %s in the DB!\n",filename.Data());
538      } else {      } else {
539        myquery.str("");        myquery.str("");
540        myquery << "select ";        myquery << "select ";
541        myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME ";        myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME,NEVENTS ";
542        myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";";            myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";";    
543        pResult = dbc->Query(myquery.str().c_str());        pResult = dbc->Query(myquery.str().c_str());
544        for( r=0; r < 1000; r++){        for( r=0; r < 1000; r++){
545          Row = pResult->Next();                Row = pResult->Next();      
546          if( Row == NULL ) break;          if( Row == NULL ) break;
547          found = true;          found = true;
548          if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data());          if ( !r && !neat ) printf("\n File %s contains the following runs: \n\n",filename.Data());
549          TString UTC="UTC";          TString UTC=tzone.Data();
550          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());          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;          delete pResult;  
554        myquery.str("");        myquery.str("");
# Line 485  int main(int numinp, char *inps[]){ Line 559  int main(int numinp, char *inps[]){
559        for( r=0; r < 1000; r++){        for( r=0; r < 1000; r++){
560          Row = pResult->Next();                Row = pResult->Next();      
561          if( Row == NULL ) break;          if( Row == NULL ) break;
562          if ( !r ) printf("\n File %s contains the following DELETED runs: \n\n",filename.Data());          if ( !r && !neat ) printf("\n File %s contains the following DELETED runs: \n\n",filename.Data());
563          TString UTC="UTC";          TString UTC=tzone.Data();
564          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());          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 ){        if ( !found ){
568          printf("\n No run associated to the file %s \n",filename.Data());          if ( !neat ) printf("\n No run associated to the file %s \n",filename.Data());
569        };        };
570        myquery.str("");        myquery.str("");
571        myquery << "select ";        myquery << "select ";
# Line 507  int main(int numinp, char *inps[]){ Line 581  int main(int numinp, char *inps[]){
581          };          };
582        };        };
583        delete pResult;          delete pResult;  
584        printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname);        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    //    //
# Line 515  int main(int numinp, char *inps[]){ Line 666  int main(int numinp, char *inps[]){
666    //    //
667    if ( dbc ) dbc->Close();    if ( dbc ) dbc->Close();
668    //    //
669    printf("\n");    if ( !neat ) printf("\n");
670    //    //
671    exit(0);    exit(0);
672  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23