/[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.8 by pam-fi, Mon Sep 11 16:38:18 2006 UTC
# Line 48  using namespace pamela; Line 48  using namespace pamela;
48   * @param tsync        file timesync.   * @param tsync        file timesync.
49   * @param debug        debug flag.   * @param debug        debug flag.
50   */   */
51  PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug){  PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, Long64_t olderthan){
52    //    //
53    //    //
54    SetConnection(host,user,password);    SetConnection(host,user,password);
# 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              file = TFile::Open(this->GetRootName().Data());
72              if ( !file ) INSERT_ROOT = false;
73      };
74    //  this->OpenFile();
75    //    //
76    this->SetID_RAW(0);    this->SetID_RAW(0);
77    this->SetID_ROOT(0);    this->SetID_ROOT(0);
78    //  
79      VALIDATE = false;
80      clean_time = new TDatime();
81      if(olderthan >= 0){
82            VALIDATE = true;
83            UInt_t timelim = 0;
84            // timelim = now - olderthan
85            timelim =  (UInt_t)clean_time->Convert() - olderthan;
86            clean_time->Set(timelim,false);
87      };
88      
89        //
90  };  };
91    
92  /**  /**
# Line 78  PamelaDBOperations::PamelaDBOperations(T Line 94  PamelaDBOperations::PamelaDBOperations(T
94   */   */
95  void PamelaDBOperations::Close(){  void PamelaDBOperations::Close(){
96    if( conn && conn->IsConnected() ) conn->Close();    if( conn && conn->IsConnected() ) conn->Close();
97      delete clean_time;
98    delete glrun;    delete glrun;
99    delete this;    delete this;
100  };  };
# Line 172  void PamelaDBOperations::SetNOBOOT(Bool_ Line 189  void PamelaDBOperations::SetNOBOOT(Bool_
189   * Store the olderthan variable   * Store the olderthan variable
190   * @param olderthan   * @param olderthan
191   */   */
192  void PamelaDBOperations::SetOlderThan(Long64_t oldthan){  // void PamelaDBOperations::SetOlderThan(Long64_t oldthan){
193    olderthan = oldthan;  //   olderthan = oldthan;
194  };  // };
195    
196  /**  /**
197   * 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 320  Int_t PamelaDBOperations::SetUpperLimits Line 337  Int_t PamelaDBOperations::SetUpperLimits
337    // check if last runtrailer is within limits, if not extend limits (one should check for all packets but we need only runtrailer)    // check if last runtrailer is within limits, if not extend limits (one should check for all packets but we need only runtrailer)
338    //    //
339    PacketType *pctp=0;    PacketType *pctp=0;
   T->GetEntry(upperentry);  
   code = eh->GetCounter();  
   Int_t lasttrail = code->Get(pctp->RunTrailer);  
   Int_t lasthead = code->Get(pctp->RunHeader);  
340    TTree *rh=(TTree*)file->Get("RunHeader");    TTree *rh=(TTree*)file->Get("RunHeader");
341    if ( !rh || rh->IsZombie() ) throw -17;    if ( !rh || rh->IsZombie() ) throw -17;
342    TTree *rt=(TTree*)file->Get("RunTrailer");    TTree *rt=(TTree*)file->Get("RunTrailer");
# Line 346  Int_t PamelaDBOperations::SetUpperLimits Line 359  Int_t PamelaDBOperations::SetUpperLimits
359    UInt_t pkth = 0;    UInt_t pkth = 0;
360    ULong64_t obth = 0;    ULong64_t obth = 0;
361    //    //
362      T->GetEntry(upperentry);
363      code = eh->GetCounter();
364      Int_t lasttrail = code->Get(pctp->RunTrailer);
365      Int_t lasthead = code->Get(pctp->RunHeader);
366    if ( lasttrail < rtev ){    if ( lasttrail < rtev ){
367      rt->GetEntry(lasttrail);      rt->GetEntry(lasttrail);
368      pht = eht->GetPscuHeader();      pht = eht->GetPscuHeader();
# Line 356  Int_t PamelaDBOperations::SetUpperLimits Line 373  Int_t PamelaDBOperations::SetUpperLimits
373    if ( lasthead < rhev ){    if ( lasthead < rhev ){
374      rh->GetEntry(lasthead);      rh->GetEntry(lasthead);
375      phh = ehh->GetPscuHeader();      phh = ehh->GetPscuHeader();
376      pkth = PKT(pht->GetCounter());      pkth = PKT(phh->GetCounter());
377      obth = OBT(pht->GetOrbitalTime());      obth = OBT(phh->GetOrbitalTime());
378    };    };
379    //    //
380    if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);    if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
# Line 401  Int_t PamelaDBOperations::SetUpperLimits Line 418  Int_t PamelaDBOperations::SetUpperLimits
418      pkth = PKT(phh->GetCounter());      pkth = PKT(phh->GetCounter());
419      obth = OBT(phh->GetOrbitalTime());      obth = OBT(phh->GetOrbitalTime());
420      //      //
421    //    if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth);
422        //
423      if ( pkth < spkth && obth < sobth ){      if ( pkth < spkth && obth < sobth ){
       if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);  
424        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);
425        //        //
426        rhev--;        rhev = k-1;
427        rh->GetEntry(rhev);        rh->GetEntry(rhev);
428        pkth = spkth;        pkth = spkth;
429        obth = sobth;        obth = sobth;
       if ( IsDebug() ) printf(" lasthead %i pt %i p1 %i ot %u o1 %u \n",rhev,pkth,spkth,obth,sobth);  
430        //        //
431        UInt_t evbefh = 0;        UInt_t evbefh = 0;
432        code = ehh->GetCounter();        code = ehh->GetCounter();
# Line 419  Int_t PamelaDBOperations::SetUpperLimits Line 436  Int_t PamelaDBOperations::SetUpperLimits
436          ph = eh->GetPscuHeader();          ph = eh->GetPscuHeader();
437          t_pktlast = PKT(ph->GetCounter());          t_pktlast = PKT(ph->GetCounter());
438          t_obtlast = OBT(ph->GetOrbitalTime());          t_obtlast = OBT(ph->GetOrbitalTime());
439          if ( t_pktlast < spkth && t_obtlast < sobth ){ // jump          if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump
440            upperpkt = pkth;            upperpkt = pkth;
441            upperobt = obth;            upperobt = obth;
442            upperentry = evbefh-1;            upperentry = evbefh-1;
# Line 439  Int_t PamelaDBOperations::SetUpperLimits Line 456  Int_t PamelaDBOperations::SetUpperLimits
456          };              };    
457        };        };
458        if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);        if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
459          goto kikko0;
460      };      };
461    };    };
462     kikko0:
463    //    //
464    //    //
465    //    //
# Line 458  Int_t PamelaDBOperations::SetUpperLimits Line 477  Int_t PamelaDBOperations::SetUpperLimits
477      pktt = PKT(pht->GetCounter());      pktt = PKT(pht->GetCounter());
478      obtt = OBT(pht->GetOrbitalTime());      obtt = OBT(pht->GetOrbitalTime());
479      //      //
480    //    if ( IsDebug() ) printf(" k %i rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt);
481        //
482      if ( pktt < spktt && obtt < sobtt ){      if ( pktt < spktt && obtt < sobtt ){
       if ( IsDebug() ) printf(" rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);  
483        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);
484        //        //
485        rtev--;        rtev = k-1;
486        rt->GetEntry(rtev);        rt->GetEntry(rtev);
487        pktt = spktt;        pktt = spktt;
488        obtt = sobtt;        obtt = sobtt;
# Line 476  Int_t PamelaDBOperations::SetUpperLimits Line 496  Int_t PamelaDBOperations::SetUpperLimits
496          ph = eh->GetPscuHeader();          ph = eh->GetPscuHeader();
497          t_pktlast = PKT(ph->GetCounter());          t_pktlast = PKT(ph->GetCounter());
498          t_obtlast = OBT(ph->GetOrbitalTime());          t_obtlast = OBT(ph->GetOrbitalTime());
499          if ( t_pktlast < spktt && t_obtlast < sobtt ){ // jump          if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump
500            upperpkt = pktt;            upperpkt = pktt;
501            upperobt = obtt;            upperobt = obtt;
502            upperentry = evbeft-1;            upperentry = evbeft-1;
# Line 496  Int_t PamelaDBOperations::SetUpperLimits Line 516  Int_t PamelaDBOperations::SetUpperLimits
516          };          };
517        };        };
518        if ( IsDebug() ) printf(" rtev after %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);        if ( IsDebug() ) printf(" rtev after %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
519        break;        goto kikko;
520          //      break;
521        //        //
522      };      };
523      //        //  
524    };    };
525    //    //
526    // kikko:   kikko:
527      //
528      T->GetEntry(upperentry);
529      code = eh->GetCounter();
530      lasttrail = code->Get(pctp->RunTrailer);
531      lasthead = code->Get(pctp->RunHeader);
532      if ( lasttrail < rtev ){
533        rt->GetEntry(lasttrail);
534        pht = eht->GetPscuHeader();
535        pktt = PKT(pht->GetCounter());
536        obtt = OBT(pht->GetOrbitalTime());
537      };
538      //
539      if ( lasthead < rhev ){
540        rh->GetEntry(lasthead);
541        phh = ehh->GetPscuHeader();
542        pkth = PKT(phh->GetCounter());
543        obth = OBT(phh->GetOrbitalTime());
544      };
545      //
546      if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
547      if ( pkth > upperpkt && obth > upperobt ){
548        if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt);
549        upperpkt = pkth;
550        upperobt = obth;
551        rhev = lasthead+1;
552      } else {
553        rhev = lasthead;
554      };
555      if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
556      //
557      if ( IsDebug() ) printf(" rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
558      if ( pktt > upperpkt && obtt > upperobt ){
559        if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt);
560        upperpkt = pktt;
561        upperobt = obtt;
562        rtev = lasttrail+1;
563      } else {
564        rtev = lasttrail;
565      };
566      if ( IsDebug() ) printf(" rtev after %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
567    //    //
568    if ( IsDebug() ) printf(" Upper limits are: OBT %llu pkt_num %i upper entry %i \n",upperobt,upperpkt,upperentry);    if ( IsDebug() ) printf(" Upper limits are: OBT %llu pkt_num %i upper entry %i \n",upperobt,upperpkt,upperentry);
569    //    //
# Line 584  const PacketType* PamelaDBOperations::Ge Line 645  const PacketType* PamelaDBOperations::Ge
645  // PRIVATE FUNCTIONS  // PRIVATE FUNCTIONS
646  //  //
647    
648  /**  // /**
649   * Open the ROOT filename for reading  // * Open the ROOT filename for reading
650   */  // */
651  void PamelaDBOperations::OpenFile(){  // void PamelaDBOperations::OpenFile(){
652    file = TFile::Open(this->GetRootName().Data());  //   file = TFile::Open(this->GetRootName().Data());
653  };  //   //
654    //   if ( !file ) throw -12;
655    // };
656    
657    
658  /**  /**
659   * Check if LEVEL0 file and DB connection have really be opened   * Check if LEVEL0 file and DB connection have really be opened
660   */   */
661  void PamelaDBOperations::CheckFile(){    void PamelaDBOperations::CheckConnection(){  
   //  
   if ( !file ) throw -12;  
662    //    //
663    // check connection    // check connection
664    //    //
665    if( !conn ) throw -1;        if( !conn ) throw -1;
666    bool connect = conn->IsConnected();    bool connect = conn->IsConnected();
667    if( !connect ) throw -1;        if( !connect ) throw -1;
668  };  };
669    
670  /**  /**
# Line 3124  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3185  Int_t PamelaDBOperations::CleanGL_RUN_FR
3185    TSQLRow    *row2   = 0;    TSQLRow    *row2   = 0;
3186    //    //
3187    UInt_t moved = 0;    UInt_t moved = 0;
3188    UInt_t timelim = 0;  //  UInt_t timelim = 0;
3189    TDatime *time = new TDatime();  //  TDatime *time = new TDatime();
3190    //    //
3191    stringstream oss;    stringstream oss;
3192    oss.str("");    oss.str("");
3193    //    //
3194    //    //
   //  
   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);  
   //  
3195    // check if there are entries older than "olderthan" seconds from now    // check if there are entries older than "olderthan" seconds from now
3196    //    //
3197    oss.str("");    oss.str("");
3198    oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"    oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"
3199        << " INSERT_TIME <= '" << time->AsSQLString() << "';";        << " INSERT_TIME <= '" << clean_time->AsSQLString() << "';";
3200    //    //
3201    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());
3202    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
3203    //    //
3204    if ( result ){    if ( result ){
# Line 3245  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3294  Int_t PamelaDBOperations::CleanGL_RUN_FR
3294  Int_t PamelaDBOperations::ValidateRuns(){  Int_t PamelaDBOperations::ValidateRuns(){
3295    //    //
3296    TSQLResult *result = 0;    TSQLResult *result = 0;
3297    // TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
   //  
   UInt_t timelim = 0;  
   TDatime *time = new TDatime();  
3298    //    //
3299    stringstream oss;    stringstream oss;
3300    oss.str("");    oss.str("");
3301    //    //
3302    //    // =======================================================
3303    //    // validate runs by checking missing calibrations
3304    if ( olderthan < 0 ){    // =======================================================
3305      if ( IsDebug() ) printf(" Do not validate runs \n");    UInt_t t_stop  = 0;
3306      return(1);    UInt_t t_start = 0;
3307      // --------------------------------------------------------------
3308      // 1) get the OBT of the last run inserted after clean-time limit
3309      // --------------------------------------------------------------
3310      oss.str("");
3311      oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << clean_time->AsSQLString()
3312              << "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3313      if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str());
3314      result = conn->Query(oss.str().c_str());
3315      if ( !result ) throw -4;
3316      if ( !result->GetRowCount() ) {
3317              printf(" No runs to validate \n");
3318              return(1);
3319      }else{
3320            row = result->Next();
3321            t_start = (UInt_t)atoll(row->GetField(4));
3322      };  
3323      // --------------------------------------------------------------
3324      // 2) get the OBT of the last validated run
3325      // --------------------------------------------------------------
3326      oss.str("");
3327      oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start
3328          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3329      if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());
3330      result = conn->Query(oss.str().c_str());
3331      if ( !result ) throw -4;
3332      if ( result->GetRowCount() ){
3333              row = result->Next();
3334              t_stop = (UInt_t)atoll(row->GetField(4));
3335    };    };
3336    //    if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start);
3337    // timelim = now - olderthan    // --------------------------------------------------------------
3338    //    // now retrieves runs to be validated
3339    time->Set();    // --------------------------------------------------------------
3340    timelim =  (UInt_t)time->Convert() - olderthan;    oss.str("");
3341    time->Set(timelim,false);    oss << " SELECT * FROM GL_RUN  WHERE  RUNHEADER_TIME <=" << t_start;
3342    //    oss << " AND RUNHEADER_TIME >="<< t_stop;
3343    // First of all validate runs with default calibration:    oss << " ORDER BY RUNHEADER_TIME DESC;";
3344    //  //  if ( IsDebug() )
3345    oss.str("");    if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str());
   oss << " UPDATE GL_RUN SET VALIDATION=1 WHERE"  
       << " VALIDATION = 0 AND TRK_CALIB_USED=104 AND "  
       << " INSERT_TIME <= '" << time->AsSQLString() << "';";  
   //  
   if ( IsDebug() ) printf(" Validate runs with trk default calibration inserted before %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str());  
3346    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
   //  
3347    if ( !result ) throw -4;    if ( !result ) throw -4;
3348      if ( !result->GetRowCount() ) printf(" No runs to validate \n");
3349    //  printf("------------------------------------------------------------------------------- \n");
3350      
3351      Int_t nrow = 0;
3352      GL_RUN* this_run = new GL_RUN();
3353      GL_RUN* next_run = new GL_RUN();
3354      Int_t   nseq_max = 1000;
3355    //  UInt_t* sequence = new UInt_t[100];
3356      vector<UInt_t> sequence(nseq_max);
3357      Int_t   nseq = 0;
3358      Bool_t CHECK = false;
3359      Bool_t this_ONLINE = false;
3360      Bool_t next_ONLINE = false;
3361      UInt_t t1=0,t2=0;
3362      // ---------------------------------------------------------------------------------
3363      // - loop over runs, back in time,
3364      // - select sequences of runs close in time (less than 60 s apart),
3365      //   which could be preceeded by a calibration
3366      // - check if there might be a missing calibration
3367      // ---------------------------------------------------------------------------------
3368      while(1){
3369              
3370              row = result->Next();
3371              if( row == NULL ) break;
3372              
3373              //------------
3374              //get run info
3375              //------------
3376              this_run->Set_GL_RUN(row);
3377                      
3378              Bool_t this_BAD = false;
3379              if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true;
3380              else if (this_run->GetTRK_CALIB_USED() == 104)                          this_ONLINE = false;
3381              else{
3382    //                printf("Missing or corrupted header!! \n");
3383                      this_ONLINE = false;
3384                      this_BAD = true;
3385              };
3386    
3387              //-----------------------------------
3388              //compare with previous(next in time)
3389              //-----------------------------------
3390              CHECK = false;
3391              UInt_t interval=0;
3392              
3393              if( nrow != 0){
3394            
3395                      
3396                      t1 = this_run->GetRUNTRAILER_TIME();
3397                      t2 = next_run->GetRUNHEADER_TIME();
3398                      interval = (t2-t1);
3399                      
3400                      if(this_ONLINE && next_ONLINE){                               // this: ON-LINE + next: ON-LINE
3401                              
3402                              if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0;     //=> run fragments
3403                              
3404                              if( interval >= 60 )CHECK = true;                     //more than 60 s => there might be a calibration
3405                              
3406                              if( !CHECK && this_run->VALIDATION ){
3407                                      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
3408                                      nseq=0;
3409                              }
3410                      
3411                      }else if( !this_ONLINE && next_ONLINE) {              // this: DEFAULT + next:ON-LINE
3412                              
3413                              CHECK = true;
3414    
3415                      }else if( !next_ONLINE ){                                             // this:ANY + next:DEFAULT
3416                              
3417                              assignVALIDATION(next_run->ID,true);
3418                              nseq=0;
3419                      }
3420              }
3421    
3422              //----------------------------
3423              //check run sequence for calib
3424              //----------------------------
3425              if( CHECK ){
3426                      // check if calibration exists
3427                      if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval);
3428                      Bool_t MISSING = MissingTRK_CALIB(t1,t2);
3429                      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);
3430                      nseq=0;
3431              };
3432              //--------------
3433              //store run info
3434              //--------------
3435              *next_run   = *this_run;
3436              next_ONLINE = this_ONLINE;
3437              if( !this_BAD ){
3438                      if(nseq < nseq_max){
3439                              sequence[nseq] = this_run->ID;
3440                              nseq++;
3441                      }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max);
3442              };
3443              
3444              if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID);
3445              nrow++;
3446              
3447      };
3448      delete this_run;
3449      delete next_run;
3450    //    //
3451    return(0);    return(0);
3452  };  };
3453    /**
3454     * Check if there might be a missing tracker calibration in a given time interval
3455     * @param t1 From absolute time
3456     * @param t2 To absolute time
3457     * @return true if there might be a missing calibration
3458     */
3459    Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){
3460            
3461            GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB();
3462            
3463            // get the closest VALIDATED calibration before the run start (t2)
3464            if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true);      //>>> missing
3465            
3466            if ( trkcalib->TO_TIME  < t2 ) return(true);                                    //>>> missing
3467            
3468            //==============================================================
3469            // Check is done first on the basis of time between calibration,
3470            // which should be equal to the time between ascending-nodes.
3471            //==============================================================
3472            if ( t2 - trkcalib->FROM_TIME > 5700) {
3473                    if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME);
3474            //==============================================================
3475            // there might be a missing calibration, due to:
3476            // - MM full
3477            // - corrupted packets
3478            // - loss of data
3479            // There is an exception in case a download was done during ascending node
3480            //==============================================================
3481                    Bool_t DOWNLOAD = false;
3482                    // check if the calib was skipped becouse of download .... DA FARE!!
3483                    if(DOWNLOAD)return(false);
3484                    
3485                    return(true);                                   //>>> missing
3486                    
3487            };
3488            
3489            //==============================================================
3490            // If the last calibration is close to the run less than this time,
3491            // it is enough to say that there are no missing calibrations
3492            //==============================================================
3493            // the long time interval bewteen runs might be due to download
3494            if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME);
3495            return(false);
3496            
3497    };
3498    /**
3499     * Assign VALIDATION value to a GL_RUN entry
3500     * @param idrun Run ID
3501     * @param validation true/false
3502     */
3503    Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){
3504            TSQLResult *result = 0;
3505            stringstream oss;
3506            oss.str("");
3507            oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";";
3508            //
3509    //      if ( IsDebug() )
3510    //      printf(" Set VALIDATION = %i for run %i \n",validation,idrun);
3511            if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str());
3512            result = conn->Query(oss.str().c_str());
3513            if ( !result ) throw -4;
3514            return(0);
3515    }
3516    
3517    
3518    

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

  ViewVC Help
Powered by ViewVC 1.1.23