/[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.33 by mocchiut, Tue May 15 14:04:40 2012 UTC revision 1.40 by mocchiut, Tue Oct 14 13:19:32 2014 UTC
# Line 226  void PamelaDBOperations::OpenL0File(TStr Line 226  void PamelaDBOperations::OpenL0File(TStr
226                qu.str("");                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;";                //            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]                //            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-"<< 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]                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());                if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str());
250                result3 = conn->Query(qu.str().c_str());                result3 = conn->Query(qu.str().c_str());
251                if ( result3 ){                if ( result3 ){
# Line 1354  void PamelaDBOperations::CheckConnection Line 1373  void PamelaDBOperations::CheckConnection
1373    oss.str("");    oss.str("");
1374    oss << "SET wait_timeout=173000;";    oss << "SET wait_timeout=173000;";
1375    conn->Query(oss.str().c_str());    conn->Query(oss.str().c_str());
1376      delete conn->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';");
1377    //    //
1378  }  }
1379    
# Line 1639  Int_t PamelaDBOperations::insertPamelaRa Line 1659  Int_t PamelaDBOperations::insertPamelaRa
1659  Int_t PamelaDBOperations::insertPamelaGL_TIMESYNC(){  Int_t PamelaDBOperations::insertPamelaGL_TIMESYNC(){
1660    //    //
1661    Int_t signal = 0;    Int_t signal = 0;
1662    UInt_t idresof = 0;    //  UInt_t idresof = 0;
1663      idresof = 0;
1664    stringstream   oss;    stringstream   oss;
1665    TSQLResult *result = 0;    TSQLResult *result = 0;
1666    TSQLRow *row = 0;    TSQLRow *row = 0;
# Line 1953  Int_t PamelaDBOperations::insertPamelaRo Line 1974  Int_t PamelaDBOperations::insertPamelaRo
1974      //      //
1975      if ( chewbacca ){      if ( chewbacca ){
1976          oss.str("");          oss.str("");
1977          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<<" and ID_RESURS_OFFSET="<< idresof <<" limit 1;"; // 10RED BUG!!!! without 'and ID_RESURS_OFFSET="<< idresof ' this query is not enough to ensure finding the correct line in GL_TIMSYNC...
1978          if ( debug ) printf(" %s \n",oss.str().c_str());          if ( debug ) printf(" %s \n",oss.str().c_str());
1979          result = conn->Query(oss.str().c_str());          result = conn->Query(oss.str().c_str());
1980          //          //
# Line 2162  Int_t PamelaDBOperations::assignBOOT_NUM Line 2183  Int_t PamelaDBOperations::assignBOOT_NUM
2183      UInt_t lowerts = tsync-(obt0/1000)-5;      UInt_t lowerts = tsync-(obt0/1000)-5;
2184      if ( chewbacca ){      if ( chewbacca ){
2185        oss.str("");        oss.str("");
2186        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
2187            << upperts            << upperts
2188            << " AND LAST_TIME_SYNC_INFO-(OBT_TIME_SYNC)>"            << " AND CAST((LAST_TIME_SYNC_INFO-(OBT_TIME_SYNC)) AS SIGNED INT)>" // 10RED MYSQL OPERATORS BUG
2189            << lowerts            << lowerts
2190            << " AND BOOT_NUMBER>1;";            << " AND BOOT_NUMBER>1;";
2191      } else {      } else {
2192        oss.str("");        oss.str("");
2193        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
2194            << upperts            << upperts
2195            << " AND TIMESYNC-(OBT0/1000)>"            << " AND CAST((TIMESYNC-(OBT0/1000)) AS SIGNED INT)>" // 10RED MYSQL OPERATORS BUG
2196            << lowerts            << lowerts
2197            << " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;";            << " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;";
2198      };      };
# Line 2957  void PamelaDBOperations::HandleRunFragme Line 2978  void PamelaDBOperations::HandleRunFragme
2978          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);
2979          //          //
2980          glrun->SetEV_FROM(firstev);          glrun->SetEV_FROM(firstev);
2981            glrun->SetEV_TO(lastev); // EM 10 RED ghost run bug
2982          glrun->SetNEVENTS(lastev-firstev+1);          glrun->SetNEVENTS(lastev-firstev+1);
2983          //          //
2984          glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME());          glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME());
# Line 3152  void PamelaDBOperations::HandleRunFragme Line 3174  void PamelaDBOperations::HandleRunFragme
3174          };          };
3175          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);
3176          //          //
3177            glrun->SetEV_FROM(firstev); // EM 10RED ghost run bug
3178          glrun->SetEV_TO(lastev);          glrun->SetEV_TO(lastev);
3179          glrun->SetNEVENTS(lastev-firstev+1);          glrun->SetNEVENTS(lastev-firstev+1);
3180          glrun->SetPKT_COUNTER(glrun1->GetPKT_COUNTER());          glrun->SetPKT_COUNTER(glrun1->GetPKT_COUNTER());
# Line 3994  Bool_t PamelaDBOperations::IsRunConsiste Line 4017  Bool_t PamelaDBOperations::IsRunConsiste
4017                  glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT());                  glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT());
4018                  //                  //
4019                  glrun->SetEV_FROM(firstev);                  glrun->SetEV_FROM(firstev);
4020                    glrun->SetEV_TO(lastev); // 10 RED ghost run bug
4021                  glrun->SetNEVENTS(lastev-firstev+1);                  glrun->SetNEVENTS(lastev-firstev+1);
4022                  //                  //
4023                  glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME());                  glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME());
# Line 5449  Int_t PamelaDBOperations::insertTRK_CALI Line 5473  Int_t PamelaDBOperations::insertTRK_CALI
5473    
5474          if ( IsDebug() ) cout << endl << ">>>> TRY TO RECOVER TRACKER CALIBRATIONS <<<<"<<endl;          if ( IsDebug() ) cout << endl << ">>>> TRY TO RECOVER TRACKER CALIBRATIONS <<<<"<<endl;
5475    
5476          TSQLResult *result = 0;          TSQLResult *rresult = 0; // 10RED bug, result is re-used inside result looop...
5477            TSQLResult *result = 0; // 10RED bug, result is re-used inside result looop...
5478          TSQLRow    *row    = 0;          TSQLRow    *row    = 0;
5479          //          //
5480          stringstream oss;          stringstream oss;
# Line 5479  Int_t PamelaDBOperations::insertTRK_CALI Line 5504  Int_t PamelaDBOperations::insertTRK_CALI
5504          oss << " ORDER BY ID DESC LIMIT "<<ncalib<<"; ";                  oss << " ORDER BY ID DESC LIMIT "<<ncalib<<"; ";        
5505          if ( IsDebug() ) cout << oss.str().c_str() << endl;          if ( IsDebug() ) cout << oss.str().c_str() << endl;
5506    
5507          result = conn->Query(oss.str().c_str());          rresult = conn->Query(oss.str().c_str());
5508          if ( !result ) throw -4;;          if ( !result ) throw -4;;
5509          if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl;          if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl;
5510                    
# Line 5488  Int_t PamelaDBOperations::insertTRK_CALI Line 5513  Int_t PamelaDBOperations::insertTRK_CALI
5513          // -----------------------------------          // -----------------------------------
5514          UInt_t nn=0;          UInt_t nn=0;
5515          do {          do {
5516              row = result->Next();              row = rresult->Next();
5517              if(!row)break;              if(!row)break;
5518                            
5519              UInt_t id       = (UInt_t)atoll(row->GetField(0));              UInt_t id       = (UInt_t)atoll(row->GetField(0));
# Line 5668  Int_t PamelaDBOperations::insertTRK_CALI Line 5693  Int_t PamelaDBOperations::insertTRK_CALI
5693                      if(FOUND)break;                      if(FOUND)break;
5694    
5695                  }while(1);//endl loop over root table entries                  }while(1);//endl loop over root table entries
5696                    
5697                    delete result2; // 10RED potential memory leak
5698                  if(FOUND)break;                  if(FOUND)break;
5699    
5700              }//end loop over tables              }//end loop over tables
# Line 5721  Int_t PamelaDBOperations::insertTRK_CALI Line 5747  Int_t PamelaDBOperations::insertTRK_CALI
5747                // ---------------------------------------------------------------------                // ---------------------------------------------------------------------
5748                UInt_t idtimesync = 0;                UInt_t idtimesync = 0;
5749                oss.str("");                oss.str("");
5750                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<<" and ID_RESURS_OFFSET="<< idresof <<" limit 1;"; // 10RED BUG!!!! without 'and ID_RESURS_OFFSET="<< idresof ' this query is not enough to ensure finding the correct line in GL_TIMSYNC...
5751                if ( debug ) printf(" %s \n",oss.str().c_str());                if ( debug ) printf(" %s \n",oss.str().c_str());
5752                result = conn->Query(oss.str().c_str());                result = conn->Query(oss.str().c_str());
5753                if ( !result ) throw -3;                if ( !result ) throw -3;
# Line 5822  Int_t PamelaDBOperations::insertTRK_CALI Line 5848  Int_t PamelaDBOperations::insertTRK_CALI
5848          }while(1);//end loop over calibrations          }while(1);//end loop over calibrations
5849                    
5850                    
5851          if( result )delete result;          if( rresult )delete rresult; // 10RED bug
5852          if( row    )delete row;          if( row    )delete row;
5853                    
5854                    
# Line 6123  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6149  Int_t PamelaDBOperations::CleanGL_RUN_FR
6149      memset(myid,0,500*sizeof(UInt_t));      memset(myid,0,500*sizeof(UInt_t));
6150      //      //
6151      oss.str("");      oss.str("");
6152      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;";
6153      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());
6154      nresult = conn->Query(oss.str().c_str());      nresult = conn->Query(oss.str().c_str());
6155      //      //
# Line 6154  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 6180  Int_t PamelaDBOperations::CleanGL_RUN_FR
6180            while ( anr ){            while ( anr ){
6181              //              //
6182              oss.str("");              oss.str("");
6183              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
6184              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());
6185              //              //
6186              nresult1 = conn->Query(oss.str().c_str());              nresult1 = conn->Query(oss.str().c_str());

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.40

  ViewVC Help
Powered by ViewVC 1.1.23