/[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.21 by mocchiut, Mon Nov 27 14:25:35 2006 UTC revision 1.25 by mocchiut, Tue Jan 23 17:04:12 2007 UTC
# Line 273  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 1707  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 1820  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 3092  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 3116  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 3147  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 4415  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.21  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.23