/[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.4 by mocchiut, Fri Sep 8 12:44:27 2006 UTC revision 1.5 by pam-fi, Fri Sep 8 14:42:48 2006 UTC
# Line 3245  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3245  Int_t PamelaDBOperations::CleanGL_RUN_FR
3245  Int_t PamelaDBOperations::ValidateRuns(){  Int_t PamelaDBOperations::ValidateRuns(){
3246    //    //
3247    TSQLResult *result = 0;    TSQLResult *result = 0;
3248    // TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
3249    //    //
3250    UInt_t timelim = 0;    UInt_t timelim = 0;
3251    TDatime *time = new TDatime();    TDatime *time = new TDatime();
# Line 3265  Int_t PamelaDBOperations::ValidateRuns() Line 3265  Int_t PamelaDBOperations::ValidateRuns()
3265    time->Set();    time->Set();
3266    timelim =  (UInt_t)time->Convert() - olderthan;    timelim =  (UInt_t)time->Convert() - olderthan;
3267    time->Set(timelim,false);    time->Set(timelim,false);
3268    //  
3269    // First of all validate runs with default calibration:    printf("Validate runs older than %s \n",time->AsSQLString());
3270    //  
3271      // =======================================================
3272      // validate runs by checking missing calibrations
3273      // =======================================================
3274      UInt_t t_stop  = 0;
3275      UInt_t t_start = 0;
3276      // --------------------------------------------------------------
3277      // 1) get the OBT of the last run inserted after clean-time limit
3278      // --------------------------------------------------------------
3279    oss.str("");    oss.str("");
3280    oss << " UPDATE GL_RUN SET VALIDATION=1 WHERE"    oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << time->AsSQLString()
3281        << " VALIDATION = 0 AND TRK_CALIB_USED=104 AND "        << "' ORDER BY INSERT_TIME DESC LIMIT 1;";
3282        << " INSERT_TIME <= '" << time->AsSQLString() << "';";    printf(" Get start validation-time: query is \n %s \n",oss.str().c_str());
3283    //    result = conn->Query(oss.str().c_str());
3284    if ( IsDebug() ) printf(" Validate runs with trk default calibration inserted before %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str());    if ( !result ) throw -4;
3285      if ( !result->GetRowCount() ) {
3286              printf(" No runs to validate \n");
3287              return(1);
3288      }else{
3289            row = result->Next();
3290            t_start = (UInt_t)atoll(row->GetField(4));
3291            printf("t_start %i\n",t_start);
3292      };  
3293      // --------------------------------------------------------------
3294      // 2) get the OBT of the last validated run
3295      // --------------------------------------------------------------
3296      oss.str("");
3297      oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start
3298          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3299      printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());
3300    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
   //  
3301    if ( !result ) throw -4;    if ( !result ) throw -4;
3302      if ( result->GetRowCount() ){
3303              row = result->Next();
3304              t_stop = (UInt_t)atoll(row->GetField(4));
3305      };
3306      printf("t_stop %i\n",t_stop);
3307      // --------------------------------------------------------------
3308      // now retrieves runs to be validated
3309      // --------------------------------------------------------------
3310      oss.str("");
3311      oss << " SELECT * FROM GL_RUN  WHERE  RUNHEADER_TIME <=" << t_start;
3312      oss << " AND RUNHEADER_TIME >="<< t_stop;
3313      oss << " ORDER BY RUNHEADER_TIME DESC;";
3314    //  if ( IsDebug() )
3315      printf(" Check runs for validation: query is \n %s \n",oss.str().c_str());
3316      result = conn->Query(oss.str().c_str());
3317      if ( !result ) throw -4;
3318      if ( !result->GetRowCount() ) printf(" No runs to validate \n");
3319      printf("------------------------------------------------------------------------------- \n");
3320      
3321      Int_t nrow = 0;
3322      GL_RUN* this_run = new GL_RUN();
3323      GL_RUN* next_run = new GL_RUN();
3324      Int_t   nseq_max = 100;
3325    //  UInt_t* sequence = new UInt_t[100];
3326      vector<UInt_t> sequence(nseq_max);
3327      Int_t   nseq = 0;
3328      Bool_t CHECK = false;
3329      Bool_t this_ONLINE = false;
3330      Bool_t next_ONLINE = false;
3331      UInt_t t1=0,t2=0;
3332      // ---------------------------------------------------------------------------------
3333      // - loop over runs, back in time,
3334      // - select sequences of runs close in time (less than 60 s apart),
3335      //   which could be preceeded by a calibration
3336      // - check if there might be a missing calibration
3337      // ---------------------------------------------------------------------------------
3338      while(1){
3339              
3340              row = result->Next();
3341              if( row == NULL ) break;
3342              
3343              //------------
3344              //get run info
3345              //------------
3346              this_run->Set_GL_RUN(row);
3347              
3348              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);
3349              
3350              Bool_t this_BAD = false;
3351              if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true;
3352              else if (this_run->GetTRK_CALIB_USED() == 104)                          this_ONLINE = false;
3353              else{
3354                      printf("Missing or corrupted header!! \n");
3355                      this_ONLINE = false;
3356                      this_BAD = true;
3357              };
3358    
3359              //-----------------------------------
3360              //compare with previous(next in time)
3361              //-----------------------------------
3362              CHECK = false;
3363              UInt_t interval=0;
3364              
3365              if( nrow != 0){
3366            
3367                      
3368                      t1 = this_run->GetRUNTRAILER_TIME();
3369                      t2 = next_run->GetRUNHEADER_TIME();
3370                      interval = (t2-t1);
3371                      
3372                      if(this_ONLINE && next_ONLINE){                               // this: ON-LINE + next: ON-LINE
3373                              
3374                              if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0;     //=> run fragments
3375                              
3376                              if( interval >= 60 )CHECK = true;                     //more than 60 s => there might be a calibration
3377                              
3378    /*                        if( CHECK && !next_run->GetRM_ACQ_AFTER_CALIB() )
3379                                      printf(" ValidateRuns ***WARNING*** : DT = %i but RM_ACQ_AFTER_CALIB = %i \n",(t2-t1),next_run->GetRM_ACQ_AFTER_CALIB());*/
3380                                                      
3381                              
3382                              if( !CHECK && this_run->VALIDATION ){
3383                                      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
3384                                      nseq=0;
3385                              }
3386                      
3387                      }else if( !this_ONLINE && next_ONLINE) {              // this: DEFAULT + next:ON-LINE
3388                              
3389                              CHECK = true;
3390    //                        if( interval < 60 ) printf(" ValidateRuns ***WARNING*** : kkkkkk DT = %i \n",interval);
3391    
3392                      }else if( !next_ONLINE ){                                             // this:ANY + next:DEFAULT
3393                              
3394                              assignVALIDATION(next_run->ID,true);
3395                              nseq=0;
3396                      }
3397              }
3398    
3399              //----------------------------
3400              //check run sequence for calib
3401              //----------------------------
3402              if( CHECK ){
3403                      // check if calibration exists
3404                      printf("DT %i ===> CHECK Missing calibration\n",interval);
3405                      Bool_t MISSING = MissingTRK_CALIB(t1,t2);
3406                      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);
3407                      nseq=0;
3408              } else printf("DT %i\n",interval);
3409              //--------------
3410              //store run info
3411              //--------------
3412              *next_run   = *this_run;
3413              next_ONLINE = this_ONLINE;
3414              if( !this_BAD ){
3415                      if(nseq < nseq_max){
3416                              sequence[nseq] = this_run->ID;
3417                              nseq++;
3418                      }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max);
3419              };
3420              
3421              nrow++;
3422              
3423      };
3424      delete this_run;
3425      delete next_run;
3426    //    //
3427    return(0);    return(0);
3428  };  };
3429    /**
3430     * Check if there might be a missing tracker calibration in a given time interval
3431     * @param t1 From absolute time
3432     * @param t2 To absolute time
3433     * @return true if there might be a missing calibration
3434     */
3435    Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){
3436            
3437            GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB();
3438            
3439            // get the closest VALIDATED calibration before the run start (t2)
3440            if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true);      //>>> missing
3441            
3442            if ( trkcalib->TO_TIME  < t2 ) return(true);                                    //>>> missing
3443            
3444            //==============================================================
3445            // Check is done first on the basis of time between calibration,
3446            // which should be equal to the time between ascending-nodes.
3447            //==============================================================
3448            if ( t2 - trkcalib->FROM_TIME > 5700) {
3449                    printf("Long time to previous calib %i :-( \n",t2 - trkcalib->FROM_TIME);
3450            //==============================================================
3451            // there might be a missing calibration, due to:
3452            // - MM full
3453            // - corrupted packets
3454            // - loss of data
3455            // There is an exception in case a download was done during ascending node
3456            //==============================================================
3457                    Bool_t DOWNLOAD = false;
3458                    // check if the calib was skipped becouse of download .... DA FARE!!
3459                    if(DOWNLOAD)return(false);
3460                    
3461                    return(true);                                   //>>> missing
3462                    
3463            };
3464            
3465            //==============================================================
3466            // If the last calibration is close to the run less than this time,
3467            // it is enough to say that there are no missing calibrations
3468            //==============================================================
3469            // the long time interval bewteen runs might be due to download
3470            printf("Short time to previous calib %i :-) \n",t2 - trkcalib->FROM_TIME);
3471            return(false);
3472            
3473    };
3474    /**
3475     * Assign VALIDATION value to a GL_RUN entry
3476     * @param idrun Run ID
3477     * @param validation true/false
3478     */
3479    Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){
3480            TSQLResult *result = 0;
3481            stringstream oss;
3482            oss.str("");
3483            oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << "';";
3484            //
3485    //      if ( IsDebug() )
3486            printf(" Set VALIDATION = %i for run %i \n",validation,idrun);
3487    //      printf(" Set VALIDATION = %i for run %i : query is \n %s \n",validation,idrun,oss.str().c_str());
3488    //      result = conn->Query(oss.str().c_str());
3489    //      if ( !result ) throw -4;
3490            return(0);
3491    }
3492    
3493    
3494    

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

  ViewVC Help
Powered by ViewVC 1.1.23