/[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.26 by mocchiut, Wed Nov 25 09:39:50 2009 UTC revision 1.38 by mocchiut, Fri Oct 10 13:00:12 2014 UTC
# Line 88  PamelaDBOperations::PamelaDBOperations(T Line 88  PamelaDBOperations::PamelaDBOperations(T
88    //    //
89    glrun = new GL_RUN();    glrun = new GL_RUN();
90    //    //
91    if ( !chewbacca ){    //   if ( !chewbacca ){
92      if ( !boot ) SetNOBOOT(false);    //     if ( !boot ) SetNOBOOT(false);
93      SetTsync(tsync,gpamela);    //     SetTsync(tsync,gpamela);
94      SetBOOTnumber(boot,gpamela);    //     SetBOOTnumber(boot,gpamela);
95      SetObt0(obt0);    //     SetObt0(obt0);
96    };    //   };
97    //    //
98    SetTLEPath(tlefilename);    SetTLEPath(tlefilename);
99    //    //
# Line 126  void PamelaDBOperations::Close(){ Line 126  void PamelaDBOperations::Close(){
126  //  //
127  // SETTERS  // SETTERS
128  //  //
129    void PamelaDBOperations::NotChewbacca(UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t gpamela){
130      if ( !boot ) SetNOBOOT(false);
131      SetTsync(tsync,gpamela);
132      SetBOOTnumber(boot,gpamela);
133      SetObt0(obt0);
134    };
135    
136  void PamelaDBOperations::OpenL0File(TString filerootname){  void PamelaDBOperations::OpenL0File(TString filerootname){
137    if( INSERT_ROOT ){    if( INSERT_ROOT ){
# Line 183  void PamelaDBOperations::OpenL0File(TStr Line 189  void PamelaDBOperations::OpenL0File(TStr
189            chboot = (UInt_t)atoll(row2->GetField(5));            chboot = (UInt_t)atoll(row2->GetField(5));
190            //            //
191            if ( !chboot ){            if ( !chboot ){
192                if ( debug ) printf(" mmm... no BOOT number determined by chewbacca, try to find it looking at DB \n");
193                //
194                // new feature: check in ROOT_TABLE (timewise) the previous and the next BOOT number != 0 , if it is the same we know this one!
195                // if it is different roll back to the old behaviour
196                //
197              qu.str("");              qu.str("");
198              //      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;";              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;";
             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]  
199              if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());              if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());
200                UInt_t chbootA = 0;
201                UInt_t chbootB = 1;
202              result3 = conn->Query(qu.str().c_str());              result3 = conn->Query(qu.str().c_str());
203              if ( result3 ){              if ( result3 ){
204                row3 = result3->Next();                row3 = result3->Next();
205                if ( row3 && result3->GetRowCount() == 1 ){                if ( row3 ){
206                  chboot = (UInt_t)atoll(row3->GetField(0));                  chbootA = (UInt_t)atoll(row3->GetField(0));
207                  if ( debug ) printf(" Found boot_number = %u \n",chboot);                  if ( debug ) printf(" Found boot_number A = %u \n",chbootA);
208                } else {                };
209                  if ( debug ) printf(" AGH CANNOT DETERMINE THE BOOT NUMBER... \n");              };
210                  throw -29;              delete result3;
211                qu.str("");
212                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;";
213                if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());
214                result3 = conn->Query(qu.str().c_str());
215                if ( result3 ){
216                  row3 = result3->Next();
217                  if ( row3 ){
218                    chbootB = (UInt_t)atoll(row3->GetField(0));
219                    if ( debug ) printf(" Found boot_number B = %u \n",chbootB);
220                  };
221                };
222                if ( chbootA == chbootB ){
223                  chboot = chbootA;
224                  if ( debug ) printf(" Found boot_number! it is %u \n",chboot);
225                } else {        
226                  qu.str("");
227                  //            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;";
228                  //            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]
229                  qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND ABS(LAST_TIME_SYNC_INFO-"<< (float)chlastts <<")<50000 AND ABS(REAL_TIME_INIT-"<< atof(row2->GetField(10)) <<")<50000 group by BOOT_NUMBER order by BOOT_NUMBER asc;"; // even more relaxed conditions... 091214 [9REDtest3: error -29] // 10RED MYSQL operators BUG:
230                  /*
231    
232    mysql> select CAST(1322000646 AS UNSIGNED INTEGER)-1322017203.;
233    +--------------------------------------------------+
234    | CAST(1322000646 AS UNSIGNED INTEGER)-1322017203. |
235    +--------------------------------------------------+
236    |                                           -16557 |
237    +--------------------------------------------------+
238    1 row in set (0.06 sec)
239    
240    mysql> select CAST(1322000646 AS UNSIGNED INTEGER)-1322017203;
241    +-------------------------------------------------+
242    | CAST(1322000646 AS UNSIGNED INTEGER)-1322017203 |
243    +-------------------------------------------------+
244    |                            18446744073709535059 |
245    +-------------------------------------------------+
246    1 row in set (0.02 sec)
247    
248                  */
249                  if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());
250                  result3 = conn->Query(qu.str().c_str());
251                  if ( result3 ){
252                    row3 = result3->Next();
253                    if ( row3 && result3->GetRowCount() == 1 ){
254                      chboot = (UInt_t)atoll(row3->GetField(0));
255                      if ( debug ) printf(" Found boot_number = %u \n",chboot);
256                    } else {
257                      if ( debug ) printf(" AGH CANNOT DETERMINE THE BOOT NUMBER... \n");
258                      throw -29;
259                    };
260                };                };
261              };              };
262            };            };
# Line 1305  void PamelaDBOperations::CheckConnection Line 1366  void PamelaDBOperations::CheckConnection
1366    stringstream oss;    stringstream oss;
1367    //      //  
1368    oss.str("");    oss.str("");
1369    oss << "SET time_zone='+0:00';";    oss << "SET time_zone='+0:00'; SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';";
1370    TSQLResult *result = 0;    TSQLResult *result = 0;
1371    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
1372    if ( !result ) throw -10;    if ( !result ) throw -10;
# Line 1688  Int_t PamelaDBOperations::insertPamelaGL Line 1749  Int_t PamelaDBOperations::insertPamelaGL
1749      TYPE = 0;      TYPE = 0;
1750      TSYNC = 0;      TSYNC = 0;
1751      //      //
1752      Double_t minimum = 0.;      //    Double_t minimum = 0.;
1753      Double_t maximum = 0.;      // Double_t maximum = 0.;
1754      Double_t minimum2 = 0.;      //Double_t minimum2 = 0.;
1755      Double_t maximum2 = 0.;      Double_t maximum2 = 0.;
1756      //      //
1757      //      //
# Line 1698  Int_t PamelaDBOperations::insertPamelaGL Line 1759  Int_t PamelaDBOperations::insertPamelaGL
1759      pamela::McmdRecord *mcrc = 0;      pamela::McmdRecord *mcrc = 0;
1760      TArrayC *mcmddata = 0;      TArrayC *mcmddata = 0;
1761      //      //
1762      minimum = numeric_limits<Double_t>::max();      //    minimum = numeric_limits<Double_t>::max();
1763      maximum = numeric_limits<Double_t>::min();      //    maximum = numeric_limits<Double_t>::min();
1764      minimum2 = numeric_limits<Double_t>::max();      //    minimum2 = numeric_limits<Double_t>::max();
1765      maximum2 = numeric_limits<Double_t>::min();      maximum2 = numeric_limits<Double_t>::min();
1766      //      //
1767      T = (TTree*)file->Get("Mcmd");      T = (TTree*)file->Get("Mcmd");
# Line 2120  Int_t PamelaDBOperations::assignBOOT_NUM Line 2181  Int_t PamelaDBOperations::assignBOOT_NUM
2181      UInt_t lowerts = tsync-(obt0/1000)-5;      UInt_t lowerts = tsync-(obt0/1000)-5;
2182      if ( chewbacca ){      if ( chewbacca ){
2183        oss.str("");        oss.str("");
2184        oss << "select BOOT_NUMBER from ROOT_TABLE where LAST_TIME_SYNC_INFO-(OBT_TIME_SYNC)<"        oss << "select BOOT_NUMBER from ROOT_TABLE where CAST((LAST_TIME_SYNC_INFO-(OBT_TIME_SYNC)) AS SIGNED INT)<" // 10RED MYSQL OPERATORS BUG
2185            << upperts            << upperts
2186            << " AND LAST_TIME_SYNC_INFO-(OBT_TIME_SYNC)>"            << " AND CAST((LAST_TIME_SYNC_INFO-(OBT_TIME_SYNC)) AS SIGNED INT)>" // 10RED MYSQL OPERATORS BUG
2187            << lowerts            << lowerts
2188            << " AND BOOT_NUMBER>1;";            << " AND BOOT_NUMBER>1;";
2189      } else {      } else {
2190        oss.str("");        oss.str("");
2191        oss << "select GL_RAW.BOOT_NUMBER from GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW where TIMESYNC-(OBT0/1000)<"        oss << "select GL_RAW.BOOT_NUMBER from GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW where CAST((TIMESYNC-(OBT0/1000)) AS SIGNED INT)<" // 10RED MYSQL OPERATORS BUG
2192            << upperts            << upperts
2193            << " AND TIMESYNC-(OBT0/1000)>"            << " AND CAST((TIMESYNC-(OBT0/1000)) AS SIGNED INT)>" // 10RED MYSQL OPERATORS BUG
2194            << lowerts            << lowerts
2195            << " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;";            << " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;";
2196      };      };
# Line 2228  Int_t PamelaDBOperations::insertPamelaRU Line 2289  Int_t PamelaDBOperations::insertPamelaRU
2289    //    //
2290    // no runtrailers in the file!    // no runtrailers in the file!
2291    //    //
2292    if ( !rtev ){    if ( IsDebug() ) printf(" Start rtev %i rhev %i nrtev %i nrhev %i \n",rtev,rhev,nrtev,nrhev);
2293      if ( !rhev ){    if ( !rtev || (chewbacca && !nrtev) ){
2294        if ( IsDebug() ) printf(" No runtrailers \n");
2295        if ( !rhev || (chewbacca && !nrhev) ){
2296        if ( IsDebug() ) printf(" No runheaders nor runtrailers!! \n");        if ( IsDebug() ) printf(" No runheaders nor runtrailers!! \n");
2297        if ( !(upperentry-chminentry) ){        if ( !(upperentry-chminentry) ){
2298          if ( IsDebug() ) printf(" No physics events nor runs in the file \n"); // di nuovo potrebbe esserci un runtrailer senza eventi (riempimento MM)          if ( IsDebug() ) printf(" No physics events nor runs in the file \n"); // di nuovo potrebbe esserci un runtrailer senza eventi (riempimento MM)
# Line 2266  Int_t PamelaDBOperations::insertPamelaRU Line 2329  Int_t PamelaDBOperations::insertPamelaRU
2329      //      //
2330    } else {    } else {
2331      //      //
2332        if ( IsDebug() ) printf(" We have runtrailers \n");
2333      Int_t conptt = -1;      Int_t conptt = -1;
2334      for (Int_t ptt=0; ptt<rtev; ptt++){      for (Int_t ptt=0; ptt<rtev; ptt++){
2335        //        //
# Line 2912  void PamelaDBOperations::HandleRunFragme Line 2976  void PamelaDBOperations::HandleRunFragme
2976          if ( IsDebug() ) printf(" here firstev is %i lastev is %i \n",firstev,lastev);          if ( IsDebug() ) printf(" here firstev is %i lastev is %i \n",firstev,lastev);
2977          //          //
2978          glrun->SetEV_FROM(firstev);          glrun->SetEV_FROM(firstev);
2979            glrun->SetEV_TO(lastev); // EM 10 RED ghost run bug
2980          glrun->SetNEVENTS(lastev-firstev+1);          glrun->SetNEVENTS(lastev-firstev+1);
2981          //          //
2982          glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME());          glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME());
# Line 3107  void PamelaDBOperations::HandleRunFragme Line 3172  void PamelaDBOperations::HandleRunFragme
3172          };          };
3173          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);
3174          //          //
3175            glrun->SetEV_FROM(firstev); // EM 10RED ghost run bug
3176          glrun->SetEV_TO(lastev);          glrun->SetEV_TO(lastev);
3177          glrun->SetNEVENTS(lastev-firstev+1);          glrun->SetNEVENTS(lastev-firstev+1);
3178          glrun->SetPKT_COUNTER(glrun1->GetPKT_COUNTER());          glrun->SetPKT_COUNTER(glrun1->GetPKT_COUNTER());
# Line 3199  void PamelaDBOperations::HandleRunFragme Line 3265  void PamelaDBOperations::HandleRunFragme
3265          // "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number.          // "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number.
3266          //          //
3267          // 090112 [8RED (-70): RUN ALREADY INSERTED]          // 090112 [8RED (-70): RUN ALREADY INSERTED]
3268            // 093012 [8RED (-70): RUN ALREADY INSERTED] try to be more general... the run has not been instered yet if the runheader-trailer PKT interval is not covered by already inserted runs, NOTICE: we must look in the GL_RUN_TRASH table!
3269          //          //
3270          Bool_t OK = false;          Bool_t OK = false;
3271          UInt_t IDRL2A = 0;          UInt_t IDRL2A = 0;
3272          UInt_t IDRL2B = 0;          UInt_t IDRL2B = 0;
3273          if ( chewbacca ){          if ( chewbacca ){
3274            if ( result->GetRowCount() == 2 ){            if ( result->GetRowCount() >= 2 ){
3275                //
3276                if ( IsDebug() ) printf(" RH---| gap |---RT case, number of pieces in the GL_RUN table: %i \n",result->GetRowCount());
3277                OK = true;
3278              IDRL2A = (UInt_t)atoll(row->GetField(0));              IDRL2A = (UInt_t)atoll(row->GetField(0));
3279              UInt_t IDRL0A = (UInt_t)atoll(row->GetField(1));              //
3280              row = result->Next();              while ( row ){
             IDRL2B = (UInt_t)atoll(row->GetField(0));  
             UInt_t IDRL0B = (UInt_t)atoll(row->GetField(1));  
             if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B);  
             if ( IDRL0A == IDRL0B ){  
               TSQLResult *result2 = 0;  
               TSQLRow    *row2    = 0;  
               oss.str("");  
               oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;";  
               if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());  
               result2 = conn->Query(oss.str().c_str());  
3281                //                //
3282                if ( !result2 ) throw -4;                TSQLResult *trresult = 0;
3283                  TSQLRow    *trrow    = 0;
3284                //                //
3285                row2 = result2->Next();                stringstream tross;
3286                  tross.str("");
3287                //                //
3288                if ( row2 ){                tross << " SELECT RUNHEADER_PKT, RUNTRAILER_PKT FROM GL_RUN_TRASH where ID=" << row->GetField(0) << ";";
3289                  UInt_t PKA = (UInt_t)atoll(row2->GetField(0));                if ( IsDebug() ) printf(" check in the gl_run_trash table for pkt intervals: query is \n %s \n",tross.str().c_str());
3290                  delete result2;                trresult = conn->Query(tross.str().c_str());
3291                  oss.str("");                if ( !trresult ) throw -4;
3292                  oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;";                trrow = trresult->Next();
3293                  if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());                if ( !trrow || trresult->GetRowCount() != 1 ){
3294                  result2 = conn->Query(oss.str().c_str());                  OK = false;
3295                  //                  if ( IsDebug() ) printf(" OPS! no such run (or multiple runs!) in GL_RUN_TRASH table, something wrong is going on! \n");
3296                  if ( !result2 ) throw -4;                  break;
3297                  //                };
3298                  row2 = result2->Next();                //
3299                  //                UInt_t pktH =  (UInt_t)atoll(row->GetField(0));
3300                  if ( row2 ){                UInt_t pktT =  (UInt_t)atoll(row->GetField(1));
3301                    UInt_t PKB = (UInt_t)atoll(row2->GetField(0));                delete trresult;
3302                    //                if (
3303                    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);                    (PKT(pktH) >= PKT(glrun->GetRUNHEADER_PKT()) && PKT(pktH) <= PKT(glrun->GetRUNTRAILER_PKT())) ||
3304                    if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){                    (PKT(pktT) >= PKT(glrun->GetRUNHEADER_PKT()) && PKT(pktT) <= PKT(glrun->GetRUNTRAILER_PKT())) ||
3305                      if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n");                    (PKT(pktH) <= PKT(glrun->GetRUNTRAILER_PKT()) && PKT(pktT) >= PKT(glrun->GetRUNTRAILER_PKT())) ){            
3306                      OK = true;                  OK = false;
3307                    };                  if ( IsDebug() ) printf(" The run is overlapping with already inserted ones!! \n");
3308                  };                  break;          
3309                };                                  };
3310                  //PKT(glrun->GetRUNHEADER_PKT())  PKT(glrun->GetRUNTRAILER_PKT())
3311                  row = result->Next();
3312              };              };
3313            };                    
3314                //    if ( result->GetRowCount() == 2 ) {
3315                //      IDRL2A = (UInt_t)atoll(row->GetField(0));
3316                //      UInt_t IDRL0A = (UInt_t)atoll(row->GetField(1));
3317                //      row = result->Next();
3318                //      IDRL2B = (UInt_t)atoll(row->GetField(0));
3319                //      UInt_t IDRL0B = (UInt_t)atoll(row->GetField(1));
3320                //      if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B);
3321                //      //      if ( IDRL0A == IDRL0B ){ //091230 why this condition???? RH could be in a file and RT in another one...
3322                //      if ( true ){
3323                //        TSQLResult *result2 = 0;
3324                //        TSQLRow    *row2    = 0;
3325                //        oss.str("");
3326                //        oss << "select PKT_NUMBER_FINAL from ROOT_TABLE_MERGING where REAL_TIME_INIT<" << chrtinit << " order by REAL_TIME_INIT desc limit 1;";
3327                //        if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
3328                //        result2 = conn->Query(oss.str().c_str());
3329                //        //
3330                //        if ( !result2 ) throw -4;
3331                //        //
3332                //        row2 = result2->Next();
3333                //        //
3334                //        if ( row2 ){
3335                //          UInt_t PKA = (UInt_t)atoll(row2->GetField(0));
3336                //          delete result2;
3337                //          oss.str("");
3338                //          oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc limit 1;";
3339                //          if ( IsDebug() ) printf(" Check if we are in the case RH---| small gap |---RT: query is \n %s \n",oss.str().c_str());
3340                //          result2 = conn->Query(oss.str().c_str());
3341                //          //
3342                //          if ( !result2 ) throw -4;
3343                //          //
3344                //          row2 = result2->Next();
3345                //          //
3346                //          if ( row2 ){
3347                //            UInt_t PKB = (UInt_t)atoll(row2->GetField(0));
3348                //            //
3349                //            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);
3350                //            if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){
3351                //              if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n");
3352                //              OK = true;
3353                //            };
3354                //          };
3355                //        };                  
3356                //      };
3357                //    };      
3358              };
3359          };          };
3360          if ( OK ){          if ( OK ){
3361            //            //
3362            // this is the case in which we must insert a piece of run between two fragments in the GL_RUN table            // this is the case in which we must insert a piece of run between two fragments in the GL_RUN table // we arrive here ONLY with internal pieces of runs, never runheader or runtrailer by definition  
3363            //            //
3364            // 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 )            // 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 )
3365            //            //
3366              if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n");
3367              //
3368            GL_RUN *glA = new GL_RUN();            GL_RUN *glA = new GL_RUN();
3369            glA->Query_GL_RUN(IDRL2A,conn);            glA->Query_GL_RUN(IDRL2A,conn);
3370            //            //
3371              glrun->SetRUNHEADER_TIME(glA->GetRUNHEADER_TIME());
3372              glrun->SetRUNHEADER_OBT(glA->GetRUNHEADER_OBT());
3373              glrun->SetRUNHEADER_PKT(glA->GetRUNHEADER_PKT());
3374              //
3375              glrun->SetRUNTRAILER_TIME(glA->GetRUNTRAILER_TIME());
3376              glrun->SetRUNTRAILER_OBT(glA->GetRUNTRAILER_OBT());
3377              glrun->SetRUNTRAILER_PKT(glA->GetRUNTRAILER_PKT());
3378              //
3379              if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) glrun->SetPHYSENDRUN_MASK_S3S2S12(glA->GetPHYSENDRUN_MASK_S3S2S12());
3380              if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) glrun->SetPHYSENDRUN_MASK_S11CRC(glA->GetPHYSENDRUN_MASK_S11CRC());
3381              //          
3382            if ( glA->GetACQ_BUILD_INFO() != 0 ){            if ( glA->GetACQ_BUILD_INFO() != 0 ){
3383              //              //
3384              // the first piece contains a good runheader we can update all the other runs with correct infos!              // the first piece contains a good runheader we can update all the other runs with correct infos!
3385              //              //
3386              oss.str("");              glrun->SetCOMPILATIONTIMESTAMP(glA->GetCOMPILATIONTIMESTAMP());
3387              oss << "UPDATE GL_RUN_FRAGMENTS SET "              glrun->SetFAV_WRK_SCHEDULE(glA->GetFAV_WRK_SCHEDULE());
3388                  << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "              glrun->SetEFF_WRK_SCHEDULE(glA->GetEFF_WRK_SCHEDULE());
3389                  << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "              glrun->SetPRH_VAR_TRG_MODE_A(glA->GetPRH_VAR_TRG_MODE_A());
3390                  << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , "              glrun->SetPRH_VAR_TRG_MODE_B(glA->GetPRH_VAR_TRG_MODE_B());
3391                  << " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , "              glrun->SetACQ_BUILD_INFO(glA->GetACQ_BUILD_INFO());
3392                  << " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , "              glrun->SetACQ_VAR_INFO(glA->GetACQ_VAR_INFO());
3393                  << " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , "              glrun->SetRM_ACQ_AFTER_CALIB(glA->GetRM_ACQ_AFTER_CALIB());
3394                  << " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , "              glrun->SetRM_ACQ_SETTING_MODE(glA->GetRM_ACQ_SETTING_MODE());
3395                  << " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , "              glrun->SetTRK_CALIB_USED(glA->GetTRK_CALIB_USED());
3396                  << " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , "              glrun->SetCAL_DSP_MASK(glA->GetCAL_DSP_MASK());
3397                  << " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , "              glrun->SetLAST_TIMESYNC(glA->GetLAST_TIMESYNC());
3398                  << " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , "                glrun->SetOBT_TIMESYNC(glA->GetOBT_TIMESYNC());
                 << " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , "    
                 << " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , "    
                 << " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , "    
                 << " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , ";  
3399              //              //
3400              if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )            };
3401                oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , ";            //
3402              if ( glA->GetPHYSENDRUN_MASK_S11CRC() )            if ( glA->GetPKT_READY_COUNTER() != 0 ){
               oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , ";  
             //          
             oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC();  
             oss << " WHERE ID=" << glrun->GetID() << ";";  
             if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str());  
             conn->Query(oss.str().c_str());      
             //  
           } else {  
             //  
             // sig no runheader, let set anyway what is possible...  
3403              //              //
3404              oss.str("");              // the first piece contains a good runtrailer we can update all the other runs with correct infos!
             oss << "UPDATE GL_RUN_FRAGMENTS SET "  
                 << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , ";  
3405              //              //
3406              if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )              glrun->SetPKT_COUNTER(glA->GetPKT_COUNTER());
3407                oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , ";              glrun->SetPKT_READY_COUNTER(glA->GetPKT_READY_COUNTER());
             if ( glA->GetPHYSENDRUN_MASK_S11CRC() )  
               oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , ";  
             //          
             oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "  
                 << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT();  
             oss << " WHERE ID=" << glrun->GetID() << ";";  
             if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str());  
             conn->Query(oss.str().c_str());      
3408            };            };
3409            //            //
3410            // update runheader ROOT_ID_FRAG            // update runheader ROOT_ID_FRAG
# Line 3316  void PamelaDBOperations::HandleRunFragme Line 3414  void PamelaDBOperations::HandleRunFragme
3414            if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str());            if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str());
3415            conn->Query(oss.str().c_str());            conn->Query(oss.str().c_str());
3416            //            //
           // now let's look for runtrailer if any in the last run  
           //  
           glA->Query_GL_RUN(IDRL2B,conn);  
           //  
           if ( glA->GetPKT_READY_COUNTER() != 0 ){  
             //  
             // the first piece contains a good runtrailer we can update all the other runs with correct infos!  
             //  
             oss.str("");  
             oss << "UPDATE GL_RUN_FRAGMENTS SET "  
                 << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "  
                 << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "  
                 << " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , "  
                 << " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , ";  
             //  
             if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){  
               oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };  
             if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) {  
               oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };  
             //          
             oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER()  
                 << " WHERE ID=" << glrun->GetID() << ";";  
             if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str());  
             conn->Query(oss.str().c_str());      
             //  
           } else {  
             //  
             // sig no runtrailer, let set anyway what is possible...  
             //  
             oss.str("");  
             oss << "UPDATE GL_RUN_FRAGMENTS SET "  
                 << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "  
                 << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , ";  
               //  
             if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){  
               oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };  
             if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){  
               oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };  
             //          
             oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()  
                 << " WHERE ID=" << glrun->GetID() << ";";  
             if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str());  
             conn->Query(oss.str().c_str());      
           };  
           //  
           UInt_t myi = glrun->GetID();  
3417            oss.str("");            oss.str("");
3418            oss << " ID= "<< myi;            oss << "SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG = " << IDRL2A << ";";
3419            //            if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str());
3420            glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);              TSQLResult *tsresult = 0;
3421              TSQLRow    *tsrow    = 0;
3422              tsresult=conn->Query(oss.str().c_str());
3423              if ( !tsresult ) throw -4;
3424              tsrow = tsresult->Next();
3425              if ( !tsrow || tsresult->GetRowCount() != 1 ) throw -4;
3426              IDRL2B = (UInt_t)atoll(tsrow->GetField(0));
3427              glrun->SetID_RUN_FRAG(IDRL2B);
3428            //            //
3429            // fill the new run in GL_RUN            // fill the new run in GL_RUN
3430            //            //
           glrun->SetID_RUN_FRAG(IDRL2B);  
3431            glrun->Fill_GL_RUN(conn);                glrun->Fill_GL_RUN(conn);    
3432              //
3433            glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");            glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
3434            delete glA;            delete glA;
3435            //            //
3436          } else {          } else {
3437    //        //
3438    //        // this is the case in which we must insert a piece of run between two fragments in the GL_RUN table
3439    //        //
3440    //        // 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 )
3441    //        //
3442    //        GL_RUN *glA = new GL_RUN();
3443    //        glA->Query_GL_RUN(IDRL2A,conn);
3444    //        //
3445    //        if ( glA->GetACQ_BUILD_INFO() != 0 ){
3446    //          //
3447    //          // the first piece contains a good runheader we can update all the other runs with correct infos!
3448    //          //
3449    //          oss.str("");
3450    //          oss << "UPDATE GL_RUN_FRAGMENTS SET "
3451    //              << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "
3452    //              << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
3453    //              << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , "
3454    //              << " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , "
3455    //              << " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , "
3456    //              << " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , "
3457    //              << " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , "
3458    //              << " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , "
3459    //              << " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , "
3460    //              << " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , "
3461    //              << " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , "  
3462    //              << " RM_ACQ_SETTING_MODE=" << glA->GetRM_ACQ_SETTING_MODE()<< " , "  
3463    //              << " TRK_CALIB_USED=" << glA->GetTRK_CALIB_USED()<< " , "  
3464    //              << " CAL_DSP_MASK=" << glA->GetCAL_DSP_MASK()<< " , "  
3465    //              << " LAST_TIMESYNC=" << glA->GetLAST_TIMESYNC()<< " , ";
3466    //          //
3467    //          if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
3468    //            oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12() << " , ";
3469    //          if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
3470    //            oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC() << " , ";
3471    //          //        
3472    //          oss << " OBT_TIMESYNC=" << glA->GetOBT_TIMESYNC();
3473    //          oss << " WHERE ID=" << glrun->GetID() << ";";
3474    //          if ( IsDebug() ) printf(" update with correct infos: %s\n",oss.str().c_str());
3475    //          conn->Query(oss.str().c_str());    
3476    //          //
3477    //        } else {
3478    //          //
3479    //          // sig no runheader, let set anyway what is possible...
3480    //          //
3481    //          oss.str("");
3482    //          oss << "UPDATE GL_RUN_FRAGMENTS SET "
3483    //              << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , ";
3484    //          //
3485    //          if ( glA->GetPHYSENDRUN_MASK_S3S2S12() )
3486    //            oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , ";
3487    //          if ( glA->GetPHYSENDRUN_MASK_S11CRC() )
3488    //            oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , ";
3489    //          //        
3490    //          oss << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , "
3491    //              << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT();
3492    //          oss << " WHERE ID=" << glrun->GetID() << ";";
3493    //          if ( IsDebug() ) printf(" update with correct infos2: %s\n",oss.str().c_str());
3494    //          conn->Query(oss.str().c_str());    
3495    //        };
3496    //        //
3497    //        // update runheader ROOT_ID_FRAG
3498    //        //
3499    //        oss.str("");
3500    //        oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";";
3501    //        if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str());
3502    //        conn->Query(oss.str().c_str());
3503    //        //
3504    //        // now let's look for runtrailer if any in the last run
3505    //        //
3506    //        glA->Query_GL_RUN(IDRL2B,conn);
3507    //        //
3508    //        if ( glA->GetPKT_READY_COUNTER() != 0 ){
3509    //          //
3510    //          // the first piece contains a good runtrailer we can update all the other runs with correct infos!
3511    //          //
3512    //          oss.str("");
3513    //          oss << "UPDATE GL_RUN_FRAGMENTS SET "
3514    //              << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
3515    //              << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , "
3516    //              << " RUNTRAILER_PKT=" << glA->GetRUNTRAILER_PKT()<< " , "
3517    //              << " PKT_COUNTER=" << glA->GetPKT_COUNTER()<< " , ";
3518    //          //
3519    //          if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
3520    //            oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
3521    //          if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) {
3522    //            oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
3523    //          //        
3524    //          oss << " PKT_READY_COUNTER=" << glA->GetPKT_READY_COUNTER()
3525    //              << " WHERE ID=" << glrun->GetID() << ";";
3526    //          if ( IsDebug() ) printf(" update with correct trailer infos: %s\n",oss.str().c_str());
3527    //          conn->Query(oss.str().c_str());    
3528    //          //
3529    //        } else {
3530    //          //
3531    //          // sig no runtrailer, let set anyway what is possible...
3532    //          //
3533    //          oss.str("");
3534    //          oss << "UPDATE GL_RUN_FRAGMENTS SET "
3535    //              << " RUNTRAILER_TIME=" << glA->GetRUNTRAILER_TIME()<< " , "
3536    //              << " RUNTRAILER_OBT=" << glA->GetRUNTRAILER_OBT()<< " , ";
3537    //            //
3538    //          if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ){
3539    //            oss << " PHYSENDRUN_MASK_S3S2S12=" << glA->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; };
3540    //          if ( glA->GetPHYSENDRUN_MASK_S11CRC() ){
3541    //            oss << " PHYSENDRUN_MASK_S11CRC=" << glA->GetPHYSENDRUN_MASK_S11CRC()<< " , "; };
3542    //          //        
3543    //          oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()
3544    //              << " WHERE ID=" << glrun->GetID() << ";";
3545    //          if ( IsDebug() ) printf(" update with correct trailer infos2: %s\n",oss.str().c_str());
3546    //          conn->Query(oss.str().c_str());    
3547    //        };
3548    //        //
3549    //        UInt_t myi = glrun->GetID();
3550    //        oss.str("");
3551    //        oss << " ID= "<< myi;
3552    //        //
3553    //        glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn);  
3554    //        //
3555    //        // fill the new run in GL_RUN
3556    //        //
3557    //        glrun->SetID_RUN_FRAG(IDRL2B);
3558    //        glrun->Fill_GL_RUN(conn);    
3559    //        glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
3560    //        delete glA;
3561    //        //
3562    //      } else {
3563            //            //
3564            // is just a repetition            // is just a repetition
3565            //            //
# Line 3434  Bool_t PamelaDBOperations::IsRunConsiste Line 3619  Bool_t PamelaDBOperations::IsRunConsiste
3619    //      //  
3620    EventCounter *code=0;    EventCounter *code=0;
3621    //    //
3622    UInt_t nevent = 0;    //  UInt_t nevent = 0;
3623    UInt_t checkfirst = 0;    UInt_t checkfirst = 0;
3624    UInt_t checklast = 0;    UInt_t checklast = 0;
3625    UInt_t firstentry = 0;    UInt_t firstentry = 0;
# Line 3456  Bool_t PamelaDBOperations::IsRunConsiste Line 3641  Bool_t PamelaDBOperations::IsRunConsiste
3641    EventHeader *eh = 0;    EventHeader *eh = 0;
3642    PscuHeader *ph = 0;    PscuHeader *ph = 0;
3643    T->SetBranchAddress("Header", &eh);    T->SetBranchAddress("Header", &eh);
3644    nevent = T->GetEntries();    //  nevent = T->GetEntries();
3645    //    //
3646    //    //
3647    if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run!    if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run!
# Line 3830  Bool_t PamelaDBOperations::IsRunConsiste Line 4015  Bool_t PamelaDBOperations::IsRunConsiste
4015                  glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT());                  glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT());
4016                  //                  //
4017                  glrun->SetEV_FROM(firstev);                  glrun->SetEV_FROM(firstev);
4018                    glrun->SetEV_TO(lastev); // 10 RED ghost run bug
4019                  glrun->SetNEVENTS(lastev-firstev+1);                  glrun->SetNEVENTS(lastev-firstev+1);
4020                  //                  //
4021                  glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME());                  glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME());
# Line 3977  void PamelaDBOperations::HandleSuspiciou Line 4163  void PamelaDBOperations::HandleSuspiciou
4163    EventCounter *code=0;    EventCounter *code=0;
4164    UInt_t firstev = 0;    UInt_t firstev = 0;
4165    UInt_t lastev = 0;    UInt_t lastev = 0;
4166    UInt_t nevent = 0;    //  UInt_t nevent = 0;
4167    UInt_t checkfirst = 0;    UInt_t checkfirst = 0;
4168    UInt_t checklast = 0;    UInt_t checklast = 0;
4169    UInt_t firstentry = 0;    UInt_t firstentry = 0;
# Line 4002  void PamelaDBOperations::HandleSuspiciou Line 4188  void PamelaDBOperations::HandleSuspiciou
4188    EventHeader *eh = 0;    EventHeader *eh = 0;
4189    PscuHeader *ph = 0;    PscuHeader *ph = 0;
4190    T->SetBranchAddress("Header", &eh);    T->SetBranchAddress("Header", &eh);
4191    nevent = T->GetEntries();    //  nevent = T->GetEntries();
4192    //    //
4193    codt = eht->GetCounter();    codt = eht->GetCounter();
4194    codh = ehh->GetCounter();    codh = ehh->GetCounter();
# Line 4258  Int_t PamelaDBOperations::insertCALO_CAL Line 4444  Int_t PamelaDBOperations::insertCALO_CAL
4444          // 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.]          // 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.]
4445          //          //
4446          totped = 0.;          totped = 0.;
4447            Int_t ns = 0;
4448            if ( section == 2 ) ns = 3;
4449            if ( section == 3 ) ns = 1;
4450            if ( section == 1 ) ns = 2;
4451          for (UInt_t ss=0; ss<96; ss++){          for (UInt_t ss=0; ss<96; ss++){
4452            totped += calibCalPed->calped[section][0][ss];            totped += fabs(calibCalPed->calped[ns][0][ss]);
4453          }          }
4454          if ( totped < 1. ){          if ( totped < 1. ){
4455            if ( IsDebug() ) printf(" Section %i totped %f -  No calibration data! Calorimeter power problems? \n",section,totped);            if ( IsDebug() ) printf(" Section %i totped %f -  No calibration data! Calorimeter power problems? \n",section,totped);
# Line 4448  Int_t PamelaDBOperations::insertCALOPULS Line 4638  Int_t PamelaDBOperations::insertCALOPULS
4638            // 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.]            // 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.]
4639            //            //
4640            totpul = 0.;            totpul = 0.;
4641              Int_t ns = 0;
4642              if ( section == 2 ) ns = 3;
4643              if ( section == 3 ) ns = 1;
4644              if ( section == 1 ) ns = 2;
4645            for (UInt_t ss=0; ss<96; ss++){            for (UInt_t ss=0; ss<96; ss++){
4646              totpul += cp1->calpuls[section][0][ss];              totpul += cp1->calpuls[ns][0][ss];
4647            }            }
4648            if ( totpul >= 3145632. ){            if ( totpul >= 3145632. ){
4649              if ( IsDebug() ) printf(" PULSE1 Section %i totpul %f -  No calibration data! Calorimeter power problems? \n",section,totpul);              if ( IsDebug() ) printf(" PULSE1 Section %i totpul %f -  No calibration data! Calorimeter power problems? \n",section,totpul);
# Line 4617  Int_t PamelaDBOperations::insertCALOPULS Line 4811  Int_t PamelaDBOperations::insertCALOPULS
4811            // 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.]            // 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.]
4812            //            //
4813            totpul = 0.;            totpul = 0.;
4814              Int_t ns = 0;
4815              if ( section == 2 ) ns = 3;
4816              if ( section == 3 ) ns = 1;
4817              if ( section == 1 ) ns = 2;
4818            for (UInt_t ss=0; ss<96; ss++){            for (UInt_t ss=0; ss<96; ss++){
4819              totpul += cp2->calpuls[section][0][ss];              totpul += cp2->calpuls[ns][0][ss];
4820            }            }
4821            if ( totpul >= 3145632. ){            if ( totpul >= 3145632. ){
4822              if ( IsDebug() ) printf(" PULSE2 Section %i totpul %f -  No calibration data! Calorimeter power problems? \n",section,totpul);              if ( IsDebug() ) printf(" PULSE2 Section %i totpul %f -  No calibration data! Calorimeter power problems? \n",section,totpul);
# Line 5273  Int_t PamelaDBOperations::insertTRK_CALI Line 5471  Int_t PamelaDBOperations::insertTRK_CALI
5471    
5472          if ( IsDebug() ) cout << endl << ">>>> TRY TO RECOVER TRACKER CALIBRATIONS <<<<"<<endl;          if ( IsDebug() ) cout << endl << ">>>> TRY TO RECOVER TRACKER CALIBRATIONS <<<<"<<endl;
5473    
5474          TSQLResult *result = 0;          TSQLResult *rresult = 0; // 10RED bug, result is re-used inside result looop...
5475            TSQLResult *result = 0; // 10RED bug, result is re-used inside result looop...
5476          TSQLRow    *row    = 0;          TSQLRow    *row    = 0;
5477          //          //
5478          stringstream oss;          stringstream oss;
# Line 5303  Int_t PamelaDBOperations::insertTRK_CALI Line 5502  Int_t PamelaDBOperations::insertTRK_CALI
5502          oss << " ORDER BY ID DESC LIMIT "<<ncalib<<"; ";                  oss << " ORDER BY ID DESC LIMIT "<<ncalib<<"; ";        
5503          if ( IsDebug() ) cout << oss.str().c_str() << endl;          if ( IsDebug() ) cout << oss.str().c_str() << endl;
5504    
5505          result = conn->Query(oss.str().c_str());          rresult = conn->Query(oss.str().c_str());
5506          if ( !result ) throw -4;;          if ( !result ) throw -4;;
5507          if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl;          if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl;
5508                    
# Line 5312  Int_t PamelaDBOperations::insertTRK_CALI Line 5511  Int_t PamelaDBOperations::insertTRK_CALI
5511          // -----------------------------------          // -----------------------------------
5512          UInt_t nn=0;          UInt_t nn=0;
5513          do {          do {
5514              row = result->Next();              row = rresult->Next();
5515              if(!row)break;              if(!row)break;
5516                            
5517              UInt_t id       = (UInt_t)atoll(row->GetField(0));              UInt_t id       = (UInt_t)atoll(row->GetField(0));
# Line 5351  Int_t PamelaDBOperations::insertTRK_CALI Line 5550  Int_t PamelaDBOperations::insertTRK_CALI
5550              TString path       = "";              TString path       = "";
5551              TString name       = "";              TString name       = "";
5552              TString raw        = "";              TString raw        = "";
5553              UInt_t obt0        = 0;              //      UInt_t obt0        = 0;
5554              UInt_t timesync    = 0;              //      UInt_t timesync    = 0;
5555              UInt_t boot_number = 0;              //      UInt_t boot_number = 0;
5556              bool   FOUND       = false;              bool   FOUND       = false;
5557    
5558              if ( IsDebug() ) cout << "------------------------------------------------------------" <<endl;              if ( IsDebug() ) cout << "------------------------------------------------------------" <<endl;
# Line 5426  Int_t PamelaDBOperations::insertTRK_CALI Line 5625  Int_t PamelaDBOperations::insertTRK_CALI
5625                      path       = (TString)row2->GetField(0);                      path       = (TString)row2->GetField(0);
5626                      name       = (TString)row2->GetField(1);                      name       = (TString)row2->GetField(1);
5627                      raw        = (TString)row2->GetField(5);                      raw        = (TString)row2->GetField(5);
5628                      obt0        = (UInt_t)atoll(row2->GetField(2));                      //              obt0        = (UInt_t)atoll(row2->GetField(2));
5629                      timesync    = (UInt_t)atoll(row2->GetField(3));                      //              timesync    = (UInt_t)atoll(row2->GetField(3));
5630                      boot_number = (UInt_t)atoll(row2->GetField(4));                      //              boot_number = (UInt_t)atoll(row2->GetField(4));
5631                                    
5632                      if ( IsDebug() ) cout << "- - - - - - - - - - -" <<endl;                      if ( IsDebug() ) cout << "- - - - - - - - - - -" <<endl;
5633  //                  cout << path <<endl;  //                  cout << path <<endl;
# Line 5492  Int_t PamelaDBOperations::insertTRK_CALI Line 5691  Int_t PamelaDBOperations::insertTRK_CALI
5691                      if(FOUND)break;                      if(FOUND)break;
5692    
5693                  }while(1);//endl loop over root table entries                  }while(1);//endl loop over root table entries
5694                    
5695                    delete result2; // 10RED potential memory leak
5696                  if(FOUND)break;                  if(FOUND)break;
5697    
5698              }//end loop over tables              }//end loop over tables
# Line 5646  Int_t PamelaDBOperations::insertTRK_CALI Line 5846  Int_t PamelaDBOperations::insertTRK_CALI
5846          }while(1);//end loop over calibrations          }while(1);//end loop over calibrations
5847                    
5848                    
5849          if( result )delete result;          if( rresult )delete rresult; // 10RED bug
5850          if( row    )delete row;          if( row    )delete row;
5851                    
5852                    
# Line 5947  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6147  Int_t PamelaDBOperations::CleanGL_RUN_FR
6147      memset(myid,0,500*sizeof(UInt_t));      memset(myid,0,500*sizeof(UInt_t));
6148      //      //
6149      oss.str("");      oss.str("");
6150      oss << "SELECT ID,RUNTRAILER_TIME,RUNTRAILER_PKT,BOOT_NUMBER FROM GL_RUN_FRAGMENTS WHERE INSERT_TIME <= '" << clean_time->AsSQLString() << "'order BY RUNHEADER_TIME asc;";      oss << "SELECT ID,RUNTRAILER_TIME,RUNTRAILER_PKT,BOOT_NUMBER FROM GL_RUN_FRAGMENTS WHERE INSERT_TIME <= '" << clean_time->AsSQLString() << "' order BY RUNHEADER_TIME asc;";
6151      if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str());      if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str());
6152      nresult = conn->Query(oss.str().c_str());      nresult = conn->Query(oss.str().c_str());
6153      //      //
# Line 5978  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6178  Int_t PamelaDBOperations::CleanGL_RUN_FR
6178            while ( anr ){            while ( anr ){
6179              //              //
6180              oss.str("");              oss.str("");
6181              oss << "SELECT ID,RUNTRAILER_TIME,RUNTRAILER_PKT,BOOT_NUMBER FROM GL_RUN_FRAGMENTS WHERE BOOT_NUMBER=" << mbo << " AND RUNHEADER_PKT=" << mrhp <<  "+1 AND ABS(RUNHEADER_TIME-"<< mrht <<")<=1 AND INSERT_TIME <= '" << clean_time->AsSQLString() << "' order BY RUNHEADER_TIME asc;";              oss << "SELECT ID,RUNTRAILER_TIME,RUNTRAILER_PKT,BOOT_NUMBER FROM GL_RUN_FRAGMENTS WHERE BOOT_NUMBER=" << mbo << " AND RUNHEADER_PKT=" << mrhp <<  "+1 AND ABS(RUNHEADER_TIME-"<< (float)mrht <<")<=1 AND INSERT_TIME <= '" << clean_time->AsSQLString() << "' order BY RUNHEADER_TIME asc;"; // 10RED MYSQL OPERATOR BUG
6182              if ( IsDebug() ) printf(" In the loop searching for fragmented runs : query is \n %s \n",oss.str().c_str());              if ( IsDebug() ) printf(" In the loop searching for fragmented runs : query is \n %s \n",oss.str().c_str());
6183              //              //
6184              nresult1 = conn->Query(oss.str().c_str());              nresult1 = conn->Query(oss.str().c_str());

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

  ViewVC Help
Powered by ViewVC 1.1.23