--- chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2009/08/05 18:48:44 1.25 +++ chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2014/10/14 13:19:32 1.40 @@ -88,12 +88,12 @@ // glrun = new GL_RUN(); // - if ( !chewbacca ){ - if ( !boot ) SetNOBOOT(false); - SetTsync(tsync,gpamela); - SetBOOTnumber(boot,gpamela); - SetObt0(obt0); - }; + // if ( !chewbacca ){ + // if ( !boot ) SetNOBOOT(false); + // SetTsync(tsync,gpamela); + // SetBOOTnumber(boot,gpamela); + // SetObt0(obt0); + // }; // SetTLEPath(tlefilename); // @@ -126,6 +126,12 @@ // // SETTERS // +void PamelaDBOperations::NotChewbacca(UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t gpamela){ + if ( !boot ) SetNOBOOT(false); + SetTsync(tsync,gpamela); + SetBOOTnumber(boot,gpamela); + SetObt0(obt0); +}; void PamelaDBOperations::OpenL0File(TString filerootname){ if( INSERT_ROOT ){ @@ -183,19 +189,74 @@ chboot = (UInt_t)atoll(row2->GetField(5)); // if ( !chboot ){ + if ( debug ) printf(" mmm... no BOOT number determined by chewbacca, try to find it looking at DB \n"); + // + // new feature: check in ROOT_TABLE (timewise) the previous and the next BOOT number != 0 , if it is the same we know this one! + // if it is different roll back to the old behaviour + // qu.str(""); - // 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 <<")<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 REAL_TIME_INIT>"<< row2->GetField(10) <<" order by REAL_TIME_INIT asc limit 1;"; if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); + UInt_t chbootA = 0; + UInt_t chbootB = 1; result3 = conn->Query(qu.str().c_str()); if ( result3 ){ row3 = result3->Next(); - if ( row3 && result3->GetRowCount() == 1 ){ - chboot = (UInt_t)atoll(row3->GetField(0)); - if ( debug ) printf(" Found boot_number = %u \n",chboot); - } else { - if ( debug ) printf(" AGH CANNOT DETERMINE THE BOOT NUMBER... \n"); - throw -29; + if ( row3 ){ + chbootA = (UInt_t)atoll(row3->GetField(0)); + if ( debug ) printf(" Found boot_number A = %u \n",chbootA); + }; + }; + delete result3; + qu.str(""); + 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;"; + if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); + result3 = conn->Query(qu.str().c_str()); + if ( result3 ){ + row3 = result3->Next(); + if ( row3 ){ + chbootB = (UInt_t)atoll(row3->GetField(0)); + if ( debug ) printf(" Found boot_number B = %u \n",chbootB); + }; + }; + if ( chbootA == chbootB ){ + chboot = chbootA; + if ( debug ) printf(" Found boot_number! it is %u \n",chboot); + } else { + qu.str(""); + // 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 <<")<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-"<< (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: + /* + +mysql> select CAST(1322000646 AS UNSIGNED INTEGER)-1322017203.; ++--------------------------------------------------+ +| CAST(1322000646 AS UNSIGNED INTEGER)-1322017203. | ++--------------------------------------------------+ +| -16557 | ++--------------------------------------------------+ +1 row in set (0.06 sec) + +mysql> select CAST(1322000646 AS UNSIGNED INTEGER)-1322017203; ++-------------------------------------------------+ +| CAST(1322000646 AS UNSIGNED INTEGER)-1322017203 | ++-------------------------------------------------+ +| 18446744073709535059 | ++-------------------------------------------------+ +1 row in set (0.02 sec) + + */ + if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); + result3 = conn->Query(qu.str().c_str()); + if ( result3 ){ + row3 = result3->Next(); + if ( row3 && result3->GetRowCount() == 1 ){ + chboot = (UInt_t)atoll(row3->GetField(0)); + if ( debug ) printf(" Found boot_number = %u \n",chboot); + } else { + if ( debug ) printf(" AGH CANNOT DETERMINE THE BOOT NUMBER... \n"); + throw -29; + }; }; }; }; @@ -1312,6 +1373,7 @@ oss.str(""); oss << "SET wait_timeout=173000;"; conn->Query(oss.str().c_str()); + delete conn->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"); // } @@ -1597,7 +1659,8 @@ Int_t PamelaDBOperations::insertPamelaGL_TIMESYNC(){ // Int_t signal = 0; - UInt_t idresof = 0; + // UInt_t idresof = 0; + idresof = 0; stringstream oss; TSQLResult *result = 0; TSQLRow *row = 0; @@ -1688,9 +1751,9 @@ TYPE = 0; TSYNC = 0; // - Double_t minimum = 0.; - Double_t maximum = 0.; - Double_t minimum2 = 0.; + // Double_t minimum = 0.; + // Double_t maximum = 0.; + //Double_t minimum2 = 0.; Double_t maximum2 = 0.; // // @@ -1698,9 +1761,9 @@ pamela::McmdRecord *mcrc = 0; TArrayC *mcmddata = 0; // - minimum = numeric_limits::max(); - maximum = numeric_limits::min(); - minimum2 = numeric_limits::max(); + // minimum = numeric_limits::max(); + // maximum = numeric_limits::min(); + // minimum2 = numeric_limits::max(); maximum2 = numeric_limits::min(); // T = (TTree*)file->Get("Mcmd"); @@ -1911,7 +1974,7 @@ // if ( chewbacca ){ oss.str(""); - oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<Query(oss.str().c_str()); // @@ -2120,16 +2183,16 @@ UInt_t lowerts = tsync-(obt0/1000)-5; if ( chewbacca ){ oss.str(""); - 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 << upperts - << " AND LAST_TIME_SYNC_INFO-(OBT_TIME_SYNC)>" + << " AND CAST((LAST_TIME_SYNC_INFO-(OBT_TIME_SYNC)) AS SIGNED INT)>" // 10RED MYSQL OPERATORS BUG << lowerts << " AND BOOT_NUMBER>1;"; } else { oss.str(""); - 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 << upperts - << " AND TIMESYNC-(OBT0/1000)>" + << " AND CAST((TIMESYNC-(OBT0/1000)) AS SIGNED INT)>" // 10RED MYSQL OPERATORS BUG << lowerts << " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;"; }; @@ -2228,8 +2291,10 @@ // // no runtrailers in the file! // - if ( !rtev ){ - if ( !rhev ){ + if ( IsDebug() ) printf(" Start rtev %i rhev %i nrtev %i nrhev %i \n",rtev,rhev,nrtev,nrhev); + if ( !rtev || (chewbacca && !nrtev) ){ + if ( IsDebug() ) printf(" No runtrailers \n"); + if ( !rhev || (chewbacca && !nrhev) ){ if ( IsDebug() ) printf(" No runheaders nor runtrailers!! \n"); if ( !(upperentry-chminentry) ){ if ( IsDebug() ) printf(" No physics events nor runs in the file \n"); // di nuovo potrebbe esserci un runtrailer senza eventi (riempimento MM) @@ -2266,6 +2331,7 @@ // } else { // + if ( IsDebug() ) printf(" We have runtrailers \n"); Int_t conptt = -1; for (Int_t ptt=0; pttSetEV_FROM(firstev); + glrun->SetEV_TO(lastev); // EM 10 RED ghost run bug glrun->SetNEVENTS(lastev-firstev+1); // glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); @@ -3107,6 +3174,7 @@ }; if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev); // + glrun->SetEV_FROM(firstev); // EM 10RED ghost run bug glrun->SetEV_TO(lastev); glrun->SetNEVENTS(lastev-firstev+1); glrun->SetPKT_COUNTER(glrun1->GetPKT_COUNTER()); @@ -3199,114 +3267,146 @@ // "small gap" piece... we recognize this since: we have two entries from this query, the pkt number is consistent with our pkt number. // // 090112 [8RED (-70): RUN ALREADY INSERTED] + // 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! // Bool_t OK = false; UInt_t IDRL2A = 0; UInt_t IDRL2B = 0; if ( chewbacca ){ - if ( result->GetRowCount() == 2 ){ + if ( result->GetRowCount() >= 2 ){ + // + if ( IsDebug() ) printf(" RH---| gap |---RT case, number of pieces in the GL_RUN table: %i \n",result->GetRowCount()); + OK = true; IDRL2A = (UInt_t)atoll(row->GetField(0)); - UInt_t IDRL0A = (UInt_t)atoll(row->GetField(1)); - row = result->Next(); - 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()); + // + while ( row ){ // - if ( !result2 ) throw -4; + TSQLResult *trresult = 0; + TSQLRow *trrow = 0; // - row2 = result2->Next(); + stringstream tross; + tross.str(""); // - if ( row2 ){ - UInt_t PKA = (UInt_t)atoll(row2->GetField(0)); - delete result2; - oss.str(""); - oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc 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()); - // - if ( !result2 ) throw -4; - // - row2 = result2->Next(); - // - if ( row2 ){ - UInt_t PKB = (UInt_t)atoll(row2->GetField(0)); - // - 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); - if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){ - if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n"); - OK = true; - }; - }; - }; + tross << " SELECT RUNHEADER_PKT, RUNTRAILER_PKT FROM GL_RUN_TRASH where ID=" << row->GetField(0) << ";"; + if ( IsDebug() ) printf(" check in the gl_run_trash table for pkt intervals: query is \n %s \n",tross.str().c_str()); + trresult = conn->Query(tross.str().c_str()); + if ( !trresult ) throw -4; + trrow = trresult->Next(); + if ( !trrow || trresult->GetRowCount() != 1 ){ + OK = false; + if ( IsDebug() ) printf(" OPS! no such run (or multiple runs!) in GL_RUN_TRASH table, something wrong is going on! \n"); + break; + }; + // + UInt_t pktH = (UInt_t)atoll(row->GetField(0)); + UInt_t pktT = (UInt_t)atoll(row->GetField(1)); + delete trresult; + if ( + (PKT(pktH) >= PKT(glrun->GetRUNHEADER_PKT()) && PKT(pktH) <= PKT(glrun->GetRUNTRAILER_PKT())) || + (PKT(pktT) >= PKT(glrun->GetRUNHEADER_PKT()) && PKT(pktT) <= PKT(glrun->GetRUNTRAILER_PKT())) || + (PKT(pktH) <= PKT(glrun->GetRUNTRAILER_PKT()) && PKT(pktT) >= PKT(glrun->GetRUNTRAILER_PKT())) ){ + OK = false; + if ( IsDebug() ) printf(" The run is overlapping with already inserted ones!! \n"); + break; + }; + //PKT(glrun->GetRUNHEADER_PKT()) PKT(glrun->GetRUNTRAILER_PKT()) + row = result->Next(); }; - }; + + // if ( result->GetRowCount() == 2 ) { + // IDRL2A = (UInt_t)atoll(row->GetField(0)); + // UInt_t IDRL0A = (UInt_t)atoll(row->GetField(1)); + // row = result->Next(); + // 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 ){ //091230 why this condition???? RH could be in a file and RT in another one... + // if ( true ){ + // 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()); + // // + // if ( !result2 ) throw -4; + // // + // row2 = result2->Next(); + // // + // if ( row2 ){ + // UInt_t PKA = (UInt_t)atoll(row2->GetField(0)); + // delete result2; + // oss.str(""); + // oss << "select PKT_NUMBER_INIT from ROOT_TABLE_MERGING where REAL_TIME_INIT>" << chrtinit << " order by REAL_TIME_INIT asc 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()); + // // + // if ( !result2 ) throw -4; + // // + // row2 = result2->Next(); + // // + // if ( row2 ){ + // UInt_t PKB = (UInt_t)atoll(row2->GetField(0)); + // // + // 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); + // if ( PKT(PKA)+1LL == PKT(glrun->GetRUNHEADER_PKT()) && PKT(PKB) == PKT(glrun->GetRUNTRAILER_PKT())+1LL ){ + // if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n"); + // OK = true; + // }; + // }; + // }; + // }; + // }; + }; }; if ( OK ){ // - // 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 // // 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 ) // + if ( IsDebug() ) printf(" Ok, we are in the case: RH---| small gap |---RT \n"); + // GL_RUN *glA = new GL_RUN(); glA->Query_GL_RUN(IDRL2A,conn); // + glrun->SetRUNHEADER_TIME(glA->GetRUNHEADER_TIME()); + glrun->SetRUNHEADER_OBT(glA->GetRUNHEADER_OBT()); + glrun->SetRUNHEADER_PKT(glA->GetRUNHEADER_PKT()); + // + glrun->SetRUNTRAILER_TIME(glA->GetRUNTRAILER_TIME()); + glrun->SetRUNTRAILER_OBT(glA->GetRUNTRAILER_OBT()); + glrun->SetRUNTRAILER_PKT(glA->GetRUNTRAILER_PKT()); + // + if ( glA->GetPHYSENDRUN_MASK_S3S2S12() ) glrun->SetPHYSENDRUN_MASK_S3S2S12(glA->GetPHYSENDRUN_MASK_S3S2S12()); + if ( glA->GetPHYSENDRUN_MASK_S11CRC() ) glrun->SetPHYSENDRUN_MASK_S11CRC(glA->GetPHYSENDRUN_MASK_S11CRC()); + // if ( glA->GetACQ_BUILD_INFO() != 0 ){ // // the first piece contains a good runheader we can update all the other runs with correct infos! // - oss.str(""); - oss << "UPDATE GL_RUN_FRAGMENTS SET " - << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , " - << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " - << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , " - << " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , " - << " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , " - << " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , " - << " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , " - << " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , " - << " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , " - << " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , " - << " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , " - << " 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()<< " , "; + glrun->SetCOMPILATIONTIMESTAMP(glA->GetCOMPILATIONTIMESTAMP()); + glrun->SetFAV_WRK_SCHEDULE(glA->GetFAV_WRK_SCHEDULE()); + glrun->SetEFF_WRK_SCHEDULE(glA->GetEFF_WRK_SCHEDULE()); + glrun->SetPRH_VAR_TRG_MODE_A(glA->GetPRH_VAR_TRG_MODE_A()); + glrun->SetPRH_VAR_TRG_MODE_B(glA->GetPRH_VAR_TRG_MODE_B()); + glrun->SetACQ_BUILD_INFO(glA->GetACQ_BUILD_INFO()); + glrun->SetACQ_VAR_INFO(glA->GetACQ_VAR_INFO()); + glrun->SetRM_ACQ_AFTER_CALIB(glA->GetRM_ACQ_AFTER_CALIB()); + glrun->SetRM_ACQ_SETTING_MODE(glA->GetRM_ACQ_SETTING_MODE()); + glrun->SetTRK_CALIB_USED(glA->GetTRK_CALIB_USED()); + glrun->SetCAL_DSP_MASK(glA->GetCAL_DSP_MASK()); + glrun->SetLAST_TIMESYNC(glA->GetLAST_TIMESYNC()); + glrun->SetOBT_TIMESYNC(glA->GetOBT_TIMESYNC()); // - 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 << " 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... + }; + // + if ( glA->GetPKT_READY_COUNTER() != 0 ){ // - oss.str(""); - oss << "UPDATE GL_RUN_FRAGMENTS SET " - << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "; + // the first piece contains a good runtrailer we can update all the other runs with correct infos! // - 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 << " 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()); + glrun->SetPKT_COUNTER(glA->GetPKT_COUNTER()); + glrun->SetPKT_READY_COUNTER(glA->GetPKT_READY_COUNTER()); }; // // update runheader ROOT_ID_FRAG @@ -3316,65 +3416,152 @@ if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); conn->Query(oss.str().c_str()); // - // 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(); oss.str(""); - oss << " ID= "<< myi; - // - glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); + oss << "SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG = " << IDRL2A << ";"; + if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); + TSQLResult *tsresult = 0; + TSQLRow *tsrow = 0; + tsresult=conn->Query(oss.str().c_str()); + if ( !tsresult ) throw -4; + tsrow = tsresult->Next(); + if ( !tsrow || tsresult->GetRowCount() != 1 ) throw -4; + IDRL2B = (UInt_t)atoll(tsrow->GetField(0)); + glrun->SetID_RUN_FRAG(IDRL2B); // // fill the new run in GL_RUN // - glrun->SetID_RUN_FRAG(IDRL2B); glrun->Fill_GL_RUN(conn); + // glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); delete glA; // } else { +// // +// // this is the case in which we must insert a piece of run between two fragments in the GL_RUN table +// // +// // 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 ) +// // +// GL_RUN *glA = new GL_RUN(); +// glA->Query_GL_RUN(IDRL2A,conn); +// // +// if ( glA->GetACQ_BUILD_INFO() != 0 ){ +// // +// // the first piece contains a good runheader we can update all the other runs with correct infos! +// // +// oss.str(""); +// oss << "UPDATE GL_RUN_FRAGMENTS SET " +// << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , " +// << " RUNHEADER_OBT=" << glA->GetRUNHEADER_OBT()<< " , " +// << " RUNHEADER_PKT=" << glA->GetRUNHEADER_PKT()<< " , " +// << " COMPILATIONTIMESTAMP=" << glA->GetCOMPILATIONTIMESTAMP()<< " , " +// << " FAV_WRK_SCHEDULE=" << glA->GetFAV_WRK_SCHEDULE()<< " , " +// << " EFF_WRK_SCHEDULE=" << glA->GetEFF_WRK_SCHEDULE()<< " , " +// << " PRH_VAR_TRG_MODE_A=" << glA->GetPRH_VAR_TRG_MODE_A()<< " , " +// << " PRH_VAR_TRG_MODE_B=" << glA->GetPRH_VAR_TRG_MODE_B()<< " , " +// << " ACQ_BUILD_INFO=" << glA->GetACQ_BUILD_INFO()<< " , " +// << " ACQ_VAR_INFO=" << glA->GetACQ_VAR_INFO()<< " , " +// << " RM_ACQ_AFTER_CALIB=" << glA->GetRM_ACQ_AFTER_CALIB()<< " , " +// << " 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()<< " , "; +// // +// 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 << " 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... +// // +// oss.str(""); +// oss << "UPDATE GL_RUN_FRAGMENTS SET " +// << " RUNHEADER_TIME=" << glA->GetRUNHEADER_TIME()<< " , "; +// // +// 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 << " 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()); +// }; +// // +// // update runheader ROOT_ID_FRAG +// // +// oss.str(""); +// oss << "UPDATE GL_RUN SET ID_RUN_FRAG = " << glrun->GetID() << " where ID = " << IDRL2A << ";"; +// if ( IsDebug() ) printf(" update gl_run to have cross indexing: %s\n",oss.str().c_str()); +// conn->Query(oss.str().c_str()); +// // +// // 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(); +// oss.str(""); +// oss << " ID= "<< myi; +// // +// glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); +// // +// // fill the new run in GL_RUN +// // +// glrun->SetID_RUN_FRAG(IDRL2B); +// glrun->Fill_GL_RUN(conn); +// glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); +// delete glA; +// // +// } else { // // is just a repetition // @@ -3434,7 +3621,7 @@ // EventCounter *code=0; // - UInt_t nevent = 0; + // UInt_t nevent = 0; UInt_t checkfirst = 0; UInt_t checklast = 0; UInt_t firstentry = 0; @@ -3456,7 +3643,7 @@ EventHeader *eh = 0; PscuHeader *ph = 0; T->SetBranchAddress("Header", &eh); - nevent = T->GetEntries(); + // nevent = T->GetEntries(); // // if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run! @@ -3830,6 +4017,7 @@ glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); // glrun->SetEV_FROM(firstev); + glrun->SetEV_TO(lastev); // 10 RED ghost run bug glrun->SetNEVENTS(lastev-firstev+1); // glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); @@ -3977,7 +4165,7 @@ EventCounter *code=0; UInt_t firstev = 0; UInt_t lastev = 0; - UInt_t nevent = 0; + // UInt_t nevent = 0; UInt_t checkfirst = 0; UInt_t checklast = 0; UInt_t firstentry = 0; @@ -4002,7 +4190,7 @@ EventHeader *eh = 0; PscuHeader *ph = 0; T->SetBranchAddress("Header", &eh); - nevent = T->GetEntries(); + // nevent = T->GetEntries(); // codt = eht->GetCounter(); codh = ehh->GetCounter(); @@ -4236,6 +4424,7 @@ UInt_t totime = 0; UInt_t obt = 0; UInt_t pkt = 0; + Float_t totped = 0.; // tr = (TTree*)file->Get("CalibCalPed"); if ( !tr || tr->IsZombie() ) throw -21; @@ -4253,6 +4442,22 @@ if ( calibCalPed->cstwerr[section] ){ valid = 1; if ( calibCalPed->cperror[section] ) valid = 0; + // + // 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.] + // + totped = 0.; + Int_t ns = 0; + if ( section == 2 ) ns = 3; + if ( section == 3 ) ns = 1; + if ( section == 1 ) ns = 2; + for (UInt_t ss=0; ss<96; ss++){ + totped += fabs(calibCalPed->calped[ns][0][ss]); + } + if ( totped < 1. ){ + if ( IsDebug() ) printf(" Section %i totped %f - No calibration data! Calorimeter power problems? \n",section,totped); + valid = 0; + }; + // ph = eh->GetPscuHeader(); obt = ph->GetOrbitalTime(); pkt = ph->GetCounter(); @@ -4420,6 +4625,8 @@ tr->SetBranchAddress("Header", &eh); nevents = tr->GetEntries(); // + Float_t totpul = 0.; + // if ( nevents > 0 ){ // for (UInt_t i=0; i < nevents; i++){ @@ -4429,6 +4636,22 @@ if ( cp1->pstwerr[section] && cp1->unpackError == 0 ){ valid = 1; if ( cp1->pperror[section] ) valid = 0; + // + // 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.] + // + totpul = 0.; + Int_t ns = 0; + if ( section == 2 ) ns = 3; + if ( section == 3 ) ns = 1; + if ( section == 1 ) ns = 2; + for (UInt_t ss=0; ss<96; ss++){ + totpul += cp1->calpuls[ns][0][ss]; + } + if ( totpul >= 3145632. ){ + if ( IsDebug() ) printf(" PULSE1 Section %i totpul %f - No calibration data! Calorimeter power problems? \n",section,totpul); + valid = 0; + }; + // ph = eh->GetPscuHeader(); obt = ph->GetOrbitalTime(); pkt = ph->GetCounter(); @@ -4586,6 +4809,22 @@ if ( cp2->pstwerr[section] && cp2->unpackError == 0 ){ valid = 1; if ( cp2->pperror[section] ) valid = 0; + // + // 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.] + // + totpul = 0.; + Int_t ns = 0; + if ( section == 2 ) ns = 3; + if ( section == 3 ) ns = 1; + if ( section == 1 ) ns = 2; + for (UInt_t ss=0; ss<96; ss++){ + totpul += cp2->calpuls[ns][0][ss]; + } + if ( totpul >= 3145632. ){ + if ( IsDebug() ) printf(" PULSE2 Section %i totpul %f - No calibration data! Calorimeter power problems? \n",section,totpul); + valid = 0; + }; + // ph = eh->GetPscuHeader(); obt = ph->GetOrbitalTime(); pkt = ph->GetCounter(); @@ -5234,7 +5473,8 @@ if ( IsDebug() ) cout << endl << ">>>> TRY TO RECOVER TRACKER CALIBRATIONS <<<<"<Query(oss.str().c_str()); + rresult = conn->Query(oss.str().c_str()); if ( !result ) throw -4;; if ( IsDebug() ) cout <<"Rows: "<GetRowCount()<Next(); + row = rresult->Next(); if(!row)break; UInt_t id = (UInt_t)atoll(row->GetField(0)); @@ -5312,9 +5552,9 @@ TString path = ""; TString name = ""; TString raw = ""; - UInt_t obt0 = 0; - UInt_t timesync = 0; - UInt_t boot_number = 0; + // UInt_t obt0 = 0; + // UInt_t timesync = 0; + // UInt_t boot_number = 0; bool FOUND = false; if ( IsDebug() ) cout << "------------------------------------------------------------" <GetField(0); name = (TString)row2->GetField(1); raw = (TString)row2->GetField(5); - obt0 = (UInt_t)atoll(row2->GetField(2)); - timesync = (UInt_t)atoll(row2->GetField(3)); - boot_number = (UInt_t)atoll(row2->GetField(4)); + // obt0 = (UInt_t)atoll(row2->GetField(2)); + // timesync = (UInt_t)atoll(row2->GetField(3)); + // boot_number = (UInt_t)atoll(row2->GetField(4)); if ( IsDebug() ) cout << "- - - - - - - - - - -" <Query(oss.str().c_str()); if ( !result ) throw -3; @@ -5607,7 +5848,7 @@ }while(1);//end loop over calibrations - if( result )delete result; + if( rresult )delete rresult; // 10RED bug if( row )delete row; @@ -5908,7 +6149,7 @@ memset(myid,0,500*sizeof(UInt_t)); // oss.str(""); - 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;"; if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str()); nresult = conn->Query(oss.str().c_str()); // @@ -5939,7 +6180,7 @@ while ( anr ){ // oss.str(""); - 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 if ( IsDebug() ) printf(" In the loop searching for fragmented runs : query is \n %s \n",oss.str().c_str()); // nresult1 = conn->Query(oss.str().c_str());