--- chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2008/11/28 10:57:44 1.12 +++ chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2008/12/23 20:43:10 1.20 @@ -101,6 +101,7 @@ if (INSERT_RAW) SetRawName(filerawname); // INSERT_ROOT = !filerootname.IsNull(); + if ( INSERT_ROOT ) this->SetRootName(filerootname); this->SetOrbitNo(dwinput); // this->SetID_RAW(0); @@ -134,8 +135,10 @@ stringstream qu; TSQLResult *result = 0; TSQLResult *result2 = 0; + TSQLResult *result3 = 0; TSQLRow *row = 0; TSQLRow *row2 = 0; + TSQLRow *row3 = 0; TString chpath; TString chfile; UInt_t ridn = 0; @@ -160,7 +163,7 @@ }; delete result; qu.str(""); - qu << "SELECT FOLDER_NAME,FILE_NAME,OBT_TIME_SYNC,LAST_TIME_SYNC_INFO,TIME_OFFSET,BOOT_NUMBER,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL from ROOT_TABLE where ID_N=" << ridn << ";"; + qu << "SELECT FOLDER_NAME,FILE_NAME,OBT_TIME_SYNC,LAST_TIME_SYNC_INFO,TIME_OFFSET,BOOT_NUMBER,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,REAL_TIME_INIT from ROOT_TABLE where ID_N=" << ridn << ";"; if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); result2 = conn->Query(qu.str().c_str()); if ( result2 ){ @@ -177,6 +180,23 @@ chresursts = (UInt_t)atoll(row2->GetField(4)); chboot = (UInt_t)atoll(row2->GetField(5)); // + if ( !chboot ){ + qu.str(""); + qu << "SELECT BOOT_NUMBER from ROOT_TABLE where BOOT_NUMBER!=0 AND ABS(LAST_TIME_SYNC_INFO-"<< chlastts <<")<10000 AND (REAL_TIME_INIT-"<< row2->GetField(10) <<")<7200 group by BOOT_NUMBER order by BOOT_NUMBER asc;"; + if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); + result3 = conn->Query(qu.str().c_str()); + if ( result3 ){ + row3 = result3->Next(); + if ( row3 && result3->GetRowCount() == 1 ){ + chboot = (UInt_t)atoll(row3->GetField(0)); + if ( debug ) printf(" Found boot_number = %u \n",chboot); + } else { + if ( debug ) printf(" AGH CANNOT DETERMINE THE BOOT NUMBER... \n"); + throw -29; + }; + }; + }; + // chpktinit = (UInt_t)atoll(row2->GetField(6)); chpktfinal = (UInt_t)atoll(row2->GetField(7)); chobtinit = (UInt_t)atoll(row2->GetField(8)); @@ -189,13 +209,15 @@ throw -85; }; filerootname = chpath + chfile;// + ".root"; - if ( debug ) printf(" chewbacca: filename is %s \n",filerootname.Data()); }; this->SetRootName(filerootname); - file = TFile::Open(this->GetRootName().Data()); - } else { - this->SetRootName(""); }; + if ( debug ) printf(" Filename is %s \n",filerootname.Data()); + file = TFile::Open(this->GetRootName().Data()); + // } else { + // this->SetRootName(""); + // this->SetRootName(filerootname); + // }; } // @@ -395,23 +417,28 @@ return; }; // - TString name = this->GetRootFile(); - Int_t nlength = name.Length(); - if ( nlength < 5 ) return; - TString dwo = 0; - for (Int_t i = 0; i<5; i++){ - dwo.Append(name[i],1); - }; - if ( dwo.IsDigit() ){ - dworbit = (UInt_t)dwo.Atoi(); - } else { - dwo=""; - for (Int_t i = 8; i<13; i++){ + if ( !chewbacca ){ + TString name = this->GetRootFile(); + Int_t nlength = name.Length(); + if ( nlength < 5 ){ + if ( IsDebug() ) printf(" Agh problems determining the orbit number! name = %s \n",name.Data()); + return; + }; + TString dwo = 0; + for (Int_t i = 0; i<5; i++){ dwo.Append(name[i],1); - }; - if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); + }; + if ( dwo.IsDigit() ){ + dworbit = (UInt_t)dwo.Atoi(); + } else { + dwo=""; + for (Int_t i = 8; i<13; i++){ + dwo.Append(name[i],1); + }; + if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); + }; + if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); }; - if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); return; }; @@ -1577,6 +1604,7 @@ result = conn->Query(oss.str().c_str()); if ( !result ) throw -10; row = result->Next(); + if ( !row ) throw -92; idresof = (UInt_t)atoll(row->GetField(0)); existsts = true; goto eout; @@ -1598,7 +1626,7 @@ if ( !row ){ oss.str(""); oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " - << dworbit << " order by FROM_ORBIT desc limit 1;"; + << dworbit << " AND SPECIAL_FILE='' order by FROM_ORBIT desc limit 1;"; if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); result = conn->Query(oss.str().c_str()); if ( !result ) throw -10; @@ -2239,7 +2267,7 @@ ptht = cod->Get(pctp->RunHeader) - 1; // evbeft = cod->Get(pctp->Physics); tcod = (UInt_t)cod->Get(pctp->Physics); - if ( !tcod ) tcod = 1; + if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT evbeft = TMath::Min(upperentry,(tcod-1)); if ( debug ) printf(" Loop in runtrailers, evbeft is %u upperentry %u cod->getetc %u \n",evbeft,upperentry,cod->Get(pctp->Physics)); // @@ -2278,7 +2306,7 @@ obth = phh->GetOrbitalTime(); cod = ehh->GetCounter(); tcod = (UInt_t)cod->Get(pctp->Physics); - if ( !tcod ) tcod = 1; + if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT evbefh = TMath::Max(chminentry,(tcod-1)); // if ( PKT(pkth) >= PKT(pktfirst) && PKT(pkth) <= upperpkt ){ @@ -2340,7 +2368,7 @@ cod = ehh->GetCounter(); // evbeft = cod->Get(pctp->Physics); tcod = (UInt_t)cod->Get(pctp->Physics); - if ( !tcod ) tcod = 1; + if ( !tcod ) tcod = 1; // IS A BUG SINCE RUNS WITH ZERO EVENTS WILL LOOK LIKE RUNS WITH ONE EVENT evbeft = TMath::Min(upperentry,(tcod-1)); rh->GetEntry(pth); phh = ehh->GetPscuHeader(); @@ -2382,7 +2410,7 @@ // if ( conptt+1 == (nrtev+nrtbef )){ if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt); ptht++; - if ( ptht < rhev ){ + if ( ptht < rhev ){ rh->GetEntry(ptht); //pth++; //if ( pth < rhev ){ @@ -2410,7 +2438,8 @@ if ( (UInt_t)evbeft < upperentry-1 && upperentry>0 ){ if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER! evbeft %u upperentry-1 %u \n",(UInt_t)evbeft,upperentry-1); // - if ( (ptt-1) < 0 ) throw -15; // should never arrive here! + // if ( (ptt-1) < 0 ) throw -15; // should never arrive here! + if ( (rtev-1) < 0 || ptt < 0 ) throw -15; // should never arrive here! // rt->GetEntry(ptt-1); rt->GetEntry(rtev-1); cod = eht->GetCounter(); @@ -2645,10 +2674,14 @@ // // we have now the good first piece of a run, fill the glrun object // - if ( rhfirstev != firstev && !mishead ) mishead = true; - if ( rtlastev != lastev && !mistrail ) mistrail = true; + if ( firstev != (lastev+1) ){ // could be a problem sometimes (?) + if ( rhfirstev != firstev && !mishead ) mishead = true; + if ( rtlastev != lastev && !mistrail ) mistrail = true; + }; // + if ( IsDebug() ) printf(" bhere firstev is %i lastev is %i \n",firstev,lastev); this->FillClass(mishead,mistrail,firstev,lastev); + if ( IsDebug() ) printf(" chere firstev is %i lastev is %i \n",firstev,lastev); // if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n"); if ( IsDebug() ) printf(" C THIS RUN: RUNHEADER_OBT %u RUNTRAILER_OBT %u RUNHEADER_PKT %u RUNTRAILER_PKT %u \n", glrun->GetRUNHEADER_OBT(),glrun->GetRUNTRAILER_OBT(),glrun->GetRUNHEADER_PKT(),glrun->GetRUNTRAILER_PKT()); @@ -2743,7 +2776,7 @@ // found = false; // default value // - if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n"); + if ( IsDebug() ) printf(" A Found a possible candidate, checking if it is the good one... \n"); // // if we have both runheader and runtrailer we can check with pkt_counter: // @@ -2759,6 +2792,7 @@ if ( IsDebug() ) printf(" FOUND!!! check %llu pktt %llu \n",chkpkt,pktt); // found = true; + if ( IsDebug() ) printf(" where firstev is %i lastev is %i \n",firstev,lastev); // } else { // @@ -2824,6 +2858,7 @@ oss << " ID="<GetField(0)<<";"; // glrun1->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); // here we have runheader infos + if ( IsDebug() ) printf(" there firstev is %i lastev is %i \n",firstev,lastev); // // merge infos // @@ -2854,6 +2889,8 @@ glrun1->SetRUNTRAILER_OBT(glrun->GetRUNTRAILER_OBT()); glrun1->SetRUNTRAILER_PKT(glrun->GetRUNTRAILER_PKT()); // + if ( IsDebug() ) printf(" here firstev is %i lastev is %i \n",firstev,lastev); + // glrun->SetEV_FROM(firstev); glrun->SetNEVENTS(lastev-firstev+1); // @@ -2946,7 +2983,7 @@ // found = false; // default value // - if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n"); + if ( IsDebug() ) printf(" B Found a possible candidate, checking if it is the good one... \n"); // // if we have both runheader and runtrailer we can check with pkt_counter: // @@ -3175,7 +3212,7 @@ glrun->SetID(this->AssignRunID()); glrun->SetID_RUN_FRAG(0); glrun->Fill_GL_RUN(conn); // it'ok we arrive here only inside a file hence in the middle of the runs... - }; + }; // }; // @@ -3219,6 +3256,7 @@ if ( firstev == lastev+1 || lastev == firstev ) { // no events inside the run! //if ( firstev <= lastev+1 ) { // no events inside the run! if ( IsDebug() ) printf(" Checking but no events in the run! \n"); + firstev = lastev+1; // this is necessary for files with no Physics entries, should have no influence on other files // return true is correct return(true); // @@ -3474,7 +3512,7 @@ // found = false; // default value // - if ( IsDebug() ) printf(" Found a possible candidate, checking if it is the good one... \n"); + if ( IsDebug() ) printf(" C Found a possible candidate, checking if it is the good one... \n"); // // if we have both runheader and runtrailer we can check with pkt_counter: //