/[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.20 by mocchiut, Mon Nov 20 09:11:58 2006 UTC revision 1.27 by mocchiut, Mon Feb 12 13:32:18 2007 UTC
# Line 56  string getTleDatetime(cTle*); Line 56  string getTleDatetime(cTle*);
56   * @param debug        debug flag.   * @param debug        debug flag.
57   * @param tlefilename  ascii file with TLE 3 line elements.   * @param tlefilename  ascii file with TLE 3 line elements.
58   */   */
59  PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename){  PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename, UInt_t dwinput){
60    //    //
61    //    //
62    SetConnection(host,user,password);    SetConnection(host,user,password);
# Line 79  PamelaDBOperations::PamelaDBOperations(T Line 79  PamelaDBOperations::PamelaDBOperations(T
79    INSERT_ROOT = !filerootname.IsNull();    INSERT_ROOT = !filerootname.IsNull();
80    if( INSERT_ROOT ){    if( INSERT_ROOT ){
81      this->SetRootName(filerootname);      this->SetRootName(filerootname);
82      this->SetOrbitNo();      this->SetOrbitNo(dwinput);
83      file = TFile::Open(this->GetRootName().Data());      file = TFile::Open(this->GetRootName().Data());
84    } else {    } else {
85      this->SetRootName("");      this->SetRootName("");
# Line 157  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   * Set the nofrag flag
169   *   *
170   */   */
# Line 207  void PamelaDBOperations::SetRootName(TSt Line 215  void PamelaDBOperations::SetRootName(TSt
215  /**  /**
216   * Store the downlink orbit number from filename.   * Store the downlink orbit number from filename.
217   */   */
218  void PamelaDBOperations::SetOrbitNo(){  void PamelaDBOperations::SetOrbitNo(UInt_t dwinput){
219    dworbit = 0;    dworbit = 0;
220      //
221      if ( dwinput ){
222        dworbit = dwinput;
223        if ( IsDebug() ) printf(" Downlink orbit given by hand: %i  \n",dworbit);
224        return;
225      };
226      //
227    TString name = this->GetRootFile();    TString name = this->GetRootFile();
228    Int_t nlength = name.Length();    Int_t nlength = name.Length();
229    if ( nlength < 5 ) return;    if ( nlength < 5 ) return;
# Line 265  Bool_t PamelaDBOperations::SetID_RAW(){ Line 280  Bool_t PamelaDBOperations::SetID_RAW(){
280    oss << "SELECT ID FROM GL_RAW WHERE "    oss << "SELECT ID FROM GL_RAW WHERE "
281        << " PATH = '" << this->GetRawPath().Data() << "' AND "        << " PATH = '" << this->GetRawPath().Data() << "' AND "
282        << " NAME = '" << this->GetRawFile().Data() << "' ";        << " NAME = '" << this->GetRawFile().Data() << "' ";
283    
284    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
285    if ( result == NULL ) throw -4;    if ( result == NULL ) throw -4;
286    row = result->Next();    row = result->Next();
# Line 295  Int_t PamelaDBOperations::SetUpperLimits Line 311  Int_t PamelaDBOperations::SetUpperLimits
311    UInt_t nevent = 0;    UInt_t nevent = 0;
312    UInt_t pktlast = 0;    UInt_t pktlast = 0;
313    UInt_t obtlast = 0;    UInt_t obtlast = 0;
314    UInt_t t_pktlast = 0;    Long64_t t_pktlast = 0LL;
315    UInt_t t_obtlast = 0;    //  UInt_t t_obtlast = 0;
316    UInt_t upperpkt2 = 0;    Long64_t t_obtlast = 0LL;
317    ULong64_t upperobt2 = 0;    Long64_t upperpkt2 = 0LL;
318      Long64_t upperobt2 = 0LL;
319    UInt_t zomp = 0;    UInt_t zomp = 0;
320    UInt_t jump = 50000; // was 5000    UInt_t jump = 50000; // was 5000
321    EventCounter *code=0;    EventCounter *code=0;
322    //    //
323    UInt_t deltapkt = 5000;    Long64_t deltapkt = 5000LL;
324    ULong64_t deltaobt = 50000;    Long64_t deltaobt = 50000LL;
325    //    //
326    //   pcksList packetsNames;    //   pcksList packetsNames;
327    //   pcksList::iterator Iter;    //   pcksList::iterator Iter;
# Line 342  Int_t PamelaDBOperations::SetUpperLimits Line 359  Int_t PamelaDBOperations::SetUpperLimits
359    upperobt = OBT(obtlast);    upperobt = OBT(obtlast);
360    upperentry = nevent-1;    upperentry = nevent-1;
361    //    //
362    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);
363    //    //
364    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);
365    //    //
366    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);
367    //    //
368    if ( !nevent ) return(2);    if ( !nevent ) return(2);
369    //    //
370    if ( nevent < 2 ) return(4);    if ( nevent < 2 ) return(4);
371      if ( nevent < jump ) jump = 1;
372      //  if ( nevent < jump ) jump = int(nevent/10);
373      //  if ( !jump ) jump = 1;
374    //    //
375    if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) ){    if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) && nevent > deltapkt ){
376      //      //
377        if ( IsDebug() ) printf(" starting jump %i \n",jump);
378      // go back      // go back
379      zomp = nevent - 2;      zomp = nevent - 2;
380      //      //
# Line 375  Int_t PamelaDBOperations::SetUpperLimits Line 396  Int_t PamelaDBOperations::SetUpperLimits
396          upperpkt2 = PKT(ph->GetCounter());          upperpkt2 = PKT(ph->GetCounter());
397          upperobt2 = OBT(ph->GetOrbitalTime());          upperobt2 = OBT(ph->GetOrbitalTime());
398          //          //
399          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) ){
400              if ( IsDebug() ) printf(" .-. upperpkt2 %lld upperobt2 %lld \n",upperpkt2,upperobt2);  
401              if ( IsDebug() ) printf(" .-. upperpkt %lld t_pktlast %lld upperobt %lld t_obtlast %lld \n",upperpkt,t_pktlast,upperobt,t_obtlast);    
402              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);    
403              throw -13;    
404            };
405          //          //
406          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 ){
407            zomp = i + jump + 1;            zomp = i + jump + 1;
408            if ( zomp > nevent-2 ) zomp = nevent - 2;            if ( zomp > nevent-2 ) zomp = nevent - 2;
409            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);
410            break;            break;
411          };          };
412          //          //
# Line 415  Int_t PamelaDBOperations::SetUpperLimits Line 441  Int_t PamelaDBOperations::SetUpperLimits
441    //    //
442    rhev = rh->GetEntries();    rhev = rh->GetEntries();
443    rtev = rt->GetEntries();    rtev = rt->GetEntries();
444    UInt_t sobtt = 0;    Long64_t sobtt = 0LL;
445    UInt_t sobth = 0;    Long64_t sobth = 0LL;
446    UInt_t spktt = 0;    Long64_t spktt = 0LL;
447    UInt_t spkth = 0;    Long64_t spkth = 0LL;
448    UInt_t pktt = 0;    Long64_t pktt = 0LL;
449    ULong64_t obtt = 0;    Long64_t obtt = 0LL;
450    UInt_t pkth = 0;    Long64_t pkth = 0LL;
451    ULong64_t obth = 0;    Long64_t obth = 0LL;
452    //    //
453      if ( rhev || rtev ){
454    
455    
456    T->GetEntry(upperentry);    T->GetEntry(upperentry);
457    code = eh->GetCounter();    code = eh->GetCounter();
458    Int_t lasttrail = code->Get(pctp->RunTrailer);    Int_t lasttrail = code->Get(pctp->RunTrailer);
# Line 442  Int_t PamelaDBOperations::SetUpperLimits Line 471  Int_t PamelaDBOperations::SetUpperLimits
471      obth = OBT(phh->GetOrbitalTime());      obth = OBT(phh->GetOrbitalTime());
472    };    };
473    //    //
474    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);
475    if ( pkth > upperpkt && obth > upperobt ){    if ( pkth > upperpkt && obth > upperobt ){
476      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);
477      upperpkt = pkth;      upperpkt = pkth;
478      upperobt = obth;      upperobt = obth;
479      rhev = lasthead+1;      rhev = lasthead+1;
480    } else {    } else {
481      rhev = lasthead;      rhev = lasthead;
482    };    };
483    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);
484    //    //
485    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);
486    if ( pktt > upperpkt && obtt > upperobt ){    if ( pktt > upperpkt && obtt > upperobt ){
487      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);
488      upperpkt = pktt;      upperpkt = pktt;
489      upperobt = obtt;      upperobt = obtt;
490      rtev = lasttrail+1;      rtev = lasttrail+1;
491    } else {    } else {
492      rtev = lasttrail;      rtev = lasttrail;
493    };    };
494    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);
495    //  goto kikko;    //  goto kikko;
496    //    //
497    //    //
498    // Check if runtrailer/runheader are within lower limits    // Check if runtrailer/runheader are within lower limits
499    //    //
500    //    //
501    pkth = 0;    pkth = 0LL;
502    obth = 0;    obth = 0LL;
503    spkth = 0;    spkth = 0LL;
504    sobth = 0;    sobth = 0LL;
505    for (Int_t k=0; k<rhev; k++){    for (Int_t k=0; k<rhev; k++){
506      if ( k > 0 ){      if ( k > 0 ){
507        spkth = pkth;        spkth = pkth;
# Line 520  Int_t PamelaDBOperations::SetUpperLimits Line 549  Int_t PamelaDBOperations::SetUpperLimits
549            upperentry = evbefh-1;            upperentry = evbefh-1;
550          };              };    
551        };        };
552        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);
553        goto kikko0;        goto kikko0;
554      };      };
555    };    };
# Line 528  Int_t PamelaDBOperations::SetUpperLimits Line 557  Int_t PamelaDBOperations::SetUpperLimits
557    //    //
558    //    //
559    //    //
560    pktt = 0;    pktt = 0LL;
561    obtt = 0;    obtt = 0LL;
562    spktt = 0;    spktt = 0LL;
563    sobtt = 0;    sobtt = 0LL;
564    for (Int_t k=0; k<rtev; k++){    for (Int_t k=0; k<rtev; k++){
565      if ( k > 0 ){      if ( k > 0 ){
566        spktt = pktt;        spktt = pktt;
# Line 551  Int_t PamelaDBOperations::SetUpperLimits Line 580  Int_t PamelaDBOperations::SetUpperLimits
580        rt->GetEntry(rtev);        rt->GetEntry(rtev);
581        pktt = spktt;        pktt = spktt;
582        obtt = sobtt;        obtt = sobtt;
583        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);
584        //        //
585        UInt_t evbeft = 0;        UInt_t evbeft = 0;
586        code = eht->GetCounter();        code = eht->GetCounter();
# Line 580  Int_t PamelaDBOperations::SetUpperLimits Line 609  Int_t PamelaDBOperations::SetUpperLimits
609            upperentry = evbeft-1;            upperentry = evbeft-1;
610          };          };
611        };        };
612        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);
613        goto kikko;        goto kikko;
614        //      break;        //      break;
615        //        //
# Line 608  Int_t PamelaDBOperations::SetUpperLimits Line 637  Int_t PamelaDBOperations::SetUpperLimits
637      obth = OBT(phh->GetOrbitalTime());      obth = OBT(phh->GetOrbitalTime());
638    };    };
639    //    //
640    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);
641    if ( pkth > upperpkt && obth > upperobt ){    if ( pkth > upperpkt && obth > upperobt ){
642      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);
643      upperpkt = pkth;      upperpkt = pkth;
644      upperobt = obth;      upperobt = obth;
645      rhev = lasthead+1;      rhev = lasthead+1;
646    } else {    } else {
647      rhev = lasthead;      rhev = lasthead;
648    };    };
649    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);
650    //    //
651    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);
652    if ( pktt > upperpkt && obtt > upperobt ){    if ( pktt > upperpkt && obtt > upperobt ){
653      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);
654      upperpkt = pktt;      upperpkt = pktt;
655      upperobt = obtt;      upperobt = obtt;
656      rtev = lasttrail+1;      rtev = lasttrail+1;
657    } else {    } else {
658      rtev = lasttrail;      rtev = lasttrail;
659    };    };
660    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);
661    //    //
662    if ( IsDebug() ) printf(" Upper limits are: OBT %llu pkt_num %i upper entry %i \n",upperobt,upperpkt,upperentry);  
663    
664      };
665      //
666      if ( IsDebug() ) printf(" Upper limits are: OBT %lld pkt_num %lld upper entry %i \n",upperobt,upperpkt,upperentry);
667    //    //
668    return(0);    return(0);
669  }  }
# Line 764  void PamelaDBOperations::CheckConnection Line 797  void PamelaDBOperations::CheckConnection
797    if( !conn ) throw -1;    if( !conn ) throw -1;
798    bool connect = conn->IsConnected();    bool connect = conn->IsConnected();
799    if( !connect ) throw -1;    if( !connect ) throw -1;
800      //
801      if ( IsDebug() ) printf("\n DB INFORMATIONS:\n SQL: %s Version: %s Host %s Port %i \n\n",conn->GetDBMS(),conn->ServerInfo(),conn->GetHost(),conn->GetPort());
802      //
803    if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27;    if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27;
804    //    //
805    // set DB timezone to UTC    // set DB timezone to UTC
# Line 775  void PamelaDBOperations::CheckConnection Line 811  void PamelaDBOperations::CheckConnection
811    TSQLResult *result = 0;    TSQLResult *result = 0;
812    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
813    if ( !result ) throw -10;    if ( !result ) throw -10;
814      oss.str("");
815      oss << "SET wait_timeout=173000;";
816      conn->Query(oss.str().c_str());
817    //    //
818  };  };
819    
820  /**  /**
821   * Return the correct packet number if we went back to zero   * Return the correct packet number if we went back to zero
822   */   */
823  UInt_t PamelaDBOperations::PKT(UInt_t pkt_num){    Long64_t PamelaDBOperations::PKT(UInt_t pkt_num){  
824    //    //
825    //  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));
826    //    //
827    if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2)  ) return((pkt_num+16777215));    if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2)  ){
828        if ( IsDebug() ) printf(" rise up pktnum %lld \n",(Long64_t)pkt_num+16777215LL);
829        return((Long64_t)pkt_num+16777215LL);
830      };
831    //    //
832    if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){    if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){
833      if ( (pkt_num-16777215) < 0 ){      if ( IsDebug() ) printf(" rise down pktnum %lld \n",(Long64_t)pkt_num-16777215LL);
834        return((16777215-pkt_num));      return((Long64_t)pkt_num-16777215LL);
     } else {  
       return((pkt_num-16777215));  
     };  
835    };    };
836    //    //
837    return(pkt_num);    if ( IsDebug() ) printf(" as it is %lld \n",(Long64_t)pkt_num);
838      return((Long64_t)pkt_num);
839    //    //
840  };  };
841    
842  /**  /**
843   * Return the correct On Board Time if we went back to zero   * Return the correct On Board Time if we went back to zero
844   */   */
845  ULong64_t PamelaDBOperations::OBT(UInt_t obt){    Long64_t PamelaDBOperations::OBT(UInt_t obt){  
846    //    //
847    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()));
848    //    //
849    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
850      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()));  
     };  
851    };    };
852    //    //
853    return((ULong64_t)obt);    return((Long64_t)obt);
854  };  };
855    
856  /**  /**
# Line 993  Int_t PamelaDBOperations::insertPamelaGL Line 1029  Int_t PamelaDBOperations::insertPamelaGL
1029    if ((row != NULL) && ((UInt_t)atoll(row->GetField(0)) > 0)){    if ((row != NULL) && ((UInt_t)atoll(row->GetField(0)) > 0)){
1030      if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);      if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);
1031      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;
1032        //
1033        tsync = (UInt_t)atoll(row->GetField(2));
1034        obt0 = (UInt_t)atoll(row->GetField(1));
1035        //
1036      return(1);      return(1);
1037    };    };
1038    //    //
# Line 1189  Int_t PamelaDBOperations::insertPamelaGL Line 1229  Int_t PamelaDBOperations::insertPamelaGL
1229    if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);    if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);
1230    toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0;    toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0;
1231    //    //
1232      tsync = TSYNC;
1233      obt0 = OBT;
1234      //
1235    delete result;    delete result;
1236    return(signal);    return(signal);
1237  }  }
# Line 1288  Int_t PamelaDBOperations::assignBOOT_NUM Line 1331  Int_t PamelaDBOperations::assignBOOT_NUM
1331    VarDumpEvent  *vde = 0;    VarDumpEvent  *vde = 0;
1332    VarDumpRecord *vdr = 0;    VarDumpRecord *vdr = 0;
1333    //    //
1334      Bool_t found = false;
1335    trDumpEv->SetBranchAddress("VarDump", &vde);    trDumpEv->SetBranchAddress("VarDump", &vde);
1336    if ( trDumpEv->GetEntries() > 0 ){    if ( trDumpEv->GetEntries() > 0 ){
1337      Bool_t found = false;      found = false;
1338      for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){      for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){
1339        trDumpEv->GetEntry(i);        trDumpEv->GetEntry(i);
1340        //      vde->Records->GetEntries();        //      vde->Records->GetEntries();
# Line 1307  Int_t PamelaDBOperations::assignBOOT_NUM Line 1351  Int_t PamelaDBOperations::assignBOOT_NUM
1351        this->SetBOOTnumber((Int_t)vdr->VAR_VALUE);        this->SetBOOTnumber((Int_t)vdr->VAR_VALUE);
1352        //        //
1353      } else {      } else {
1354        if ( !this->GetBOOTnumber() ) return(4);        if ( !this->GetBOOTnumber() && !this->AutoBoot()) return(4);
1355        };
1356      } else {
1357        if ( !this->GetBOOTnumber() && !this->AutoBoot()) return(2);
1358      };
1359      //
1360      UInt_t bn = 0;
1361      Bool_t afound = false;
1362      if ( !found && this->AutoBoot()){
1363        afound = true;
1364        //
1365        // Search for other files with similar timesync
1366        //
1367        if ( IsDebug() ) printf(" tsync %u obt0 %u \n",tsync,obt0);
1368        UInt_t upperts = tsync-(obt0/1000)+5;
1369        UInt_t lowerts = tsync-(obt0/1000)-5;
1370        oss.str("");
1371        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)<"
1372            << upperts
1373            << " AND TIMESYNC-(OBT0/1000)>"
1374            << lowerts
1375            << " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;";
1376        result = conn->Query(oss.str().c_str());
1377        if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to find boot number:\n %s \n",oss.str().c_str());
1378        //
1379        if ( !result ) throw -4;;
1380        found = true;
1381        if ( result->GetRowCount()<3 ){
1382          if ( IsDebug() ) printf(" AGH! no results!\n");
1383          found = false;
1384        } else {
1385          row = result->Next();      
1386          bn = (UInt_t)atoll(row->GetField(0));
1387          for ( Int_t r=1; r<result->GetRowCount() ;r++){
1388            if ( !row ) throw -4;
1389            if ( IsDebug() ) printf(" BOOT number is %s \n",row->GetField(0));
1390            if ( bn != (UInt_t)atoll(row->GetField(0)) ){
1391              if ( IsDebug() ) printf(" AGH! bn = %u here instead %u \n",bn,(UInt_t)atoll(row->GetField(0)));
1392              found = false;
1393            };
1394            row = result->Next();
1395          };
1396      };      };
1397      };
1398      //
1399      Int_t sgn = 0;
1400      //
1401      if ( !found && !BOOTNO ){
1402        throw -29;
1403    } else {    } else {
1404      if ( !this->GetBOOTnumber() ) return(2);      if ( afound ){
1405          this->SetBOOTnumber(bn);
1406          sgn = 8;
1407        };
1408    };    };
1409    //    //
1410    oss.str("");    oss.str("");
# Line 1320  Int_t PamelaDBOperations::assignBOOT_NUM Line 1414  Int_t PamelaDBOperations::assignBOOT_NUM
1414    conn->Query(oss.str().c_str());          conn->Query(oss.str().c_str());      
1415    //    //
1416    delete result;    delete result;
1417    return(0);    return(sgn);
1418  };  };
1419    
1420  /**  /**
# Line 1638  Bool_t PamelaDBOperations::IsRunAlreadyI Line 1732  Bool_t PamelaDBOperations::IsRunAlreadyI
1732    delete result;    delete result;
1733    //    //
1734    if ( signal && IsDebug() ) printf(" The run has already been inserted \n");        if ( signal && IsDebug() ) printf(" The run has already been inserted \n");    
1735      if ( !signal && IsDebug() ) printf(" The run existed and was deleted, fill the DB \n");
1736    return(signal);    return(signal);
1737  };  };
1738    
# Line 1751  void PamelaDBOperations::HandleRunFragme Line 1846  void PamelaDBOperations::HandleRunFragme
1846      //      //
1847    } else {    } else {
1848      if ( IsDebug() ) printf(" The run is already present in the fragment table \n");      if ( IsDebug() ) printf(" The run is already present in the fragment table \n");
1849        return;
1850    };    };
1851    //    //
1852    //    //
# Line 3023  Int_t PamelaDBOperations::insertTRK_CALI Line 3119  Int_t PamelaDBOperations::insertTRK_CALI
3119      pkt1 = ph1->GetCounter();        pkt1 = ph1->GetCounter();  
3120      fromtime = this->GetAbsTime(ph1->GetOrbitalTime());        fromtime = this->GetAbsTime(ph1->GetOrbitalTime());  
3121      //      //
3122      valid = 1;  //     valid = 1;
3123      //  //     //
3124      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
3125      //      //
3126      //      //
3127      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) ){
3128        //        //
3129        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);
3130          //      
3131          valid = ValidateTrkCalib( caltrk1, eh1 );
3132          if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl;
3133        //        //
3134        // Do we have the second calibration packet?        // Do we have the second calibration packet?
3135        //        //
# Line 3047  Int_t PamelaDBOperations::insertTRK_CALI Line 3146  Int_t PamelaDBOperations::insertTRK_CALI
3146            obt2 = ph2->GetOrbitalTime();              obt2 = ph2->GetOrbitalTime();  
3147            pkt2 = ph2->GetCounter();              pkt2 = ph2->GetCounter();  
3148            //            //
3149            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
3150            //                  //      
3151          } else {          } else {
3152            //            //
# Line 3078  Int_t PamelaDBOperations::insertTRK_CALI Line 3177  Int_t PamelaDBOperations::insertTRK_CALI
3177          //          //
3178          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);
3179          //          //
3180            UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 );
3181            if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl;
3182            valid = valid & valid2;
3183            //
3184          // Handle good calib          // Handle good calib
3185          //          //
3186          this->HandleTRK_CALIB(true,true);          this->HandleTRK_CALIB(true,true);
# Line 4346  void PamelaDBOperations::RemoveCALIBS(){ Line 4449  void PamelaDBOperations::RemoveCALIBS(){
4449      //      //
4450    };    };
4451  };  };
4452    
4453    /**
4454     *
4455     * Rearrange calibration tables
4456     *
4457     **/
4458    UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){
4459    
4460        Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0};
4461        UInt_t timeaftercalib=120000; //2000;
4462    //  ----------
4463    //  Check CRCs
4464    //  ----------
4465        for(Int_t ipkt=0; ipkt<6; ipkt++){
4466            if( caltrk->crc_hcal[ipkt] )return 0; // :-(
4467            for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-(
4468        }
4469    //  -----------------------
4470    //  Check missing packets:
4471    //  -----------------------
4472    //    Readout order:
4473    //    ------------------
4474    //    DSP   packet board
4475    //    ------------------
4476    //    12    0      1
4477    //    10    1      1
4478    //     8    2      1
4479    //     4    3      1
4480    //     6    4      1
4481    //     2    5      1
4482    //    ------------------
4483    //    11    0      2
4484    //     9    1      2
4485    //     7    2      2
4486    //     3    3      2
4487    //     5    4      2
4488    //     1    5      2
4489    //    ------------------
4490    //  -------------------------------------------------
4491    //  Check if it is first or second calibration packet
4492    //  -------------------------------------------------
4493        UInt_t build=0;
4494        TString classname = caltrk->GetName();
4495        UInt_t base=0;
4496        UInt_t mask=0;
4497        if(classname.Contains("CalibTrk1Event")){
4498            base=12;
4499            mask=0x03F000;
4500        }
4501        if(classname.Contains("CalibTrk2Event")){
4502            base=18;
4503            mask=0xFC0000;
4504        }
4505    //  -------------------------------------------------
4506    //  Count number of packets and set build variable
4507    //  -------------------------------------------------
4508        Int_t  npkts=0;
4509        for(Int_t ipkt=0; ipkt<6; ipkt++){
4510            if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){
4511                npkts++;
4512                build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );
4513            }
4514        }
4515    //    if( npkts==6 )return 1; // :-)
4516    
4517    //    cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;
4518    
4519    //  -----------------------------------------------
4520    //  If missing packets: check the acq configuration
4521    //  (some DSPs might be excluded from acquisition)
4522    //  -----------------------------------------------
4523    
4524    //  -----------------------------------------------
4525    //  retrieve the first run header after calib
4526    //  -----------------------------------------------
4527         PacketType *pctp;
4528         EventCounter *cod;
4529         cod = eh->GetCounter();
4530         Int_t irun = cod->Get(pctp->RunHeader);
4531         TTree *rh=(TTree*)file->Get("RunHeader");
4532         if ( !rh || rh->IsZombie() ) throw -17;
4533         if( rh->GetEntries() == irun ){
4534              if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1)  -- cannot validate :-( "<<endl;
4535             return 0; // :-(
4536         }
4537    
4538         RunHeaderEvent *run  = 0;
4539         EventHeader    *hrun = 0;
4540         rh->SetBranchAddress("RunHeader", &run);
4541         rh->SetBranchAddress("Header", &hrun);
4542         rh->GetEntry(irun);
4543    //     cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl;
4544    
4545         if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){
4546              if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl;
4547             return 0; // :-(
4548         }
4549        
4550         if( !run->RM_ACQ_AFTER_CALIB ){
4551              if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0    -- cannot validate :-( "<<endl;
4552             return 0; // :-(
4553         }
4554    
4555         UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime());
4556         if( dtime > timeaftercalib ){
4557             if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl;
4558             return 0; // :-(
4559         }
4560        
4561    
4562    
4563         if( (run->ACQ_BUILD_INFO & mask) != build ){
4564             if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl;
4565             return 0; // :-(
4566         }
4567         return 1; // :-)
4568    
4569    }
4570    
4571    /**
4572     *
4573     * Check the DB (only for overlapping runs at the moment)
4574     *
4575     **/
4576    UInt_t PamelaDBOperations::Check(){
4577      //
4578      UInt_t test = 0;
4579      //
4580      UInt_t thisrht = 0;
4581      UInt_t thisrtt = 0;
4582      UInt_t thisid = 0;
4583      UInt_t prevrht = 0;
4584      UInt_t prevrtt = 0;
4585      UInt_t previd = 0;
4586      //
4587      UInt_t prevl0id = 0;
4588      UInt_t thisl0id = 0;
4589      //
4590      stringstream oss;
4591      TSQLResult *result = 0;
4592      TSQLRow    *row    = 0;
4593      TSQLResult *result2 = 0;
4594      TSQLRow    *row2    = 0;
4595      oss.str("");
4596      oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN order by RUNHEADER_TIME asc;";
4597      //  oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;";
4598      result = conn->Query(oss.str().c_str());
4599      //
4600      if ( !result ) throw -4;;
4601      //
4602      row = result->Next();
4603      //
4604      while ( row ){
4605        thisid = (UInt_t)atoll(row->GetField(0));
4606        thisl0id = (UInt_t)atoll(row->GetField(1));
4607        thisrht = (UInt_t)atoll(row->GetField(2));
4608        thisrtt = (UInt_t)atoll(row->GetField(3));
4609        //
4610        //    if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){
4611        //    if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){
4612        if ( (thisrht < prevrtt) && (thisrht != prevrht) ){
4613          if ( IsDebug() ) printf(" IDprev %u ID %u    prevrht %u prevrtt %u  thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt);
4614          printf(" CHECK n.1 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-prevrtt),previd,thisid);
4615          TString prevf = "";
4616          TString thisf = "";
4617          oss.str("");
4618          oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";";
4619          result2 = conn->Query(oss.str().c_str());
4620          if ( !result2 ) throw -4;;
4621          row2 = result2->Next();
4622          prevf = (TString)row2->GetField(0);
4623          oss.str("");
4624          oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";";
4625          result2 = conn->Query(oss.str().c_str());
4626          if ( !result2 ) throw -4;;
4627          row2 = result2->Next();
4628          thisf = (TString)row2->GetField(0);
4629          if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data());
4630          test = 1;
4631        };
4632        //
4633        if ( (thisrtt < prevrht) && (thisrht != prevrht) ){
4634          if ( IsDebug() ) printf(" IDprev %u ID %u    prevrht %u prevrtt %u  thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt);
4635          printf(" CHECK n.2 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrtt-prevrht),previd,thisid);
4636          TString prevf = "";
4637          TString thisf = "";
4638          oss.str("");
4639          oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";";
4640          result2 = conn->Query(oss.str().c_str());
4641          if ( !result2 ) throw -4;;
4642          row2 = result2->Next();
4643          prevf = (TString)row2->GetField(0);
4644          oss.str("");
4645          oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";";
4646          result2 = conn->Query(oss.str().c_str());
4647          if ( !result2 ) throw -4;;
4648          row2 = result2->Next();
4649          thisf = (TString)row2->GetField(0);
4650          if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data());
4651          test = 1;
4652        };
4653        //
4654        if ( (thisrht > thisrtt) && (thisrht != prevrht) ){
4655          if ( IsDebug() ) printf(" IDprev %u ID %u    prevrht %u prevrtt %u  thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt);
4656          printf(" CHECK n.3 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-thisrtt),previd,thisid);
4657          TString prevf = "";
4658          TString thisf = "";
4659          oss.str("");
4660          oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";";
4661          result2 = conn->Query(oss.str().c_str());
4662          if ( !result2 ) throw -4;;
4663          row2 = result2->Next();
4664          prevf = (TString)row2->GetField(0);
4665          oss.str("");
4666          oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";";
4667          result2 = conn->Query(oss.str().c_str());
4668          if ( !result2 ) throw -4;;
4669          row2 = result2->Next();
4670          thisf = (TString)row2->GetField(0);
4671          if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data());
4672          test = 1;
4673        };
4674    
4675        //
4676        prevrht = thisrht;
4677        prevrtt = thisrtt;
4678        previd = thisid;
4679        prevl0id = thisl0id;
4680        row = result->Next();
4681      };
4682      //
4683      return(test);
4684      //
4685    };

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.27

  ViewVC Help
Powered by ViewVC 1.1.23