/[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.10 by mocchiut, Tue Sep 12 08:43:50 2006 UTC
# Line 63  PamelaDBOperations::PamelaDBOperations(T Line 63  PamelaDBOperations::PamelaDBOperations(T
63    SetObt0(obt0);    SetObt0(obt0);
64    //    //
65    //    //
66    SetRootName(filerootname);    INSERT_RAW =!filerawname.IsNull();
67    SetRawName(filerawname);    if(INSERT_RAW)SetRawName(filerawname);
68    //    //
69    this->OpenFile();    INSERT_ROOT = !filerootname.IsNull();
70      if( INSERT_ROOT ){
71        this->SetRootName(filerootname);
72        file = TFile::Open(this->GetRootName().Data());
73      };
74    //    //
75    this->SetID_RAW(0);    this->SetID_RAW(0);
76    this->SetID_ROOT(0);    this->SetID_ROOT(0);
77    
78      VALIDATE = false;
79      
80    //    //
81  };  };
82    
# Line 78  PamelaDBOperations::PamelaDBOperations(T Line 85  PamelaDBOperations::PamelaDBOperations(T
85   */   */
86  void PamelaDBOperations::Close(){  void PamelaDBOperations::Close(){
87    if( conn && conn->IsConnected() ) conn->Close();    if( conn && conn->IsConnected() ) conn->Close();
88      delete clean_time;
89    delete glrun;    delete glrun;
90    delete this;    delete this;
91  };  };
# Line 86  void PamelaDBOperations::Close(){ Line 94  void PamelaDBOperations::Close(){
94  // SETTERS  // SETTERS
95  //  //
96    
97    //
98    // must be out of the constructor in order to FORCE the validation of the latest runs in case you run the validation together with the latest file
99    //
100    void PamelaDBOperations::CheckValidate(Long64_t olderthan){
101      clean_time = new TDatime();
102      if(olderthan >= 0){
103        VALIDATE = true;
104        UInt_t timelim = 0;
105        timelim =  (UInt_t)clean_time->Convert() - olderthan;
106        clean_time->Set(timelim,false);
107      };
108    };
109    
110  /**  /**
111   * Open the DB connection   * Open the DB connection
112   * @param host         hostname for the SQL connection.   * @param host         hostname for the SQL connection.
# Line 172  void PamelaDBOperations::SetNOBOOT(Bool_ Line 193  void PamelaDBOperations::SetNOBOOT(Bool_
193   * Store the olderthan variable   * Store the olderthan variable
194   * @param olderthan   * @param olderthan
195   */   */
196  void PamelaDBOperations::SetOlderThan(Long64_t oldthan){  // void PamelaDBOperations::SetOlderThan(Long64_t oldthan){
197    olderthan = oldthan;  //   olderthan = oldthan;
198  };  // };
199    
200  /**  /**
201   * Retrieve the ID_RAW, if exists, returns NULL if does not exist.   * Retrieve the ID_RAW, if exists, returns NULL if does not exist.
# Line 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 2987  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3191  Int_t PamelaDBOperations::CleanGL_RUN_FR
3191    TSQLRow    *row2   = 0;    TSQLRow    *row2   = 0;
3192    //    //
3193    UInt_t moved = 0;    UInt_t moved = 0;
3194    UInt_t timelim = 0;  //  UInt_t timelim = 0;
3195    TDatime *time = new TDatime();  //  TDatime *time = new TDatime();
3196    //    //
3197    stringstream oss;    stringstream oss;
3198    oss.str("");    oss.str("");
3199    //    //
3200    //    //
   //  
   if ( olderthan < 0 ){  
     if ( IsDebug() ) printf(" Do not clean GL_RUN_FRAGMENTS table \n");  
     return(1);  
   };  
   //  
   // timelim = now - olderthan  
   //  
   time->Set();  
   timelim =  (UInt_t)time->Convert() - olderthan;  
   time->Set(timelim,false);  
   //  
3201    // check if there are entries older than "olderthan" seconds from now    // check if there are entries older than "olderthan" seconds from now
3202    //    //
3203    oss.str("");    oss.str("");
3204    oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"    oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"
3205        << " INSERT_TIME <= '" << time->AsSQLString() << "';";        << " INSERT_TIME <= '" << clean_time->AsSQLString() << "';";
3206    //    //
3207    if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str());    if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str());
3208    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
3209    //    //
3210    if ( result ){    if ( result ){
# Line 3108  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3300  Int_t PamelaDBOperations::CleanGL_RUN_FR
3300  Int_t PamelaDBOperations::ValidateRuns(){  Int_t PamelaDBOperations::ValidateRuns(){
3301    //    //
3302    TSQLResult *result = 0;    TSQLResult *result = 0;
3303    // TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
   //  
   UInt_t timelim = 0;  
   TDatime *time = new TDatime();  
3304    //    //
3305    stringstream oss;    stringstream oss;
3306    oss.str("");    oss.str("");
3307    //    //
3308    //    // =======================================================
3309    //    // validate runs by checking missing calibrations
3310    if ( olderthan < 0 ){    // =======================================================
3311      if ( IsDebug() ) printf(" Do not validate runs \n");    UInt_t t_stop  = 0;
3312      return(1);    UInt_t t_start = 0;
3313      // --------------------------------------------------------------
3314      // 1) get the OBT of the last run inserted after clean-time limit
3315      // --------------------------------------------------------------
3316      oss.str("");
3317      oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << clean_time->AsSQLString()
3318              << "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3319      if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str());
3320      result = conn->Query(oss.str().c_str());
3321      if ( !result ) throw -4;
3322      if ( !result->GetRowCount() ) {
3323              printf(" No runs to validate \n");
3324              return(1);
3325      }else{
3326            row = result->Next();
3327            t_start = (UInt_t)atoll(row->GetField(4));
3328      };  
3329      // --------------------------------------------------------------
3330      // 2) get the OBT of the last validated run
3331      // --------------------------------------------------------------
3332      oss.str("");
3333      oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start
3334          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3335      if ( IsDebug() ) printf(" Get stop 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              row = result->Next();
3340              t_stop = (UInt_t)atoll(row->GetField(4));
3341    };    };
3342    //    if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start);
3343    // timelim = now - olderthan    // --------------------------------------------------------------
3344    //    // now retrieves runs to be validated
3345    time->Set();    // --------------------------------------------------------------
3346    timelim =  (UInt_t)time->Convert() - olderthan;    oss.str("");
3347    time->Set(timelim,false);    oss << " SELECT * FROM GL_RUN  WHERE  RUNHEADER_TIME <=" << t_start;
3348    //    oss << " AND RUNHEADER_TIME >="<< t_stop;
3349    // First of all validate runs with default calibration:    oss << " ORDER BY RUNHEADER_TIME DESC;";
3350    //  //  if ( IsDebug() )
3351    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());  
3352    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
   //  
3353    if ( !result ) throw -4;    if ( !result ) throw -4;
3354      if ( !result->GetRowCount() ) printf(" No runs to validate \n");
3355    //  printf("------------------------------------------------------------------------------- \n");
3356      
3357      Int_t nrow = 0;
3358      GL_RUN* this_run = new GL_RUN();
3359      GL_RUN* next_run = new GL_RUN();
3360      Int_t   nseq_max = 1000;
3361    //  UInt_t* sequence = new UInt_t[100];
3362      vector<UInt_t> sequence(nseq_max);
3363      Int_t   nseq = 0;
3364      Bool_t CHECK = false;
3365      Bool_t this_ONLINE = false;
3366      Bool_t next_ONLINE = false;
3367      UInt_t t1=0,t2=0;
3368      // ---------------------------------------------------------------------------------
3369      // - loop over runs, back in time,
3370      // - select sequences of runs close in time (less than 60 s apart),
3371      //   which could be preceeded by a calibration
3372      // - check if there might be a missing calibration
3373      // ---------------------------------------------------------------------------------
3374      while(1){
3375              
3376              row = result->Next();
3377              if( row == NULL ) break;
3378              
3379              //------------
3380              //get run info
3381              //------------
3382              this_run->Set_GL_RUN(row);
3383                      
3384              Bool_t this_BAD = false;
3385              if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true;
3386              else if (this_run->GetTRK_CALIB_USED() == 104)                          this_ONLINE = false;
3387              else{
3388    //                printf("Missing or corrupted header!! \n");
3389                      this_ONLINE = false;
3390                      this_BAD = true;
3391              };
3392    
3393              //-----------------------------------
3394              //compare with previous(next in time)
3395              //-----------------------------------
3396              CHECK = false;
3397              UInt_t interval=0;
3398              
3399              if( nrow != 0){
3400            
3401                      
3402                      t1 = this_run->GetRUNTRAILER_TIME();
3403                      t2 = next_run->GetRUNHEADER_TIME();
3404                      interval = (t2-t1);
3405                      
3406                      if(this_ONLINE && next_ONLINE){                               // this: ON-LINE + next: ON-LINE
3407                              
3408                              if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0;     //=> run fragments
3409                              
3410                              if( interval >= 60 )CHECK = true;                     //more than 60 s => there might be a calibration
3411                              
3412                              if( !CHECK && this_run->VALIDATION ){
3413                                      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
3414                                      nseq=0;
3415                              }
3416                      
3417                      }else if( !this_ONLINE && next_ONLINE) {              // this: DEFAULT + next:ON-LINE
3418                              
3419                              CHECK = true;
3420    
3421                      }else if( !next_ONLINE ){                                             // this:ANY + next:DEFAULT
3422                              
3423                              assignVALIDATION(next_run->ID,true);
3424                              nseq=0;
3425                      }
3426              }
3427    
3428              //----------------------------
3429              //check run sequence for calib
3430              //----------------------------
3431              if( CHECK ){
3432                      // check if calibration exists
3433                      if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval);
3434                      Bool_t MISSING = MissingTRK_CALIB(t1,t2);
3435                      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);
3436                      nseq=0;
3437              };
3438              //--------------
3439              //store run info
3440              //--------------
3441              *next_run   = *this_run;
3442              next_ONLINE = this_ONLINE;
3443              if( !this_BAD ){
3444                      if(nseq < nseq_max){
3445                              sequence[nseq] = this_run->ID;
3446                              nseq++;
3447                      }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max);
3448              };
3449              
3450              if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID);
3451              nrow++;
3452              
3453      };
3454      delete this_run;
3455      delete next_run;
3456    //    //
3457    return(0);    return(0);
3458  };  };
3459    /**
3460     * Check if there might be a missing tracker calibration in a given time interval
3461     * @param t1 From absolute time
3462     * @param t2 To absolute time
3463     * @return true if there might be a missing calibration
3464     */
3465    Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){
3466            
3467            GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB();
3468            
3469            // get the closest VALIDATED calibration before the run start (t2)
3470            if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true);      //>>> missing
3471            
3472            if ( trkcalib->TO_TIME  < t2 ) return(true);                                    //>>> missing
3473            
3474            //==============================================================
3475            // Check is done first on the basis of time between calibration,
3476            // which should be equal to the time between ascending-nodes.
3477            //==============================================================
3478            if ( t2 - trkcalib->FROM_TIME > 5700) {
3479                    if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME);
3480            //==============================================================
3481            // there might be a missing calibration, due to:
3482            // - MM full
3483            // - corrupted packets
3484            // - loss of data
3485            // There is an exception in case a download was done during ascending node
3486            //==============================================================
3487                    Bool_t DOWNLOAD = false;
3488                    // check if the calib was skipped becouse of download .... DA FARE!!
3489                    if(DOWNLOAD)return(false);
3490                    
3491                    return(true);                                   //>>> missing
3492                    
3493            };
3494            
3495            //==============================================================
3496            // If the last calibration is close to the run less than this time,
3497            // it is enough to say that there are no missing calibrations
3498            //==============================================================
3499            // the long time interval bewteen runs might be due to download
3500            if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME);
3501            return(false);
3502            
3503    };
3504    /**
3505     * Assign VALIDATION value to a GL_RUN entry
3506     * @param idrun Run ID
3507     * @param validation true/false
3508     */
3509    Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){
3510            TSQLResult *result = 0;
3511            stringstream oss;
3512            oss.str("");
3513            oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";";
3514            //
3515    //      if ( IsDebug() )
3516    //      printf(" Set VALIDATION = %i for run %i \n",validation,idrun);
3517            if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str());
3518            result = conn->Query(oss.str().c_str());
3519            if ( !result ) throw -4;
3520            return(0);
3521    }
3522    
3523    
3524    

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

  ViewVC Help
Powered by ViewVC 1.1.23