/[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.2 by mocchiut, Wed Jun 14 09:53:26 2006 UTC revision 1.8 by mocchiut, Tue Sep 19 09:17:50 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 -tzone timezone the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n");
39      printf("\n -convert dbtime convert the dbtime given in seconds (from the DB) to a string\n");
40      printf("\n -runat time     returns run number which contains the given date,\n");
41      printf("\n                 for time use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n");
42    printf("\nExamples: \n");    printf("\nExamples: \n");
43    printf("\n R2-D2 -idRun 1085 \n");    printf("\n R2-D2 -idRun 1085 \n");
44    printf("\n R2-D2 -filename DW_050208_00900.root \n");    printf("\n R2-D2 -filename DW_050208_00900.root \n");
# Line 50  int main(int numinp, char *inps[]){ Line 54  int main(int numinp, char *inps[]){
54    TString message;    TString message;
55    Int_t error = 0;    Int_t error = 0;
56    //    //
57    ULong64_t run = 0ULL;    UInt_t run = 0ULL;
58    //    //
59    TString filename = "";    TString filename = "";
60    //    //
# Line 59  int main(int numinp, char *inps[]){ Line 63  int main(int numinp, char *inps[]){
63    TString user = "anonymous";    TString user = "anonymous";
64    TString psw = "";    TString psw = "";
65    //    //
66      const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
67      const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
68      const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
69      if ( !pamdbhost ) pamdbhost = "";
70      if ( !pamdbuser ) pamdbuser = "";
71      if ( !pamdbpsw ) pamdbpsw = "";
72      if ( strcmp(pamdbhost,"") ) host = pamdbhost;
73      if ( strcmp(pamdbuser,"") ) user = pamdbuser;
74      if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
75      //
76      //  printf(" host %s user %s psw %s \n",host.Data(),user.Data(),psw.Data());
77      //
78      TString tzone = "MSK";
79      TString runtime = "1970-01-01 00:00:00";
80      UInt_t dbti = 0;
81      Bool_t convert = false;
82      Bool_t ruti = false;
83      //
84      TSQLResult *pResult;
85      TSQLRow *Row;
86      int t;
87      int r;
88      stringstream myquery;
89    //    //
90    // Checking input parameters    // Checking input parameters
91    //    //
# Line 78  int main(int numinp, char *inps[]){ Line 105  int main(int numinp, char *inps[]){
105            r2d2usage();            r2d2usage();
106            exit(-3);            exit(-3);
107          };          };
108          char *pEnd;              run = (UInt_t)atoll(inps[i+1]);
         run = strtoull(inps[i+1],&pEnd,0);        
109        };        };
110        if ( !strcmp(inps[i],"-filename") ) {        if ( !strcmp(inps[i],"-filename") ) {
111          if ( numinp-1 < i+1 ){          if ( numinp-1 < i+1 ){
# Line 109  int main(int numinp, char *inps[]){ Line 135  int main(int numinp, char *inps[]){
135          };          };
136          psw = (TString)inps[i+1];                psw = (TString)inps[i+1];      
137        };        };
138          //
139          if ( !strcmp(inps[i],"-tzone") ) {
140            if ( numinp-1 < i+1 ){
141              r2d2usage();
142              exit(-3);
143            };
144            tzone = (TString)inps[i+1];    
145          };
146          //
147          if ( !strcmp(inps[i],"-convert") ) {
148            convert = true;
149            if ( numinp-1 < i+1 ){
150              r2d2usage();
151              exit(-3);
152            };
153            dbti = (UInt_t)atoll(inps[i+1]);        
154          };
155          //
156          if ( !strcmp(inps[i],"-runat") ) {
157            ruti = true;
158            if ( numinp-1 < i+1 ){
159              r2d2usage();
160              exit(-3);
161            };
162            runtime = (TString)inps[i+1];  
163          };
164          //
165        i++;        i++;
166      };      };
167      //      //
# Line 134  int main(int numinp, char *inps[]){ Line 187  int main(int numinp, char *inps[]){
187    //    //
188    GL_ROOT *glroot = new GL_ROOT();    GL_ROOT *glroot = new GL_ROOT();
189    GL_RUN *glrun = new GL_RUN();    GL_RUN *glrun = new GL_RUN();
190      GL_TIMESYNC *dbtime = new GL_TIMESYNC();
191      //
192      // At which date correspond the DB time "dbti"?
193      //
194      if ( convert ){
195        printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone,dbti).Data(),tzone.Data());
196      };
197      //
198      // Which run contains the date "runtime"?
199      //
200      if ( ruti ){
201        //
202        TDatime *time = new TDatime(runtime.Data());
203        UInt_t dbti = time->Convert();
204        //
205        TString thetime = dbtime->UnConvertTime(tzone,dbti);
206        //
207        TDatime *time2 = new TDatime(thetime.Data());
208        UInt_t mytime = time2->Convert();
209        //
210        myquery.str("");
211        myquery << "select ";
212        myquery << " ID ";
213        myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND "
214                << " RUNTRAILER_TIME>=" << mytime  << " ;";
215        //    printf("myquery is %s \n",myquery.str().c_str());
216        pResult = dbc->Query(myquery.str().c_str());
217        for( r=0; r < 1000; r++){
218          Row = pResult->Next();      
219          if ( !r && !Row ){
220            printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone.Data(),mytime);
221          };
222          if( Row == NULL ) break;
223          printf("\n Date %s %s (DB time %u ) is contained in run %u \n",runtime.Data(),tzone.Data(),mytime,(UInt_t)atoll(Row->GetField(0)));
224        };    
225      };
226    //    //
227    if ( run != 0ULL ){    // To which file the run "run" belongs?
228      //
229      if ( run != 0 ){
230        glrun->Clear();
231      error = glrun->Query_GL_RUN(run,dbc);      error = glrun->Query_GL_RUN(run,dbc);
232      error = glroot->Query_GL_ROOT(glrun->ID_REG_RUN,dbc);      glroot->Clear();
233      if ( error ){      error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc);
234        printf(" Error querying the DB! \n");      if ( !glrun->ID_ROOT_L0 ){
235        exit(-4);        printf("\n No run with ID=%u in the DB!\n",run);
236        } else {
237          if ( error ){
238            printf(" Error querying the DB! \n");
239            exit(-4);
240          };
241          printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data());
242      };      };
     printf("\n Run %llu belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data());  
243    };    };
244      //
245      // Which runs are contained in the file "filename"?
246      //
247    if ( strcmp(filename.Data(),"") ){    if ( strcmp(filename.Data(),"") ){
     TSQLResult *pResult;  
     TSQLRow *Row;  
     int t;  
     int r;  
     stringstream myquery;  
248      // ----------------      // ----------------
249      Int_t ID = 0;      Int_t ID = 0;
250      Int_t ID_RAW = 0;      Int_t ID_RAW = 0;
# Line 165  int main(int numinp, char *inps[]){ Line 260  int main(int numinp, char *inps[]){
260      myquery << ",NAME";      myquery << ",NAME";
261      myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";";          myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";";    
262      pResult = dbc->Query(myquery.str().c_str());      pResult = dbc->Query(myquery.str().c_str());
     if(!pResult->GetRowCount()) return (-51);  
263      for( r=0; r < 1000; r++){      for( r=0; r < 1000; r++){
264        Row = pResult->Next();              Row = pResult->Next();      
265        if( Row == NULL ) break;        if( Row == NULL ) break;
# Line 175  int main(int numinp, char *inps[]){ Line 269  int main(int numinp, char *inps[]){
269        };        };
270      };      };
271      delete pResult;        delete pResult;  
272      printf("\n File %s contains the following runs: \n",filename.Data());      if ( !ID && !ID_RAW ){
273      myquery.str("");        printf("\n No file with name %s in the DB!\n",filename.Data());
274      myquery << "select ";      } else {
275      myquery << " ID";        myquery.str("");
276      myquery << " from GL_RUN where ID_REG_RUN=" << ID << ";";            myquery << "select ";
277      pResult = dbc->Query(myquery.str().c_str());        myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME ";
278      if(!pResult->GetRowCount()) return (-51);        myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";";    
279      for( r=0; r < 1000; r++){        pResult = dbc->Query(myquery.str().c_str());
280        Row = pResult->Next();              for( r=0; r < 1000; r++){
281        if( Row == NULL ) break;          Row = pResult->Next();      
282        for( t = 0; t < pResult->GetFieldCount(); t++){          if ( !r && !Row ){
283          if (t==0) printf(" => %i \n",atoi(Row->GetField(t)));            printf("\n No run associated to the file %s \n",filename.Data());
284            };
285            if( Row == NULL ) break;
286            if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data());
287            TString UTC="UTC";
288            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());
289        };        };
290      };        delete pResult;  
291      delete pResult;          myquery.str("");
292      myquery.str("");        myquery << "select ";
293      myquery << "select ";        myquery << " PATH,NAME";
294      myquery << " PATH,NAME";        myquery << " from GL_RAW where ID=" << ID_RAW << ";";    
295      myquery << " from GL_RAW where ID=" << ID_RAW << ";";            pResult = dbc->Query(myquery.str().c_str());
296      pResult = dbc->Query(myquery.str().c_str());        for( r=0; r < 1000; r++){
297      if(!pResult->GetRowCount()) return (-51);          Row = pResult->Next();      
298      for( r=0; r < 1000; r++){          if( Row == NULL ) break;
299        Row = pResult->Next();                for( t = 0; t < pResult->GetFieldCount(); t++){
300        if( Row == NULL ) break;            if(t==0) rawpath = Row->GetField(t);
301        for( t = 0; t < pResult->GetFieldCount(); t++){            if(t==1) rawname = Row->GetField(t);
302          if(t==0) rawpath = Row->GetField(t);          };
         if(t==1) rawname = Row->GetField(t);  
303        };        };
304          delete pResult;  
305          printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname);
306      };      };
     delete pResult;    
     printf(" and belongs to raw data file %s/%s \n",rawpath,rawname);  
307    };      };  
308    //    //
309    // Close the DB connection    // Close the DB connection

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

  ViewVC Help
Powered by ViewVC 1.1.23