/[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.23 by mocchiut, Mon Dec 4 09:49:34 2006 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 295  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 342  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 375  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 415  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 442  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 520  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 528  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 551  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 580  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 608  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 781  void PamelaDBOperations::CheckConnection Line 795  void PamelaDBOperations::CheckConnection
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 993  Int_t PamelaDBOperations::insertPamelaGL Line 1004  Int_t PamelaDBOperations::insertPamelaGL
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);      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 1189  Int_t PamelaDBOperations::insertPamelaGL Line 1204  Int_t PamelaDBOperations::insertPamelaGL
1204    if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);    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 1288  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 1307  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 {
1332        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 {    } else {
1379      if ( !this->GetBOOTnumber() ) return(2);      if ( afound ){
1380          this->SetBOOTnumber(bn);
1381          sgn = 8;
1382        };
1383    };    };
1384    //    //
1385    oss.str("");    oss.str("");
# Line 1320  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 1638  Bool_t PamelaDBOperations::IsRunAlreadyI Line 1707  Bool_t PamelaDBOperations::IsRunAlreadyI
1707    delete result;    delete result;
1708    //    //
1709    if ( signal && IsDebug() ) printf(" The run has already been inserted \n");        if ( signal && IsDebug() ) printf(" The run has already been inserted \n");    
1710      if ( !signal && IsDebug() ) printf(" The run existed and was deleted, fill the DB \n");
1711    return(signal);    return(signal);
1712  };  };
1713    
# Line 1751  void PamelaDBOperations::HandleRunFragme Line 1821  void PamelaDBOperations::HandleRunFragme
1821      //      //
1822    } else {    } else {
1823      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");
1824        return;
1825    };    };
1826    //    //
1827    //    //
# Line 3023  Int_t PamelaDBOperations::insertTRK_CALI Line 3094  Int_t PamelaDBOperations::insertTRK_CALI
3094      pkt1 = ph1->GetCounter();        pkt1 = ph1->GetCounter();  
3095      fromtime = this->GetAbsTime(ph1->GetOrbitalTime());        fromtime = this->GetAbsTime(ph1->GetOrbitalTime());  
3096      //      //
3097      valid = 1;  //     valid = 1;
3098      //  //     //
3099      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
3100      //      //
3101      //      //
3102      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) ){
3103        //        //
3104        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);
3105          //      
3106          valid = ValidateTrkCalib( caltrk1, eh1 );
3107          if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl;
3108        //        //
3109        // Do we have the second calibration packet?        // Do we have the second calibration packet?
3110        //        //
# Line 3047  Int_t PamelaDBOperations::insertTRK_CALI Line 3121  Int_t PamelaDBOperations::insertTRK_CALI
3121            obt2 = ph2->GetOrbitalTime();              obt2 = ph2->GetOrbitalTime();  
3122            pkt2 = ph2->GetCounter();              pkt2 = ph2->GetCounter();  
3123            //            //
3124            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
3125            //                  //      
3126          } else {          } else {
3127            //            //
# Line 3078  Int_t PamelaDBOperations::insertTRK_CALI Line 3152  Int_t PamelaDBOperations::insertTRK_CALI
3152          //          //
3153          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);
3154          //          //
3155            UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 );
3156            if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl;
3157            valid = valid & valid2;
3158            //
3159          // Handle good calib          // Handle good calib
3160          //          //
3161          this->HandleTRK_CALIB(true,true);          this->HandleTRK_CALIB(true,true);
# Line 4346  void PamelaDBOperations::RemoveCALIBS(){ Line 4424  void PamelaDBOperations::RemoveCALIBS(){
4424      //      //
4425    };    };
4426  };  };
4427    /**
4428     *
4429     * Rearrange calibration tables
4430     *
4431     **/
4432    UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){
4433    
4434        Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0};
4435        UInt_t timeaftercalib=120000; //2000;
4436    //  ----------
4437    //  Check CRCs
4438    //  ----------
4439        for(Int_t ipkt=0; ipkt<6; ipkt++){
4440            if( caltrk->crc_hcal[ipkt] )return 0; // :-(
4441            for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-(
4442        }
4443    //  -----------------------
4444    //  Check missing packets:
4445    //  -----------------------
4446    //    Readout order:
4447    //    ------------------
4448    //    DSP   packet board
4449    //    ------------------
4450    //    12    0      1
4451    //    10    1      1
4452    //     8    2      1
4453    //     4    3      1
4454    //     6    4      1
4455    //     2    5      1
4456    //    ------------------
4457    //    11    0      2
4458    //     9    1      2
4459    //     7    2      2
4460    //     3    3      2
4461    //     5    4      2
4462    //     1    5      2
4463    //    ------------------
4464    //  -------------------------------------------------
4465    //  Check if it is first or second calibration packet
4466    //  -------------------------------------------------
4467        UInt_t build=0;
4468        TString classname = caltrk->GetName();
4469        UInt_t base=0;
4470        UInt_t mask=0;
4471        if(classname.Contains("CalibTrk1Event")){
4472            base=12;
4473            mask=0x03F000;
4474        }
4475        if(classname.Contains("CalibTrk2Event")){
4476            base=18;
4477            mask=0xFC0000;
4478        }
4479    //  -------------------------------------------------
4480    //  Count number of packets and set build variable
4481    //  -------------------------------------------------
4482        Int_t  npkts=0;
4483        for(Int_t ipkt=0; ipkt<6; ipkt++){
4484            if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){
4485                npkts++;
4486                build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );
4487            }
4488        }
4489    //    if( npkts==6 )return 1; // :-)
4490    
4491    //    cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;
4492    
4493    //  -----------------------------------------------
4494    //  If missing packets: check the acq configuration
4495    //  (some DSPs might be excluded from acquisition)
4496    //  -----------------------------------------------
4497    
4498    //  -----------------------------------------------
4499    //  retrieve the first run header after calib
4500    //  -----------------------------------------------
4501         PacketType *pctp;
4502         EventCounter *cod;
4503         cod = eh->GetCounter();
4504         Int_t irun = cod->Get(pctp->RunHeader);
4505         TTree *rh=(TTree*)file->Get("RunHeader");
4506         if ( !rh || rh->IsZombie() ) throw -17;
4507         if( rh->GetEntries() == irun ){
4508              if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1)  -- cannot validate :-( "<<endl;
4509             return 0; // :-(
4510         }
4511    
4512         RunHeaderEvent *run  = 0;
4513         EventHeader    *hrun = 0;
4514         rh->SetBranchAddress("RunHeader", &run);
4515         rh->SetBranchAddress("Header", &hrun);
4516         rh->GetEntry(irun);
4517    //     cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl;
4518    
4519         if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){
4520              if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl;
4521             return 0; // :-(
4522         }
4523        
4524         if( !run->RM_ACQ_AFTER_CALIB ){
4525              if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0    -- cannot validate :-( "<<endl;
4526             return 0; // :-(
4527         }
4528    
4529         UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime());
4530         if( dtime > timeaftercalib ){
4531             if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl;
4532             return 0; // :-(
4533         }
4534        
4535    
4536    
4537         if( (run->ACQ_BUILD_INFO & mask) != build ){
4538             if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl;
4539             return 0; // :-(
4540         }
4541         return 1; // :-)
4542    
4543    }

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

  ViewVC Help
Powered by ViewVC 1.1.23