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

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

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

revision 1.3 by mocchiut, Wed Sep 6 11:03:34 2006 UTC revision 1.5 by mocchiut, Thu Sep 7 08:50:39 2006 UTC
# Line 32  void r2d2usage(){ Line 32  void r2d2usage(){
32    printf("\n -v | --verbose  be verbose [default: print nothing on STDOUT]\n");    printf("\n -v | --verbose  be verbose [default: print nothing on STDOUT]\n");
33    printf("\n -idRun          ID_RUN: ID number of the run \n");    printf("\n -idRun          ID_RUN: ID number of the run \n");
34    printf("\n -filename       output yoda filename \n");    printf("\n -filename       output yoda filename \n");
35    printf("\n -host           name for the host [default = mysql://localhost/pamelaprod]\n");    printf("\n -host           name for the host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n");
36    printf("\n -user           username for the DB [default = anonymous] \n");    printf("\n -user           username for the DB [default = $PAM_DBUSER or \"anonymous\"] \n");
37    printf("\n -psw            password for the DB [default = \"\"]\n");    printf("\n -psw            password for the DB [default = $PAM_DBPSW or \"\"]\n");
38    printf("\n -convert [ -tzone timezone -dbtime dbtime ] \n");    printf("\n -convert [ -tzone timezone -dbtime dbtime ] \n");
39    printf("\n                 convert the dbtime given in seconds (from the DB) to a string for\n");    printf("\n                 convert the dbtime given in seconds (from the DB) to a string for\n");
40    printf("\n                 the given time zone (UTC,GMT,MSK,MSD,CET,CEST are accepted) \n");    printf("\n                 the given time zone (UTC,GMT,MSK,MSD,CET,CEST are accepted) \n");
41    printf("\n -runat \"yyyy-mm-dd hh:mm:ss\" \n");    printf("\n -runat [ -tzone timezone -time \"yyyy-mm-dd hh:mm:ss\" ] \n");
42    printf("\n                 returns run number which contain the given date in MSK (if any)\n");    printf("\n                 returns run number which contains the given date in the given time zone \n");
43    printf("\nExamples: \n");    printf("\nExamples: \n");
44    printf("\n R2-D2 -idRun 1085 \n");    printf("\n R2-D2 -idRun 1085 \n");
45    printf("\n R2-D2 -filename DW_050208_00900.root \n");    printf("\n R2-D2 -filename DW_050208_00900.root \n");
# Line 63  int main(int numinp, char *inps[]){ Line 63  int main(int numinp, char *inps[]){
63    TString host = "mysql://localhost/pamelaprod";    TString host = "mysql://localhost/pamelaprod";
64    TString user = "anonymous";    TString user = "anonymous";
65    TString psw = "";    TString psw = "";
66      //
67      const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
68      const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
69      const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
70      if ( strcmp(pamdbhost,"") ) host = pamdbhost;
71      if ( strcmp(pamdbuser,"") ) user = pamdbuser;
72      if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
73      //
74      printf(" host %s user %s psw %s \n",host.Data(),user.Data(),psw.Data());
75      //
76    TString tzone = "MSK";    TString tzone = "MSK";
77      TString tzone2 = "MSK";
78    TString runtime = "1970-01-01 00:00:00";    TString runtime = "1970-01-01 00:00:00";
79    UInt_t dbti = 0;    UInt_t dbti = 0;
80    Bool_t convert = false;    Bool_t convert = false;
81    Bool_t ruti = false;    Bool_t ruti = false;
82    //    //
83      TSQLResult *pResult;
84      TSQLRow *Row;
85      int t;
86      int r;
87      stringstream myquery;
88    //    //
89    // Checking input parameters    // Checking input parameters
90    //    //
# Line 119  int main(int numinp, char *inps[]){ Line 135  int main(int numinp, char *inps[]){
135          psw = (TString)inps[i+1];                psw = (TString)inps[i+1];      
136        };        };
137        //        //
       if ( !strcmp(inps[i],"-runat") ) {  
         ruti = true;  
         if ( numinp-1 < i+1 ){  
           r2d2usage();  
           exit(-3);  
         };  
         runtime = (TString)inps[i+1];    
       };  
       //  
138        if ( !strcmp(inps[i],"-convert") ) {        if ( !strcmp(inps[i],"-convert") ) {
139          convert = true;          convert = true;
140          if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){          if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
# Line 160  int main(int numinp, char *inps[]){ Line 167  int main(int numinp, char *inps[]){
167          };          };
168        };        };
169        //        //
170          if ( !strcmp(inps[i],"-runat") ) {
171            ruti = true;
172            if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
173              if ( numinp < i+2 ){
174                r2d2usage();
175                throw -3;
176              };
177              i += 2;        
178              while ( strcmp(inps[i],"]") ){
179                if ( !strcmp(inps[i],"-tzone") ) {
180                  if ( numinp-1 < i+1 ){
181                    r2d2usage();
182                    exit(-3);
183                  };
184                  tzone2 = (TString)inps[i+1];      
185                };
186                if ( !strcmp(inps[i],"-time") ) {
187                  if ( numinp-1 < i+1 ){
188                    r2d2usage();
189                    exit(-3);
190                  };
191                  runtime = (TString)inps[i+1];    
192                };
193                i++;
194                if ( i > numinp-1 ){
195                  r2d2usage();
196                  throw -3;
197                };
198              };
199            };
200          };
201          //
202        i++;        i++;
203      };      };
204      //      //
# Line 190  int main(int numinp, char *inps[]){ Line 229  int main(int numinp, char *inps[]){
229    // At which date correspond the DB time "dbti"?    // At which date correspond the DB time "dbti"?
230    //    //
231    if ( convert ){    if ( convert ){
232      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());
233    };    };
234    //    //
235    // Which run contains the date "runtime"?    // Which run contains the date "runtime"?
236    //    //
237    if ( ruti ){    if ( ruti ){
238            //
239        TDatime *time = new TDatime(runtime.Data());
240        UInt_t dbti = time->Convert();
241        //
242        TString thetime = dbtime->UnConvertTime(tzone2.Data(),dbti);
243        //
244        TDatime *time2 = new TDatime(thetime.Data());
245        UInt_t mytime = time2->Convert();
246        //
247        myquery.str("");
248        myquery << "select ";
249        myquery << " ID ";
250        myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND "
251                << " RUNTRAILER_TIME>=" << mytime  << " ;";
252        //    printf("myquery is %s \n",myquery.str().c_str());
253        pResult = dbc->Query(myquery.str().c_str());
254        for( r=0; r < 1000; r++){
255          Row = pResult->Next();      
256          if ( !r && !Row ){
257            printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone2.Data(),mytime);
258          };
259          if( Row == NULL ) break;
260          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)));
261        };    
262    };    };
263    //    //
264    // To which file the run "run" belongs?    // To which file the run "run" belongs?
# Line 220  int main(int numinp, char *inps[]){ Line 282  int main(int numinp, char *inps[]){
282    // Which runs are contained in the file "filename"?    // Which runs are contained in the file "filename"?
283    //    //
284    if ( strcmp(filename.Data(),"") ){    if ( strcmp(filename.Data(),"") ){
     TSQLResult *pResult;  
     TSQLRow *Row;  
     int t;  
     int r;  
     stringstream myquery;  
285      // ----------------      // ----------------
286      Int_t ID = 0;      Int_t ID = 0;
287      Int_t ID_RAW = 0;      Int_t ID_RAW = 0;
# Line 240  int main(int numinp, char *inps[]){ Line 297  int main(int numinp, char *inps[]){
297      myquery << ",NAME";      myquery << ",NAME";
298      myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";";          myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";";    
299      pResult = dbc->Query(myquery.str().c_str());      pResult = dbc->Query(myquery.str().c_str());
     if(!pResult->GetRowCount()) return (-51);  
300      for( r=0; r < 1000; r++){      for( r=0; r < 1000; r++){
301        Row = pResult->Next();              Row = pResult->Next();      
302        if( Row == NULL ) break;        if( Row == NULL ) break;
# Line 258  int main(int numinp, char *inps[]){ Line 314  int main(int numinp, char *inps[]){
314        myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME ";        myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME ";
315        myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";";            myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";";    
316        pResult = dbc->Query(myquery.str().c_str());        pResult = dbc->Query(myquery.str().c_str());
       if(!pResult->GetRowCount()) return (-51);  
317        for( r=0; r < 1000; r++){        for( r=0; r < 1000; r++){
318          Row = pResult->Next();                Row = pResult->Next();      
319          if ( !r && !Row ){          if ( !r && !Row ){
320            printf(" No run associated to the file %s \n",filename.Data());            printf("\n No run associated to the file %s \n",filename.Data());
321          };          };
322          if( Row == NULL ) break;          if( Row == NULL ) break;
323          if ( !r ) printf("\n File %s contains the following runs: \n",filename.Data());          if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data());
324          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());          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());
325        };        };
326        delete pResult;          delete pResult;  
327        myquery.str("");        myquery.str("");
# Line 274  int main(int numinp, char *inps[]){ Line 329  int main(int numinp, char *inps[]){
329        myquery << " PATH,NAME";        myquery << " PATH,NAME";
330        myquery << " from GL_RAW where ID=" << ID_RAW << ";";            myquery << " from GL_RAW where ID=" << ID_RAW << ";";    
331        pResult = dbc->Query(myquery.str().c_str());        pResult = dbc->Query(myquery.str().c_str());
       if(!pResult->GetRowCount()) return (-51);  
332        for( r=0; r < 1000; r++){        for( r=0; r < 1000; r++){
333          Row = pResult->Next();                Row = pResult->Next();      
334          if( Row == NULL ) break;          if( Row == NULL ) break;
# Line 284  int main(int numinp, char *inps[]){ Line 338  int main(int numinp, char *inps[]){
338          };          };
339        };        };
340        delete pResult;          delete pResult;  
341        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);
342      };      };
343    };      };  
344    //    //

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.23