/[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.19 by mocchiut, Thu Nov 9 16:47:47 2006 UTC revision 1.25 by mocchiut, Tue Jan 23 17:04:12 2007 UTC
# 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 265  Bool_t PamelaDBOperations::SetID_RAW(){ Line 273  Bool_t PamelaDBOperations::SetID_RAW(){
273    oss << "SELECT ID FROM GL_RAW WHERE "    oss << "SELECT ID FROM GL_RAW WHERE "
274        << " PATH = '" << this->GetRawPath().Data() << "' AND "        << " PATH = '" << this->GetRawPath().Data() << "' AND "
275        << " NAME = '" << this->GetRawFile().Data() << "' ";        << " NAME = '" << this->GetRawFile().Data() << "' ";
276    
277    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
278    if ( result == NULL ) throw -4;    if ( result == NULL ) throw -4;
279    row = result->Next();    row = result->Next();
# Line 295  Int_t PamelaDBOperations::SetUpperLimits Line 304  Int_t PamelaDBOperations::SetUpperLimits
304    UInt_t nevent = 0;    UInt_t nevent = 0;
305    UInt_t pktlast = 0;    UInt_t pktlast = 0;
306    UInt_t obtlast = 0;    UInt_t obtlast = 0;
307    UInt_t t_pktlast = 0;    Long64_t t_pktlast = 0LL;
308    UInt_t t_obtlast = 0;    //  UInt_t t_obtlast = 0;
309    UInt_t upperpkt2 = 0;    Long64_t t_obtlast = 0LL;
310    ULong64_t upperobt2 = 0;    Long64_t upperpkt2 = 0LL;
311      Long64_t upperobt2 = 0LL;
312    UInt_t zomp = 0;    UInt_t zomp = 0;
313    UInt_t jump = 50000; // was 5000    UInt_t jump = 50000; // was 5000
314    EventCounter *code=0;    EventCounter *code=0;
315    //    //
316    UInt_t deltapkt = 5000;    Long64_t deltapkt = 5000LL;
317    ULong64_t deltaobt = 50000;    Long64_t deltaobt = 50000LL;
318    //    //
319    //   pcksList packetsNames;    //   pcksList packetsNames;
320    //   pcksList::iterator Iter;    //   pcksList::iterator Iter;
# Line 342  Int_t PamelaDBOperations::SetUpperLimits Line 352  Int_t PamelaDBOperations::SetUpperLimits
352    upperobt = OBT(obtlast);    upperobt = OBT(obtlast);
353    upperentry = nevent-1;    upperentry = nevent-1;
354    //    //
355    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);
356    //    //
357    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);
358    //    //
359    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);
360    //    //
# Line 375  Int_t PamelaDBOperations::SetUpperLimits Line 385  Int_t PamelaDBOperations::SetUpperLimits
385          upperpkt2 = PKT(ph->GetCounter());          upperpkt2 = PKT(ph->GetCounter());
386          upperobt2 = OBT(ph->GetOrbitalTime());          upperobt2 = OBT(ph->GetOrbitalTime());
387          //          //
388          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) ){
389              if ( IsDebug() ) printf(" .-. upperpkt2 %lld upperobt2 %lld \n",upperpkt2,upperobt2);  
390              if ( IsDebug() ) printf(" .-. upperpkt %lld t_pktlast %lld upperobt %lld t_obtlast %lld \n",upperpkt,t_pktlast,upperobt,t_obtlast);    
391              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);    
392              throw -13;    
393            };
394          //          //
395          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 ){
396            zomp = i + jump + 1;            zomp = i + jump + 1;
397            if ( zomp > nevent-2 ) zomp = nevent - 2;            if ( zomp > nevent-2 ) zomp = nevent - 2;
398            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);
399            break;            break;
400          };          };
401          //          //
# Line 415  Int_t PamelaDBOperations::SetUpperLimits Line 430  Int_t PamelaDBOperations::SetUpperLimits
430    //    //
431    rhev = rh->GetEntries();    rhev = rh->GetEntries();
432    rtev = rt->GetEntries();    rtev = rt->GetEntries();
433    UInt_t sobtt = 0;    Long64_t sobtt = 0LL;
434    UInt_t sobth = 0;    Long64_t sobth = 0LL;
435    UInt_t spktt = 0;    Long64_t spktt = 0LL;
436    UInt_t spkth = 0;    Long64_t spkth = 0LL;
437    UInt_t pktt = 0;    Long64_t pktt = 0LL;
438    ULong64_t obtt = 0;    Long64_t obtt = 0LL;
439    UInt_t pkth = 0;    Long64_t pkth = 0LL;
440    ULong64_t obth = 0;    Long64_t obth = 0LL;
441    //    //
442    T->GetEntry(upperentry);    T->GetEntry(upperentry);
443    code = eh->GetCounter();    code = eh->GetCounter();
# Line 442  Int_t PamelaDBOperations::SetUpperLimits Line 457  Int_t PamelaDBOperations::SetUpperLimits
457      obth = OBT(phh->GetOrbitalTime());      obth = OBT(phh->GetOrbitalTime());
458    };    };
459    //    //
460    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);
461    if ( pkth > upperpkt && obth > upperobt ){    if ( pkth > upperpkt && obth > upperobt ){
462      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);
463      upperpkt = pkth;      upperpkt = pkth;
464      upperobt = obth;      upperobt = obth;
465      rhev = lasthead+1;      rhev = lasthead+1;
466    } else {    } else {
467      rhev = lasthead;      rhev = lasthead;
468    };    };
469    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);
470    //    //
471    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);
472    if ( pktt > upperpkt && obtt > upperobt ){    if ( pktt > upperpkt && obtt > upperobt ){
473      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);
474      upperpkt = pktt;      upperpkt = pktt;
475      upperobt = obtt;      upperobt = obtt;
476      rtev = lasttrail+1;      rtev = lasttrail+1;
477    } else {    } else {
478      rtev = lasttrail;      rtev = lasttrail;
479    };    };
480    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);
481    //  goto kikko;    //  goto kikko;
482    //    //
483    //    //
484    // Check if runtrailer/runheader are within lower limits    // Check if runtrailer/runheader are within lower limits
485    //    //
486    //    //
487    pkth = 0;    pkth = 0LL;
488    obth = 0;    obth = 0LL;
489    spkth = 0;    spkth = 0LL;
490    sobth = 0;    sobth = 0LL;
491    for (Int_t k=0; k<rhev; k++){    for (Int_t k=0; k<rhev; k++){
492      if ( k > 0 ){      if ( k > 0 ){
493        spkth = pkth;        spkth = pkth;
# Line 520  Int_t PamelaDBOperations::SetUpperLimits Line 535  Int_t PamelaDBOperations::SetUpperLimits
535            upperentry = evbefh-1;            upperentry = evbefh-1;
536          };              };    
537        };        };
538        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);
539        goto kikko0;        goto kikko0;
540      };      };
541    };    };
# Line 528  Int_t PamelaDBOperations::SetUpperLimits Line 543  Int_t PamelaDBOperations::SetUpperLimits
543    //    //
544    //    //
545    //    //
546    pktt = 0;    pktt = 0LL;
547    obtt = 0;    obtt = 0LL;
548    spktt = 0;    spktt = 0LL;
549    sobtt = 0;    sobtt = 0LL;
550    for (Int_t k=0; k<rtev; k++){    for (Int_t k=0; k<rtev; k++){
551      if ( k > 0 ){      if ( k > 0 ){
552        spktt = pktt;        spktt = pktt;
# Line 551  Int_t PamelaDBOperations::SetUpperLimits Line 566  Int_t PamelaDBOperations::SetUpperLimits
566        rt->GetEntry(rtev);        rt->GetEntry(rtev);
567        pktt = spktt;        pktt = spktt;
568        obtt = sobtt;        obtt = sobtt;
569        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);
570        //        //
571        UInt_t evbeft = 0;        UInt_t evbeft = 0;
572        code = eht->GetCounter();        code = eht->GetCounter();
# Line 580  Int_t PamelaDBOperations::SetUpperLimits Line 595  Int_t PamelaDBOperations::SetUpperLimits
595            upperentry = evbeft-1;            upperentry = evbeft-1;
596          };          };
597        };        };
598        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);
599        goto kikko;        goto kikko;
600        //      break;        //      break;
601        //        //
# Line 608  Int_t PamelaDBOperations::SetUpperLimits Line 623  Int_t PamelaDBOperations::SetUpperLimits
623      obth = OBT(phh->GetOrbitalTime());      obth = OBT(phh->GetOrbitalTime());
624    };    };
625    //    //
626    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);
627    if ( pkth > upperpkt && obth > upperobt ){    if ( pkth > upperpkt && obth > upperobt ){
628      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);
629      upperpkt = pkth;      upperpkt = pkth;
630      upperobt = obth;      upperobt = obth;
631      rhev = lasthead+1;      rhev = lasthead+1;
632    } else {    } else {
633      rhev = lasthead;      rhev = lasthead;
634    };    };
635    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);
636    //    //
637    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);
638    if ( pktt > upperpkt && obtt > upperobt ){    if ( pktt > upperpkt && obtt > upperobt ){
639      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);
640      upperpkt = pktt;      upperpkt = pktt;
641      upperobt = obtt;      upperobt = obtt;
642      rtev = lasttrail+1;      rtev = lasttrail+1;
643    } else {    } else {
644      rtev = lasttrail;      rtev = lasttrail;
645    };    };
646    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);
647    //    //
648    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);
649    //    //
650    return(0);    return(0);
651  }  }
# Line 781  void PamelaDBOperations::CheckConnection Line 796  void PamelaDBOperations::CheckConnection
796  /**  /**
797   * Return the correct packet number if we went back to zero   * Return the correct packet number if we went back to zero
798   */   */
799  UInt_t PamelaDBOperations::PKT(UInt_t pkt_num){    Long64_t PamelaDBOperations::PKT(UInt_t pkt_num){  
800    //    //
801    //  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));
802    //    //
803    if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2)  ) return((pkt_num+16777215));    if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2)  ){
804        if ( IsDebug() ) printf(" rise up pktnum %lld \n",(Long64_t)pkt_num+16777215LL);
805        return((Long64_t)pkt_num+16777215LL);
806      };
807    //    //
808    if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){    if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){
809      if ( (pkt_num-16777215) < 0 ){      if ( IsDebug() ) printf(" rise down pktnum %lld \n",(Long64_t)pkt_num-16777215LL);
810        return((16777215-pkt_num));      return((Long64_t)pkt_num-16777215LL);
     } else {  
       return((pkt_num-16777215));  
     };  
811    };    };
812    //    //
813    return(pkt_num);    if ( IsDebug() ) printf(" as it is %lld \n",(Long64_t)pkt_num);
814      return((Long64_t)pkt_num);
815    //    //
816  };  };
817    
818  /**  /**
819   * Return the correct On Board Time if we went back to zero   * Return the correct On Board Time if we went back to zero
820   */   */
821  ULong64_t PamelaDBOperations::OBT(UInt_t obt){    Long64_t PamelaDBOperations::OBT(UInt_t obt){  
822    //    //
823    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()));
824    //    //
825    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
826      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()));  
     };  
827    };    };
828    //    //
829    return((ULong64_t)obt);    return((Long64_t)obt);
830  };  };
831    
832  /**  /**
# Line 993  Int_t PamelaDBOperations::insertPamelaGL Line 1005  Int_t PamelaDBOperations::insertPamelaGL
1005    if ((row != NULL) && ((UInt_t)atoll(row->GetField(0)) > 0)){    if ((row != NULL) && ((UInt_t)atoll(row->GetField(0)) > 0)){
1006      if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);      if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);
1007      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;
1008        //
1009        tsync = (UInt_t)atoll(row->GetField(2));
1010        obt0 = (UInt_t)atoll(row->GetField(1));
1011        //
1012      return(1);      return(1);
1013    };    };
1014    //    //
# Line 1189  Int_t PamelaDBOperations::insertPamelaGL Line 1205  Int_t PamelaDBOperations::insertPamelaGL
1205    if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);    if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);
1206    toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0;    toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0;
1207    //    //
1208      tsync = TSYNC;
1209      obt0 = OBT;
1210      //
1211    delete result;    delete result;
1212    return(signal);    return(signal);
1213  }  }
# Line 1288  Int_t PamelaDBOperations::assignBOOT_NUM Line 1307  Int_t PamelaDBOperations::assignBOOT_NUM
1307    VarDumpEvent  *vde = 0;    VarDumpEvent  *vde = 0;
1308    VarDumpRecord *vdr = 0;    VarDumpRecord *vdr = 0;
1309    //    //
1310      Bool_t found = false;
1311    trDumpEv->SetBranchAddress("VarDump", &vde);    trDumpEv->SetBranchAddress("VarDump", &vde);
1312    if ( trDumpEv->GetEntries() > 0 ){    if ( trDumpEv->GetEntries() > 0 ){
1313      Bool_t found = false;      found = false;
1314      for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){      for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){
1315        trDumpEv->GetEntry(i);        trDumpEv->GetEntry(i);
1316        vde->Records->GetEntries();        //      vde->Records->GetEntries();
1317        if ( vde->Records->GetEntries()>0 ){        if ( vde->Records->GetEntries()>5 ){
1318          found = true;          found = true;
1319          goto fill;          goto fill;
1320        };        };
# Line 1307  Int_t PamelaDBOperations::assignBOOT_NUM Line 1327  Int_t PamelaDBOperations::assignBOOT_NUM
1327        this->SetBOOTnumber((Int_t)vdr->VAR_VALUE);        this->SetBOOTnumber((Int_t)vdr->VAR_VALUE);
1328        //        //
1329      } else {      } else {
1330        if ( !this->GetBOOTnumber() ) return(4);        if ( !this->GetBOOTnumber() && !this->AutoBoot()) return(4);
1331        };
1332      } else {
1333        if ( !this->GetBOOTnumber() && !this->AutoBoot()) return(2);
1334      };
1335      //
1336      UInt_t bn = 0;
1337      Bool_t afound = false;
1338      if ( !found && this->AutoBoot()){
1339        afound = true;
1340        //
1341        // Search for other files with similar timesync
1342        //
1343        if ( IsDebug() ) printf(" tsync %u obt0 %u \n",tsync,obt0);
1344        UInt_t upperts = tsync-(obt0/1000)+5;
1345        UInt_t lowerts = tsync-(obt0/1000)-5;
1346        oss.str("");
1347        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)<"
1348            << upperts
1349            << " AND TIMESYNC-(OBT0/1000)>"
1350            << lowerts
1351            << " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;";
1352        result = conn->Query(oss.str().c_str());
1353        if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to find boot number:\n %s \n",oss.str().c_str());
1354        //
1355        if ( !result ) throw -4;;
1356        found = true;
1357        if ( result->GetRowCount()<3 ){
1358          if ( IsDebug() ) printf(" AGH! no results!\n");
1359          found = false;
1360        } else {
1361          row = result->Next();      
1362          bn = (UInt_t)atoll(row->GetField(0));
1363          for ( Int_t r=1; r<result->GetRowCount() ;r++){
1364            if ( !row ) throw -4;
1365            if ( IsDebug() ) printf(" BOOT number is %s \n",row->GetField(0));
1366            if ( bn != (UInt_t)atoll(row->GetField(0)) ){
1367              if ( IsDebug() ) printf(" AGH! bn = %u here instead %u \n",bn,(UInt_t)atoll(row->GetField(0)));
1368              found = false;
1369            };
1370            row = result->Next();
1371          };
1372      };      };
1373      };
1374      //
1375      Int_t sgn = 0;
1376      //
1377      if ( !found ){
1378        throw -29;
1379    } else {    } else {
1380      if ( !this->GetBOOTnumber() ) return(2);      if ( afound ){
1381          this->SetBOOTnumber(bn);
1382          sgn = 8;
1383        };
1384    };    };
1385    //    //
1386    oss.str("");    oss.str("");
# Line 1320  Int_t PamelaDBOperations::assignBOOT_NUM Line 1390  Int_t PamelaDBOperations::assignBOOT_NUM
1390    conn->Query(oss.str().c_str());          conn->Query(oss.str().c_str());      
1391    //    //
1392    delete result;    delete result;
1393    return(0);    return(sgn);
1394  };  };
1395    
1396  /**  /**
# Line 1638  Bool_t PamelaDBOperations::IsRunAlreadyI Line 1708  Bool_t PamelaDBOperations::IsRunAlreadyI
1708    delete result;    delete result;
1709    //    //
1710    if ( signal && IsDebug() ) printf(" The run has already been inserted \n");        if ( signal && IsDebug() ) printf(" The run has already been inserted \n");    
1711      if ( !signal && IsDebug() ) printf(" The run existed and was deleted, fill the DB \n");
1712    return(signal);    return(signal);
1713  };  };
1714    
# Line 1751  void PamelaDBOperations::HandleRunFragme Line 1822  void PamelaDBOperations::HandleRunFragme
1822      //      //
1823    } else {    } else {
1824      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");
1825        return;
1826    };    };
1827    //    //
1828    //    //
# Line 3023  Int_t PamelaDBOperations::insertTRK_CALI Line 3095  Int_t PamelaDBOperations::insertTRK_CALI
3095      pkt1 = ph1->GetCounter();        pkt1 = ph1->GetCounter();  
3096      fromtime = this->GetAbsTime(ph1->GetOrbitalTime());        fromtime = this->GetAbsTime(ph1->GetOrbitalTime());  
3097      //      //
3098      valid = 1;  //     valid = 1;
3099      //  //     //
3100      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
3101      //      //
3102      //      //
3103      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) ){
3104        //        //
3105        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);
3106          //      
3107          valid = ValidateTrkCalib( caltrk1, eh1 );
3108          if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl;
3109        //        //
3110        // Do we have the second calibration packet?        // Do we have the second calibration packet?
3111        //        //
# Line 3047  Int_t PamelaDBOperations::insertTRK_CALI Line 3122  Int_t PamelaDBOperations::insertTRK_CALI
3122            obt2 = ph2->GetOrbitalTime();              obt2 = ph2->GetOrbitalTime();  
3123            pkt2 = ph2->GetCounter();              pkt2 = ph2->GetCounter();  
3124            //            //
3125            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
3126            //                  //      
3127          } else {          } else {
3128            //            //
# Line 3078  Int_t PamelaDBOperations::insertTRK_CALI Line 3153  Int_t PamelaDBOperations::insertTRK_CALI
3153          //          //
3154          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);
3155          //          //
3156            UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 );
3157            if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl;
3158            valid = valid & valid2;
3159            //
3160          // Handle good calib          // Handle good calib
3161          //          //
3162          this->HandleTRK_CALIB(true,true);          this->HandleTRK_CALIB(true,true);
# Line 4346  void PamelaDBOperations::RemoveCALIBS(){ Line 4425  void PamelaDBOperations::RemoveCALIBS(){
4425      //      //
4426    };    };
4427  };  };
4428    
4429    /**
4430     *
4431     * Rearrange calibration tables
4432     *
4433     **/
4434    UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){
4435    
4436        Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0};
4437        UInt_t timeaftercalib=120000; //2000;
4438    //  ----------
4439    //  Check CRCs
4440    //  ----------
4441        for(Int_t ipkt=0; ipkt<6; ipkt++){
4442            if( caltrk->crc_hcal[ipkt] )return 0; // :-(
4443            for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-(
4444        }
4445    //  -----------------------
4446    //  Check missing packets:
4447    //  -----------------------
4448    //    Readout order:
4449    //    ------------------
4450    //    DSP   packet board
4451    //    ------------------
4452    //    12    0      1
4453    //    10    1      1
4454    //     8    2      1
4455    //     4    3      1
4456    //     6    4      1
4457    //     2    5      1
4458    //    ------------------
4459    //    11    0      2
4460    //     9    1      2
4461    //     7    2      2
4462    //     3    3      2
4463    //     5    4      2
4464    //     1    5      2
4465    //    ------------------
4466    //  -------------------------------------------------
4467    //  Check if it is first or second calibration packet
4468    //  -------------------------------------------------
4469        UInt_t build=0;
4470        TString classname = caltrk->GetName();
4471        UInt_t base=0;
4472        UInt_t mask=0;
4473        if(classname.Contains("CalibTrk1Event")){
4474            base=12;
4475            mask=0x03F000;
4476        }
4477        if(classname.Contains("CalibTrk2Event")){
4478            base=18;
4479            mask=0xFC0000;
4480        }
4481    //  -------------------------------------------------
4482    //  Count number of packets and set build variable
4483    //  -------------------------------------------------
4484        Int_t  npkts=0;
4485        for(Int_t ipkt=0; ipkt<6; ipkt++){
4486            if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){
4487                npkts++;
4488                build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );
4489            }
4490        }
4491    //    if( npkts==6 )return 1; // :-)
4492    
4493    //    cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;
4494    
4495    //  -----------------------------------------------
4496    //  If missing packets: check the acq configuration
4497    //  (some DSPs might be excluded from acquisition)
4498    //  -----------------------------------------------
4499    
4500    //  -----------------------------------------------
4501    //  retrieve the first run header after calib
4502    //  -----------------------------------------------
4503         PacketType *pctp;
4504         EventCounter *cod;
4505         cod = eh->GetCounter();
4506         Int_t irun = cod->Get(pctp->RunHeader);
4507         TTree *rh=(TTree*)file->Get("RunHeader");
4508         if ( !rh || rh->IsZombie() ) throw -17;
4509         if( rh->GetEntries() == irun ){
4510              if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1)  -- cannot validate :-( "<<endl;
4511             return 0; // :-(
4512         }
4513    
4514         RunHeaderEvent *run  = 0;
4515         EventHeader    *hrun = 0;
4516         rh->SetBranchAddress("RunHeader", &run);
4517         rh->SetBranchAddress("Header", &hrun);
4518         rh->GetEntry(irun);
4519    //     cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl;
4520    
4521         if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){
4522              if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl;
4523             return 0; // :-(
4524         }
4525        
4526         if( !run->RM_ACQ_AFTER_CALIB ){
4527              if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0    -- cannot validate :-( "<<endl;
4528             return 0; // :-(
4529         }
4530    
4531         UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime());
4532         if( dtime > timeaftercalib ){
4533             if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl;
4534             return 0; // :-(
4535         }
4536        
4537    
4538    
4539         if( (run->ACQ_BUILD_INFO & mask) != build ){
4540             if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl;
4541             return 0; // :-(
4542         }
4543         return 1; // :-)
4544    
4545    }
4546    
4547    /**
4548     *
4549     * Check the DB (only for overlapping runs at the moment)
4550     *
4551     **/
4552    UInt_t PamelaDBOperations::Check(){
4553      //
4554      UInt_t test = 0;
4555      //
4556      UInt_t thisrht = 0;
4557      UInt_t thisrtt = 0;
4558      UInt_t thisid = 0;
4559      UInt_t prevrht = 0;
4560      UInt_t prevrtt = 0;
4561      UInt_t previd = 0;
4562      //
4563      UInt_t prevl0id = 0;
4564      UInt_t thisl0id = 0;
4565      //
4566      stringstream oss;
4567      TSQLResult *result = 0;
4568      TSQLRow    *row    = 0;
4569      TSQLResult *result2 = 0;
4570      TSQLRow    *row2    = 0;
4571      oss.str("");
4572      oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN order by RUNHEADER_TIME asc;";
4573      //  oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;";
4574      result = conn->Query(oss.str().c_str());
4575      //
4576      if ( !result ) throw -4;;
4577      //
4578      row = result->Next();
4579      //
4580      while ( row ){
4581        thisid = (UInt_t)atoll(row->GetField(0));
4582        thisl0id = (UInt_t)atoll(row->GetField(1));
4583        thisrht = (UInt_t)atoll(row->GetField(2));
4584        thisrtt = (UInt_t)atoll(row->GetField(3));
4585        //
4586        //    if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){
4587        //    if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){
4588        if ( (thisrht < prevrtt) && (thisrht != prevrht) ){
4589          if ( IsDebug() ) printf(" IDprev %u ID %u    prevrht %u prevrtt %u  thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt);
4590          printf(" CHECK n.1 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-prevrtt),previd,thisid);
4591          TString prevf = "";
4592          TString thisf = "";
4593          oss.str("");
4594          oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";";
4595          result2 = conn->Query(oss.str().c_str());
4596          if ( !result2 ) throw -4;;
4597          row2 = result2->Next();
4598          prevf = (TString)row2->GetField(0);
4599          oss.str("");
4600          oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";";
4601          result2 = conn->Query(oss.str().c_str());
4602          if ( !result2 ) throw -4;;
4603          row2 = result2->Next();
4604          thisf = (TString)row2->GetField(0);
4605          if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data());
4606          test = 1;
4607        };
4608        //
4609        if ( (thisrtt < prevrht) && (thisrht != prevrht) ){
4610          if ( IsDebug() ) printf(" IDprev %u ID %u    prevrht %u prevrtt %u  thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt);
4611          printf(" CHECK n.2 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrtt-prevrht),previd,thisid);
4612          TString prevf = "";
4613          TString thisf = "";
4614          oss.str("");
4615          oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";";
4616          result2 = conn->Query(oss.str().c_str());
4617          if ( !result2 ) throw -4;;
4618          row2 = result2->Next();
4619          prevf = (TString)row2->GetField(0);
4620          oss.str("");
4621          oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";";
4622          result2 = conn->Query(oss.str().c_str());
4623          if ( !result2 ) throw -4;;
4624          row2 = result2->Next();
4625          thisf = (TString)row2->GetField(0);
4626          if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data());
4627          test = 1;
4628        };
4629        //
4630        if ( (thisrht > thisrtt) && (thisrht != prevrht) ){
4631          if ( IsDebug() ) printf(" IDprev %u ID %u    prevrht %u prevrtt %u  thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt);
4632          printf(" CHECK n.3 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-thisrtt),previd,thisid);
4633          TString prevf = "";
4634          TString thisf = "";
4635          oss.str("");
4636          oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";";
4637          result2 = conn->Query(oss.str().c_str());
4638          if ( !result2 ) throw -4;;
4639          row2 = result2->Next();
4640          prevf = (TString)row2->GetField(0);
4641          oss.str("");
4642          oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";";
4643          result2 = conn->Query(oss.str().c_str());
4644          if ( !result2 ) throw -4;;
4645          row2 = result2->Next();
4646          thisf = (TString)row2->GetField(0);
4647          if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data());
4648          test = 1;
4649        };
4650    
4651        //
4652        prevrht = thisrht;
4653        prevrtt = thisrtt;
4654        previd = thisid;
4655        prevl0id = thisl0id;
4656        row = result->Next();
4657      };
4658      //
4659      return(test);
4660      //
4661    };

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.23