/[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.27 by mocchiut, Mon Feb 12 13:32:18 2007 UTC revision 1.51 by mocchiut, Fri Oct 19 07:47:52 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, UInt_t dwinput){  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, Bool_t staticp, Bool_t gpamela){
60    //    //
61      STATIC=false;
62      if ( staticp ) STATIC=true;
63    //    //
64    SetConnection(host,user,password);    SetConnection(host,user,password);
65    //    //
# Line 66  PamelaDBOperations::PamelaDBOperations(T Line 68  PamelaDBOperations::PamelaDBOperations(T
68    glrun = new GL_RUN();    glrun = new GL_RUN();
69    //    //
70    if ( !boot ) SetNOBOOT(false);    if ( !boot ) SetNOBOOT(false);
71    SetBOOTnumber(boot);    SetTsync(tsync,gpamela);
72    SetTsync(tsync);    SetBOOTnumber(boot,gpamela);
73    SetObt0(obt0);    SetObt0(obt0);
74    //    //
75    SetTLEPath(tlefilename);    SetTLEPath(tlefilename);
# Line 177  void PamelaDBOperations::SetNoFrag(Bool_ Line 179  void PamelaDBOperations::SetNoFrag(Bool_
179   * @param boot    BOOT number of the RAW file   * @param boot    BOOT number of the RAW file
180   */   */
181  void PamelaDBOperations::SetBOOTnumber(UInt_t boot){  void PamelaDBOperations::SetBOOTnumber(UInt_t boot){
182      this->SetBOOTnumber(boot,false);
183    };
184    
185    /**
186     * Store the BOOT number of the RAW file.
187     * @param boot    BOOT number of the RAW file
188     */
189    void PamelaDBOperations::SetBOOTnumber(UInt_t boot, Bool_t gpamela){
190    BOOTNO=boot;    BOOTNO=boot;
191      if ( gpamela ){
192        stringstream oss;
193        TSQLResult *result = 0;
194        TSQLRow    *row    = 0;    
195        if ( !boot ){
196          //
197          BOOTNO = 1;
198          //
199          // look in the DB for the last timesync and the last run
200          //
201          oss.str("");
202          oss << "SELECT BOOT_NUMBER FROM GL_RUN order by RUNHEADER_TIME desc limit 1;";
203          result = conn->Query(oss.str().c_str());
204          if ( result ){
205            row = result->Next();
206            if ( row ){
207              BOOTNO = (UInt_t)atoll(row->GetField(0)) + 1;
208            };
209          };
210        };
211      };
212  };  };
213    
214  /**  /**
# Line 185  void PamelaDBOperations::SetBOOTnumber(U Line 216  void PamelaDBOperations::SetBOOTnumber(U
216   * @param boot    time sync   * @param boot    time sync
217   */   */
218  void PamelaDBOperations::SetTsync(UInt_t ts){  void PamelaDBOperations::SetTsync(UInt_t ts){
219      this->SetTsync(ts,false);
220    };
221    
222    /**
223     * Store the time sync of the RAW file.
224     * @param boot    time sync
225     */
226    void PamelaDBOperations::SetTsync(UInt_t ts, Bool_t gpamela){
227      //
228      // if not gpamela or given tsync file set ts
229      //
230    tsync=ts;    tsync=ts;
231      if ( gpamela ){
232        stringstream oss;
233        TSQLResult *result = 0;
234        TSQLRow    *row    = 0;    
235        TSQLResult *result2 = 0;
236        TSQLRow    *row2    = 0;    
237        if ( !ts ){
238          //
239          tsync = 1;
240          //
241          // look in the DB for the last timesync and the last run
242          //
243          oss.str("");
244          oss << "SELECT TIMESYNC FROM GL_TIMESYNC order by TIMESYNC desc limit 1;";
245          result = conn->Query(oss.str().c_str());
246          if ( result ){
247            row = result->Next();
248            if ( row ){
249              tsync = (UInt_t)atoll(row->GetField(0)) + 1;
250              oss.str("");
251              oss << "SELECT (RUNTRAILER_TIME-RUNHEADER_TIME) FROM GL_RUN order by RUNHEADER_TIME desc limit 1;";
252              result2 = conn->Query(oss.str().c_str());
253              if ( result2 ){
254                row2 = result2->Next();
255                if ( row2 ){
256                  tsync += (UInt_t)atoll(row2->GetField(0));
257                };
258              }
259            };
260          };
261        };
262      };
263  };  };
264    
265  /**  /**
# Line 261  void PamelaDBOperations::SetTLEPath(TStr Line 335  void PamelaDBOperations::SetTLEPath(TStr
335    tlefilename = str;    tlefilename = str;
336  };  };
337    
338    TString PamelaDBOperations::GetRawPath(){
339      if ( STATIC ){
340        return((TString)gSystem->DirName(filerawname.Data())+'/');
341      } else {
342        return((TString)gSystem->ExpandPathName("$PAM_RAW")+'/');
343      };
344    };
345    
346    TString PamelaDBOperations::GetRootPath(){
347      if ( STATIC ){
348        return((TString)gSystem->DirName(filerootname.Data())+'/');
349      } else {
350        return((TString)gSystem->ExpandPathName("$PAM_L0")+'/');
351      };
352    };
353    
354  /**  /**
355   * Store the olderthan variable   * Store the olderthan variable
356   * @param olderthan   * @param olderthan
# Line 277  Bool_t PamelaDBOperations::SetID_RAW(){ Line 367  Bool_t PamelaDBOperations::SetID_RAW(){
367    TSQLResult *result = 0;    TSQLResult *result = 0;
368    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
369    oss.str("");    oss.str("");
370    oss << "SELECT ID FROM GL_RAW WHERE "    if ( STATIC ){
371        << " PATH = '" << this->GetRawPath().Data() << "' AND "      oss << "SELECT ID FROM GL_RAW WHERE "
372        << " NAME = '" << this->GetRawFile().Data() << "' ";          << " PATH = '" << this->GetRawPath().Data() << "' AND "
373            << " NAME = '" << this->GetRawFile().Data() << "' ";  
374      } else {
375        oss << "SELECT ID FROM GL_RAW WHERE "
376            << " PATH = '$PAM_RAW' AND "
377            << " NAME = '" << this->GetRawFile().Data() << "' ";  
378      }
379    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
380    if ( result == NULL ) throw -4;    if ( result == NULL ) throw -4;
381    row = result->Next();    row = result->Next();
# Line 323  Int_t PamelaDBOperations::SetUpperLimits Line 418  Int_t PamelaDBOperations::SetUpperLimits
418    Long64_t deltapkt = 5000LL;    Long64_t deltapkt = 5000LL;
419    Long64_t deltaobt = 50000LL;    Long64_t deltaobt = 50000LL;
420    //    //
421    //   pcksList packetsNames;    pcksList packetsNames;
422    //   pcksList::iterator Iter;    pcksList::iterator Iter;
423    //   getPacketsNames(packetsNames);    getPacketsNames(packetsNames);
424    //    //
425    pktfirst = 0;    pktfirst = 0;
426    obtfirst = 0;    obtfirst = 0;
427      ppktfirst = 0;
428      pobtfirst = 0;
429    //    //
430    TTree *T = 0;    TTree *T = 0;
431    T = (TTree*)file->Get("Physics");    T = (TTree*)file->Get("Physics");
# Line 342  Int_t PamelaDBOperations::SetUpperLimits Line 439  Int_t PamelaDBOperations::SetUpperLimits
439    ph = eh->GetPscuHeader();    ph = eh->GetPscuHeader();
440    pktfirst = ph->GetCounter();    pktfirst = ph->GetCounter();
441    obtfirst = ph->GetOrbitalTime();      obtfirst = ph->GetOrbitalTime();  
442      ppktfirst = pktfirst;
443      pobtfirst = obtfirst;
444    //    //
445    //   code = eh->GetCounter();    code = eh->GetCounter();
446    //   UInt_t en = 0;    UInt_t en = 0;
447    //   for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){    for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){
448    //     en = code->Get(GetPacketType(*Iter));      en = code->Get(GetPacketType(*Iter));
449    //     if ( en ) printf(" Packet type is %s, entries: %i \n",*Iter,en);      if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){
450    //};          if ( IsDebug() ) printf(" We have a calibration before the first physic packet: packet type is %s, entries: %i \n",*Iter,en);
451          //
452          TTree *TC = 0;
453          TC = (TTree*)file->Get("CalibCalPed");
454          if ( !TC || TC->IsZombie() ) throw -16;
455          EventHeader *ehc = 0;
456          PscuHeader *phc = 0;
457          TC->SetBranchAddress("Header", &ehc);
458          TC->GetEntry(0);
459          phc = ehc->GetPscuHeader();
460          pktfirst = phc->GetCounter();
461          obtfirst = phc->GetOrbitalTime();  
462          //
463        };
464      };  
465    //    //
466    T->GetEntry(nevent-1);    T->GetEntry(nevent-1);
467    ph = eh->GetPscuHeader();    ph = eh->GetPscuHeader();
# Line 359  Int_t PamelaDBOperations::SetUpperLimits Line 472  Int_t PamelaDBOperations::SetUpperLimits
472    upperobt = OBT(obtlast);    upperobt = OBT(obtlast);
473    upperentry = nevent-1;    upperentry = nevent-1;
474    //    //
475    if ( IsDebug() ) printf(" First entries are: OBT %i pkt_num %i \n",obtfirst,pktfirst);    if ( IsDebug() ) printf(" First entries are: OBT %u pkt_num %u \n",obtfirst,pktfirst);
476    //    //
477    if ( IsDebug() ) printf(" Last entries are: OBT %lld pkt_num %lld entry %i\n",upperobt,upperpkt,upperentry);    if ( IsDebug() ) printf(" Last entries are: OBT %lld pkt_num %lld entry %i\n",upperobt,upperpkt,upperentry);
478    //    //
479    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(32);
480    //    //
481    if ( !nevent ) return(2);    if ( !nevent ) return(64);
482    //    //
483    if ( nevent < 2 ) return(4);    if ( nevent < 2 ) return(128);
484    if ( nevent < jump ) jump = 1;    if ( nevent < jump ) jump = 1;
485    //  if ( nevent < jump ) jump = int(nevent/10);    //  if ( nevent < jump ) jump = int(nevent/10);
486    //  if ( !jump ) jump = 1;    //  if ( !jump ) jump = 1;
# Line 406  Int_t PamelaDBOperations::SetUpperLimits Line 519  Int_t PamelaDBOperations::SetUpperLimits
519          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 ){
520            zomp = i + jump + 1;            zomp = i + jump + 1;
521            if ( zomp > nevent-2 ) zomp = nevent - 2;            if ( zomp > nevent-2 ) zomp = nevent - 2;
522            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);            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);
523            break;            break;
524          };          };
525          //          //
# Line 452  Int_t PamelaDBOperations::SetUpperLimits Line 565  Int_t PamelaDBOperations::SetUpperLimits
565    //    //
566    if ( rhev || rtev ){    if ( rhev || rtev ){
567    
568        T->GetEntry(upperentry);
569    T->GetEntry(upperentry);      code = eh->GetCounter();
570    code = eh->GetCounter();      Int_t lasttrail = code->Get(pctp->RunTrailer);
571    Int_t lasttrail = code->Get(pctp->RunTrailer);      Int_t lasthead = code->Get(pctp->RunHeader);
572    Int_t lasthead = code->Get(pctp->RunHeader);      if ( lasttrail < rtev ){
573    if ( lasttrail < rtev ){        rt->GetEntry(lasttrail);
574      rt->GetEntry(lasttrail);        pht = eht->GetPscuHeader();
575      pht = eht->GetPscuHeader();        pktt = PKT(pht->GetCounter());
576      pktt = PKT(pht->GetCounter());        obtt = OBT(pht->GetOrbitalTime());
577      obtt = OBT(pht->GetOrbitalTime());      };
578    };      //
579    //      if ( lasthead < rhev ){
580    if ( lasthead < rhev ){        rh->GetEntry(lasthead);
581      rh->GetEntry(lasthead);        phh = ehh->GetPscuHeader();
582      phh = ehh->GetPscuHeader();        pkth = PKT(phh->GetCounter());
583      pkth = PKT(phh->GetCounter());        obth = OBT(phh->GetOrbitalTime());
584      obth = OBT(phh->GetOrbitalTime());      };
585    };      //
586    //      if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);
587    if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);      if ( pkth > upperpkt && obth > upperobt ){
588    if ( 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);
589      if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt);        upperpkt = pkth;
590      upperpkt = pkth;        upperobt = obth;
591      upperobt = obth;        rhev = lasthead+1;
592      rhev = lasthead+1;      } else {
593    } else {        rhev = lasthead;
594      rhev = lasthead;      };
595    };      if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);
596    if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);      //
597    //      if ( IsDebug() ) printf(" rtev beforev %i  pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);
598    if ( IsDebug() ) printf(" rtev beforev %i  pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);      if ( pktt > upperpkt && obtt > upperobt ){
599    if ( 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);
600      if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt);        upperpkt = pktt;
601      upperpkt = pktt;        upperobt = obtt;
602      upperobt = obtt;        rtev = lasttrail+1;
603      rtev = lasttrail+1;      } else {
604    } else {        rtev = lasttrail;
605      rtev = lasttrail;      };
606    };      if ( IsDebug() ) printf(" rtev after %i  pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);
607    if ( IsDebug() ) printf(" rtev after %i  pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);      //  goto kikko;
608    //  goto kikko;      //
609    //      //
610    //      // Check if runtrailer/runheader are within lower limits
611    // Check if runtrailer/runheader are within lower limits      //
612    //      //
613    //      pkth = 0LL;
614    pkth = 0LL;      obth = 0LL;
615    obth = 0LL;      spkth = 0LL;
616    spkth = 0LL;      sobth = 0LL;
617    sobth = 0LL;      for (Int_t k=0; k<rhev; k++){
618    for (Int_t k=0; k<rhev; k++){        if ( k > 0 ){
619      if ( k > 0 ){          spkth = pkth;
620        spkth = pkth;          sobth = obth;
621        sobth = obth;        };
622      };        rh->GetEntry(k);
623      rh->GetEntry(k);        phh = ehh->GetPscuHeader();
624      phh = ehh->GetPscuHeader();        pkth = PKT(phh->GetCounter());
625      pkth = PKT(phh->GetCounter());        obth = OBT(phh->GetOrbitalTime());
626      obth = OBT(phh->GetOrbitalTime());        //
627      //        //    if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth);
628  //    if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth);        //
629      //        if ( pkth < spkth && obth < sobth ){
630      if ( pkth < spkth && obth < sobth ){          if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i  \n",rhev);
631        if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i  \n",rhev);          //
632        //          rhev = k-1;
633        rhev = k-1;          rh->GetEntry(rhev);
634        rh->GetEntry(rhev);          pkth = spkth;
635        pkth = spkth;          obth = sobth;
636        obth = sobth;          //
637        //          UInt_t evbefh = 0;
638        UInt_t evbefh = 0;          code = ehh->GetCounter();
639        code = ehh->GetCounter();          evbefh = code->Get(pctp->Physics);    
640        evbefh = code->Get(pctp->Physics);              if ( evbefh >= 0 ){
641        if ( evbefh >= 0 ){            T->GetEntry(evbefh);
         T->GetEntry(evbefh);  
         ph = eh->GetPscuHeader();  
         t_pktlast = PKT(ph->GetCounter());  
         t_obtlast = OBT(ph->GetOrbitalTime());  
         if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump  
           upperpkt = pkth;  
           upperobt = obth;  
           upperentry = evbefh-1;  
         } else {  
           while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){  
             evbefh++;    
             T->GetEntry(evbefh);  
             ph = eh->GetPscuHeader();  
             t_pktlast = PKT(ph->GetCounter());  
             t_obtlast = OBT(ph->GetOrbitalTime());  
           };  
           T->GetEntry(evbefh-1);  
642            ph = eh->GetPscuHeader();            ph = eh->GetPscuHeader();
643            upperpkt = PKT(ph->GetCounter());            t_pktlast = PKT(ph->GetCounter());
644            upperobt = OBT(ph->GetOrbitalTime());            t_obtlast = OBT(ph->GetOrbitalTime());
645            upperentry = evbefh-1;            if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump
646          };                  upperpkt = pkth;
647                upperobt = obth;
648                upperentry = evbefh-1;
649              } else {
650                while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){
651                  evbefh++;
652                  T->GetEntry(evbefh);
653                  ph = eh->GetPscuHeader();
654                  t_pktlast = PKT(ph->GetCounter());
655                  t_obtlast = OBT(ph->GetOrbitalTime());
656                };
657                T->GetEntry(evbefh-1);
658                ph = eh->GetPscuHeader();
659                upperpkt = PKT(ph->GetCounter());
660                upperobt = OBT(ph->GetOrbitalTime());
661                upperentry = evbefh-1;
662              };    
663            };
664            if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);
665            goto kikko0;
666        };        };
       if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);  
       goto kikko0;  
667      };      };
668    };    kikko0:
669   kikko0:      //
   //  
   //  
   //  
   pktt = 0LL;  
   obtt = 0LL;  
   spktt = 0LL;  
   sobtt = 0LL;  
   for (Int_t k=0; k<rtev; k++){  
     if ( k > 0 ){  
       spktt = pktt;  
       sobtt = obtt;  
     };  
     rt->GetEntry(k);  
     pht = eht->GetPscuHeader();  
     pktt = PKT(pht->GetCounter());  
     obtt = OBT(pht->GetOrbitalTime());  
670      //      //
 //    if ( IsDebug() ) printf(" k %i rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt);  
671      //      //
672      if ( pktt < spktt && obtt < sobtt ){      pktt = 0LL;
673        if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev);      obtt = 0LL;
674        spktt = 0LL;
675        sobtt = 0LL;
676        for (Int_t k=0; k<rtev; k++){
677          if ( k > 0 ){
678            spktt = pktt;
679            sobtt = obtt;
680          };
681          rt->GetEntry(k);
682          pht = eht->GetPscuHeader();
683          pktt = PKT(pht->GetCounter());
684          obtt = OBT(pht->GetOrbitalTime());
685        //        //
686        rtev = k-1;        //    if ( IsDebug() ) printf(" k %i rtev beforev %i  pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt);
       rt->GetEntry(rtev);  
       pktt = spktt;  
       obtt = sobtt;  
       if ( IsDebug() ) printf(" lasttrail %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);  
687        //        //
688        UInt_t evbeft = 0;        if ( pktt < spktt && obtt < sobtt ){
689        code = eht->GetCounter();          if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev);
690        evbeft = code->Get(pctp->Physics);              //
691        if ( evbeft >= 0 ){          rtev = k-1;
692          T->GetEntry(evbeft);          rt->GetEntry(rtev);
693          ph = eh->GetPscuHeader();          pktt = spktt;
694          t_pktlast = PKT(ph->GetCounter());          obtt = sobtt;
695          t_obtlast = OBT(ph->GetOrbitalTime());          if ( IsDebug() ) printf(" lasttrail %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);
696          if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump          //
697            upperpkt = pktt;          UInt_t evbeft = 0;
698            upperobt = obtt;          code = eht->GetCounter();
699            upperentry = evbeft-1;          evbeft = code->Get(pctp->Physics);    
700          } else {          if ( evbeft >= 0 ){
701            while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){            T->GetEntry(evbeft);
702              evbeft++;              ph = eh->GetPscuHeader();
703              T->GetEntry(evbeft);            t_pktlast = PKT(ph->GetCounter());
704              t_obtlast = OBT(ph->GetOrbitalTime());
705              if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump
706                upperpkt = pktt;
707                upperobt = obtt;
708                upperentry = evbeft-1;
709              } else {
710                while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){
711                  evbeft++;
712                  T->GetEntry(evbeft);
713                  ph = eh->GetPscuHeader();
714                  t_pktlast = PKT(ph->GetCounter());
715                  t_obtlast = OBT(ph->GetOrbitalTime());
716                };
717                T->GetEntry(evbeft-1);
718              ph = eh->GetPscuHeader();              ph = eh->GetPscuHeader();
719              t_pktlast = PKT(ph->GetCounter());              upperpkt = PKT(ph->GetCounter());
720              t_obtlast = OBT(ph->GetOrbitalTime());              upperobt = OBT(ph->GetOrbitalTime());
721                upperentry = evbeft-1;
722            };            };
           T->GetEntry(evbeft-1);  
           ph = eh->GetPscuHeader();  
           upperpkt = PKT(ph->GetCounter());  
           upperobt = OBT(ph->GetOrbitalTime());  
           upperentry = evbeft-1;  
723          };          };
724            if ( IsDebug() ) printf(" rtev after %i  pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);
725            goto kikko;
726            //      break;
727            //
728        };        };
729        if ( IsDebug() ) printf(" rtev after %i  pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);        //  
       goto kikko;  
       //      break;  
       //  
730      };      };
731      //        //
732    };    kikko:
733    //      //
734   kikko:      T->GetEntry(upperentry);
735    //      code = eh->GetCounter();
736    T->GetEntry(upperentry);      lasttrail = code->Get(pctp->RunTrailer);
737    code = eh->GetCounter();      lasthead = code->Get(pctp->RunHeader);
738    lasttrail = code->Get(pctp->RunTrailer);      if ( lasttrail < rtev ){
739    lasthead = code->Get(pctp->RunHeader);        rt->GetEntry(lasttrail);
740    if ( lasttrail < rtev ){        pht = eht->GetPscuHeader();
741      rt->GetEntry(lasttrail);        pktt = PKT(pht->GetCounter());
742      pht = eht->GetPscuHeader();        obtt = OBT(pht->GetOrbitalTime());
743      pktt = PKT(pht->GetCounter());      };
744      obtt = OBT(pht->GetOrbitalTime());      //
745    };      if ( lasthead < rhev ){
746    //        rh->GetEntry(lasthead);
747    if ( lasthead < rhev ){        phh = ehh->GetPscuHeader();
748      rh->GetEntry(lasthead);        pkth = PKT(phh->GetCounter());
749      phh = ehh->GetPscuHeader();        obth = OBT(phh->GetOrbitalTime());
750      pkth = PKT(phh->GetCounter());      };
751      obth = OBT(phh->GetOrbitalTime());      //
752    };      if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);
753    //      if ( pkth > upperpkt && obth > upperobt ){
754    if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,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);
755    if ( pkth > upperpkt && obth > upperobt ){        upperpkt = pkth;
756      if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt);        upperobt = obth;
757      upperpkt = pkth;        rhev = lasthead+1;
758      upperobt = obth;      } else {
759      rhev = lasthead+1;        rhev = lasthead;
760    } else {      };
761      rhev = lasthead;      if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);
762    };      //
763    if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt);      if ( IsDebug() ) printf(" rtev beforev %i  pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);
764    //      if ( pktt > upperpkt && obtt > upperobt ){
765    if ( IsDebug() ) printf(" rtev beforev %i  pt %lld upperp %lld ot %lld uppero %lld \n",rtev,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);
766    if ( pktt > upperpkt && obtt > upperobt ){        upperpkt = pktt;
767      if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt);        upperobt = obtt;
768      upperpkt = pktt;        rtev = lasttrail+1;
769      upperobt = obtt;      } else {
770      rtev = lasttrail+1;        rtev = lasttrail;
771    } else {      };
772      rtev = lasttrail;      if ( IsDebug() ) printf(" rtev after %i  pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);
773    };      //
   if ( IsDebug() ) printf(" rtev after %i  pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt);  
   //  
   
   
774    };    };
775    //    //
776    if ( IsDebug() ) printf(" Upper limits are: OBT %lld pkt_num %lld 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);
# Line 822  void PamelaDBOperations::CheckConnection Line 932  void PamelaDBOperations::CheckConnection
932   */   */
933  Long64_t PamelaDBOperations::PKT(UInt_t pkt_num){    Long64_t PamelaDBOperations::PKT(UInt_t pkt_num){  
934    //    //
935    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));    if ( IsDebug() ) printf(" pkt conversion: pkt_num is %u pktfirst is %u  (UInt_t)(16777214/2)) is %u  \n",pkt_num,ppktfirst,(UInt_t)(16777214/2));
936    //    //
937    if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2)  ){    if ( pkt_num < (ppktfirst/2) && ppktfirst > (16777214/2)  ){
938      if ( IsDebug() ) printf(" rise up pktnum %lld \n",(Long64_t)pkt_num+16777215LL);      if ( IsDebug() ) printf(" rise up pktnum %lld \n",(Long64_t)pkt_num+16777215LL);
939      return((Long64_t)pkt_num+16777215LL);      return((Long64_t)pkt_num+16777215LL);
940    };    };
941    //    //
942    if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){    if ( pkt_num > ((Long64_t)ppktfirst*2) && pkt_num > (16777214/2) ){
943      if ( IsDebug() ) printf(" rise down pktnum %lld \n",(Long64_t)pkt_num-16777215LL);      if ( IsDebug() ) printf(" rise down pktnum %lld \n",(Long64_t)pkt_num-16777215LL);
944      return((Long64_t)pkt_num-16777215LL);      return((Long64_t)pkt_num-16777215LL);
945    };    };
# Line 844  Long64_t PamelaDBOperations::PKT(UInt_t Line 954  Long64_t PamelaDBOperations::PKT(UInt_t
954   */   */
955  Long64_t PamelaDBOperations::OBT(UInt_t obt){    Long64_t PamelaDBOperations::OBT(UInt_t obt){  
956    //    //
957    if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((Long64_t)(obt+numeric_limits<UInt_t>::max()));    if ( IsDebug() ) printf(" obt conversion: obt is %u obtfirst is %u  (numeric_limits<UInt_t>::max()/2) is %u  \n",obt,pobtfirst,(UInt_t)(numeric_limits<UInt_t>::max()/2));
958    //    //
959    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){    if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){
960        if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)(obt+numeric_limits<UInt_t>::max()));
961        return((Long64_t)(obt+numeric_limits<UInt_t>::max()));
962      };
963      //
964      if ( obt > ((Long64_t)pobtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
965        if ( IsDebug() ) printf(" pobtfirst*2 %lld \n",((Long64_t)pobtfirst*2));
966        if ( IsDebug() ) printf(" rise down pktnum %lld \n", (Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());
967      return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());      return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());
968    };    };
969    //    //
970      if ( IsDebug() ) printf(" as it is %lld \n",(Long64_t)obt);
971    return((Long64_t)obt);    return((Long64_t)obt);
972  };  };
973    
# Line 965  Int_t PamelaDBOperations::insertPamelaRa Line 1083  Int_t PamelaDBOperations::insertPamelaRa
1083    if ( idr ) return(1);    if ( idr ) return(1);
1084    //    //
1085    oss.str("");    oss.str("");
1086    oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('"    if ( STATIC ){
1087        << this->GetRawPath().Data() << "', '" << this->GetRawFile().Data() << "')";      oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('"
1088            << this->GetRawPath().Data() << "', '" << this->GetRawFile().Data() << "')";
1089      } else {
1090        oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << this->GetRawFile().Data() << "')";
1091      };
1092    if ( conn->Query(oss.str().c_str()) == 0 ) throw -4;    if ( conn->Query(oss.str().c_str()) == 0 ) throw -4;
1093    //    //
1094    idr =  this->SetID_RAW();    idr =  this->SetID_RAW();
# Line 985  Int_t PamelaDBOperations::insertPamelaGL Line 1107  Int_t PamelaDBOperations::insertPamelaGL
1107    TSQLResult *result = 0;    TSQLResult *result = 0;
1108    TSQLRow *row = 0;    TSQLRow *row = 0;
1109    UInt_t t0 = 0;    UInt_t t0 = 0;
1110      Int_t signal = 0;
1111      UInt_t idresof = 0;
1112      //
1113      signal = this->SetUpperLimits();
1114    //    //
1115    stringstream   oss;    stringstream   oss;
1116    //      //  
1117    if ( this->GetID_RAW() == 0 )  throw -11;    if ( this->GetID_RAW() == 0 )  throw -11;
1118    //    //
1119    oss.str("");    oss.str("");
1120    oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='"    oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='"
1121        << this->GetRawFile().Data() << "';";        << this->GetRawFile().Data() << "';";
1122    if ( IsDebug() ) printf(" %s \n",oss.str().c_str());    if ( IsDebug() ) printf(" %s \n",oss.str().c_str());
1123    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
# Line 1000  Int_t PamelaDBOperations::insertPamelaGL Line 1126  Int_t PamelaDBOperations::insertPamelaGL
1126    //    //
1127    if ( !row ){    if ( !row ){
1128      oss.str("");      oss.str("");
1129      oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< "      oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< "
1130          << dworbit << " order by FROM_ORBIT desc limit 1;";          << dworbit << " order by FROM_ORBIT desc limit 1;";
1131      if ( IsDebug() ) printf(" %s \n",oss.str().c_str());      if ( IsDebug() ) printf(" %s \n",oss.str().c_str());
1132      result = conn->Query(oss.str().c_str());      result = conn->Query(oss.str().c_str());
# Line 1009  Int_t PamelaDBOperations::insertPamelaGL Line 1135  Int_t PamelaDBOperations::insertPamelaGL
1135      if ( !row ) throw -10;      if ( !row ) throw -10;
1136    };    };
1137    //    //
1138      idresof = (UInt_t)atoll(row->GetField(6));
1139      //
1140    TTimeStamp tu = TTimeStamp((UInt_t)atoi(row->GetField(0)),(UInt_t)atoi(row->GetField(1)),(UInt_t)atoi(row->GetField(2)),(UInt_t)atoi(row->GetField(3)),(UInt_t)atoi(row->GetField(4)),(UInt_t)atoi(row->GetField(5)),0,true,0);    TTimeStamp tu = TTimeStamp((UInt_t)atoi(row->GetField(0)),(UInt_t)atoi(row->GetField(1)),(UInt_t)atoi(row->GetField(2)),(UInt_t)atoi(row->GetField(3)),(UInt_t)atoi(row->GetField(4)),(UInt_t)atoi(row->GetField(5)),0,true,0);
1141    t0 = (UInt_t)tu.GetSec();    t0 = (UInt_t)tu.GetSec();
1142    if ( IsDebug() ) printf(" t0 is %u ti is %s %s %s %s %s %s\n",t0,row->GetField(0),row->GetField(1),row->GetField(2),row->GetField(3),row->GetField(4),row->GetField(5));    if ( IsDebug() ) printf(" t0 is %u ti is %s %s %s %s %s %s %s\n",t0,row->GetField(0),row->GetField(1),row->GetField(2),row->GetField(3),row->GetField(4),row->GetField(5),row->GetField(6));
1143    //    //
1144    /*    /*
1145     * Verify that the TIMESYNC have been not already processed     * Verify that the TIMESYNC have been not already processed
# Line 1037  Int_t PamelaDBOperations::insertPamelaGL Line 1165  Int_t PamelaDBOperations::insertPamelaGL
1165    };    };
1166    //    //
1167    TTree *T = 0;    TTree *T = 0;
   Int_t signal = 0;  
1168    //    //
1169    UInt_t nevent = 0;    UInt_t nevent = 0;
1170    UInt_t recEntries = 0;    UInt_t recEntries = 0;
# Line 1218  Int_t PamelaDBOperations::insertPamelaGL Line 1345  Int_t PamelaDBOperations::insertPamelaGL
1345    if ( !existsts ) throw -3;    if ( !existsts ) throw -3;
1346    //    //
1347    oss.str("");    oss.str("");
1348    oss << "INSERT INTO GL_TIMESYNC (ID_RAW,TYPE,OBT0,TIMESYNC) VALUES ('"    oss << "INSERT INTO GL_TIMESYNC (ID_RAW,TYPE,OBT0,TIMESYNC,ID_RESURS_OFFSET) VALUES ('"
1349        << this->GetID_RAW() << "','"//224'"        << this->GetID_RAW() << "','"//224'"
1350        << dec << (UInt_t)TYPE << "','"        << dec << (UInt_t)TYPE << "','"
1351        << dec << (UInt_t)OBT << "','"        << dec << (UInt_t)OBT << "','"
1352        << dec << (UInt_t)TSYNC << "');";        << dec << (UInt_t)TSYNC << "','"
1353          << dec << (UInt_t)idresof << "');";
1354    conn->Query(oss.str().c_str());    conn->Query(oss.str().c_str());
1355    if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to fill it:\n %s \n",oss.str().c_str());    if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to fill it:\n %s \n",oss.str().c_str());
1356      if ( conn->GetErrorCode() ){
1357        printf(" OK, you got an error because the database structure you are using is not up to date\n Using backward compability code, hence you can continue safetly \n");
1358        oss.str("");
1359        oss << "INSERT INTO GL_TIMESYNC (ID_RAW,TYPE,OBT0,TIMESYNC) VALUES ('"
1360            << this->GetID_RAW() << "','"//224'"
1361            << dec << (UInt_t)TYPE << "','"
1362            << dec << (UInt_t)OBT << "','"
1363            << dec << (UInt_t)TSYNC << "');";
1364        conn->Query(oss.str().c_str());
1365        if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to fill it:\n %s \n",oss.str().c_str());
1366      };
1367    //    //
1368    if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);    if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0);
1369      //
1370    toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0;    toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0;
1371    //    //
1372    tsync = TSYNC;    tsync = TSYNC;
# Line 1247  Int_t PamelaDBOperations::insertPamelaRo Line 1387  Int_t PamelaDBOperations::insertPamelaRo
1387    UInt_t idtimesync = 0;    UInt_t idtimesync = 0;
1388    //    //
1389    oss.str("");    oss.str("");
1390    oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW "    if ( STATIC ){
1391        << " LEFT JOIN GL_ROOT "      oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW "
1392        << " ON GL_RAW.ID = GL_ROOT.ID_RAW "          << " LEFT JOIN GL_ROOT "
1393        << " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND "          << " ON GL_RAW.ID = GL_ROOT.ID_RAW "
1394        << " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID ";          << " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND "
1395            << " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID ";
1396      } else {
1397        oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW "
1398            << " LEFT JOIN GL_ROOT "
1399            << " ON GL_RAW.ID = GL_ROOT.ID_RAW "
1400            << " WHERE GL_RAW.PATH = '$PAM_RAW' AND "
1401            << " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID ";
1402      };
1403    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
1404    //    //
1405    if ( !result ) throw -12;    if ( !result ) throw -12;
# Line 1278  Int_t PamelaDBOperations::insertPamelaRo Line 1426  Int_t PamelaDBOperations::insertPamelaRo
1426    idtimesync = (UInt_t)atoll(row->GetField(0));    idtimesync = (UInt_t)atoll(row->GetField(0));
1427    //    //
1428    oss.str("");    oss.str("");
1429    oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('"    if ( STATIC ){
1430        << this->GetID_RAW() << "', '" << idtimesync << "', '" << this->GetRootPath().Data() << "', '" << this->GetRootFile().Data() << "')";      oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('"
1431            << this->GetID_RAW() << "', '" << idtimesync << "', '" << this->GetRootPath().Data() << "', '" << this->GetRootFile().Data() << "')";
1432      } else {
1433        oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('"
1434            << this->GetID_RAW() << "', '" << idtimesync << "', '$PAM_L0', '" << this->GetRootFile().Data() << "')";
1435      };
1436    //    //
1437    if (conn->Query(oss.str().c_str()) == 0) throw -4;    if (conn->Query(oss.str().c_str()) == 0) throw -4;
1438    //    //
# Line 1306  Int_t PamelaDBOperations::assignBOOT_NUM Line 1459  Int_t PamelaDBOperations::assignBOOT_NUM
1459    TSQLResult *result = 0;    TSQLResult *result = 0;
1460    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
1461    oss.str("");    oss.str("");
1462    oss << "SELECT ID, BOOT_NUMBER FROM GL_RAW WHERE "    if ( STATIC ){
1463        << " PATH = '" << this->GetRawPath().Data() << "' AND "      oss << "SELECT ID, BOOT_NUMBER FROM GL_RAW WHERE "
1464        << " NAME = '" << this->GetRawFile().Data() << "' ";          << " PATH = '" << this->GetRawPath().Data() << "' AND "
1465            << " NAME = '" << this->GetRawFile().Data() << "' ";
1466      } else {
1467        oss << "SELECT ID, BOOT_NUMBER FROM GL_RAW WHERE "
1468            << " PATH = '$PAM_RAW' AND "
1469            << " NAME = '" << this->GetRawFile().Data() << "' ";
1470      };
1471    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
1472    //    //
1473    if ( !result ) throw -4;;    if ( !result ) throw -4;;
# Line 1427  Int_t PamelaDBOperations::insertPamelaRU Line 1586  Int_t PamelaDBOperations::insertPamelaRU
1586    stringstream oss;    stringstream oss;
1587    oss.str("");    oss.str("");
1588    //    //
1589    signal = this->SetUpperLimits();    //  signal = this->SetUpperLimits();
1590    //    //
1591    // loop on runheader and runtrailer events    // loop on runheader and runtrailer events
1592    //    //
# Line 1445  Int_t PamelaDBOperations::insertPamelaRU Line 1604  Int_t PamelaDBOperations::insertPamelaRU
1604    rt->SetBranchAddress("RunTrailer", &runt);    rt->SetBranchAddress("RunTrailer", &runt);
1605    rt->SetBranchAddress("Header", &eht);    rt->SetBranchAddress("Header", &eht);
1606    //    //
1607      TTree *T = (TTree*)file->Get("Physics");
1608      if ( !T || T->IsZombie() ) throw -16;
1609      EventHeader *eh = 0;
1610      T->SetBranchAddress("Header", &eh);
1611      //
1612      if ( !(rh->GetEntries()) && !(rt->GetEntries()) && !(T->GetEntries()) ) return(16);
1613      //
1614    UInt_t obtt = 0;    UInt_t obtt = 0;
1615    UInt_t obth = 0;    UInt_t obth = 0;
1616    UInt_t pktt = 0;    UInt_t pktt = 0;
# Line 1478  Int_t PamelaDBOperations::insertPamelaRU Line 1644  Int_t PamelaDBOperations::insertPamelaRU
1644        //        //
1645        if ( !ptt &&  !(ptht+1) ){        if ( !ptt &&  !(ptht+1) ){
1646          //          //
1647          if ( IsDebug() ) printf(" Piece of run at the beginning of the file %i %i %i \n",ptht,pth,ptt);          if ( IsDebug() ) printf(" Piece of run at the beginning of the file %u %u %u \n",ptht,pth,ptt);
1648          //          //
1649          this->HandleRunFragments(true,false,0,(evbeft-1));          this->HandleRunFragments(true,false,0,(evbeft-1));
1650          //          //
1651          //          //
1652        } else if ( pth == ptht ){        } else if ( pth == ptht ){
1653          //          //
1654          if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt);          if ( IsDebug() ) printf(" Missing header %u %u %u\n",ptht,pth,ptt);
1655          //          //
1656          if ( (ptt-1) < 0 ) throw -15; // should never arrive here!          if ( (ptt-1) < 0 ) throw -15; // should never arrive here!
1657          rt->GetEntry(ptt-1);          rt->GetEntry(ptt-1);
# Line 1494  Int_t PamelaDBOperations::insertPamelaRU Line 1660  Int_t PamelaDBOperations::insertPamelaRU
1660          rt->GetEntry(ptt);          rt->GetEntry(ptt);
1661          pht = eht->GetPscuHeader();          pht = eht->GetPscuHeader();
1662          //          //
1663          if ( IsDebug() ) printf(" Try to find the beginning of a run which has only the runtrailer   %i %i %i \n",ptht,pth,ptt);          if ( IsDebug() ) printf(" Try to find the beginning of a run which has only the runtrailer   %u %u %u \n",ptht,pth,ptt);
1664          if ( IsDebug() ) printf(" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  %i %i %i \n",pkth,obth,obtt);          if ( IsDebug() ) printf(" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  %u %u %u \n",pkth,obth,obtt);
1665          //          //
1666          this->HandleMissingHoT(true,false,evbefh,evbeft-1);          this->HandleMissingHoT(true,false,evbefh,evbeft-1);
1667          //          //
1668        } else {        } else {
1669          //          //
1670          if ( IsDebug() ) printf(" Could be a good run, we have a runheader followed by a runtrailer %i %i %i\n",ptht,pth,ptt);          if ( IsDebug() ) printf(" Could be a good run, we have a runheader followed by a runtrailer %u %u %u\n",ptht,pth,ptt);
1671          //          //
1672          rh->GetEntry(ptht);          rh->GetEntry(ptht);
1673          phh = ehh->GetPscuHeader();          phh = ehh->GetPscuHeader();
# Line 1509  Int_t PamelaDBOperations::insertPamelaRU Line 1675  Int_t PamelaDBOperations::insertPamelaRU
1675          obth = phh->GetOrbitalTime();          obth = phh->GetOrbitalTime();
1676          cod = ehh->GetCounter();          cod = ehh->GetCounter();
1677          evbefh = cod->Get(pctp->Physics);          evbefh = cod->Get(pctp->Physics);
1678          if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %i %i %i \n",pkth,obth,obtt);          if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %u %u %u \n",pkth,obth,obtt);
1679          //          //
1680          // handle this run          // handle this run
1681          //          //
# Line 1519  Int_t PamelaDBOperations::insertPamelaRU Line 1685  Int_t PamelaDBOperations::insertPamelaRU
1685          //          //
1686          if ( PKT(pkth)>PKT(pktfirst) && OBT(obth)>OBT(obtfirst) && !ptt ){          if ( PKT(pkth)>PKT(pktfirst) && OBT(obth)>OBT(obtfirst) && !ptt ){
1687            //            //
1688            if ( IsDebug() ) printf(" Piece of run at the beginning of the file WITH NO RUNTRAILER \n");            if ( IsDebug() ) printf(" Piece of run at the beginning of the file WITH NO RUNTRAILER evbefh = %u \n",evbefh);        
           //  
           this->HandleRunFragments(true,true,0,(evbefh-1));  
1689            //            //
1690              if ( evbefh == 0 ) {
1691                //
1692                signal = 8;
1693                if ( IsDebug() ) printf(" Not supported yet: run with no events, no runtrailer, no runheader \n");
1694                //
1695              } else {
1696                //
1697                this->HandleRunFragments(true,true,0,(evbefh-1));
1698                //
1699              };
1700          };          };
1701          //          //
1702          //          //
1703          if ( (ptht - pth) > 1 ){          if ( (ptht - pth) > 1 ){
1704            //            //
1705            if ( IsDebug() ) printf(" Missing runtrailers! \n");            if ( IsDebug() ) printf(" Missing runtrailers! \n");
1706            if ( IsDebug() ) printf(" Attention there is a jump in the runheader counter %i %i %i \n",ptht,pth,ptt);            if ( IsDebug() ) printf(" Attention there is a jump in the runheader counter %u %u %u \n",ptht,pth,ptt);
1707            // is not the consecutive header            // is not the consecutive header
1708            while ( pth != ptht ){                      while ( pth != ptht ){          
1709              //              //
# Line 1550  Int_t PamelaDBOperations::insertPamelaRU Line 1724  Int_t PamelaDBOperations::insertPamelaRU
1724              obth = phh->GetOrbitalTime();              obth = phh->GetOrbitalTime();
1725              evbefh = cod->Get(pctp->Physics);              evbefh = cod->Get(pctp->Physics);
1726              //              //
1727              if ( IsDebug() ) printf(" Try to find the end of a run which has only the runheader   %i %i %i \n",ptht,pth,ptt);              if ( IsDebug() ) printf(" Try to find the end of a run which has only the runheader   %u %u %u \n",ptht,pth,ptt);
1728              if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %i %i %i \n",pkth,obth,obtt);              if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %u %u %u \n",pkth,obth,obtt);
1729              //              //
1730              this->HandleMissingHoT(false,true,evbefh,evbeft-1);              this->HandleMissingHoT(false,true,evbefh,evbeft-1);
1731              //              //
# Line 1560  Int_t PamelaDBOperations::insertPamelaRU Line 1734  Int_t PamelaDBOperations::insertPamelaRU
1734          } else if ( !(ptht - pth) ){          } else if ( !(ptht - pth) ){
1735            //            //
1736            if ( IsDebug() ) printf(" Missing runheader! \n");            if ( IsDebug() ) printf(" Missing runheader! \n");
1737            if ( IsDebug() ) printf(" Attention! the runheader counter did not changed %i %i %i \n",ptht,pth,ptt);            if ( IsDebug() ) printf(" Attention! the runheader counter did not changed %u %u %u \n",ptht,pth,ptt);
1738            if ( IsDebug() ) printf(" The run should have already been handled by HandleRun() \n");            if ( IsDebug() ) printf(" The run should have already been handled by HandleRun() \n");
1739            //            //
1740          } else {          } else {
# Line 1581  Int_t PamelaDBOperations::insertPamelaRU Line 1755  Int_t PamelaDBOperations::insertPamelaRU
1755            obth = phh->GetOrbitalTime();            obth = phh->GetOrbitalTime();
1756            cod = ehh->GetCounter();            cod = ehh->GetCounter();
1757            evbefh = cod->Get(pctp->Physics);            evbefh = cod->Get(pctp->Physics);
1758            if ( IsDebug() ) printf(" Piece of run at the end of file %i %i %i \n",pkth,obth,obtt);            if ( IsDebug() ) printf(" Piece of run at the end of file %u %u %u \n",pkth,obth,obtt);
1759            if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''' %i %i %i \n",ptht,pth,ptt);            if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''' %u %u %u \n",ptht,pth,ptt);
1760            if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''' %i \n",rhev);            if ( IsDebug() ) printf(" ''''''''''''''''''''''''''''''' %u \n",rhev);
1761            //            //
1762            this->HandleRunFragments(false,true,evbefh,upperentry);            this->HandleRunFragments(false,true,evbefh,upperentry);
1763          } else {          } else {
# Line 1631  Bool_t PamelaDBOperations::IsRunAlreadyI Line 1805  Bool_t PamelaDBOperations::IsRunAlreadyI
1805    //                                  ( runhead_time <= _our_runhead_time &&  runtrail_time >= _our_runtrail_time) &&    //                                  ( runhead_time <= _our_runhead_time &&  runtrail_time >= _our_runtrail_time) &&
1806    //                                  ( runhead_obt <= _our_runheadobt || runhead_pkt <= _our_runheadpkt ) &&    //                                  ( runhead_obt <= _our_runheadobt || runhead_pkt <= _our_runheadpkt ) &&
1807    //                                  ( runtrail_obt <= _our_runtrailobt || runtrail_pkt <= _our_runtrailpkt ) )    //                                  ( runtrail_obt <= _our_runtrailobt || runtrail_pkt <= _our_runtrailpkt ) )
1808      //                                  ||
1809      //                                  ( runhead_time = _our_runhead_time &&  runtrail_time = _our_runtrail_time && nevents > 100 )
1810      //                                  )
1811      //                                  ||
1812      //                                  ( runhead_time = _our_runhead_time &&  runtrail_time > _our_runtrail_time && nevents > 100 )
1813      //                                  )
1814      //                                  ||
1815      //                                  ( runhead_time < _our_runhead_time &&  runtrail_time = _our_runtrail_time && nevents > 100 )
1816    //                                  )    //                                  )
1817    //    //
1818    oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE "    oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE "
# Line 1646  Bool_t PamelaDBOperations::IsRunAlreadyI Line 1828  Bool_t PamelaDBOperations::IsRunAlreadyI
1828        << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR "        << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR "
1829        << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND ("        << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND ("
1830        << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR "        << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR "
1831        << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));";        << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") OR "
1832          << " (RUNHEADER_TIME=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "                //  these two lines in a certain way disable the patch below...
1833          << " RUNTRAILER_TIME=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100) OR"    //
1834          << " (RUNHEADER_TIME=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "                //
1835          << " RUNTRAILER_TIME>" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100) OR"    //
1836          << " (RUNHEADER_TIME<" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "                //
1837          << " RUNTRAILER_TIME=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100)"    //
1838          << " ));";
1839    //    //
1840    if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str());    if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str());
1841    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
# Line 1668  Bool_t PamelaDBOperations::IsRunAlreadyI Line 1857  Bool_t PamelaDBOperations::IsRunAlreadyI
1857      //      //
1858      // the run has already been inserted      // the run has already been inserted
1859      //      //
1860      //    return(true);  //<<<<<<<<<<<<<<<<<<<<<<<< patch follows, uncomment here      if ( signal && IsDebug() ) printf(" The run has already been inserted \n");    
1861        return(true);  //<<<<<<<<<<<<<<<<<<<<<<<< patch follows, uncomment here
1862      //      //
1863      // PATCH!      // PATCH!
1864      // we keep the processing run if (in order of growing importance) 1) we have the runtrailer while the old run doesn't have it 2) we have the runheader      // we keep the processing run if (in order of growing importance) 1) we have the runtrailer while the old run doesn't have it 2) we have the runheader
# Line 1983  void PamelaDBOperations::HandleRunFragme Line 2173  void PamelaDBOperations::HandleRunFragme
2173        ULong64_t aobt = OBT(glrun1->GetRUNTRAILER_OBT());        ULong64_t aobt = OBT(glrun1->GetRUNTRAILER_OBT());
2174        UInt_t bpkt = PKT(glrun->GetRUNHEADER_PKT());        UInt_t bpkt = PKT(glrun->GetRUNHEADER_PKT());
2175        ULong64_t bobt = OBT(glrun->GetRUNHEADER_OBT());        ULong64_t bobt = OBT(glrun->GetRUNHEADER_OBT());
2176        if ( IsDebug() ) printf(" Check overlapping events: %i %i %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev);        if ( IsDebug() ) printf(" Check overlapping events: %u %u %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev);
2177        TTree *T= 0;        TTree *T= 0;
2178        T = (TTree*)file->Get("Physics");        T = (TTree*)file->Get("Physics");
2179        if ( !T || T->IsZombie() ) throw -16;        if ( !T || T->IsZombie() ) throw -16;
# Line 1997  void PamelaDBOperations::HandleRunFragme Line 2187  void PamelaDBOperations::HandleRunFragme
2187          bobt = OBT(ph->GetOrbitalTime());                bobt = OBT(ph->GetOrbitalTime());      
2188          firstev++;          firstev++;
2189        };        };
2190        if ( IsDebug() ) printf(" Check overlapping events done: %i %i %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev);        if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev);
2191        //        //
2192        glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER());        glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER());
2193        glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER());        glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER());
# Line 2180  void PamelaDBOperations::HandleRunFragme Line 2370  void PamelaDBOperations::HandleRunFragme
2370        ULong64_t aobt = OBT(glrun->GetRUNTRAILER_OBT());        ULong64_t aobt = OBT(glrun->GetRUNTRAILER_OBT());
2371        UInt_t bpkt = PKT(glrun1->GetRUNHEADER_PKT());        UInt_t bpkt = PKT(glrun1->GetRUNHEADER_PKT());
2372        ULong64_t bobt = OBT(glrun1->GetRUNHEADER_OBT());        ULong64_t bobt = OBT(glrun1->GetRUNHEADER_OBT());
2373        if ( IsDebug() ) printf(" Check overlapping events: %i %i %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev);        if ( IsDebug() ) printf(" Check overlapping events: %u %u %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev);
2374        TTree *T= 0;        TTree *T= 0;
2375        T = (TTree*)file->Get("Physics");        T = (TTree*)file->Get("Physics");
2376        if ( !T || T->IsZombie() ) throw -16;        if ( !T || T->IsZombie() ) throw -16;
# Line 2194  void PamelaDBOperations::HandleRunFragme Line 2384  void PamelaDBOperations::HandleRunFragme
2384          aobt = OBT(ph->GetOrbitalTime());                aobt = OBT(ph->GetOrbitalTime());      
2385          lastev--;          lastev--;
2386        };        };
2387        if ( IsDebug() ) printf(" Check overlapping events done: %i %i %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev);        if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev);
2388        //        //
2389        glrun->SetEV_TO(lastev);        glrun->SetEV_TO(lastev);
2390        glrun->SetNEVENTS(lastev-firstev+1);        glrun->SetNEVENTS(lastev-firstev+1);
# Line 2801  Int_t PamelaDBOperations::insertCALO_CAL Line 2991  Int_t PamelaDBOperations::insertCALO_CAL
2991          fromtime = this->GetAbsTime(ph->GetOrbitalTime());            fromtime = this->GetAbsTime(ph->GetOrbitalTime());  
2992          if ( this->PKT(pkt) >= this->PKT(pktfirst) && this->OBT(obt) >= this->OBT(obtfirst) ){          if ( this->PKT(pkt) >= this->PKT(pktfirst) && this->OBT(obt) >= this->OBT(obtfirst) ){
2993            //            //
2994            if ( IsDebug() ) printf(" Calo calibration for section %i at time %i obt %i pkt %i \n",section,fromtime,obt,pkt);            if ( IsDebug() ) printf(" Calo calibration for section %i at time %u obt %u pkt %u \n",section,fromtime,obt,pkt);
2995            //            //
2996            // check if the calibration has already been inserted            // check if the calibration has already been inserted
2997            //            //
# Line 2846  Int_t PamelaDBOperations::insertCALO_CAL Line 3036  Int_t PamelaDBOperations::insertCALO_CAL
3036                //                //
3037                if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB for section %i \n",section);                if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB for section %i \n",section);
3038                if ( fromtime < 1150871000 ){ //1150866904                if ( fromtime < 1150871000 ){ //1150866904
3039                  if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime);                  if ( IsDebug() ) printf(" First PAMELA flight calibration at time %u \n",fromtime);
3040                  fromtime = 0;// the first flight calibration was taken at about  1156429100 s, this line allow to analyze first runs in raw mode                  fromtime = 0;// the first flight calibration was taken at about  1156429100 s, this line allow to analyze first runs in raw mode
3041                };                };
3042                //                //
# Line 2908  Int_t PamelaDBOperations::insertCALO_CAL Line 3098  Int_t PamelaDBOperations::insertCALO_CAL
3098            //            //
3099          } else {          } else {
3100            //            //
3101            if ( IsDebug() ) printf(" Repetead calo calibration for section %i at time %i obt %i pkt %i \n",section,fromtime,obt,pkt);            if ( IsDebug() ) printf(" Repeated calo calibration for section %i at time %u obt %u pkt %u \n",section,fromtime,obt,pkt);
3102            //            //
3103          };                };      
3104          //                //      
# Line 3126  Int_t PamelaDBOperations::insertTRK_CALI Line 3316  Int_t PamelaDBOperations::insertTRK_CALI
3316      //      //
3317      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) ){
3318        //        //
3319        if ( IsDebug() ) printf(" Trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1);        if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u \n",fromtime,obt1,pkt1);
3320        //              //      
3321        valid = ValidateTrkCalib( caltrk1, eh1 );        valid = ValidateTrkCalib( caltrk1, eh1 );
3322        if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl;        if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl;
# Line 3169  Int_t PamelaDBOperations::insertTRK_CALI Line 3359  Int_t PamelaDBOperations::insertTRK_CALI
3359          //          //
3360        };        };
3361        //        //
3362        if ( IsDebug() ) printf(" Found trk calibration2 at obt %i pkt %i t2 is %i \n",obt2,pkt2,t2);        if ( IsDebug() ) printf(" Found trk calibration2 at obt %u pkt %u t2 is %u \n",obt2,pkt2,t2);
3363        //        //
3364        // The calibration is good        // The calibration is good
3365        //        //
3366        if ( this->PKT(pkt2) == this->PKT(pkt1)+1 ){        if ( this->PKT(pkt2) == this->PKT(pkt1)+1 ){
3367          //          //
3368          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 %u pkt %u t2 is %u is good \n",obt2,pkt2,t2);
3369          //          //
3370          UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 );          UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 );
3371          if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl;          if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl;
# Line 3189  Int_t PamelaDBOperations::insertTRK_CALI Line 3379  Int_t PamelaDBOperations::insertTRK_CALI
3379          //          //
3380          if ( t2 != pret2+1 ){          if ( t2 != pret2+1 ){
3381            //            //
3382            if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %i pkt %i t2 is %i pret2 is %i \n",obt2,pkt2,t2,pret2);            if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u pret2 is %u \n",obt2,pkt2,t2,pret2);
3383            //            //
3384            while ( t2 > pret2+1 ){            while ( t2 > pret2+1 ){
3385              //              //
# Line 3218  Int_t PamelaDBOperations::insertTRK_CALI Line 3408  Int_t PamelaDBOperations::insertTRK_CALI
3408          //          //
3409          // Check for missing calibtrk2          // Check for missing calibtrk2
3410          //          //
3411          if ( IsDebug() ) printf(" Missing the trk calibration2! Next one at obt %i pkt %i t2 is %i\n",obt2,pkt2,t2);          if ( IsDebug() ) printf(" Missing the trk calibration2! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2);
3412          t2 = pret2;          t2 = pret2;
3413          //          //
3414          // handle missing calib2          // handle missing calib2
# Line 3232  Int_t PamelaDBOperations::insertTRK_CALI Line 3422  Int_t PamelaDBOperations::insertTRK_CALI
3422        //        //
3423      } else {      } else {
3424        //        //
3425        if ( IsDebug() ) printf(" Repetead trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1);        if ( IsDebug() ) printf(" Repetead trk calibration1 at time %u obt %u pkt %u \n",fromtime,obt1,pkt1);
3426        //        //
3427      };      };
3428      //          //    
# Line 3257  Int_t PamelaDBOperations::insertTRK_CALI Line 3447  Int_t PamelaDBOperations::insertTRK_CALI
3447      valid = 0;      valid = 0;
3448      if ( this->PKT(pkt2) > this->PKT(pktfirst) || this->OBT(obt2) > this->OBT(obtfirst) ){      if ( this->PKT(pkt2) > this->PKT(pktfirst) || this->OBT(obt2) > this->OBT(obtfirst) ){
3449        //        //
3450        if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %i pkt %i t2 is %i\n",obt2,pkt2,t2);        if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2);
3451        //        //
3452        this->HandleTRK_CALIB(false,true);        this->HandleTRK_CALIB(false,true);
3453        //        //
# Line 3311  Int_t PamelaDBOperations::insertS4_CALIB Line 3501  Int_t PamelaDBOperations::insertS4_CALIB
3501      fromtime = this->GetAbsTime(ph->GetOrbitalTime());        fromtime = this->GetAbsTime(ph->GetOrbitalTime());  
3502      if ( this->PKT(pkt) >= this->PKT(pktfirst) && this->OBT(obt) >= this->OBT(obtfirst) ){      if ( this->PKT(pkt) >= this->PKT(pktfirst) && this->OBT(obt) >= this->OBT(obtfirst) ){
3503        //        //
3504        if ( IsDebug() ) printf(" S4 calibration at time %i obt %i pkt %i \n",fromtime,obt,pkt);        if ( IsDebug() ) printf(" S4 calibration at time %u obt %u pkt %u \n",fromtime,obt,pkt);
3505        //        //
3506        // check if the calibration has already been inserted        // check if the calibration has already been inserted
3507        //        //
# Line 3354  Int_t PamelaDBOperations::insertS4_CALIB Line 3544  Int_t PamelaDBOperations::insertS4_CALIB
3544            //            //
3545            if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB \n");            if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB \n");
3546            if ( fromtime < 1150871000 ){              if ( fromtime < 1150871000 ){  
3547              if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime);              if ( IsDebug() ) printf(" First PAMELA flight calibration at time %u \n",fromtime);
3548              fromtime = 0;// the first flight calibration was taken at about  1156429100 s, this line allow to analyze first runs in raw mode              fromtime = 0;// the first flight calibration was taken at about  1156429100 s, this line allow to analyze first runs in raw mode
3549            };            };
3550            //            //
# Line 3413  Int_t PamelaDBOperations::insertS4_CALIB Line 3603  Int_t PamelaDBOperations::insertS4_CALIB
3603        //        //
3604      } else {      } else {
3605        //        //
3606        if ( IsDebug() ) printf(" Repetead S4 calibration at time %i obt %i pkt %i \n",fromtime,obt,pkt);        if ( IsDebug() ) printf(" Repeated S4 calibration at time %u obt %u pkt %u \n",fromtime,obt,pkt);
3607        //        //
3608      };            };      
3609      //            //      
# Line 3624  Int_t PamelaDBOperations::ValidateRuns(T Line 3814  Int_t PamelaDBOperations::ValidateRuns(T
3814        row = result->Next();        row = result->Next();
3815        t_stop = (UInt_t)atoll(row->GetField(4));        t_stop = (UInt_t)atoll(row->GetField(4));
3816      };      };
3817      if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start);      if ( IsDebug() ) printf("Validation interval: from time %u - to time %u \n\n",t_stop,t_start);
3818      // --------------------------------------------------------------      // --------------------------------------------------------------
3819      // now retrieves runs to be validated      // now retrieves runs to be validated
3820      // --------------------------------------------------------------      // --------------------------------------------------------------
# Line 3795  Int_t PamelaDBOperations::ValidateRuns(T Line 3985  Int_t PamelaDBOperations::ValidateRuns(T
3985                    }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max);                    }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max);
3986            };            };
3987                        
3988            if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID);            if ( IsDebug() ) printf("%i Run %u \n",nrow,this_run->ID);
3989            nrow++;            nrow++;
3990                        
3991    };    };
# Line 3824  Bool_t PamelaDBOperations::MissingTRK_CA Line 4014  Bool_t PamelaDBOperations::MissingTRK_CA
4014          // which should be equal to the time between ascending-nodes.          // which should be equal to the time between ascending-nodes.
4015          //==============================================================          //==============================================================
4016          if ( t2 - trkcalib->FROM_TIME > 5700) {          if ( t2 - trkcalib->FROM_TIME > 5700) {
4017                  if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME);                  if ( IsDebug() )printf("Long time between calib and run start %u :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME);
4018          //==============================================================          //==============================================================
4019          // there might be a missing calibration, due to:          // there might be a missing calibration, due to:
4020          // - MM full          // - MM full
# Line 3845  Bool_t PamelaDBOperations::MissingTRK_CA Line 4035  Bool_t PamelaDBOperations::MissingTRK_CA
4035          // it is enough to say that there are no missing calibrations          // it is enough to say that there are no missing calibrations
4036          //==============================================================          //==============================================================
4037          // the long time interval bewteen runs might be due to download          // the long time interval bewteen runs might be due to download
4038          if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME);          if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME);
4039          return(false);          return(false);
4040                    
4041  };  };
# Line 4161  void PamelaDBOperations::ValidationOFF() Line 4351  void PamelaDBOperations::ValidationOFF()
4351        };        };
4352      };      };
4353    };    };
4354    if ( IsDebug() ) printf(" %i runs have been unvalidated \n",unv);    if ( IsDebug() ) printf(" %u runs have been unvalidated \n",unv);
4355  };  };
4356    
4357  /**  /**
# Line 4192  void PamelaDBOperations::RemoveRUNS(){ Line 4382  void PamelaDBOperations::RemoveRUNS(){
4382      if ( IsDebug() ) printf(" Deleting run from GL_RUN table \n");          if ( IsDebug() ) printf(" Deleting run from GL_RUN table \n");    
4383      while ( Row ){      while ( Row ){
4384        delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN");        delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN");
4385        if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0)));        if ( IsDebug() ) printf(" del run %u \n",(UInt_t)atoll(Row->GetField(0)));
4386        drun++;        drun++;
4387        Row = pResult->Next();            Row = pResult->Next();    
4388      };      };
# Line 4213  void PamelaDBOperations::RemoveRUNS(){ Line 4403  void PamelaDBOperations::RemoveRUNS(){
4403    } else {    } else {
4404      if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN table \n");          if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN table \n");    
4405      while ( Row ){      while ( Row ){
4406        if ( IsDebug() ) printf(" restore run %i \n",(UInt_t)atoll(Row->GetField(1)));        if ( IsDebug() ) printf(" restore run %u \n",(UInt_t)atoll(Row->GetField(1)));
4407        delrun->RestoreRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN_FRAGMENTS");        delrun->RestoreRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN_FRAGMENTS");
4408        if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(1)));        if ( IsDebug() ) printf(" del run %u \n",(UInt_t)atoll(Row->GetField(1)));
4409        delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN");        delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN");
4410        if ( (UInt_t)atoll(Row->GetField(1)) != (UInt_t)atoll(Row->GetField(0)) ){        if ( (UInt_t)atoll(Row->GetField(1)) != (UInt_t)atoll(Row->GetField(0)) ){
4411          if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0)));          if ( IsDebug() ) printf(" del run %u \n",(UInt_t)atoll(Row->GetField(0)));
4412          delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN");          delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN");
4413        };        };
4414        drun++;        drun++;
# Line 4244  void PamelaDBOperations::RemoveRUNS(){ Line 4434  void PamelaDBOperations::RemoveRUNS(){
4434    } else {    } else {
4435      if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_TRASH table \n");          if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_TRASH table \n");    
4436      while ( Row ){      while ( Row ){
4437        if ( IsDebug() ) printf(" del run idtrash %i \n",(UInt_t)atoll(Row->GetField(0)));        if ( IsDebug() ) printf(" del run idtrash %u \n",(UInt_t)atoll(Row->GetField(0)));
4438        myquery.str("");        myquery.str("");
4439        myquery << " DELETE FROM GL_RUN_TRASH where ID_TRASH=" << Row->GetField(0) <<";";              myquery << " DELETE FROM GL_RUN_TRASH where ID_TRASH=" << Row->GetField(0) <<";";      
4440        conn->Query(myquery.str().c_str());        conn->Query(myquery.str().c_str());
# Line 4253  void PamelaDBOperations::RemoveRUNS(){ Line 4443  void PamelaDBOperations::RemoveRUNS(){
4443      };      };
4444    };    };
4445    //      //  
4446    if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_TRASH table \n",drun);        if ( IsDebug() ) printf(" Deleted %u run(s) from GL_RUN_TRASH table \n",drun);    
4447    //    //
4448    //    //
4449    //    //
# Line 4271  void PamelaDBOperations::RemoveRUNS(){ Line 4461  void PamelaDBOperations::RemoveRUNS(){
4461    } else {    } else {
4462      if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_FRAGMENTS table \n");          if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_FRAGMENTS table \n");    
4463      while ( Row ){      while ( Row ){
4464        if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0)));        if ( IsDebug() ) printf(" del run %u \n",(UInt_t)atoll(Row->GetField(0)));
4465        myquery.str("");        myquery.str("");
4466        myquery << " DELETE FROM GL_RUN_FRAGMENTS where ID=" << Row->GetField(0) <<";";        myquery << " DELETE FROM GL_RUN_FRAGMENTS where ID=" << Row->GetField(0) <<";";
4467        conn->Query(myquery.str().c_str());        conn->Query(myquery.str().c_str());
# Line 4280  void PamelaDBOperations::RemoveRUNS(){ Line 4470  void PamelaDBOperations::RemoveRUNS(){
4470      };      };
4471    };    };
4472    //      //  
4473    if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_FRAGMENTS table \n",drun);        if ( IsDebug() ) printf(" Deleted %u run(s) from GL_RUN_FRAGMENTS table \n",drun);    
4474    //    //
4475    //    //
4476    //    //
# Line 4592  UInt_t PamelaDBOperations::Check(){ Line 4782  UInt_t PamelaDBOperations::Check(){
4782    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
4783    TSQLResult *result2 = 0;    TSQLResult *result2 = 0;
4784    TSQLRow    *row2    = 0;    TSQLRow    *row2    = 0;
4785      TSQLResult *result3 = 0;
4786      TSQLRow    *row3    = 0;
4787    oss.str("");    oss.str("");
4788    oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN order by RUNHEADER_TIME asc;";    oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME,NEVENTS FROM GL_RUN order by RUNHEADER_TIME asc;";
4789    //  oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;";    //  oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;";
4790    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
4791    //    //
4792    if ( !result ) throw -4;;    if ( !result ) throw -4;;
4793    //    //
4794    row = result->Next();    row = result->Next();
4795      UInt_t nid = 0;
4796    //    //
4797    while ( row ){    while ( row ){
4798        nid++;
4799        if ( !(nid%1000) && nid ) printf(" %iK run scanned \n",nid/1000);
4800      thisid = (UInt_t)atoll(row->GetField(0));      thisid = (UInt_t)atoll(row->GetField(0));
4801      thisl0id = (UInt_t)atoll(row->GetField(1));      thisl0id = (UInt_t)atoll(row->GetField(1));
4802      thisrht = (UInt_t)atoll(row->GetField(2));      thisrht = (UInt_t)atoll(row->GetField(2));
4803      thisrtt = (UInt_t)atoll(row->GetField(3));      thisrtt = (UInt_t)atoll(row->GetField(3));
4804      //      //
4805        if ( (UInt_t)atoll(row->GetField(4)) > 1 ){
4806          //
4807          //
4808          //
4809          oss.str("");
4810          oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!="
4811              << thisid << " AND ( RUNHEADER_TIME="
4812              << thisrht << " OR RUNTRAILER_TIME="
4813              << thisrtt << " ) AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;";
4814          result3 = conn->Query(oss.str().c_str());
4815          if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str());
4816          if ( result3 ){
4817            //
4818            oss.str("");
4819            oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!="
4820                << thisid << " AND RUNHEADER_TIME="
4821                << thisrht << " AND RUNTRAILER_TIME!="
4822                << thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;";
4823            result3 = conn->Query(oss.str().c_str());
4824            if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str());
4825            if ( result3 ){
4826              row3 = result3->Next();
4827              //
4828              while ( row3 ){
4829                //
4830                // 2 runs with same runheader
4831                //
4832                printf(" CHECK n.4 RUNs %u and %u HAVE SAME RUNHEADER \n",thisid,(UInt_t)atoll(row3->GetField(0)));  
4833                row3 = result3->Next();
4834              };
4835            };
4836            //
4837            oss.str("");
4838            oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!="
4839                << thisid << " AND RUNHEADER_TIME!="
4840                << thisrht << " AND RUNTRAILER_TIME="
4841                << thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;";
4842            result3 = conn->Query(oss.str().c_str());
4843            if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str());
4844            if ( result3 ){
4845              row3 = result3->Next();
4846              //
4847              while ( row3 ){
4848                //
4849                // 2 runs with same runtrailer
4850                //
4851                printf(" CHECK n.5 RUNs %u and %u HAVE SAME RUNTRAILER \n",thisid,(UInt_t)atoll(row3->GetField(0)));
4852                row3 = result3->Next();
4853              };
4854            };
4855            //
4856            oss.str("");
4857            oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!="
4858                << thisid << " AND RUNHEADER_TIME="
4859                << thisrht << " AND RUNTRAILER_TIME="
4860                << thisrtt << " AND ID_RUN_FRAG!="
4861                << thisid << " order by RUNHEADER_TIME asc;";
4862            result3 = conn->Query(oss.str().c_str());
4863            if ( result3 ){
4864              row3 = result3->Next();
4865              //
4866              while ( row3 ){
4867                //
4868                // duplicated run
4869                //
4870                printf(" CHECK n.7 RUNs %u and %u HAVE SAME RUNTRAILER AND RUNHEADER (ARE THE SAME?) \n",thisid,(UInt_t)atoll(row3->GetField(0)));
4871                row3 = result3->Next();
4872              };
4873            };
4874          };
4875          //
4876          oss.str("");
4877          oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!="
4878              << thisid << " AND RUNHEADER_TIME>"
4879              << thisrht << " AND RUNTRAILER_TIME<"
4880              << thisrtt << " order by RUNHEADER_TIME asc;";
4881          result3 = conn->Query(oss.str().c_str());
4882          if ( result3 ){
4883            row3 = result3->Next();
4884            //
4885            while ( row3 ){
4886              //
4887              // run contained in the checked one
4888              //
4889              printf(" CHECK n.6 RUN %u CONTAINS RUN %u  \n",thisid,(UInt_t)atoll(row3->GetField(0)));
4890              row3 = result3->Next();
4891            };
4892          };
4893          //
4894        };
4895        //
4896      //    if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){      //    if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){
4897      //    if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){      //    if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){
4898      if ( (thisrht < prevrtt) && (thisrht != prevrht) ){      if ( (thisrht < prevrtt) && (thisrht != prevrht) ){
# Line 4638  UInt_t PamelaDBOperations::Check(){ Line 4924  UInt_t PamelaDBOperations::Check(){
4924        oss.str("");        oss.str("");
4925        oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";";        oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";";
4926        result2 = conn->Query(oss.str().c_str());        result2 = conn->Query(oss.str().c_str());
4927        if ( !result2 ) throw -4;;        if ( !result2 ) throw -4;
4928        row2 = result2->Next();        row2 = result2->Next();
4929        prevf = (TString)row2->GetField(0);        prevf = (TString)row2->GetField(0);
4930        oss.str("");        oss.str("");

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

  ViewVC Help
Powered by ViewVC 1.1.23