/[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.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 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);  //    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 ){
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);
# 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 460  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);  //    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 ){
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);
# Line 479  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 628  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 3168  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 3291  Int_t PamelaDBOperations::ValidateRuns() Line 3296  Int_t PamelaDBOperations::ValidateRuns()
3296    TSQLResult *result = 0;    TSQLResult *result = 0;
3297    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
3298    //    //
   UInt_t timelim = 0;  
   TDatime *time = new TDatime();  
   //  
3299    stringstream oss;    stringstream oss;
3300    oss.str("");    oss.str("");
3301    //    //
   //  
   //  
   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());  
   
3302    // =======================================================    // =======================================================
3303    // validate runs by checking missing calibrations    // validate runs by checking missing calibrations
3304    // =======================================================    // =======================================================
# Line 3321  Int_t PamelaDBOperations::ValidateRuns() Line 3308  Int_t PamelaDBOperations::ValidateRuns()
3308    // 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
3309    // --------------------------------------------------------------    // --------------------------------------------------------------
3310    oss.str("");    oss.str("");
3311    oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << time->AsSQLString()    oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << clean_time->AsSQLString()
3312        << "' ORDER BY INSERT_TIME DESC LIMIT 1;";            << "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3313    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());
3314    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
3315    if ( !result ) throw -4;    if ( !result ) throw -4;
3316    if ( !result->GetRowCount() ) {    if ( !result->GetRowCount() ) {
# Line 3332  Int_t PamelaDBOperations::ValidateRuns() Line 3319  Int_t PamelaDBOperations::ValidateRuns()
3319    }else{    }else{
3320          row = result->Next();          row = result->Next();
3321          t_start = (UInt_t)atoll(row->GetField(4));          t_start = (UInt_t)atoll(row->GetField(4));
         printf("t_start %i\n",t_start);  
3322    };      };  
3323    // --------------------------------------------------------------    // --------------------------------------------------------------
3324    // 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 3326  Int_t PamelaDBOperations::ValidateRuns()
3326    oss.str("");    oss.str("");
3327    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
3328        <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";        <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3329    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());
3330    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
3331    if ( !result ) throw -4;    if ( !result ) throw -4;
3332    if ( result->GetRowCount() ){    if ( result->GetRowCount() ){
3333            row = result->Next();            row = result->Next();
3334            t_stop = (UInt_t)atoll(row->GetField(4));            t_stop = (UInt_t)atoll(row->GetField(4));
3335    };    };
3336    printf("t_stop %i\n",t_stop);    if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start);
3337    // --------------------------------------------------------------    // --------------------------------------------------------------
3338    // now retrieves runs to be validated    // now retrieves runs to be validated
3339    // --------------------------------------------------------------    // --------------------------------------------------------------
# Line 3356  Int_t PamelaDBOperations::ValidateRuns() Line 3342  Int_t PamelaDBOperations::ValidateRuns()
3342    oss << " AND RUNHEADER_TIME >="<< t_stop;    oss << " AND RUNHEADER_TIME >="<< t_stop;
3343    oss << " ORDER BY RUNHEADER_TIME DESC;";    oss << " ORDER BY RUNHEADER_TIME DESC;";
3344  //  if ( IsDebug() )  //  if ( IsDebug() )
3345    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());
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");    if ( !result->GetRowCount() ) printf(" No runs to validate \n");
3349    printf("------------------------------------------------------------------------------- \n");  //  printf("------------------------------------------------------------------------------- \n");
3350        
3351    Int_t nrow = 0;    Int_t nrow = 0;
3352    GL_RUN* this_run = new GL_RUN();    GL_RUN* this_run = new GL_RUN();
3353    GL_RUN* next_run = new GL_RUN();    GL_RUN* next_run = new GL_RUN();
3354    Int_t   nseq_max = 100;    Int_t   nseq_max = 1000;
3355  //  UInt_t* sequence = new UInt_t[100];  //  UInt_t* sequence = new UInt_t[100];
3356    vector<UInt_t> sequence(nseq_max);    vector<UInt_t> sequence(nseq_max);
3357    Int_t   nseq = 0;    Int_t   nseq = 0;
# Line 3388  Int_t PamelaDBOperations::ValidateRuns() Line 3374  Int_t PamelaDBOperations::ValidateRuns()
3374            //get run info            //get run info
3375            //------------            //------------
3376            this_run->Set_GL_RUN(row);            this_run->Set_GL_RUN(row);
3377                                
           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);  
             
3378            Bool_t this_BAD = false;            Bool_t this_BAD = false;
3379            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;
3380            else if (this_run->GetTRK_CALIB_USED() == 104)                          this_ONLINE = false;            else if (this_run->GetTRK_CALIB_USED() == 104)                          this_ONLINE = false;
3381            else{            else{
3382                    printf("Missing or corrupted header!! \n");  //                printf("Missing or corrupted header!! \n");
3383                    this_ONLINE = false;                    this_ONLINE = false;
3384                    this_BAD = true;                    this_BAD = true;
3385            };            };
# Line 3419  Int_t PamelaDBOperations::ValidateRuns() Line 3403  Int_t PamelaDBOperations::ValidateRuns()
3403                                                        
3404                            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
3405                                                        
 /*                        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());*/  
                                                     
                             
3406                            if( !CHECK && this_run->VALIDATION ){                            if( !CHECK && this_run->VALIDATION ){
3407                                    for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);                                    for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
3408                                    nseq=0;                                    nseq=0;
# Line 3431  Int_t PamelaDBOperations::ValidateRuns() Line 3411  Int_t PamelaDBOperations::ValidateRuns()
3411                    }else if( !this_ONLINE && next_ONLINE) {              // this: DEFAULT + next:ON-LINE                    }else if( !this_ONLINE && next_ONLINE) {              // this: DEFAULT + next:ON-LINE
3412                                                        
3413                            CHECK = true;                            CHECK = true;
 //                        if( interval < 60 ) printf(" ValidateRuns ***WARNING*** : kkkkkk DT = %i \n",interval);  
3414    
3415                    }else if( !next_ONLINE ){                                             // this:ANY + next:DEFAULT                    }else if( !next_ONLINE ){                                             // this:ANY + next:DEFAULT
3416                                                        
# Line 3445  Int_t PamelaDBOperations::ValidateRuns() Line 3424  Int_t PamelaDBOperations::ValidateRuns()
3424            //----------------------------            //----------------------------
3425            if( CHECK ){            if( CHECK ){
3426                    // check if calibration exists                    // check if calibration exists
3427                    printf("DT %i ===> CHECK Missing calibration\n",interval);                    if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval);
3428                    Bool_t MISSING = MissingTRK_CALIB(t1,t2);                    Bool_t MISSING = MissingTRK_CALIB(t1,t2);
3429                    for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);                    for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);
3430                    nseq=0;                    nseq=0;
3431            } else printf("DT %i\n",interval);            };
3432            //--------------            //--------------
3433            //store run info            //store run info
3434            //--------------            //--------------
# Line 3462  Int_t PamelaDBOperations::ValidateRuns() Line 3441  Int_t PamelaDBOperations::ValidateRuns()
3441                    }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);
3442            };            };
3443                        
3444              if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID);
3445            nrow++;            nrow++;
3446                        
3447    };    };
# Line 3490  Bool_t PamelaDBOperations::MissingTRK_CA Line 3470  Bool_t PamelaDBOperations::MissingTRK_CA
3470          // which should be equal to the time between ascending-nodes.          // which should be equal to the time between ascending-nodes.
3471          //==============================================================          //==============================================================
3472          if ( t2 - trkcalib->FROM_TIME > 5700) {          if ( t2 - trkcalib->FROM_TIME > 5700) {
3473                  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);
3474          //==============================================================          //==============================================================
3475          // there might be a missing calibration, due to:          // there might be a missing calibration, due to:
3476          // - MM full          // - MM full
# Line 3511  Bool_t PamelaDBOperations::MissingTRK_CA Line 3491  Bool_t PamelaDBOperations::MissingTRK_CA
3491          // it is enough to say that there are no missing calibrations          // it is enough to say that there are no missing calibrations
3492          //==============================================================          //==============================================================
3493          // the long time interval bewteen runs might be due to download          // the long time interval bewteen runs might be due to download
3494          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);
3495          return(false);          return(false);
3496                    
3497  };  };
# Line 3524  Int_t PamelaDBOperations::assignVALIDATI Line 3504  Int_t PamelaDBOperations::assignVALIDATI
3504          TSQLResult *result = 0;          TSQLResult *result = 0;
3505          stringstream oss;          stringstream oss;
3506          oss.str("");          oss.str("");
3507          oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << "';";          oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";";
3508          //          //
3509  //      if ( IsDebug() )  //      if ( IsDebug() )
3510          printf(" Set VALIDATION = %i for run %i \n",validation,idrun);  //      printf(" Set VALIDATION = %i for run %i \n",validation,idrun);
3511  //      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());
3512  //      result = conn->Query(oss.str().c_str());          result = conn->Query(oss.str().c_str());
3513  //      if ( !result ) throw -4;          if ( !result ) throw -4;
3514          return(0);          return(0);
3515  }  }
3516    

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

  ViewVC Help
Powered by ViewVC 1.1.23