/[PAMELA software]/chewbacca/YodaProfiler/src/PamelaDBOperations.cpp
ViewVC logotype

Diff of /chewbacca/YodaProfiler/src/PamelaDBOperations.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by mocchiut, Fri Nov 7 08:56:13 2008 UTC revision 1.28 by mocchiut, Mon Dec 14 13:20:37 2009 UTC
# Line 60  string getTleDatetime(cTle*); Line 60  string getTleDatetime(cTle*);
60   */   */
61  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, Bool_t keepenv){  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, Bool_t keepenv){
62    //    //
63      RELAXED = false;
64    chewbacca = false;    chewbacca = false;
65    chminentry = 0;    chminentry = 0;
66    chID = 0;    chID = 0;
# Line 101  PamelaDBOperations::PamelaDBOperations(T Line 102  PamelaDBOperations::PamelaDBOperations(T
102    if (INSERT_RAW) SetRawName(filerawname);    if (INSERT_RAW) SetRawName(filerawname);
103    //    //
104    INSERT_ROOT = !filerootname.IsNull();    INSERT_ROOT = !filerootname.IsNull();
105      if ( INSERT_ROOT ) this->SetRootName(filerootname);
106    this->SetOrbitNo(dwinput);    this->SetOrbitNo(dwinput);
107    //    //
108    this->SetID_RAW(0);    this->SetID_RAW(0);
# Line 134  void PamelaDBOperations::OpenL0File(TStr Line 136  void PamelaDBOperations::OpenL0File(TStr
136        stringstream qu;        stringstream qu;
137        TSQLResult *result = 0;        TSQLResult *result = 0;
138        TSQLResult *result2 = 0;        TSQLResult *result2 = 0;
139          TSQLResult *result3 = 0;
140        TSQLRow    *row    = 0;            TSQLRow    *row    = 0;    
141        TSQLRow    *row2    = 0;            TSQLRow    *row2    = 0;    
142          TSQLRow    *row3    = 0;    
143        TString chpath;        TString chpath;
144        TString chfile;        TString chfile;
145        UInt_t ridn = 0;        UInt_t ridn = 0;
146        qu.str("");        qu.str("");
147        qu << "SELECT ROOT_ID_N,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,INSERTED_BY from ROOT_TABLE_MERGING where ID_N=" << chID << ";";        qu << "SELECT ROOT_ID_N,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,INSERTED_BY,REAL_TIME_INIT from ROOT_TABLE_MERGING where ID_N=" << chID << ";";
148        if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());        if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());
149        result = conn->Query(qu.str().c_str());        result = conn->Query(qu.str().c_str());
150        if ( result ){        if ( result ){
# Line 152  void PamelaDBOperations::OpenL0File(TStr Line 156  void PamelaDBOperations::OpenL0File(TStr
156            chobtmin = (UInt_t)atoll(row->GetField(3));            chobtmin = (UInt_t)atoll(row->GetField(3));
157            chobtmax = (UInt_t)atoll(row->GetField(4));            chobtmax = (UInt_t)atoll(row->GetField(4));
158            chiby = (TString)(row->GetField(5));            chiby = (TString)(row->GetField(5));
159              chrtinit = (UInt_t)atoll(row->GetField(6));
160          } else {          } else {
161            throw -84;            throw -84;
162          };          };
# Line 160  void PamelaDBOperations::OpenL0File(TStr Line 165  void PamelaDBOperations::OpenL0File(TStr
165        };        };
166        delete result;        delete result;
167        qu.str("");        qu.str("");
168        qu << "SELECT FOLDER_NAME,FILE_NAME,OBT_TIME_SYNC,LAST_TIME_SYNC_INFO,TIME_OFFSET,BOOT_NUMBER,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL from ROOT_TABLE where ID_N=" << ridn << ";";        qu << "SELECT FOLDER_NAME,FILE_NAME,OBT_TIME_SYNC,LAST_TIME_SYNC_INFO,TIME_OFFSET,BOOT_NUMBER,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,REAL_TIME_INIT from ROOT_TABLE where ID_N=" << ridn << ";";
169        if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());        if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());
170        result2 = conn->Query(qu.str().c_str());        result2 = conn->Query(qu.str().c_str());
171        if ( result2 ){        if ( result2 ){
# Line 177  void PamelaDBOperations::OpenL0File(TStr Line 182  void PamelaDBOperations::OpenL0File(TStr
182            chresursts = (UInt_t)atoll(row2->GetField(4));            chresursts = (UInt_t)atoll(row2->GetField(4));
183            chboot = (UInt_t)atoll(row2->GetField(5));            chboot = (UInt_t)atoll(row2->GetField(5));
184            //            //
185              if ( !chboot ){
186                qu.str("");
187                //      qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND ABS(LAST_TIME_SYNC_INFO-"<< chlastts <<")<10000 AND ABS(REAL_TIME_INIT-"<< row2->GetField(10) <<")<7200 group by BOOT_NUMBER order by BOOT_NUMBER asc;";
188                //      qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND ABS(LAST_TIME_SYNC_INFO-"<< chlastts <<")<40000 AND ABS(REAL_TIME_INIT-"<< row2->GetField(10) <<")<40000 group by BOOT_NUMBER order by BOOT_NUMBER asc;"; // relax conditions... 090112 [8RED: error -29]
189                qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND ABS(LAST_TIME_SYNC_INFO-"<< chlastts <<")<50000 AND ABS(REAL_TIME_INIT-"<< row2->GetField(10) <<")<50000 group by BOOT_NUMBER order by BOOT_NUMBER asc;"; // even more relaxed conditions... 091214 [9REDtest3: error -29]
190                if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());
191                result3 = conn->Query(qu.str().c_str());
192                if ( result3 ){
193                  row3 = result3->Next();
194                  if ( row3 && result3->GetRowCount() == 1 ){
195                    chboot = (UInt_t)atoll(row3->GetField(0));
196                    if ( debug ) printf(" Found boot_number = %u \n",chboot);
197                  } else {
198                    if ( debug ) printf(" AGH CANNOT DETERMINE THE BOOT NUMBER... \n");
199                    throw -29;
200                  };
201                };
202              };
203              //
204            chpktinit = (UInt_t)atoll(row2->GetField(6));            chpktinit = (UInt_t)atoll(row2->GetField(6));
205            chpktfinal = (UInt_t)atoll(row2->GetField(7));            chpktfinal = (UInt_t)atoll(row2->GetField(7));
206            chobtinit = (UInt_t)atoll(row2->GetField(8));            chobtinit = (UInt_t)atoll(row2->GetField(8));
# Line 189  void PamelaDBOperations::OpenL0File(TStr Line 213  void PamelaDBOperations::OpenL0File(TStr
213          throw -85;          throw -85;
214        };        };
215        filerootname = chpath + chfile;// + ".root";        filerootname = chpath + chfile;// + ".root";
       if ( debug ) printf(" chewbacca: filename is %s \n",filerootname.Data());  
216      };      };
217      this->SetRootName(filerootname);      this->SetRootName(filerootname);
     file = TFile::Open(this->GetRootName().Data());  
   } else {  
     this->SetRootName("");  
218    };    };
219      if ( debug ) printf(" Filename is %s \n",filerootname.Data());
220      file = TFile::Open(this->GetRootName().Data());
221      //  } else {
222      //    this->SetRootName("");
223      //    this->SetRootName(filerootname);
224      //  };
225  }  }
226    
227  //  //
# Line 395  void PamelaDBOperations::SetOrbitNo(UInt Line 421  void PamelaDBOperations::SetOrbitNo(UInt
421      return;      return;
422    };    };
423    //    //
424    TString name = this->GetRootFile();    if ( !chewbacca ){
425    Int_t nlength = name.Length();      TString name = this->GetRootFile();
426    if ( nlength < 5 ) return;      Int_t nlength = name.Length();
427    TString dwo = 0;      if ( nlength < 5 ){
428    for (Int_t i = 0; i<5; i++){        if ( IsDebug() ) printf(" Agh problems determining the orbit number! name = %s \n",name.Data());
429      dwo.Append(name[i],1);        return;
430    };      };
431    if ( dwo.IsDigit() ){      TString dwo = "";
432      dworbit = (UInt_t)dwo.Atoi();      for (Int_t i = 0; i<5; i++){
   } else {  
     dwo="";  
     for (Int_t i = 8; i<13; i++){  
433        dwo.Append(name[i],1);        dwo.Append(name[i],1);
434      };          };
435      if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi();      if ( dwo.IsDigit() ){
436          dworbit = (UInt_t)dwo.Atoi();
437        } else {
438          dwo="";
439          for (Int_t i = 8; i<13; i++){
440            dwo.Append(name[i],1);
441          };    
442          if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi();
443        };
444        if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data());
445    };    };
   if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data());  
446    return;    return;
447  };  };
448    
# Line 791  Int_t PamelaDBOperations::SetUpperLimits Line 822  Int_t PamelaDBOperations::SetUpperLimits
822      ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();
823      pktlast = ph->GetCounter();      pktlast = ph->GetCounter();
824      nevent = upperentry - chminentry;      nevent = upperentry - chminentry;
825        if ( ((Int_t)upperentry - (Int_t)chminentry) < 0 ) nevent = 0; // nevent is UInt_t! 090112 [8RED: error -88]
826        if ( IsDebug() ) printf(" Setting nevent to %u - upperentry %i chminentry %i \n",nevent,upperentry,chminentry);
827      //      //
828    } else {    } else {
829      upperpkt = PKT(pktlast);      upperpkt = PKT(pktlast);
# Line 799  Int_t PamelaDBOperations::SetUpperLimits Line 832  Int_t PamelaDBOperations::SetUpperLimits
832    };    };
833    //    //
834    if ( chewbacca && nevent < 1 ) {    if ( chewbacca && nevent < 1 ) {
835        if ( IsDebug() ) printf(" chewbacca and no events in the file \n");
836      pktfirst = chpktmin;      pktfirst = chpktmin;
837      upperpkt = PKT(chpktmax);      upperpkt = PKT(chpktmax);
838      pktlast = chpktmax;      pktlast = chpktmax;
# Line 824  Int_t PamelaDBOperations::SetUpperLimits Line 858  Int_t PamelaDBOperations::SetUpperLimits
858    //  if ( nevent < jump ) jump = int(nevent/10);    //  if ( nevent < jump ) jump = int(nevent/10);
859    //  if ( !jump ) jump = 1;    //  if ( !jump ) jump = 1;
860    //    //
861    if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) && nevent > deltapkt ){  
862      if ( ((PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt)) && nevent > deltapkt ){
863      //      //
864      if ( IsDebug() ) printf(" starting jump %i \n",jump);      if ( IsDebug() ) printf(" starting jump %i \n",jump);
865      //    if ( IsDebug() ) printf(" (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) %llu < %llu && %llu > %llu \n     OR \n     (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) %llu > %llu && %llu < %llu \n",PKT(pktlast),PKT(pktfirst),OBT(obtlast),OBT(obtfirst),PKT(pktlast),PKT(pktfirst),OBT(obtlast),OBT(obtfirst));      //    if ( IsDebug() ) printf(" (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) %llu < %llu && %llu > %llu \n     OR \n     (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) %llu > %llu && %llu < %llu \n",PKT(pktlast),PKT(pktfirst),OBT(obtlast),OBT(obtfirst),PKT(pktlast),PKT(pktfirst),OBT(obtlast),OBT(obtfirst));
# Line 1352  Long64_t PamelaDBOperations::OBT(UInt_t Line 1387  Long64_t PamelaDBOperations::OBT(UInt_t
1387    //    //
1388    //  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));    //  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));
1389    //    //
1390    if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){    if ( obt < ((Long64_t)pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){
1391      //    if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());      //    if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());
1392      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());
1393    };    };
# Line 1471  void PamelaDBOperations::FillClass(Bool_ Line 1506  void PamelaDBOperations::FillClass(Bool_
1506      glrun->SetRUNTRAILER_PKT(lastPkt);      glrun->SetRUNTRAILER_PKT(lastPkt);
1507      //          //    
1508    };    };
1509      //
1510      // ad hoc solution for INF EV_TO [8RED] 090113
1511      //
1512      if ( !firstev && lastev == -1 ){
1513        if ( IsDebug() ) printf(" EE firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1);
1514        firstev = 1;
1515        lastev = 0;
1516      };
1517    glrun->SetEV_FROM((UInt_t)firstev);    glrun->SetEV_FROM((UInt_t)firstev);
1518    glrun->SetEV_TO((UInt_t)lastev);    glrun->SetEV_TO((UInt_t)lastev);
1519    glrun->SetNEVENTS((UInt_t)lastev-(UInt_t)firstev+1);    glrun->SetNEVENTS((UInt_t)lastev-(UInt_t)firstev+1);
# Line 1577  Int_t PamelaDBOperations::insertPamelaGL Line 1620  Int_t PamelaDBOperations::insertPamelaGL
1620      result = conn->Query(oss.str().c_str());      result = conn->Query(oss.str().c_str());
1621      if ( !result ) throw -10;      if ( !result ) throw -10;
1622      row = result->Next();      row = result->Next();
1623        if ( !row ) throw -92;
1624      idresof = (UInt_t)atoll(row->GetField(0));      idresof = (UInt_t)atoll(row->GetField(0));
1625      existsts = true;      existsts = true;
1626      goto eout;      goto eout;
# Line 1598  Int_t PamelaDBOperations::insertPamelaGL Line 1642  Int_t PamelaDBOperations::insertPamelaGL
1642      if ( !row ){      if ( !row ){
1643        oss.str("");        oss.str("");
1644        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< "        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< "
1645            << dworbit << " order by FROM_ORBIT desc limit 1;";            << dworbit << " AND SPECIAL_FILE='' order by FROM_ORBIT desc limit 1;";
1646        if ( IsDebug() ) printf(" %s \n",oss.str().c_str());        if ( IsDebug() ) printf(" %s \n",oss.str().c_str());
1647        result = conn->Query(oss.str().c_str());        result = conn->Query(oss.str().c_str());
1648        if ( !result ) throw -10;        if ( !result ) throw -10;
# Line 2239  Int_t PamelaDBOperations::insertPamelaRU Line 2283  Int_t PamelaDBOperations::insertPamelaRU
2283          ptht = cod->Get(pctp->RunHeader) - 1;          ptht = cod->Get(pctp->RunHeader) - 1;
2284          //      evbeft = cod->Get(pctp->Physics);          //      evbeft = cod->Get(pctp->Physics);
2285          tcod = (UInt_t)cod->Get(pctp->Physics);          tcod = (UInt_t)cod->Get(pctp->Physics);
2286          if ( !tcod ) tcod = 1;          if ( !tcod ) tcod = 1;    // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT
2287          evbeft = TMath::Min(upperentry,(tcod-1));          evbeft = TMath::Min(upperentry,(tcod-1));
2288          if ( debug ) printf(" Loop in runtrailers, evbeft is %u upperentry %u cod->getetc %u \n",evbeft,upperentry,cod->Get(pctp->Physics));          if ( debug ) printf(" Loop in runtrailers, evbeft is %u upperentry %u cod->getetc %u \n",evbeft,upperentry,cod->Get(pctp->Physics));
2289          //          //
# Line 2278  Int_t PamelaDBOperations::insertPamelaRU Line 2322  Int_t PamelaDBOperations::insertPamelaRU
2322            obth = phh->GetOrbitalTime();            obth = phh->GetOrbitalTime();
2323            cod = ehh->GetCounter();            cod = ehh->GetCounter();
2324            tcod = (UInt_t)cod->Get(pctp->Physics);            tcod = (UInt_t)cod->Get(pctp->Physics);
2325            if ( !tcod ) tcod = 1;            if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT
2326            evbefh = TMath::Max(chminentry,(tcod-1));            evbefh = TMath::Max(chminentry,(tcod-1));
2327            //            //
2328            if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){            if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){
# Line 2340  Int_t PamelaDBOperations::insertPamelaRU Line 2384  Int_t PamelaDBOperations::insertPamelaRU
2384                cod = ehh->GetCounter();                cod = ehh->GetCounter();
2385                //            evbeft = cod->Get(pctp->Physics);                //            evbeft = cod->Get(pctp->Physics);
2386                tcod = (UInt_t)cod->Get(pctp->Physics);                tcod = (UInt_t)cod->Get(pctp->Physics);
2387                if ( !tcod ) tcod = 1;                if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT
2388                evbeft = TMath::Min(upperentry,(tcod-1));                evbeft = TMath::Min(upperentry,(tcod-1));
2389                rh->GetEntry(pth);                rh->GetEntry(pth);
2390                phh = ehh->GetPscuHeader();                phh = ehh->GetPscuHeader();
# Line 2382  Int_t PamelaDBOperations::insertPamelaRU Line 2426  Int_t PamelaDBOperations::insertPamelaRU
2426            //    if ( conptt+1 == (nrtev+nrtbef )){              //    if ( conptt+1 == (nrtev+nrtbef )){  
2427            if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt);            if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt);
2428            ptht++;            ptht++;
2429            if ( ptht < rhev ){            if ( ptht < rhev ){
2430              rh->GetEntry(ptht);              rh->GetEntry(ptht);
2431              //pth++;              //pth++;
2432              //if ( pth < rhev ){              //if ( pth < rhev ){
# Line 2410  Int_t PamelaDBOperations::insertPamelaRU Line 2454  Int_t PamelaDBOperations::insertPamelaRU
2454              if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){              if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){
2455                if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER! evbeft %u upperentry-1 %u \n",(UInt_t)evbeft,upperentry-1);                if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER! evbeft %u upperentry-1 %u \n",(UInt_t)evbeft,upperentry-1);
2456                //                //
2457                if ( (ptt-1) < 0 ) throw -15; // should never arrive here!                //              if ( (ptt-1) < 0 ) throw -15; // should never arrive here!
2458                  if ( (rtev-1) < 0 || ptt < 0 ) throw -15; // should never arrive here!
2459                //              rt->GetEntry(ptt-1);                //              rt->GetEntry(ptt-1);
2460                rt->GetEntry(rtev-1);                rt->GetEntry(rtev-1);
2461                cod = eht->GetCounter();                cod = eht->GetCounter();
# Line 2645  void PamelaDBOperations::HandleRunFragme Line 2690  void PamelaDBOperations::HandleRunFragme
2690      //      //
2691      // we have now the good first piece of a run, fill the glrun object      // we have now the good first piece of a run, fill the glrun object
2692      //      //
2693      if ( rhfirstev != firstev && !mishead ) mishead = true;      if ( firstev != (lastev+1) ){ // could be a problem sometimes (?)
2694      if ( rtlastev != lastev && !mistrail ) mistrail = true;        if ( rhfirstev != firstev && !mishead ) mishead = true;
2695          if ( rtlastev != lastev && !mistrail ) mistrail = true;
2696        };
2697      //      //
2698        if ( IsDebug() ) printf(" bhere firstev is %i lastev is %i \n",firstev,lastev);
2699      this->FillClass(mishead,mistrail,firstev,lastev);      this->FillClass(mishead,mistrail,firstev,lastev);
2700        if ( IsDebug() ) printf(" chere firstev is %i lastev is %i \n",firstev,lastev);
2701      //      //
2702      if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n");      if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n");
2703      if ( IsDebug() ) printf(" C THIS RUN: RUNHEADER_OBT %u RUNTRAILER_OBT %u RUNHEADER_PKT %u RUNTRAILER_PKT %u \n", glrun->GetRUNHEADER_OBT(),glrun->GetRUNTRAILER_OBT(),glrun->GetRUNHEADER_PKT(),glrun->GetRUNTRAILER_PKT());      if ( IsDebug() ) printf(" C THIS RUN: RUNHEADER_OBT %u RUNTRAILER_OBT %u RUNHEADER_PKT %u RUNTRAILER_PKT %u \n", glrun->GetRUNHEADER_OBT(),glrun->GetRUNTRAILER_OBT(),glrun->GetRUNHEADER_PKT(),glrun->GetRUNTRAILER_PKT());
# Line 2690  void PamelaDBOperations::HandleRunFragme Line 2739  void PamelaDBOperations::HandleRunFragme
2739        glrun->Fill_GL_RUN_FRAGMENTS(conn);        glrun->Fill_GL_RUN_FRAGMENTS(conn);
2740        //        //
2741      } else {      } else {
2742        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, relaxed %u \n",RELAXED);
2743        if ( PEDANTIC ) throw -69;        if ( !RELAXED ){
2744        return;          if ( PEDANTIC ) throw -69;
2745            return;
2746          } else {
2747            glrun->SetID((UInt_t)atoll(row->GetField(0)));
2748            glrun->SetID_RUN_FRAG(0);
2749          };
2750      };      };
2751      //      //
2752      if ( chewbacca && mishead && mistrail ) goto justcheck;      if ( chewbacca && mishead && mistrail ) goto justcheck;
# Line 2743  void PamelaDBOperations::HandleRunFragme Line 2797  void PamelaDBOperations::HandleRunFragme
2797          //          //
2798          found = false; // default value          found = false; // default value
2799          //          //
2800          if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n");          if ( IsDebug() ) printf(" A Found a possible candidate, checking if it is the good one... \n");
2801          //          //
2802          // if we have both runheader and runtrailer we can check with pkt_counter:          // if we have both runheader and runtrailer we can check with pkt_counter:
2803          //          //
# Line 2759  void PamelaDBOperations::HandleRunFragme Line 2813  void PamelaDBOperations::HandleRunFragme
2813              if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt);              if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt);
2814              //              //
2815              found = true;              found = true;
2816                if ( IsDebug() ) printf(" where firstev is %i lastev is %i \n",firstev,lastev);
2817              //              //
2818            } else {            } else {
2819              //              //
# Line 2824  void PamelaDBOperations::HandleRunFragme Line 2879  void PamelaDBOperations::HandleRunFragme
2879          oss << " ID="<<row->GetField(0)<<";";          oss << " ID="<<row->GetField(0)<<";";
2880          //          //
2881          glrun1->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // here we have runheader infos          glrun1->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // here we have runheader infos
2882            if ( IsDebug() ) printf(" there firstev is %i lastev is %i \n",firstev,lastev);
2883          //          //
2884          // merge infos          // merge infos
2885          //          //
# Line 2854  void PamelaDBOperations::HandleRunFragme Line 2910  void PamelaDBOperations::HandleRunFragme
2910          glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT());          glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT());
2911          glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT());          glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT());
2912          //          //
2913            if ( IsDebug() ) printf(" here firstev is %i lastev is %i \n",firstev,lastev);
2914            //
2915          glrun->SetEV_FROM(firstev);          glrun->SetEV_FROM(firstev);
2916          glrun->SetNEVENTS(lastev-firstev+1);          glrun->SetNEVENTS(lastev-firstev+1);
2917          //          //
# Line 2946  void PamelaDBOperations::HandleRunFragme Line 3004  void PamelaDBOperations::HandleRunFragme
3004          //          //
3005          found = false; // default value          found = false; // default value
3006          //          //
3007          if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n");          if ( IsDebug() ) printf(" B Found a possible candidate, checking if it is the good one... \n");
3008          //          //
3009          // if we have both runheader and runtrailer we can check with pkt_counter:          // if we have both runheader and runtrailer we can check with pkt_counter:
3010          //          //
# Line 3046  void PamelaDBOperations::HandleRunFragme Line 3104  void PamelaDBOperations::HandleRunFragme
3104            apkt = PKT(ph->GetCounter());            apkt = PKT(ph->GetCounter());
3105            aobt = OBT(ph->GetOrbitalTime());                aobt = OBT(ph->GetOrbitalTime());    
3106            lastev--;            lastev--;
3107            if ( PEDANTIC ) throw -72;            if ( PEDANTIC && !RELAXED) throw -72;
3108          };          };
3109          if ( IsDebug() ) printf(" Check overlapping events done: %u %u %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);
3110          //          //
# Line 3114  void PamelaDBOperations::HandleRunFragme Line 3172  void PamelaDBOperations::HandleRunFragme
3172        // not found, has this run already inserted in the GL_RUN or in the GL_RUN_FRAGMENTS table?        // not found, has this run already inserted in the GL_RUN or in the GL_RUN_FRAGMENTS table?
3173        //        //
3174        oss.str("");        oss.str("");
3175        oss << " SELECT ID FROM GL_RUN WHERE "        oss << " SELECT ID,ID_ROOT_L0 FROM GL_RUN WHERE "
3176            << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND ("            << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND ("
3177            << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "            << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "
3178            << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("            << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("
# Line 3137  void PamelaDBOperations::HandleRunFragme Line 3195  void PamelaDBOperations::HandleRunFragme
3195        row = result->Next();        row = result->Next();
3196        //        //
3197        if ( row ){        if ( row ){
3198          if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n");          //
3199          if ( PEDANTIC ) throw -70;          // we end up here if chewbacca and we have RH---| small gap |---RT, in this case the two pieces are attached and moved to GL_RUN. We are now processing the
3200            // "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number.
3201            //
3202            // 090112 [8RED (-70): RUN ALREADY INSERTED]
3203            //
3204            Bool_t OK = false;
3205            UInt_t IDRL2A = 0;
3206            UInt_t IDRL2B = 0;
3207            if ( chewbacca ){
3208              if ( result->GetRowCount() == 2 ){
3209                IDRL2A = (UInt_t)atoll(row->GetField(0));
3210                UInt_t IDRL0A = (UInt_t)atoll(row->GetField(1));
3211                row = result->Next();
3212                IDRL2B = (UInt_t)atoll(row->GetField(0));
3213                UInt_t IDRL0B = (UInt_t)atoll(row->GetField(1));
3214                if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B);
3215                if ( IDRL0A == IDRL0B ){
3216                  TSQLResult *result2 = 0;
3217                  TSQLRow    *row2    = 0;
3218                  oss.str("");
3219                  oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;";
3220                  if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
3221                  result2 = conn->Query(oss.str().c_str());
3222                  //
3223                  if ( !result2 ) throw -4;
3224                  //
3225                  row2 = result2->Next();
3226                  //
3227                  if ( row2 ){
3228                    UInt_t PKA = (UInt_t)atoll(row2->GetField(0));
3229                    delete result2;
3230                    oss.str("");
3231                    oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;";
3232                    if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
3233                    result2 = conn->Query(oss.str().c_str());
3234                    //
3235                    if ( !result2 ) throw -4;
3236                    //
3237                    row2 = result2->Next();
3238                    //
3239                    if ( row2 ){
3240                      UInt_t PKB = (UInt_t)atoll(row2->GetField(0));
3241                      //
3242                      if ( IsDebug() ) printf(" PKT(PKA) + 1 %llu == runheaderpkt %llu && PKB = runtrailer %llu + 1 %llu \n",PKT(PKA)+1LL, PKT(glrun->GetRUNHEADER_PKT()),PKT(PKB), PKT(glrun->GetRUNTRAILER_PKT())+1LL);
3243                      if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){
3244                        if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n");
3245                        OK = true;
3246                      };
3247                    };
3248                  };                  
3249                };
3250              };      
3251            };
3252            if ( OK ){
3253              //
3254              // this is the case in which we must insert a piece of run between two fragments in the GL_RUN table
3255              //
3256              // we have to update with runheader/trailer infos our run and we have to change the ROOT_ID_FRAG of the header piece ( 1/2 2/1 must become 1/3 3/2 2/1 )
3257              //
3258              GL_RUN *glA = new GL_RUN();
3259              glA->Query_GL_RUN(IDRL2A,conn);
3260              //
3261              if ( glA->GetACQ_BUILD_INFO() != 0 ){
3262                //
3263                // the first piece contains a good runheader we can update all the other runs with correct infos!
3264                //
3265                oss.str("");
3266                oss << "UPDATE GL_RUN_FRAGMENTS SET "
3267                    << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "
3268                    << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
3269                    << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , "
3270                    << " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , "
3271                    << " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , "
3272                    << " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , "
3273                    << " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , "
3274                    << " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , "
3275                    << " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , "
3276                    << " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , "
3277                    << " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , "  
3278                    << " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , "  
3279                    << " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , "  
3280                    << " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , "  
3281                    << " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , ";
3282                //
3283                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
3284                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , ";
3285                if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
3286                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , ";
3287                //        
3288                oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC();
3289                oss << " WHERE ID=" << glrun->GetID() << ";";
3290                if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str());
3291                conn->Query(oss.str().c_str());    
3292                //
3293              } else {
3294                //
3295                // sig no runheader, let set anyway what is possible...
3296                //
3297                oss.str("");
3298                oss << "UPDATE GL_RUN_FRAGMENTS SET "
3299                    << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , ";
3300                //
3301                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
3302                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , ";
3303                if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
3304                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , ";
3305                //        
3306                oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
3307                    << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT();
3308                oss << " WHERE ID=" << glrun->GetID() << ";";
3309                if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str());
3310                conn->Query(oss.str().c_str());    
3311              };
3312              //
3313              // update runheader ROOT_ID_FRAG
3314              //
3315              oss.str("");
3316              oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";";
3317              if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str());
3318              conn->Query(oss.str().c_str());
3319              //
3320              // now let's look for runtrailer if any in the last run
3321              //
3322              glA->Query_GL_RUN(IDRL2B,conn);
3323              //
3324              if ( glA->GetPKT_READY_COUNTER() != 0 ){
3325                //
3326                // the first piece contains a good runtrailer we can update all the other runs with correct infos!
3327                //
3328                oss.str("");
3329                oss << "UPDATE GL_RUN_FRAGMENTS SET "
3330                    << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
3331                    << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "
3332                    << " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , "
3333                    << " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , ";
3334                //
3335                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
3336                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
3337                if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) {
3338                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
3339                //        
3340                oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER()
3341                    << " WHERE ID=" << glrun->GetID() << ";";
3342                if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str());
3343                conn->Query(oss.str().c_str());    
3344                //
3345              } else {
3346                //
3347                // sig no runtrailer, let set anyway what is possible...
3348                //
3349                oss.str("");
3350                oss << "UPDATE GL_RUN_FRAGMENTS SET "
3351                    << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
3352                    << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , ";
3353                  //
3354                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
3355                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
3356                if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){
3357                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
3358                //        
3359                oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()
3360                    << " WHERE ID=" << glrun->GetID() << ";";
3361                if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str());
3362                conn->Query(oss.str().c_str());    
3363              };
3364              //
3365              UInt_t myi = glrun->GetID();
3366              oss.str("");
3367              oss << " ID= "<< myi;
3368              //
3369              glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);  
3370              //
3371              // fill the new run in GL_RUN
3372              //
3373              glrun->SetID_RUN_FRAG(IDRL2B);
3374              glrun->Fill_GL_RUN(conn);    
3375              glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
3376              delete glA;
3377              //
3378            } else {
3379              //
3380              // is just a repetition
3381              //
3382              if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n");        
3383              if ( PEDANTIC ) throw -70;
3384            };
3385            //
3386        } else {        } else {
3387          if ( NoFrag() ){          if ( NoFrag() ){
3388            glrun->SetID_RUN_FRAG(glrun->GetID());            glrun->SetID_RUN_FRAG(glrun->GetID());
# Line 3175  void PamelaDBOperations::HandleMissingHo Line 3419  void PamelaDBOperations::HandleMissingHo
3419        glrun->SetID(this->AssignRunID());        glrun->SetID(this->AssignRunID());
3420        glrun->SetID_RUN_FRAG(0);        glrun->SetID_RUN_FRAG(0);
3421        glrun->Fill_GL_RUN(conn);    // it'ok we arrive here only inside a file hence in the middle of the runs...        glrun->Fill_GL_RUN(conn);    // it'ok we arrive here only inside a file hence in the middle of the runs...
3422      };        };
3423      //      //
3424    };    };
3425    //    //
# Line 3219  Bool_t PamelaDBOperations::IsRunConsiste Line 3463  Bool_t PamelaDBOperations::IsRunConsiste
3463    if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run!    if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run!
3464      //if ( firstev <= lastev+1 ) { // no events inside the run!      //if ( firstev <= lastev+1 ) { // no events inside the run!
3465      if ( IsDebug() ) printf(" Checking but no events in the run! \n");      if ( IsDebug() ) printf(" Checking but no events in the run! \n");
3466        firstev = lastev+1; // this is necessary for files with no Physics entries, should have no influence on other files
3467      // return true is correct      // return true is correct
3468      return(true);      return(true);
3469      //      //
# Line 3474  Bool_t PamelaDBOperations::IsRunConsiste Line 3719  Bool_t PamelaDBOperations::IsRunConsiste
3719                  //                  //
3720                  found = false; // default value                  found = false; // default value
3721                  //                  //
3722                  if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n");                  if ( IsDebug() ) printf(" C Found a possible candidate, checking if it is the good one... \n");
3723                  //                  //
3724                  // if we have both runheader and runtrailer we can check with pkt_counter:                  // if we have both runheader and runtrailer we can check with pkt_counter:
3725                  //                  //
# Line 3992  Int_t PamelaDBOperations::insertCALO_CAL Line 4237  Int_t PamelaDBOperations::insertCALO_CAL
4237    UInt_t totime = 0;    UInt_t totime = 0;
4238    UInt_t obt = 0;    UInt_t obt = 0;
4239    UInt_t pkt = 0;    UInt_t pkt = 0;
4240      Float_t totped = 0.;
4241    //    //
4242    tr = (TTree*)file->Get("CalibCalPed");    tr = (TTree*)file->Get("CalibCalPed");
4243    if ( !tr || tr->IsZombie() ) throw -21;    if ( !tr || tr->IsZombie() ) throw -21;
# Line 4009  Int_t PamelaDBOperations::insertCALO_CAL Line 4255  Int_t PamelaDBOperations::insertCALO_CAL
4255        if ( calibCalPed->cstwerr[section] ){        if ( calibCalPed->cstwerr[section] ){
4256          valid = 1;          valid = 1;
4257          if ( calibCalPed->cperror[section] ) valid = 0;          if ( calibCalPed->cperror[section] ) valid = 0;
4258            //
4259            // check pedestal values for one plane, if all zeros calibration is not valid (calorimeter power problems) [8th data reduction bug, fixed on 25/11/2009 by E.M.]
4260            //
4261            totped = 0.;
4262            Int_t ns = 0;
4263            if ( section == 2 ) ns = 3;
4264            if ( section == 3 ) ns = 1;
4265            if ( section == 1 ) ns = 2;
4266            for (UInt_t ss=0; ss<96; ss++){
4267              totped += fabs(calibCalPed->calped[ns][0][ss]);
4268            }
4269            if ( totped < 1. ){
4270              if ( IsDebug() ) printf(" Section %i totped %f -  No calibration data! Calorimeter power problems? \n",section,totped);
4271              valid = 0;
4272            };
4273            //
4274          ph = eh->GetPscuHeader();          ph = eh->GetPscuHeader();
4275          obt = ph->GetOrbitalTime();            obt = ph->GetOrbitalTime();  
4276          pkt = ph->GetCounter();            pkt = ph->GetCounter();  
# Line 4176  Int_t PamelaDBOperations::insertCALOPULS Line 4438  Int_t PamelaDBOperations::insertCALOPULS
4438    tr->SetBranchAddress("Header", &eh);    tr->SetBranchAddress("Header", &eh);
4439    nevents = tr->GetEntries();    nevents = tr->GetEntries();
4440    //    //
4441      Float_t totpul = 0.;
4442      //
4443    if ( nevents > 0 ){    if ( nevents > 0 ){
4444      //      //
4445      for (UInt_t i=0; i < nevents; i++){      for (UInt_t i=0; i < nevents; i++){
# Line 4185  Int_t PamelaDBOperations::insertCALOPULS Line 4449  Int_t PamelaDBOperations::insertCALOPULS
4449          if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){          if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){
4450            valid = 1;            valid = 1;
4451            if ( cp1->pperror[section] ) valid = 0;            if ( cp1->pperror[section] ) valid = 0;
4452              //
4453              // check pulse values for one plane, if all zeros calibration is not valid (calorimeter power problems) [8th data reduction bug, fixed on 25/11/2009 by E.M.]
4454              //
4455              totpul = 0.;
4456              Int_t ns = 0;
4457              if ( section == 2 ) ns = 3;
4458              if ( section == 3 ) ns = 1;
4459              if ( section == 1 ) ns = 2;
4460              for (UInt_t ss=0; ss<96; ss++){
4461                totpul += cp1->calpuls[ns][0][ss];
4462              }
4463              if ( totpul >= 3145632. ){
4464                if ( IsDebug() ) printf(" PULSE1 Section %i totpul %f -  No calibration data! Calorimeter power problems? \n",section,totpul);
4465                valid = 0;
4466              };
4467              //
4468            ph = eh->GetPscuHeader();            ph = eh->GetPscuHeader();
4469            obt = ph->GetOrbitalTime();              obt = ph->GetOrbitalTime();  
4470            pkt = ph->GetCounter();              pkt = ph->GetCounter();  
# Line 4342  Int_t PamelaDBOperations::insertCALOPULS Line 4622  Int_t PamelaDBOperations::insertCALOPULS
4622          if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){          if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){
4623            valid = 1;            valid = 1;
4624            if ( cp2->pperror[section] ) valid = 0;            if ( cp2->pperror[section] ) valid = 0;
4625              //
4626              // check pulse values for one plane, if all zeros calibration is not valid (calorimeter power problems) [8th data reduction bug, fixed on 25/11/2009 by E.M.]
4627              //
4628              totpul = 0.;
4629              Int_t ns = 0;
4630              if ( section == 2 ) ns = 3;
4631              if ( section == 3 ) ns = 1;
4632              if ( section == 1 ) ns = 2;
4633              for (UInt_t ss=0; ss<96; ss++){
4634                totpul += cp2->calpuls[ns][0][ss];
4635              }
4636              if ( totpul >= 3145632. ){
4637                if ( IsDebug() ) printf(" PULSE2 Section %i totpul %f -  No calibration data! Calorimeter power problems? \n",section,totpul);
4638                valid = 0;
4639              };
4640              //
4641            ph = eh->GetPscuHeader();            ph = eh->GetPscuHeader();
4642            obt = ph->GetOrbitalTime();              obt = ph->GetOrbitalTime();  
4643            pkt = ph->GetCounter();              pkt = ph->GetCounter();  
# Line 4707  void PamelaDBOperations::HandleTRK_CALIB Line 5003  void PamelaDBOperations::HandleTRK_CALIB
5003      if ( !result ) throw -4;;      if ( !result ) throw -4;;
5004      row = result->Next();      row = result->Next();
5005      if(row)glcal->ID = (UInt_t)atoll(row->GetField(0));      if(row)glcal->ID = (UInt_t)atoll(row->GetField(0));
5006        //
5007        delete result; // mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages]
5008      //      //
5009  };  };
5010    
# Line 5215  Int_t PamelaDBOperations::insertTRK_CALI Line 5512  Int_t PamelaDBOperations::insertTRK_CALI
5512    
5513              if(FOUND){              if(FOUND){
5514    
5515              if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <<endl;                if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <<endl;
5516    
5517                  ////////////////////////////////////////////                ////////////////////////////////////////////
5518                  // insert a new entry in GL_TRK_CALIB and                // insert a new entry in GL_TRK_CALIB and
5519                  // modify the time-tag of the previous one                // modify the time-tag of the previous one
5520                  ////////////////////////////////////////////                ////////////////////////////////////////////
5521    
5522                  // ---------------------------------------------------------------------                // ---------------------------------------------------------------------
5523                  // step 1: insert a new raw file in GL_RAW                // step 1: insert a new raw file in GL_RAW
5524                  // ---------------------------------------------------------------------                // ---------------------------------------------------------------------
5525                  //                //
5526                  // check if the raw file already exist                // check if the raw file already exist
5527                  //                //
5528                  UInt_t id_raw = 0;   // EM GL_RAW is there only for backward compatibility so we do not need to fill it when in "chewbacca" mode                UInt_t id_raw = 0;   // EM GL_RAW is there only for backward compatibility so we do not need to fill it when in "chewbacca" mode
5529  //              oss.str("");                //                oss.str("");
5530  //              oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";";                //                oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";";
5531  //              if ( IsDebug() ) cout << oss.str().c_str() << endl;                //                if ( IsDebug() ) cout << oss.str().c_str() << endl;
5532                                    
5533  //              result = conn->Query(oss.str().c_str());                //                result = conn->Query(oss.str().c_str());
5534  //              if ( !result ) throw -4;;                //                if ( !result ) throw -4;;
5535  //              if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl;                //                if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl;
5536  //              if( result->GetRowCount() == 0){                //                if( result->GetRowCount() == 0){
5537  //                  if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl;                //                    if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl;
5538  //                  // - - - - - - - - - - -                //                    // - - - - - - - - - - -
5539  //                  // insert new raw file                //                    // insert new raw file
5540  //                  // - - - - - - - - - - -                //                    // - - - - - - - - - - -
5541  //                  GL_RAW glraw = GL_RAW();                    //                    GL_RAW glraw = GL_RAW();    
5542  //                  glraw.PATH        = gSystem->DirName(raw.Data());                //                    glraw.PATH        = gSystem->DirName(raw.Data());
5543  //                  glraw.NAME        = gSystem->BaseName(raw.Data());                //                    glraw.NAME        = gSystem->BaseName(raw.Data());
5544  //                  glraw.BOOT_NUMBER = boot_number;                //                    glraw.BOOT_NUMBER = boot_number;
5545  //                  //                //                    //
5546  //                  insertPamelaRawFile( &glraw );                //                    insertPamelaRawFile( &glraw );
5547  //                  //                              //                    //              
5548  //                  id_raw = glraw.ID;                              //                    id_raw = glraw.ID;              
5549  //              }else{                //                }else{
5550  //                  row = result->Next();                //                    row = result->Next();
5551  //                  id_raw = (UInt_t)atoll(row->GetField(0));                //                    id_raw = (UInt_t)atoll(row->GetField(0));
5552  //              }                //                }
5553  //              if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl;                //                if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl;
5554    
5555                  // ---------------------------------------------------------------------                // ---------------------------------------------------------------------
5556                  // step 1(bis): retrieve the timesync id associated to the file                // step 1(bis): retrieve the timesync id associated to the file
5557                  // (NB, uso lo stesso associato al file iniziale)                // (NB, uso lo stesso associato al file iniziale)
5558                  // ---------------------------------------------------------------------                // ---------------------------------------------------------------------
5559                  UInt_t idtimesync = 0;                UInt_t idtimesync = 0;
5560                  oss.str("");                oss.str("");
5561                  oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;";                oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;";
5562                  if ( debug ) printf(" %s \n",oss.str().c_str());                if ( debug ) printf(" %s \n",oss.str().c_str());
5563                  result = conn->Query(oss.str().c_str());                result = conn->Query(oss.str().c_str());
5564                  if ( !result ) throw -3;                if ( !result ) throw -3;
5565                  row = result->Next();                  row = result->Next();
5566                  if ( !row ) throw -3;                  if ( !row ) throw -3;
5567                  idtimesync = (UInt_t)atoll(row->GetField(0));                  idtimesync = (UInt_t)atoll(row->GetField(0));
5568                  if ( IsDebug() ) cout << "ID_TIMESYNC = "<<idtimesync<<endl;                  if ( IsDebug() ) cout << "ID_TIMESYNC = "<<idtimesync<<endl;
5569                                    
5570                    delete result;// mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages]
5571                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
5572                  // step 2: insert a new root file in GL_ROOT                  // step 2: insert a new root file in GL_ROOT
5573                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
# Line 5317  Int_t PamelaDBOperations::insertTRK_CALI Line 5615  Int_t PamelaDBOperations::insertTRK_CALI
5615                  }                  }
5616                  if ( IsDebug() ) cout << "ID_ROOT = "<<id_root<<endl;                  if ( IsDebug() ) cout << "ID_ROOT = "<<id_root<<endl;
5617    
5618                    delete result;// mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages]
5619                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
5620                  // step 3: modify time-tag of corrupted GL_TRK_CALIB entry                  // step 3: modify time-tag of corrupted GL_TRK_CALIB entry
5621                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
# Line 5329  Int_t PamelaDBOperations::insertTRK_CALI Line 5628  Int_t PamelaDBOperations::insertTRK_CALI
5628                  result = conn->Query(oss.str().c_str());                  result = conn->Query(oss.str().c_str());
5629                  if ( !result ) throw -4;;                  if ( !result ) throw -4;;
5630    
5631                    delete result; // mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages]
5632    
5633                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
5634                  // step 4: insert the new calibration:                  // step 4: insert the new calibration:
5635                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
# Line 5780  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6081  Int_t PamelaDBOperations::CleanGL_RUN_FR
6081                  oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , ";                  oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , ";
6082                //                              //              
6083                oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , "                oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , "
6084                    << " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT()<< ";";                    << " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT();
6085                  oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112
6086                conn->Query(oss.str().c_str());                  conn->Query(oss.str().c_str());  
6087              };                  };    
6088            };            };
# Line 5829  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6131  Int_t PamelaDBOperations::CleanGL_RUN_FR
6131                if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){                if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){
6132                  oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };                  oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
6133                //                              //              
6134                oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()<< ";";                oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT();
6135                  oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112
6136                conn->Query(oss.str().c_str());                  conn->Query(oss.str().c_str());  
6137              };                  };    
6138            };            };
# Line 5880  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6183  Int_t PamelaDBOperations::CleanGL_RUN_FR
6183                row2 = result2->Next();                row2 = result2->Next();
6184                //                //
6185                if ( row2 ){                if ( row2 ){
6186                  if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n");                  if ( IsDebug() ) printf(" The run already exists in the GL_RUN table! \n");
6187                  if ( PEDANTIC ) throw -83;                  if ( PEDANTIC ) throw -83;
6188                  row2->Close();                  row2->Close();
6189                };                };
# Line 5957  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6260  Int_t PamelaDBOperations::CleanGL_RUN_FR
6260        glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);          glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);  
6261        //        //
6262        oss.str("");        oss.str("");
6263        oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE "        oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER,ID_ROOT_L0 FROM GL_RUN WHERE "
6264            << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND ("            << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND ("
6265            << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "            << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "
6266            << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("            << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("
# Line 6015  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6318  Int_t PamelaDBOperations::CleanGL_RUN_FR
6318          moved++;          moved++;
6319          //          //
6320        } else {        } else {
6321          if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n");  
6322          if ( PEDANTIC ) throw -83;          // questa parte mah mah mah... da controllare
6323    
6324            //
6325            // we end up here if chewbacca and we have RH---| small gap |---RT, in this case the two pieces are attached and moved to GL_RUN. We are now processing the
6326            // "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number.
6327            //
6328            // 090112 [8RED (-70): RUN ALREADY INSERTED]
6329            //
6330            Bool_t OK = false;
6331            UInt_t IDRL2A = 0;
6332            UInt_t IDRL2B = 0;
6333              if ( result2->GetRowCount() == 2 ){
6334                IDRL2A = (UInt_t)atoll(row2->GetField(0));
6335                UInt_t IDRL0A = (UInt_t)atoll(row2->GetField(4));
6336                row2 = result2->Next();
6337                IDRL2B = (UInt_t)atoll(row2->GetField(0));
6338                UInt_t IDRL0B = (UInt_t)atoll(row2->GetField(4));
6339                if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B);
6340                //      if ( IDRL0A == IDRL0B ){
6341    //            TSQLResult *result2a = 0;
6342    //            TSQLRow    *row2a    = 0;
6343    //            oss.str("");
6344    //            oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;";
6345    //            if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
6346    //            result2a = conn->Query(oss.str().c_str());
6347    //            //
6348    //            if ( !result2a ) throw -4;
6349    //            //
6350    //            row2a = result2a->Next();
6351    //            //
6352    //            if ( row2a ){
6353    //              UInt_t PKA = (UInt_t)atoll(row2a->GetField(0));
6354    //              delete result2a;
6355    //              oss.str("");
6356    //              oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;";
6357    //              if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
6358    //              result2a = conn->Query(oss.str().c_str());
6359    //              //
6360    //              if ( !result2a ) throw -4;
6361    //              //
6362    //              row2a = result2a->Next();
6363    //              //
6364    //              if ( row2a ){
6365    //                UInt_t PKB = (UInt_t)atoll(row2a->GetField(0));
6366    //                //
6367    //                if ( IsDebug() ) printf(" PKT(PKA) + 1 %llu == runheaderpkt %llu && PKB = runtrailer %llu + 1 %llu \n",PKT(PKA)+1LL, PKT(glrun->GetRUNHEADER_PKT()),PKT(PKB), PKT(glrun->GetRUNTRAILER_PKT())+1LL);
6368    //                if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){
6369    //                  if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n");
6370                        OK = true;
6371                        //            };
6372                        //          };
6373                        //        };                  
6374                        //    };
6375              };      
6376            if ( OK ){
6377              //
6378              // this is the case in which we must insert a piece of run between two fragments in the GL_RUN table
6379              //
6380              // we have to update with runheader/trailer infos our run and we have to change the ROOT_ID_FRAG of the header piece ( 1/2 2/1 must become 1/3 3/2 2/1 )
6381              //
6382              GL_RUN *glA = new GL_RUN();
6383              glA->Query_GL_RUN(IDRL2A,conn);
6384              //
6385              if ( glA->GetACQ_BUILD_INFO() != 0 ){
6386                //
6387                // the first piece contains a good runheader we can update all the other runs with correct infos!
6388                //
6389                oss.str("");
6390                oss << "UPDATE GL_RUN_FRAGMENTS SET "
6391                    << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "
6392                    << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
6393                    << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , "
6394                    << " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , "
6395                    << " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , "
6396                    << " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , "
6397                    << " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , "
6398                    << " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , "
6399                    << " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , "
6400                    << " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , "
6401                    << " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , "  
6402                    << " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , "  
6403                    << " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , "  
6404                    << " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , "  
6405                    << " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , ";
6406                //
6407                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
6408                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , ";
6409                if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
6410                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , ";
6411                //        
6412                oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC();
6413                oss << " WHERE ID=" << glrun->GetID() << ";";
6414                if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str());
6415                conn->Query(oss.str().c_str());    
6416                //
6417              } else {
6418                //
6419                // sig no runheader, let set anyway what is possible...
6420                //
6421                oss.str("");
6422                oss << "UPDATE GL_RUN_FRAGMENTS SET "
6423                    << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , ";
6424                //
6425                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
6426                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , ";
6427                if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
6428                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , ";
6429                //        
6430                oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
6431                    << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT();
6432                oss << " WHERE ID=" << glrun->GetID() << ";";
6433                if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str());
6434                conn->Query(oss.str().c_str());    
6435              };
6436              //
6437              // update runheader ROOT_ID_FRAG
6438              //
6439              oss.str("");
6440              oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";";
6441              if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str());
6442              conn->Query(oss.str().c_str());
6443              //
6444              // now let's look for runtrailer if any in the last run
6445              //
6446              glA->Query_GL_RUN(IDRL2B,conn);
6447              //
6448              if ( glA->GetPKT_READY_COUNTER() != 0 ){
6449                //
6450                // the first piece contains a good runtrailer we can update all the other runs with correct infos!
6451                //
6452                oss.str("");
6453                oss << "UPDATE GL_RUN_FRAGMENTS SET "
6454                    << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
6455                    << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "
6456                    << " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , "
6457                    << " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , ";
6458                //
6459                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
6460                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
6461                if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) {
6462                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
6463                //        
6464                oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER()
6465                    << " WHERE ID=" << glrun->GetID() << ";";
6466                if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str());
6467                conn->Query(oss.str().c_str());    
6468                //
6469              } else {
6470                //
6471                // sig no runtrailer, let set anyway what is possible...
6472                //
6473                oss.str("");
6474                oss << "UPDATE GL_RUN_FRAGMENTS SET "
6475                    << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
6476                    << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , ";
6477                  //
6478                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
6479                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
6480                if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){
6481                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
6482                //        
6483                oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()
6484                    << " WHERE ID=" << glrun->GetID() << ";";
6485                if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str());
6486                conn->Query(oss.str().c_str());    
6487              };
6488              //
6489              UInt_t myi = glrun->GetID();
6490              oss.str("");
6491              oss << " ID= "<< myi;
6492              //
6493              glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);  
6494              //
6495              // fill the new run in GL_RUN
6496              //
6497              glrun->SetID_RUN_FRAG(IDRL2B);
6498              glrun->Fill_GL_RUN(conn);    
6499              glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
6500              delete glA;
6501              moved++;
6502              //
6503            } else {
6504              //
6505              // is just a repetition
6506              //
6507              if ( IsDebug() ) printf(" The run %u is already present in the GL_RUN table...\n",glrun->GetID());    
6508              //      printf(" CCCCCCCCICCCCCCCCCCCCIOOOOOOOOOO si muove Ciccio! %u \n",glrun->GetID());
6509              //      if ( PEDANTIC && glrun->GetID() != 61563 ) throw -83;
6510              if ( PEDANTIC ) throw -83;
6511            };
6512            //      if ( IsDebug() ) printf(" The run already exists in the GL_RUN table! ...\n");
6513            //      if ( PEDANTIC ) throw -83;
6514        };        };
6515        if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0));              if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0));      
6516        //        //
# Line 6082  Int_t PamelaDBOperations::ValidateRuns(T Line 6576  Int_t PamelaDBOperations::ValidateRuns(T
6576      // 2) get the OBT of the last validated run      // 2) get the OBT of the last validated run
6577      // --------------------------------------------------------------      // --------------------------------------------------------------
6578      oss.str("");      oss.str("");
6579      oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start      //    oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start
6580        oss << " SELECT * FROM GL_RUN  WHERE VALIDATION>0 AND RUNHEADER_TIME<="<< t_start
6581          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
6582      if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());      if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());
6583      result = conn->Query(oss.str().c_str());      result = conn->Query(oss.str().c_str());
# Line 6225  Int_t PamelaDBOperations::ValidateRuns(T Line 6720  Int_t PamelaDBOperations::ValidateRuns(T
6720          if( interval >= calibtime )CHECK = true;                        //more than calibtime s => there might be a calibration          if( interval >= calibtime )CHECK = true;                        //more than calibtime s => there might be a calibration
6721                                                        
6722          if( !CHECK && this_run->VALIDATION ){          if( !CHECK && this_run->VALIDATION ){
6723            for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);            //      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
6724              for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],this_run->VALIDATION);
6725            nseq=0;            nseq=0;
6726          }          }
6727                                        
# Line 6246  Int_t PamelaDBOperations::ValidateRuns(T Line 6742  Int_t PamelaDBOperations::ValidateRuns(T
6742      if( CHECK ){      if( CHECK ){
6743        // check if calibration exists        // check if calibration exists
6744        if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval);        if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval);
6745        Bool_t MISSING = MissingTRK_CALIB(t1,t2);        //      Bool_t MISSING = MissingTRK_CALIB(t1,t2);
6746        for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);        UInt_t MISSING = MissingTRK_CALIB(t1,t2);
6747          UInt_t val = 0;
6748          if ( MISSING == 1 ) val = 0;
6749          if ( MISSING == 0 ) val = 1;
6750          if ( MISSING == 2 ) val = 2;
6751          for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],val);
6752        nseq=0;        nseq=0;
6753      };      };
6754      //--------------      //--------------
# Line 6277  Int_t PamelaDBOperations::ValidateRuns(T Line 6778  Int_t PamelaDBOperations::ValidateRuns(T
6778   * @param t2 To absolute time   * @param t2 To absolute time
6779   * @return true if there might be a missing calibration   * @return true if there might be a missing calibration
6780   */   */
6781  Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){  //Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){
6782    UInt_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){
6783                    
6784    GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB();    GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB();
6785                    
6786    // get the closest calibration before the run start (t2)    // get the closest calibration before the run start (t2)
6787    if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true);    //>>> missing    //  if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true);        //>>> missing
6788      if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(1);       //>>> missing
6789                    
6790    if ( trkcalib->TO_TIME  < t2 ) return(true);                                  //>>> missing    //  if ( trkcalib->TO_TIME  < t2 ) return(true);                                      //>>> missing
6791      if ( trkcalib->TO_TIME  < t2 ) return(1);                                     //>>> missing
6792                    
6793    //==============================================================    //==============================================================
6794    // Check is done first on the basis of time between calibration,    // Check is done first on the basis of time between calibration,
# Line 6301  Bool_t PamelaDBOperations::MissingTRK_CA Line 6805  Bool_t PamelaDBOperations::MissingTRK_CA
6805      //==============================================================      //==============================================================
6806      Bool_t DOWNLOAD = false;      Bool_t DOWNLOAD = false;
6807      // check if the calib was skipped becouse of download .... DA FARE!!      // check if the calib was skipped becouse of download .... DA FARE!!
6808      if(DOWNLOAD)return(false);      //    if(DOWNLOAD)return(false);
6809        if(DOWNLOAD)return(0);
6810                                    
6811      return(true);                                       //>>> missing      //    return(true);                                         //>>> missing
6812        return(1);                                  //>>> missing
6813                                    
6814    };    };
6815                    
# Line 6313  Bool_t PamelaDBOperations::MissingTRK_CA Line 6819  Bool_t PamelaDBOperations::MissingTRK_CA
6819    //==============================================================    //==============================================================
6820    // the long time interval bewteen runs might be due to download    // the long time interval bewteen runs might be due to download
6821    if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME);    if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME);
6822    return(false);    if ( trkcalib->VALIDATION ) return(0);
6823      if ( IsDebug() )printf("Calibration is not validated... :-/ ==> OK but with VALIDATION=2! \n");
6824      return(2);
6825                    
6826  };  };
6827  /**  /**
# Line 6322  Bool_t PamelaDBOperations::MissingTRK_CA Line 6830  Bool_t PamelaDBOperations::MissingTRK_CA
6830   * @param validation true/false   * @param validation true/false
6831   */   */
6832  Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){  Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){
6833      return(this->assignVALIDATION(idrun,(UInt_t)validation));
6834    }
6835    
6836    Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, UInt_t validation){
6837    TSQLResult *result = 0;    TSQLResult *result = 0;
6838    stringstream oss;    stringstream oss;
6839    oss.str("");    oss.str("");

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.28

  ViewVC Help
Powered by ViewVC 1.1.23