/[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.15 by mocchiut, Tue Oct 24 14:24:23 2006 UTC revision 1.22 by pam-fi, Wed Nov 29 18:12:02 2006 UTC
# Line 14  Line 14 
14  #include <TSQLRow.h>  #include <TSQLRow.h>
15  #include <TTree.h>  #include <TTree.h>
16  #include <TGraph.h>  #include <TGraph.h>
17  #include <TDatime.h>  #include <TTimeStamp.h>
18  #include <TF1.h>  #include <TF1.h>
19  //  //
20  #include <EventHeader.h>  #include <EventHeader.h>
# Line 81  PamelaDBOperations::PamelaDBOperations(T Line 81  PamelaDBOperations::PamelaDBOperations(T
81      this->SetRootName(filerootname);      this->SetRootName(filerootname);
82      this->SetOrbitNo();      this->SetOrbitNo();
83      file = TFile::Open(this->GetRootName().Data());      file = TFile::Open(this->GetRootName().Data());
84      } else {
85        this->SetRootName("");
86    };    };
87    //    //
88    this->SetID_RAW(0);    this->SetID_RAW(0);
# Line 110  void PamelaDBOperations::Close(){ Line 112  void PamelaDBOperations::Close(){
112  //  //
113  void PamelaDBOperations::CheckValidate(Long64_t olderthan){  void PamelaDBOperations::CheckValidate(Long64_t olderthan){
114    clean_time = new TDatime();    clean_time = new TDatime();
115      //
116    if(olderthan >= 0){    if(olderthan >= 0){
117      VALIDATE = true;      VALIDATE = true;
118      UInt_t timelim = 0;      UInt_t timelim = 0;
119      timelim =  (UInt_t)clean_time->Convert() - olderthan;      timelim =  (UInt_t)clean_time->Convert(true) - olderthan;
120      clean_time->Set(timelim,false);      clean_time->Set(timelim,false);
121    };    };
122  };  };
# Line 154  void PamelaDBOperations::SetDebugFlag(Bo Line 157  void PamelaDBOperations::SetDebugFlag(Bo
157  };  };
158    
159  /**  /**
160     * Set the autoboot flag
161     *
162     */
163    void PamelaDBOperations::SetAutoBoot(Bool_t dbg){
164      AUTOBOOT = dbg;
165    };
166    
167    /**
168     * Set the nofrag flag
169     *
170     */
171    void PamelaDBOperations::SetNoFrag(Bool_t nf){
172      NOFRAG = nf;
173    };
174    
175    /**
176   * Store the BOOT number of the RAW file.   * Store the BOOT number of the RAW file.
177   * @param boot    BOOT number of the RAW file   * @param boot    BOOT number of the RAW file
178   */   */
# Line 284  Int_t PamelaDBOperations::SetUpperLimits Line 303  Int_t PamelaDBOperations::SetUpperLimits
303    UInt_t nevent = 0;    UInt_t nevent = 0;
304    UInt_t pktlast = 0;    UInt_t pktlast = 0;
305    UInt_t obtlast = 0;    UInt_t obtlast = 0;
306    UInt_t t_pktlast = 0;    Long64_t t_pktlast = 0LL;
307    UInt_t t_obtlast = 0;    //  UInt_t t_obtlast = 0;
308    UInt_t upperpkt2 = 0;    Long64_t t_obtlast = 0LL;
309    ULong64_t upperobt2 = 0;    Long64_t upperpkt2 = 0LL;
310      Long64_t upperobt2 = 0LL;
311    UInt_t zomp = 0;    UInt_t zomp = 0;
312    UInt_t jump = 50000; // was 5000    UInt_t jump = 50000; // was 5000
313    EventCounter *code=0;    EventCounter *code=0;
314    //    //
315    UInt_t deltapkt = 5000;    Long64_t deltapkt = 5000LL;
316    ULong64_t deltaobt = 50000;    Long64_t deltaobt = 50000LL;
317    //    //
318    //   pcksList packetsNames;    //   pcksList packetsNames;
319    //   pcksList::iterator Iter;    //   pcksList::iterator Iter;
# Line 331  Int_t PamelaDBOperations::SetUpperLimits Line 351  Int_t PamelaDBOperations::SetUpperLimits
351    upperobt = OBT(obtlast);    upperobt = OBT(obtlast);
352    upperentry = nevent-1;    upperentry = nevent-1;
353    //    //
354    if ( IsDebug() ) printf(" First entries are: OBT %llu pkt_num %i \n",obtfirst,pktfirst);    if ( IsDebug() ) printf(" First entries are: OBT %i pkt_num %i \n",obtfirst,pktfirst);
355    //    //
356    if ( IsDebug() ) printf(" Last entries are: OBT %llu pkt_num %i entry %i\n",upperobt,upperpkt,upperentry);    if ( IsDebug() ) printf(" Last entries are: OBT %lld pkt_num %lld entry %i\n",upperobt,upperpkt,upperentry);
357    //    //
358    if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) || (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) ) return(1);    if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) || (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) ) return(1);
359    //    //
# Line 364  Int_t PamelaDBOperations::SetUpperLimits Line 384  Int_t PamelaDBOperations::SetUpperLimits
384          upperpkt2 = PKT(ph->GetCounter());          upperpkt2 = PKT(ph->GetCounter());
385          upperobt2 = OBT(ph->GetOrbitalTime());          upperobt2 = OBT(ph->GetOrbitalTime());
386          //          //
387          if ( (t_pktlast < upperpkt && t_obtlast > upperobt) || (t_pktlast < upperpkt2 && t_obtlast > upperobt2) ) throw -13;              if ( (t_pktlast < upperpkt && t_obtlast > upperobt) || (t_pktlast < upperpkt2 && t_obtlast > upperobt2) ){
388              if ( IsDebug() ) printf(" .-. upperpkt2 %lld upperobt2 %lld \n",upperpkt2,upperobt2);  
389              if ( IsDebug() ) printf(" .-. upperpkt %lld t_pktlast %lld upperobt %lld t_obtlast %lld \n",upperpkt,t_pktlast,upperobt,t_obtlast);    
390              if ( IsDebug() ) printf(" .-. jump %i zomp %i upperpkt %lld pktlast %u upperobt %lld obtlast %u last entry is %i \n",jump,zomp,upperpkt,pktlast,upperobt,obtlast,i);    
391              throw -13;    
392            };
393          //          //
394          if ( t_pktlast < upperpkt && t_obtlast < upperobt && t_pktlast < upperpkt2 && t_obtlast < upperobt2 ){          if ( t_pktlast < upperpkt && t_obtlast < upperobt && t_pktlast < upperpkt2 && t_obtlast < upperobt2 ){
395            zomp = i + jump + 1;            zomp = i + jump + 1;
396            if ( zomp > nevent-2 ) zomp = nevent - 2;            if ( zomp > nevent-2 ) zomp = nevent - 2;
397            if ( IsDebug() ) printf(" .-. jump %i zomp %i upperpkt %i pktlast %i upperobt %llu obtlast %u last entry is %i \n",jump,zomp,upperpkt,pktlast,upperobt,obtlast,i);            if ( IsDebug() ) printf(" .-. jump %i zomp %i upperpkt %lld pktlast %i upperobt %lld obtlast %u last entry is %i \n",jump,zomp,upperpkt,pktlast,upperobt,obtlast,i);
398            break;            break;
399          };          };
400          //          //
# Line 404  Int_t PamelaDBOperations::SetUpperLimits Line 429  Int_t PamelaDBOperations::SetUpperLimits
429    //    //
430    rhev = rh->GetEntries();    rhev = rh->GetEntries();
431    rtev = rt->GetEntries();    rtev = rt->GetEntries();
432    UInt_t sobtt = 0;    Long64_t sobtt = 0LL;
433    UInt_t sobth = 0;    Long64_t sobth = 0LL;
434    UInt_t spktt = 0;    Long64_t spktt = 0LL;
435    UInt_t spkth = 0;    Long64_t spkth = 0LL;
436    UInt_t pktt = 0;    Long64_t pktt = 0LL;
437    ULong64_t obtt = 0;    Long64_t obtt = 0LL;
438    UInt_t pkth = 0;    Long64_t pkth = 0LL;
439    ULong64_t obth = 0;    Long64_t obth = 0LL;
440    //    //
441    T->GetEntry(upperentry);    T->GetEntry(upperentry);
442    code = eh->GetCounter();    code = eh->GetCounter();
# Line 431  Int_t PamelaDBOperations::SetUpperLimits Line 456  Int_t PamelaDBOperations::SetUpperLimits
456      obth = OBT(phh->GetOrbitalTime());      obth = OBT(phh->GetOrbitalTime());
457    };    };
458    //    //
459    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 %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);
460    if ( pkth > upperpkt && obth > upperobt ){    if ( pkth > upperpkt && obth > upperobt ){
461      if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt);      if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt);
462      upperpkt = pkth;      upperpkt = pkth;
463      upperobt = obth;      upperobt = obth;
464      rhev = lasthead+1;      rhev = lasthead+1;
465    } else {    } else {
466      rhev = lasthead;      rhev = lasthead;
467    };    };
468    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 %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);
469    //    //
470    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 %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);
471    if ( pktt > upperpkt && obtt > upperobt ){    if ( pktt > upperpkt && obtt > upperobt ){
472      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 %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt);
473      upperpkt = pktt;      upperpkt = pktt;
474      upperobt = obtt;      upperobt = obtt;
475      rtev = lasttrail+1;      rtev = lasttrail+1;
476    } else {    } else {
477      rtev = lasttrail;      rtev = lasttrail;
478    };    };
479    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 %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);
480    //  goto kikko;    //  goto kikko;
481    //    //
482    //    //
483    // Check if runtrailer/runheader are within lower limits    // Check if runtrailer/runheader are within lower limits
484    //    //
485    //    //
486    pkth = 0;    pkth = 0LL;
487    obth = 0;    obth = 0LL;
488    spkth = 0;    spkth = 0LL;
489    sobth = 0;    sobth = 0LL;
490    for (Int_t k=0; k<rhev; k++){    for (Int_t k=0; k<rhev; k++){
491      if ( k > 0 ){      if ( k > 0 ){
492        spkth = pkth;        spkth = pkth;
# Line 509  Int_t PamelaDBOperations::SetUpperLimits Line 534  Int_t PamelaDBOperations::SetUpperLimits
534            upperentry = evbefh-1;            upperentry = evbefh-1;
535          };              };    
536        };        };
537        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 %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);
538        goto kikko0;        goto kikko0;
539      };      };
540    };    };
# Line 517  Int_t PamelaDBOperations::SetUpperLimits Line 542  Int_t PamelaDBOperations::SetUpperLimits
542    //    //
543    //    //
544    //    //
545    pktt = 0;    pktt = 0LL;
546    obtt = 0;    obtt = 0LL;
547    spktt = 0;    spktt = 0LL;
548    sobtt = 0;    sobtt = 0LL;
549    for (Int_t k=0; k<rtev; k++){    for (Int_t k=0; k<rtev; k++){
550      if ( k > 0 ){      if ( k > 0 ){
551        spktt = pktt;        spktt = pktt;
# Line 540  Int_t PamelaDBOperations::SetUpperLimits Line 565  Int_t PamelaDBOperations::SetUpperLimits
565        rt->GetEntry(rtev);        rt->GetEntry(rtev);
566        pktt = spktt;        pktt = spktt;
567        obtt = sobtt;        obtt = sobtt;
568        if ( IsDebug() ) printf(" lasttrail %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt);        if ( IsDebug() ) printf(" lasttrail %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);
569        //        //
570        UInt_t evbeft = 0;        UInt_t evbeft = 0;
571        code = eht->GetCounter();        code = eht->GetCounter();
# Line 569  Int_t PamelaDBOperations::SetUpperLimits Line 594  Int_t PamelaDBOperations::SetUpperLimits
594            upperentry = evbeft-1;            upperentry = evbeft-1;
595          };          };
596        };        };
597        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 %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);
598        goto kikko;        goto kikko;
599        //      break;        //      break;
600        //        //
# Line 597  Int_t PamelaDBOperations::SetUpperLimits Line 622  Int_t PamelaDBOperations::SetUpperLimits
622      obth = OBT(phh->GetOrbitalTime());      obth = OBT(phh->GetOrbitalTime());
623    };    };
624    //    //
625    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 %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);
626    if ( pkth > upperpkt && obth > upperobt ){    if ( pkth > upperpkt && obth > upperobt ){
627      if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt);      if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt);
628      upperpkt = pkth;      upperpkt = pkth;
629      upperobt = obth;      upperobt = obth;
630      rhev = lasthead+1;      rhev = lasthead+1;
631    } else {    } else {
632      rhev = lasthead;      rhev = lasthead;
633    };    };
634    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 %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);
635    //    //
636    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 %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);
637    if ( pktt > upperpkt && obtt > upperobt ){    if ( pktt > upperpkt && obtt > upperobt ){
638      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 %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt);
639      upperpkt = pktt;      upperpkt = pktt;
640      upperobt = obtt;      upperobt = obtt;
641      rtev = lasttrail+1;      rtev = lasttrail+1;
642    } else {    } else {
643      rtev = lasttrail;      rtev = lasttrail;
644    };    };
645    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 %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);
646    //    //
647    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 %lld pkt_num %lld upper entry %i \n",upperobt,upperpkt,upperentry);
648    //    //
649    return(0);    return(0);
650  }  }
# Line 753  void PamelaDBOperations::CheckConnection Line 778  void PamelaDBOperations::CheckConnection
778    if( !conn ) throw -1;    if( !conn ) throw -1;
779    bool connect = conn->IsConnected();    bool connect = conn->IsConnected();
780    if( !connect ) throw -1;    if( !connect ) throw -1;
781    if ( !dworbit ) throw -27;    if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27;
782      //
783      // set DB timezone to UTC
784      //
785      stringstream oss;
786      //  
787      oss.str("");
788      oss << "SET time_zone='+0:00';";
789      TSQLResult *result = 0;
790      result = conn->Query(oss.str().c_str());
791      if ( !result ) throw -10;
792      //
793  };  };
794    
795  /**  /**
796   * Return the correct packet number if we went back to zero   * Return the correct packet number if we went back to zero
797   */   */
798  UInt_t PamelaDBOperations::PKT(UInt_t pkt_num){    Long64_t PamelaDBOperations::PKT(UInt_t pkt_num){  
799    //    //
800    //  if ( IsDebug() ) printf(" pkt conversion: pkt_num is %u pktfirst is %u (pktfirst - (UInt_t)(16777212/2)) is %u  \n",pkt_num,pktfirst,(pktfirst - (UInt_t)(16777212/2)));    if ( IsDebug() ) printf(" pkt conversion: pkt_num is %u pktfirst is %u  (UInt_t)(16777214/2)) is %u  \n",pkt_num,pktfirst,(UInt_t)(16777214/2));
801    //    //
802    if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2)  ) return((pkt_num+16777215));    if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2)  ){
803        if ( IsDebug() ) printf(" rise up pktnum %lld \n",(Long64_t)pkt_num+16777215LL);
804        return((Long64_t)pkt_num+16777215LL);
805      };
806    //    //
807    if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){    if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){
808      if ( (pkt_num-16777215) < 0 ){      if ( IsDebug() ) printf(" rise down pktnum %lld \n",(Long64_t)pkt_num-16777215LL);
809        return((16777215-pkt_num));      return((Long64_t)pkt_num-16777215LL);
     } else {  
       return((pkt_num-16777215));  
     };  
810    };    };
811    //    //
812    return(pkt_num);    if ( IsDebug() ) printf(" as it is %lld \n",(Long64_t)pkt_num);
813      return((Long64_t)pkt_num);
814    //    //
815  };  };
816    
817  /**  /**
818   * Return the correct On Board Time if we went back to zero   * Return the correct On Board Time if we went back to zero
819   */   */
820  ULong64_t PamelaDBOperations::OBT(UInt_t obt){    Long64_t PamelaDBOperations::OBT(UInt_t obt){  
821    //    //
822    if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max()));    if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((Long64_t)(obt+numeric_limits<UInt_t>::max()));
823    //    //
824    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
825      if ( (obt-numeric_limits<UInt_t>::max()) < 0  ){      return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());
       return((ULong64_t)(numeric_limits<UInt_t>::max()-obt));  
     } else {  
       return((ULong64_t)(obt-numeric_limits<UInt_t>::max()));  
     };  
826    };    };
827    //    //
828    return((ULong64_t)obt);    return((Long64_t)obt);
829  };  };
830    
831  /**  /**
# Line 933  Int_t PamelaDBOperations::insertPamelaGL Line 966  Int_t PamelaDBOperations::insertPamelaGL
966    if ( this->GetID_RAW() == 0 )  throw -11;    if ( this->GetID_RAW() == 0 )  throw -11;
967    //    //
968    oss.str("");    oss.str("");
969    oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='"    oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='"
970        << this->GetRawFile().Data() << "';";        << this->GetRawFile().Data() << "';";
971    if ( IsDebug() ) printf(" %s \n",oss.str().c_str());    if ( IsDebug() ) printf(" %s \n",oss.str().c_str());
972    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
# Line 942  Int_t PamelaDBOperations::insertPamelaGL Line 975  Int_t PamelaDBOperations::insertPamelaGL
975    //    //
976    if ( !row ){    if ( !row ){
977      oss.str("");      oss.str("");
978      oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< "      oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< "
979          << dworbit << " order by FROM_ORBIT desc limit 1;";          << dworbit << " order by FROM_ORBIT desc limit 1;";
980      if ( IsDebug() ) printf(" %s \n",oss.str().c_str());      if ( IsDebug() ) printf(" %s \n",oss.str().c_str());
981      result = conn->Query(oss.str().c_str());      result = conn->Query(oss.str().c_str());
# Line 951  Int_t PamelaDBOperations::insertPamelaGL Line 984  Int_t PamelaDBOperations::insertPamelaGL
984      if ( !row ) throw -10;      if ( !row ) throw -10;
985    };    };
986    //    //
987    t0 = (UInt_t)TDatime(row->GetField(0)).Convert();    TTimeStamp tu = TTimeStamp((UInt_t)atoi(row->GetField(0)),(UInt_t)atoi(row->GetField(1)),(UInt_t)atoi(row->GetField(2)),(UInt_t)atoi(row->GetField(3)),(UInt_t)atoi(row->GetField(4)),(UInt_t)atoi(row->GetField(5)),0,true,0);
988      t0 = (UInt_t)tu.GetSec();
989      if ( IsDebug() ) printf(" t0 is %u ti is %s %s %s %s %s %s\n",t0,row->GetField(0),row->GetField(1),row->GetField(2),row->GetField(3),row->GetField(4),row->GetField(5));
990      //
991    /*    /*
992     * Verify that the TIMESYNC have been not already processed     * Verify that the TIMESYNC have been not already processed
993     */     */
# Line 966  Int_t PamelaDBOperations::insertPamelaGL Line 1002  Int_t PamelaDBOperations::insertPamelaGL
1002    if (result == NULL) throw -10;    if (result == NULL) throw -10;
1003    row = result->Next();    row = result->Next();
1004    if ((row != NULL) && ((UInt_t)atoll(row->GetField(0)) > 0)){    if ((row != NULL) && ((UInt_t)atoll(row->GetField(0)) > 0)){
1005        if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);
1006      toffset = (UInt_t)atoll(row->GetField(2)) - (UInt_t)(this->OBT((UInt_t)atoll(row->GetField(1)))/1000) + t0;      toffset = (UInt_t)atoll(row->GetField(2)) - (UInt_t)(this->OBT((UInt_t)atoll(row->GetField(1)))/1000) + t0;
1007        //
1008        tsync = (UInt_t)atoll(row->GetField(2));
1009        obt0 = (UInt_t)atoll(row->GetField(1));
1010        //
1011      return(1);      return(1);
1012    };    };
1013    //    //
# Line 1160  Int_t PamelaDBOperations::insertPamelaGL Line 1201  Int_t PamelaDBOperations::insertPamelaGL
1201    conn->Query(oss.str().c_str());    conn->Query(oss.str().c_str());
1202    if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to fill it:\n %s \n",oss.str().c_str());    if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to fill it:\n %s \n",oss.str().c_str());
1203    //    //
1204      if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);
1205    toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0;    toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0;
1206    //    //
1207      tsync = TSYNC;
1208      obt0 = OBT;
1209      //
1210    delete result;    delete result;
1211    return(signal);    return(signal);
1212  }  }
# Line 1261  Int_t PamelaDBOperations::assignBOOT_NUM Line 1306  Int_t PamelaDBOperations::assignBOOT_NUM
1306    VarDumpEvent  *vde = 0;    VarDumpEvent  *vde = 0;
1307    VarDumpRecord *vdr = 0;    VarDumpRecord *vdr = 0;
1308    //    //
1309      Bool_t found = false;
1310    trDumpEv->SetBranchAddress("VarDump", &vde);    trDumpEv->SetBranchAddress("VarDump", &vde);
1311    if ( trDumpEv->GetEntries() > 0 ){    if ( trDumpEv->GetEntries() > 0 ){
1312      Bool_t found = false;      found = false;
1313      for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){      for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){
1314        trDumpEv->GetEntry(i);        trDumpEv->GetEntry(i);
1315        vde->Records->GetEntries();        //      vde->Records->GetEntries();
1316        if ( vde->Records->GetEntries()>0 ){        if ( vde->Records->GetEntries()>5 ){
1317          found = true;          found = true;
1318          goto fill;          goto fill;
1319        };        };
# Line 1280  Int_t PamelaDBOperations::assignBOOT_NUM Line 1326  Int_t PamelaDBOperations::assignBOOT_NUM
1326        this->SetBOOTnumber((Int_t)vdr->VAR_VALUE);        this->SetBOOTnumber((Int_t)vdr->VAR_VALUE);
1327        //        //
1328      } else {      } else {
1329        if ( !this->GetBOOTnumber() ) return(4);        if ( !this->GetBOOTnumber() && !this->AutoBoot()) return(4);
1330      };      };
1331    } else {    } else {
1332      if ( !this->GetBOOTnumber() ) return(2);      if ( !this->GetBOOTnumber() && !this->AutoBoot()) return(2);
1333      };
1334      //
1335      UInt_t bn = 0;
1336      Bool_t afound = false;
1337      if ( !found && this->AutoBoot()){
1338        afound = true;
1339        //
1340        // Search for other files with similar timesync
1341        //
1342        if ( IsDebug() ) printf(" tsync %u obt0 %u \n",tsync,obt0);
1343        UInt_t upperts = tsync-(obt0/1000)+5;
1344        UInt_t lowerts = tsync-(obt0/1000)-5;
1345        oss.str("");
1346        oss << "select GL_RAW.BOOT_NUMBER from GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW where TIMESYNC-(OBT0/1000)<"
1347            << upperts
1348            << " AND TIMESYNC-(OBT0/1000)>"
1349            << lowerts
1350            << " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;";
1351        result = conn->Query(oss.str().c_str());
1352        if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to find boot number:\n %s \n",oss.str().c_str());
1353        //
1354        if ( !result ) throw -4;;
1355        found = true;
1356        if ( result->GetRowCount()<3 ){
1357          if ( IsDebug() ) printf(" AGH! no results!\n");
1358          found = false;
1359        } else {
1360          row = result->Next();      
1361          bn = (UInt_t)atoll(row->GetField(0));
1362          for ( Int_t r=1; r<result->GetRowCount() ;r++){
1363            if ( !row ) throw -4;
1364            if ( IsDebug() ) printf(" BOOT number is %s \n",row->GetField(0));
1365            if ( bn != (UInt_t)atoll(row->GetField(0)) ){
1366              if ( IsDebug() ) printf(" AGH! bn = %u here instead %u \n",bn,(UInt_t)atoll(row->GetField(0)));
1367              found = false;
1368            };
1369            row = result->Next();
1370          };
1371        };
1372      };
1373      //
1374      Int_t sgn = 0;
1375      //
1376      if ( !found ){
1377        throw -29;
1378      } else {
1379        if ( afound ){
1380          this->SetBOOTnumber(bn);
1381          sgn = 8;
1382        };
1383    };    };
1384    //    //
1385    oss.str("");    oss.str("");
# Line 1293  Int_t PamelaDBOperations::assignBOOT_NUM Line 1389  Int_t PamelaDBOperations::assignBOOT_NUM
1389    conn->Query(oss.str().c_str());          conn->Query(oss.str().c_str());      
1390    //    //
1391    delete result;    delete result;
1392    return(0);    return(sgn);
1393  };  };
1394    
1395  /**  /**
# Line 1659  void PamelaDBOperations::HandleRunFragme Line 1755  void PamelaDBOperations::HandleRunFragme
1755    UInt_t rhfirstev = firstev;    UInt_t rhfirstev = firstev;
1756    UInt_t rtlastev = lastev;    UInt_t rtlastev = lastev;
1757    Bool_t found = false;    Bool_t found = false;
1758      Bool_t foundinrun = false;
1759    //    //
1760    TSQLResult *result = 0;    TSQLResult *result = 0;
1761    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
# Line 1685  void PamelaDBOperations::HandleRunFragme Line 1782  void PamelaDBOperations::HandleRunFragme
1782    //    //
1783    if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n");    if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n");
1784    //    //
1785      // First of all insert the run in the fragment table...
1786      //
1787      oss.str("");
1788      oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE "
1789          << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND ("
1790          << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "
1791          << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("
1792          << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR "
1793          << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND ("
1794          << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR "
1795          << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR "
1796          << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "
1797          << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND ("
1798          << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR "
1799          << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND ("
1800          << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR "
1801          << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));";
1802      //
1803      if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str());
1804      result = conn->Query(oss.str().c_str());
1805      //
1806      if ( !result ) throw -4;
1807      //
1808      row = result->Next();
1809      //
1810      if ( !row ){
1811        //
1812        // no, insert this run in the GL_RUN_FRAGMENTS table (check if exist before!)
1813        //
1814        if ( IsDebug() ) printf(" The run is new \n");
1815        if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n");
1816        //
1817        glrun->SetID(this->AssignRunID());
1818        glrun->SetID_RUN_FRAG(0);
1819        glrun->Fill_GL_RUN_FRAGMENTS(conn);
1820        //
1821      } else {
1822        if ( IsDebug() ) printf(" The run is already present in the fragment table \n");
1823      };
1824      //
1825      //
1826    // can we find the other piece of the run in the GL_RUN_FRAGMENTS table?    // can we find the other piece of the run in the GL_RUN_FRAGMENTS table?
1827    //        //    
1828    if ( mishead && rhfirstev == firstev ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is    if ( mishead && rhfirstev == firstev ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is
# Line 1693  void PamelaDBOperations::HandleRunFragme Line 1831  void PamelaDBOperations::HandleRunFragme
1831      oss.str("");      oss.str("");
1832      oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN_FRAGMENTS WHERE "      oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN_FRAGMENTS WHERE "
1833          << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND "          << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND "
1834          << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME()          << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "
1835            << " ID != " << glrun->ID
1836          << " ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!!          << " ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!!
1837      //      //
1838      if ( IsDebug() ) printf(" look for runheader in the fragments table: query is \n %s \n",oss.str().c_str());      if ( IsDebug() ) printf(" look for runheader in the fragments table: query is \n %s \n",oss.str().c_str());
# Line 1703  void PamelaDBOperations::HandleRunFragme Line 1842  void PamelaDBOperations::HandleRunFragme
1842      //      //
1843      row = result->Next();      row = result->Next();
1844      //      //
1845        if ( !row && NoFrag() ){
1846          //
1847          oss.str("");
1848          oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN WHERE "
1849              << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND "
1850              << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "
1851              << " ID != " << glrun->ID
1852              << " AND ID=ID_RUN_FRAG ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!!
1853          //
1854          if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str());
1855          result = conn->Query(oss.str().c_str());
1856          //
1857          if ( !result ) throw -4;
1858          //
1859          foundinrun = true;
1860          //
1861          row = result->Next();
1862          //
1863        };
1864        //
1865      if ( !row ){      if ( !row ){
1866        if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n");        if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n");
1867        found = false;        found = false;
# Line 1777  void PamelaDBOperations::HandleRunFragme Line 1936  void PamelaDBOperations::HandleRunFragme
1936        //        //
1937        if ( IsDebug() ) printf(" now you can handle the piece of the run \n ");        if ( IsDebug() ) printf(" now you can handle the piece of the run \n ");
1938        //        //
1939          if ( foundinrun ){
1940            glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS");
1941            glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN");
1942          };
1943          //
1944        GL_RUN *glrun1 = new GL_RUN();        GL_RUN *glrun1 = new GL_RUN();
1945        //        //
1946        UInt_t idfrag = (UInt_t)atoll(row->GetField(0));        //      UInt_t idfrag = (UInt_t)atoll(row->GetField(0));
1947        //        //
1948        oss.str("");        oss.str("");
1949        oss << " ID="<<row->GetField(0)<<";";        oss << " ID="<<row->GetField(0)<<";";
# Line 1816  void PamelaDBOperations::HandleRunFragme Line 1980  void PamelaDBOperations::HandleRunFragme
1980        //        //
1981        glrun->SetEV_FROM(firstev);        glrun->SetEV_FROM(firstev);
1982        glrun->SetNEVENTS(lastev-firstev+1);        glrun->SetNEVENTS(lastev-firstev+1);
1983          //
1984        glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME());        glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME());
1985        glrun->SetRUNHEADER_OBT(glrun1->GetRUNHEADER_OBT());        glrun->SetRUNHEADER_OBT(glrun1->GetRUNHEADER_OBT());
1986        glrun->SetRUNHEADER_PKT(glrun1->GetRUNHEADER_PKT());        glrun->SetRUNHEADER_PKT(glrun1->GetRUNHEADER_PKT());
# Line 1835  void PamelaDBOperations::HandleRunFragme Line 2000  void PamelaDBOperations::HandleRunFragme
2000        //        //
2001        if ( !IsRunAlreadyInserted() ){        if ( !IsRunAlreadyInserted() ){
2002          //          //
2003          glrun->SetID(this->AssignRunID());          //      glrun->SetID(this->AssignRunID());
2004          glrun->SetID_RUN_FRAG(glrun1->GetID());          glrun->SetID_RUN_FRAG(glrun1->GetID());
2005          glrun->Fill_GL_RUN(conn);          glrun->Fill_GL_RUN(conn);
2006          //          //
2007          // get id number          // set id number
2008          //          //
 //      oss.str("");  
 //      oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<<this->GetBOOTnumber()<<" AND "  
 //          << " RUNHEADER_OBT="<<glrun->GetRUNHEADER_OBT()<<" AND "  
 //          << " RUNTRAILER_OBT="<<glrun->GetRUNTRAILER_OBT()<<";";  
 //      //  
 //      if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str());  
 //      //  
 //      result =  conn->Query(oss.str().c_str());  
 //      if ( !result ) throw -4;  
 //      row = result->Next();  
 //      //  
 //      UInt_t idrun0 = 0;  
 //      if ( !row ){  
 //        throw -10;  
 //      } else {  
 //        idrun0 = (UInt_t)atoll(row->GetField(0));  
 //      };  
         //  
         //      glrun1->SetID_RUN_FRAG(idrun0);  
2009          glrun1->SetID_RUN_FRAG(glrun->GetID());          glrun1->SetID_RUN_FRAG(glrun->GetID());
2010          glrun1->Fill_GL_RUN(conn);          glrun1->Fill_GL_RUN(conn);
2011          //          //
 //      oss.str("");  
 //      oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<<idrun0<<" ;";  
 //      //  
 //      if ( IsDebug() ) printf(" search for idrun1 , query is : \n%s\n",oss.str().c_str());  
 //      //  
 //      result =  conn->Query(oss.str().c_str());  
 //      if ( !result ) throw -4;  
 //      row = result->Next();  
 //      //  
 //      UInt_t idrun1 = 0;  
 //      if ( !row ){  
 //        throw -10;  
 //      } else {  
 //        idrun1 = (UInt_t)atoll(row->GetField(0));  
 //      };  
 //      //  
 //      oss.str("");  
 //      oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<<idrun1<<" WHERE ID="<<idrun0<<" ;";  
 //      //  
 //      result =  conn->Query(oss.str().c_str());  
 //      if ( !result ) throw -4;  
         //  
2012        };        };
2013          // delete old entry in fragment table
2014        //        //
2015        delete glrun1;        glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
2016          glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
2017        //        //
2018        // delete old entry in fragment table        delete glrun1;
2019        //        //
       glrun->DeleteRun(conn,idfrag,"GL_RUN_FRAGMENTS");  
 //       oss.str("");  
 //       //  
 //       oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";";  
 //       //  
 //       if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str());  
 //       result =  conn->Query(oss.str().c_str());  
 //       if ( !result ) throw -4;  
2020        //        //
2021        return;        return;
2022        //        //
# Line 1907  void PamelaDBOperations::HandleRunFragme Line 2025  void PamelaDBOperations::HandleRunFragme
2025    };    };
2026    //    //
2027    if ( mistrail && rtlastev == lastev ) { // look for runtrailer (only when at the end of the file, if at the beginning and the runh is    if ( mistrail && rtlastev == lastev ) { // look for runtrailer (only when at the end of the file, if at the beginning and the runh is
2028                                             // missing it no way we can found a piece in the frag table      // missing it no way we can found a piece in the frag table
2029      //      //
2030      oss.str("");      oss.str("");
2031      oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN_FRAGMENTS WHERE "      oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN_FRAGMENTS WHERE "
2032          << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND "          << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND "
2033          << " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME()          << " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() << " AND "
2034            << " ID != " << glrun->ID
2035          << " ORDER BY RUNTRAILER_TIME ASC LIMIT 1;";          << " ORDER BY RUNTRAILER_TIME ASC LIMIT 1;";
2036      //      //
2037      if ( IsDebug() ) printf(" look for runtrailer in the fragments table: query is \n %s \n",oss.str().c_str());      if ( IsDebug() ) printf(" look for runtrailer in the fragments table: query is \n %s \n",oss.str().c_str());
# Line 1922  void PamelaDBOperations::HandleRunFragme Line 2041  void PamelaDBOperations::HandleRunFragme
2041      //      //
2042      row = result->Next();      row = result->Next();
2043      //      //
2044        if ( !row && NoFrag() ){
2045          //
2046          oss.str("");
2047          oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN WHERE "
2048              << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND "
2049              << " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() << " AND "
2050              << " ID != " << glrun->ID
2051              << " AND ID=ID_RUN_FRAG ORDER BY RUNTRAILER_TIME ASC LIMIT 1;";
2052          //
2053          if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str());
2054          result = conn->Query(oss.str().c_str());
2055          //
2056          if ( !result ) throw -4;
2057          //
2058          foundinrun = true;
2059          row = result->Next();
2060          //
2061        };
2062        //
2063      if ( !row ){      if ( !row ){
2064        if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n");        if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n");
2065        found = false;        found = false;
# Line 1995  void PamelaDBOperations::HandleRunFragme Line 2133  void PamelaDBOperations::HandleRunFragme
2133        //        //
2134        if ( IsDebug() ) printf(" now you can handle the piece of the run \n ");        if ( IsDebug() ) printf(" now you can handle the piece of the run \n ");
2135        //        //
2136          if ( foundinrun ){
2137            glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS");
2138            glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN");
2139          };
2140          //
2141        GL_RUN *glrun1 = new GL_RUN();        GL_RUN *glrun1 = new GL_RUN();
2142        //        //
2143        UInt_t idfrag = (UInt_t)atoll(row->GetField(0));        //      UInt_t idfrag = (UInt_t)atoll(row->GetField(0));
2144        //        //
2145        oss.str("");        oss.str("");
2146        oss << " ID="<<row->GetField(0)<<";";        oss << " ID="<<row->GetField(0)<<";";
# Line 2053  void PamelaDBOperations::HandleRunFragme Line 2196  void PamelaDBOperations::HandleRunFragme
2196        //        //
2197        if ( !IsRunAlreadyInserted() ){        if ( !IsRunAlreadyInserted() ){
2198          //          //
2199          glrun->SetID(this->AssignRunID());          //      glrun->SetID(this->AssignRunID());
2200          //          //
2201          glrun->SetID_RUN_FRAG(glrun1->GetID());          glrun->SetID_RUN_FRAG(glrun1->GetID());
2202          glrun->Fill_GL_RUN(conn);          glrun->Fill_GL_RUN(conn);
2203          //          //
2204          // get id number          // set id number
2205          //          //
 //      oss.str("");  
 //      oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<<this->GetBOOTnumber()<<" AND "  
 //          << " RUNHEADER_OBT="<<glrun->GetRUNHEADER_OBT()<<" AND "  
 //          << " RUNTRAILER_OBT="<<glrun->GetRUNTRAILER_OBT()<<";";  
 //      //  
 //      if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str());  
 //      //  
 //      result =  conn->Query(oss.str().c_str());  
 //      if ( !result ) throw -4;  
 //      row = result->Next();  
 //      //  
 //      UInt_t idrun0 = 0;  
 //      if ( !row ){  
 //        throw -10;  
 //      } else {  
 //        idrun0 = (UInt_t)atoll(row->GetField(0));  
 //      };  
 //      //  
 //      glrun1->SetID_RUN_FRAG(idrun0);  
 //  
2206          glrun1->SetID_RUN_FRAG(glrun->GetID());          glrun1->SetID_RUN_FRAG(glrun->GetID());
2207          glrun1->Fill_GL_RUN(conn);          glrun1->Fill_GL_RUN(conn);
2208          //          //
 //      oss.str("");  
 //      oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<<idrun0<<" ;";  
 //      //  
 //      if ( IsDebug() ) printf(" search for idrun1 , query is : \n%s\n",oss.str().c_str());  
 //      //  
 //      result =  conn->Query(oss.str().c_str());  
 //      if ( !result ) throw -4;  
 //      row = result->Next();  
 //      //  
 //      UInt_t idrun1 = 0;  
 //      if ( !row ){  
 //        throw -10;  
 //      } else {  
 //        idrun1 = (UInt_t)atoll(row->GetField(0));  
 //      };  
 //      //  
 //      oss.str("");  
 //      oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<<idrun1<<" WHERE ID="<<idrun0<<" ;";  
 //      //  
 //      result =  conn->Query(oss.str().c_str());  
 //      if ( !result ) throw -4;  
         //  
2209        };        };
2210        //        //
2211        delete glrun1;        // delete old entries in fragment table
       //  
       // delete old entry in fragment table  
2212        //        //
2213        glrun->DeleteRun(conn,idfrag,"GL_RUN_FRAGMENTS");        glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
2214  //       oss.str("");        glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
 //       //  
 //       oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";";  
 //       //  
 //       if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str());  
 //       result =  conn->Query(oss.str().c_str());  
 //       if ( !result ) throw -4;  
2215        //        //
2216          delete glrun1;
2217        //        //
2218        return;        return;
2219        //        //
# Line 2156  void PamelaDBOperations::HandleRunFragme Line 2250  void PamelaDBOperations::HandleRunFragme
2250      //      //
2251      row = result->Next();      row = result->Next();
2252      //      //
2253      if ( !row ){      if ( row ){
       //  
       oss.str("");  
       oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE "  
           << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND ("  
           << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "  
           << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("  
           << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR "  
           << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND ("  
           << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR "  
           << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR "  
           << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "  
           << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND ("  
           << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR "  
           << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND ("  
           << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR "  
           << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));";  
       //  
       if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str());  
       result = conn->Query(oss.str().c_str());  
       //  
       if ( !result ) throw -4;  
       //  
       row = result->Next();  
       //  
       if ( !row ){  
         //  
         // no, insert this run in the GL_RUN_FRAGMENTS table (check if exist before!)  
         //  
         if ( IsDebug() ) printf(" The run is new \n");  
         if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n");  
         //  
         glrun->SetID(this->AssignRunID());  
         glrun->SetID_RUN_FRAG(0);  
         glrun->Fill_GL_RUN_FRAGMENTS(conn);  
         //  
       } else {  
         if ( IsDebug() ) printf(" The run is already present in the fragment table \n");  
       };  
     } else {  
2254        if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n");        if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n");
2255        } else {
2256          if ( NoFrag() ){
2257            glrun->SetID_RUN_FRAG(glrun->GetID());
2258            glrun->Fill_GL_RUN(conn);      
2259            glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
2260          };    
2261      };      };
2262    };    };
2263    //    //
# Line 2757  Int_t PamelaDBOperations::insertCALO_CAL Line 2818  Int_t PamelaDBOperations::insertCALO_CAL
2818                // no calibrations in the db contain our calibration                // no calibrations in the db contain our calibration
2819                //                //
2820                if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB for section %i \n",section);                if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB for section %i \n",section);
2821                if ( fromtime < 1150863400 ){                if ( fromtime < 1150871000 ){ //1150866904
2822                  if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime);                  if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime);
2823                  fromtime = 0;// the first flight calibration was taken at about  1156429100 s, this line allow to analyze first runs in raw mode                  fromtime = 0;// the first flight calibration was taken at about  1156429100 s, this line allow to analyze first runs in raw mode
2824                };                };
# Line 2902  void PamelaDBOperations::HandleTRK_CALIB Line 2963  void PamelaDBOperations::HandleTRK_CALIB
2963        // no calibrations in the db contain our calibration        // no calibrations in the db contain our calibration
2964        //        //
2965        if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n");        if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n");
2966        if ( fromtime < 1150863400 ) fromtime = 0; // the first flight calibration was taken at about 1150863300 s, this line allows to analyze first runs in raw mode        if ( fromtime < 1150871000 ) fromtime = 0; // the first flight calibration was taken at about 1150863300 s, this line allows to analyze first runs in raw mode
2967        //        //
2968        oss.str("");        oss.str("");
2969        oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE "        oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE "
# Line 3031  Int_t PamelaDBOperations::insertTRK_CALI Line 3092  Int_t PamelaDBOperations::insertTRK_CALI
3092      pkt1 = ph1->GetCounter();        pkt1 = ph1->GetCounter();  
3093      fromtime = this->GetAbsTime(ph1->GetOrbitalTime());        fromtime = this->GetAbsTime(ph1->GetOrbitalTime());  
3094      //      //
3095      valid = 1;  //     valid = 1;
3096      //  //     //
3097      if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1  //     if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1
3098      //      //
3099      //      //
3100      if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){      if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){
3101        //        //
3102        if ( IsDebug() ) printf(" Trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1);        if ( IsDebug() ) printf(" Trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1);
3103          //      
3104          valid = ValidateTrkCalib( caltrk1, eh1 );
3105          if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl;
3106        //        //
3107        // Do we have the second calibration packet?        // Do we have the second calibration packet?
3108        //        //
# Line 3055  Int_t PamelaDBOperations::insertTRK_CALI Line 3119  Int_t PamelaDBOperations::insertTRK_CALI
3119            obt2 = ph2->GetOrbitalTime();              obt2 = ph2->GetOrbitalTime();  
3120            pkt2 = ph2->GetCounter();              pkt2 = ph2->GetCounter();  
3121            //            //
3122            if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2  //        if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2
3123            //                  //      
3124          } else {          } else {
3125            //            //
# Line 3086  Int_t PamelaDBOperations::insertTRK_CALI Line 3150  Int_t PamelaDBOperations::insertTRK_CALI
3150          //          //
3151          if ( IsDebug() ) printf(" The trk calibration2 at obt %i pkt %i t2 is %i is good \n",obt2,pkt2,t2);          if ( IsDebug() ) printf(" The trk calibration2 at obt %i pkt %i t2 is %i is good \n",obt2,pkt2,t2);
3152          //          //
3153            UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 );
3154            if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl;
3155            valid = valid & valid2;
3156            //
3157          // Handle good calib          // Handle good calib
3158          //          //
3159          this->HandleTRK_CALIB(true,true);          this->HandleTRK_CALIB(true,true);
# Line 3258  Int_t PamelaDBOperations::insertS4_CALIB Line 3326  Int_t PamelaDBOperations::insertS4_CALIB
3326            // no calibrations in the db contain our calibration            // no calibrations in the db contain our calibration
3327            //            //
3328            if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB \n");            if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB \n");
3329            if ( fromtime < 1150863400 ){            if ( fromtime < 1150871000 ){  
3330              if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime);              if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime);
3331              fromtime = 0;// the first flight calibration was taken at about  1156429100 s, this line allow to analyze first runs in raw mode              fromtime = 0;// the first flight calibration was taken at about  1156429100 s, this line allow to analyze first runs in raw mode
3332            };            };
# Line 3331  Int_t PamelaDBOperations::insertS4_CALIB Line 3399  Int_t PamelaDBOperations::insertS4_CALIB
3399   * Scan the fragment table and move old fragments to the GL_RUN table   * Scan the fragment table and move old fragments to the GL_RUN table
3400   */   */
3401  Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){  Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){
3402      return(this->CleanGL_RUN_FRAGMENTS(""));
3403    };
3404    
3405    /**
3406     * Scan the fragment table and move old fragments to the GL_RUN table
3407     */
3408    Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(TString fcleanfile){
3409    //    //
3410    TSQLResult *result = 0;    TSQLResult *result = 0;
3411    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
# Line 3338  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3413  Int_t PamelaDBOperations::CleanGL_RUN_FR
3413    TSQLRow    *row2   = 0;    TSQLRow    *row2   = 0;
3414    //    //
3415    UInt_t moved = 0;    UInt_t moved = 0;
 //  UInt_t timelim = 0;  
 //  TDatime *time = new TDatime();  
3416    //    //
3417    stringstream oss;    stringstream oss;
3418    oss.str("");    oss.str("");
3419    //    //
3420    //    if ( !strcmp(fcleanfile.Data(),"") ){
3421    // check if there are entries older than "olderthan" seconds from now      //
3422    //      // check if there are entries older than "olderthan" seconds from now
3423    oss.str("");      //
3424    oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"      oss.str("");
3425        << " INSERT_TIME <= '" << clean_time->AsSQLString() << "';";      oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"
3426    //          << " INSERT_TIME <= '" << clean_time->AsSQLString() << "';";
3427    if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str());      //
3428    result = conn->Query(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());
3429        result = conn->Query(oss.str().c_str());
3430        //
3431      } else {
3432        oss.str("");
3433        oss << " SELECT ID FROM GL_ROOT WHERE NAME='" << fcleanfile.Data() << "';";
3434        if ( IsDebug() ) printf(" Getting ID_ROOT_L0 query %s \n",oss.str().c_str());
3435        result = conn->Query(oss.str().c_str());
3436        //    
3437        if ( result ){
3438          //
3439          row = result->Next();
3440          //
3441          if ( row ){
3442            oss.str("");
3443            oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"
3444                << " ID_ROOT_L0=" << row->GetField(0) << ";";
3445            //
3446            if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS for ROOT file query is \n %s \n",oss.str().c_str());
3447            result = conn->Query(oss.str().c_str());
3448            //    
3449          };
3450        } else {
3451          return(2);
3452        };
3453      };
3454    //    //
3455    if ( result ){    if ( result ){
3456      //      //
# Line 3448  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3546  Int_t PamelaDBOperations::CleanGL_RUN_FR
3546   * Check if runs are good, i.e. if the tracker calibration is correctly associated..   * Check if runs are good, i.e. if the tracker calibration is correctly associated..
3547   */   */
3548  Int_t PamelaDBOperations::ValidateRuns(){  Int_t PamelaDBOperations::ValidateRuns(){
3549      return(this->ValidateRuns(""));
3550    };
3551    
3552    /**
3553     * Check if runs are good, i.e. if the tracker calibration is correctly associated..
3554     */
3555    Int_t PamelaDBOperations::ValidateRuns(TString valfile){
3556    //    //
3557    TSQLResult *result = 0;    TSQLResult *result = 0;
3558    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
3559    //    //
3560      UInt_t calibtime = 50;
3561      //
3562    stringstream oss;    stringstream oss;
3563    oss.str("");    oss.str("");
3564    //    //
# Line 3460  Int_t PamelaDBOperations::ValidateRuns() Line 3567  Int_t PamelaDBOperations::ValidateRuns()
3567    // =======================================================    // =======================================================
3568    UInt_t t_stop  = 0;    UInt_t t_stop  = 0;
3569    UInt_t t_start = 0;    UInt_t t_start = 0;
3570    // --------------------------------------------------------------    if ( !strcmp(valfile.Data(),"") ) {
3571    // 1) get the OBT of the last run inserted after clean-time limit      // --------------------------------------------------------------
3572    // --------------------------------------------------------------      // 1) get the OBT of the last run inserted after clean-time limit
3573    oss.str("");      // --------------------------------------------------------------
3574    oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << clean_time->AsSQLString()      oss.str("");
3575            << "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;";      oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << clean_time->AsSQLString()
3576    if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str());          << "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3577    result = conn->Query(oss.str().c_str());      if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str());
3578    if ( !result ) throw -4;      result = conn->Query(oss.str().c_str());
3579    if ( !result->GetRowCount() ) {      if ( !result ) throw -4;
3580            printf(" No runs to validate \n");      if ( !result->GetRowCount() ) {
3581            return(1);        printf(" No runs to validate \n");
3582    }else{        return(1);
3583          row = result->Next();      }else{
3584          t_start = (UInt_t)atoll(row->GetField(4));        row = result->Next();
3585    };          t_start = (UInt_t)atoll(row->GetField(4));
3586    // --------------------------------------------------------------      };  
3587    // 2) get the OBT of the last validated run      // --------------------------------------------------------------
3588    // --------------------------------------------------------------      // 2) get the OBT of the last validated run
3589    oss.str("");      // --------------------------------------------------------------
3590    oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start      oss.str("");
3591        <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";      oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start
3592    if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3593    result = conn->Query(oss.str().c_str());      if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());
3594    if ( !result ) throw -4;      result = conn->Query(oss.str().c_str());
3595    if ( result->GetRowCount() ){      if ( !result ) throw -4;
3596            row = result->Next();      if ( result->GetRowCount() ){
3597            t_stop = (UInt_t)atoll(row->GetField(4));        row = result->Next();
3598          t_stop = (UInt_t)atoll(row->GetField(4));
3599        };
3600        if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start);
3601        // --------------------------------------------------------------
3602        // now retrieves runs to be validated
3603        // --------------------------------------------------------------
3604        oss.str("");
3605        oss << " SELECT * FROM GL_RUN  WHERE  RUNHEADER_TIME <=" << t_start;
3606        oss << " AND RUNHEADER_TIME >="<< t_stop;
3607        oss << " ORDER BY RUNHEADER_TIME DESC;";
3608        if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str());
3609        result = conn->Query(oss.str().c_str());
3610      } else {
3611        //
3612        stringstream myquery;
3613        UInt_t myid = 0;
3614        myquery.str("");
3615        myquery << " SELECT ID FROM GL_ROOT where NAME='"<<valfile.Data() <<"';";
3616        //
3617        result = conn->Query(myquery.str().c_str());
3618        //
3619        row = result->Next();      
3620        if( !row ){
3621          if ( strcmp(valfile.Data(),GetRootName().Data()) ){
3622            if ( IsDebug() ) printf(" No file to be validated even if option \"-validate file\" was used!!\n");
3623            return(2);
3624          };
3625          if ( IsDebug() ) printf(" No file to be validated (force mode)! \n");
3626          return(0);
3627        };
3628        myid=(UInt_t)atoll(row->GetField(0));
3629        //
3630        myquery.str("");
3631        myquery << " SELECT MAX(RUNTRAILER_TIME),MIN(RUNHEADER_TIME) FROM GL_RUN WHERE ID_ROOT_L0="<< myid <<";";
3632        //
3633        result = conn->Query(myquery.str().c_str());
3634        //
3635        row = result->Next();      
3636        if( !row->GetField(0) || !row->GetField(1)){
3637          //
3638          if ( IsDebug() ) printf(" NO RUN ASSOCIATED TO THIS FILE! \n");
3639          //
3640          return(0);
3641          //
3642        } else {  
3643          //
3644          UInt_t runhtime = (UInt_t)atoll(row->GetField(0));
3645          UInt_t runttime = (UInt_t)atoll(row->GetField(1));
3646          UInt_t caltime = 0;
3647          //
3648          myquery.str("");
3649          myquery << " SELECT FROM_TIME FROM GL_TRK_CALIB where FROM_TIME>" <<runhtime;
3650          myquery << " order by FROM_TIME asc limit 1;";
3651          //
3652          if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
3653          //
3654          //
3655          result = conn->Query(myquery.str().c_str());
3656          //
3657          row = result->Next();      
3658          if( !row ){
3659            caltime = runhtime;
3660          } else {
3661            caltime = (UInt_t)atoll(row->GetField(0));
3662          };
3663          //
3664          myquery.str("");
3665          myquery << " SELECT * from GL_RUN where RUNHEADER_TIME>="<< runttime <<" AND RUNHEADER_TIME<=" ;
3666          myquery << caltime << " order by RUNHEADER_TIME DESC";
3667          //
3668          if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
3669          //
3670          result = conn->Query(myquery.str().c_str());
3671          //
3672        };
3673    };    };
3674    if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start);    //
   // --------------------------------------------------------------  
   // now retrieves runs to be validated  
   // --------------------------------------------------------------  
   oss.str("");  
   oss << " SELECT * FROM GL_RUN  WHERE  RUNHEADER_TIME <=" << t_start;  
   oss << " AND RUNHEADER_TIME >="<< t_stop;  
   oss << " ORDER BY RUNHEADER_TIME DESC;";  
 //  if ( IsDebug() )  
   if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str());  
   result = conn->Query(oss.str().c_str());  
3675    if ( !result ) throw -4;    if ( !result ) throw -4;
3676    if ( !result->GetRowCount() ) printf(" No runs to validate \n");    if ( !result->GetRowCount() && IsDebug() ) printf(" No runs to validate \n");
3677  //  printf("------------------------------------------------------------------------------- \n");    //
     
3678    Int_t nrow = 0;    Int_t nrow = 0;
3679    GL_RUN* this_run = new GL_RUN();    GL_RUN* this_run = new GL_RUN();
3680    GL_RUN* next_run = new GL_RUN();    GL_RUN* next_run = new GL_RUN();
# Line 3517  Int_t PamelaDBOperations::ValidateRuns() Line 3688  Int_t PamelaDBOperations::ValidateRuns()
3688    UInt_t t1=0,t2=0;    UInt_t t1=0,t2=0;
3689    // ---------------------------------------------------------------------------------    // ---------------------------------------------------------------------------------
3690    // - loop over runs, back in time,    // - loop over runs, back in time,
3691    // - select sequences of runs close in time (less than 60 s apart),    // - select sequences of runs close in time (less than calibtime s apart),
3692    //   which could be preceeded by a calibration    //   which could be preceeded by a calibration
3693    // - check if there might be a missing calibration    // - check if there might be a missing calibration
3694    // ---------------------------------------------------------------------------------    // ---------------------------------------------------------------------------------
# Line 3557  Int_t PamelaDBOperations::ValidateRuns() Line 3728  Int_t PamelaDBOperations::ValidateRuns()
3728                                                        
3729                            if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0;     //=> run fragments                            if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0;     //=> run fragments
3730                                                        
3731                            if( interval >= 60 )CHECK = true;                     //more than 60 s => there might be a calibration                            if( interval >= calibtime )CHECK = true;                      //more than calibtime s => there might be a calibration
3732                                                        
3733                            if( !CHECK && this_run->VALIDATION ){                            if( !CHECK && this_run->VALIDATION ){
3734                                    for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);                                    for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
# Line 3755  Int_t PamelaDBOperations::populateTLE()/ Line 3926  Int_t PamelaDBOperations::populateTLE()/
3926    
3927    
3928  // Insert tle in the table GL_TLE using the connection conn.  // Insert tle in the table GL_TLE using the connection conn.
3929  int PamelaDBOperations::insertTle(cTle *tle)  Int_t PamelaDBOperations::insertTle(cTle *tle)
3930  {  {
3931    stringstream oss;    stringstream oss;
3932    TSQLResult *result = 0;    TSQLResult *result = 0;
# Line 3838  string getTleDatetime(cTle *tle) Line 4009  string getTleDatetime(cTle *tle)
4009    
4010    return date.str();    return date.str();
4011  }  }
4012    
4013    /**
4014     * Remove a file from the DB, delete on cascade all entries related to that file
4015     * rearrange GL_RUN and GL_XXX_CALIB tables, turn off validation till the following
4016     * calibration
4017     **/
4018    Int_t PamelaDBOperations::removeFile(TString remfile){
4019      //
4020      // Determine ID_ROOT_L0 and ID_RAW
4021      //
4022      TSQLResult *pResult;
4023      TSQLRow *Row;
4024      stringstream myquery;
4025      //  
4026      myquery.str("");
4027      myquery << " SELECT ID, ID_RAW FROM GL_ROOT where NAME='"<<remfile.Data() <<"';";
4028      //
4029      pResult = conn->Query(myquery.str().c_str());
4030      //
4031      Row = pResult->Next();      
4032      if( !Row ){
4033        if ( strcmp(remfile.Data(),GetRootName().Data()) ){
4034          if ( IsDebug() ) printf(" No file to be removed even if option \"-remove file\" was used!!\n");
4035          return(1);
4036        };
4037        if ( IsDebug() ) printf(" No file to be removed (force mode)! \n");
4038        return(0);
4039      };
4040      //
4041      this->SetID_ROOT((UInt_t)atoll(Row->GetField(0)));
4042      this->SetID_RAW((UInt_t)atoll(Row->GetField(1)));
4043      //
4044      this->ValidationOFF();
4045      //
4046      this->RemoveCALIBS();
4047      //
4048      this->RemoveRUNS();
4049      //
4050      this->RemoveFILES();
4051      //
4052      this->SetID_ROOT(0);
4053      this->SetID_RAW(0);
4054      //
4055      return(0);
4056    };
4057    
4058    /**
4059     *
4060     * Set validation bit to zero for runs following the removing file till
4061     * 1) a run with TRK_CALIB_USED=140
4062     * 2) a run with VALIDATION = 0
4063     * 3) the next calibration
4064     *
4065     **/
4066    void PamelaDBOperations::ValidationOFF(){
4067      TSQLResult *pResult;
4068      TSQLRow *Row;
4069      stringstream myquery;
4070      Int_t unv = 0;
4071      //select ID from GL_RUN where RUNHEADER_TIME>=1152671382 AND (VALIDATION=0 OR TRK_CALIB_USED=104) order by RUNHEADER_TIME asc limit 1;
4072      myquery.str("");
4073      myquery << " SELECT MAX(RUNTRAILER_TIME) FROM GL_RUN WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";";
4074      //
4075      pResult = conn->Query(myquery.str().c_str());
4076      //
4077      Row = pResult->Next();      
4078      if( !Row->GetField(0) ){
4079        //
4080        if ( IsDebug() ) printf(" NO RUN ASSOCIATED TO THIS FILE! \n");
4081        //
4082      } else {  
4083        //
4084        UInt_t runhtime = (UInt_t)atoll(Row->GetField(0));
4085        UInt_t caltime = 0;
4086        //
4087        myquery.str("");
4088        myquery << " SELECT FROM_TIME FROM GL_TRK_CALIB where FROM_TIME>" <<runhtime;
4089        myquery << " order by FROM_TIME asc limit 1;";
4090        //
4091        if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
4092        //
4093        //
4094        delete pResult;
4095        pResult = conn->Query(myquery.str().c_str());
4096        //
4097        Row = pResult->Next();      
4098        if( !Row ){
4099          caltime = runhtime;
4100        } else {
4101          caltime = (UInt_t)atoll(Row->GetField(0));
4102        };
4103        //
4104        myquery.str("");
4105        myquery << " SELECT ID,RUNHEADER_TIME from GL_RUN where RUNHEADER_TIME>="<< runhtime <<" AND (VALIDATION=0 OR TRK_CALIB_USED=104 OR RUNHEADER_TIME>" ;
4106        myquery << caltime << ") order by RUNHEADER_TIME asc LIMIT 1";
4107        //
4108        if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
4109        //
4110        pResult = conn->Query(myquery.str().c_str());
4111        //
4112        Row = pResult->Next();      
4113        if( !Row ){
4114          //
4115          if ( IsDebug() ) printf(" NO RUN NEED TO BE UNVALIDATED \n");
4116          //
4117        } else {
4118          myquery.str("");
4119          myquery << " SELECT ID from GL_RUN where RUNHEADER_TIME<"<< Row->GetField(1) <<" AND ";
4120          myquery << " RUNHEADER_TIME>=" <<runhtime;
4121          myquery << " order by RUNHEADER_TIME asc;";
4122          //
4123          if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
4124          //
4125          pResult = conn->Query(myquery.str().c_str());
4126          //
4127          Row = pResult->Next();  
4128          while ( Row ){
4129            //      
4130            unv++;
4131            this->assignVALIDATION((UInt_t)atoll(Row->GetField(0)), false);
4132            Row = pResult->Next();  
4133            //
4134          };
4135        };
4136      };
4137      if ( IsDebug() ) printf(" %i runs have been unvalidated \n",unv);
4138    };
4139    
4140    /**
4141     *
4142     * Rearrange GL_RUN table and remove runs
4143     *
4144     **/
4145    void PamelaDBOperations::RemoveRUNS(){
4146      TSQLResult *pResult;
4147      TSQLRow *Row;
4148      stringstream myquery;
4149      UInt_t drun = 0;
4150      GL_RUN *delrun = new GL_RUN();
4151      //
4152      myquery.str("");
4153      myquery << " SELECT ID FROM GL_RUN where ID_RUN_FRAG=0 and ID_ROOT_L0=" <<this->GetID_ROOT() <<";";
4154      //
4155      if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
4156      //
4157      pResult = conn->Query(myquery.str().c_str());
4158      //
4159      Row = pResult->Next();    
4160      //
4161      //
4162      if ( !Row ){
4163        if ( IsDebug() ) printf(" No run with ID_RUN_FRAG=0 belonged to this file \n");
4164      } else {
4165        if ( IsDebug() ) printf(" Deleting run from GL_RUN table \n");    
4166        while ( Row ){
4167          delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN");
4168          if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0)));
4169          drun++;
4170          Row = pResult->Next();    
4171        };
4172      };
4173      //
4174      //
4175      myquery.str("");
4176      myquery << " SELECT ID,ID_RUN_FRAG FROM GL_RUN where ID_RUN_FRAG!=0 and ID_ROOT_L0=" <<this->GetID_ROOT() <<";";
4177      //
4178      if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
4179      //
4180      pResult = conn->Query(myquery.str().c_str());
4181      //
4182      Row = pResult->Next();    
4183      //
4184      if ( !Row ){
4185        if ( IsDebug() ) printf(" No run with ID_RUN_FRAG!=0 belonged to this file \n");
4186      } else {
4187        if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN table \n");    
4188        while ( Row ){
4189          if ( IsDebug() ) printf(" restore run %i \n",(UInt_t)atoll(Row->GetField(1)));
4190          delrun->RestoreRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN_FRAGMENTS");
4191          if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(1)));
4192          delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN");
4193          if ( (UInt_t)atoll(Row->GetField(1)) != (UInt_t)atoll(Row->GetField(0)) ){
4194            if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0)));
4195            delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN");
4196          };
4197          drun++;
4198          Row = pResult->Next();    
4199        };
4200      };
4201      //
4202      if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN table \n",drun);    
4203      //
4204      //
4205      //
4206      drun = 0;
4207      //
4208      myquery.str("");
4209      myquery << " SELECT ID_TRASH FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID_ROOT_L0=" <<this->GetID_ROOT() <<";";
4210      //
4211      pResult = conn->Query(myquery.str().c_str());
4212      //
4213      Row = pResult->Next();    
4214      //
4215      if ( !Row ){
4216        if ( IsDebug() ) printf(" No run from GL_RUN_FRAGMENTS table in the trash table for this file \n");
4217      } else {
4218        if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_TRASH table \n");    
4219        while ( Row ){
4220          if ( IsDebug() ) printf(" del run idtrash %i \n",(UInt_t)atoll(Row->GetField(0)));
4221          myquery.str("");
4222          myquery << " DELETE FROM GL_RUN_TRASH where ID_TRASH=" << Row->GetField(0) <<";";      
4223          conn->Query(myquery.str().c_str());
4224          drun++;
4225          Row = pResult->Next();    
4226        };
4227      };
4228      //  
4229      if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_TRASH table \n",drun);    
4230      //
4231      //
4232      //
4233      drun = 0;
4234      //
4235      myquery.str("");
4236      myquery << " SELECT ID FROM GL_RUN_FRAGMENTS where ID_ROOT_L0=" <<this->GetID_ROOT() <<";";
4237      //
4238      pResult = conn->Query(myquery.str().c_str());
4239      //
4240      Row = pResult->Next();    
4241      //
4242      if ( !Row ){
4243        if ( IsDebug() ) printf(" No run in the GL_RUN_FRAGMENTS table for this file \n");
4244      } else {
4245        if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_FRAGMENTS table \n");    
4246        while ( Row ){
4247          if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0)));
4248          myquery.str("");
4249          myquery << " DELETE FROM GL_RUN_FRAGMENTS where ID=" << Row->GetField(0) <<";";
4250          conn->Query(myquery.str().c_str());
4251          drun++;
4252          Row = pResult->Next();    
4253        };
4254      };
4255      //  
4256      if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_FRAGMENTS table \n",drun);    
4257      //
4258      //
4259      //
4260      delete delrun;
4261      //
4262    };
4263    
4264    
4265    /**
4266     *
4267     * Rearrange calibration tables
4268     *
4269     **/
4270    void PamelaDBOperations::RemoveFILES(){
4271      stringstream myquery;
4272      //
4273      myquery.str("");
4274      myquery << " DELETE FROM GL_RAW WHERE ID=" <<this->GetID_RAW() <<";";
4275      //
4276      if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
4277      //
4278      conn->Query(myquery.str().c_str());
4279      //
4280    };
4281    
4282    /**
4283     *
4284     * Rearrange calibration tables
4285     *
4286     **/
4287    void PamelaDBOperations::RemoveCALIBS(){
4288      TSQLResult *pResult;
4289      TSQLRow *Row;
4290      stringstream myquery;
4291      //  
4292      //
4293      // Calorimeter
4294      //
4295      for (Int_t section = 0; section < 4; section++){
4296        myquery.str("");
4297        myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_CALO_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<" AND ";
4298        myquery << " SECTION=" << section << ";";
4299        //
4300        pResult = conn->Query(myquery.str().c_str());
4301        //
4302        Row = pResult->Next();      
4303        if( !Row->GetField(0) || !Row->GetField(1) ){
4304          //
4305          if ( IsDebug() ) printf(" NO CALO CALIBRATION SECTION %i ASSOCIATED TO THIS FILE! \n",section);
4306          //
4307        } else {
4308          //
4309          myquery.str("");
4310          myquery << " UPDATE GL_CALO_CALIB SET TO_TIME=" << Row->GetField(1);
4311          myquery << " WHERE TO_TIME="<< Row->GetField(0) << " AND ";
4312          myquery << " SECTION=" << section << ";";
4313          //
4314          pResult = conn->Query(myquery.str().c_str());
4315          //
4316          if( !pResult ){
4317            //
4318            if ( IsDebug() ) printf(" ERROR DELETING CALO CALIBRATIONS \n");
4319            //
4320            throw -4;
4321            //
4322          };
4323          //
4324        };
4325      };
4326      myquery.str("");
4327      myquery << " DELETE FROM GL_CALO_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT();
4328      //
4329      pResult = conn->Query(myquery.str().c_str());
4330      //
4331      if( !pResult ){
4332        //
4333        if ( IsDebug() ) printf(" ERROR DELETING CALO CALIBRATIONS \n");
4334        //
4335        throw -4;
4336        //
4337      };
4338      //
4339      // Tracker
4340      //
4341      myquery.str("");
4342      myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_TRK_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";";
4343      //
4344      pResult = conn->Query(myquery.str().c_str());
4345      //
4346      Row = pResult->Next();      
4347      if( !Row->GetField(0) || !Row->GetField(1) ){
4348        //
4349        if ( IsDebug() ) printf(" NO TRK CALIBRATION ASSOCIATED TO THIS FILE! \n");
4350        //
4351      } else {
4352        //
4353        myquery.str("");
4354        myquery << " UPDATE GL_TRK_CALIB SET TO_TIME=" << Row->GetField(1);
4355        myquery << " WHERE TO_TIME="<< Row->GetField(0) << ";";
4356        //
4357        pResult = conn->Query(myquery.str().c_str());
4358        //
4359        if( !pResult ){
4360          //
4361          if ( IsDebug() ) printf(" ERROR DELETING TRK CALIBRATIONS \n");
4362          //
4363          throw -4;
4364          //
4365        };
4366        //
4367        myquery.str("");
4368        myquery << " DELETE FROM GL_TRK_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT();
4369        //
4370        pResult = conn->Query(myquery.str().c_str());
4371        //
4372        if( !pResult ){
4373          //
4374          if ( IsDebug() ) printf(" ERROR DELETING TRK CALIBRATIONS \n");
4375          //
4376          throw -4;
4377          //
4378        };
4379      };
4380      //
4381      //
4382      // S4
4383      //
4384      myquery.str("");
4385      myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_S4_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";";
4386      //
4387      pResult = conn->Query(myquery.str().c_str());
4388      //
4389      Row = pResult->Next();      
4390      if( !Row->GetField(0) || !Row->GetField(1) ){
4391        //
4392        if ( IsDebug() ) printf(" NO S4 CALIBRATION ASSOCIATED TO THIS FILE! \n");
4393        //
4394      } else {
4395        //
4396        myquery.str("");
4397        myquery << " UPDATE GL_S4_CALIB SET TO_TIME=" << Row->GetField(1);
4398        myquery << " WHERE TO_TIME="<< Row->GetField(0) << ";";
4399        //
4400        pResult = conn->Query(myquery.str().c_str());
4401        //
4402        if( !pResult ){
4403          //
4404          if ( IsDebug() ) printf(" ERROR DELETING S4 CALIBRATIONS \n");
4405          //
4406          throw -4;
4407          //
4408        };
4409        //
4410        myquery.str("");
4411        myquery << " DELETE FROM GL_S4_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT();
4412        //
4413        pResult = conn->Query(myquery.str().c_str());
4414        //
4415        if( !pResult ){
4416          //
4417          if ( IsDebug() ) printf(" ERROR DELETING S4 CALIBRATIONS \n");
4418          //
4419          throw -4;
4420          //
4421        };
4422        //
4423      };
4424    };
4425    /**
4426     *
4427     * Rearrange calibration tables
4428     *
4429     **/
4430    UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){
4431    
4432        Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0};
4433        UInt_t timeaftercalib=120000; //2000;
4434    //  ----------
4435    //  Check CRCs
4436    //  ----------
4437        for(Int_t ipkt=0; ipkt<6; ipkt++){
4438            if( caltrk->crc_hcal[ipkt] )return 0; // :-(
4439            for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-(
4440        }
4441    //  -----------------------
4442    //  Check missing packets:
4443    //  -----------------------
4444    //    Readout order:
4445    //    ------------------
4446    //    DSP   packet board
4447    //    ------------------
4448    //    12    0      1
4449    //    10    1      1
4450    //     8    2      1
4451    //     4    3      1
4452    //     6    4      1
4453    //     2    5      1
4454    //    ------------------
4455    //    11    0      2
4456    //     9    1      2
4457    //     7    2      2
4458    //     3    3      2
4459    //     5    4      2
4460    //     1    5      2
4461    //    ------------------
4462    //  -------------------------------------------------
4463    //  Check if it is first or second calibration packet
4464    //  -------------------------------------------------
4465        UInt_t build=0;
4466        TString classname = caltrk->GetName();
4467        UInt_t base=0;
4468        UInt_t mask=0;
4469        if(classname.Contains("CalibTrk1Event")){
4470            base=12;
4471            mask=0x03F000;
4472        }
4473        if(classname.Contains("CalibTrk2Event")){
4474            base=18;
4475            mask=0xFC0000;
4476        }
4477    //  -------------------------------------------------
4478    //  Count number of packets and set build variable
4479    //  -------------------------------------------------
4480        Int_t  npkts=0;
4481        for(Int_t ipkt=0; ipkt<6; ipkt++){
4482            if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){
4483                npkts++;
4484                build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );
4485            }
4486        }
4487    //    if( npkts==6 )return 1; // :-)
4488    
4489    //    cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;
4490    
4491    //  -----------------------------------------------
4492    //  If missing packets: check the acq configuration
4493    //  (some DSPs might be excluded from acquisition)
4494    //  -----------------------------------------------
4495    
4496    //  -----------------------------------------------
4497    //  retrieve the first run header after calib
4498    //  -----------------------------------------------
4499         PacketType *pctp;
4500         EventCounter *cod;
4501         cod = eh->GetCounter();
4502         Int_t irun = cod->Get(pctp->RunHeader);
4503         TTree *rh=(TTree*)file->Get("RunHeader");
4504         if ( !rh || rh->IsZombie() ) throw -17;
4505         if( rh->GetEntries() == irun ){
4506              if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1)  -- cannot validate :-( "<<endl;
4507             return 0; // :-(
4508         }
4509    
4510         RunHeaderEvent *run  = 0;
4511         EventHeader    *hrun = 0;
4512         rh->SetBranchAddress("RunHeader", &run);
4513         rh->SetBranchAddress("Header", &hrun);
4514         rh->GetEntry(irun);
4515    //     cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl;
4516    
4517         if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){
4518              if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl;
4519             return 0; // :-(
4520         }
4521        
4522         if( !run->RM_ACQ_AFTER_CALIB ){
4523              if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0    -- cannot validate :-( "<<endl;
4524             return 0; // :-(
4525         }
4526    
4527         UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime());
4528         if( dtime > timeaftercalib ){
4529             if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl;
4530             return 0; // :-(
4531         }
4532        
4533    
4534    
4535         if( (run->ACQ_BUILD_INFO & mask) != build ){
4536             if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl;
4537             return 0; // :-(
4538         }
4539         return 1; // :-)
4540    
4541    }

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.22

  ViewVC Help
Powered by ViewVC 1.1.23