/[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.4 by pam-fi, Fri Oct 31 11:21:44 2008 UTC revision 1.29 by mocchiut, Wed Dec 23 07:19:32 2009 UTC
# Line 58  string getTleDatetime(cTle*); Line 58  string getTleDatetime(cTle*);
58   * @param debug        debug flag.   * @param debug        debug flag.
59   * @param tlefilename  ascii file with TLE 3 line elements.   * @param tlefilename  ascii file with TLE 3 line elements.
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){  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 76  PamelaDBOperations::PamelaDBOperations(T Line 77  PamelaDBOperations::PamelaDBOperations(T
77      //      //
78    };    };
79    //    //
80      KEEPENV = false;
81      if ( keepenv ) KEEPENV=true;
82    STATIC=false;    STATIC=false;
83    if ( staticp ) STATIC=true;    if ( staticp ) STATIC=true;
84    //    //
# Line 99  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 132  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 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 149  void PamelaDBOperations::OpenL0File(TStr Line 155  void PamelaDBOperations::OpenL0File(TStr
155            chpktmax = (UInt_t)atoll(row->GetField(2));            chpktmax = (UInt_t)atoll(row->GetField(2));
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));
159              chrtinit = (UInt_t)atoll(row->GetField(6));
160          } else {          } else {
161            throw -84;            throw -84;
162          };          };
# Line 157  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 ){
172          row2 = result2->Next();          row2 = result2->Next();
173          if ( row2 ){          if ( row2 ){
174            chpath = (TString)gSystem->ExpandPathName(row2->GetField(0))+'/';            if ( KEEPENV ){
175                chpath = (TString)(row2->GetField(0))+'/';
176              } else {
177                chpath = (TString)gSystem->ExpandPathName(row2->GetField(0))+'/';
178              };
179            chfile = (TString)(row2->GetField(1));            chfile = (TString)(row2->GetField(1));
180            chobtts = (UInt_t)atoll(row2->GetField(2));            chobtts = (UInt_t)atoll(row2->GetField(2));
181            chlastts = (UInt_t)atoll(row2->GetField(3));            chlastts = (UInt_t)atoll(row2->GetField(3));
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                if ( debug ) printf(" mmm... no BOOT number determined by chewbacca, try to find it looking at DB \n");
187                //
188                // new feature: check in ROOT_TABLE (timewise) the previous and the next BOOT number != 0 , if it is the same we know this one!
189                // if it is different roll back to the old behaviour
190                //
191                qu.str("");
192                qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND REAL_TIME_INIT>"<< row2->GetField(10) <<" order by REAL_TIME_INIT asc limit 1;";
193                if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());
194                UInt_t chbootA = 0;
195                UInt_t chbootB = 1;
196                result3 = conn->Query(qu.str().c_str());
197                if ( result3 ){
198                  row3 = result3->Next();
199                  if ( row3 ){
200                    chbootA = (UInt_t)atoll(row3->GetField(0));
201                    if ( debug ) printf(" Found boot_number A = %u \n",chbootA);
202                  };
203                };
204                delete result3;
205                qu.str("");
206                qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND REAL_TIME_INIT<"<< row2->GetField(10) <<" order by REAL_TIME_INIT desc limit 1;";
207                if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());
208                result3 = conn->Query(qu.str().c_str());
209                if ( result3 ){
210                  row3 = result3->Next();
211                  if ( row3 ){
212                    chbootB = (UInt_t)atoll(row3->GetField(0));
213                    if ( debug ) printf(" Found boot_number B = %u \n",chbootB);
214                  };
215                };
216                if ( chbootA == chbootB ){
217                  chboot = chbootA;
218                  if ( debug ) printf(" Found boot_number! it is %u \n",chboot);
219                } else {        
220                  qu.str("");
221                  //            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;";
222                  //            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]
223                  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]
224                  if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());
225                  result3 = conn->Query(qu.str().c_str());
226                  if ( result3 ){
227                    row3 = result3->Next();
228                    if ( row3 && result3->GetRowCount() == 1 ){
229                      chboot = (UInt_t)atoll(row3->GetField(0));
230                      if ( debug ) printf(" Found boot_number = %u \n",chboot);
231                    } else {
232                      if ( debug ) printf(" AGH CANNOT DETERMINE THE BOOT NUMBER... \n");
233                      throw -29;
234                    };
235                  };
236                };
237              };
238              //
239            chpktinit = (UInt_t)atoll(row2->GetField(6));            chpktinit = (UInt_t)atoll(row2->GetField(6));
240            chpktfinal = (UInt_t)atoll(row2->GetField(7));            chpktfinal = (UInt_t)atoll(row2->GetField(7));
241            chobtinit = (UInt_t)atoll(row2->GetField(8));            chobtinit = (UInt_t)atoll(row2->GetField(8));
# Line 182  void PamelaDBOperations::OpenL0File(TStr Line 248  void PamelaDBOperations::OpenL0File(TStr
248          throw -85;          throw -85;
249        };        };
250        filerootname = chpath + chfile;// + ".root";        filerootname = chpath + chfile;// + ".root";
       if ( debug ) printf(" chewbacca: filename is %s \n",filerootname.Data());  
251      };      };
252      this->SetRootName(filerootname);      this->SetRootName(filerootname);
     file = TFile::Open(this->GetRootName().Data());  
   } else {  
     this->SetRootName("");  
253    };    };
254      if ( debug ) printf(" Filename is %s \n",filerootname.Data());
255      file = TFile::Open(this->GetRootName().Data());
256      //  } else {
257      //    this->SetRootName("");
258      //    this->SetRootName(filerootname);
259      //  };
260  }  }
261    
262  //  //
# Line 388  void PamelaDBOperations::SetOrbitNo(UInt Line 456  void PamelaDBOperations::SetOrbitNo(UInt
456      return;      return;
457    };    };
458    //    //
459    TString name = this->GetRootFile();    if ( !chewbacca ){
460    Int_t nlength = name.Length();      TString name = this->GetRootFile();
461    if ( nlength < 5 ) return;      Int_t nlength = name.Length();
462    TString dwo = 0;      if ( nlength < 5 ){
463    for (Int_t i = 0; i<5; i++){        if ( IsDebug() ) printf(" Agh problems determining the orbit number! name = %s \n",name.Data());
464      dwo.Append(name[i],1);        return;
465    };      };
466    if ( dwo.IsDigit() ){      TString dwo = "";
467      dworbit = (UInt_t)dwo.Atoi();      for (Int_t i = 0; i<5; i++){
   } else {  
     dwo="";  
     for (Int_t i = 8; i<13; i++){  
468        dwo.Append(name[i],1);        dwo.Append(name[i],1);
469      };          };
470      if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi();      if ( dwo.IsDigit() ){
471          dworbit = (UInt_t)dwo.Atoi();
472        } else {
473          dwo="";
474          for (Int_t i = 8; i<13; i++){
475            dwo.Append(name[i],1);
476          };    
477          if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi();
478        };
479        if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data());
480    };    };
   if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data());  
481    return;    return;
482  };  };
483    
# Line 435  TString PamelaDBOperations::GetRawPath() Line 508  TString PamelaDBOperations::GetRawPath()
508    
509  TString PamelaDBOperations::GetRootPath(){  TString PamelaDBOperations::GetRootPath(){
510    if ( STATIC ){    if ( STATIC ){
511      return((TString)gSystem->DirName(filerootname.Data())+'/');      return((TString)gSystem->DirName(this->GetRootName().Data())+'/');
512    } else {    } else {    
513      return((TString)gSystem->ExpandPathName("$PAM_L0")+'/');      if ( KEEPENV ){
514          return((TString)gSystem->ExpandPathName(gSystem->DirName(filerootname.Data()))+'/');
515        } else {
516          return((TString)gSystem->ExpandPathName("$PAM_L0")+'/');
517        };
518    };    };
519  };  };
520    
# Line 649  Int_t PamelaDBOperations::SetUpperLimits Line 726  Int_t PamelaDBOperations::SetUpperLimits
726      UInt_t tjump = 50000;      UInt_t tjump = 50000;
727      //UInt_t tjump = 100;      //UInt_t tjump = 100;
728      while ( tjump > 0 ){      while ( tjump > 0 ){
729        pktlast = numeric_limits<UInt_t>::max();        //      pktlast = numeric_limits<UInt_t>::max();
730        while ( pktlast > chpktmax && (Int_t)(nevent-1-it) >= 0 ){        pktlast = chpktmax + 1;
731          while ( PKT(pktlast) > PKT(chpktmax) && (Int_t)(nevent-1-it) >= 0 ){
732          if ( (Int_t)(nevent-1-it) >= 0 ){          if ( (Int_t)(nevent-1-it) >= 0 ){
733            T->GetEntry(nevent-1-it);            T->GetEntry(nevent-1-it);
734            ph = eh->GetPscuHeader();            ph = eh->GetPscuHeader();
# Line 658  Int_t PamelaDBOperations::SetUpperLimits Line 736  Int_t PamelaDBOperations::SetUpperLimits
736          } else {          } else {
737            pktlast = chpktmax + 1;            pktlast = chpktmax + 1;
738          };          };
739          if ( (!(it%1000) || abs((int)pktlast - (int)chpktmax)<1000 ) && debug ) printf(" look for up %i %i %i nevent %u (nevent-1-it) %i \n",it,pktlast,chpktmax,nevent,(Int_t)(nevent-1-it));          if ( (!(it%1000) || abs((int)(PKT(pktlast) - PKT(chpktmax)))<1000 ) && debug ) printf(" look for up %i %i %i nevent %u (nevent-1-it) %i \n",it,pktlast,chpktmax,nevent,(Int_t)(nevent-1-it));
740          it += tjump;          it += tjump;
741        };        };
742        if ( tjump > 1 ) it -= 2*tjump;        if ( tjump > 1 ) it -= 2*tjump;
# Line 682  Int_t PamelaDBOperations::SetUpperLimits Line 760  Int_t PamelaDBOperations::SetUpperLimits
760      tjump = 50000;      tjump = 50000;
761      //tjump = 100;      //tjump = 100;
762      while ( tjump > 0 ){      while ( tjump > 0 ){
763        pktlast = 0;        //      pktlast = 0;
764        while ( pktlast < chpktmin && it < (Int_t)nevent ){        pktlast = chpktmin - 1;
765          if ( debug ) printf("LLlook for down %i %i %llu %llu \n",it,pktlast,PKT(pktlast),PKT(chpktmin));
766          while ( PKT(pktlast) < PKT(chpktmin) && it < (Int_t)nevent ){
767          if ( it < (Int_t)nevent ){          if ( it < (Int_t)nevent ){
768            T->GetEntry(it);            T->GetEntry(it);
769            ph = eh->GetPscuHeader();            ph = eh->GetPscuHeader();
# Line 777  Int_t PamelaDBOperations::SetUpperLimits Line 857  Int_t PamelaDBOperations::SetUpperLimits
857      ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();
858      pktlast = ph->GetCounter();      pktlast = ph->GetCounter();
859      nevent = upperentry - chminentry;      nevent = upperentry - chminentry;
860        if ( ((Int_t)upperentry - (Int_t)chminentry) < 0 ) nevent = 0; // nevent is UInt_t! 090112 [8RED: error -88]
861        if ( IsDebug() ) printf(" Setting nevent to %u - upperentry %i chminentry %i \n",nevent,upperentry,chminentry);
862      //      //
863    } else {    } else {
864      upperpkt = PKT(pktlast);      upperpkt = PKT(pktlast);
# Line 785  Int_t PamelaDBOperations::SetUpperLimits Line 867  Int_t PamelaDBOperations::SetUpperLimits
867    };    };
868    //    //
869    if ( chewbacca && nevent < 1 ) {    if ( chewbacca && nevent < 1 ) {
870        if ( IsDebug() ) printf(" chewbacca and no events in the file \n");
871      pktfirst = chpktmin;      pktfirst = chpktmin;
872      upperpkt = PKT(chpktmax);      upperpkt = PKT(chpktmax);
873      pktlast = chpktmax;      pktlast = chpktmax;
# Line 810  Int_t PamelaDBOperations::SetUpperLimits Line 893  Int_t PamelaDBOperations::SetUpperLimits
893    //  if ( nevent < jump ) jump = int(nevent/10);    //  if ( nevent < jump ) jump = int(nevent/10);
894    //  if ( !jump ) jump = 1;    //  if ( !jump ) jump = 1;
895    //    //
896    if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) && nevent > deltapkt ){  
897      if ( ((PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt)) && nevent > deltapkt ){
898      //      //
899      if ( IsDebug() ) printf(" starting jump %i \n",jump);      if ( IsDebug() ) printf(" starting jump %i \n",jump);
900      //    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 1125  UInt_t PamelaDBOperations::AssignRunID() Line 1209  UInt_t PamelaDBOperations::AssignRunID()
1209    stringstream   oss;    stringstream   oss;
1210    //      //  
1211    oss.str("");    oss.str("");
1212    oss << "INSERT INTO _RUNID_GEN VALUES (NULL);";    if ( chewbacca ){// if chewbacca and tag=none then use chewbacca tag (chiby = chewbacca inserted by), if chewbacca and tag!=none then use tag, if not chewbacca use tag.
1213        if ( !strcmp(tag.Data(),"NONE") ){
1214          oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< chiby.Data() <<"');";
1215        } else {
1216          oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');";
1217        };
1218      } else {
1219        oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');";
1220      };
1221    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
1222    if ( !result ) throw -10;    if ( !result ) throw -10;
1223    oss.str("");    oss.str("");
# Line 1330  Long64_t PamelaDBOperations::OBT(UInt_t Line 1422  Long64_t PamelaDBOperations::OBT(UInt_t
1422    //    //
1423    //  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));
1424    //    //
1425    if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){    if ( obt < ((Long64_t)pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){
1426      //    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());
1427      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());
1428    };    };
# Line 1449  void PamelaDBOperations::FillClass(Bool_ Line 1541  void PamelaDBOperations::FillClass(Bool_
1541      glrun->SetRUNTRAILER_PKT(lastPkt);      glrun->SetRUNTRAILER_PKT(lastPkt);
1542      //          //    
1543    };    };
1544      //
1545      // ad hoc solution for INF EV_TO [8RED] 090113
1546      //
1547      if ( !firstev && lastev == -1 ){
1548        if ( IsDebug() ) printf(" EE firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1);
1549        firstev = 1;
1550        lastev = 0;
1551      };
1552    glrun->SetEV_FROM((UInt_t)firstev);    glrun->SetEV_FROM((UInt_t)firstev);
1553    glrun->SetEV_TO((UInt_t)lastev);    glrun->SetEV_TO((UInt_t)lastev);
1554    glrun->SetNEVENTS((UInt_t)lastev-(UInt_t)firstev+1);    glrun->SetNEVENTS((UInt_t)lastev-(UInt_t)firstev+1);
# Line 1464  void PamelaDBOperations::FillClass(Bool_ Line 1564  void PamelaDBOperations::FillClass(Bool_
1564  // PUBLIC FUNCTIONS  // PUBLIC FUNCTIONS
1565  //  //
1566    
 // /**  
 //  * Insert a new row into GL_RAW table.  
 //  */  
 // Int_t PamelaDBOperations::insertPamelaRawFile(){  
 //   //  
 //   stringstream oss;  
 //   //  
 //   Bool_t idr =  this->SetID_RAW();  
 //   if ( idr ) return(1);  
 //   //  
 //   oss.str("");  
 //   if ( STATIC ){  
 //     oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('"  
 //      << this->GetRawPath().Data() << "', '" << this->GetRawFile().Data() << "')";  
 //   } else {  
 //     oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << this->GetRawFile().Data() << "')";  
 //   };  
 //   if ( conn->Query(oss.str().c_str()) == 0 ) throw -4;  
 //   //  
 //   idr =  this->SetID_RAW();  
 //   if ( !idr ) throw -11;  
 //   //  
 //   return(0);  
 // }  
1567  /**  /**
1568   * Insert a new row into GL_RAW table.   * Insert a new row into GL_RAW table.
1569   */   */
# Line 1501  Int_t PamelaDBOperations::insertPamelaRa Line 1577  Int_t PamelaDBOperations::insertPamelaRa
1577            
1578      glraw.PATH = GetRawPath();      glraw.PATH = GetRawPath();
1579      glraw.NAME = GetRawFile();      glraw.NAME = GetRawFile();
1580      glraw.BOOT_NUMBER = 0;//???      //    glraw.BOOT_NUMBER = 0;//???
1581        glraw.BOOT_NUMBER = this->GetBOOTnumber();
1582            
1583      if( insertPamelaRawFile(&glraw) )return(1);      if( insertPamelaRawFile(&glraw) )return(1);
1584      //      //
# Line 1515  Int_t PamelaDBOperations::insertPamelaRa Line 1592  Int_t PamelaDBOperations::insertPamelaRa
1592   */   */
1593  Int_t PamelaDBOperations::insertPamelaRawFile(GL_RAW *glraw){  Int_t PamelaDBOperations::insertPamelaRawFile(GL_RAW *glraw){
1594    //    //
1595      if(!glraw)return(1);//??      if(!glraw)return(1);//?? ok I think
1596      //      //
1597      stringstream oss;      stringstream oss;
1598      //      //
# Line 1578  Int_t PamelaDBOperations::insertPamelaGL Line 1655  Int_t PamelaDBOperations::insertPamelaGL
1655      result = conn->Query(oss.str().c_str());      result = conn->Query(oss.str().c_str());
1656      if ( !result ) throw -10;      if ( !result ) throw -10;
1657      row = result->Next();      row = result->Next();
1658        if ( !row ) throw -92;
1659      idresof = (UInt_t)atoll(row->GetField(0));      idresof = (UInt_t)atoll(row->GetField(0));
1660      existsts = true;      existsts = true;
1661      goto eout;      goto eout;
# Line 1599  Int_t PamelaDBOperations::insertPamelaGL Line 1677  Int_t PamelaDBOperations::insertPamelaGL
1677      if ( !row ){      if ( !row ){
1678        oss.str("");        oss.str("");
1679        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< "
1680            << dworbit << " order by FROM_ORBIT desc limit 1;";            << dworbit << " AND SPECIAL_FILE='' order by FROM_ORBIT desc limit 1;";
1681        if ( IsDebug() ) printf(" %s \n",oss.str().c_str());        if ( IsDebug() ) printf(" %s \n",oss.str().c_str());
1682        result = conn->Query(oss.str().c_str());        result = conn->Query(oss.str().c_str());
1683        if ( !result ) throw -10;        if ( !result ) throw -10;
# Line 1852  Int_t PamelaDBOperations::insertPamelaGL Line 1930  Int_t PamelaDBOperations::insertPamelaGL
1930    return(signal);    return(signal);
1931  }  }
1932    
 // /**  
 //  * Insert all the new rows into GL_ROOT.  
 //  * The raw file indicates in the parameters should be already been stored in the database.  
 //  */  
 // Int_t PamelaDBOperations::insertPamelaRootFile(){  
 //   stringstream oss;  
 //   TSQLResult *result = 0;  
 //   TSQLRow    *row    = 0;  
 //   UInt_t idtimesync = 0;  
 //   //  
 //   //  
 //   if ( chewbacca ){  
 //     oss.str("");  
 //     oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;";  
 //     if ( debug ) printf(" query is %s \n",oss.str().c_str());  
 //     result = conn->Query(oss.str().c_str());  
 //     //  
 //     if ( !result ) throw -3;  
 //     //  
 //     row = result->Next();  
 //     //  
 //     if ( !row ) throw -3;  
 //     idtimesync = (UInt_t)atoll(row->GetField(0));  
 //   } else {  
 //     oss.str("");  
 //     if ( STATIC ){  
 //       oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW "  
 //        << " LEFT JOIN GL_ROOT "  
 //        << " ON GL_RAW.ID = GL_ROOT.ID_RAW "  
 //        << " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND "  
 //        << " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID ";  
 //     } else {  
 //       oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW "  
 //        << " LEFT JOIN GL_ROOT "  
 //        << " ON GL_RAW.ID = GL_ROOT.ID_RAW "  
 //        << " WHERE GL_RAW.PATH = '$PAM_RAW' AND "  
 //        << " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID ";  
 //     };  
 //     result = conn->Query(oss.str().c_str());  
 //     //  
 //     if ( !result ) throw -12;  
 //     //  
 //     row = result->Next();  
 //     //  
 //     if ( !row ) throw -10;  
 //     if ( row != NULL && (UInt_t)atoll(row->GetField(0))>0 ){  
 //       idroot = (UInt_t)atoll(row->GetField(2));  
 //       return(1);  
 //     };  
 //     //  
 //     // determine which timesync has to be used  
 //     //  
 //     oss.str("");  
 //     oss << "SELECT GL_TIMESYNC.ID FROM GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW ORDER BY GL_TIMESYNC.ID DESC LIMIT 1;";  
 //     result = conn->Query(oss.str().c_str());  
 //     //  
 //     if ( !result ) throw -3;  
 //     //  
 //     row = result->Next();  
 //     //  
 //     if ( !row ) throw -3;  
 //     idtimesync = (UInt_t)atoll(row->GetField(0));  
 //   };  
 //   //  
 //   oss.str("");  
 //   if ( STATIC ){  
 //     oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('"  
 //      << this->GetID_RAW() << "', '" << idtimesync << "', '" << this->GetRootPath().Data() << "', '" << this->GetRootFile().Data() << "')";  
 //   } else {  
 //     oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('"  
 //      << this->GetID_RAW() << "', '" << idtimesync << "', '$PAM_L0', '" << this->GetRootFile().Data() << "')";  
 //   };  
 //   //  
 //   if ( debug ) printf(" query is %s \n",oss.str().c_str());  
 //   if (conn->Query(oss.str().c_str()) == 0) throw -4;  
 //   //  
 //   delete result;  
 //   //  
 //   oss.str("");  
 //   //  oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";";  
 //   if ( STATIC ){  
 //     oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << this->GetRootPath().Data() << "' and NAME='"<< this->GetRootFile().Data() <<"';";  
 //   } else {  
 //     oss << "SELECT ID FROM GL_ROOT WHERE PATH='$PAM_L0' and NAME='"<< this->GetRootFile().Data() <<"';";  
 //   };  
 //   //  
 //   if ( debug ) printf(" query is %s \n",oss.str().c_str());  
 //   result = conn->Query(oss.str().c_str());  
 //   if ( !result ) throw -12;  
 //   row = result->Next();  
 //   if ( !row ) throw -3;  
 //   this->SetID_ROOT((UInt_t)atoll(row->GetField(0)));  
 //   if ( debug ) printf(" The ID of the ROOT file is %u \n",this->GetID_ROOT());  
 //   //  
 //   delete result;  
 //   //  
 //   return(0);  
 // }  
1933  /**  /**
1934   * Insert all the new rows into GL_ROOT.   * Insert all the new rows into GL_ROOT.
1935   * The raw file indicates in the parameters should be already been stored in the database.   * The raw file indicates in the parameters should be already been stored in the database.
# Line 1959  Int_t PamelaDBOperations::insertPamelaRo Line 1939  Int_t PamelaDBOperations::insertPamelaRo
1939      stringstream oss;      stringstream oss;
1940      TSQLResult *result = 0;      TSQLResult *result = 0;
1941      TSQLRow    *row    = 0;      TSQLRow    *row    = 0;
1942    //      //
1943      // ----------------------      // ----------------------
1944      // determine the timesync      // determine the timesync
1945      // ----------------------      // ----------------------
# Line 2031  Int_t PamelaDBOperations::insertPamelaRo Line 2011  Int_t PamelaDBOperations::insertPamelaRo
2011            
2012      glroot.ID_RAW = GetID_RAW();      glroot.ID_RAW = GetID_RAW();
2013      glroot.ID_TIMESYNC = idtimesync;      glroot.ID_TIMESYNC = idtimesync;
2014      glroot.PATH = GetRootPath();      if ( STATIC ){
2015          glroot.PATH = GetRootPath();
2016        } else {
2017          if ( KEEPENV ){
2018            glroot.PATH = gSystem->DirName(filerootname.Data());
2019          } else {
2020            glroot.PATH = "$PAM_L0";
2021          };
2022        };
2023      glroot.NAME = GetRootFile();      glroot.NAME = GetRootFile();
2024    
2025      if ( insertPamelaRootFile(&glroot) )return 1;      if ( insertPamelaRootFile(&glroot) )return 1;
# Line 2046  Int_t PamelaDBOperations::insertPamelaRo Line 2034  Int_t PamelaDBOperations::insertPamelaRo
2034   * The raw file indicates in the parameters should be already been stored in the database.   * The raw file indicates in the parameters should be already been stored in the database.
2035   */   */
2036  Int_t PamelaDBOperations::insertPamelaRootFile(GL_ROOT *glroot){  Int_t PamelaDBOperations::insertPamelaRootFile(GL_ROOT *glroot){
   
   
   
2037    stringstream oss;    stringstream oss;
2038    TSQLResult *result = 0;    TSQLResult *result = 0;
2039    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
2040    //    //
2041    //    //
2042    oss.str("");    oss.str("");
2043    if ( STATIC ){    oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('"
2044      oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('"        << glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '" << glroot->PATH << "', '" << glroot->NAME << "')";
         << glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '" << glroot->PATH << "', '" << glroot->NAME << "')";  
   } else {  
     oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('"  
         << glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '$PAM_L0', '" << glroot->NAME << "')";  
   };  
2045    //    //
2046    if ( debug ) printf("%s \n",oss.str().c_str());    if ( debug ) printf("%s \n",oss.str().c_str());
2047    if (conn->Query(oss.str().c_str()) == 0) throw -4;    if (conn->Query(oss.str().c_str()) == 0) throw -4;
# Line 2070  Int_t PamelaDBOperations::insertPamelaRo Line 2050  Int_t PamelaDBOperations::insertPamelaRo
2050    //    //
2051    oss.str("");    oss.str("");
2052    //  oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";";    //  oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";";
2053    if ( STATIC ){    oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << glroot->PATH << "' and NAME='"<< glroot->NAME <<"';";
     oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << glroot->PATH << "' and NAME='"<< glroot->NAME <<"';";  
   } else {  
     oss << "SELECT ID FROM GL_ROOT WHERE PATH='$PAM_L0' and NAME='"<< glroot->NAME <<"';";  
   };  
2054    //    //
2055    if ( debug ) printf("%s \n",oss.str().c_str());    if ( debug ) printf("%s \n",oss.str().c_str());
2056    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
# Line 2342  Int_t PamelaDBOperations::insertPamelaRU Line 2318  Int_t PamelaDBOperations::insertPamelaRU
2318          ptht = cod->Get(pctp->RunHeader) - 1;          ptht = cod->Get(pctp->RunHeader) - 1;
2319          //      evbeft = cod->Get(pctp->Physics);          //      evbeft = cod->Get(pctp->Physics);
2320          tcod = (UInt_t)cod->Get(pctp->Physics);          tcod = (UInt_t)cod->Get(pctp->Physics);
2321          if ( !tcod ) tcod = 1;          if ( !tcod ) tcod = 1;    // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT
2322          evbeft = TMath::Min(upperentry,(tcod-1));          evbeft = TMath::Min(upperentry,(tcod-1));
2323          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));
2324          //          //
# Line 2381  Int_t PamelaDBOperations::insertPamelaRU Line 2357  Int_t PamelaDBOperations::insertPamelaRU
2357            obth = phh->GetOrbitalTime();            obth = phh->GetOrbitalTime();
2358            cod = ehh->GetCounter();            cod = ehh->GetCounter();
2359            tcod = (UInt_t)cod->Get(pctp->Physics);            tcod = (UInt_t)cod->Get(pctp->Physics);
2360            if ( !tcod ) tcod = 1;            if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT
2361            evbefh = TMath::Max(chminentry,(tcod-1));            evbefh = TMath::Max(chminentry,(tcod-1));
2362            //            //
2363            if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){            if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){
# Line 2420  Int_t PamelaDBOperations::insertPamelaRU Line 2396  Int_t PamelaDBOperations::insertPamelaRU
2396                //                //
2397                this->HandleRunFragments(true,true,chminentry,(evbefh));                this->HandleRunFragments(true,true,chminentry,(evbefh));
2398                //                //
2399                  // what about pth=ptht-1
2400              };              };
2401            };            };
2402            //            //
# Line 2442  Int_t PamelaDBOperations::insertPamelaRU Line 2419  Int_t PamelaDBOperations::insertPamelaRU
2419                cod = ehh->GetCounter();                cod = ehh->GetCounter();
2420                //            evbeft = cod->Get(pctp->Physics);                //            evbeft = cod->Get(pctp->Physics);
2421                tcod = (UInt_t)cod->Get(pctp->Physics);                tcod = (UInt_t)cod->Get(pctp->Physics);
2422                if ( !tcod ) tcod = 1;                if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT
2423                evbeft = TMath::Min(upperentry,(tcod-1));                evbeft = TMath::Min(upperentry,(tcod-1));
2424                rh->GetEntry(pth);                rh->GetEntry(pth);
2425                phh = ehh->GetPscuHeader();                phh = ehh->GetPscuHeader();
# Line 2482  Int_t PamelaDBOperations::insertPamelaRU Line 2459  Int_t PamelaDBOperations::insertPamelaRU
2459          //      if ( ptt+1 == rtev){            //      if ( ptt+1 == rtev){  
2460          if ( conptt+1 == nrtev ){            if ( conptt+1 == nrtev ){  
2461            //    if ( conptt+1 == (nrtev+nrtbef )){              //    if ( conptt+1 == (nrtev+nrtbef )){  
2462              if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt);
2463            ptht++;            ptht++;
2464            if ( ptht < rhev ){            if ( ptht < rhev ){
2465              rh->GetEntry(ptht);              rh->GetEntry(ptht);
2466                //pth++;
2467                //if ( pth < rhev ){
2468                //rh->GetEntry(pth);
2469              phh = ehh->GetPscuHeader();              phh = ehh->GetPscuHeader();
2470              pkth = phh->GetCounter();              pkth = phh->GetCounter();
2471              obth = phh->GetOrbitalTime();              obth = phh->GetOrbitalTime();
# Line 2508  Int_t PamelaDBOperations::insertPamelaRU Line 2489  Int_t PamelaDBOperations::insertPamelaRU
2489              if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){              if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){
2490                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);
2491                //                //
2492                if ( (ptt-1) < 0 ) throw -15; // should never arrive here!                //              if ( (ptt-1) < 0 ) throw -15; // should never arrive here!
2493                rt->GetEntry(ptt-1);                if ( (rtev-1) < 0 || ptt < 0 ) throw -15; // should never arrive here!
2494                  //              rt->GetEntry(ptt-1);
2495                  rt->GetEntry(rtev-1);
2496                cod = eht->GetCounter();                cod = eht->GetCounter();
2497                tcod = (UInt_t)cod->Get(pctp->Physics);                tcod = (UInt_t)cod->Get(pctp->Physics)+1;
2498                evbefh = TMath::Max(chminentry,tcod);                evbefh = TMath::Max(chminentry,tcod);
2499                //            evbefh = cod->Get(pctp->Physics);                //            evbefh = cod->Get(pctp->Physics);
2500                rt->GetEntry(ptt);                rt->GetEntry(ptt);
# Line 2742  void PamelaDBOperations::HandleRunFragme Line 2725  void PamelaDBOperations::HandleRunFragme
2725      //      //
2726      // 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
2727      //      //
2728      if ( rhfirstev != firstev && !mishead ) mishead = true;      if ( firstev != (lastev+1) ){ // could be a problem sometimes (?)
2729      if ( rtlastev != lastev && !mistrail ) mistrail = true;        if ( rhfirstev != firstev && !mishead ) mishead = true;
2730          if ( rtlastev != lastev && !mistrail ) mistrail = true;
2731        };
2732      //      //
2733        if ( IsDebug() ) printf(" bhere firstev is %i lastev is %i \n",firstev,lastev);
2734      this->FillClass(mishead,mistrail,firstev,lastev);      this->FillClass(mishead,mistrail,firstev,lastev);
2735        if ( IsDebug() ) printf(" chere firstev is %i lastev is %i \n",firstev,lastev);
2736      //      //
2737      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");
2738      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 2787  void PamelaDBOperations::HandleRunFragme Line 2774  void PamelaDBOperations::HandleRunFragme
2774        glrun->Fill_GL_RUN_FRAGMENTS(conn);        glrun->Fill_GL_RUN_FRAGMENTS(conn);
2775        //        //
2776      } else {      } else {
2777        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);
2778        if ( PEDANTIC ) throw -69;        if ( !RELAXED ){
2779        return;          if ( PEDANTIC ) throw -69;
2780            return;
2781          } else {
2782            glrun->SetID((UInt_t)atoll(row->GetField(0)));
2783            glrun->SetID_RUN_FRAG(0);
2784          };
2785      };      };
2786      //      //
2787      if ( chewbacca && mishead && mistrail ) goto justcheck;      if ( chewbacca && mishead && mistrail ) goto justcheck;
# Line 2840  void PamelaDBOperations::HandleRunFragme Line 2832  void PamelaDBOperations::HandleRunFragme
2832          //          //
2833          found = false; // default value          found = false; // default value
2834          //          //
2835          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");
2836          //          //
2837          // 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:
2838          //          //
# Line 2856  void PamelaDBOperations::HandleRunFragme Line 2848  void PamelaDBOperations::HandleRunFragme
2848              if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt);              if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt);
2849              //              //
2850              found = true;              found = true;
2851                if ( IsDebug() ) printf(" where firstev is %i lastev is %i \n",firstev,lastev);
2852              //              //
2853            } else {            } else {
2854              //              //
# Line 2921  void PamelaDBOperations::HandleRunFragme Line 2914  void PamelaDBOperations::HandleRunFragme
2914          oss << " ID="<<row->GetField(0)<<";";          oss << " ID="<<row->GetField(0)<<";";
2915          //          //
2916          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
2917            if ( IsDebug() ) printf(" there firstev is %i lastev is %i \n",firstev,lastev);
2918          //          //
2919          // merge infos          // merge infos
2920          //          //
# Line 2951  void PamelaDBOperations::HandleRunFragme Line 2945  void PamelaDBOperations::HandleRunFragme
2945          glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT());          glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT());
2946          glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT());          glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT());
2947          //          //
2948            if ( IsDebug() ) printf(" here firstev is %i lastev is %i \n",firstev,lastev);
2949            //
2950          glrun->SetEV_FROM(firstev);          glrun->SetEV_FROM(firstev);
2951          glrun->SetNEVENTS(lastev-firstev+1);          glrun->SetNEVENTS(lastev-firstev+1);
2952          //          //
# Line 3043  void PamelaDBOperations::HandleRunFragme Line 3039  void PamelaDBOperations::HandleRunFragme
3039          //          //
3040          found = false; // default value          found = false; // default value
3041          //          //
3042          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");
3043          //          //
3044          // 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:
3045          //          //
# Line 3143  void PamelaDBOperations::HandleRunFragme Line 3139  void PamelaDBOperations::HandleRunFragme
3139            apkt = PKT(ph->GetCounter());            apkt = PKT(ph->GetCounter());
3140            aobt = OBT(ph->GetOrbitalTime());                aobt = OBT(ph->GetOrbitalTime());    
3141            lastev--;            lastev--;
3142            if ( PEDANTIC ) throw -72;            if ( PEDANTIC && !RELAXED) throw -72;
3143          };          };
3144          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);
3145          //          //
# Line 3211  void PamelaDBOperations::HandleRunFragme Line 3207  void PamelaDBOperations::HandleRunFragme
3207        // 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?
3208        //        //
3209        oss.str("");        oss.str("");
3210        oss << " SELECT ID FROM GL_RUN WHERE "        oss << " SELECT ID,ID_ROOT_L0 FROM GL_RUN WHERE "
3211            << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND ("            << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND ("
3212            << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "            << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "
3213            << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("            << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("
# Line 3234  void PamelaDBOperations::HandleRunFragme Line 3230  void PamelaDBOperations::HandleRunFragme
3230        row = result->Next();        row = result->Next();
3231        //        //
3232        if ( row ){        if ( row ){
3233          if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n");          //
3234          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
3235            // "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number.
3236            //
3237            // 090112 [8RED (-70): RUN ALREADY INSERTED]
3238            //
3239            Bool_t OK = false;
3240            UInt_t IDRL2A = 0;
3241            UInt_t IDRL2B = 0;
3242            if ( chewbacca ){
3243              if ( result->GetRowCount() == 2 ){
3244                IDRL2A = (UInt_t)atoll(row->GetField(0));
3245                UInt_t IDRL0A = (UInt_t)atoll(row->GetField(1));
3246                row = result->Next();
3247                IDRL2B = (UInt_t)atoll(row->GetField(0));
3248                UInt_t IDRL0B = (UInt_t)atoll(row->GetField(1));
3249                if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B);
3250                if ( IDRL0A == IDRL0B ){
3251                  TSQLResult *result2 = 0;
3252                  TSQLRow    *row2    = 0;
3253                  oss.str("");
3254                  oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;";
3255                  if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
3256                  result2 = conn->Query(oss.str().c_str());
3257                  //
3258                  if ( !result2 ) throw -4;
3259                  //
3260                  row2 = result2->Next();
3261                  //
3262                  if ( row2 ){
3263                    UInt_t PKA = (UInt_t)atoll(row2->GetField(0));
3264                    delete result2;
3265                    oss.str("");
3266                    oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;";
3267                    if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
3268                    result2 = conn->Query(oss.str().c_str());
3269                    //
3270                    if ( !result2 ) throw -4;
3271                    //
3272                    row2 = result2->Next();
3273                    //
3274                    if ( row2 ){
3275                      UInt_t PKB = (UInt_t)atoll(row2->GetField(0));
3276                      //
3277                      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);
3278                      if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){
3279                        if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n");
3280                        OK = true;
3281                      };
3282                    };
3283                  };                  
3284                };
3285              };      
3286            };
3287            if ( OK ){
3288              //
3289              // this is the case in which we must insert a piece of run between two fragments in the GL_RUN table
3290              //
3291              // 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 )
3292              //
3293              GL_RUN *glA = new GL_RUN();
3294              glA->Query_GL_RUN(IDRL2A,conn);
3295              //
3296              if ( glA->GetACQ_BUILD_INFO() != 0 ){
3297                //
3298                // the first piece contains a good runheader we can update all the other runs with correct infos!
3299                //
3300                oss.str("");
3301                oss << "UPDATE GL_RUN_FRAGMENTS SET "
3302                    << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "
3303                    << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
3304                    << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , "
3305                    << " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , "
3306                    << " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , "
3307                    << " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , "
3308                    << " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , "
3309                    << " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , "
3310                    << " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , "
3311                    << " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , "
3312                    << " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , "  
3313                    << " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , "  
3314                    << " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , "  
3315                    << " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , "  
3316                    << " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , ";
3317                //
3318                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
3319                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , ";
3320                if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
3321                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , ";
3322                //        
3323                oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC();
3324                oss << " WHERE ID=" << glrun->GetID() << ";";
3325                if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str());
3326                conn->Query(oss.str().c_str());    
3327                //
3328              } else {
3329                //
3330                // sig no runheader, let set anyway what is possible...
3331                //
3332                oss.str("");
3333                oss << "UPDATE GL_RUN_FRAGMENTS SET "
3334                    << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , ";
3335                //
3336                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
3337                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , ";
3338                if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
3339                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , ";
3340                //        
3341                oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
3342                    << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT();
3343                oss << " WHERE ID=" << glrun->GetID() << ";";
3344                if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str());
3345                conn->Query(oss.str().c_str());    
3346              };
3347              //
3348              // update runheader ROOT_ID_FRAG
3349              //
3350              oss.str("");
3351              oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";";
3352              if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str());
3353              conn->Query(oss.str().c_str());
3354              //
3355              // now let's look for runtrailer if any in the last run
3356              //
3357              glA->Query_GL_RUN(IDRL2B,conn);
3358              //
3359              if ( glA->GetPKT_READY_COUNTER() != 0 ){
3360                //
3361                // the first piece contains a good runtrailer we can update all the other runs with correct infos!
3362                //
3363                oss.str("");
3364                oss << "UPDATE GL_RUN_FRAGMENTS SET "
3365                    << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
3366                    << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "
3367                    << " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , "
3368                    << " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , ";
3369                //
3370                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
3371                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
3372                if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) {
3373                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
3374                //        
3375                oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER()
3376                    << " WHERE ID=" << glrun->GetID() << ";";
3377                if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str());
3378                conn->Query(oss.str().c_str());    
3379                //
3380              } else {
3381                //
3382                // sig no runtrailer, let set anyway what is possible...
3383                //
3384                oss.str("");
3385                oss << "UPDATE GL_RUN_FRAGMENTS SET "
3386                    << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
3387                    << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , ";
3388                  //
3389                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
3390                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
3391                if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){
3392                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
3393                //        
3394                oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()
3395                    << " WHERE ID=" << glrun->GetID() << ";";
3396                if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str());
3397                conn->Query(oss.str().c_str());    
3398              };
3399              //
3400              UInt_t myi = glrun->GetID();
3401              oss.str("");
3402              oss << " ID= "<< myi;
3403              //
3404              glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);  
3405              //
3406              // fill the new run in GL_RUN
3407              //
3408              glrun->SetID_RUN_FRAG(IDRL2B);
3409              glrun->Fill_GL_RUN(conn);    
3410              glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
3411              delete glA;
3412              //
3413            } else {
3414              //
3415              // is just a repetition
3416              //
3417              if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n");        
3418              if ( PEDANTIC ) throw -70;
3419            };
3420            //
3421        } else {        } else {
3422          if ( NoFrag() ){          if ( NoFrag() ){
3423            glrun->SetID_RUN_FRAG(glrun->GetID());            glrun->SetID_RUN_FRAG(glrun->GetID());
# Line 3272  void PamelaDBOperations::HandleMissingHo Line 3454  void PamelaDBOperations::HandleMissingHo
3454        glrun->SetID(this->AssignRunID());        glrun->SetID(this->AssignRunID());
3455        glrun->SetID_RUN_FRAG(0);        glrun->SetID_RUN_FRAG(0);
3456        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...
3457      };        };
3458      //      //
3459    };    };
3460    //    //
# Line 3316  Bool_t PamelaDBOperations::IsRunConsiste Line 3498  Bool_t PamelaDBOperations::IsRunConsiste
3498    if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run!    if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run!
3499      //if ( firstev <= lastev+1 ) { // no events inside the run!      //if ( firstev <= lastev+1 ) { // no events inside the run!
3500      if ( IsDebug() ) printf(" Checking but no events in the run! \n");      if ( IsDebug() ) printf(" Checking but no events in the run! \n");
3501        firstev = lastev+1; // this is necessary for files with no Physics entries, should have no influence on other files
3502      // return true is correct      // return true is correct
3503      return(true);      return(true);
3504      //      //
# Line 3345  Bool_t PamelaDBOperations::IsRunConsiste Line 3528  Bool_t PamelaDBOperations::IsRunConsiste
3528        //        //
3529      } else {      } else {
3530        //        //
3531        if ( IsDebug() ) printf(" There are no-phyics packets inside the run!\n");        if ( IsDebug() ) printf(" There are no-physics packets inside the run!\n");
3532        //        //
3533        // HERE WE MUST HANDLE THAT RUNS AND GO BACK        // HERE WE MUST HANDLE THAT RUNS AND GO BACK
3534        //        //
# Line 3355  Bool_t PamelaDBOperations::IsRunConsiste Line 3538  Bool_t PamelaDBOperations::IsRunConsiste
3538        UInt_t check = 0;        UInt_t check = 0;
3539        UInt_t lastevtemp = lastev;        UInt_t lastevtemp = lastev;
3540        UInt_t firstevno = firstev;        UInt_t firstevno = firstev;
3541          UInt_t rhchko=0;
3542          UInt_t rhchk=0;
3543        //        //
3544        for (UInt_t i=firstev; i<=lastev; i++){        for (UInt_t i=firstev; i<=lastev; i++){
3545          //          //
# Line 3363  Bool_t PamelaDBOperations::IsRunConsiste Line 3548  Bool_t PamelaDBOperations::IsRunConsiste
3548          //          //
3549          check = 0;          check = 0;
3550          //          //
3551    
3552            // if we have a runheader set lastev then exit
3553            //
3554          for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){          for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){
3555            if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter));            if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter));
3556          };          };
3557            // check here if we have a runheader
3558            rhchko = rhchk;  
3559            rhchk = code->Get(GetPacketType("RunHeader"));    
3560          //          //
3561          if ( checkfirst < check || i == lastev ){          if ( checkfirst < check || i == lastev ){
3562            //            //
# Line 3449  Bool_t PamelaDBOperations::IsRunConsiste Line 3640  Bool_t PamelaDBOperations::IsRunConsiste
3640              //      this->HandleRunFragments(true,mistrail,firstentry,lastentry); // cannot call it here since it enters a loop which will destroy the already stored variables if we arrive here from HandleRunFragments              //      this->HandleRunFragments(true,mistrail,firstentry,lastentry); // cannot call it here since it enters a loop which will destroy the already stored variables if we arrive here from HandleRunFragments
3641              //              //
3642    
   
   
   
   
   
   
   
   
   
   
   
   
3643              mishead = true;              mishead = true;
3644    
3645    
# Line 3575  Bool_t PamelaDBOperations::IsRunConsiste Line 3754  Bool_t PamelaDBOperations::IsRunConsiste
3754                  //                  //
3755                  found = false; // default value                  found = false; // default value
3756                  //                  //
3757                  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");
3758                  //                  //
3759                  // 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:
3760                  //                  //
# Line 3780  Bool_t PamelaDBOperations::IsRunConsiste Line 3959  Bool_t PamelaDBOperations::IsRunConsiste
3959              }; // EEE              }; // EEE
3960    
3961    
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
3962            } else {            } else {
3963              if ( !IsRunAlreadyInserted() ){              if ( !IsRunAlreadyInserted() ){
3964                glrun->SetID(this->AssignRunID());                glrun->SetID(this->AssignRunID());
# Line 3825  Bool_t PamelaDBOperations::IsRunConsiste Line 3973  Bool_t PamelaDBOperations::IsRunConsiste
3973            //            //
3974          };          };
3975          //          //
3976            if ( i > firstev ){
3977              if ( rhchko != rhchk ){
3978                if ( IsDebug() ) printf("oh oh... we have a runheader! stop here and handle later the remaining piece\n");
3979                lastev = i;
3980                return(false);
3981              };
3982            };
3983            //
3984          if ( check == checklast && i != lastev ){          if ( check == checklast && i != lastev ){
3985            lastevtemp = i - 1;            lastevtemp = i - 1;
3986            i = lastev - 1;            i = lastev - 1;
# Line 4116  Int_t PamelaDBOperations::insertCALO_CAL Line 4272  Int_t PamelaDBOperations::insertCALO_CAL
4272    UInt_t totime = 0;    UInt_t totime = 0;
4273    UInt_t obt = 0;    UInt_t obt = 0;
4274    UInt_t pkt = 0;    UInt_t pkt = 0;
4275      Float_t totped = 0.;
4276    //    //
4277    tr = (TTree*)file->Get("CalibCalPed");    tr = (TTree*)file->Get("CalibCalPed");
4278    if ( !tr || tr->IsZombie() ) throw -21;    if ( !tr || tr->IsZombie() ) throw -21;
# Line 4133  Int_t PamelaDBOperations::insertCALO_CAL Line 4290  Int_t PamelaDBOperations::insertCALO_CAL
4290        if ( calibCalPed->cstwerr[section] ){        if ( calibCalPed->cstwerr[section] ){
4291          valid = 1;          valid = 1;
4292          if ( calibCalPed->cperror[section] ) valid = 0;          if ( calibCalPed->cperror[section] ) valid = 0;
4293            //
4294            // 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.]
4295            //
4296            totped = 0.;
4297            Int_t ns = 0;
4298            if ( section == 2 ) ns = 3;
4299            if ( section == 3 ) ns = 1;
4300            if ( section == 1 ) ns = 2;
4301            for (UInt_t ss=0; ss<96; ss++){
4302              totped += fabs(calibCalPed->calped[ns][0][ss]);
4303            }
4304            if ( totped < 1. ){
4305              if ( IsDebug() ) printf(" Section %i totped %f -  No calibration data! Calorimeter power problems? \n",section,totped);
4306              valid = 0;
4307            };
4308            //
4309          ph = eh->GetPscuHeader();          ph = eh->GetPscuHeader();
4310          obt = ph->GetOrbitalTime();            obt = ph->GetOrbitalTime();  
4311          pkt = ph->GetCounter();            pkt = ph->GetCounter();  
# Line 4300  Int_t PamelaDBOperations::insertCALOPULS Line 4473  Int_t PamelaDBOperations::insertCALOPULS
4473    tr->SetBranchAddress("Header", &eh);    tr->SetBranchAddress("Header", &eh);
4474    nevents = tr->GetEntries();    nevents = tr->GetEntries();
4475    //    //
4476      Float_t totpul = 0.;
4477      //
4478    if ( nevents > 0 ){    if ( nevents > 0 ){
4479      //      //
4480      for (UInt_t i=0; i < nevents; i++){      for (UInt_t i=0; i < nevents; i++){
# Line 4309  Int_t PamelaDBOperations::insertCALOPULS Line 4484  Int_t PamelaDBOperations::insertCALOPULS
4484          if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){          if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){
4485            valid = 1;            valid = 1;
4486            if ( cp1->pperror[section] ) valid = 0;            if ( cp1->pperror[section] ) valid = 0;
4487              //
4488              // 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.]
4489              //
4490              totpul = 0.;
4491              Int_t ns = 0;
4492              if ( section == 2 ) ns = 3;
4493              if ( section == 3 ) ns = 1;
4494              if ( section == 1 ) ns = 2;
4495              for (UInt_t ss=0; ss<96; ss++){
4496                totpul += cp1->calpuls[ns][0][ss];
4497              }
4498              if ( totpul >= 3145632. ){
4499                if ( IsDebug() ) printf(" PULSE1 Section %i totpul %f -  No calibration data! Calorimeter power problems? \n",section,totpul);
4500                valid = 0;
4501              };
4502              //
4503            ph = eh->GetPscuHeader();            ph = eh->GetPscuHeader();
4504            obt = ph->GetOrbitalTime();              obt = ph->GetOrbitalTime();  
4505            pkt = ph->GetCounter();              pkt = ph->GetCounter();  
# Line 4466  Int_t PamelaDBOperations::insertCALOPULS Line 4657  Int_t PamelaDBOperations::insertCALOPULS
4657          if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){          if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){
4658            valid = 1;            valid = 1;
4659            if ( cp2->pperror[section] ) valid = 0;            if ( cp2->pperror[section] ) valid = 0;
4660              //
4661              // 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.]
4662              //
4663              totpul = 0.;
4664              Int_t ns = 0;
4665              if ( section == 2 ) ns = 3;
4666              if ( section == 3 ) ns = 1;
4667              if ( section == 1 ) ns = 2;
4668              for (UInt_t ss=0; ss<96; ss++){
4669                totpul += cp2->calpuls[ns][0][ss];
4670              }
4671              if ( totpul >= 3145632. ){
4672                if ( IsDebug() ) printf(" PULSE2 Section %i totpul %f -  No calibration data! Calorimeter power problems? \n",section,totpul);
4673                valid = 0;
4674              };
4675              //
4676            ph = eh->GetPscuHeader();            ph = eh->GetPscuHeader();
4677            obt = ph->GetOrbitalTime();              obt = ph->GetOrbitalTime();  
4678            pkt = ph->GetCounter();              pkt = ph->GetCounter();  
# Line 4641  Int_t PamelaDBOperations::insertCALOPULS Line 4848  Int_t PamelaDBOperations::insertCALOPULS
4848    return(0);    return(0);
4849  };  };
4850    
 // /**  
 //  * Fill the GL_TRK_CALIB table  
 //  */  
 // void PamelaDBOperations::HandleTRK_CALIB(Bool_t pk1, Bool_t pk2){  
 //   //  
 //   TSQLResult *result = 0;  
 //   TSQLRow    *row    = 0;  
 //   //  
 //   stringstream oss;  
 //   oss.str("");  
 //   //  
 //   UInt_t totime = 0;  
 //   //  
 //   if ( !pk1 && !pk2 ){  
 //     if ( IsDebug() ) printf(" Cannot handle trk calibration with both packet missing!\n");  
 //     return;  
 //   };  
 //   //  
 //   // check if the calibration has already been inserted  
 //   //  
 //   oss.str("");  
 //   oss << " SELECT ID FROM GL_TRK_CALIB WHERE "  
 //       << " BOOT_NUMBER = "<< this->GetBOOTnumber(); //  
 //   oss << " AND ( ( ";    
 //   if ( pk1 ){  
 //     oss << " OBT1 = "<< obt1 << " AND "  
 //      << " PKT1 = "<< pkt1  
 //      << " ) OR ( ";  
 //   } else {  
 //     oss << " PKT1 = "<< pkt2-1  
 //      << " ) OR ( ";    
 //   };        
 //   if ( pk2 ){  
 //     oss << " OBT2 = "<< obt2 << " AND "  
 //      << " PKT2 = "<< pkt2;  
 //   } else {  
 //     oss << " PKT2 = "<< pkt1+1;  
 //   };        
 //   oss << " ) );";    
 //   //  
 //   if ( IsDebug() ) printf(" Check if the trk calibration has already been inserted: query is \n %s \n",oss.str().c_str());  
 //   result = conn->Query(oss.str().c_str());  
 //   //  
 //   if ( !result ) throw -4;  
 //   //  
 //   row = result->Next();  
 //   //  
 //   if ( row ){  
 //     //  
 //     if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n");  
 //     if ( PEDANTIC ) throw -80;  
 //     //  
 //   } else {  
 //     //  
 //     // we have to insert a new calibration, check where to place it  
 //     //  
 //     oss.str("");  
 //     oss << " SELECT ID,TO_TIME FROM GL_TRK_CALIB WHERE "  
 //      << " FROM_TIME < "<< fromtime << " AND "  
 //      << " TO_TIME > "<< fromtime << ";";  
 //     //  
 //     if ( IsDebug() ) printf(" Check where to place the trk calibration: query is \n %s \n",oss.str().c_str());  
 //     result = conn->Query(oss.str().c_str());  
 //     //  
 //     if ( !result ) throw -4;  
 //     //  
 //     row = result->Next();  
 //     //  
 //     if ( !row ){  
 //       //  
 //       // no calibrations in the db contain our calibration  
 //       //  
 //       if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n");  
 //       if ( fromtime < 1150871000 ) fromtime = 0; // the first flight calibration was taken at about 1150863300 s, this line allows to analyze first runs in raw mode  
 //       //  
 //       oss.str("");  
 //       oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE "  
 //        << " FROM_TIME > "<< fromtime << " ORDER BY FROM_TIME ASC LIMIT 1;";  
 //       //  
 //       if ( IsDebug() ) printf(" Check the upper limit for calibration: query is \n %s \n",oss.str().c_str());  
 //       result = conn->Query(oss.str().c_str());  
 //       //  
 //       if ( !result ) throw -4;  
 //       //  
 //       row = result->Next();  
 //       if ( !row ){  
 //      totime = numeric_limits<UInt_t>::max();  
 //       } else {  
 //      totime = (UInt_t)atoll(row->GetField(0));  
 //       };  
 //       //  
 //     } else {  
 //       //  
 //       // determine upper and lower limits and make space for the new calibration  
 //       //  
 //       totime = (UInt_t)atoll(row->GetField(1));  
 //       //  
 //       oss.str("");  
 //       oss << " UPDATE GL_TRK_CALIB SET "    
 //        << " TO_TIME = "<< fromtime << " WHERE "  // NOTICE: to_time is equal to from_time of the calibration before, so the interval is: [from_time,to_time[  
 //        << " ID = "<< row->GetField(0) << ";";  
 //       //  
 //       if ( IsDebug() ) printf(" Make space for the new trk calibration: query is \n %s \n",oss.str().c_str());  
 //       result = conn->Query(oss.str().c_str());  
 //       //  
 //       if ( !result ) throw -4;  
 //       //  
 //     };  
 //     //  
 //     oss.str("");  
 //     oss << " INSERT INTO GL_TRK_CALIB (ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION) "  
 //      << " VALUES (NULL,' "  
 //      << idroot << "',";  
 //     //  
 //     if ( !pk1 ){  
 //       oss << "NULL,";  
 //     } else {  
 //       oss << "'"  
 //        << t1 << "',";  
 //     };  
 //     //  
 //     if ( !pk2 ){  
 //       oss << "NULL,'";  
 //     } else {  
 //       oss << "'"  
 //        << t2 << "','";  
 //     };  
 //     //  
 //     oss << fromtime << "','"  
 //      << totime << "','"  
 //      << obt1 << "','"  
 //      << pkt1 << "','"  
 //      << obt2 << "','"  
 //      << pkt2 << "','"  
 //      << this->GetBOOTnumber() << "','"  
 //      << valid << "');";  
 //     //  
 //     if ( IsDebug() ) printf(" Insert the new trk calibration: query is \n %s \n",oss.str().c_str());  
 //     //  
 //     result = conn->Query(oss.str().c_str());  
 //     //  
 //     if ( !result ) throw -4;  
 //     //  
 //   };  
 //   //  
 // };  
4851  /**  /**
4852   * Fill the GL_TRK_CALIB table   * Fill the GL_TRK_CALIB table
4853   */   */
# Line 4977  void PamelaDBOperations::HandleTRK_CALIB Line 5038  void PamelaDBOperations::HandleTRK_CALIB
5038      if ( !result ) throw -4;;      if ( !result ) throw -4;;
5039      row = result->Next();      row = result->Next();
5040      if(row)glcal->ID = (UInt_t)atoll(row->GetField(0));      if(row)glcal->ID = (UInt_t)atoll(row->GetField(0));
5041        //
5042        delete result; // mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages]
5043      //      //
5044  };  };
5045    
# Line 5187  Int_t PamelaDBOperations::insertTRK_CALI Line 5249  Int_t PamelaDBOperations::insertTRK_CALI
5249                  //                  //
5250              };              };
5251              //              //
5252    
5253                if( !(MISSING_pkt1&MISSING_pkt2) ){
5254                  this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2);
5255                  ncalib++;
5256                  if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true;
5257                }
5258    
5259    
5260          } else {          } else {
5261              //            //
5262              if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1);              if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1);
5263              //      if ( PEDANTIC ) throw -79;              //      if ( PEDANTIC ) throw -79;
5264              //              //
5265          };          };
5266          //              //    
5267    
         if( !(MISSING_pkt1&MISSING_pkt2) ){  
             this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2);  
             ncalib++;  
             if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true;  
         }  
   
5268      }; //end loop on pkt1      }; //end loop on pkt1
5269    
5270    
# Line 5416  Int_t PamelaDBOperations::insertTRK_CALI Line 5480  Int_t PamelaDBOperations::insertTRK_CALI
5480                                    
5481                      if ( IsDebug() ) cout << "- - - - - - - - - - -" <<endl;                      if ( IsDebug() ) cout << "- - - - - - - - - - -" <<endl;
5482  //                  cout << path <<endl;  //                  cout << path <<endl;
5483                      cout << "File    : " <<name <<endl;  //                  cout << "File    : " <<name <<endl;
5484  //                  cout << obt0 <<endl;  //                  cout << obt0 <<endl;
5485  //                  cout << timesync <<endl;  //                  cout << timesync <<endl;
5486                      cout << "boot n. : "<<boot_number <<endl;  //                  cout << "boot n. : "<<boot_number <<endl;
5487  //                  cout << raw <<endl;  //                  cout << raw <<endl;
5488    
5489                      // ------------------------------------------------------                      // ------------------------------------------------------
5490                      // ... retrieve the calibration packets.                      // ... retrieve the calibration packets.
5491                      // ------------------------------------------------------                      // ------------------------------------------------------
5492                      TFile *file = new TFile(path+"/"+name);                      if ( IsDebug() ) printf(" file is %s/%s \n",((TString)gSystem->ExpandPathName(path.Data())).Data(),name.Data());
5493                        TFile *file = new TFile(((TString)gSystem->ExpandPathName(path.Data()))+"/"+name); // EM, path could be symbolic and we must expand it
5494                      if(!file)throw -100;                      if(!file)throw -100;
5495                      if(file->IsZombie())throw -100;                      if(file->IsZombie())throw -100;
5496                      //                      //
# Line 5482  Int_t PamelaDBOperations::insertTRK_CALI Line 5547  Int_t PamelaDBOperations::insertTRK_CALI
5547    
5548              if(FOUND){              if(FOUND){
5549    
5550              if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <<endl;                if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <<endl;
5551    
5552                  ////////////////////////////////////////////                ////////////////////////////////////////////
5553                  // insert a new entry in GL_TRK_CALIB and                // insert a new entry in GL_TRK_CALIB and
5554                  // modify the time-tag of the previous one                // modify the time-tag of the previous one
5555                  ////////////////////////////////////////////                ////////////////////////////////////////////
5556    
5557                  // ---------------------------------------------------------------------                // ---------------------------------------------------------------------
5558                  // step 1: insert a new raw file in GL_RAW                // step 1: insert a new raw file in GL_RAW
5559                  // ---------------------------------------------------------------------                // ---------------------------------------------------------------------
5560                  //                //
5561                  // check if the raw file already exist                // check if the raw file already exist
5562                  //                //
5563                  UInt_t id_raw = 0;                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
5564                  oss.str("");                //                oss.str("");
5565                  oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";";                //                oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";";
5566                  if ( IsDebug() ) cout << oss.str().c_str() << endl;                //                if ( IsDebug() ) cout << oss.str().c_str() << endl;
5567                                    
5568                  result = conn->Query(oss.str().c_str());                //                result = conn->Query(oss.str().c_str());
5569                  if ( !result ) throw -4;;                //                if ( !result ) throw -4;;
5570                  if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl;                //                if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl;
5571                  if( result->GetRowCount() == 0){                //                if( result->GetRowCount() == 0){
5572                      if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl;                //                    if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl;
5573                      // - - - - - - - - - - -                //                    // - - - - - - - - - - -
5574                      // insert new raw file                //                    // insert new raw file
5575                      // - - - - - - - - - - -                //                    // - - - - - - - - - - -
5576                      GL_RAW glraw = GL_RAW();                    //                    GL_RAW glraw = GL_RAW();    
5577                      glraw.PATH        = gSystem->DirName(raw.Data());                //                    glraw.PATH        = gSystem->DirName(raw.Data());
5578                      glraw.NAME        = gSystem->BaseName(raw.Data());                //                    glraw.NAME        = gSystem->BaseName(raw.Data());
5579                      glraw.BOOT_NUMBER = boot_number;                //                    glraw.BOOT_NUMBER = boot_number;
5580                      //                //                    //
5581                      insertPamelaRawFile( &glraw );                //                    insertPamelaRawFile( &glraw );
5582                      //                              //                    //              
5583                      id_raw = glraw.ID;                              //                    id_raw = glraw.ID;              
5584                  }else{                //                }else{
5585                      row = result->Next();                //                    row = result->Next();
5586                      id_raw = (UInt_t)atoll(row->GetField(0));                //                    id_raw = (UInt_t)atoll(row->GetField(0));
5587                  }                //                }
5588                  if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl;                //                if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl;
5589    
5590                  // ---------------------------------------------------------------------                // ---------------------------------------------------------------------
5591                  // step 1(bis): retrieve the timesync id associated to the file                // step 1(bis): retrieve the timesync id associated to the file
5592                  // (NB, uso lo stesso associato al file iniziale)                // (NB, uso lo stesso associato al file iniziale)
5593                  // ---------------------------------------------------------------------                // ---------------------------------------------------------------------
5594                  UInt_t idtimesync = 0;                UInt_t idtimesync = 0;
5595                  oss.str("");                oss.str("");
5596                  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;";
5597                  if ( debug ) printf(" %s \n",oss.str().c_str());                if ( debug ) printf(" %s \n",oss.str().c_str());
5598                  result = conn->Query(oss.str().c_str());                result = conn->Query(oss.str().c_str());
5599                  if ( !result ) throw -3;                if ( !result ) throw -3;
5600                  row = result->Next();                  row = result->Next();
5601                  if ( !row ) throw -3;                  if ( !row ) throw -3;
5602                  idtimesync = (UInt_t)atoll(row->GetField(0));                  idtimesync = (UInt_t)atoll(row->GetField(0));
5603                  if ( IsDebug() ) cout << "ID_TIMESYNC = "<<idtimesync<<endl;                  if ( IsDebug() ) cout << "ID_TIMESYNC = "<<idtimesync<<endl;
5604                                    
5605                    delete result;// mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages]
5606                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
5607                  // step 2: insert a new root file in GL_ROOT                  // step 2: insert a new root file in GL_ROOT
5608                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
5609                  //                  //
5610                  // check if the raw file already exist                  // check if the root file already exist
5611                  //                  //
5612                  UInt_t id_root = 0;                  UInt_t id_root = 0;
5613                  oss.str("");                  oss.str("");
# Line 5559  Int_t PamelaDBOperations::insertTRK_CALI Line 5625  Int_t PamelaDBOperations::insertTRK_CALI
5625                      GL_ROOT glroot = GL_ROOT();                                  GL_ROOT glroot = GL_ROOT();            
5626                      glroot.ID_RAW      = id_raw;                      glroot.ID_RAW      = id_raw;
5627                      glroot.ID_TIMESYNC = idtimesync;                      glroot.ID_TIMESYNC = idtimesync;
5628                      glroot.PATH        = path;                      //
5629                        // EM STATIC = the full expanded path must be put in the DB, KEEPENV = the path given as input (or found in ROOT_TABLE) must be used,
5630                        //             NOT STATIC NOT KEEPENV = $PAM_L0 must be used in the DB
5631                        //
5632                        if ( STATIC ){
5633                          glroot.PATH        = (TString)gSystem->ExpandPathName(path);
5634                        } else {
5635                          if ( KEEPENV ){
5636                            glroot.PATH      = path;
5637                          } else {
5638                            glroot.PATH      = "$PAM_L0";
5639                          };
5640                        };
5641                        //              glroot.PATH        = path;
5642                      glroot.NAME        = name;                      glroot.NAME        = name;
5643                      //                      //
5644                      insertPamelaRootFile( &glroot );                      insertPamelaRootFile( &glroot );
# Line 5571  Int_t PamelaDBOperations::insertTRK_CALI Line 5650  Int_t PamelaDBOperations::insertTRK_CALI
5650                  }                  }
5651                  if ( IsDebug() ) cout << "ID_ROOT = "<<id_root<<endl;                  if ( IsDebug() ) cout << "ID_ROOT = "<<id_root<<endl;
5652    
5653                    delete result;// mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages]
5654                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
5655                  // step 3: modify time-tag of corrupted GL_TRK_CALIB entry                  // step 3: modify time-tag of corrupted GL_TRK_CALIB entry
5656                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
# Line 5583  Int_t PamelaDBOperations::insertTRK_CALI Line 5663  Int_t PamelaDBOperations::insertTRK_CALI
5663                  result = conn->Query(oss.str().c_str());                  result = conn->Query(oss.str().c_str());
5664                  if ( !result ) throw -4;;                  if ( !result ) throw -4;;
5665    
5666                    delete result; // mmm... "Error in <TMySQLResult::Next>: result set closed" solved? 090112 [8RED error messages]
5667    
5668                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
5669                  // step 4: insert the new calibration:                  // step 4: insert the new calibration:
5670                  // ---------------------------------------------------------------------                  // ---------------------------------------------------------------------
# Line 6034  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6116  Int_t PamelaDBOperations::CleanGL_RUN_FR
6116                  oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , ";                  oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , ";
6117                //                              //              
6118                oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , "                oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , "
6119                    << " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT()<< ";";                    << " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT();
6120                  oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112
6121                conn->Query(oss.str().c_str());                  conn->Query(oss.str().c_str());  
6122              };                  };    
6123            };            };
# Line 6083  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6166  Int_t PamelaDBOperations::CleanGL_RUN_FR
6166                if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){                if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){
6167                  oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };                  oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
6168                //                              //              
6169                oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()<< ";";                oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT();
6170                  oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112
6171                conn->Query(oss.str().c_str());                  conn->Query(oss.str().c_str());  
6172              };                  };    
6173            };            };
# Line 6134  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6218  Int_t PamelaDBOperations::CleanGL_RUN_FR
6218                row2 = result2->Next();                row2 = result2->Next();
6219                //                //
6220                if ( row2 ){                if ( row2 ){
6221                  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");
6222                  if ( PEDANTIC ) throw -83;                  if ( PEDANTIC ) throw -83;
6223                  row2->Close();                  row2->Close();
6224                };                };
# Line 6211  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6295  Int_t PamelaDBOperations::CleanGL_RUN_FR
6295        glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);          glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);  
6296        //        //
6297        oss.str("");        oss.str("");
6298        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 "
6299            << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND ("            << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND ("
6300            << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "            << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "
6301            << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("            << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("
# Line 6269  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6353  Int_t PamelaDBOperations::CleanGL_RUN_FR
6353          moved++;          moved++;
6354          //          //
6355        } else {        } else {
6356          if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n");  
6357          if ( PEDANTIC ) throw -83;          // questa parte mah mah mah... da controllare
6358    
6359            //
6360            // 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
6361            // "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number.
6362            //
6363            // 090112 [8RED (-70): RUN ALREADY INSERTED]
6364            //
6365            Bool_t OK = false;
6366            UInt_t IDRL2A = 0;
6367            UInt_t IDRL2B = 0;
6368              if ( result2->GetRowCount() == 2 ){
6369                IDRL2A = (UInt_t)atoll(row2->GetField(0));
6370                UInt_t IDRL0A = (UInt_t)atoll(row2->GetField(4));
6371                row2 = result2->Next();
6372                IDRL2B = (UInt_t)atoll(row2->GetField(0));
6373                UInt_t IDRL0B = (UInt_t)atoll(row2->GetField(4));
6374                if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B);
6375                //      if ( IDRL0A == IDRL0B ){
6376    //            TSQLResult *result2a = 0;
6377    //            TSQLRow    *row2a    = 0;
6378    //            oss.str("");
6379    //            oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;";
6380    //            if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
6381    //            result2a = conn->Query(oss.str().c_str());
6382    //            //
6383    //            if ( !result2a ) throw -4;
6384    //            //
6385    //            row2a = result2a->Next();
6386    //            //
6387    //            if ( row2a ){
6388    //              UInt_t PKA = (UInt_t)atoll(row2a->GetField(0));
6389    //              delete result2a;
6390    //              oss.str("");
6391    //              oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;";
6392    //              if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
6393    //              result2a = conn->Query(oss.str().c_str());
6394    //              //
6395    //              if ( !result2a ) throw -4;
6396    //              //
6397    //              row2a = result2a->Next();
6398    //              //
6399    //              if ( row2a ){
6400    //                UInt_t PKB = (UInt_t)atoll(row2a->GetField(0));
6401    //                //
6402    //                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);
6403    //                if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){
6404    //                  if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n");
6405                        OK = true;
6406                        //            };
6407                        //          };
6408                        //        };                  
6409                        //    };
6410              };      
6411            if ( OK ){
6412              //
6413              // this is the case in which we must insert a piece of run between two fragments in the GL_RUN table
6414              //
6415              // 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 )
6416              //
6417              GL_RUN *glA = new GL_RUN();
6418              glA->Query_GL_RUN(IDRL2A,conn);
6419              //
6420              if ( glA->GetACQ_BUILD_INFO() != 0 ){
6421                //
6422                // the first piece contains a good runheader we can update all the other runs with correct infos!
6423                //
6424                oss.str("");
6425                oss << "UPDATE GL_RUN_FRAGMENTS SET "
6426                    << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "
6427                    << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
6428                    << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , "
6429                    << " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , "
6430                    << " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , "
6431                    << " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , "
6432                    << " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , "
6433                    << " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , "
6434                    << " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , "
6435                    << " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , "
6436                    << " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , "  
6437                    << " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , "  
6438                    << " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , "  
6439                    << " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , "  
6440                    << " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , ";
6441                //
6442                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
6443                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , ";
6444                if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
6445                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , ";
6446                //        
6447                oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC();
6448                oss << " WHERE ID=" << glrun->GetID() << ";";
6449                if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str());
6450                conn->Query(oss.str().c_str());    
6451                //
6452              } else {
6453                //
6454                // sig no runheader, let set anyway what is possible...
6455                //
6456                oss.str("");
6457                oss << "UPDATE GL_RUN_FRAGMENTS SET "
6458                    << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , ";
6459                //
6460                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
6461                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , ";
6462                if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
6463                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , ";
6464                //        
6465                oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
6466                    << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT();
6467                oss << " WHERE ID=" << glrun->GetID() << ";";
6468                if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str());
6469                conn->Query(oss.str().c_str());    
6470              };
6471              //
6472              // update runheader ROOT_ID_FRAG
6473              //
6474              oss.str("");
6475              oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";";
6476              if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str());
6477              conn->Query(oss.str().c_str());
6478              //
6479              // now let's look for runtrailer if any in the last run
6480              //
6481              glA->Query_GL_RUN(IDRL2B,conn);
6482              //
6483              if ( glA->GetPKT_READY_COUNTER() != 0 ){
6484                //
6485                // the first piece contains a good runtrailer we can update all the other runs with correct infos!
6486                //
6487                oss.str("");
6488                oss << "UPDATE GL_RUN_FRAGMENTS SET "
6489                    << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
6490                    << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "
6491                    << " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , "
6492                    << " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , ";
6493                //
6494                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
6495                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
6496                if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) {
6497                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
6498                //        
6499                oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER()
6500                    << " WHERE ID=" << glrun->GetID() << ";";
6501                if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str());
6502                conn->Query(oss.str().c_str());    
6503                //
6504              } else {
6505                //
6506                // sig no runtrailer, let set anyway what is possible...
6507                //
6508                oss.str("");
6509                oss << "UPDATE GL_RUN_FRAGMENTS SET "
6510                    << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
6511                    << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , ";
6512                  //
6513                if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
6514                  oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
6515                if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){
6516                  oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
6517                //        
6518                oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()
6519                    << " WHERE ID=" << glrun->GetID() << ";";
6520                if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str());
6521                conn->Query(oss.str().c_str());    
6522              };
6523              //
6524              UInt_t myi = glrun->GetID();
6525              oss.str("");
6526              oss << " ID= "<< myi;
6527              //
6528              glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);  
6529              //
6530              // fill the new run in GL_RUN
6531              //
6532              glrun->SetID_RUN_FRAG(IDRL2B);
6533              glrun->Fill_GL_RUN(conn);    
6534              glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
6535              delete glA;
6536              moved++;
6537              //
6538            } else {
6539              //
6540              // is just a repetition
6541              //
6542              if ( IsDebug() ) printf(" The run %u is already present in the GL_RUN table...\n",glrun->GetID());    
6543              //      printf(" CCCCCCCCICCCCCCCCCCCCIOOOOOOOOOO si muove Ciccio! %u \n",glrun->GetID());
6544              //      if ( PEDANTIC && glrun->GetID() != 61563 ) throw -83;
6545              if ( PEDANTIC ) throw -83;
6546            };
6547            //      if ( IsDebug() ) printf(" The run already exists in the GL_RUN table! ...\n");
6548            //      if ( PEDANTIC ) throw -83;
6549        };        };
6550        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));      
6551        //        //
# Line 6336  Int_t PamelaDBOperations::ValidateRuns(T Line 6611  Int_t PamelaDBOperations::ValidateRuns(T
6611      // 2) get the OBT of the last validated run      // 2) get the OBT of the last validated run
6612      // --------------------------------------------------------------      // --------------------------------------------------------------
6613      oss.str("");      oss.str("");
6614      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
6615        oss << " SELECT * FROM GL_RUN  WHERE VALIDATION>0 AND RUNHEADER_TIME<="<< t_start
6616          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
6617      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());
6618      result = conn->Query(oss.str().c_str());      result = conn->Query(oss.str().c_str());
# Line 6479  Int_t PamelaDBOperations::ValidateRuns(T Line 6755  Int_t PamelaDBOperations::ValidateRuns(T
6755          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
6756                                                        
6757          if( !CHECK && this_run->VALIDATION ){          if( !CHECK && this_run->VALIDATION ){
6758            for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);            //      for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
6759              for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],this_run->VALIDATION);
6760            nseq=0;            nseq=0;
6761          }          }
6762                                        
# Line 6500  Int_t PamelaDBOperations::ValidateRuns(T Line 6777  Int_t PamelaDBOperations::ValidateRuns(T
6777      if( CHECK ){      if( CHECK ){
6778        // check if calibration exists        // check if calibration exists
6779        if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval);        if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval);
6780        Bool_t MISSING = MissingTRK_CALIB(t1,t2);        //      Bool_t MISSING = MissingTRK_CALIB(t1,t2);
6781        for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING);        UInt_t MISSING = MissingTRK_CALIB(t1,t2);
6782          UInt_t val = 0;
6783          if ( MISSING == 1 ) val = 0;
6784          if ( MISSING == 0 ) val = 1;
6785          if ( MISSING == 2 ) val = 2;
6786          for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],val);
6787        nseq=0;        nseq=0;
6788      };      };
6789      //--------------      //--------------
# Line 6531  Int_t PamelaDBOperations::ValidateRuns(T Line 6813  Int_t PamelaDBOperations::ValidateRuns(T
6813   * @param t2 To absolute time   * @param t2 To absolute time
6814   * @return true if there might be a missing calibration   * @return true if there might be a missing calibration
6815   */   */
6816  Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){  //Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){
6817    UInt_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){
6818                    
6819    GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB();    GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB();
6820                    
6821    // get the closest calibration before the run start (t2)    // get the closest calibration before the run start (t2)
6822    if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true);    //>>> missing    //  if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true);        //>>> missing
6823      if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(1);       //>>> missing
6824                    
6825    if ( trkcalib->TO_TIME  < t2 ) return(true);                                  //>>> missing    //  if ( trkcalib->TO_TIME  < t2 ) return(true);                                      //>>> missing
6826      if ( trkcalib->TO_TIME  < t2 ) return(1);                                     //>>> missing
6827                    
6828    //==============================================================    //==============================================================
6829    // Check is done first on the basis of time between calibration,    // Check is done first on the basis of time between calibration,
# Line 6555  Bool_t PamelaDBOperations::MissingTRK_CA Line 6840  Bool_t PamelaDBOperations::MissingTRK_CA
6840      //==============================================================      //==============================================================
6841      Bool_t DOWNLOAD = false;      Bool_t DOWNLOAD = false;
6842      // check if the calib was skipped becouse of download .... DA FARE!!      // check if the calib was skipped becouse of download .... DA FARE!!
6843      if(DOWNLOAD)return(false);      //    if(DOWNLOAD)return(false);
6844        if(DOWNLOAD)return(0);
6845                                    
6846      return(true);                                       //>>> missing      //    return(true);                                         //>>> missing
6847        return(1);                                  //>>> missing
6848                                    
6849    };    };
6850                    
# Line 6567  Bool_t PamelaDBOperations::MissingTRK_CA Line 6854  Bool_t PamelaDBOperations::MissingTRK_CA
6854    //==============================================================    //==============================================================
6855    // the long time interval bewteen runs might be due to download    // the long time interval bewteen runs might be due to download
6856    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);
6857    return(false);    if ( trkcalib->VALIDATION ) return(0);
6858      if ( IsDebug() )printf("Calibration is not validated... :-/ ==> OK but with VALIDATION=2! \n");
6859      return(2);
6860                    
6861  };  };
6862  /**  /**
# Line 6576  Bool_t PamelaDBOperations::MissingTRK_CA Line 6865  Bool_t PamelaDBOperations::MissingTRK_CA
6865   * @param validation true/false   * @param validation true/false
6866   */   */
6867  Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){  Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){
6868      return(this->assignVALIDATION(idrun,(UInt_t)validation));
6869    }
6870    
6871    Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, UInt_t validation){
6872    TSQLResult *result = 0;    TSQLResult *result = 0;
6873    stringstream oss;    stringstream oss;
6874    oss.str("");    oss.str("");
# Line 6772  Int_t PamelaDBOperations::removeFile(TSt Line 7065  Int_t PamelaDBOperations::removeFile(TSt
7065    stringstream myquery;    stringstream myquery;
7066    //      //  
7067    myquery.str("");    myquery.str("");
7068    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() <<"';";
7069    //    //
7070    pResult = conn->Query(myquery.str().c_str());    pResult = conn->Query(myquery.str().c_str());
7071    //    //
# Line 6788  Int_t PamelaDBOperations::removeFile(TSt Line 7081  Int_t PamelaDBOperations::removeFile(TSt
7081    //    //
7082    this->SetID_ROOT((UInt_t)atoll(Row->GetField(0)));    this->SetID_ROOT((UInt_t)atoll(Row->GetField(0)));
7083    this->SetID_RAW((UInt_t)atoll(Row->GetField(1)));    this->SetID_RAW((UInt_t)atoll(Row->GetField(1)));
7084      UInt_t idtsy=(UInt_t)atoll(Row->GetField(2));
7085    //    //
7086    this->ValidationOFF();    this->ValidationOFF();
7087    //    //
# Line 6795  Int_t PamelaDBOperations::removeFile(TSt Line 7089  Int_t PamelaDBOperations::removeFile(TSt
7089    //    //
7090    this->RemoveRUNS();    this->RemoveRUNS();
7091    //    //
7092    this->RemoveFILES();    this->RemoveFILES(idtsy);
7093    //    //
7094    this->SetID_ROOT(0);    this->SetID_ROOT(0);
7095    this->SetID_RAW(0);    this->SetID_RAW(0);
# Line 7015  void PamelaDBOperations::RemoveRUNS(){ Line 7309  void PamelaDBOperations::RemoveRUNS(){
7309   * Rearrange calibration tables   * Rearrange calibration tables
7310   *   *
7311   **/   **/
7312  void PamelaDBOperations::RemoveFILES(){  void PamelaDBOperations::RemoveFILES(UInt_t idtsy){
7313    stringstream myquery;    stringstream myquery;
7314    //    //
7315    myquery.str("");    myquery.str("");
# Line 7025  void PamelaDBOperations::RemoveFILES(){ Line 7319  void PamelaDBOperations::RemoveFILES(){
7319    //    //
7320    conn->Query(myquery.str().c_str());    conn->Query(myquery.str().c_str());
7321    //    //
7322      myquery.str("");
7323      myquery << " DELETE FROM GL_ROOT WHERE ID=" <<this->GetID_ROOT() <<";";
7324      //
7325      if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
7326      //
7327      conn->Query(myquery.str().c_str());  //
7328      //
7329      if ( !chewbacca ){
7330        myquery.str("");
7331        myquery << " DELETE FROM GL_TIMESYNC WHERE ID=" << idtsy <<";";
7332        //
7333        if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
7334        //
7335        conn->Query(myquery.str().c_str());
7336      };
7337      //
7338  };  };
7339    
7340  /**  /**
# Line 7374  UInt_t PamelaDBOperations::ValidateTrkCa Line 7684  UInt_t PamelaDBOperations::ValidateTrkCa
7684    
7685    
7686  }  }
 // UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){  
   
 //     if(!caltrk || !eh) return 0;  
   
 //   Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0};  
 //   UInt_t timeaftercalib=120000; //2000;  
 //   //  ----------  
 //   //  Check CRCs  
 //   //  ----------  
 //   for(Int_t ipkt=0; ipkt<6; ipkt++){  
 //     if( caltrk->crc_hcal[ipkt] )return 0; // :-(  
 //     for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-(  
 //   }  
 //   //  -----------------------  
 //   //  Check missing packets:  
 //   //  -----------------------  
 //   //    Readout order:  
 //   //    ------------------  
 //   //    DSP   packet board  
 //   //    ------------------  
 //   //    12    0      1  
 //   //    10    1      1  
 //   //     8    2      1  
 //   //     4    3      1  
 //   //     6    4      1  
 //   //     2    5      1  
 //   //    ------------------  
 //   //    11    0      2  
 //   //     9    1      2  
 //   //     7    2      2  
 //   //     3    3      2  
 //   //     5    4      2  
 //   //     1    5      2  
 //   //    ------------------  
 //   //  -------------------------------------------------  
 //   //  Check if it is first or second calibration packet  
 //   //  -------------------------------------------------  
 //   UInt_t build=0;  
 //   TString classname = caltrk->GetName();  
 //   UInt_t base=0;  
 //   UInt_t mask=0;  
 //   if(classname.Contains("CalibTrk1Event")){  
 //     base=12;  
 //     mask=0x03F000;  
 //   }  
 //   if(classname.Contains("CalibTrk2Event")){  
 //     base=18;  
 //     mask=0xFC0000;  
 //   }  
 //   //  -------------------------------------------------  
 //   //  Count number of packets and set build variable  
 //   //  -------------------------------------------------  
 //   Int_t  npkts=0;  
 //   for(Int_t ipkt=0; ipkt<6; ipkt++){  
 //     if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){  
 //       npkts++;  
 //       build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) );  
 //     }  
 //   }  
 //   //    if( npkts==6 )return 1; // :-)  
   
 //   //    cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl;  
   
 //   //  -----------------------------------------------  
 //   //  If missing packets: check the acq configuration  
 //   //  (some DSPs might be excluded from acquisition)  
 //   //  -----------------------------------------------  
   
 //   //  -----------------------------------------------  
 //   //  retrieve the first run header after calib  
 //   //  -----------------------------------------------  
 //   PacketType *pctp;  
 //   EventCounter *cod;  
 //   cod = eh->GetCounter();  
 //   Int_t irun = cod->Get(pctp->RunHeader);  
 //   TTree *rh=(TTree*)file->Get("RunHeader");  
 //   if ( !rh || rh->IsZombie() ) throw -17;  
 //   if( rh->GetEntries() == irun ){  
 //     if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1)  -- cannot validate :-( "<<endl;  
 //     return 0; // :-(  
 //   }  
   
 //   RunHeaderEvent *run  = 0;  
 //   EventHeader    *hrun = 0;  
 //   rh->SetBranchAddress("RunHeader", &run);  
 //   rh->SetBranchAddress("Header", &hrun);  
 //   rh->GetEntry(irun);  
 //   //     cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl;  
   
 //   if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){  
 //     if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl;  
 //     return 0; // :-(  
 //   }  
       
 //   if( !run->RM_ACQ_AFTER_CALIB ){  
 //     if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0    -- cannot validate :-( "<<endl;  
 //     return 0; // :-(  
 //   }  
   
 //   UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime());  
 //   if( dtime > timeaftercalib ){  
 //     if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl;  
 //     return 0; // :-(  
 //   }  
       
   
   
 //   if( (run->ACQ_BUILD_INFO & mask) != build ){  
 //     if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl;  
 //     return 0; // :-(  
 //   }  
 //   return 1; // :-)  
   
 // }  
7687    
7688  /**  /**
7689   *   *

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.29

  ViewVC Help
Powered by ViewVC 1.1.23