/[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.3 by mocchiut, Tue Sep 5 10:48:58 2006 UTC revision 1.11 by mocchiut, Wed Sep 13 08:34:01 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 223  Int_t PamelaDBOperations::SetUpperLimits Line 244  Int_t PamelaDBOperations::SetUpperLimits
244    ULong64_t upperobt2 = 0;    ULong64_t upperobt2 = 0;
245    UInt_t zomp = 0;    UInt_t zomp = 0;
246    UInt_t jump = 50000; // was 5000    UInt_t jump = 50000; // was 5000
247      EventCounter *code=0;
248      //
249      //   pcksList packetsNames;
250      //   pcksList::iterator Iter;
251      //   getPacketsNames(packetsNames);
252    //    //
253    pktfirst = 0;    pktfirst = 0;
254    obtfirst = 0;    obtfirst = 0;
# Line 240  Int_t PamelaDBOperations::SetUpperLimits Line 266  Int_t PamelaDBOperations::SetUpperLimits
266    pktfirst = ph->GetCounter();    pktfirst = ph->GetCounter();
267    obtfirst = ph->GetOrbitalTime();      obtfirst = ph->GetOrbitalTime();  
268    //    //
269      //   code = eh->GetCounter();
270      //   UInt_t en = 0;
271      //   for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){
272      //     en = code->Get(GetPacketType(*Iter));
273      //     if ( en ) printf(" Packet type is %s, entries: %i \n",*Iter,en);
274      //};  
275      //
276    T->GetEntry(nevent-1);    T->GetEntry(nevent-1);
277    ph = eh->GetPscuHeader();    ph = eh->GetPscuHeader();
278    pktlast = ph->GetCounter();    pktlast = ph->GetCounter();
# Line 308  Int_t PamelaDBOperations::SetUpperLimits Line 341  Int_t PamelaDBOperations::SetUpperLimits
341    // 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)
342    //    //
343    PacketType *pctp=0;    PacketType *pctp=0;
   EventCounter *code=0;  
   T->GetEntry(upperentry);  
   code = eh->GetCounter();  
   Int_t lasttrail = code->Get(pctp->RunTrailer);  
   Int_t lasthead = code->Get(pctp->RunHeader);  
344    TTree *rh=(TTree*)file->Get("RunHeader");    TTree *rh=(TTree*)file->Get("RunHeader");
345    if ( !rh || rh->IsZombie() ) throw -17;    if ( !rh || rh->IsZombie() ) throw -17;
346    TTree *rt=(TTree*)file->Get("RunTrailer");    TTree *rt=(TTree*)file->Get("RunTrailer");
# Line 326  Int_t PamelaDBOperations::SetUpperLimits Line 354  Int_t PamelaDBOperations::SetUpperLimits
354    //    //
355    rhev = rh->GetEntries();    rhev = rh->GetEntries();
356    rtev = rt->GetEntries();    rtev = rt->GetEntries();
357      UInt_t sobtt = 0;
358      UInt_t sobth = 0;
359      UInt_t spktt = 0;
360      UInt_t spkth = 0;
361    UInt_t pktt = 0;    UInt_t pktt = 0;
362    ULong64_t obtt = 0;    ULong64_t obtt = 0;
363    UInt_t pkth = 0;    UInt_t pkth = 0;
364    ULong64_t obth = 0;    ULong64_t obth = 0;
365    //    //
366      T->GetEntry(upperentry);
367      code = eh->GetCounter();
368      Int_t lasttrail = code->Get(pctp->RunTrailer);
369      Int_t lasthead = code->Get(pctp->RunHeader);
370    if ( lasttrail < rtev ){    if ( lasttrail < rtev ){
371      rt->GetEntry(lasttrail);      rt->GetEntry(lasttrail);
372      pht = eht->GetPscuHeader();      pht = eht->GetPscuHeader();
# Line 338  Int_t PamelaDBOperations::SetUpperLimits Line 374  Int_t PamelaDBOperations::SetUpperLimits
374      obtt = OBT(pht->GetOrbitalTime());      obtt = OBT(pht->GetOrbitalTime());
375    };    };
376    //    //
377      if ( lasthead < rhev ){
378        rh->GetEntry(lasthead);
379        phh = ehh->GetPscuHeader();
380        pkth = PKT(phh->GetCounter());
381        obth = OBT(phh->GetOrbitalTime());
382      };
383      //
384      if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
385      if ( pkth > upperpkt && obth > upperobt ){
386        if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt);
387        upperpkt = pkth;
388        upperobt = obth;
389        rhev = lasthead+1;
390      } else {
391        rhev = lasthead;
392      };
393      if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
394      //
395    if ( IsDebug() ) printf(" rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);    if ( IsDebug() ) printf(" rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
396    if ( pktt > upperpkt && obtt > upperobt ){    if ( pktt > upperpkt && obtt > upperobt ){
397      if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt);      if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt);
# Line 348  Int_t PamelaDBOperations::SetUpperLimits Line 402  Int_t PamelaDBOperations::SetUpperLimits
402      rtev = lasttrail;      rtev = lasttrail;
403    };    };
404    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);
405      //  goto kikko;
406      //
407      //
408      // Check if runtrailer/runheader are within lower limits
409      //
410      //
411      pkth = 0;
412      obth = 0;
413      spkth = 0;
414      sobth = 0;
415      for (Int_t k=0; k<rhev; k++){
416        if ( k > 0 ){
417          spkth = pkth;
418          sobth = obth;
419        };
420        rh->GetEntry(k);
421        phh = ehh->GetPscuHeader();
422        pkth = PKT(phh->GetCounter());
423        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);
426        //
427        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);
429          //
430          rhev = k-1;
431          rh->GetEntry(rhev);
432          pkth = spkth;
433          obth = sobth;
434          //
435          UInt_t evbefh = 0;
436          code = ehh->GetCounter();
437          evbefh = code->Get(pctp->Physics);    
438          if ( evbefh >= 0 ){
439            T->GetEntry(evbefh);
440            ph = eh->GetPscuHeader();
441            t_pktlast = PKT(ph->GetCounter());
442            t_obtlast = OBT(ph->GetOrbitalTime());
443            if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump
444              upperpkt = pkth;
445              upperobt = obth;
446              upperentry = evbefh-1;
447            } else {
448              while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){
449                evbefh++;  
450                T->GetEntry(evbefh);
451                ph = eh->GetPscuHeader();
452                t_pktlast = PKT(ph->GetCounter());
453                t_obtlast = OBT(ph->GetOrbitalTime());
454              };
455              T->GetEntry(evbefh-1);
456              ph = eh->GetPscuHeader();
457              upperpkt = PKT(ph->GetCounter());
458              upperobt = OBT(ph->GetOrbitalTime());
459              upperentry = evbefh-1;
460            };    
461          };
462          if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt);
463          goto kikko0;
464        };
465      };
466     kikko0:
467      //
468      //
469      //
470      pktt = 0;
471      obtt = 0;
472      spktt = 0;
473      sobtt = 0;
474      for (Int_t k=0; k<rtev; k++){
475        if ( k > 0 ){
476          spktt = pktt;
477          sobtt = obtt;
478        };
479        rt->GetEntry(k);
480        pht = eht->GetPscuHeader();
481        pktt = PKT(pht->GetCounter());
482        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);
485        //
486        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);
488          //
489          rtev = k-1;
490          rt->GetEntry(rtev);
491          pktt = spktt;
492          obtt = sobtt;
493          if ( IsDebug() ) printf(" lasttrail %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
494          //
495          UInt_t evbeft = 0;
496          code = eht->GetCounter();
497          evbeft = code->Get(pctp->Physics);    
498          if ( evbeft >= 0 ){
499            T->GetEntry(evbeft);
500            ph = eh->GetPscuHeader();
501            t_pktlast = PKT(ph->GetCounter());
502            t_obtlast = OBT(ph->GetOrbitalTime());
503            if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump
504              upperpkt = pktt;
505              upperobt = obtt;
506              upperentry = evbeft-1;
507            } else {
508              while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){
509                evbeft++;  
510                T->GetEntry(evbeft);
511                ph = eh->GetPscuHeader();
512                t_pktlast = PKT(ph->GetCounter());
513                t_obtlast = OBT(ph->GetOrbitalTime());
514              };
515              T->GetEntry(evbeft-1);
516              ph = eh->GetPscuHeader();
517              upperpkt = PKT(ph->GetCounter());
518              upperobt = OBT(ph->GetOrbitalTime());
519              upperentry = evbeft-1;
520            };
521          };
522          if ( IsDebug() ) printf(" rtev after %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
523          goto kikko;
524          //      break;
525          //
526        };
527        //  
528      };
529      //
530     kikko:
531      //
532      T->GetEntry(upperentry);
533      code = eh->GetCounter();
534      lasttrail = code->Get(pctp->RunTrailer);
535      lasthead = code->Get(pctp->RunHeader);
536      if ( lasttrail < rtev ){
537        rt->GetEntry(lasttrail);
538        pht = eht->GetPscuHeader();
539        pktt = PKT(pht->GetCounter());
540        obtt = OBT(pht->GetOrbitalTime());
541      };
542    //    //
543    if ( lasthead < rhev ){    if ( lasthead < rhev ){
544      rh->GetEntry(lasthead);      rh->GetEntry(lasthead);
545      phh = ehh->GetPscuHeader();      phh = ehh->GetPscuHeader();
546      pkth = PKT(pht->GetCounter());      pkth = PKT(phh->GetCounter());
547      obth = OBT(pht->GetOrbitalTime());      obth = OBT(phh->GetOrbitalTime());
548    };    };
549    //    //
550    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 367  Int_t PamelaDBOperations::SetUpperLimits Line 558  Int_t PamelaDBOperations::SetUpperLimits
558    };    };
559    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);
560    //    //
561      if ( IsDebug() ) printf(" rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
562      if ( pktt > upperpkt && obtt > upperobt ){
563        if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt);
564        upperpkt = pktt;
565        upperobt = obtt;
566        rtev = lasttrail+1;
567      } else {
568        rtev = lasttrail;
569      };
570      if ( IsDebug() ) printf(" rtev after %i  pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);
571      //
572    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);
573    //    //
574    return(0);    return(0);
# Line 447  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 727  Int_t PamelaDBOperations::insertPamelaGL Line 931  Int_t PamelaDBOperations::insertPamelaGL
931          //          //
932          TYPE = 55;//224;          TYPE = 55;//224;
933          //          //
934            if ( IsDebug() ) printf("mcmd tsync %i tsync %u obt %u \n",i,TSYNC,OBT);
935            //
936          if ( TSYNC && OBT ){          if ( TSYNC && OBT ){
937            existsts = true;            existsts = true;
938            goto eout;            goto eout;
# Line 749  Int_t PamelaDBOperations::insertPamelaGL Line 955  Int_t PamelaDBOperations::insertPamelaGL
955      //      //
956      rt->SetBranchAddress("RunTrailer", &runt);      rt->SetBranchAddress("RunTrailer", &runt);
957      //      //
958      if ( rhev > 0 ){      Int_t nrhev = rh->GetEntries();
959        rh->GetEntry(0);      Int_t nrtev = rt->GetEntries();
960        //      if ( IsDebug() ) printf(" ou nevent %i rhev %i rtev %i \n",nevent,nrhev,nrtev);
961        TSYNC = runh->LAST_TIME_SYNC_INFO;      //
962        OBT = runh->OBT_TIME_SYNC * 1000;      if ( nrhev > 0 ){
963        //        for (Int_t i=0; i<nrhev; i++){
964        TYPE = 20;          //
965        //          rh->GetEntry(i);
966        if ( TSYNC && OBT ){          //
967          existsts = true;          TSYNC = runh->LAST_TIME_SYNC_INFO;
968          goto eout;          OBT = runh->OBT_TIME_SYNC * 1000;
969            //
970            TYPE = 20;
971            //
972            if ( IsDebug() ) printf("runheader %i tsync %u obt %u \n",i,TSYNC,OBT);
973            //
974            if ( TSYNC && OBT ){
975              existsts = true;
976              goto eout;
977            };
978        };        };
979        //        //
980      };      };
981      if ( rtev > 0 ){      if ( nrtev > 0 ){
982        //        //
983        if ( IsDebug() ) printf(" No runheader \n");        if ( IsDebug() ) printf(" No runheader \n");
984        signal = 6;        signal = 6;
985        //        //
986        rt->GetEntry(0);        for (Int_t i=0; i<nrtev; i++){
987        //          //
988        TSYNC = runt->LAST_TYME_SYNC_INFO;          rt->GetEntry(i);
989        OBT = runt->OBT_TYME_SYNC * 1000;          //
990        //          TSYNC = runt->LAST_TYME_SYNC_INFO;
991        TYPE = 21;          OBT = runt->OBT_TYME_SYNC * 1000;
992        //          //
993        if ( TSYNC && OBT ){          TYPE = 21;
994          existsts = true;          //
995          goto eout;          if ( IsDebug() ) printf("runtrailer %i tsync %u obt %u \n",i,TSYNC,OBT);
996            //
997            if ( TSYNC && OBT ){
998              existsts = true;
999              goto eout;
1000            };
1001        };        };
1002        //        //
1003      } else {      } else {
# Line 2987  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3207  Int_t PamelaDBOperations::CleanGL_RUN_FR
3207    TSQLRow    *row2   = 0;    TSQLRow    *row2   = 0;
3208    //    //
3209    UInt_t moved = 0;    UInt_t moved = 0;
3210    UInt_t timelim = 0;  //  UInt_t timelim = 0;
3211    TDatime *time = new TDatime();  //  TDatime *time = new TDatime();
3212    //    //
3213    stringstream oss;    stringstream oss;
3214    oss.str("");    oss.str("");
3215    //    //
3216    //    //
   //  
   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);  
   //  
3217    // check if there are entries older than "olderthan" seconds from now    // check if there are entries older than "olderthan" seconds from now
3218    //    //
3219    oss.str("");    oss.str("");
3220    oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"    oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"
3221        << " INSERT_TIME <= '" << time->AsSQLString() << "';";        << " INSERT_TIME <= '" << clean_time->AsSQLString() << "';";
3222    //    //
3223    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());
3224    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
3225    //    //
3226    if ( result ){    if ( result ){
# Line 3108  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3316  Int_t PamelaDBOperations::CleanGL_RUN_FR
3316  Int_t PamelaDBOperations::ValidateRuns(){  Int_t PamelaDBOperations::ValidateRuns(){
3317    //    //
3318    TSQLResult *result = 0;    TSQLResult *result = 0;
3319    // TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
   //  
   UInt_t timelim = 0;  
   TDatime *time = new TDatime();  
3320    //    //
3321    stringstream oss;    stringstream oss;
3322    oss.str("");    oss.str("");
3323    //    //
3324    //    // =======================================================
3325    //    // validate runs by checking missing calibrations
3326    if ( olderthan < 0 ){    // =======================================================
3327      if ( IsDebug() ) printf(" Do not validate runs \n");    UInt_t t_stop  = 0;
3328      return(1);    UInt_t t_start = 0;
3329      // --------------------------------------------------------------
3330      // 1) get the OBT of the last run inserted after clean-time limit
3331      // --------------------------------------------------------------
3332      oss.str("");
3333      oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << clean_time->AsSQLString()
3334              << "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3335      if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str());
3336      result = conn->Query(oss.str().c_str());
3337      if ( !result ) throw -4;
3338      if ( !result->GetRowCount() ) {
3339              printf(" No runs to validate \n");
3340              return(1);
3341      }else{
3342            row = result->Next();
3343            t_start = (UInt_t)atoll(row->GetField(4));
3344      };  
3345      // --------------------------------------------------------------
3346      // 2) get the OBT of the last validated run
3347      // --------------------------------------------------------------
3348      oss.str("");
3349      oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start
3350          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3351      if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());
3352      result = conn->Query(oss.str().c_str());
3353      if ( !result ) throw -4;
3354      if ( result->GetRowCount() ){
3355              row = result->Next();
3356              t_stop = (UInt_t)atoll(row->GetField(4));
3357    };    };
3358    //    if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start);
3359    // timelim = now - olderthan    // --------------------------------------------------------------
3360    //    // now retrieves runs to be validated
3361    time->Set();    // --------------------------------------------------------------
3362    timelim =  (UInt_t)time->Convert() - olderthan;    oss.str("");
3363    time->Set(timelim,false);    oss << " SELECT * FROM GL_RUN  WHERE  RUNHEADER_TIME <=" << t_start;
3364    //    oss << " AND RUNHEADER_TIME >="<< t_stop;
3365    // First of all validate runs with default calibration:    oss << " ORDER BY RUNHEADER_TIME DESC;";
3366    //  //  if ( IsDebug() )
3367    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());  
3368    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
   //  
3369    if ( !result ) throw -4;    if ( !result ) throw -4;
3370      if ( !result->GetRowCount() ) printf(" No runs to validate \n");
3371    //  printf("------------------------------------------------------------------------------- \n");
3372      
3373      Int_t nrow = 0;
3374      GL_RUN* this_run = new GL_RUN();
3375      GL_RUN* next_run = new GL_RUN();
3376      Int_t   nseq_max = 1000;
3377    //  UInt_t* sequence = new UInt_t[100];
3378      vector<UInt_t> sequence(nseq_max);
3379      Int_t   nseq = 0;
3380      Bool_t CHECK = false;
3381      Bool_t this_ONLINE = false;
3382      Bool_t next_ONLINE = false;
3383      UInt_t t1=0,t2=0;
3384      // ---------------------------------------------------------------------------------
3385      // - loop over runs, back in time,
3386      // - select sequences of runs close in time (less than 60 s apart),
3387      //   which could be preceeded by a calibration
3388      // - check if there might be a missing calibration
3389      // ---------------------------------------------------------------------------------
3390      while(1){
3391              
3392              row = result->Next();
3393              if( row == NULL ) break;
3394              
3395              //------------
3396              //get run info
3397              //------------
3398              this_run->Set_GL_RUN(row);
3399                      
3400              Bool_t this_BAD = false;
3401              if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true;
3402              else if (this_run->GetTRK_CALIB_USED() == 104)                          this_ONLINE = false;
3403              else{
3404    //                printf("Missing or corrupted header!! \n");
3405                      this_ONLINE = false;
3406                      this_BAD = true;
3407              };
3408    
3409              //-----------------------------------
3410              //compare with previous(next in time)
3411              //-----------------------------------
3412              CHECK = false;
3413              UInt_t interval=0;
3414              
3415              if( nrow != 0){
3416            
3417                      
3418                      t1 = this_run->GetRUNTRAILER_TIME();
3419                      t2 = next_run->GetRUNHEADER_TIME();
3420                      interval = (t2-t1);
3421                      
3422                      if(this_ONLINE && next_ONLINE){                               // this: ON-LINE + next: ON-LINE
3423                              
3424                              if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0;     //=> run fragments
3425                              
3426                              if( interval >= 60 )CHECK = true;                     //more than 60 s => there might be a calibration
3427                              
3428                              if( !CHECK && this_run->VALIDATION ){
3429                                      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
3430                                      nseq=0;
3431                              }
3432                      
3433                      }else if( !this_ONLINE && next_ONLINE) {              // this: DEFAULT + next:ON-LINE
3434                              
3435                              CHECK = true;
3436    
3437                      }else if( !next_ONLINE ){                                             // this:ANY + next:DEFAULT
3438                              
3439                              assignVALIDATION(next_run->ID,true);
3440                              nseq=0;
3441                      }
3442              }
3443    
3444              //----------------------------
3445              //check run sequence for calib
3446              //----------------------------
3447              if( CHECK ){
3448                      // check if calibration exists
3449                      if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval);
3450                      Bool_t MISSING = MissingTRK_CALIB(t1,t2);
3451                      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);
3452                      nseq=0;
3453              };
3454              //--------------
3455              //store run info
3456              //--------------
3457              *next_run   = *this_run;
3458              next_ONLINE = this_ONLINE;
3459              if( !this_BAD ){
3460                      if(nseq < nseq_max){
3461                              sequence[nseq] = this_run->ID;
3462                              nseq++;
3463                      }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max);
3464              };
3465              
3466              if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID);
3467              nrow++;
3468              
3469      };
3470      delete this_run;
3471      delete next_run;
3472    //    //
3473    return(0);    return(0);
3474  };  };
3475    /**
3476     * Check if there might be a missing tracker calibration in a given time interval
3477     * @param t1 From absolute time
3478     * @param t2 To absolute time
3479     * @return true if there might be a missing calibration
3480     */
3481    Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){
3482            
3483            GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB();
3484            
3485            // get the closest VALIDATED calibration before the run start (t2)
3486            if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true);      //>>> missing
3487            
3488            if ( trkcalib->TO_TIME  < t2 ) return(true);                                    //>>> missing
3489            
3490            //==============================================================
3491            // Check is done first on the basis of time between calibration,
3492            // which should be equal to the time between ascending-nodes.
3493            //==============================================================
3494            if ( t2 - trkcalib->FROM_TIME > 5700) {
3495                    if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME);
3496            //==============================================================
3497            // there might be a missing calibration, due to:
3498            // - MM full
3499            // - corrupted packets
3500            // - loss of data
3501            // There is an exception in case a download was done during ascending node
3502            //==============================================================
3503                    Bool_t DOWNLOAD = false;
3504                    // check if the calib was skipped becouse of download .... DA FARE!!
3505                    if(DOWNLOAD)return(false);
3506                    
3507                    return(true);                                   //>>> missing
3508                    
3509            };
3510            
3511            //==============================================================
3512            // If the last calibration is close to the run less than this time,
3513            // it is enough to say that there are no missing calibrations
3514            //==============================================================
3515            // the long time interval bewteen runs might be due to download
3516            if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME);
3517            return(false);
3518            
3519    };
3520    /**
3521     * Assign VALIDATION value to a GL_RUN entry
3522     * @param idrun Run ID
3523     * @param validation true/false
3524     */
3525    Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){
3526            TSQLResult *result = 0;
3527            stringstream oss;
3528            oss.str("");
3529            oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";";
3530            //
3531    //      if ( IsDebug() )
3532    //      printf(" Set VALIDATION = %i for run %i \n",validation,idrun);
3533            if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str());
3534            result = conn->Query(oss.str().c_str());
3535            if ( !result ) throw -4;
3536            return(0);
3537    }
3538    
3539    
3540    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.23