/[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.9 by mocchiut, Tue Nov 4 17:11:41 2008 UTC revision 1.26 by mocchiut, Wed Nov 25 09:39:50 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                if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());
190                result3 = conn->Query(qu.str().c_str());
191                if ( result3 ){
192                  row3 = result3->Next();
193                  if ( row3 && result3->GetRowCount() == 1 ){
194                    chboot = (UInt_t)atoll(row3->GetField(0));
195                    if ( debug ) printf(" Found boot_number = %u \n",chboot);
196                  } else {
197                    if ( debug ) printf(" AGH CANNOT DETERMINE THE BOOT NUMBER... \n");
198                    throw -29;
199                  };
200                };
201              };
202              //
203            chpktinit = (UInt_t)atoll(row2->GetField(6));            chpktinit = (UInt_t)atoll(row2->GetField(6));
204            chpktfinal = (UInt_t)atoll(row2->GetField(7));            chpktfinal = (UInt_t)atoll(row2->GetField(7));
205            chobtinit = (UInt_t)atoll(row2->GetField(8));            chobtinit = (UInt_t)atoll(row2->GetField(8));
# Line 189  void PamelaDBOperations::OpenL0File(TStr Line 212  void PamelaDBOperations::OpenL0File(TStr
212          throw -85;          throw -85;
213        };        };
214        filerootname = chpath + chfile;// + ".root";        filerootname = chpath + chfile;// + ".root";
       if ( debug ) printf(" chewbacca: filename is %s \n",filerootname.Data());  
215      };      };
216      this->SetRootName(filerootname);      this->SetRootName(filerootname);
     file = TFile::Open(this->GetRootName().Data());  
   } else {  
     this->SetRootName("");  
217    };    };
218      if ( debug ) printf(" Filename is %s \n",filerootname.Data());
219      file = TFile::Open(this->GetRootName().Data());
220      //  } else {
221      //    this->SetRootName("");
222      //    this->SetRootName(filerootname);
223      //  };
224  }  }
225    
226  //  //
# Line 395  void PamelaDBOperations::SetOrbitNo(UInt Line 420  void PamelaDBOperations::SetOrbitNo(UInt
420      return;      return;
421    };    };
422    //    //
423    TString name = this->GetRootFile();    if ( !chewbacca ){
424    Int_t nlength = name.Length();      TString name = this->GetRootFile();
425    if ( nlength < 5 ) return;      Int_t nlength = name.Length();
426    TString dwo = 0;      if ( nlength < 5 ){
427    for (Int_t i = 0; i<5; i++){        if ( IsDebug() ) printf(" Agh problems determining the orbit number! name = %s \n",name.Data());
428      dwo.Append(name[i],1);        return;
429    };      };
430    if ( dwo.IsDigit() ){      TString dwo = "";
431      dworbit = (UInt_t)dwo.Atoi();      for (Int_t i = 0; i<5; i++){
   } else {  
     dwo="";  
     for (Int_t i = 8; i<13; i++){  
432        dwo.Append(name[i],1);        dwo.Append(name[i],1);
433      };          };
434      if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi();      if ( dwo.IsDigit() ){
435          dworbit = (UInt_t)dwo.Atoi();
436        } else {
437          dwo="";
438          for (Int_t i = 8; i<13; i++){
439            dwo.Append(name[i],1);
440          };    
441          if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi();
442        };
443        if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data());
444    };    };
   if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data());  
445    return;    return;
446  };  };
447    
# Line 791  Int_t PamelaDBOperations::SetUpperLimits Line 821  Int_t PamelaDBOperations::SetUpperLimits
821      ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();
822      pktlast = ph->GetCounter();      pktlast = ph->GetCounter();
823      nevent = upperentry - chminentry;      nevent = upperentry - chminentry;
824        if ( ((Int_t)upperentry - (Int_t)chminentry) < 0 ) nevent = 0; // nevent is UInt_t! 090112 [8RED: error -88]
825        if ( IsDebug() ) printf(" Setting nevent to %u - upperentry %i chminentry %i \n",nevent,upperentry,chminentry);
826      //      //
827    } else {    } else {
828      upperpkt = PKT(pktlast);      upperpkt = PKT(pktlast);
# Line 799  Int_t PamelaDBOperations::SetUpperLimits Line 831  Int_t PamelaDBOperations::SetUpperLimits
831    };    };
832    //    //
833    if ( chewbacca && nevent < 1 ) {    if ( chewbacca && nevent < 1 ) {
834        if ( IsDebug() ) printf(" chewbacca and no events in the file \n");
835      pktfirst = chpktmin;      pktfirst = chpktmin;
836      upperpkt = PKT(chpktmax);      upperpkt = PKT(chpktmax);
837      pktlast = chpktmax;      pktlast = chpktmax;
# Line 824  Int_t PamelaDBOperations::SetUpperLimits Line 857  Int_t PamelaDBOperations::SetUpperLimits
857    //  if ( nevent < jump ) jump = int(nevent/10);    //  if ( nevent < jump ) jump = int(nevent/10);
858    //  if ( !jump ) jump = 1;    //  if ( !jump ) jump = 1;
859    //    //
860    if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) && nevent > deltapkt ){  
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      //      //
863      if ( IsDebug() ) printf(" starting jump %i \n",jump);      if ( IsDebug() ) printf(" starting jump %i \n",jump);
864      //    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 1386  Long64_t PamelaDBOperations::OBT(UInt_t
1386    //    //
1387    //  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));
1388    //    //
1389    if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){    if ( obt < ((Long64_t)pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){
1390      //    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());
1391      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());
1392    };    };
# Line 1471  void PamelaDBOperations::FillClass(Bool_ Line 1505  void PamelaDBOperations::FillClass(Bool_
1505      glrun->SetRUNTRAILER_PKT(lastPkt);      glrun->SetRUNTRAILER_PKT(lastPkt);
1506      //          //    
1507    };    };
1508      //
1509      // ad hoc solution for INF EV_TO [8RED] 090113
1510      //
1511      if ( !firstev && lastev == -1 ){
1512        if ( IsDebug() ) printf(" EE firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1);
1513        firstev = 1;
1514        lastev = 0;
1515      };
1516    glrun->SetEV_FROM((UInt_t)firstev);    glrun->SetEV_FROM((UInt_t)firstev);
1517    glrun->SetEV_TO((UInt_t)lastev);    glrun->SetEV_TO((UInt_t)lastev);
1518    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 1619  Int_t PamelaDBOperations::insertPamelaGL
1619      result = conn->Query(oss.str().c_str());      result = conn->Query(oss.str().c_str());
1620      if ( !result ) throw -10;      if ( !result ) throw -10;
1621      row = result->Next();      row = result->Next();
1622        if ( !row ) throw -92;
1623      idresof = (UInt_t)atoll(row->GetField(0));      idresof = (UInt_t)atoll(row->GetField(0));
1624      existsts = true;      existsts = true;
1625      goto eout;      goto eout;
# Line 1598  Int_t PamelaDBOperations::insertPamelaGL Line 1641  Int_t PamelaDBOperations::insertPamelaGL
1641      if ( !row ){      if ( !row ){
1642        oss.str("");        oss.str("");
1643        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< "
1644            << dworbit << " order by FROM_ORBIT desc limit 1;";            << dworbit << " AND SPECIAL_FILE='' order by FROM_ORBIT desc limit 1;";
1645        if ( IsDebug() ) printf(" %s \n",oss.str().c_str());        if ( IsDebug() ) printf(" %s \n",oss.str().c_str());
1646        result = conn->Query(oss.str().c_str());        result = conn->Query(oss.str().c_str());
1647        if ( !result ) throw -10;        if ( !result ) throw -10;
# Line 2239  Int_t PamelaDBOperations::insertPamelaRU Line 2282  Int_t PamelaDBOperations::insertPamelaRU
2282          ptht = cod->Get(pctp->RunHeader) - 1;          ptht = cod->Get(pctp->RunHeader) - 1;
2283          //      evbeft = cod->Get(pctp->Physics);          //      evbeft = cod->Get(pctp->Physics);
2284          tcod = (UInt_t)cod->Get(pctp->Physics);          tcod = (UInt_t)cod->Get(pctp->Physics);
2285          if ( !tcod ) tcod = 1;          if ( !tcod ) tcod = 1;    // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT
2286          evbeft = TMath::Min(upperentry,(tcod-1));          evbeft = TMath::Min(upperentry,(tcod-1));
2287          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));
2288          //          //
# Line 2278  Int_t PamelaDBOperations::insertPamelaRU Line 2321  Int_t PamelaDBOperations::insertPamelaRU
2321            obth = phh->GetOrbitalTime();            obth = phh->GetOrbitalTime();
2322            cod = ehh->GetCounter();            cod = ehh->GetCounter();
2323            tcod = (UInt_t)cod->Get(pctp->Physics);            tcod = (UInt_t)cod->Get(pctp->Physics);
2324            if ( !tcod ) tcod = 1;            if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT
2325            evbefh = TMath::Max(chminentry,(tcod-1));            evbefh = TMath::Max(chminentry,(tcod-1));
2326            //            //
2327            if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){            if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){
# Line 2317  Int_t PamelaDBOperations::insertPamelaRU Line 2360  Int_t PamelaDBOperations::insertPamelaRU
2360                //                //
2361                this->HandleRunFragments(true,true,chminentry,(evbefh));                this->HandleRunFragments(true,true,chminentry,(evbefh));
2362                //                //
2363                  // what about pth=ptht-1
2364              };              };
2365            };            };
2366            //            //
# Line 2339  Int_t PamelaDBOperations::insertPamelaRU Line 2383  Int_t PamelaDBOperations::insertPamelaRU
2383                cod = ehh->GetCounter();                cod = ehh->GetCounter();
2384                //            evbeft = cod->Get(pctp->Physics);                //            evbeft = cod->Get(pctp->Physics);
2385                tcod = (UInt_t)cod->Get(pctp->Physics);                tcod = (UInt_t)cod->Get(pctp->Physics);
2386                if ( !tcod ) tcod = 1;                if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT
2387                evbeft = TMath::Min(upperentry,(tcod-1));                evbeft = TMath::Min(upperentry,(tcod-1));
2388                rh->GetEntry(pth);                rh->GetEntry(pth);
2389                phh = ehh->GetPscuHeader();                phh = ehh->GetPscuHeader();
# Line 2379  Int_t PamelaDBOperations::insertPamelaRU Line 2423  Int_t PamelaDBOperations::insertPamelaRU
2423          //      if ( ptt+1 == rtev){            //      if ( ptt+1 == rtev){  
2424          if ( conptt+1 == nrtev ){            if ( conptt+1 == nrtev ){  
2425            //    if ( conptt+1 == (nrtev+nrtbef )){              //    if ( conptt+1 == (nrtev+nrtbef )){  
2426              if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt);
2427            ptht++;            ptht++;
2428            if ( ptht < rhev ){            if ( ptht < rhev ){
2429              rh->GetEntry(ptht);              rh->GetEntry(ptht);
2430                //pth++;
2431                //if ( pth < rhev ){
2432                //rh->GetEntry(pth);
2433              phh = ehh->GetPscuHeader();              phh = ehh->GetPscuHeader();
2434              pkth = phh->GetCounter();              pkth = phh->GetCounter();
2435              obth = phh->GetOrbitalTime();              obth = phh->GetOrbitalTime();
# Line 2405  Int_t PamelaDBOperations::insertPamelaRU Line 2453  Int_t PamelaDBOperations::insertPamelaRU
2453              if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){              if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){
2454                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);
2455                //                //
2456                if ( (ptt-1) < 0 ) throw -15; // should never arrive here!                //              if ( (ptt-1) < 0 ) throw -15; // should never arrive here!
2457                rt->GetEntry(ptt-1);                if ( (rtev-1) < 0 || ptt < 0 ) throw -15; // should never arrive here!
2458                  //              rt->GetEntry(ptt-1);
2459                  rt->GetEntry(rtev-1);
2460                cod = eht->GetCounter();                cod = eht->GetCounter();
2461                tcod = (UInt_t)cod->Get(pctp->Physics);                tcod = (UInt_t)cod->Get(pctp->Physics)+1;
2462                evbefh = TMath::Max(chminentry,tcod);                evbefh = TMath::Max(chminentry,tcod);
2463                //            evbefh = cod->Get(pctp->Physics);                //            evbefh = cod->Get(pctp->Physics);
2464                rt->GetEntry(ptt);                rt->GetEntry(ptt);
# Line 2639  void PamelaDBOperations::HandleRunFragme Line 2689  void PamelaDBOperations::HandleRunFragme
2689      //      //
2690      // 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
2691      //      //
2692      if ( rhfirstev != firstev && !mishead ) mishead = true;      if ( firstev != (lastev+1) ){ // could be a problem sometimes (?)
2693      if ( rtlastev != lastev && !mistrail ) mistrail = true;        if ( rhfirstev != firstev && !mishead ) mishead = true;
2694          if ( rtlastev != lastev && !mistrail ) mistrail = true;
2695        };
2696      //      //
2697        if ( IsDebug() ) printf(" bhere firstev is %i lastev is %i \n",firstev,lastev);
2698      this->FillClass(mishead,mistrail,firstev,lastev);      this->FillClass(mishead,mistrail,firstev,lastev);
2699        if ( IsDebug() ) printf(" chere firstev is %i lastev is %i \n",firstev,lastev);
2700      //      //
2701      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");
2702      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 2684  void PamelaDBOperations::HandleRunFragme Line 2738  void PamelaDBOperations::HandleRunFragme
2738        glrun->Fill_GL_RUN_FRAGMENTS(conn);        glrun->Fill_GL_RUN_FRAGMENTS(conn);
2739        //        //
2740      } else {      } else {
2741        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);
2742        if ( PEDANTIC ) throw -69;        if ( !RELAXED ){
2743        return;          if ( PEDANTIC ) throw -69;
2744            return;
2745          } else {
2746            glrun->SetID((UInt_t)atoll(row->GetField(0)));
2747            glrun->SetID_RUN_FRAG(0);
2748          };
2749      };      };
2750      //      //
2751      if ( chewbacca && mishead && mistrail ) goto justcheck;      if ( chewbacca && mishead && mistrail ) goto justcheck;
# Line 2737  void PamelaDBOperations::HandleRunFragme Line 2796  void PamelaDBOperations::HandleRunFragme
2796          //          //
2797          found = false; // default value          found = false; // default value
2798          //          //
2799          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");
2800          //          //
2801          // 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:
2802          //          //
# Line 2753  void PamelaDBOperations::HandleRunFragme Line 2812  void PamelaDBOperations::HandleRunFragme
2812              if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt);              if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt);
2813              //              //
2814              found = true;              found = true;
2815                if ( IsDebug() ) printf(" where firstev is %i lastev is %i \n",firstev,lastev);
2816              //              //
2817            } else {            } else {
2818              //              //
# Line 2818  void PamelaDBOperations::HandleRunFragme Line 2878  void PamelaDBOperations::HandleRunFragme
2878          oss << " ID="<<row->GetField(0)<<";";          oss << " ID="<<row->GetField(0)<<";";
2879          //          //
2880          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
2881            if ( IsDebug() ) printf(" there firstev is %i lastev is %i \n",firstev,lastev);
2882          //          //
2883          // merge infos          // merge infos
2884          //          //
# Line 2848  void PamelaDBOperations::HandleRunFragme Line 2909  void PamelaDBOperations::HandleRunFragme
2909          glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT());          glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT());
2910          glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT());          glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT());
2911          //          //
2912            if ( IsDebug() ) printf(" here firstev is %i lastev is %i \n",firstev,lastev);
2913            //
2914          glrun->SetEV_FROM(firstev);          glrun->SetEV_FROM(firstev);
2915          glrun->SetNEVENTS(lastev-firstev+1);          glrun->SetNEVENTS(lastev-firstev+1);
2916          //          //
# Line 2940  void PamelaDBOperations::HandleRunFragme Line 3003  void PamelaDBOperations::HandleRunFragme
3003          //          //
3004          found = false; // default value          found = false; // default value
3005          //          //
3006          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");
3007          //          //
3008          // 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:
3009          //          //
# Line 3040  void PamelaDBOperations::HandleRunFragme Line 3103  void PamelaDBOperations::HandleRunFragme
3103            apkt = PKT(ph->GetCounter());            apkt = PKT(ph->GetCounter());
3104            aobt = OBT(ph->GetOrbitalTime());                aobt = OBT(ph->GetOrbitalTime());    
3105            lastev--;            lastev--;
3106            if ( PEDANTIC ) throw -72;            if ( PEDANTIC && !RELAXED) throw -72;
3107          };          };
3108          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);
3109          //          //
# Line 3108  void PamelaDBOperations::HandleRunFragme Line 3171  void PamelaDBOperations::HandleRunFragme
3171        // 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?
3172        //        //
3173        oss.str("");        oss.str("");
3174        oss << " SELECT ID FROM GL_RUN WHERE "        oss << " SELECT ID,ID_ROOT_L0 FROM GL_RUN WHERE "
3175            << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND ("            << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND ("
3176            << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "            << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "
3177            << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("            << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("
# Line 3131  void PamelaDBOperations::HandleRunFragme Line 3194  void PamelaDBOperations::HandleRunFragme
3194        row = result->Next();        row = result->Next();
3195        //        //
3196        if ( row ){        if ( row ){
3197          if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n");          //
3198          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
3199            // "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number.
3200            //
3201            // 090112 [8RED (-70): RUN ALREADY INSERTED]
3202            //
3203            Bool_t OK = false;
3204            UInt_t IDRL2A = 0;
3205            UInt_t IDRL2B = 0;
3206            if ( chewbacca ){
3207              if ( result->GetRowCount() == 2 ){
3208                IDRL2A = (UInt_t)atoll(row->GetField(0));
3209                UInt_t IDRL0A = (UInt_t)atoll(row->GetField(1));
3210                row = result->Next();
3211                IDRL2B = (UInt_t)atoll(row->GetField(0));
3212                UInt_t IDRL0B = (UInt_t)atoll(row->GetField(1));
3213                if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B);
3214                if ( IDRL0A == IDRL0B ){
3215                  TSQLResult *result2 = 0;
3216                  TSQLRow    *row2    = 0;
3217                  oss.str("");
3218                  oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;";
3219                  if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
3220                  result2 = conn->Query(oss.str().c_str());
3221                  //
3222                  if ( !result2 ) throw -4;
3223                  //
3224                  row2 = result2->Next();
3225                  //
3226                  if ( row2 ){
3227                    UInt_t PKA = (UInt_t)atoll(row2->GetField(0));
3228                    delete result2;
3229                    oss.str("");
3230                    oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;";
3231                    if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
3232                    result2 = conn->Query(oss.str().c_str());
3233                    //
3234                    if ( !result2 ) throw -4;
3235                    //
3236                    row2 = result2->Next();
3237                    //
3238                    if ( row2 ){
3239                      UInt_t PKB = (UInt_t)atoll(row2->GetField(0));
3240                      //
3241                      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);
3242                      if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){
3243                        if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n");
3244                        OK = true;
3245                      };
3246                    };
3247                  };                  
3248                };
3249              };      
3250            };
3251            if ( OK ){
3252              //
3253              // this is the case in which we must insert a piece of run between two fragments in the GL_RUN table
3254              //
3255              // 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 )
3256              //
3257              GL_RUN *glA = new GL_RUN();
3258              glA->Query_GL_RUN(IDRL2A,conn);
3259              //
3260              if ( glA->GetACQ_BUILD_INFO() != 0 ){
3261                //
3262                // the first piece contains a good runheader we can update all the other runs with correct infos!
3263                //
3264                oss.str("");
3265                oss << "UPDATE GL_RUN_FRAGMENTS SET "
3266                    << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "
3267                    << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
3268                    << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , "
3269                    << " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , "
3270                    << " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , "
3271                    << " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , "
3272                    << " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , "
3273                    << " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , "
3274                    << " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , "
3275                    << " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , "
3276                    << " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , "  
3277                    << " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , "  
3278                    << " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , "  
3279                    << " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , "  
3280                    << " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , ";
3281                //
3282                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
3283                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , ";
3284                if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
3285                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , ";
3286                //        
3287                oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC();
3288                oss << " WHERE ID=" << glrun->GetID() << ";";
3289                if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str());
3290                conn->Query(oss.str().c_str());    
3291                //
3292              } else {
3293                //
3294                // sig no runheader, let set anyway what is possible...
3295                //
3296                oss.str("");
3297                oss << "UPDATE GL_RUN_FRAGMENTS SET "
3298                    << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , ";
3299                //
3300                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
3301                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , ";
3302                if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
3303                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , ";
3304                //        
3305                oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
3306                    << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT();
3307                oss << " WHERE ID=" << glrun->GetID() << ";";
3308                if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str());
3309                conn->Query(oss.str().c_str());    
3310              };
3311              //
3312              // update runheader ROOT_ID_FRAG
3313              //
3314              oss.str("");
3315              oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";";
3316              if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str());
3317              conn->Query(oss.str().c_str());
3318              //
3319              // now let's look for runtrailer if any in the last run
3320              //
3321              glA->Query_GL_RUN(IDRL2B,conn);
3322              //
3323              if ( glA->GetPKT_READY_COUNTER() != 0 ){
3324                //
3325                // the first piece contains a good runtrailer we can update all the other runs with correct infos!
3326                //
3327                oss.str("");
3328                oss << "UPDATE GL_RUN_FRAGMENTS SET "
3329                    << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
3330                    << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "
3331                    << " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , "
3332                    << " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , ";
3333                //
3334                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
3335                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
3336                if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) {
3337                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
3338                //        
3339                oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER()
3340                    << " WHERE ID=" << glrun->GetID() << ";";
3341                if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str());
3342                conn->Query(oss.str().c_str());    
3343                //
3344              } else {
3345                //
3346                // sig no runtrailer, let set anyway what is possible...
3347                //
3348                oss.str("");
3349                oss << "UPDATE GL_RUN_FRAGMENTS SET "
3350                    << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
3351                    << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , ";
3352                  //
3353                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
3354                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
3355                if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){
3356                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
3357                //        
3358                oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()
3359                    << " WHERE ID=" << glrun->GetID() << ";";
3360                if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str());
3361                conn->Query(oss.str().c_str());    
3362              };
3363              //
3364              UInt_t myi = glrun->GetID();
3365              oss.str("");
3366              oss << " ID= "<< myi;
3367              //
3368              glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);  
3369              //
3370              // fill the new run in GL_RUN
3371              //
3372              glrun->SetID_RUN_FRAG(IDRL2B);
3373              glrun->Fill_GL_RUN(conn);    
3374              glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
3375              delete glA;
3376              //
3377            } else {
3378              //
3379              // is just a repetition
3380              //
3381              if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n");        
3382              if ( PEDANTIC ) throw -70;
3383            };
3384            //
3385        } else {        } else {
3386          if ( NoFrag() ){          if ( NoFrag() ){
3387            glrun->SetID_RUN_FRAG(glrun->GetID());            glrun->SetID_RUN_FRAG(glrun->GetID());
# Line 3169  void PamelaDBOperations::HandleMissingHo Line 3418  void PamelaDBOperations::HandleMissingHo
3418        glrun->SetID(this->AssignRunID());        glrun->SetID(this->AssignRunID());
3419        glrun->SetID_RUN_FRAG(0);        glrun->SetID_RUN_FRAG(0);
3420        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...
3421      };        };
3422      //      //
3423    };    };
3424    //    //
# Line 3213  Bool_t PamelaDBOperations::IsRunConsiste Line 3462  Bool_t PamelaDBOperations::IsRunConsiste
3462    if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run!    if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run!
3463      //if ( firstev <= lastev+1 ) { // no events inside the run!      //if ( firstev <= lastev+1 ) { // no events inside the run!
3464      if ( IsDebug() ) printf(" Checking but no events in the run! \n");      if ( IsDebug() ) printf(" Checking but no events in the run! \n");
3465        firstev = lastev+1; // this is necessary for files with no Physics entries, should have no influence on other files
3466      // return true is correct      // return true is correct
3467      return(true);      return(true);
3468      //      //
# Line 3242  Bool_t PamelaDBOperations::IsRunConsiste Line 3492  Bool_t PamelaDBOperations::IsRunConsiste
3492        //        //
3493      } else {      } else {
3494        //        //
3495        if ( IsDebug() ) printf(" There are no-phyics packets inside the run!\n");        if ( IsDebug() ) printf(" There are no-physics packets inside the run!\n");
3496        //        //
3497        // HERE WE MUST HANDLE THAT RUNS AND GO BACK        // HERE WE MUST HANDLE THAT RUNS AND GO BACK
3498        //        //
# Line 3252  Bool_t PamelaDBOperations::IsRunConsiste Line 3502  Bool_t PamelaDBOperations::IsRunConsiste
3502        UInt_t check = 0;        UInt_t check = 0;
3503        UInt_t lastevtemp = lastev;        UInt_t lastevtemp = lastev;
3504        UInt_t firstevno = firstev;        UInt_t firstevno = firstev;
3505          UInt_t rhchko=0;
3506          UInt_t rhchk=0;
3507        //        //
3508        for (UInt_t i=firstev; i<=lastev; i++){        for (UInt_t i=firstev; i<=lastev; i++){
3509          //          //
# Line 3260  Bool_t PamelaDBOperations::IsRunConsiste Line 3512  Bool_t PamelaDBOperations::IsRunConsiste
3512          //          //
3513          check = 0;          check = 0;
3514          //          //
3515    
3516            // if we have a runheader set lastev then exit
3517            //
3518          for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){          for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){
3519            if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter));            if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter));
3520          };          };
3521            // check here if we have a runheader
3522            rhchko = rhchk;  
3523            rhchk = code->Get(GetPacketType("RunHeader"));    
3524          //          //
3525          if ( checkfirst < check || i == lastev ){          if ( checkfirst < check || i == lastev ){
3526            //            //
# Line 3460  Bool_t PamelaDBOperations::IsRunConsiste Line 3718  Bool_t PamelaDBOperations::IsRunConsiste
3718                  //                  //
3719                  found = false; // default value                  found = false; // default value
3720                  //                  //
3721                  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");
3722                  //                  //
3723                  // 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:
3724                  //                  //
# Line 3679  Bool_t PamelaDBOperations::IsRunConsiste Line 3937  Bool_t PamelaDBOperations::IsRunConsiste
3937            //            //
3938          };          };
3939          //          //
3940            if ( i > firstev ){
3941              if ( rhchko != rhchk ){
3942                if ( IsDebug() ) printf("oh oh... we have a runheader! stop here and handle later the remaining piece\n");
3943                lastev = i;
3944                return(false);
3945              };
3946            };
3947            //
3948          if ( check == checklast && i != lastev ){          if ( check == checklast && i != lastev ){
3949            lastevtemp = i - 1;            lastevtemp = i - 1;
3950            i = lastev - 1;            i = lastev - 1;
# Line 3970  Int_t PamelaDBOperations::insertCALO_CAL Line 4236  Int_t PamelaDBOperations::insertCALO_CAL
4236    UInt_t totime = 0;    UInt_t totime = 0;
4237    UInt_t obt = 0;    UInt_t obt = 0;
4238    UInt_t pkt = 0;    UInt_t pkt = 0;
4239      Float_t totped = 0.;
4240    //    //
4241    tr = (TTree*)file->Get("CalibCalPed");    tr = (TTree*)file->Get("CalibCalPed");
4242    if ( !tr || tr->IsZombie() ) throw -21;    if ( !tr || tr->IsZombie() ) throw -21;
# Line 3987  Int_t PamelaDBOperations::insertCALO_CAL Line 4254  Int_t PamelaDBOperations::insertCALO_CAL
4254        if ( calibCalPed->cstwerr[section] ){        if ( calibCalPed->cstwerr[section] ){
4255          valid = 1;          valid = 1;
4256          if ( calibCalPed->cperror[section] ) valid = 0;          if ( calibCalPed->cperror[section] ) valid = 0;
4257            //
4258            // 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.]
4259            //
4260            totped = 0.;
4261            for (UInt_t ss=0; ss<96; ss++){
4262              totped += calibCalPed->calped[section][0][ss];
4263            }
4264            if ( totped < 1. ){
4265              if ( IsDebug() ) printf(" Section %i totped %f -  No calibration data! Calorimeter power problems? \n",section,totped);
4266              valid = 0;
4267            };
4268            //
4269          ph = eh->GetPscuHeader();          ph = eh->GetPscuHeader();
4270          obt = ph->GetOrbitalTime();            obt = ph->GetOrbitalTime();  
4271          pkt = ph->GetCounter();            pkt = ph->GetCounter();  
# Line 4154  Int_t PamelaDBOperations::insertCALOPULS Line 4433  Int_t PamelaDBOperations::insertCALOPULS
4433    tr->SetBranchAddress("Header", &eh);    tr->SetBranchAddress("Header", &eh);
4434    nevents = tr->GetEntries();    nevents = tr->GetEntries();
4435    //    //
4436      Float_t totpul = 0.;
4437      //
4438    if ( nevents > 0 ){    if ( nevents > 0 ){
4439      //      //
4440      for (UInt_t i=0; i < nevents; i++){      for (UInt_t i=0; i < nevents; i++){
# Line 4163  Int_t PamelaDBOperations::insertCALOPULS Line 4444  Int_t PamelaDBOperations::insertCALOPULS
4444          if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){          if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){
4445            valid = 1;            valid = 1;
4446            if ( cp1->pperror[section] ) valid = 0;            if ( cp1->pperror[section] ) valid = 0;
4447              //
4448              // 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.]
4449              //
4450              totpul = 0.;
4451              for (UInt_t ss=0; ss<96; ss++){
4452                totpul += cp1->calpuls[section][0][ss];
4453              }
4454              if ( totpul >= 3145632. ){
4455                if ( IsDebug() ) printf(" PULSE1 Section %i totpul %f -  No calibration data! Calorimeter power problems? \n",section,totpul);
4456                valid = 0;
4457              };
4458              //
4459            ph = eh->GetPscuHeader();            ph = eh->GetPscuHeader();
4460            obt = ph->GetOrbitalTime();              obt = ph->GetOrbitalTime();  
4461            pkt = ph->GetCounter();              pkt = ph->GetCounter();  
# Line 4320  Int_t PamelaDBOperations::insertCALOPULS Line 4613  Int_t PamelaDBOperations::insertCALOPULS
4613          if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){          if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){
4614            valid = 1;            valid = 1;
4615            if ( cp2->pperror[section] ) valid = 0;            if ( cp2->pperror[section] ) valid = 0;
4616              //
4617              // 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.]
4618              //
4619              totpul = 0.;
4620              for (UInt_t ss=0; ss<96; ss++){
4621                totpul += cp2->calpuls[section][0][ss];
4622              }
4623              if ( totpul >= 3145632. ){
4624                if ( IsDebug() ) printf(" PULSE2 Section %i totpul %f -  No calibration data! Calorimeter power problems? \n",section,totpul);
4625                valid = 0;
4626              };
4627              //
4628            ph = eh->GetPscuHeader();            ph = eh->GetPscuHeader();
4629            obt = ph->GetOrbitalTime();              obt = ph->GetOrbitalTime();  
4630            pkt = ph->GetCounter();              pkt = ph->GetCounter();  
# Line 4685  void PamelaDBOperations::HandleTRK_CALIB Line 4990  void PamelaDBOperations::HandleTRK_CALIB
4990      if ( !result ) throw -4;;      if ( !result ) throw -4;;
4991      row = result->Next();      row = result->Next();
4992      if(row)glcal->ID = (UInt_t)atoll(row->GetField(0));      if(row)glcal->ID = (UInt_t)atoll(row->GetField(0));
4993        //
4994        delete result; // mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages]
4995      //      //
4996  };  };
4997    
# Line 5193  Int_t PamelaDBOperations::insertTRK_CALI Line 5499  Int_t PamelaDBOperations::insertTRK_CALI
5499    
5500              if(FOUND){              if(FOUND){
5501    
5502              if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <<endl;                if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <<endl;
   
                 ////////////////////////////////////////////  
                 // insert a new entry in GL_TRK_CALIB and  
                 // modify the time-tag of the previous one  
                 ////////////////////////////////////////////  
5503    
5504                  // ---------------------------------------------------------------------                ////////////////////////////////////////////
5505                  // step 1: insert a new raw file in GL_RAW                // insert a new entry in GL_TRK_CALIB and
5506                  // ---------------------------------------------------------------------                // modify the time-tag of the previous one
5507                  //                ////////////////////////////////////////////
5508                  // check if the raw file already exist  
5509                  //                // ---------------------------------------------------------------------
5510                  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                // step 1: insert a new raw file in GL_RAW
5511  //              oss.str("");                // ---------------------------------------------------------------------
5512  //              oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";";                //
5513  //              if ( IsDebug() ) cout << oss.str().c_str() << endl;                // check if the raw file already exist
5514                  //
5515                  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
5516                  //                oss.str("");
5517                  //                oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";";
5518                  //                if ( IsDebug() ) cout << oss.str().c_str() << endl;
5519                                    
5520  //              result = conn->Query(oss.str().c_str());                //                result = conn->Query(oss.str().c_str());
5521  //              if ( !result ) throw -4;;                //                if ( !result ) throw -4;;
5522  //              if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl;                //                if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl;
5523  //              if( result->GetRowCount() == 0){                //                if( result->GetRowCount() == 0){
5524  //                  if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl;                //                    if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl;
5525  //                  // - - - - - - - - - - -                //                    // - - - - - - - - - - -
5526  //                  // insert new raw file                //                    // insert new raw file
5527  //                  // - - - - - - - - - - -                //                    // - - - - - - - - - - -
5528  //                  GL_RAW glraw = GL_RAW();                    //                    GL_RAW glraw = GL_RAW();    
5529  //                  glraw.PATH        = gSystem->DirName(raw.Data());                //                    glraw.PATH        = gSystem->DirName(raw.Data());
5530  //                  glraw.NAME        = gSystem->BaseName(raw.Data());                //                    glraw.NAME        = gSystem->BaseName(raw.Data());
5531  //                  glraw.BOOT_NUMBER = boot_number;                //                    glraw.BOOT_NUMBER = boot_number;
5532  //                  //                //                    //
5533  //                  insertPamelaRawFile( &glraw );                //                    insertPamelaRawFile( &glraw );
5534  //                  //                              //                    //              
5535  //                  id_raw = glraw.ID;                              //                    id_raw = glraw.ID;              
5536  //              }else{                //                }else{
5537  //                  row = result->Next();                //                    row = result->Next();
5538  //                  id_raw = (UInt_t)atoll(row->GetField(0));                //                    id_raw = (UInt_t)atoll(row->GetField(0));
5539  //              }                //                }
5540  //              if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl;                //                if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl;
5541    
5542                  // ---------------------------------------------------------------------                // ---------------------------------------------------------------------
5543                  // step 1(bis): retrieve the timesync id associated to the file                // step 1(bis): retrieve the timesync id associated to the file
5544                  // (NB, uso lo stesso associato al file iniziale)                // (NB, uso lo stesso associato al file iniziale)
5545                  // ---------------------------------------------------------------------                // ---------------------------------------------------------------------
5546                  UInt_t idtimesync = 0;                UInt_t idtimesync = 0;
5547                  oss.str("");                oss.str("");
5548                  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;";
5549                  if ( debug ) printf(" %s \n",oss.str().c_str());                if ( debug ) printf(" %s \n",oss.str().c_str());
5550                  result = conn->Query(oss.str().c_str());                result = conn->Query(oss.str().c_str());
5551                  if ( !result ) throw -3;                if ( !result ) throw -3;
5552                  row = result->Next();                  row = result->Next();
5553                  if ( !row ) throw -3;                  if ( !row ) throw -3;
5554                  idtimesync = (UInt_t)atoll(row->GetField(0));                  idtimesync = (UInt_t)atoll(row->GetField(0));
5555                  if ( IsDebug() ) cout << "ID_TIMESYNC = "<<idtimesync<<endl;                  if ( IsDebug() ) cout << "ID_TIMESYNC = "<<idtimesync<<endl;
5556                                    
5557                    delete result;// mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages]
5558                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
5559                  // step 2: insert a new root file in GL_ROOT                  // step 2: insert a new root file in GL_ROOT
5560                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
# Line 5295  Int_t PamelaDBOperations::insertTRK_CALI Line 5602  Int_t PamelaDBOperations::insertTRK_CALI
5602                  }                  }
5603                  if ( IsDebug() ) cout << "ID_ROOT = "<<id_root<<endl;                  if ( IsDebug() ) cout << "ID_ROOT = "<<id_root<<endl;
5604    
5605                    delete result;// mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages]
5606                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
5607                  // step 3: modify time-tag of corrupted GL_TRK_CALIB entry                  // step 3: modify time-tag of corrupted GL_TRK_CALIB entry
5608                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
# Line 5307  Int_t PamelaDBOperations::insertTRK_CALI Line 5615  Int_t PamelaDBOperations::insertTRK_CALI
5615                  result = conn->Query(oss.str().c_str());                  result = conn->Query(oss.str().c_str());
5616                  if ( !result ) throw -4;;                  if ( !result ) throw -4;;
5617    
5618                    delete result; // mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages]
5619    
5620                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
5621                  // step 4: insert the new calibration:                  // step 4: insert the new calibration:
5622                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
# Line 5758  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6068  Int_t PamelaDBOperations::CleanGL_RUN_FR
6068                  oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , ";                  oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , ";
6069                //                              //              
6070                oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , "                oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , "
6071                    << " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT()<< ";";                    << " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT();
6072                  oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112
6073                conn->Query(oss.str().c_str());                  conn->Query(oss.str().c_str());  
6074              };                  };    
6075            };            };
# Line 5807  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6118  Int_t PamelaDBOperations::CleanGL_RUN_FR
6118                if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){                if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){
6119                  oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };                  oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
6120                //                              //              
6121                oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()<< ";";                oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT();
6122                  oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112
6123                conn->Query(oss.str().c_str());                  conn->Query(oss.str().c_str());  
6124              };                  };    
6125            };            };
# Line 5858  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6170  Int_t PamelaDBOperations::CleanGL_RUN_FR
6170                row2 = result2->Next();                row2 = result2->Next();
6171                //                //
6172                if ( row2 ){                if ( row2 ){
6173                  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");
6174                  if ( PEDANTIC ) throw -83;                  if ( PEDANTIC ) throw -83;
6175                  row2->Close();                  row2->Close();
6176                };                };
# Line 5935  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6247  Int_t PamelaDBOperations::CleanGL_RUN_FR
6247        glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);          glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);  
6248        //        //
6249        oss.str("");        oss.str("");
6250        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 "
6251            << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND ("            << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND ("
6252            << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "            << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "
6253            << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("            << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("
# Line 5993  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6305  Int_t PamelaDBOperations::CleanGL_RUN_FR
6305          moved++;          moved++;
6306          //          //
6307        } else {        } else {
6308          if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n");  
6309          if ( PEDANTIC ) throw -83;          // questa parte mah mah mah... da controllare
6310    
6311            //
6312            // 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
6313            // "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number.
6314            //
6315            // 090112 [8RED (-70): RUN ALREADY INSERTED]
6316            //
6317            Bool_t OK = false;
6318            UInt_t IDRL2A = 0;
6319            UInt_t IDRL2B = 0;
6320              if ( result2->GetRowCount() == 2 ){
6321                IDRL2A = (UInt_t)atoll(row2->GetField(0));
6322                UInt_t IDRL0A = (UInt_t)atoll(row2->GetField(4));
6323                row2 = result2->Next();
6324                IDRL2B = (UInt_t)atoll(row2->GetField(0));
6325                UInt_t IDRL0B = (UInt_t)atoll(row2->GetField(4));
6326                if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B);
6327                //      if ( IDRL0A == IDRL0B ){
6328    //            TSQLResult *result2a = 0;
6329    //            TSQLRow    *row2a    = 0;
6330    //            oss.str("");
6331    //            oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;";
6332    //            if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
6333    //            result2a = conn->Query(oss.str().c_str());
6334    //            //
6335    //            if ( !result2a ) throw -4;
6336    //            //
6337    //            row2a = result2a->Next();
6338    //            //
6339    //            if ( row2a ){
6340    //              UInt_t PKA = (UInt_t)atoll(row2a->GetField(0));
6341    //              delete result2a;
6342    //              oss.str("");
6343    //              oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;";
6344    //              if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
6345    //              result2a = conn->Query(oss.str().c_str());
6346    //              //
6347    //              if ( !result2a ) throw -4;
6348    //              //
6349    //              row2a = result2a->Next();
6350    //              //
6351    //              if ( row2a ){
6352    //                UInt_t PKB = (UInt_t)atoll(row2a->GetField(0));
6353    //                //
6354    //                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);
6355    //                if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){
6356    //                  if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n");
6357                        OK = true;
6358                        //            };
6359                        //          };
6360                        //        };                  
6361                        //    };
6362              };      
6363            if ( OK ){
6364              //
6365              // this is the case in which we must insert a piece of run between two fragments in the GL_RUN table
6366              //
6367              // 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 )
6368              //
6369              GL_RUN *glA = new GL_RUN();
6370              glA->Query_GL_RUN(IDRL2A,conn);
6371              //
6372              if ( glA->GetACQ_BUILD_INFO() != 0 ){
6373                //
6374                // the first piece contains a good runheader we can update all the other runs with correct infos!
6375                //
6376                oss.str("");
6377                oss << "UPDATE GL_RUN_FRAGMENTS SET "
6378                    << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "
6379                    << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
6380                    << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , "
6381                    << " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , "
6382                    << " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , "
6383                    << " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , "
6384                    << " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , "
6385                    << " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , "
6386                    << " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , "
6387                    << " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , "
6388                    << " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , "  
6389                    << " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , "  
6390                    << " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , "  
6391                    << " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , "  
6392                    << " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , ";
6393                //
6394                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
6395                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , ";
6396                if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
6397                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , ";
6398                //        
6399                oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC();
6400                oss << " WHERE ID=" << glrun->GetID() << ";";
6401                if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str());
6402                conn->Query(oss.str().c_str());    
6403                //
6404              } else {
6405                //
6406                // sig no runheader, let set anyway what is possible...
6407                //
6408                oss.str("");
6409                oss << "UPDATE GL_RUN_FRAGMENTS SET "
6410                    << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , ";
6411                //
6412                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
6413                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , ";
6414                if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
6415                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , ";
6416                //        
6417                oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
6418                    << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT();
6419                oss << " WHERE ID=" << glrun->GetID() << ";";
6420                if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str());
6421                conn->Query(oss.str().c_str());    
6422              };
6423              //
6424              // update runheader ROOT_ID_FRAG
6425              //
6426              oss.str("");
6427              oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";";
6428              if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str());
6429              conn->Query(oss.str().c_str());
6430              //
6431              // now let's look for runtrailer if any in the last run
6432              //
6433              glA->Query_GL_RUN(IDRL2B,conn);
6434              //
6435              if ( glA->GetPKT_READY_COUNTER() != 0 ){
6436                //
6437                // the first piece contains a good runtrailer we can update all the other runs with correct infos!
6438                //
6439                oss.str("");
6440                oss << "UPDATE GL_RUN_FRAGMENTS SET "
6441                    << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
6442                    << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "
6443                    << " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , "
6444                    << " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , ";
6445                //
6446                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
6447                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
6448                if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) {
6449                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
6450                //        
6451                oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER()
6452                    << " WHERE ID=" << glrun->GetID() << ";";
6453                if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str());
6454                conn->Query(oss.str().c_str());    
6455                //
6456              } else {
6457                //
6458                // sig no runtrailer, let set anyway what is possible...
6459                //
6460                oss.str("");
6461                oss << "UPDATE GL_RUN_FRAGMENTS SET "
6462                    << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
6463                    << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , ";
6464                  //
6465                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
6466                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
6467                if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){
6468                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
6469                //        
6470                oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()
6471                    << " WHERE ID=" << glrun->GetID() << ";";
6472                if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str());
6473                conn->Query(oss.str().c_str());    
6474              };
6475              //
6476              UInt_t myi = glrun->GetID();
6477              oss.str("");
6478              oss << " ID= "<< myi;
6479              //
6480              glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);  
6481              //
6482              // fill the new run in GL_RUN
6483              //
6484              glrun->SetID_RUN_FRAG(IDRL2B);
6485              glrun->Fill_GL_RUN(conn);    
6486              glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
6487              delete glA;
6488              moved++;
6489              //
6490            } else {
6491              //
6492              // is just a repetition
6493              //
6494              if ( IsDebug() ) printf(" The run %u is already present in the GL_RUN table...\n",glrun->GetID());    
6495              //      printf(" CCCCCCCCICCCCCCCCCCCCIOOOOOOOOOO si muove Ciccio! %u \n",glrun->GetID());
6496              //      if ( PEDANTIC && glrun->GetID() != 61563 ) throw -83;
6497              if ( PEDANTIC ) throw -83;
6498            };
6499            //      if ( IsDebug() ) printf(" The run already exists in the GL_RUN table! ...\n");
6500            //      if ( PEDANTIC ) throw -83;
6501        };        };
6502        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));      
6503        //        //
# Line 6060  Int_t PamelaDBOperations::ValidateRuns(T Line 6563  Int_t PamelaDBOperations::ValidateRuns(T
6563      // 2) get the OBT of the last validated run      // 2) get the OBT of the last validated run
6564      // --------------------------------------------------------------      // --------------------------------------------------------------
6565      oss.str("");      oss.str("");
6566      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
6567        oss << " SELECT * FROM GL_RUN  WHERE VALIDATION>0 AND RUNHEADER_TIME<="<< t_start
6568          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
6569      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());
6570      result = conn->Query(oss.str().c_str());      result = conn->Query(oss.str().c_str());
# Line 6203  Int_t PamelaDBOperations::ValidateRuns(T Line 6707  Int_t PamelaDBOperations::ValidateRuns(T
6707          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
6708                                                        
6709          if( !CHECK && this_run->VALIDATION ){          if( !CHECK && this_run->VALIDATION ){
6710            for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);            //      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
6711              for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],this_run->VALIDATION);
6712            nseq=0;            nseq=0;
6713          }          }
6714                                        
# Line 6224  Int_t PamelaDBOperations::ValidateRuns(T Line 6729  Int_t PamelaDBOperations::ValidateRuns(T
6729      if( CHECK ){      if( CHECK ){
6730        // check if calibration exists        // check if calibration exists
6731        if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval);        if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval);
6732        Bool_t MISSING = MissingTRK_CALIB(t1,t2);        //      Bool_t MISSING = MissingTRK_CALIB(t1,t2);
6733        for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);        UInt_t MISSING = MissingTRK_CALIB(t1,t2);
6734          UInt_t val = 0;
6735          if ( MISSING == 1 ) val = 0;
6736          if ( MISSING == 0 ) val = 1;
6737          if ( MISSING == 2 ) val = 2;
6738          for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],val);
6739        nseq=0;        nseq=0;
6740      };      };
6741      //--------------      //--------------
# Line 6255  Int_t PamelaDBOperations::ValidateRuns(T Line 6765  Int_t PamelaDBOperations::ValidateRuns(T
6765   * @param t2 To absolute time   * @param t2 To absolute time
6766   * @return true if there might be a missing calibration   * @return true if there might be a missing calibration
6767   */   */
6768  Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){  //Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){
6769    UInt_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){
6770                    
6771    GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB();    GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB();
6772                    
6773    // get the closest calibration before the run start (t2)    // get the closest calibration before the run start (t2)
6774    if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true);    //>>> missing    //  if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true);        //>>> missing
6775      if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(1);       //>>> missing
6776                    
6777    if ( trkcalib->TO_TIME  < t2 ) return(true);                                  //>>> missing    //  if ( trkcalib->TO_TIME  < t2 ) return(true);                                      //>>> missing
6778      if ( trkcalib->TO_TIME  < t2 ) return(1);                                     //>>> missing
6779                    
6780    //==============================================================    //==============================================================
6781    // Check is done first on the basis of time between calibration,    // Check is done first on the basis of time between calibration,
# Line 6279  Bool_t PamelaDBOperations::MissingTRK_CA Line 6792  Bool_t PamelaDBOperations::MissingTRK_CA
6792      //==============================================================      //==============================================================
6793      Bool_t DOWNLOAD = false;      Bool_t DOWNLOAD = false;
6794      // check if the calib was skipped becouse of download .... DA FARE!!      // check if the calib was skipped becouse of download .... DA FARE!!
6795      if(DOWNLOAD)return(false);      //    if(DOWNLOAD)return(false);
6796        if(DOWNLOAD)return(0);
6797                                    
6798      return(true);                                       //>>> missing      //    return(true);                                         //>>> missing
6799        return(1);                                  //>>> missing
6800                                    
6801    };    };
6802                    
# Line 6291  Bool_t PamelaDBOperations::MissingTRK_CA Line 6806  Bool_t PamelaDBOperations::MissingTRK_CA
6806    //==============================================================    //==============================================================
6807    // the long time interval bewteen runs might be due to download    // the long time interval bewteen runs might be due to download
6808    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);
6809    return(false);    if ( trkcalib->VALIDATION ) return(0);
6810      if ( IsDebug() )printf("Calibration is not validated... :-/ ==> OK but with VALIDATION=2! \n");
6811      return(2);
6812                    
6813  };  };
6814  /**  /**
# Line 6300  Bool_t PamelaDBOperations::MissingTRK_CA Line 6817  Bool_t PamelaDBOperations::MissingTRK_CA
6817   * @param validation true/false   * @param validation true/false
6818   */   */
6819  Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){  Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){
6820      return(this->assignVALIDATION(idrun,(UInt_t)validation));
6821    }
6822    
6823    Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, UInt_t validation){
6824    TSQLResult *result = 0;    TSQLResult *result = 0;
6825    stringstream oss;    stringstream oss;
6826    oss.str("");    oss.str("");
# Line 6496  Int_t PamelaDBOperations::removeFile(TSt Line 7017  Int_t PamelaDBOperations::removeFile(TSt
7017    stringstream myquery;    stringstream myquery;
7018    //      //  
7019    myquery.str("");    myquery.str("");
7020    myquery << " SELECT ID, ID_RAW FROM GL_ROOT where NAME='"<<remfile.Data() <<"';";    myquery << " SELECT ID,ID_RAW,ID_TIMESYNC FROM GL_ROOT where NAME='"<<remfile.Data() <<"';";
7021    //    //
7022    pResult = conn->Query(myquery.str().c_str());    pResult = conn->Query(myquery.str().c_str());
7023    //    //
# Line 6512  Int_t PamelaDBOperations::removeFile(TSt Line 7033  Int_t PamelaDBOperations::removeFile(TSt
7033    //    //
7034    this->SetID_ROOT((UInt_t)atoll(Row->GetField(0)));    this->SetID_ROOT((UInt_t)atoll(Row->GetField(0)));
7035    this->SetID_RAW((UInt_t)atoll(Row->GetField(1)));    this->SetID_RAW((UInt_t)atoll(Row->GetField(1)));
7036      UInt_t idtsy=(UInt_t)atoll(Row->GetField(2));
7037    //    //
7038    this->ValidationOFF();    this->ValidationOFF();
7039    //    //
# Line 6519  Int_t PamelaDBOperations::removeFile(TSt Line 7041  Int_t PamelaDBOperations::removeFile(TSt
7041    //    //
7042    this->RemoveRUNS();    this->RemoveRUNS();
7043    //    //
7044    this->RemoveFILES();    this->RemoveFILES(idtsy);
7045    //    //
7046    this->SetID_ROOT(0);    this->SetID_ROOT(0);
7047    this->SetID_RAW(0);    this->SetID_RAW(0);
# Line 6739  void PamelaDBOperations::RemoveRUNS(){ Line 7261  void PamelaDBOperations::RemoveRUNS(){
7261   * Rearrange calibration tables   * Rearrange calibration tables
7262   *   *
7263   **/   **/
7264  void PamelaDBOperations::RemoveFILES(){  void PamelaDBOperations::RemoveFILES(UInt_t idtsy){
7265    stringstream myquery;    stringstream myquery;
7266    //    //
7267    myquery.str("");    myquery.str("");
# Line 6749  void PamelaDBOperations::RemoveFILES(){ Line 7271  void PamelaDBOperations::RemoveFILES(){
7271    //    //
7272    conn->Query(myquery.str().c_str());    conn->Query(myquery.str().c_str());
7273    //    //
7274      myquery.str("");
7275      myquery << " DELETE FROM GL_ROOT WHERE ID=" <<this->GetID_ROOT() <<";";
7276      //
7277      if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
7278      //
7279      conn->Query(myquery.str().c_str());  //
7280      //
7281      if ( !chewbacca ){
7282        myquery.str("");
7283        myquery << " DELETE FROM GL_TIMESYNC WHERE ID=" << idtsy <<";";
7284        //
7285        if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
7286        //
7287        conn->Query(myquery.str().c_str());
7288      };
7289      //
7290  };  };
7291    
7292  /**  /**

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.26

  ViewVC Help
Powered by ViewVC 1.1.23