--- chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2008/09/23 07:20:33 1.1 +++ chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2008/09/25 12:13:54 1.2 @@ -490,6 +490,52 @@ }; /** + * + * Set the variables which belogns to physendrun tree + * + */ +void PamelaDBOperations::SetPhysEndRunVariables(){ + // + // + // + TTree *T = 0; + T = (TTree*)file->Get("PhysEndRun"); + if ( !T || T->IsZombie() ) throw -90; + // + PhysEndRunEvent *pher= 0; + EventHeader *eh = 0; + T->SetBranchAddress("PhysEndRun", &pher); + T->SetBranchAddress("Header", &eh); + // + UInt_t phobt = 0; + UInt_t phpkt = 0; + // + glrun->SetPHYSENDRUN_MASK_S3S2S12(0); + glrun->SetPHYSENDRUN_MASK_S11CRC(0); + // + for (Int_t p=0; pGetEntries(); p++){ + // + T->GetEntry(p); + // + phobt = (UInt_t)eh->GetPscuHeader()->GetOrbitalTime(); + phpkt = (UInt_t)eh->GetPscuHeader()->GetCounter(); + // + if ( this->PKT(phpkt) >= this->PKT(glrun->GetRUNHEADER_PKT()) && this->PKT(phpkt) <= this->PKT(glrun->GetRUNTRAILER_PKT()) && this->OBT(phobt) >= this->OBT(glrun->GetRUNHEADER_OBT()) && this->OBT(phobt) <= this->OBT(glrun->GetRUNTRAILER_OBT()) ){ + if ( glrun->GetPHYSENDRUN_MASK_S3S2S12() || glrun->GetPHYSENDRUN_MASK_S11CRC() ){ + if ( IsDebug() ) printf(" WARNING while looping in physendrun: found two PhysEndRun packet for the same RUN! \n"); + if ( IsDebug() ) printf(" Actual values: %X %X New values %X %X \n ",glrun->GetPHYSENDRUN_MASK_S3S2S12(),glrun->GetPHYSENDRUN_MASK_S11CRC(),(UInt_t)pher->TB_ENDRUN.TB_PMT_MASK_S3S2S12,(UInt_t)pher->TB_ENDRUN.TB_PMT_MASK_S11CRC); + if ( PEDANTIC && IsDebug() ) printf(" ERROR while looping in physendrun: found two PhysEndRun packet for the same RUN!\n "); + if ( PEDANTIC ) throw -91; + } else { + glrun->SetPHYSENDRUN_MASK_S3S2S12((UInt_t)pher->TB_ENDRUN.TB_PMT_MASK_S3S2S12); + glrun->SetPHYSENDRUN_MASK_S11CRC((UInt_t)pher->TB_ENDRUN.TB_PMT_MASK_S11CRC); + }; + }; + }; + // +}; + +/** * Patch, look for upper limits to avoid processing retransmitted data */ Int_t PamelaDBOperations::SetUpperLimits(){ @@ -739,12 +785,12 @@ }; // if ( chewbacca && nevent < 1 ) { - pktfirst = chpktmin; - upperpkt = PKT(chpktmax); - pktlast = chpktmax; - obtfirst = chobtmin; - obtlast = chobtmax; - upperobt = OBT(chobtmax); + pktfirst = chpktmin; + upperpkt = PKT(chpktmax); + pktlast = chpktmax; + obtfirst = chobtmin; + obtlast = chobtmax; + upperobt = OBT(chobtmax); }; // if ( IsDebug() ) printf(" First entries are: OBT %u pkt_num %u entry %i\n",obtfirst,pktfirst,chminentry); @@ -752,9 +798,9 @@ if ( IsDebug() ) printf(" Last entries are: OBT %lld pkt_num %lld entry %i\n",upperobt,upperpkt,upperentry); // if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) || (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) ){ - if ( IsDebug() ) printf(" Inconsistent PKT/OBT sequence: \n (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) %llu < %llu && %llu > %llu \n OR \n (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) %llu > %llu && %llu < %llu \n",PKT(pktlast),PKT(pktfirst),OBT(obtlast),OBT(obtfirst),PKT(pktlast),PKT(pktfirst),OBT(obtlast),OBT(obtfirst)); - if ( PEDANTIC ) throw -88; - return(32); + if ( IsDebug() ) printf(" Inconsistent PKT/OBT sequence: \n (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) > OBT(obtfirst)) %llu < %llu && %llu > %llu \n OR \n (PKT(pktlast) > PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) %llu > %llu && %llu < %llu \n",PKT(pktlast),PKT(pktfirst),OBT(obtlast),OBT(obtfirst),PKT(pktlast),PKT(pktfirst),OBT(obtlast),OBT(obtfirst)); + if ( PEDANTIC ) throw -88; + return(32); }; // if ( !nevent ) return(64); @@ -1040,7 +1086,7 @@ upperpkt = pkth; upperobt = obth; rhev = lasthead+1; - } else { + } else { rhev = lasthead; }; if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); @@ -1260,19 +1306,19 @@ */ Long64_t PamelaDBOperations::PKT(UInt_t pkt_num){ // -// if ( IsDebug() ) printf(" pkt conversion: pkt_num is %u pktfirst is %u (UInt_t)(16777214/2)) is %u \n",pkt_num,ppktfirst,(UInt_t)(16777214/2)); + // if ( IsDebug() ) printf(" pkt conversion: pkt_num is %u pktfirst is %u (UInt_t)(16777214/2)) is %u \n",pkt_num,ppktfirst,(UInt_t)(16777214/2)); // if ( pkt_num < (ppktfirst/2) && ppktfirst > (16777214/2) ){ -// if ( IsDebug() ) printf(" rise up pktnum %lld \n",(Long64_t)pkt_num+16777215LL); + // if ( IsDebug() ) printf(" rise up pktnum %lld \n",(Long64_t)pkt_num+16777215LL); return((Long64_t)pkt_num+16777215LL); }; // if ( pkt_num > ((Long64_t)ppktfirst*2) && pkt_num > (16777214/2) ){ -// if ( IsDebug() ) printf(" rise down pktnum %lld \n",(Long64_t)pkt_num-16777215LL); + // if ( IsDebug() ) printf(" rise down pktnum %lld \n",(Long64_t)pkt_num-16777215LL); return((Long64_t)pkt_num-16777215LL); }; // -// if ( IsDebug() ) printf(" as it is %lld \n",(Long64_t)pkt_num); + // if ( IsDebug() ) printf(" as it is %lld \n",(Long64_t)pkt_num); return((Long64_t)pkt_num); // }; @@ -1282,20 +1328,20 @@ */ Long64_t PamelaDBOperations::OBT(UInt_t obt){ // -// if ( IsDebug() ) printf(" obt conversion: obt is %u obtfirst is %u (numeric_limits::max()/2) is %u \n",obt,pobtfirst,(UInt_t)(numeric_limits::max()/2)); + // if ( IsDebug() ) printf(" obt conversion: obt is %u obtfirst is %u (numeric_limits::max()/2) is %u \n",obt,pobtfirst,(UInt_t)(numeric_limits::max()/2)); // if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits::max()/2) ){ -// if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)obt+(Long64_t)numeric_limits::max()); + // if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)obt+(Long64_t)numeric_limits::max()); return((Long64_t)obt+(Long64_t)numeric_limits::max()); }; // if ( obt > ((Long64_t)pobtfirst*2) && obt > (numeric_limits::max()/2) ){ -// if ( IsDebug() ) printf(" pobtfirst*2 %lld \n",((Long64_t)pobtfirst*2)); -// if ( IsDebug() ) printf(" rise down pktnum %lld \n", (Long64_t)obt-(Long64_t)numeric_limits::max()); + // if ( IsDebug() ) printf(" pobtfirst*2 %lld \n",((Long64_t)pobtfirst*2)); + // if ( IsDebug() ) printf(" rise down pktnum %lld \n", (Long64_t)obt-(Long64_t)numeric_limits::max()); return((Long64_t)obt-(Long64_t)numeric_limits::max()); }; // -// if ( IsDebug() ) printf(" as it is %lld \n",(Long64_t)obt); + // if ( IsDebug() ) printf(" as it is %lld \n",(Long64_t)obt); return((Long64_t)obt); }; @@ -1405,6 +1451,7 @@ if ( IsDebug() ) printf(" firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); // this->SetCommonGLRUN(rhtime,rttime); + this->SetPhysEndRunVariables(); // }; @@ -2061,10 +2108,10 @@ cod = ehh->GetCounter(); tcod = (UInt_t)cod->Get(pctp->Physics); evbefh = TMath::Max(chminentry,tcod); -// if ( (UInt_t)evbefh == upperentry ) evbefh = upperentry + 1; // this does not work due to the Counter bug in chewbacca + // if ( (UInt_t)evbefh == upperentry ) evbefh = upperentry + 1; // this does not work due to the Counter bug in chewbacca if ( (UInt_t)evbefh == upperentry || !upperentry ) evbefh = upperentry + 1; -// - if ( debug ) printf(" evbefh %i upperentry %u \n",evbefh,upperentry); + // + if ( debug ) printf(" evbefh %i upperentry %u \n",evbefh,upperentry); // this->HandleRunFragments(false,true,evbefh,upperentry); // @@ -2367,10 +2414,10 @@ // if ( IsDebug() ) printf(" The new run has more events than the old one \n"); glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); -// oss.str(""); -// oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; -// if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); -// conn->Query(oss.str().c_str()); + // oss.str(""); + // oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; + // if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); + // conn->Query(oss.str().c_str()); if ( signal ) signal = false; goto gonext; // @@ -2385,10 +2432,10 @@ if ( IsDebug() ) printf(" The new run has the same number of events and the runheader the old one miss the runheader \n"); // glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); -// oss.str(""); -// oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; -// if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); -// conn->Query(oss.str().c_str()); + // oss.str(""); + // oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; + // if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); + // conn->Query(oss.str().c_str()); // if ( signal ) signal = false; goto gonext; @@ -2403,10 +2450,10 @@ if ( IsDebug() ) printf(" The new run has the same number of events, the runheader and the runtrailer the old one miss the runtrailer \n"); // glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); -// oss.str(""); -// oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; -// if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); -// conn->Query(oss.str().c_str()); + // oss.str(""); + // oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";"; + // if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str()); + // conn->Query(oss.str().c_str()); if ( signal ) signal = false; // }; @@ -2488,505 +2535,511 @@ if ( IsDebug() ) printf("The run is not consistent, it contains non-physics packets! The run has been handled \n"); // } else { - // - // 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; - // - this->FillClass(mishead,mistrail,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()); - // - // First of all insert the run in the fragment table... - // - oss.str(""); - oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE " - << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" - << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " - << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" - << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " - << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" - << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " - << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " - << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " - << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" - << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " - << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" - << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " - << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; - // - if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - // - if ( !result ) throw -4; - // - row = result->Next(); - // - if ( !row ){ // - // no, insert this run in the GL_RUN_FRAGMENTS table (check if exist before!) + // we have now the good first piece of a run, fill the glrun object // - if ( IsDebug() ) printf(" The run is new \n"); - if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n"); + if ( rhfirstev != firstev && !mishead ) mishead = true; + if ( rtlastev != lastev && !mistrail ) mistrail = true; // - glrun->SetID(this->AssignRunID()); - glrun->SetID_RUN_FRAG(0); - glrun->Fill_GL_RUN_FRAGMENTS(conn); + this->FillClass(mishead,mistrail,firstev,lastev); // - } else { - if ( IsDebug() ) printf(" The run is already present in the fragment table \n"); - if ( PEDANTIC ) throw -69; - return; - }; - // - if ( chewbacca && mishead && mistrail ) goto justcheck; - // - // can we find the other piece of the run in the GL_RUN_FRAGMENTS table? - // - if ( mishead && ( rhfirstev == firstev || chewbacca ) ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is - // missing it no way we can found a piece in the frag table + 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()); + // + // First of all insert the run in the fragment table... // oss.str(""); - oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN_FRAGMENTS WHERE " - << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " - << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " - << " ID != " << glrun->ID - << " ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! + oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE " + << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" + << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " + << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" + << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " + << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" + << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " + << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " + << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " + << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" + << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " + << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" + << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " + << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; // - if ( IsDebug() ) printf(" look for runheader in the fragments table: query is \n %s \n",oss.str().c_str()); + if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); result = conn->Query(oss.str().c_str()); // if ( !result ) throw -4; // row = result->Next(); // - if ( !row && NoFrag() ){ + if ( !row ){ + // + // no, insert this run in the GL_RUN_FRAGMENTS table (check if exist before!) + // + if ( IsDebug() ) printf(" The run is new \n"); + if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n"); + // + glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(0); + 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 ( chewbacca && mishead && mistrail ) goto justcheck; + // + // can we find the other piece of the run in the GL_RUN_FRAGMENTS table? + // + if ( mishead && ( rhfirstev == firstev || chewbacca ) ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is + // missing it no way we can found a piece in the frag table // oss.str(""); - oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN WHERE " + oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN_FRAGMENTS WHERE " << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " << " ID != " << glrun->ID - << " AND ID=ID_RUN_FRAG ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! + << " ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! // - if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str()); + if ( IsDebug() ) printf(" look for runheader in the fragments table: query is \n %s \n",oss.str().c_str()); result = conn->Query(oss.str().c_str()); // if ( !result ) throw -4; // - foundinrun = true; - // row = result->Next(); // - }; - // - if ( !row ){ - if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); - found = false; - } else { - // - found = false; // default value - // - if ( IsDebug() ) printf(" 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: + if ( !row && NoFrag() ){ + // + oss.str(""); + oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN WHERE " + << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " + << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " + << " ID != " << glrun->ID + << " AND ID=ID_RUN_FRAG ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! + // + if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + // + if ( !result ) throw -4; + // + foundinrun = true; + // + row = result->Next(); + // + }; // - if ( !mistrail && (UInt_t)atoll(row->GetField(1)) != 0 ){ - ULong64_t chkpkt = 0; - ULong64_t pktt = (ULong64_t)PKT(glrun->GetRUNTRAILER_PKT()); - ULong64_t pkth = (ULong64_t)PKT((UInt_t)atoll(row->GetField(4))); + if ( !row ){ + if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); + found = false; + } else { // - chkpkt = pkth + (ULong64_t)glrun->GetPKT_COUNTER() + 1ULL + 1ULL; + found = false; // default value // - if ( labs(chkpkt-pktt)<2 ){ + if ( IsDebug() ) printf(" 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: + // + if ( !mistrail && (UInt_t)atoll(row->GetField(1)) != 0 ){ + ULong64_t chkpkt = 0; + ULong64_t pktt = (ULong64_t)PKT(glrun->GetRUNTRAILER_PKT()); + ULong64_t pkth = (ULong64_t)PKT((UInt_t)atoll(row->GetField(4))); // - if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); + chkpkt = pkth + (ULong64_t)glrun->GetPKT_COUNTER() + 1ULL + 1ULL; // - found = true; + if ( labs(chkpkt-pktt)<2 ){ + // + if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); + // + found = true; + // + } else { + // + if ( IsDebug() ) printf(" The check with pkt counter failed: check %llu pktt %llu \n",chkpkt,pktt); + // + found = false; + // + }; + }; + if ( !found && chewbacca ) goto justcheck; + if ( !found ){ // - } else { + // if we arrive here we were not able to decide if the two pieces matches using only the pkt counter information, we must check times and obts // - if ( IsDebug() ) printf(" The check with pkt counter failed: check %llu pktt %llu \n",chkpkt,pktt); + ULong64_t chkpkt1 = 0; + ULong64_t orunh1 = (ULong64_t)PKT(glrun->GetRUNHEADER_PKT()); + ULong64_t dbrunt1 = (ULong64_t)PKT((UInt_t)atoll(row->GetField(5))); + chkpkt1 = labs(orunh1-dbrunt1); // - found = false; + ULong64_t chkpkt2 = 0; + ULong64_t orunh2 = (ULong64_t)OBT(glrun->GetRUNHEADER_OBT()); + ULong64_t dbrunt2 = (ULong64_t)OBT((UInt_t)atoll(row->GetField(3))); + chkpkt2 = labs(orunh2-dbrunt2); + // + ULong64_t chkpkt3 = 0; + ULong64_t orunh3 = (ULong64_t)(glrun->GetRUNHEADER_TIME()); + ULong64_t dbrunt3 = (ULong64_t)((UInt_t)atoll(row->GetField(2))); + chkpkt3 = labs(orunh3-dbrunt3); // + if ( (chkpkt1 < 200 || chkpkt2 < 20000) && chkpkt3 < 20 ){ + // if ( chkpkt1 < 100 && chkpkt2 < 30000 && chkpkt3 < 30 ){ + // + if ( IsDebug() ) printf(" FOUND!!! check1 %llu<200 cechk2 %llu<20000 check3 %llu<20 \n",chkpkt1,chkpkt2,chkpkt3); + // + found = true; + // + } else { + // + if ( IsDebug() ) printf(" Check failed: check1 %llu<200? cechk2 %llu<20000? check3 %llu<20? \n",chkpkt1,chkpkt2,chkpkt3); + // + found = false; + // + }; }; }; - if ( !found && chewbacca ) goto justcheck; - if ( !found ){ + // + if ( found ){ + // + // we have found the missing piece, glue the two together, merge the informations, fill the gl_run table (check first runs do not exists), delete entry in frag table + // + if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); + // + if ( foundinrun ){ + glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); + glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); + }; // - // if we arrive here we were not able to decide if the two pieces matches using only the pkt counter information, we must check times and obts + GL_RUN *glrun1 = new GL_RUN(); // - ULong64_t chkpkt1 = 0; - ULong64_t orunh1 = (ULong64_t)PKT(glrun->GetRUNHEADER_PKT()); - ULong64_t dbrunt1 = (ULong64_t)PKT((UInt_t)atoll(row->GetField(5))); - chkpkt1 = labs(orunh1-dbrunt1); - // - ULong64_t chkpkt2 = 0; - ULong64_t orunh2 = (ULong64_t)OBT(glrun->GetRUNHEADER_OBT()); - ULong64_t dbrunt2 = (ULong64_t)OBT((UInt_t)atoll(row->GetField(3))); - chkpkt2 = labs(orunh2-dbrunt2); - // - ULong64_t chkpkt3 = 0; - ULong64_t orunh3 = (ULong64_t)(glrun->GetRUNHEADER_TIME()); - ULong64_t dbrunt3 = (ULong64_t)((UInt_t)atoll(row->GetField(2))); - chkpkt3 = labs(orunh3-dbrunt3); + // UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); // - if ( (chkpkt1 < 200 || chkpkt2 < 20000) && chkpkt3 < 20 ){ - // if ( chkpkt1 < 100 && chkpkt2 < 30000 && chkpkt3 < 30 ){ - // - if ( IsDebug() ) printf(" FOUND!!! check1 %llu<200 cechk2 %llu<20000 check3 %llu<20 \n",chkpkt1,chkpkt2,chkpkt3); - // - found = true; - // - } else { + oss.str(""); + oss << " ID="<GetField(0)<<";"; + // + glrun1->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // here we have runheader infos + // + // merge infos + // + UInt_t apkt = PKT(glrun1->GetRUNTRAILER_PKT()); + ULong64_t aobt = OBT(glrun1->GetRUNTRAILER_OBT()); + UInt_t bpkt = PKT(glrun->GetRUNHEADER_PKT()); + ULong64_t bobt = OBT(glrun->GetRUNHEADER_OBT()); + if ( IsDebug() ) printf(" Check overlapping events: %u %u %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); + TTree *T= 0; + T = (TTree*)file->Get("Physics"); + if ( !T || T->IsZombie() ) throw -16; + EventHeader *eh = 0; + PscuHeader *ph = 0; + T->SetBranchAddress("Header", &eh); + while ( apkt > bpkt && aobt > bobt && firstev < lastev ){ + T->GetEntry(firstev); + ph = eh->GetPscuHeader(); + bpkt = PKT(ph->GetCounter()); + bobt = OBT(ph->GetOrbitalTime()); + firstev++; + if ( PEDANTIC ) throw -71; + }; + if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); + // + glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER()); + glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER()); + glrun1->SetRUNTRAILER_TIME(glrun->GetRUNTRAILER_TIME()); + glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT()); + glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); + // + glrun->SetEV_FROM(firstev); + glrun->SetNEVENTS(lastev-firstev+1); + // + glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); + glrun->SetRUNHEADER_OBT(glrun1->GetRUNHEADER_OBT()); + glrun->SetRUNHEADER_PKT(glrun1->GetRUNHEADER_PKT()); + glrun->SetCOMPILATIONTIMESTAMP(glrun1->GetCOMPILATIONTIMESTAMP()); + glrun->SetFAV_WRK_SCHEDULE(glrun1->GetFAV_WRK_SCHEDULE()); + glrun->SetEFF_WRK_SCHEDULE(glrun1->GetEFF_WRK_SCHEDULE()); + glrun->SetPRH_VAR_TRG_MODE_A(glrun1->GetPRH_VAR_TRG_MODE_A()); + glrun->SetPRH_VAR_TRG_MODE_B(glrun1->GetPRH_VAR_TRG_MODE_B()); + glrun->SetACQ_BUILD_INFO(glrun1->GetACQ_BUILD_INFO()); + glrun->SetACQ_VAR_INFO(glrun1->GetACQ_VAR_INFO()); + glrun->SetRM_ACQ_AFTER_CALIB(glrun1->GetRM_ACQ_AFTER_CALIB()); + glrun->SetRM_ACQ_SETTING_MODE(glrun1->GetRM_ACQ_SETTING_MODE()); + glrun->SetTRK_CALIB_USED(glrun1->GetTRK_CALIB_USED()); + glrun->SetCAL_DSP_MASK(glrun1->GetCAL_DSP_MASK()); + glrun->SetLAST_TIMESYNC(glrun1->GetLAST_TIMESYNC()); + glrun->SetOBT_TIMESYNC(glrun1->GetOBT_TIMESYNC()); + // + if ( glrun1->GetPHYSENDRUN_MASK_S3S2S12() ) glrun->SetPHYSENDRUN_MASK_S3S2S12(glrun1->GetPHYSENDRUN_MASK_S3S2S12()); + if ( glrun1->GetPHYSENDRUN_MASK_S11CRC() ) glrun->SetPHYSENDRUN_MASK_S11CRC(glrun1->GetPHYSENDRUN_MASK_S11CRC()); + // + if ( !IsRunAlreadyInserted() ){ + // + // glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(glrun1->GetID()); + glrun->Fill_GL_RUN(conn); // - if ( IsDebug() ) printf(" Check failed: check1 %llu<200? cechk2 %llu<20000? check3 %llu<20? \n",chkpkt1,chkpkt2,chkpkt3); + // set id number // - found = false; + glrun1->SetID_RUN_FRAG(glrun->GetID()); + glrun1->Fill_GL_RUN(conn); // }; - }; - }; - // - if ( found ){ - // - // we have found the missing piece, glue the two together, merge the informations, fill the gl_run table (check first runs do not exists), delete entry in frag table - // - if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); - // - if ( foundinrun ){ - glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); - glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); - }; - // - GL_RUN *glrun1 = new GL_RUN(); - // - // UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); - // - oss.str(""); - oss << " ID="<GetField(0)<<";"; - // - glrun1->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // here we have runheader infos - // - // merge infos - // - UInt_t apkt = PKT(glrun1->GetRUNTRAILER_PKT()); - ULong64_t aobt = OBT(glrun1->GetRUNTRAILER_OBT()); - UInt_t bpkt = PKT(glrun->GetRUNHEADER_PKT()); - ULong64_t bobt = OBT(glrun->GetRUNHEADER_OBT()); - if ( IsDebug() ) printf(" Check overlapping events: %u %u %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); - TTree *T= 0; - T = (TTree*)file->Get("Physics"); - if ( !T || T->IsZombie() ) throw -16; - EventHeader *eh = 0; - PscuHeader *ph = 0; - T->SetBranchAddress("Header", &eh); - while ( apkt > bpkt && aobt > bobt && firstev < lastev ){ - T->GetEntry(firstev); - ph = eh->GetPscuHeader(); - bpkt = PKT(ph->GetCounter()); - bobt = OBT(ph->GetOrbitalTime()); - firstev++; - if ( PEDANTIC ) throw -71; - }; - if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); - // - glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER()); - glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER()); - glrun1->SetRUNTRAILER_TIME(glrun->GetRUNTRAILER_TIME()); - glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT()); - glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); - // - glrun->SetEV_FROM(firstev); - glrun->SetNEVENTS(lastev-firstev+1); - // - glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); - glrun->SetRUNHEADER_OBT(glrun1->GetRUNHEADER_OBT()); - glrun->SetRUNHEADER_PKT(glrun1->GetRUNHEADER_PKT()); - glrun->SetCOMPILATIONTIMESTAMP(glrun1->GetCOMPILATIONTIMESTAMP()); - glrun->SetFAV_WRK_SCHEDULE(glrun1->GetFAV_WRK_SCHEDULE()); - glrun->SetEFF_WRK_SCHEDULE(glrun1->GetEFF_WRK_SCHEDULE()); - glrun->SetPRH_VAR_TRG_MODE_A(glrun1->GetPRH_VAR_TRG_MODE_A()); - glrun->SetPRH_VAR_TRG_MODE_B(glrun1->GetPRH_VAR_TRG_MODE_B()); - glrun->SetACQ_BUILD_INFO(glrun1->GetACQ_BUILD_INFO()); - glrun->SetACQ_VAR_INFO(glrun1->GetACQ_VAR_INFO()); - glrun->SetRM_ACQ_AFTER_CALIB(glrun1->GetRM_ACQ_AFTER_CALIB()); - glrun->SetRM_ACQ_SETTING_MODE(glrun1->GetRM_ACQ_SETTING_MODE()); - glrun->SetTRK_CALIB_USED(glrun1->GetTRK_CALIB_USED()); - glrun->SetCAL_DSP_MASK(glrun1->GetCAL_DSP_MASK()); - glrun->SetLAST_TIMESYNC(glrun1->GetLAST_TIMESYNC()); - glrun->SetOBT_TIMESYNC(glrun1->GetOBT_TIMESYNC()); - // - if ( !IsRunAlreadyInserted() ){ + // delete old entry in fragment table // - // glrun->SetID(this->AssignRunID()); - glrun->SetID_RUN_FRAG(glrun1->GetID()); - glrun->Fill_GL_RUN(conn); + glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); + glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); + // + delete glrun1; // - // set id number // - glrun1->SetID_RUN_FRAG(glrun->GetID()); - glrun1->Fill_GL_RUN(conn); + return; // }; - // delete old entry in fragment table - // - glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); - glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); - // - delete glrun1; - // - // - return; // }; // - }; - // - if ( mistrail && ( rtlastev == lastev || chewbacca )) { // look for runtrailer (only when at the end of the file, if at the beginning and the runh is - // missing it no way we can found a piece in the frag table - // - oss.str(""); - oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN_FRAGMENTS WHERE " - << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " - << " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() << " AND " - << " ID != " << glrun->ID - << " ORDER BY RUNTRAILER_TIME ASC LIMIT 1;"; - // - if ( IsDebug() ) printf(" look for runtrailer in the fragments table: query is \n %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - // - if ( !result ) throw -4; - // - row = result->Next(); - // - if ( !row && NoFrag() ){ + if ( mistrail && ( rtlastev == lastev || chewbacca )) { // look for runtrailer (only when at the end of the file, if at the beginning and the runh is + // missing it no way we can found a piece in the frag table // oss.str(""); - oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN WHERE " + oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN_FRAGMENTS WHERE " << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " << " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() << " AND " << " ID != " << glrun->ID - << " AND ID=ID_RUN_FRAG ORDER BY RUNTRAILER_TIME ASC LIMIT 1;"; + << " ORDER BY RUNTRAILER_TIME ASC LIMIT 1;"; // - if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str()); + if ( IsDebug() ) printf(" look for runtrailer in the fragments table: query is \n %s \n",oss.str().c_str()); result = conn->Query(oss.str().c_str()); // if ( !result ) throw -4; // - foundinrun = true; row = result->Next(); // - }; - // - if ( !row ){ - if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); - found = false; - } else { - // - found = false; // default value - // - if ( IsDebug() ) printf(" 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: + if ( !row && NoFrag() ){ + // + oss.str(""); + oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN WHERE " + << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " + << " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() << " AND " + << " ID != " << glrun->ID + << " AND ID=ID_RUN_FRAG ORDER BY RUNTRAILER_TIME ASC LIMIT 1;"; + // + if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + // + if ( !result ) throw -4; + // + foundinrun = true; + row = result->Next(); + // + }; // - if ( !mishead && (UInt_t)atoll(row->GetField(1)) != 0 ){ - ULong64_t chkpkt = 0; - ULong64_t pktt = (ULong64_t)PKT((UInt_t)atoll(row->GetField(4))); - ULong64_t pkth = (ULong64_t)PKT(glrun->GetRUNHEADER_PKT()); + if ( !row ){ + if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); + found = false; + } else { + // + found = false; // default value // - chkpkt = pkth + (ULong64_t)((UInt_t)atoll(row->GetField(1))) + 1ULL + 1ULL; + if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n"); // - if ( labs(chkpkt-pktt)<2 ){ + // if we have both runheader and runtrailer we can check with pkt_counter: + // + if ( !mishead && (UInt_t)atoll(row->GetField(1)) != 0 ){ + ULong64_t chkpkt = 0; + ULong64_t pktt = (ULong64_t)PKT((UInt_t)atoll(row->GetField(4))); + ULong64_t pkth = (ULong64_t)PKT(glrun->GetRUNHEADER_PKT()); // - if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); + chkpkt = pkth + (ULong64_t)((UInt_t)atoll(row->GetField(1))) + 1ULL + 1ULL; // - found = true; + if ( labs(chkpkt-pktt)<2 ){ + // + if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); + // + found = true; + // + } else { + // + if ( IsDebug() ) printf(" The check with pkt counter failed: check %llu pktt %llu \n",chkpkt,pktt); + // + found = false; + // + }; + }; + if ( !found && chewbacca ) goto justcheck; + if ( !found ){ // - } else { + // if we arrive here we were not able to decide if the two pieces matches using only the pkt counter information, we must check times and obts // - if ( IsDebug() ) printf(" The check with pkt counter failed: check %llu pktt %llu \n",chkpkt,pktt); + ULong64_t chkpkt1 = 0; + ULong64_t orunh1 = (ULong64_t)PKT(glrun->GetRUNTRAILER_PKT()); + ULong64_t dbrunt1 = (ULong64_t)PKT((UInt_t)atoll(row->GetField(5))); + chkpkt1 = labs(orunh1-dbrunt1); // - found = false; + ULong64_t chkpkt2 = 0; + ULong64_t orunh2 = (ULong64_t)OBT(glrun->GetRUNTRAILER_OBT()); + ULong64_t dbrunt2 = (ULong64_t)OBT((UInt_t)atoll(row->GetField(3))); + chkpkt2 = labs(orunh2-dbrunt2); + // + ULong64_t chkpkt3 = 0; + ULong64_t orunh3 = (ULong64_t)(glrun->GetRUNTRAILER_TIME()); + ULong64_t dbrunt3 = (ULong64_t)((UInt_t)atoll(row->GetField(2))); + chkpkt3 = labs(orunh3-dbrunt3); // + if ( (chkpkt1 < 200 || chkpkt2 < 20000) && chkpkt3 < 20 ){ + // + if ( IsDebug() ) printf(" FOUND!!! check1 %llu<200 cechk2 %llu<20000 check3 %llu<20 \n",chkpkt1,chkpkt2,chkpkt3); + // + found = true; + // + } else { + // + if ( IsDebug() ) printf(" Check failed: check1 %llu<200? cechk2 %llu<20000? check3 %llu<20? \n",chkpkt1,chkpkt2,chkpkt3); + // + found = false; + // + }; }; }; - if ( !found && chewbacca ) goto justcheck; - if ( !found ){ + // + if ( found ){ + // + // we have found the missing piece, glue the two together, merge the informations, fill the gl_run table (check first runs do not exists), delete entry in frag table + // + if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); + // + if ( foundinrun ){ + glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); + glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); + }; // - // if we arrive here we were not able to decide if the two pieces matches using only the pkt counter information, we must check times and obts + GL_RUN *glrun1 = new GL_RUN(); // - ULong64_t chkpkt1 = 0; - ULong64_t orunh1 = (ULong64_t)PKT(glrun->GetRUNTRAILER_PKT()); - ULong64_t dbrunt1 = (ULong64_t)PKT((UInt_t)atoll(row->GetField(5))); - chkpkt1 = labs(orunh1-dbrunt1); + // UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); // - ULong64_t chkpkt2 = 0; - ULong64_t orunh2 = (ULong64_t)OBT(glrun->GetRUNTRAILER_OBT()); - ULong64_t dbrunt2 = (ULong64_t)OBT((UInt_t)atoll(row->GetField(3))); - chkpkt2 = labs(orunh2-dbrunt2); + oss.str(""); + oss << " ID="<GetField(0)<<";"; // - ULong64_t chkpkt3 = 0; - ULong64_t orunh3 = (ULong64_t)(glrun->GetRUNTRAILER_TIME()); - ULong64_t dbrunt3 = (ULong64_t)((UInt_t)atoll(row->GetField(2))); - chkpkt3 = labs(orunh3-dbrunt3); + glrun1->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // here we have runtrailer infos // - if ( (chkpkt1 < 200 || chkpkt2 < 20000) && chkpkt3 < 20 ){ - // - if ( IsDebug() ) printf(" FOUND!!! check1 %llu<200 cechk2 %llu<20000 check3 %llu<20 \n",chkpkt1,chkpkt2,chkpkt3); + // merge infos + // + UInt_t apkt = PKT(glrun->GetRUNTRAILER_PKT()); + ULong64_t aobt = OBT(glrun->GetRUNTRAILER_OBT()); + UInt_t bpkt = PKT(glrun1->GetRUNHEADER_PKT()); + ULong64_t bobt = OBT(glrun1->GetRUNHEADER_OBT()); + if ( IsDebug() ) printf(" Check overlapping events: %u %u %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev); + TTree *T= 0; + T = (TTree*)file->Get("Physics"); + if ( !T || T->IsZombie() ) throw -16; + EventHeader *eh = 0; + PscuHeader *ph = 0; + T->SetBranchAddress("Header", &eh); + while ( apkt > bpkt && aobt > bobt && lastev > 0 ){ + T->GetEntry(lastev); + ph = eh->GetPscuHeader(); + apkt = PKT(ph->GetCounter()); + aobt = OBT(ph->GetOrbitalTime()); + lastev--; + if ( PEDANTIC ) throw -72; + }; + if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev); + // + glrun->SetEV_TO(lastev); + glrun->SetNEVENTS(lastev-firstev+1); + glrun->SetPKT_COUNTER(glrun1->GetPKT_COUNTER()); + glrun->SetPKT_READY_COUNTER(glrun1->GetPKT_READY_COUNTER()); + glrun->SetRUNTRAILER_TIME(glrun1->GetRUNTRAILER_TIME()); + glrun->SetRUNTRAILER_OBT(glrun1->GetRUNTRAILER_OBT()); + glrun->SetRUNTRAILER_PKT(glrun1->GetRUNTRAILER_PKT()); + // + glrun1->SetRUNHEADER_TIME(glrun->GetRUNHEADER_TIME()); + glrun1->SetRUNHEADER_OBT(glrun->GetRUNHEADER_OBT()); + glrun1->SetRUNHEADER_PKT(glrun->GetRUNHEADER_PKT()); + glrun1->SetCOMPILATIONTIMESTAMP(glrun->GetCOMPILATIONTIMESTAMP()); + glrun1->SetFAV_WRK_SCHEDULE(glrun->GetFAV_WRK_SCHEDULE()); + glrun1->SetEFF_WRK_SCHEDULE(glrun->GetEFF_WRK_SCHEDULE()); + glrun1->SetPRH_VAR_TRG_MODE_A(glrun->GetPRH_VAR_TRG_MODE_A()); + glrun1->SetPRH_VAR_TRG_MODE_B(glrun->GetPRH_VAR_TRG_MODE_B()); + glrun1->SetACQ_BUILD_INFO(glrun->GetACQ_BUILD_INFO()); + glrun1->SetACQ_VAR_INFO(glrun->GetACQ_VAR_INFO()); + glrun1->SetRM_ACQ_AFTER_CALIB(glrun->GetRM_ACQ_AFTER_CALIB()); + glrun1->SetRM_ACQ_SETTING_MODE(glrun->GetRM_ACQ_SETTING_MODE()); + glrun1->SetTRK_CALIB_USED(glrun->GetTRK_CALIB_USED()); + glrun1->SetCAL_DSP_MASK(glrun->GetCAL_DSP_MASK()); + glrun1->SetLAST_TIMESYNC(glrun->GetLAST_TIMESYNC()); + glrun1->SetOBT_TIMESYNC(glrun->GetOBT_TIMESYNC()); + // + if ( glrun->GetPHYSENDRUN_MASK_S3S2S12() ) glrun1->SetPHYSENDRUN_MASK_S3S2S12(glrun->GetPHYSENDRUN_MASK_S3S2S12()); + if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ) glrun1->SetPHYSENDRUN_MASK_S11CRC(glrun->GetPHYSENDRUN_MASK_S11CRC()); + // + if ( !IsRunAlreadyInserted() ){ + // + // glrun->SetID(this->AssignRunID()); // - found = true; + glrun->SetID_RUN_FRAG(glrun1->GetID()); + glrun->Fill_GL_RUN(conn); // - } else { + // set id number // - if ( IsDebug() ) printf(" Check failed: check1 %llu<200? cechk2 %llu<20000? check3 %llu<20? \n",chkpkt1,chkpkt2,chkpkt3); - // - found = false; + glrun1->SetID_RUN_FRAG(glrun->GetID()); + glrun1->Fill_GL_RUN(conn); // }; + // + // delete old entries in fragment table + // + glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); + glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); + // + delete glrun1; + // + return; + // }; + // }; // - if ( found ){ - // - // we have found the missing piece, glue the two together, merge the informations, fill the gl_run table (check first runs do not exists), delete entry in frag table - // - if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); - // - if ( foundinrun ){ - glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); - glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); - }; + justcheck: + // + if ( !found ){ // - GL_RUN *glrun1 = new GL_RUN(); + if ( IsDebug() ) printf(" not found, check if we have already processed the file \n "); // - // UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); + // not found, has this run already inserted in the GL_RUN or in the GL_RUN_FRAGMENTS table? // oss.str(""); - oss << " ID="<GetField(0)<<";"; + oss << " SELECT ID 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 (" + << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " + << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" + << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " + << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " + << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " + << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" + << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " + << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" + << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " + << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; // - glrun1->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // here we have runtrailer infos + if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); // - // merge infos + if ( !result ) throw -4; // - UInt_t apkt = PKT(glrun->GetRUNTRAILER_PKT()); - ULong64_t aobt = OBT(glrun->GetRUNTRAILER_OBT()); - UInt_t bpkt = PKT(glrun1->GetRUNHEADER_PKT()); - ULong64_t bobt = OBT(glrun1->GetRUNHEADER_OBT()); - if ( IsDebug() ) printf(" Check overlapping events: %u %u %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev); - TTree *T= 0; - T = (TTree*)file->Get("Physics"); - if ( !T || T->IsZombie() ) throw -16; - EventHeader *eh = 0; - PscuHeader *ph = 0; - T->SetBranchAddress("Header", &eh); - while ( apkt > bpkt && aobt > bobt && lastev > 0 ){ - T->GetEntry(lastev); - ph = eh->GetPscuHeader(); - apkt = PKT(ph->GetCounter()); - aobt = OBT(ph->GetOrbitalTime()); - lastev--; - if ( PEDANTIC ) throw -72; - }; - if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu lastev is %i\n",apkt,bpkt,aobt,bobt,lastev); - // - glrun->SetEV_TO(lastev); - glrun->SetNEVENTS(lastev-firstev+1); - glrun->SetPKT_COUNTER(glrun1->GetPKT_COUNTER()); - glrun->SetPKT_READY_COUNTER(glrun1->GetPKT_READY_COUNTER()); - glrun->SetRUNTRAILER_TIME(glrun1->GetRUNTRAILER_TIME()); - glrun->SetRUNTRAILER_OBT(glrun1->GetRUNTRAILER_OBT()); - glrun->SetRUNTRAILER_PKT(glrun1->GetRUNTRAILER_PKT()); - // - glrun1->SetRUNHEADER_TIME(glrun->GetRUNHEADER_TIME()); - glrun1->SetRUNHEADER_OBT(glrun->GetRUNHEADER_OBT()); - glrun1->SetRUNHEADER_PKT(glrun->GetRUNHEADER_PKT()); - glrun1->SetCOMPILATIONTIMESTAMP(glrun->GetCOMPILATIONTIMESTAMP()); - glrun1->SetFAV_WRK_SCHEDULE(glrun->GetFAV_WRK_SCHEDULE()); - glrun1->SetEFF_WRK_SCHEDULE(glrun->GetEFF_WRK_SCHEDULE()); - glrun1->SetPRH_VAR_TRG_MODE_A(glrun->GetPRH_VAR_TRG_MODE_A()); - glrun1->SetPRH_VAR_TRG_MODE_B(glrun->GetPRH_VAR_TRG_MODE_B()); - glrun1->SetACQ_BUILD_INFO(glrun->GetACQ_BUILD_INFO()); - glrun1->SetACQ_VAR_INFO(glrun->GetACQ_VAR_INFO()); - glrun1->SetRM_ACQ_AFTER_CALIB(glrun->GetRM_ACQ_AFTER_CALIB()); - glrun1->SetRM_ACQ_SETTING_MODE(glrun->GetRM_ACQ_SETTING_MODE()); - glrun1->SetTRK_CALIB_USED(glrun->GetTRK_CALIB_USED()); - glrun1->SetCAL_DSP_MASK(glrun->GetCAL_DSP_MASK()); - glrun1->SetLAST_TIMESYNC(glrun->GetLAST_TIMESYNC()); - glrun1->SetOBT_TIMESYNC(glrun->GetOBT_TIMESYNC()); + row = result->Next(); // - if ( !IsRunAlreadyInserted() ){ - // - // glrun->SetID(this->AssignRunID()); - // - glrun->SetID_RUN_FRAG(glrun1->GetID()); - glrun->Fill_GL_RUN(conn); - // - // set id number - // - glrun1->SetID_RUN_FRAG(glrun->GetID()); - glrun1->Fill_GL_RUN(conn); - // + if ( row ){ + 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()); + glrun->Fill_GL_RUN(conn); + glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); + }; }; - // - // delete old entries in fragment table - // - glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); - glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); - // - delete glrun1; - // - return; - // }; - // - }; - // - justcheck: - // - if ( !found ){ - // - if ( IsDebug() ) printf(" not found, check if we have already processed the file \n "); - // - // 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 " - << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" - << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " - << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" - << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " - << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" - << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " - << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " - << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " - << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" - << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " - << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" - << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " - << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; - // - if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - // - if ( !result ) throw -4; - // - row = result->Next(); - // - if ( row ){ - if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); - if ( PEDANTIC ) throw -70; - } else { - if ( NoFrag() ){ - glrun->SetID_RUN_FRAG(glrun->GetID()); - glrun->Fill_GL_RUN(conn); - glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); - }; - }; - }; }; // EEE // return; @@ -3068,16 +3121,16 @@ code = eh->GetCounter(); checkfirst = 0; for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ - if ( strcmp(*Iter,"Physics") ) checkfirst += code->Get(GetPacketType(*Iter)); - }; + if ( strcmp(*Iter,"Physics") ) checkfirst += code->Get(GetPacketType(*Iter)); + }; if ( IsDebug() ) printf(" Check first is %i firstev is %i\n",checkfirst,firstev); // T->GetEntry(lastev); code = eh->GetCounter(); checklast = 0; for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ - if ( strcmp(*Iter,"Physics") ) checklast += code->Get(GetPacketType(*Iter)); - }; + if ( strcmp(*Iter,"Physics") ) checklast += code->Get(GetPacketType(*Iter)); + }; if ( IsDebug() ) printf(" Check last is %i lastev is %i\n",checklast,lastev); // if ( checkfirst == checklast ){ @@ -3092,7 +3145,7 @@ // // HERE WE MUST HANDLE THAT RUNS AND GO BACK // -// if ( IsDebug() ) printf(" Never seen this case, try to handle it anyway, it was throw -95\n"); + // if ( IsDebug() ) printf(" Never seen this case, try to handle it anyway, it was throw -95\n"); // Bool_t emptyruns = false; UInt_t check = 0; @@ -3178,345 +3231,349 @@ lastObt = firstObt; lastPkt = firstPkt; }; - glrun->SetRUNTRAILER_PKT(lastPkt); - glrun->SetRUNTRAILER_OBT(lastObt); - lastentry++; - }; - // - this->SetCommonGLRUN(firstTime,lastTime); - // - if ( chminentry == firstentry ){ // EEE - if ( IsDebug() ) printf(" Inside isrunconsistent found a fragment of run at the beginning of the file, put it in the fragment table \n"); -// -// this->HandleRunFragments(true,mistrail,firstentry,lastentry); // cannot call it here since it enters a loop which will destroy the already stored variables if we arrive here from HandleRunFragments -// - - - - - - - - - - - - - - mishead = true; - - - UInt_t rhfirstev = firstentry; -// UInt_t rtlastev = lastentry; - Bool_t found = false; - Bool_t foundinrun = false; - // - TSQLResult *result = 0; - TSQLRow *row = 0; - // - stringstream oss; - oss.str(""); - // - // 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; - // -// this->FillClass(mishead,mistrail,firstev,lastev); - // - if ( IsDebug() ) printf("zz The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n"); - if ( IsDebug() ) printf("zz 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()); - // - // First of all insert the run in the fragment table... - // - oss.str(""); - oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE " - << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" - << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " - << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" - << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " - << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" - << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " - << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " - << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " - << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" - << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " - << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" - << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " - << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; - // - if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - // - if ( !result ) throw -4; - // - row = result->Next(); - // - if ( !row ){ - // - // no, insert this run in the GL_RUN_FRAGMENTS table (check if exist before!) - // - if ( IsDebug() ) printf(" The run is new \n"); - if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n"); - // - glrun->SetID(this->AssignRunID()); - glrun->SetID_RUN_FRAG(0); - 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 ( chewbacca && mishead && mistrail ) goto zjustcheck; - // - // can we find the other piece of the run in the GL_RUN_FRAGMENTS table? - // - if ( mishead && ( rhfirstev == firstev || chewbacca ) ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is - // missing it no way we can found a piece in the frag table - // - oss.str(""); - oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN_FRAGMENTS WHERE " - << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " - << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " - << " ID != " << glrun->ID - << " ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! - // - if ( IsDebug() ) printf(" look for runheader in the fragments table: query is \n %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - // - if ( !result ) throw -4; - // - row = result->Next(); - // - if ( !row && NoFrag() ){ - // - oss.str(""); - oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN WHERE " - << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " - << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " - << " ID != " << glrun->ID - << " AND ID=ID_RUN_FRAG ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! - // - if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - // - if ( !result ) throw -4; - // - foundinrun = true; - // - row = result->Next(); - // - }; - // - if ( !row ){ - if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); - found = false; - } else { - // - found = false; // default value - // - if ( IsDebug() ) printf(" 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: - // - if ( !mistrail && (UInt_t)atoll(row->GetField(1)) != 0 ){ - ULong64_t chkpkt = 0; - ULong64_t pktt = (ULong64_t)PKT(glrun->GetRUNTRAILER_PKT()); - ULong64_t pkth = (ULong64_t)PKT((UInt_t)atoll(row->GetField(4))); - // - chkpkt = pkth + (ULong64_t)glrun->GetPKT_COUNTER() + 1ULL + 1ULL; - // - if ( labs(chkpkt-pktt)<2 ){ - // - if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); - // - found = true; - // - } else { - // - if ( IsDebug() ) printf(" The check with pkt counter failed: check %llu pktt %llu \n",chkpkt,pktt); - // - found = false; - // - }; - }; - if ( !found && chewbacca ) goto zjustcheck; - if ( !found ){ - // - // if we arrive here we were not able to decide if the two pieces matches using only the pkt counter information, we must check times and obts - // - ULong64_t chkpkt1 = 0; - ULong64_t orunh1 = (ULong64_t)PKT(glrun->GetRUNHEADER_PKT()); - ULong64_t dbrunt1 = (ULong64_t)PKT((UInt_t)atoll(row->GetField(5))); - chkpkt1 = labs(orunh1-dbrunt1); - // - ULong64_t chkpkt2 = 0; - ULong64_t orunh2 = (ULong64_t)OBT(glrun->GetRUNHEADER_OBT()); - ULong64_t dbrunt2 = (ULong64_t)OBT((UInt_t)atoll(row->GetField(3))); - chkpkt2 = labs(orunh2-dbrunt2); - // - ULong64_t chkpkt3 = 0; - ULong64_t orunh3 = (ULong64_t)(glrun->GetRUNHEADER_TIME()); - ULong64_t dbrunt3 = (ULong64_t)((UInt_t)atoll(row->GetField(2))); - chkpkt3 = labs(orunh3-dbrunt3); - // - if ( (chkpkt1 < 200 || chkpkt2 < 20000) && chkpkt3 < 20 ){ - // if ( chkpkt1 < 100 && chkpkt2 < 30000 && chkpkt3 < 30 ){ - // - if ( IsDebug() ) printf(" FOUND!!! check1 %llu<200 cechk2 %llu<20000 check3 %llu<20 \n",chkpkt1,chkpkt2,chkpkt3); - // - found = true; - // - } else { - // - if ( IsDebug() ) printf(" Check failed: check1 %llu<200? cechk2 %llu<20000? check3 %llu<20? \n",chkpkt1,chkpkt2,chkpkt3); - // - found = false; - // - }; - }; - }; - // - if ( found ){ - // - // we have found the missing piece, glue the two together, merge the informations, fill the gl_run table (check first runs do not exists), delete entry in frag table - // - if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); - // - if ( foundinrun ){ - glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); - glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); - }; - // - GL_RUN *glrun1 = new GL_RUN(); - // - // UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); - // - oss.str(""); - oss << " ID="<GetField(0)<<";"; - // - glrun1->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // here we have runheader infos - // - // merge infos - // - UInt_t apkt = PKT(glrun1->GetRUNTRAILER_PKT()); - ULong64_t aobt = OBT(glrun1->GetRUNTRAILER_OBT()); - UInt_t bpkt = PKT(glrun->GetRUNHEADER_PKT()); - ULong64_t bobt = OBT(glrun->GetRUNHEADER_OBT()); - if ( IsDebug() ) printf(" Check overlapping events: %u %u %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); - TTree *T= 0; - T = (TTree*)file->Get("Physics"); - if ( !T || T->IsZombie() ) throw -16; - EventHeader *eh = 0; - PscuHeader *ph = 0; - T->SetBranchAddress("Header", &eh); - while ( apkt > bpkt && aobt > bobt && firstev < lastev ){ - T->GetEntry(firstev); - ph = eh->GetPscuHeader(); - bpkt = PKT(ph->GetCounter()); - bobt = OBT(ph->GetOrbitalTime()); - firstev++; - if ( PEDANTIC ) throw -71; - }; - if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); - // - glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER()); - glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER()); - glrun1->SetRUNTRAILER_TIME(glrun->GetRUNTRAILER_TIME()); - glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT()); - glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); - // - glrun->SetEV_FROM(firstev); - glrun->SetNEVENTS(lastev-firstev+1); - // - glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); - glrun->SetRUNHEADER_OBT(glrun1->GetRUNHEADER_OBT()); - glrun->SetRUNHEADER_PKT(glrun1->GetRUNHEADER_PKT()); - glrun->SetCOMPILATIONTIMESTAMP(glrun1->GetCOMPILATIONTIMESTAMP()); - glrun->SetFAV_WRK_SCHEDULE(glrun1->GetFAV_WRK_SCHEDULE()); - glrun->SetEFF_WRK_SCHEDULE(glrun1->GetEFF_WRK_SCHEDULE()); - glrun->SetPRH_VAR_TRG_MODE_A(glrun1->GetPRH_VAR_TRG_MODE_A()); - glrun->SetPRH_VAR_TRG_MODE_B(glrun1->GetPRH_VAR_TRG_MODE_B()); - glrun->SetACQ_BUILD_INFO(glrun1->GetACQ_BUILD_INFO()); - glrun->SetACQ_VAR_INFO(glrun1->GetACQ_VAR_INFO()); - glrun->SetRM_ACQ_AFTER_CALIB(glrun1->GetRM_ACQ_AFTER_CALIB()); - glrun->SetRM_ACQ_SETTING_MODE(glrun1->GetRM_ACQ_SETTING_MODE()); - glrun->SetTRK_CALIB_USED(glrun1->GetTRK_CALIB_USED()); - glrun->SetCAL_DSP_MASK(glrun1->GetCAL_DSP_MASK()); - glrun->SetLAST_TIMESYNC(glrun1->GetLAST_TIMESYNC()); - glrun->SetOBT_TIMESYNC(glrun1->GetOBT_TIMESYNC()); - // - if ( !IsRunAlreadyInserted() ){ - // - // glrun->SetID(this->AssignRunID()); - glrun->SetID_RUN_FRAG(glrun1->GetID()); - glrun->Fill_GL_RUN(conn); - // - // set id number - // - glrun1->SetID_RUN_FRAG(glrun->GetID()); - glrun1->Fill_GL_RUN(conn); - // - }; - // delete old entry in fragment table - // - glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); - glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); - // - delete glrun1; - // - // -// return; - // - }; - // - }; - // - // - zjustcheck: - // - if ( !found ){ - // - if ( IsDebug() ) printf(" not found, check if we have already processed the file \n "); - // - // 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 " - << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" - << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " - << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" - << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " - << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" - << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " - << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " - << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " - << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" - << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " - << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" - << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " - << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; - // - if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - // - if ( !result ) throw -4; - // - row = result->Next(); - // - if ( row ){ - if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); - if ( PEDANTIC ) throw -70; - } else { - if ( NoFrag() ){ - glrun->SetID_RUN_FRAG(glrun->GetID()); - glrun->Fill_GL_RUN(conn); - glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); - }; - }; - }; // EEE + glrun->SetRUNTRAILER_PKT(lastPkt); + glrun->SetRUNTRAILER_OBT(lastObt); + lastentry++; + }; + // + this->SetCommonGLRUN(firstTime,lastTime); + this->SetPhysEndRunVariables(); + // + if ( chminentry == firstentry ){ // EEE + if ( IsDebug() ) printf(" Inside isrunconsistent found a fragment of run at the beginning of the file, put it in the fragment table \n"); + // + // this->HandleRunFragments(true,mistrail,firstentry,lastentry); // cannot call it here since it enters a loop which will destroy the already stored variables if we arrive here from HandleRunFragments + // + + + + + + + + + + + + + + mishead = true; + + + UInt_t rhfirstev = firstentry; + // UInt_t rtlastev = lastentry; + Bool_t found = false; + Bool_t foundinrun = false; + // + TSQLResult *result = 0; + TSQLRow *row = 0; + // + stringstream oss; + oss.str(""); + // + // 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; + // + // this->FillClass(mishead,mistrail,firstev,lastev); + // + if ( IsDebug() ) printf("zz The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n"); + if ( IsDebug() ) printf("zz 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()); + // + // First of all insert the run in the fragment table... + // + oss.str(""); + oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE " + << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" + << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " + << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" + << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " + << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" + << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " + << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " + << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " + << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" + << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " + << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" + << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " + << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; + // + if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + // + if ( !result ) throw -4; + // + row = result->Next(); + // + if ( !row ){ + // + // no, insert this run in the GL_RUN_FRAGMENTS table (check if exist before!) + // + if ( IsDebug() ) printf(" The run is new \n"); + if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n"); + // + glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(0); + 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 ( chewbacca && mishead && mistrail ) goto zjustcheck; + // + // can we find the other piece of the run in the GL_RUN_FRAGMENTS table? + // + if ( mishead && ( rhfirstev == firstev || chewbacca ) ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is + // missing it no way we can found a piece in the frag table + // + oss.str(""); + oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN_FRAGMENTS WHERE " + << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " + << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " + << " ID != " << glrun->ID + << " ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! + // + if ( IsDebug() ) printf(" look for runheader in the fragments table: query is \n %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + // + if ( !result ) throw -4; + // + row = result->Next(); + // + if ( !row && NoFrag() ){ + // + oss.str(""); + oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN WHERE " + << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " + << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " + << " ID != " << glrun->ID + << " AND ID=ID_RUN_FRAG ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! + // + if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + // + if ( !result ) throw -4; + // + foundinrun = true; + // + row = result->Next(); + // + }; + // + if ( !row ){ + if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); + found = false; + } else { + // + found = false; // default value + // + if ( IsDebug() ) printf(" 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: + // + if ( !mistrail && (UInt_t)atoll(row->GetField(1)) != 0 ){ + ULong64_t chkpkt = 0; + ULong64_t pktt = (ULong64_t)PKT(glrun->GetRUNTRAILER_PKT()); + ULong64_t pkth = (ULong64_t)PKT((UInt_t)atoll(row->GetField(4))); + // + chkpkt = pkth + (ULong64_t)glrun->GetPKT_COUNTER() + 1ULL + 1ULL; + // + if ( labs(chkpkt-pktt)<2 ){ + // + if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); + // + found = true; + // + } else { + // + if ( IsDebug() ) printf(" The check with pkt counter failed: check %llu pktt %llu \n",chkpkt,pktt); + // + found = false; + // + }; + }; + if ( !found && chewbacca ) goto zjustcheck; + if ( !found ){ + // + // if we arrive here we were not able to decide if the two pieces matches using only the pkt counter information, we must check times and obts + // + ULong64_t chkpkt1 = 0; + ULong64_t orunh1 = (ULong64_t)PKT(glrun->GetRUNHEADER_PKT()); + ULong64_t dbrunt1 = (ULong64_t)PKT((UInt_t)atoll(row->GetField(5))); + chkpkt1 = labs(orunh1-dbrunt1); + // + ULong64_t chkpkt2 = 0; + ULong64_t orunh2 = (ULong64_t)OBT(glrun->GetRUNHEADER_OBT()); + ULong64_t dbrunt2 = (ULong64_t)OBT((UInt_t)atoll(row->GetField(3))); + chkpkt2 = labs(orunh2-dbrunt2); + // + ULong64_t chkpkt3 = 0; + ULong64_t orunh3 = (ULong64_t)(glrun->GetRUNHEADER_TIME()); + ULong64_t dbrunt3 = (ULong64_t)((UInt_t)atoll(row->GetField(2))); + chkpkt3 = labs(orunh3-dbrunt3); + // + if ( (chkpkt1 < 200 || chkpkt2 < 20000) && chkpkt3 < 20 ){ + // if ( chkpkt1 < 100 && chkpkt2 < 30000 && chkpkt3 < 30 ){ + // + if ( IsDebug() ) printf(" FOUND!!! check1 %llu<200 cechk2 %llu<20000 check3 %llu<20 \n",chkpkt1,chkpkt2,chkpkt3); + // + found = true; + // + } else { + // + if ( IsDebug() ) printf(" Check failed: check1 %llu<200? cechk2 %llu<20000? check3 %llu<20? \n",chkpkt1,chkpkt2,chkpkt3); + // + found = false; + // + }; + }; + }; + // + if ( found ){ + // + // we have found the missing piece, glue the two together, merge the informations, fill the gl_run table (check first runs do not exists), delete entry in frag table + // + if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); + // + if ( foundinrun ){ + glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); + glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); + }; + // + GL_RUN *glrun1 = new GL_RUN(); + // + // UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); + // + oss.str(""); + oss << " ID="<GetField(0)<<";"; + // + glrun1->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // here we have runheader infos + // + // merge infos + // + UInt_t apkt = PKT(glrun1->GetRUNTRAILER_PKT()); + ULong64_t aobt = OBT(glrun1->GetRUNTRAILER_OBT()); + UInt_t bpkt = PKT(glrun->GetRUNHEADER_PKT()); + ULong64_t bobt = OBT(glrun->GetRUNHEADER_OBT()); + if ( IsDebug() ) printf(" Check overlapping events: %u %u %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); + TTree *T= 0; + T = (TTree*)file->Get("Physics"); + if ( !T || T->IsZombie() ) throw -16; + EventHeader *eh = 0; + PscuHeader *ph = 0; + T->SetBranchAddress("Header", &eh); + while ( apkt > bpkt && aobt > bobt && firstev < lastev ){ + T->GetEntry(firstev); + ph = eh->GetPscuHeader(); + bpkt = PKT(ph->GetCounter()); + bobt = OBT(ph->GetOrbitalTime()); + firstev++; + if ( PEDANTIC ) throw -71; + }; + if ( IsDebug() ) printf(" Check overlapping events done: %u %u %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); + // + glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER()); + glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER()); + glrun1->SetRUNTRAILER_TIME(glrun->GetRUNTRAILER_TIME()); + glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT()); + glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); + // + glrun->SetEV_FROM(firstev); + glrun->SetNEVENTS(lastev-firstev+1); + // + glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); + glrun->SetRUNHEADER_OBT(glrun1->GetRUNHEADER_OBT()); + glrun->SetRUNHEADER_PKT(glrun1->GetRUNHEADER_PKT()); + glrun->SetCOMPILATIONTIMESTAMP(glrun1->GetCOMPILATIONTIMESTAMP()); + glrun->SetFAV_WRK_SCHEDULE(glrun1->GetFAV_WRK_SCHEDULE()); + glrun->SetEFF_WRK_SCHEDULE(glrun1->GetEFF_WRK_SCHEDULE()); + glrun->SetPRH_VAR_TRG_MODE_A(glrun1->GetPRH_VAR_TRG_MODE_A()); + glrun->SetPRH_VAR_TRG_MODE_B(glrun1->GetPRH_VAR_TRG_MODE_B()); + glrun->SetACQ_BUILD_INFO(glrun1->GetACQ_BUILD_INFO()); + glrun->SetACQ_VAR_INFO(glrun1->GetACQ_VAR_INFO()); + glrun->SetRM_ACQ_AFTER_CALIB(glrun1->GetRM_ACQ_AFTER_CALIB()); + glrun->SetRM_ACQ_SETTING_MODE(glrun1->GetRM_ACQ_SETTING_MODE()); + glrun->SetTRK_CALIB_USED(glrun1->GetTRK_CALIB_USED()); + glrun->SetCAL_DSP_MASK(glrun1->GetCAL_DSP_MASK()); + glrun->SetLAST_TIMESYNC(glrun1->GetLAST_TIMESYNC()); + glrun->SetOBT_TIMESYNC(glrun1->GetOBT_TIMESYNC()); + // + if ( glrun1->GetPHYSENDRUN_MASK_S3S2S12() ) glrun->SetPHYSENDRUN_MASK_S3S2S12(glrun1->GetPHYSENDRUN_MASK_S3S2S12()); + if ( glrun1->GetPHYSENDRUN_MASK_S11CRC() ) glrun->SetPHYSENDRUN_MASK_S11CRC(glrun1->GetPHYSENDRUN_MASK_S11CRC()); + // + if ( !IsRunAlreadyInserted() ){ + // + // glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(glrun1->GetID()); + glrun->Fill_GL_RUN(conn); + // + // set id number + // + glrun1->SetID_RUN_FRAG(glrun->GetID()); + glrun1->Fill_GL_RUN(conn); + // + }; + // delete old entry in fragment table + // + glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); + glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); + // + delete glrun1; + // + // + // return; + // + }; + // + }; + // + // + zjustcheck: + // + if ( !found ){ + // + if ( IsDebug() ) printf(" not found, check if we have already processed the file \n "); + // + // 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 " + << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" + << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " + << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" + << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " + << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" + << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " + << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " + << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " + << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" + << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " + << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" + << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " + << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; + // + if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + // + if ( !result ) throw -4; + // + row = result->Next(); + // + if ( row ){ + if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); + if ( PEDANTIC ) throw -70; + } else { + if ( NoFrag() ){ + glrun->SetID_RUN_FRAG(glrun->GetID()); + glrun->Fill_GL_RUN(conn); + glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); + }; + }; + }; // EEE @@ -3551,11 +3608,11 @@ } else { - if ( !IsRunAlreadyInserted() ){ - glrun->SetID(this->AssignRunID()); - glrun->SetID_RUN_FRAG(0); - glrun->Fill_GL_RUN(conn); - }; + if ( !IsRunAlreadyInserted() ){ + glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(0); + glrun->Fill_GL_RUN(conn); + }; }; // EEE // firstevno = lastentry + 1; @@ -3647,17 +3704,17 @@ code = eh->GetCounter(); checkfirst = 0; for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ - if ( strcmp(*Iter,"Physics") ) checkfirst += code->Get(GetPacketType(*Iter)); - if ( !strcmp(*Iter,"RunHeader") ) nrunh1++; - }; + if ( strcmp(*Iter,"Physics") ) checkfirst += code->Get(GetPacketType(*Iter)); + if ( !strcmp(*Iter,"RunHeader") ) nrunh1++; + }; if ( IsDebug() ) printf(" Check first is %i \n",checkfirst); // T->GetEntry(lastev); code = eh->GetCounter(); checklast = 0; for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ - if ( strcmp(*Iter,"Physics") ) checklast += code->Get(GetPacketType(*Iter)); - }; + if ( strcmp(*Iter,"Physics") ) checklast += code->Get(GetPacketType(*Iter)); + }; if ( IsDebug() ) printf(" Check last is %i \n",checklast); // if ( checkfirst == checklast ){ @@ -3769,6 +3826,7 @@ }; // this->SetCommonGLRUN(firstTime,lastTime); + this->SetPhysEndRunVariables(); // if ( !IsRunAlreadyInserted() ){ glrun->SetID(this->AssignRunID()); @@ -3808,6 +3866,7 @@ if ( IsDebug() ) printf(" We have the runtrailer \n"); // this->SetCommonGLRUN(firstTime,lastTime); + this->SetPhysEndRunVariables(); // if ( !IsRunAlreadyInserted() ){ glrun->SetID(this->AssignRunID()); @@ -4580,9 +4639,9 @@ pkt1 = ph1->GetCounter(); fromtime = this->GetAbsTime(ph1->GetOrbitalTime()); // -// valid = 1; -// // -// if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1 + // valid = 1; + // // + // if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1 // // if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ @@ -4611,7 +4670,7 @@ pkt2 = ph2->GetCounter(); // if ( IsDebug() ) printf(" This is a trk calibration2 at obt %u pkt %u t2 is %u , t2t1cal is %u \n",obt2,pkt2,t2,t2t1cal); -// if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 + // if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 // } else { // @@ -4627,18 +4686,18 @@ // if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) && (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ // EMILIANO -// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) || (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ -// // if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ -// if ( IsDebug() ) printf(" running out of vector without finding the corresponding calibration, sig \n"); -// // -// // running out of vector without finding the corresponding calibration, sig -// // -// pret2 = t2; -// obt2 = 0; -// // pkt2 = pkt1+2; -// pkt2 = 0; -// t2t1cal = t1+1; -// }; + // if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) || (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ + // // if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ + // if ( IsDebug() ) printf(" running out of vector without finding the corresponding calibration, sig \n"); + // // + // // running out of vector without finding the corresponding calibration, sig + // // + // pret2 = t2; + // obt2 = 0; + // // pkt2 = pkt1+2; + // pkt2 = 0; + // t2t1cal = t1+1; + // }; // @@ -4745,8 +4804,8 @@ // fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); valid = 0; -// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ - // EMILIANO + // if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ + // EMILIANO if ( this->PKT(pkt2) >= this->PKT(pktfirst) && this->PKT(pkt2 <= upperpkt) && this->OBT(obt2) >= this->OBT(obtfirst) && this->OBT(obt2) <= upperobt ){ // if ( this->PKT(pkt2) > this->PKT(pktfirst) || this->OBT(obt2) > this->OBT(obtfirst) ){ // @@ -5061,9 +5120,15 @@ << " RM_ACQ_SETTING_MODE=" << glrun->GetRM_ACQ_SETTING_MODE()<< " , " << " TRK_CALIB_USED=" << glrun->GetTRK_CALIB_USED()<< " , " << " CAL_DSP_MASK=" << glrun->GetCAL_DSP_MASK()<< " , " - << " LAST_TIMESYNC=" << glrun->GetLAST_TIMESYNC()<< " , " - << " OBT_TIMESYNC=" << glrun->GetOBT_TIMESYNC() - << " WHERE ID=" << myid[u] << ";"; + << " LAST_TIMESYNC=" << glrun->GetLAST_TIMESYNC()<< " , "; + // + if ( glrun->GetPHYSENDRUN_MASK_S3S2S12() ) + oss << " PHYSENDRUN_MASK_S3S2S12=" << glrun->GetPHYSENDRUN_MASK_S3S2S12() << " , "; + if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ) + oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC() << " , "; + // + oss << " OBT_TIMESYNC=" << glrun->GetOBT_TIMESYNC(); + oss << " WHERE ID=" << myid[u] << ";"; conn->Query(oss.str().c_str()); }; // @@ -5074,8 +5139,14 @@ for (UInt_t u=1; u <= nid ; u++){ oss.str(""); oss << "UPDATE GL_RUN_FRAGMENTS SET " - << " RUNHEADER_TIME=" << glrun->GetRUNHEADER_TIME()<< " , " - << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , " + << " RUNHEADER_TIME=" << glrun->GetRUNHEADER_TIME()<< " , "; + // + if ( glrun->GetPHYSENDRUN_MASK_S3S2S12() ) + oss << " PHYSENDRUN_MASK_S3S2S12=" << glrun->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; + if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ) + oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; + // + oss << " RUNHEADER_OBT=" << glrun->GetRUNHEADER_OBT()<< " , " << " RUNHEADER_PKT=" << glrun->GetRUNHEADER_PKT()<< ";"; conn->Query(oss.str().c_str()); }; @@ -5098,8 +5169,14 @@ << " RUNTRAILER_TIME=" << glrun->GetRUNTRAILER_TIME()<< " , " << " RUNTRAILER_OBT=" << glrun->GetRUNTRAILER_OBT()<< " , " << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()<< " , " - << " PKT_COUNTER=" << glrun->GetPKT_COUNTER()<< " , " - << " PKT_READY_COUNTER=" << glrun->GetPKT_READY_COUNTER() + << " PKT_COUNTER=" << glrun->GetPKT_COUNTER()<< " , "; + // + if ( glrun->GetPHYSENDRUN_MASK_S3S2S12() ){ + oss << " PHYSENDRUN_MASK_S3S2S12=" << glrun->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; + if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ) { + oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; + // + oss << " PKT_READY_COUNTER=" << glrun->GetPKT_READY_COUNTER() << " WHERE ID=" << myid[u] << ";"; conn->Query(oss.str().c_str()); }; @@ -5112,8 +5189,14 @@ oss.str(""); oss << "UPDATE GL_RUN_FRAGMENTS SET " << " RUNTRAILER_TIME=" << glrun->GetRUNTRAILER_TIME()<< " , " - << " RUNTRAILER_OBT=" << glrun->GetRUNTRAILER_OBT()<< " , " - << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()<< ";"; + << " RUNTRAILER_OBT=" << glrun->GetRUNTRAILER_OBT()<< " , "; + // + if ( glrun->GetPHYSENDRUN_MASK_S3S2S12() ){ + oss << " PHYSENDRUN_MASK_S3S2S12=" << glrun->GetPHYSENDRUN_MASK_S3S2S12()<< " , "; }; + if ( glrun->GetPHYSENDRUN_MASK_S11CRC() ){ + oss << " PHYSENDRUN_MASK_S11CRC=" << glrun->GetPHYSENDRUN_MASK_S11CRC()<< " , "; }; + // + oss << " RUNTRAILER_PKT=" << glrun->GetRUNTRAILER_PKT()<< ";"; conn->Query(oss.str().c_str()); }; }; @@ -5272,29 +5355,29 @@ glrun->SetID_RUN_FRAG(glrun->GetID()); glrun->Fill_GL_RUN(conn); // -// oss.str(""); -// oss << " SELECT ID FROM GL_RUN WHERE " -// << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND " -// << " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND " -// << " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND " -// << " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND " -// << " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; "; -// // -// if ( IsDebug() ) printf(" Look for the ID of the inserted run: 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 ) throw -25; -// // -// oss.str(""); -// oss << " UPDATE GL_RUN SET ID_RUN_FRAG = " << row2->GetField(0) << " WHERE ID = " << row2->GetField(0); -// if ( IsDebug() ) printf(" Update the ID_RUN_FRAG of the inserted run: query is \n %s \n",oss.str().c_str()); -// result2 = conn->Query(oss.str().c_str()); -// // -// if ( !result2 ) throw -4; + // oss.str(""); + // oss << " SELECT ID FROM GL_RUN WHERE " + // << " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND " + // << " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND " + // << " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND " + // << " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND " + // << " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; "; + // // + // if ( IsDebug() ) printf(" Look for the ID of the inserted run: 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 ) throw -25; + // // + // oss.str(""); + // oss << " UPDATE GL_RUN SET ID_RUN_FRAG = " << row2->GetField(0) << " WHERE ID = " << row2->GetField(0); + // if ( IsDebug() ) printf(" Update the ID_RUN_FRAG of the inserted run: query is \n %s \n",oss.str().c_str()); + // result2 = conn->Query(oss.str().c_str()); + // // + // if ( !result2 ) throw -4; // moved++; // @@ -5306,13 +5389,13 @@ // // glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); -// oss.str(""); -// oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0); -// if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str()); -// result2 = conn->Query(oss.str().c_str()); -// // -// if ( !result2 ) throw -4; -// // + // oss.str(""); + // oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0); + // if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str()); + // result2 = conn->Query(oss.str().c_str()); + // // + // if ( !result2 ) throw -4; + // // row = result->Next(); }; }; @@ -5457,7 +5540,7 @@ GL_RUN* this_run = new GL_RUN(); GL_RUN* next_run = new GL_RUN(); Int_t nseq_max = 1000; -// UInt_t* sequence = new UInt_t[100]; + // UInt_t* sequence = new UInt_t[100]; vector sequence(nseq_max); Int_t nseq = 0; Bool_t CHECK = false; @@ -5472,82 +5555,82 @@ // --------------------------------------------------------------------------------- while(1){ - row = result->Next(); - if( row == NULL ) break; + row = result->Next(); + if( row == NULL ) break; - //------------ - //get run info - //------------ - this_run->Set_GL_RUN(row); + //------------ + //get run info + //------------ + this_run->Set_GL_RUN(row); - Bool_t this_BAD = false; - if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true; - else if (this_run->GetTRK_CALIB_USED() == 104) this_ONLINE = false; - else{ -// printf("Missing or corrupted header!! \n"); - this_ONLINE = false; - this_BAD = true; - }; + Bool_t this_BAD = false; + if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true; + else if (this_run->GetTRK_CALIB_USED() == 104) this_ONLINE = false; + else{ + // printf("Missing or corrupted header!! \n"); + this_ONLINE = false; + this_BAD = true; + }; - //----------------------------------- - //compare with previous(next in time) - //----------------------------------- - CHECK = false; - UInt_t interval=0; + //----------------------------------- + //compare with previous(next in time) + //----------------------------------- + CHECK = false; + UInt_t interval=0; - if( nrow != 0){ + if( nrow != 0){ - t1 = this_run->GetRUNTRAILER_TIME(); - t2 = next_run->GetRUNHEADER_TIME(); - interval = (t2-t1); + t1 = this_run->GetRUNTRAILER_TIME(); + t2 = next_run->GetRUNHEADER_TIME(); + interval = (t2-t1); - if(this_ONLINE && next_ONLINE){ // this: ON-LINE + next: ON-LINE + if(this_ONLINE && next_ONLINE){ // this: ON-LINE + next: ON-LINE - if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0; //=> run fragments + if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0; //=> run fragments - if( interval >= calibtime )CHECK = true; //more than calibtime s => there might be a calibration + if( interval >= calibtime )CHECK = true; //more than calibtime s => there might be a calibration - if( !CHECK && this_run->VALIDATION ){ - for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); - nseq=0; - } + if( !CHECK && this_run->VALIDATION ){ + for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); + nseq=0; + } - }else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE + }else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE - CHECK = true; + CHECK = true; - }else if( !next_ONLINE ){ // this:ANY + next:DEFAULT + }else if( !next_ONLINE ){ // this:ANY + next:DEFAULT - assignVALIDATION(next_run->ID,true); - nseq=0; - } - } + assignVALIDATION(next_run->ID,true); + nseq=0; + } + } - //---------------------------- - //check run sequence for calib - //---------------------------- - if( CHECK ){ - // check if calibration exists - if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); - Bool_t MISSING = MissingTRK_CALIB(t1,t2); - for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); - nseq=0; - }; - //-------------- - //store run info - //-------------- - *next_run = *this_run; - next_ONLINE = this_ONLINE; - if( !this_BAD ){ - if(nseq < nseq_max){ - sequence[nseq] = this_run->ID; - nseq++; - }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); - }; + //---------------------------- + //check run sequence for calib + //---------------------------- + if( CHECK ){ + // check if calibration exists + if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); + Bool_t MISSING = MissingTRK_CALIB(t1,t2); + for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); + nseq=0; + }; + //-------------- + //store run info + //-------------- + *next_run = *this_run; + next_ONLINE = this_ONLINE; + if( !this_BAD ){ + if(nseq < nseq_max){ + sequence[nseq] = this_run->ID; + nseq++; + }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); + }; - if ( IsDebug() ) printf("%i Run %u \n",nrow,this_run->ID); - nrow++; + if ( IsDebug() ) printf("%i Run %u \n",nrow,this_run->ID); + nrow++; }; delete this_run; @@ -5563,41 +5646,41 @@ */ Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ - GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); + GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); - // get the closest VALIDATED calibration before the run start (t2) - if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing + // get the closest VALIDATED calibration before the run start (t2) + if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing - if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing + if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing - //============================================================== - // Check is done first on the basis of time between calibration, - // which should be equal to the time between ascending-nodes. - //============================================================== - if ( t2 - trkcalib->FROM_TIME > 5700) { - if ( IsDebug() )printf("Long time between calib and run start %u :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME); - //============================================================== - // there might be a missing calibration, due to: - // - MM full - // - corrupted packets - // - loss of data - // There is an exception in case a download was done during ascending node - //============================================================== - Bool_t DOWNLOAD = false; - // check if the calib was skipped becouse of download .... DA FARE!! - if(DOWNLOAD)return(false); + //============================================================== + // Check is done first on the basis of time between calibration, + // which should be equal to the time between ascending-nodes. + //============================================================== + if ( t2 - trkcalib->FROM_TIME > 5700) { + if ( IsDebug() )printf("Long time between calib and run start %u :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME); + //============================================================== + // there might be a missing calibration, due to: + // - MM full + // - corrupted packets + // - loss of data + // There is an exception in case a download was done during ascending node + //============================================================== + Bool_t DOWNLOAD = false; + // check if the calib was skipped becouse of download .... DA FARE!! + if(DOWNLOAD)return(false); - return(true); //>>> missing + return(true); //>>> missing - }; + }; - //============================================================== - // If the last calibration is close to the run less than this time, - // it is enough to say that there are no missing calibrations - //============================================================== - // the long time interval bewteen runs might be due to download - if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); - return(false); + //============================================================== + // If the last calibration is close to the run less than this time, + // it is enough to say that there are no missing calibrations + //============================================================== + // the long time interval bewteen runs might be due to download + if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); + return(false); }; /** @@ -5606,17 +5689,17 @@ * @param validation true/false */ Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ - TSQLResult *result = 0; - stringstream oss; - oss.str(""); - oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";"; - // -// if ( IsDebug() ) -// printf(" Set VALIDATION = %i for run %i \n",validation,idrun); - if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - if ( !result ) throw -4; - return(0); + TSQLResult *result = 0; + stringstream oss; + oss.str(""); + oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";"; + // + // if ( IsDebug() ) + // printf(" Set VALIDATION = %i for run %i \n",validation,idrun); + if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + if ( !result ) throw -4; + return(0); } @@ -6261,114 +6344,114 @@ **/ UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){ - Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; - UInt_t timeaftercalib=120000; //2000; -// ---------- -// Check CRCs -// ---------- - for(Int_t ipkt=0; ipkt<6; ipkt++){ - if( caltrk->crc_hcal[ipkt] )return 0; // :-( - for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-( - } -// ----------------------- -// Check missing packets: -// ----------------------- -// Readout order: -// ------------------ -// DSP packet board -// ------------------ -// 12 0 1 -// 10 1 1 -// 8 2 1 -// 4 3 1 -// 6 4 1 -// 2 5 1 -// ------------------ -// 11 0 2 -// 9 1 2 -// 7 2 2 -// 3 3 2 -// 5 4 2 -// 1 5 2 -// ------------------ -// ------------------------------------------------- -// Check if it is first or second calibration packet -// ------------------------------------------------- - UInt_t build=0; - TString classname = caltrk->GetName(); - UInt_t base=0; - UInt_t mask=0; - if(classname.Contains("CalibTrk1Event")){ - base=12; - mask=0x03F000; - } - if(classname.Contains("CalibTrk2Event")){ - base=18; - mask=0xFC0000; - } -// ------------------------------------------------- -// Count number of packets and set build variable -// ------------------------------------------------- - Int_t npkts=0; - for(Int_t ipkt=0; ipkt<6; ipkt++){ - if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ - npkts++; - build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); - } - } -// if( npkts==6 )return 1; // :-) + Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; + UInt_t timeaftercalib=120000; //2000; + // ---------- + // Check CRCs + // ---------- + for(Int_t ipkt=0; ipkt<6; ipkt++){ + if( caltrk->crc_hcal[ipkt] )return 0; // :-( + for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-( + } + // ----------------------- + // Check missing packets: + // ----------------------- + // Readout order: + // ------------------ + // DSP packet board + // ------------------ + // 12 0 1 + // 10 1 1 + // 8 2 1 + // 4 3 1 + // 6 4 1 + // 2 5 1 + // ------------------ + // 11 0 2 + // 9 1 2 + // 7 2 2 + // 3 3 2 + // 5 4 2 + // 1 5 2 + // ------------------ + // ------------------------------------------------- + // Check if it is first or second calibration packet + // ------------------------------------------------- + UInt_t build=0; + TString classname = caltrk->GetName(); + UInt_t base=0; + UInt_t mask=0; + if(classname.Contains("CalibTrk1Event")){ + base=12; + mask=0x03F000; + } + if(classname.Contains("CalibTrk2Event")){ + base=18; + mask=0xFC0000; + } + // ------------------------------------------------- + // Count number of packets and set build variable + // ------------------------------------------------- + Int_t npkts=0; + for(Int_t ipkt=0; ipkt<6; ipkt++){ + if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ + npkts++; + build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); + } + } + // if( npkts==6 )return 1; // :-) + + // cout << classname << " "<GetPscuHeader()->GetOrbitalTime()<GetPscuHeader()->GetOrbitalTime()<GetCounter(); + Int_t irun = cod->Get(pctp->RunHeader); + TTree *rh=(TTree*)file->Get("RunHeader"); + if ( !rh || rh->IsZombie() ) throw -17; + if( rh->GetEntries() == irun ){ + if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<GetCounter(); - Int_t irun = cod->Get(pctp->RunHeader); - TTree *rh=(TTree*)file->Get("RunHeader"); - if ( !rh || rh->IsZombie() ) throw -17; - if( rh->GetEntries() == irun ){ - if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<SetBranchAddress("RunHeader", &run); - rh->SetBranchAddress("Header", &hrun); - rh->GetEntry(irun); -// cout << classname << " "<GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ - if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<SetBranchAddress("RunHeader", &run); + rh->SetBranchAddress("Header", &hrun); + rh->GetEntry(irun); + // cout << classname << " "<GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ + if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<RM_ACQ_AFTER_CALIB ){ - if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); - if( dtime > timeaftercalib ){ - if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<RM_ACQ_AFTER_CALIB ){ + if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); + if( dtime > timeaftercalib ){ + if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<ACQ_BUILD_INFO & mask) != build ){ - if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<ACQ_BUILD_INFO&mask) << " != "<< build << dec<ACQ_BUILD_INFO & mask) != build ){ + if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<ACQ_BUILD_INFO&mask) << " != "<< build << dec<Check(0,0)); + return(this->Check(0,0)); } UInt_t PamelaDBOperations::Check(UInt_t from, UInt_t to){ // - if ( IsDebug() ) printf(" from %u to %u \n",from,to); + if ( IsDebug() ) printf(" from %u to %u \n",from,to); // UInt_t test = 0; // @@ -6424,7 +6507,7 @@ // if ( from > 0 && nid <= from ) goto ss; if ( to > 0 && nid >= to ) goto ss; -// + // if ( (UInt_t)atoll(row->GetField(4)) > 1 ){ // // @@ -6455,7 +6538,7 @@ printf(" CHECK n.4 RUNs %u and %u HAVE SAME RUNHEADER \n",thisid,(UInt_t)atoll(row3->GetField(0))); row3 = result3->Next(); }; -// delete result3; + // delete result3; }; // @@ -6476,7 +6559,7 @@ printf(" CHECK n.5 RUNs %u and %u HAVE SAME RUNTRAILER \n",thisid,(UInt_t)atoll(row3->GetField(0))); row3 = result3->Next(); }; -// delete result3; + // delete result3; }; // oss.str(""); @@ -6496,7 +6579,7 @@ printf(" CHECK n.7 RUNs %u and %u HAVE SAME RUNTRAILER AND RUNHEADER (ARE THE SAME?) \n",thisid,(UInt_t)atoll(row3->GetField(0))); row3 = result3->Next(); }; - // delete result3; + // delete result3; }; }; @@ -6517,7 +6600,7 @@ printf(" CHECK n.6 RUN %u CONTAINS RUN %u \n",thisid,(UInt_t)atoll(row3->GetField(0))); row3 = result3->Next(); }; -// delete result3; + // delete result3; }; // }; @@ -6543,7 +6626,7 @@ thisf = (TString)row2->GetField(0); if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); test = 1; -// delete result2; + // delete result2; }; // if ( (thisrtt < prevrht) && (thisrht != prevrht) ){ @@ -6565,7 +6648,7 @@ thisf = (TString)row2->GetField(0); if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); test = 1; -// delete result2; + // delete result2; }; // if ( (thisrht > thisrtt) && (thisrht != prevrht) ){ @@ -6587,17 +6670,17 @@ thisf = (TString)row2->GetField(0); if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); test = 1; -// delete result2; + // delete result2; }; -ss: + ss: // prevrht = thisrht; prevrtt = thisrtt; previd = thisid; prevl0id = thisl0id; row = result->Next(); -// if ( result2 ) delete result2; -// if ( result3 ) delete result3; + // if ( result2 ) delete result2; + // if ( result3 ) delete result3; }; // return(test);