/[PAMELA software]/YodaProfiler/src/PamelaDBOperations.cpp
ViewVC logotype

Diff of /YodaProfiler/src/PamelaDBOperations.cpp

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

revision 1.6 by mocchiut, Fri Sep 8 16:06:02 2006 UTC revision 1.10 by mocchiut, Tue Sep 12 08:43:50 2006 UTC
# Line 63  PamelaDBOperations::PamelaDBOperations(T Line 63  PamelaDBOperations::PamelaDBOperations(T
63    SetObt0(obt0);    SetObt0(obt0);
64    //    //
65    //    //
66    SetRootName(filerootname);    INSERT_RAW =!filerawname.IsNull();
67    SetRawName(filerawname);    if(INSERT_RAW)SetRawName(filerawname);
68    //    //
69    this->OpenFile();    INSERT_ROOT = !filerootname.IsNull();
70      if( INSERT_ROOT ){
71        this->SetRootName(filerootname);
72        file = TFile::Open(this->GetRootName().Data());
73      };
74    //    //
75    this->SetID_RAW(0);    this->SetID_RAW(0);
76    this->SetID_ROOT(0);    this->SetID_ROOT(0);
77    
78      VALIDATE = false;
79      
80    //    //
81  };  };
82    
# Line 78  PamelaDBOperations::PamelaDBOperations(T Line 85  PamelaDBOperations::PamelaDBOperations(T
85   */   */
86  void PamelaDBOperations::Close(){  void PamelaDBOperations::Close(){
87    if( conn && conn->IsConnected() ) conn->Close();    if( conn && conn->IsConnected() ) conn->Close();
88      delete clean_time;
89    delete glrun;    delete glrun;
90    delete this;    delete this;
91  };  };
# Line 86  void PamelaDBOperations::Close(){ Line 94  void PamelaDBOperations::Close(){
94  // SETTERS  // SETTERS
95  //  //
96    
97    //
98    // must be out of the constructor in order to FORCE the validation of the latest runs in case you run the validation together with the latest file
99    //
100    void PamelaDBOperations::CheckValidate(Long64_t olderthan){
101      clean_time = new TDatime();
102      if(olderthan >= 0){
103        VALIDATE = true;
104        UInt_t timelim = 0;
105        timelim =  (UInt_t)clean_time->Convert() - olderthan;
106        clean_time->Set(timelim,false);
107      };
108    };
109    
110  /**  /**
111   * Open the DB connection   * Open the DB connection
112   * @param host         hostname for the SQL connection.   * @param host         hostname for the SQL connection.
# Line 172  void PamelaDBOperations::SetNOBOOT(Bool_ Line 193  void PamelaDBOperations::SetNOBOOT(Bool_
193   * Store the olderthan variable   * Store the olderthan variable
194   * @param olderthan   * @param olderthan
195   */   */
196  void PamelaDBOperations::SetOlderThan(Long64_t oldthan){  // void PamelaDBOperations::SetOlderThan(Long64_t oldthan){
197    olderthan = oldthan;  //   olderthan = oldthan;
198  };  // };
199    
200  /**  /**
201   * Retrieve the ID_RAW, if exists, returns NULL if does not exist.   * Retrieve the ID_RAW, if exists, returns NULL if does not exist.
# Line 401  Int_t PamelaDBOperations::SetUpperLimits Line 422  Int_t PamelaDBOperations::SetUpperLimits
422      pkth = PKT(phh->GetCounter());      pkth = PKT(phh->GetCounter());
423      obth = OBT(phh->GetOrbitalTime());      obth = OBT(phh->GetOrbitalTime());
424      //      //
425      if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth);  //    if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth);
426      //      //
427      if ( pkth < spkth && obth < sobth ){      if ( pkth < spkth && obth < sobth ){
428        if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i  \n",rhev);        if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i  \n",rhev);
# Line 419  Int_t PamelaDBOperations::SetUpperLimits Line 440  Int_t PamelaDBOperations::SetUpperLimits
440          ph = eh->GetPscuHeader();          ph = eh->GetPscuHeader();
441          t_pktlast = PKT(ph->GetCounter());          t_pktlast = PKT(ph->GetCounter());
442          t_obtlast = OBT(ph->GetOrbitalTime());          t_obtlast = OBT(ph->GetOrbitalTime());
443          if ( t_pktlast < spkth && t_obtlast < sobth ){ // jump          if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump
444            upperpkt = pkth;            upperpkt = pkth;
445            upperobt = obth;            upperobt = obth;
446            upperentry = evbefh-1;            upperentry = evbefh-1;
# Line 460  Int_t PamelaDBOperations::SetUpperLimits Line 481  Int_t PamelaDBOperations::SetUpperLimits
481      pktt = PKT(pht->GetCounter());      pktt = PKT(pht->GetCounter());
482      obtt = OBT(pht->GetOrbitalTime());      obtt = OBT(pht->GetOrbitalTime());
483      //      //
484      if ( IsDebug() ) printf(" k %i rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt);  //    if ( IsDebug() ) printf(" k %i rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt);
485      //      //
486      if ( pktt < spktt && obtt < sobtt ){      if ( pktt < spktt && obtt < sobtt ){
487        if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev);        if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev);
# Line 479  Int_t PamelaDBOperations::SetUpperLimits Line 500  Int_t PamelaDBOperations::SetUpperLimits
500          ph = eh->GetPscuHeader();          ph = eh->GetPscuHeader();
501          t_pktlast = PKT(ph->GetCounter());          t_pktlast = PKT(ph->GetCounter());
502          t_obtlast = OBT(ph->GetOrbitalTime());          t_obtlast = OBT(ph->GetOrbitalTime());
503          if ( t_pktlast < spktt && t_obtlast < sobtt ){ // jump          if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump
504            upperpkt = pktt;            upperpkt = pktt;
505            upperobt = obtt;            upperobt = obtt;
506            upperentry = evbeft-1;            upperentry = evbeft-1;
# Line 628  const PacketType* PamelaDBOperations::Ge Line 649  const PacketType* PamelaDBOperations::Ge
649  // PRIVATE FUNCTIONS  // PRIVATE FUNCTIONS
650  //  //
651    
652  /**  // /**
653   * Open the ROOT filename for reading  // * Open the ROOT filename for reading
654   */  // */
655  void PamelaDBOperations::OpenFile(){  // void PamelaDBOperations::OpenFile(){
656    file = TFile::Open(this->GetRootName().Data());  //   file = TFile::Open(this->GetRootName().Data());
657    //   //
658    
659    void PamelaDBOperations::CheckFile(){  
660      if ( !file ) throw -12;
661  };  };
662    
663    
664  /**  /**
665   * Check if LEVEL0 file and DB connection have really be opened   * Check if LEVEL0 file and DB connection have really be opened
666   */   */
667  void PamelaDBOperations::CheckFile(){    void PamelaDBOperations::CheckConnection(){  
   //  
   if ( !file ) throw -12;  
668    //    //
669    // check connection    // check connection
670    //    //
671    if( !conn ) throw -1;        if( !conn ) throw -1;
672    bool connect = conn->IsConnected();    bool connect = conn->IsConnected();
673    if( !connect ) throw -1;        if( !connect ) throw -1;
674  };  };
675    
676  /**  /**
# Line 3168  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3191  Int_t PamelaDBOperations::CleanGL_RUN_FR
3191    TSQLRow    *row2   = 0;    TSQLRow    *row2   = 0;
3192    //    //
3193    UInt_t moved = 0;    UInt_t moved = 0;
3194    UInt_t timelim = 0;  //  UInt_t timelim = 0;
3195    TDatime *time = new TDatime();  //  TDatime *time = new TDatime();
3196    //    //
3197    stringstream oss;    stringstream oss;
3198    oss.str("");    oss.str("");
3199    //    //
3200    //    //
   //  
   if ( olderthan < 0 ){  
     if ( IsDebug() ) printf(" Do not clean GL_RUN_FRAGMENTS table \n");  
     return(1);  
   };  
   //  
   // timelim = now - olderthan  
   //  
   time->Set();  
   timelim =  (UInt_t)time->Convert() - olderthan;  
   time->Set(timelim,false);  
   //  
3201    // check if there are entries older than "olderthan" seconds from now    // check if there are entries older than "olderthan" seconds from now
3202    //    //
3203    oss.str("");    oss.str("");
3204    oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"    oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"
3205        << " INSERT_TIME <= '" << time->AsSQLString() << "';";        << " INSERT_TIME <= '" << clean_time->AsSQLString() << "';";
3206    //    //
3207    if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str());    if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str());
3208    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
3209    //    //
3210    if ( result ){    if ( result ){
# Line 3291  Int_t PamelaDBOperations::ValidateRuns() Line 3302  Int_t PamelaDBOperations::ValidateRuns()
3302    TSQLResult *result = 0;    TSQLResult *result = 0;
3303    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
3304    //    //
   UInt_t timelim = 0;  
   TDatime *time = new TDatime();  
   //  
3305    stringstream oss;    stringstream oss;
3306    oss.str("");    oss.str("");
3307    //    //
   //  
   //  
   if ( olderthan < 0 ){  
     if ( IsDebug() ) printf(" Do not validate runs \n");  
     return(1);  
   };  
   //  
   // timelim = now - olderthan  
   //  
   time->Set();  
   timelim =  (UInt_t)time->Convert() - olderthan;  
   time->Set(timelim,false);  
   
   printf("Validate runs older than %s \n",time->AsSQLString());  
   
3308    // =======================================================    // =======================================================
3309    // validate runs by checking missing calibrations    // validate runs by checking missing calibrations
3310    // =======================================================    // =======================================================
# Line 3321  Int_t PamelaDBOperations::ValidateRuns() Line 3314  Int_t PamelaDBOperations::ValidateRuns()
3314    // 1) get the OBT of the last run inserted after clean-time limit    // 1) get the OBT of the last run inserted after clean-time limit
3315    // --------------------------------------------------------------    // --------------------------------------------------------------
3316    oss.str("");    oss.str("");
3317    oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << time->AsSQLString()    oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << clean_time->AsSQLString()
3318        << "' ORDER BY INSERT_TIME DESC LIMIT 1;";            << "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3319    printf(" Get start validation-time: query is \n %s \n",oss.str().c_str());    if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str());
3320    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
3321    if ( !result ) throw -4;    if ( !result ) throw -4;
3322    if ( !result->GetRowCount() ) {    if ( !result->GetRowCount() ) {
# Line 3332  Int_t PamelaDBOperations::ValidateRuns() Line 3325  Int_t PamelaDBOperations::ValidateRuns()
3325    }else{    }else{
3326          row = result->Next();          row = result->Next();
3327          t_start = (UInt_t)atoll(row->GetField(4));          t_start = (UInt_t)atoll(row->GetField(4));
         printf("t_start %i\n",t_start);  
3328    };      };  
3329    // --------------------------------------------------------------    // --------------------------------------------------------------
3330    // 2) get the OBT of the last validated run    // 2) get the OBT of the last validated run
# Line 3340  Int_t PamelaDBOperations::ValidateRuns() Line 3332  Int_t PamelaDBOperations::ValidateRuns()
3332    oss.str("");    oss.str("");
3333    oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start    oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start
3334        <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";        <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3335    printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());    if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());
3336    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
3337    if ( !result ) throw -4;    if ( !result ) throw -4;
3338    if ( result->GetRowCount() ){    if ( result->GetRowCount() ){
3339            row = result->Next();            row = result->Next();
3340            t_stop = (UInt_t)atoll(row->GetField(4));            t_stop = (UInt_t)atoll(row->GetField(4));
3341    };    };
3342    printf("t_stop %i\n",t_stop);    if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start);
3343    // --------------------------------------------------------------    // --------------------------------------------------------------
3344    // now retrieves runs to be validated    // now retrieves runs to be validated
3345    // --------------------------------------------------------------    // --------------------------------------------------------------
# Line 3356  Int_t PamelaDBOperations::ValidateRuns() Line 3348  Int_t PamelaDBOperations::ValidateRuns()
3348    oss << " AND RUNHEADER_TIME >="<< t_stop;    oss << " AND RUNHEADER_TIME >="<< t_stop;
3349    oss << " ORDER BY RUNHEADER_TIME DESC;";    oss << " ORDER BY RUNHEADER_TIME DESC;";
3350  //  if ( IsDebug() )  //  if ( IsDebug() )
3351    printf(" Check runs for validation: query is \n %s \n",oss.str().c_str());    if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str());
3352    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
3353    if ( !result ) throw -4;    if ( !result ) throw -4;
3354    if ( !result->GetRowCount() ) printf(" No runs to validate \n");    if ( !result->GetRowCount() ) printf(" No runs to validate \n");
3355    printf("------------------------------------------------------------------------------- \n");  //  printf("------------------------------------------------------------------------------- \n");
3356        
3357    Int_t nrow = 0;    Int_t nrow = 0;
3358    GL_RUN* this_run = new GL_RUN();    GL_RUN* this_run = new GL_RUN();
3359    GL_RUN* next_run = new GL_RUN();    GL_RUN* next_run = new GL_RUN();
3360    Int_t   nseq_max = 100;    Int_t   nseq_max = 1000;
3361  //  UInt_t* sequence = new UInt_t[100];  //  UInt_t* sequence = new UInt_t[100];
3362    vector<UInt_t> sequence(nseq_max);    vector<UInt_t> sequence(nseq_max);
3363    Int_t   nseq = 0;    Int_t   nseq = 0;
# Line 3388  Int_t PamelaDBOperations::ValidateRuns() Line 3380  Int_t PamelaDBOperations::ValidateRuns()
3380            //get run info            //get run info
3381            //------------            //------------
3382            this_run->Set_GL_RUN(row);            this_run->Set_GL_RUN(row);
3383                                
           printf(" RUN ID %i --- TRK_CALIB_USED %i --- RM_ACQ_AFTER_CALIB %i --- TIME %i %i \n",this_run->ID,this_run->TRK_CALIB_USED,this_run->RM_ACQ_AFTER_CALIB,this_run->RUNHEADER_TIME, this_run->RUNTRAILER_TIME);  
             
3384            Bool_t this_BAD = false;            Bool_t this_BAD = false;
3385            if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true;            if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true;
3386            else if (this_run->GetTRK_CALIB_USED() == 104)                          this_ONLINE = false;            else if (this_run->GetTRK_CALIB_USED() == 104)                          this_ONLINE = false;
3387            else{            else{
3388                    printf("Missing or corrupted header!! \n");  //                printf("Missing or corrupted header!! \n");
3389                    this_ONLINE = false;                    this_ONLINE = false;
3390                    this_BAD = true;                    this_BAD = true;
3391            };            };
# Line 3419  Int_t PamelaDBOperations::ValidateRuns() Line 3409  Int_t PamelaDBOperations::ValidateRuns()
3409                                                        
3410                            if( interval >= 60 )CHECK = true;                     //more than 60 s => there might be a calibration                            if( interval >= 60 )CHECK = true;                     //more than 60 s => there might be a calibration
3411                                                        
 /*                        if( CHECK && !next_run->GetRM_ACQ_AFTER_CALIB() )  
                                   printf(" ValidateRuns ***WARNING*** : DT = %i but RM_ACQ_AFTER_CALIB = %i \n",(t2-t1),next_run->GetRM_ACQ_AFTER_CALIB());*/  
                                                     
                             
3412                            if( !CHECK && this_run->VALIDATION ){                            if( !CHECK && this_run->VALIDATION ){
3413                                    for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);                                    for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
3414                                    nseq=0;                                    nseq=0;
# Line 3431  Int_t PamelaDBOperations::ValidateRuns() Line 3417  Int_t PamelaDBOperations::ValidateRuns()
3417                    }else if( !this_ONLINE && next_ONLINE) {              // this: DEFAULT + next:ON-LINE                    }else if( !this_ONLINE && next_ONLINE) {              // this: DEFAULT + next:ON-LINE
3418                                                        
3419                            CHECK = true;                            CHECK = true;
 //                        if( interval < 60 ) printf(" ValidateRuns ***WARNING*** : kkkkkk DT = %i \n",interval);  
3420    
3421                    }else if( !next_ONLINE ){                                             // this:ANY + next:DEFAULT                    }else if( !next_ONLINE ){                                             // this:ANY + next:DEFAULT
3422                                                        
# Line 3445  Int_t PamelaDBOperations::ValidateRuns() Line 3430  Int_t PamelaDBOperations::ValidateRuns()
3430            //----------------------------            //----------------------------
3431            if( CHECK ){            if( CHECK ){
3432                    // check if calibration exists                    // check if calibration exists
3433                    printf("DT %i ===> CHECK Missing calibration\n",interval);                    if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval);
3434                    Bool_t MISSING = MissingTRK_CALIB(t1,t2);                    Bool_t MISSING = MissingTRK_CALIB(t1,t2);
3435                    for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);                    for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);
3436                    nseq=0;                    nseq=0;
3437            } else printf("DT %i\n",interval);            };
3438            //--------------            //--------------
3439            //store run info            //store run info
3440            //--------------            //--------------
# Line 3462  Int_t PamelaDBOperations::ValidateRuns() Line 3447  Int_t PamelaDBOperations::ValidateRuns()
3447                    }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max);                    }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max);
3448            };            };
3449                        
3450              if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID);
3451            nrow++;            nrow++;
3452                        
3453    };    };
# Line 3490  Bool_t PamelaDBOperations::MissingTRK_CA Line 3476  Bool_t PamelaDBOperations::MissingTRK_CA
3476          // which should be equal to the time between ascending-nodes.          // which should be equal to the time between ascending-nodes.
3477          //==============================================================          //==============================================================
3478          if ( t2 - trkcalib->FROM_TIME > 5700) {          if ( t2 - trkcalib->FROM_TIME > 5700) {
3479                  printf("Long time to previous calib %i :-( \n",t2 - trkcalib->FROM_TIME);                  if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME);
3480          //==============================================================          //==============================================================
3481          // there might be a missing calibration, due to:          // there might be a missing calibration, due to:
3482          // - MM full          // - MM full
# Line 3511  Bool_t PamelaDBOperations::MissingTRK_CA Line 3497  Bool_t PamelaDBOperations::MissingTRK_CA
3497          // it is enough to say that there are no missing calibrations          // it is enough to say that there are no missing calibrations
3498          //==============================================================          //==============================================================
3499          // the long time interval bewteen runs might be due to download          // the long time interval bewteen runs might be due to download
3500          printf("Short time to previous calib %i :-) \n",t2 - trkcalib->FROM_TIME);          if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME);
3501          return(false);          return(false);
3502                    
3503  };  };
# Line 3524  Int_t PamelaDBOperations::assignVALIDATI Line 3510  Int_t PamelaDBOperations::assignVALIDATI
3510          TSQLResult *result = 0;          TSQLResult *result = 0;
3511          stringstream oss;          stringstream oss;
3512          oss.str("");          oss.str("");
3513          oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << "';";          oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";";
3514          //          //
3515  //      if ( IsDebug() )  //      if ( IsDebug() )
3516          printf(" Set VALIDATION = %i for run %i \n",validation,idrun);  //      printf(" Set VALIDATION = %i for run %i \n",validation,idrun);
3517  //      printf(" Set VALIDATION = %i for run %i : query is \n %s \n",validation,idrun,oss.str().c_str());          if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str());
3518  //      result = conn->Query(oss.str().c_str());          result = conn->Query(oss.str().c_str());
3519  //      if ( !result ) throw -4;          if ( !result ) throw -4;
3520          return(0);          return(0);
3521  }  }
3522    

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.23