--- chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2008/11/28 14:07:37 1.13 +++ chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2009/01/13 13:38:15 1.23 @@ -60,6 +60,7 @@ */ PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename, UInt_t dwinput, Bool_t staticp, Bool_t gpamela, Bool_t keepenv){ // + RELAXED = false; chewbacca = false; chminentry = 0; chID = 0; @@ -135,13 +136,15 @@ stringstream qu; TSQLResult *result = 0; TSQLResult *result2 = 0; + TSQLResult *result3 = 0; TSQLRow *row = 0; TSQLRow *row2 = 0; + TSQLRow *row3 = 0; TString chpath; TString chfile; UInt_t ridn = 0; qu.str(""); - qu << "SELECT ROOT_ID_N,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,INSERTED_BY from ROOT_TABLE_MERGING where ID_N=" << chID << ";"; + qu << "SELECT ROOT_ID_N,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,INSERTED_BY,REAL_TIME_INIT from ROOT_TABLE_MERGING where ID_N=" << chID << ";"; if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); result = conn->Query(qu.str().c_str()); if ( result ){ @@ -153,6 +156,7 @@ chobtmin = (UInt_t)atoll(row->GetField(3)); chobtmax = (UInt_t)atoll(row->GetField(4)); chiby = (TString)(row->GetField(5)); + chrtinit = (UInt_t)atoll(row->GetField(6)); } else { throw -84; }; @@ -161,7 +165,7 @@ }; delete result; qu.str(""); - qu << "SELECT FOLDER_NAME,FILE_NAME,OBT_TIME_SYNC,LAST_TIME_SYNC_INFO,TIME_OFFSET,BOOT_NUMBER,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL from ROOT_TABLE where ID_N=" << ridn << ";"; + qu << "SELECT FOLDER_NAME,FILE_NAME,OBT_TIME_SYNC,LAST_TIME_SYNC_INFO,TIME_OFFSET,BOOT_NUMBER,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,REAL_TIME_INIT from ROOT_TABLE where ID_N=" << ridn << ";"; if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); result2 = conn->Query(qu.str().c_str()); if ( result2 ){ @@ -178,6 +182,24 @@ chresursts = (UInt_t)atoll(row2->GetField(4)); chboot = (UInt_t)atoll(row2->GetField(5)); // + if ( !chboot ){ + 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] + 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; + }; + }; + }; + // chpktinit = (UInt_t)atoll(row2->GetField(6)); chpktfinal = (UInt_t)atoll(row2->GetField(7)); chobtinit = (UInt_t)atoll(row2->GetField(8)); @@ -799,6 +821,8 @@ ph = eh->GetPscuHeader(); pktlast = ph->GetCounter(); nevent = upperentry - chminentry; + if ( ((Int_t)upperentry - (Int_t)chminentry) < 0 ) nevent = 0; // nevent is UInt_t! 090112 [8RED: error -88] + if ( IsDebug() ) printf(" Setting nevent to %u - upperentry %i chminentry %i \n",nevent,upperentry,chminentry); // } else { upperpkt = PKT(pktlast); @@ -807,6 +831,7 @@ }; // if ( chewbacca && nevent < 1 ) { + if ( IsDebug() ) printf(" chewbacca and no events in the file \n"); pktfirst = chpktmin; upperpkt = PKT(chpktmax); pktlast = chpktmax; @@ -1479,6 +1504,14 @@ glrun->SetRUNTRAILER_PKT(lastPkt); // }; + // + // ad hoc solution for INF EV_TO [8RED] 090113 + // + if ( !firstev && lastev == -1 ){ + if ( IsDebug() ) printf(" EE firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); + firstev = 1; + lastev = 0; + }; glrun->SetEV_FROM((UInt_t)firstev); glrun->SetEV_TO((UInt_t)lastev); glrun->SetNEVENTS((UInt_t)lastev-(UInt_t)firstev+1); @@ -1585,6 +1618,7 @@ result = conn->Query(oss.str().c_str()); if ( !result ) throw -10; row = result->Next(); + if ( !row ) throw -92; idresof = (UInt_t)atoll(row->GetField(0)); existsts = true; goto eout; @@ -1606,7 +1640,7 @@ if ( !row ){ oss.str(""); oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " - << dworbit << " order by FROM_ORBIT desc limit 1;"; + << dworbit << " AND SPECIAL_FILE='' order by FROM_ORBIT desc limit 1;"; if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); result = conn->Query(oss.str().c_str()); if ( !result ) throw -10; @@ -2247,7 +2281,7 @@ ptht = cod->Get(pctp->RunHeader) - 1; // evbeft = cod->Get(pctp->Physics); tcod = (UInt_t)cod->Get(pctp->Physics); - if ( !tcod ) tcod = 1; + if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT evbeft = TMath::Min(upperentry,(tcod-1)); if ( debug ) printf(" Loop in runtrailers, evbeft is %u upperentry %u cod->getetc %u \n",evbeft,upperentry,cod->Get(pctp->Physics)); // @@ -2286,7 +2320,7 @@ obth = phh->GetOrbitalTime(); cod = ehh->GetCounter(); tcod = (UInt_t)cod->Get(pctp->Physics); - if ( !tcod ) tcod = 1; + if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT evbefh = TMath::Max(chminentry,(tcod-1)); // if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){ @@ -2348,7 +2382,7 @@ cod = ehh->GetCounter(); // evbeft = cod->Get(pctp->Physics); tcod = (UInt_t)cod->Get(pctp->Physics); - if ( !tcod ) tcod = 1; + if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT evbeft = TMath::Min(upperentry,(tcod-1)); rh->GetEntry(pth); phh = ehh->GetPscuHeader(); @@ -2390,7 +2424,7 @@ // if ( conptt+1 == (nrtev+nrtbef )){ if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt); ptht++; - if ( ptht < rhev ){ + if ( ptht < rhev ){ rh->GetEntry(ptht); //pth++; //if ( pth < rhev ){ @@ -2418,7 +2452,8 @@ if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){ if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER! evbeft %u upperentry-1 %u \n",(UInt_t)evbeft,upperentry-1); // - if ( (ptt-1) < 0 ) throw -15; // should never arrive here! + // if ( (ptt-1) < 0 ) throw -15; // should never arrive here! + if ( (rtev-1) < 0 || ptt < 0 ) throw -15; // should never arrive here! // rt->GetEntry(ptt-1); rt->GetEntry(rtev-1); cod = eht->GetCounter(); @@ -2653,10 +2688,14 @@ // // we have now the good first piece of a run, fill the glrun object // - if ( rhfirstev != firstev && !mishead ) mishead = true; - if ( rtlastev != lastev && !mistrail ) mistrail = true; + if ( firstev != (lastev+1) ){ // could be a problem sometimes (?) + if ( rhfirstev != firstev && !mishead ) mishead = true; + if ( rtlastev != lastev && !mistrail ) mistrail = true; + }; // + if ( IsDebug() ) printf(" bhere firstev is %i lastev is %i \n",firstev,lastev); this->FillClass(mishead,mistrail,firstev,lastev); + if ( IsDebug() ) printf(" chere firstev is %i lastev is %i \n",firstev,lastev); // if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n"); if ( IsDebug() ) printf(" C THIS RUN: RUNHEADER_OBT %u RUNTRAILER_OBT %u RUNHEADER_PKT %u RUNTRAILER_PKT %u \n", glrun->GetRUNHEADER_OBT(),glrun->GetRUNTRAILER_OBT(),glrun->GetRUNHEADER_PKT(),glrun->GetRUNTRAILER_PKT()); @@ -2698,9 +2737,14 @@ glrun->Fill_GL_RUN_FRAGMENTS(conn); // } else { - if ( IsDebug() ) printf(" The run is already present in the fragment table \n"); - if ( PEDANTIC ) throw -69; - return; + if ( IsDebug() ) printf(" The run is already present in the fragment table, relaxed %u \n",RELAXED); + if ( !RELAXED ){ + if ( PEDANTIC ) throw -69; + return; + } else { + glrun->SetID((UInt_t)atoll(row->GetField(0))); + glrun->SetID_RUN_FRAG(0); + }; }; // if ( chewbacca && mishead && mistrail ) goto justcheck; @@ -2751,7 +2795,7 @@ // found = false; // default value // - if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n"); + if ( IsDebug() ) printf(" A Found a possible candidate, checking if it is the good one... \n"); // // if we have both runheader and runtrailer we can check with pkt_counter: // @@ -2767,6 +2811,7 @@ if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); // found = true; + if ( IsDebug() ) printf(" where firstev is %i lastev is %i \n",firstev,lastev); // } else { // @@ -2832,6 +2877,7 @@ oss << " ID="<GetField(0)<<";"; // glrun1->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // here we have runheader infos + if ( IsDebug() ) printf(" there firstev is %i lastev is %i \n",firstev,lastev); // // merge infos // @@ -2862,6 +2908,8 @@ glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT()); glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); // + if ( IsDebug() ) printf(" here firstev is %i lastev is %i \n",firstev,lastev); + // glrun->SetEV_FROM(firstev); glrun->SetNEVENTS(lastev-firstev+1); // @@ -2954,7 +3002,7 @@ // found = false; // default value // - if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n"); + if ( IsDebug() ) printf(" B Found a possible candidate, checking if it is the good one... \n"); // // if we have both runheader and runtrailer we can check with pkt_counter: // @@ -3054,7 +3102,7 @@ apkt = PKT(ph->GetCounter()); aobt = OBT(ph->GetOrbitalTime()); lastev--; - if ( PEDANTIC ) throw -72; + if ( PEDANTIC && !RELAXED) throw -72; }; if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev); // @@ -3122,7 +3170,7 @@ // not found, has this run already inserted in the GL_RUN or in the GL_RUN_FRAGMENTS table? // oss.str(""); - oss << " SELECT ID FROM GL_RUN WHERE " + oss << " SELECT ID,ID_ROOT_L0 FROM GL_RUN WHERE " << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" @@ -3145,8 +3193,194 @@ row = result->Next(); // if ( row ){ - if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); - if ( PEDANTIC ) throw -70; + // + // we end up here if chewbacca and we have RH---| small gap |---RT, in this case the two pieces are attached and moved to GL_RUN. We are now processing the + // "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] + // + Bool_t OK = false; + UInt_t IDRL2A = 0; + UInt_t IDRL2B = 0; + if ( chewbacca ){ + 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 ){ + 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 + // + // 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 + // + if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); + if ( PEDANTIC ) throw -70; + }; + // } else { if ( NoFrag() ){ glrun->SetID_RUN_FRAG(glrun->GetID()); @@ -3183,7 +3417,7 @@ glrun->SetID(this->AssignRunID()); glrun->SetID_RUN_FRAG(0); glrun->Fill_GL_RUN(conn); // it'ok we arrive here only inside a file hence in the middle of the runs... - }; + }; // }; // @@ -3227,6 +3461,7 @@ if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run! //if ( firstev <= lastev+1 ) { // no events inside the run! if ( IsDebug() ) printf(" Checking but no events in the run! \n"); + firstev = lastev+1; // this is necessary for files with no Physics entries, should have no influence on other files // return true is correct return(true); // @@ -3482,7 +3717,7 @@ // found = false; // default value // - if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n"); + if ( IsDebug() ) printf(" C Found a possible candidate, checking if it is the good one... \n"); // // if we have both runheader and runtrailer we can check with pkt_counter: // @@ -4715,7 +4950,8 @@ if ( !result ) throw -4;; row = result->Next(); if(row)glcal->ID = (UInt_t)atoll(row->GetField(0)); - + // + delete result; // mmm... "Error in : result set closed" solved? 090112 [8RED error messages] // }; @@ -5223,61 +5459,62 @@ if(FOUND){ - if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <>> REPETITION FOUND :-) <<<" <BaseName(raw.Data()) <<"\";"; -// if ( IsDebug() ) cout << oss.str().c_str() << endl; + //////////////////////////////////////////// + // insert a new entry in GL_TRK_CALIB and + // modify the time-tag of the previous one + //////////////////////////////////////////// + + // --------------------------------------------------------------------- + // step 1: insert a new raw file in GL_RAW + // --------------------------------------------------------------------- + // + // check if the raw file already exist + // + UInt_t id_raw = 0; // EM GL_RAW is there only for backward compatibility so we do not need to fill it when in "chewbacca" mode + // oss.str(""); + // oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; + // if ( IsDebug() ) cout << oss.str().c_str() << endl; -// result = conn->Query(oss.str().c_str()); -// if ( !result ) throw -4;; -// if ( IsDebug() ) cout <<"Rows: "<GetRowCount()<GetRowCount() == 0){ -// if ( IsDebug() ) cout << " << Insert new RAW file >> "<DirName(raw.Data()); -// glraw.NAME = gSystem->BaseName(raw.Data()); -// glraw.BOOT_NUMBER = boot_number; -// // -// insertPamelaRawFile( &glraw ); -// // -// id_raw = glraw.ID; -// }else{ -// row = result->Next(); -// id_raw = (UInt_t)atoll(row->GetField(0)); -// } -// if ( IsDebug() ) cout << "ID_RAW = "<Query(oss.str().c_str()); - if ( !result ) throw -3; + // result = conn->Query(oss.str().c_str()); + // if ( !result ) throw -4;; + // if ( IsDebug() ) cout <<"Rows: "<GetRowCount()<GetRowCount() == 0){ + // if ( IsDebug() ) cout << " << Insert new RAW file >> "<DirName(raw.Data()); + // glraw.NAME = gSystem->BaseName(raw.Data()); + // glraw.BOOT_NUMBER = boot_number; + // // + // insertPamelaRawFile( &glraw ); + // // + // id_raw = glraw.ID; + // }else{ + // row = result->Next(); + // id_raw = (UInt_t)atoll(row->GetField(0)); + // } + // if ( IsDebug() ) cout << "ID_RAW = "<Query(oss.str().c_str()); + if ( !result ) throw -3; row = result->Next(); if ( !row ) throw -3; idtimesync = (UInt_t)atoll(row->GetField(0)); if ( IsDebug() ) cout << "ID_TIMESYNC = "<: result set closed" solved? 090112 [8RED error messages] // --------------------------------------------------------------------- // step 2: insert a new root file in GL_ROOT // --------------------------------------------------------------------- @@ -5325,6 +5562,7 @@ } if ( IsDebug() ) cout << "ID_ROOT = "<: result set closed" solved? 090112 [8RED error messages] // --------------------------------------------------------------------- // step 3: modify time-tag of corrupted GL_TRK_CALIB entry // --------------------------------------------------------------------- @@ -5337,6 +5575,8 @@ result = conn->Query(oss.str().c_str()); if ( !result ) throw -4;; + delete result; // mmm... "Error in : result set closed" solved? 090112 [8RED error messages] + // --------------------------------------------------------------------- // step 4: insert the new calibration: // --------------------------------------------------------------------- @@ -5788,7 +6028,8 @@ oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; // oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , " - << " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT()<< ";"; + << " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT(); + oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112 conn->Query(oss.str().c_str()); }; }; @@ -5837,7 +6078,8 @@ if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){ oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; // - oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()<< ";"; + oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT(); + oss << " WHERE ID=" << myid[u] << ";"; // BUG!!! 090112 conn->Query(oss.str().c_str()); }; }; @@ -5888,7 +6130,7 @@ row2 = result2->Next(); // if ( row2 ){ - if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); + if ( IsDebug() ) printf(" The run already exists in the GL_RUN table! \n"); if ( PEDANTIC ) throw -83; row2->Close(); }; @@ -5965,7 +6207,7 @@ glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // oss.str(""); - oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE " + oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER,ID_ROOT_L0 FROM GL_RUN WHERE " << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND (" << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" @@ -6023,8 +6265,199 @@ moved++; // } else { - if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); - if ( PEDANTIC ) throw -83; + + // questa parte mah mah mah... da controllare + + // + // we end up here if chewbacca and we have RH---| small gap |---RT, in this case the two pieces are attached and moved to GL_RUN. We are now processing the + // "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] + // + Bool_t OK = false; + UInt_t IDRL2A = 0; + UInt_t IDRL2B = 0; + if ( result2->GetRowCount() == 2 ){ + IDRL2A = (UInt_t)atoll(row2->GetField(0)); + UInt_t IDRL0A = (UInt_t)atoll(row2->GetField(4)); + row2 = result2->Next(); + IDRL2B = (UInt_t)atoll(row2->GetField(0)); + UInt_t IDRL0B = (UInt_t)atoll(row2->GetField(4)); + if ( IsDebug() ) printf(" IDRL0A %u B %u IDRL2A %u B %u \n",IDRL0A,IDRL0B,IDRL2A,IDRL2B); + // if ( IDRL0A == IDRL0B ){ +// TSQLResult *result2a = 0; +// TSQLRow *row2a = 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()); +// result2a = conn->Query(oss.str().c_str()); +// // +// if ( !result2a ) throw -4; +// // +// row2a = result2a->Next(); +// // +// if ( row2a ){ +// UInt_t PKA = (UInt_t)atoll(row2a->GetField(0)); +// delete result2a; +// 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()); +// result2a = conn->Query(oss.str().c_str()); +// // +// if ( !result2a ) throw -4; +// // +// row2a = result2a->Next(); +// // +// if ( row2a ){ +// UInt_t PKB = (UInt_t)atoll(row2a->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 + // + // 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; + moved++; + // + } else { + // + // is just a repetition + // + if ( IsDebug() ) printf(" The run %u is already present in the GL_RUN table...\n",glrun->GetID()); + // printf(" CCCCCCCCICCCCCCCCCCCCIOOOOOOOOOO si muove Ciccio! %u \n",glrun->GetID()); + // if ( PEDANTIC && glrun->GetID() != 61563 ) throw -83; + if ( PEDANTIC ) throw -83; + }; + // if ( IsDebug() ) printf(" The run already exists in the GL_RUN table! ...\n"); + // if ( PEDANTIC ) throw -83; }; if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0)); //