--- YodaProfiler/src/PamelaDBOperations.cpp 2006/09/08 16:06:02 1.6 +++ YodaProfiler/src/PamelaDBOperations.cpp 2006/12/04 09:49:34 1.23 @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include // #include @@ -31,11 +31,18 @@ #include #include // +#include + #include // using namespace std; using namespace pamela; +// Some function to work with cTle stuff. +bool compTLE(cTle* tle1, cTle *tle2); +float getTleJulian(cTle *); +string getTleDatetime(cTle*); + /** * Constructor. * @param host hostname for the SQL connection. @@ -47,8 +54,9 @@ * @param obt0 file obt0. * @param tsync file timesync. * @param debug debug flag. + * @param tlefilename ascii file with TLE 3 line elements. */ -PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug){ +PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename){ // // SetConnection(host,user,password); @@ -62,14 +70,26 @@ SetTsync(tsync); SetObt0(obt0); // + SetTLEPath(tlefilename); // - SetRootName(filerootname); - SetRawName(filerawname); // - this->OpenFile(); + INSERT_RAW =!filerawname.IsNull(); + if(INSERT_RAW)SetRawName(filerawname); + // + INSERT_ROOT = !filerootname.IsNull(); + if( INSERT_ROOT ){ + this->SetRootName(filerootname); + this->SetOrbitNo(); + file = TFile::Open(this->GetRootName().Data()); + } else { + this->SetRootName(""); + }; // this->SetID_RAW(0); this->SetID_ROOT(0); + + VALIDATE = false; + // }; @@ -78,6 +98,7 @@ */ void PamelaDBOperations::Close(){ if( conn && conn->IsConnected() ) conn->Close(); + delete clean_time; delete glrun; delete this; }; @@ -86,6 +107,20 @@ // SETTERS // +// +// must be out of the constructor in order to FORCE the validation of the latest runs in case you run the validation together with the latest file +// +void PamelaDBOperations::CheckValidate(Long64_t olderthan){ + clean_time = new TDatime(); + // + if(olderthan >= 0){ + VALIDATE = true; + UInt_t timelim = 0; + timelim = (UInt_t)clean_time->Convert(true) - olderthan; + clean_time->Set(timelim,false); + }; +}; + /** * Open the DB connection * @param host hostname for the SQL connection. @@ -93,6 +128,7 @@ * @param password password for the SQL connection. */ void PamelaDBOperations::SetConnection(TString host, TString user, TString password){ + if ( IsDebug() ) printf(" Connecting using host = %s user = %s password = %s \n",host.Data(),user.Data(),password.Data()); conn = TSQLServer::Connect(host.Data(),user.Data(),password.Data()); }; @@ -121,6 +157,22 @@ }; /** + * Set the autoboot flag + * + */ +void PamelaDBOperations::SetAutoBoot(Bool_t dbg){ + AUTOBOOT = dbg; +}; + +/** + * Set the nofrag flag + * + */ +void PamelaDBOperations::SetNoFrag(Bool_t nf){ + NOFRAG = nf; +}; + +/** * Store the BOOT number of the RAW file. * @param boot BOOT number of the RAW file */ @@ -161,6 +213,33 @@ }; /** + * Store the downlink orbit number from filename. + */ +void PamelaDBOperations::SetOrbitNo(){ + dworbit = 0; + 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++){ + 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()); + return; +}; + + + +/** * Store the NOBOOT flag. * @param noboot true/false. */ @@ -169,12 +248,19 @@ }; /** + * Store path to the TLE file. + */ +void PamelaDBOperations::SetTLEPath(TString str){ + tlefilename = str; +}; + +/** * Store the olderthan variable * @param olderthan */ -void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ - olderthan = oldthan; -}; +// void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ +// olderthan = oldthan; +// }; /** * Retrieve the ID_RAW, if exists, returns NULL if does not exist. @@ -217,14 +303,18 @@ UInt_t nevent = 0; UInt_t pktlast = 0; UInt_t obtlast = 0; - UInt_t t_pktlast = 0; - UInt_t t_obtlast = 0; - UInt_t upperpkt2 = 0; - ULong64_t upperobt2 = 0; + Long64_t t_pktlast = 0LL; + // UInt_t t_obtlast = 0; + Long64_t t_obtlast = 0LL; + Long64_t upperpkt2 = 0LL; + Long64_t upperobt2 = 0LL; UInt_t zomp = 0; UInt_t jump = 50000; // was 5000 EventCounter *code=0; // + Long64_t deltapkt = 5000LL; + Long64_t deltaobt = 50000LL; + // // pcksList packetsNames; // pcksList::iterator Iter; // getPacketsNames(packetsNames); @@ -261,9 +351,9 @@ upperobt = OBT(obtlast); upperentry = nevent-1; // - if ( IsDebug() ) printf(" First entries are: OBT %llu pkt_num %i \n",obtfirst,pktfirst); + if ( IsDebug() ) printf(" First entries are: OBT %i pkt_num %i \n",obtfirst,pktfirst); // - if ( IsDebug() ) printf(" Last entries are: OBT %llu pkt_num %i entry %i\n",upperobt,upperpkt,upperentry); + 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)) ) return(1); // @@ -271,7 +361,8 @@ // if ( nevent < 2 ) return(4); // - if ( PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst) ){ + if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))GetCounter()); upperobt2 = OBT(ph->GetOrbitalTime()); // - if ( (t_pktlast < upperpkt && t_obtlast > upperobt) || (t_pktlast < upperpkt2 && t_obtlast > upperobt2) ) throw -13; + if ( (t_pktlast < upperpkt && t_obtlast > upperobt) || (t_pktlast < upperpkt2 && t_obtlast > upperobt2) ){ + if ( IsDebug() ) printf(" .-. upperpkt2 %lld upperobt2 %lld \n",upperpkt2,upperobt2); + if ( IsDebug() ) printf(" .-. upperpkt %lld t_pktlast %lld upperobt %lld t_obtlast %lld \n",upperpkt,t_pktlast,upperobt,t_obtlast); + if ( IsDebug() ) printf(" .-. jump %i zomp %i upperpkt %lld pktlast %u upperobt %lld obtlast %u last entry is %i \n",jump,zomp,upperpkt,pktlast,upperobt,obtlast,i); + throw -13; + }; // if ( t_pktlast < upperpkt && t_obtlast < upperobt && t_pktlast < upperpkt2 && t_obtlast < upperobt2 ){ zomp = i + jump + 1; if ( zomp > nevent-2 ) zomp = nevent - 2; - if ( IsDebug() ) printf(" .-. jump %i zomp %i upperpkt %i pktlast %i upperobt %llu obtlast %u last entry is %i \n",jump,zomp,upperpkt,pktlast,upperobt,obtlast,i); + if ( IsDebug() ) printf(" .-. jump %i zomp %i upperpkt %lld pktlast %i upperobt %lld obtlast %u last entry is %i \n",jump,zomp,upperpkt,pktlast,upperobt,obtlast,i); break; }; // @@ -333,14 +429,14 @@ // rhev = rh->GetEntries(); rtev = rt->GetEntries(); - UInt_t sobtt = 0; - UInt_t sobth = 0; - UInt_t spktt = 0; - UInt_t spkth = 0; - UInt_t pktt = 0; - ULong64_t obtt = 0; - UInt_t pkth = 0; - ULong64_t obth = 0; + Long64_t sobtt = 0LL; + Long64_t sobth = 0LL; + Long64_t spktt = 0LL; + Long64_t spkth = 0LL; + Long64_t pktt = 0LL; + Long64_t obtt = 0LL; + Long64_t pkth = 0LL; + Long64_t obth = 0LL; // T->GetEntry(upperentry); code = eh->GetCounter(); @@ -360,37 +456,37 @@ obth = OBT(phh->GetOrbitalTime()); }; // - if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); + if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); if ( pkth > upperpkt && obth > upperobt ){ - if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt); + if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt); upperpkt = pkth; upperobt = obth; rhev = lasthead+1; } else { rhev = lasthead; }; - if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); + if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); // - if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); + if ( IsDebug() ) printf(" rtev beforev %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); if ( pktt > upperpkt && obtt > upperobt ){ - if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt); + if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt); upperpkt = pktt; upperobt = obtt; rtev = lasttrail+1; } else { rtev = lasttrail; }; - if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); + if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); // goto kikko; // // // Check if runtrailer/runheader are within lower limits // // - pkth = 0; - obth = 0; - spkth = 0; - sobth = 0; + pkth = 0LL; + obth = 0LL; + spkth = 0LL; + sobth = 0LL; for (Int_t k=0; k 0 ){ spkth = pkth; @@ -401,7 +497,7 @@ pkth = PKT(phh->GetCounter()); obth = OBT(phh->GetOrbitalTime()); // - if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth); +// if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth); // if ( pkth < spkth && obth < sobth ){ if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); @@ -419,7 +515,7 @@ ph = eh->GetPscuHeader(); t_pktlast = PKT(ph->GetCounter()); t_obtlast = OBT(ph->GetOrbitalTime()); - if ( t_pktlast < spkth && t_obtlast < sobth ){ // jump + if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump upperpkt = pkth; upperobt = obth; upperentry = evbefh-1; @@ -438,7 +534,7 @@ upperentry = evbefh-1; }; }; - if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); + if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); goto kikko0; }; }; @@ -446,10 +542,10 @@ // // // - pktt = 0; - obtt = 0; - spktt = 0; - sobtt = 0; + pktt = 0LL; + obtt = 0LL; + spktt = 0LL; + sobtt = 0LL; for (Int_t k=0; k 0 ){ spktt = pktt; @@ -460,7 +556,7 @@ pktt = PKT(pht->GetCounter()); obtt = OBT(pht->GetOrbitalTime()); // - if ( IsDebug() ) printf(" k %i rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt); +// if ( IsDebug() ) printf(" k %i rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt); // if ( pktt < spktt && obtt < sobtt ){ if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); @@ -469,7 +565,7 @@ rt->GetEntry(rtev); pktt = spktt; obtt = sobtt; - if ( IsDebug() ) printf(" lasttrail %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); + if ( IsDebug() ) printf(" lasttrail %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); // UInt_t evbeft = 0; code = eht->GetCounter(); @@ -479,7 +575,7 @@ ph = eh->GetPscuHeader(); t_pktlast = PKT(ph->GetCounter()); t_obtlast = OBT(ph->GetOrbitalTime()); - if ( t_pktlast < spktt && t_obtlast < sobtt ){ // jump + if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump upperpkt = pktt; upperobt = obtt; upperentry = evbeft-1; @@ -498,7 +594,7 @@ upperentry = evbeft-1; }; }; - if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); + if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); goto kikko; // break; // @@ -526,33 +622,65 @@ obth = OBT(phh->GetOrbitalTime()); }; // - if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); + if ( IsDebug() ) printf(" rhev before %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); if ( pkth > upperpkt && obth > upperobt ){ - if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt); + if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %lld upperp %lld oh %lld uppero %lld \n",pkth,upperpkt,obth,upperobt); upperpkt = pkth; upperobt = obth; rhev = lasthead+1; } else { rhev = lasthead; }; - if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); + if ( IsDebug() ) printf(" rhev after %i ph %lld upperp %lld oh %lld uppero %lld \n",rhev,pkth,upperpkt,obth,upperobt); // - if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); + if ( IsDebug() ) printf(" rtev beforev %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); if ( pktt > upperpkt && obtt > upperobt ){ - if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt); + if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %lld upperp %lld ot %lld uppero %lld \n",pktt,upperpkt,obtt,upperobt); upperpkt = pktt; upperobt = obtt; rtev = lasttrail+1; } else { rtev = lasttrail; }; - if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); + if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); // - if ( IsDebug() ) printf(" Upper limits are: OBT %llu pkt_num %i upper entry %i \n",upperobt,upperpkt,upperentry); + if ( IsDebug() ) printf(" Upper limits are: OBT %lld pkt_num %lld upper entry %i \n",upperobt,upperpkt,upperentry); // return(0); } +/** + * + * Trick to have unique RUN ID numbers even when runs are deleted and mysql deamon restarted. + * Entries in the _RUNID_GEN table are never deleted. + * + **/ +UInt_t PamelaDBOperations::AssignRunID(){ + // + TSQLResult *result = 0; + TSQLRow *row = 0; + UInt_t runid = 0; + // + stringstream oss; + // + oss.str(""); + oss << "INSERT INTO _RUNID_GEN VALUES (NULL);"; + result = conn->Query(oss.str().c_str()); + if ( !result ) throw -10; + oss.str(""); + oss << "SELECT ID FROM _RUNID_GEN ORDER BY ID DESC LIMIT 1;"; + result = conn->Query(oss.str().c_str()); + if ( !result ) throw -10; + // + row = result->Next(); + // + if ( !row ) throw -28; + // + runid = (UInt_t)atoll(row->GetField(0)); + // + return(runid); +}; + // // GETTERS // @@ -628,65 +756,76 @@ // PRIVATE FUNCTIONS // -/** - * Open the ROOT filename for reading - */ -void PamelaDBOperations::OpenFile(){ - file = TFile::Open(this->GetRootName().Data()); +// /** +// * Open the ROOT filename for reading +// */ +// void PamelaDBOperations::OpenFile(){ +// file = TFile::Open(this->GetRootName().Data()); +// // + +void PamelaDBOperations::CheckFile(){ + if ( !file ) throw -12; }; /** * Check if LEVEL0 file and DB connection have really be opened */ -void PamelaDBOperations::CheckFile(){ - // - if ( !file ) throw -12; +void PamelaDBOperations::CheckConnection(){ // // check connection // - if( !conn ) throw -1; + if( !conn ) throw -1; bool connect = conn->IsConnected(); - if( !connect ) throw -1; + if( !connect ) throw -1; + if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27; + // + // set DB timezone to UTC + // + stringstream oss; + // + oss.str(""); + oss << "SET time_zone='+0:00';"; + TSQLResult *result = 0; + result = conn->Query(oss.str().c_str()); + if ( !result ) throw -10; + // }; /** * Return the correct packet number if we went back to zero */ -UInt_t PamelaDBOperations::PKT(UInt_t pkt_num){ +Long64_t PamelaDBOperations::PKT(UInt_t pkt_num){ // - // if ( IsDebug() ) printf(" pkt conversion: pkt_num is %u pktfirst is %u (pktfirst - (UInt_t)(16777212/2)) is %u \n",pkt_num,pktfirst,(pktfirst - (UInt_t)(16777212/2))); + if ( IsDebug() ) printf(" pkt conversion: pkt_num is %u pktfirst is %u (UInt_t)(16777214/2)) is %u \n",pkt_num,pktfirst,(UInt_t)(16777214/2)); // - if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); + if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ){ + if ( IsDebug() ) printf(" rise up pktnum %lld \n",(Long64_t)pkt_num+16777215LL); + return((Long64_t)pkt_num+16777215LL); + }; // if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ - if ( (pkt_num-16777215) < 0 ){ - return((16777215-pkt_num)); - } else { - return((pkt_num-16777215)); - }; + if ( IsDebug() ) printf(" rise down pktnum %lld \n",(Long64_t)pkt_num-16777215LL); + return((Long64_t)pkt_num-16777215LL); }; // - return(pkt_num); + if ( IsDebug() ) printf(" as it is %lld \n",(Long64_t)pkt_num); + return((Long64_t)pkt_num); // }; /** * Return the correct On Board Time if we went back to zero */ -ULong64_t PamelaDBOperations::OBT(UInt_t obt){ +Long64_t PamelaDBOperations::OBT(UInt_t obt){ // - if ( obt < (obtfirst/2) && obtfirst > (numeric_limits::max()/2) ) return((ULong64_t)(obt+numeric_limits::max())); + if ( obt < (obtfirst/2) && obtfirst > (numeric_limits::max()/2) ) return((Long64_t)(obt+numeric_limits::max())); // if ( obt > (obtfirst*2) && obt > (numeric_limits::max()/2) ){ - if ( (obt-numeric_limits::max()) < 0 ){ - return((ULong64_t)(numeric_limits::max()-obt)); - } else { - return((ULong64_t)(obt-numeric_limits::max())); - }; + return((Long64_t)obt-(Long64_t)numeric_limits::max()); }; // - return((ULong64_t)obt); + return((Long64_t)obt); }; /** @@ -827,16 +966,28 @@ if ( this->GetID_RAW() == 0 ) throw -11; // oss.str(""); - oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " - << id << " AND TO_ID_RAW >= " - << id << ";"; + oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" + << this->GetRawFile().Data() << "';"; if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); result = conn->Query(oss.str().c_str()); if ( !result ) throw -10; row = result->Next(); - if ( !row ) throw -10; // - t0 = (UInt_t)TDatime(row->GetField(0)).Convert(); + if ( !row ){ + oss.str(""); + oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " + << dworbit << " 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; + row = result->Next(); + if ( !row ) throw -10; + }; + // + TTimeStamp tu = TTimeStamp((UInt_t)atoi(row->GetField(0)),(UInt_t)atoi(row->GetField(1)),(UInt_t)atoi(row->GetField(2)),(UInt_t)atoi(row->GetField(3)),(UInt_t)atoi(row->GetField(4)),(UInt_t)atoi(row->GetField(5)),0,true,0); + t0 = (UInt_t)tu.GetSec(); + if ( IsDebug() ) printf(" t0 is %u ti is %s %s %s %s %s %s\n",t0,row->GetField(0),row->GetField(1),row->GetField(2),row->GetField(3),row->GetField(4),row->GetField(5)); + // /* * Verify that the TIMESYNC have been not already processed */ @@ -851,7 +1002,12 @@ if (result == NULL) throw -10; row = result->Next(); if ((row != NULL) && ((UInt_t)atoll(row->GetField(0)) > 0)){ + if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0); toffset = (UInt_t)atoll(row->GetField(2)) - (UInt_t)(this->OBT((UInt_t)atoll(row->GetField(1)))/1000) + t0; + // + tsync = (UInt_t)atoll(row->GetField(2)); + obt0 = (UInt_t)atoll(row->GetField(1)); + // return(1); }; // @@ -908,6 +1064,8 @@ // TYPE = 55;//224; // + if ( IsDebug() ) printf("mcmd tsync %i tsync %u obt %u \n",i,TSYNC,OBT); + // if ( TSYNC && OBT ){ existsts = true; goto eout; @@ -930,35 +1088,49 @@ // rt->SetBranchAddress("RunTrailer", &runt); // - if ( rhev > 0 ){ - rh->GetEntry(0); - // - TSYNC = runh->LAST_TIME_SYNC_INFO; - OBT = runh->OBT_TIME_SYNC * 1000; - // - TYPE = 20; - // - if ( TSYNC && OBT ){ - existsts = true; - goto eout; + Int_t nrhev = rh->GetEntries(); + Int_t nrtev = rt->GetEntries(); + if ( IsDebug() ) printf(" ou nevent %i rhev %i rtev %i \n",nevent,nrhev,nrtev); + // + if ( nrhev > 0 ){ + for (Int_t i=0; iGetEntry(i); + // + TSYNC = runh->LAST_TIME_SYNC_INFO; + OBT = runh->OBT_TIME_SYNC * 1000; + // + TYPE = 20; + // + if ( IsDebug() ) printf("runheader %i tsync %u obt %u \n",i,TSYNC,OBT); + // + if ( TSYNC && OBT ){ + existsts = true; + goto eout; + }; }; // }; - if ( rtev > 0 ){ + if ( nrtev > 0 ){ // if ( IsDebug() ) printf(" No runheader \n"); signal = 6; // - rt->GetEntry(0); - // - TSYNC = runt->LAST_TYME_SYNC_INFO; - OBT = runt->OBT_TYME_SYNC * 1000; - // - TYPE = 21; - // - if ( TSYNC && OBT ){ - existsts = true; - goto eout; + for (Int_t i=0; iGetEntry(i); + // + TSYNC = runt->LAST_TYME_SYNC_INFO; + OBT = runt->OBT_TYME_SYNC * 1000; + // + TYPE = 21; + // + if ( IsDebug() ) printf("runtrailer %i tsync %u obt %u \n",i,TSYNC,OBT); + // + if ( TSYNC && OBT ){ + existsts = true; + goto eout; + }; }; // } else { @@ -1029,8 +1201,12 @@ conn->Query(oss.str().c_str()); if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to fill it:\n %s \n",oss.str().c_str()); // + if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0); toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; // + tsync = TSYNC; + obt0 = OBT; + // delete result; return(signal); } @@ -1130,13 +1306,14 @@ VarDumpEvent *vde = 0; VarDumpRecord *vdr = 0; // + Bool_t found = false; trDumpEv->SetBranchAddress("VarDump", &vde); if ( trDumpEv->GetEntries() > 0 ){ - Bool_t found = false; + found = false; for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){ trDumpEv->GetEntry(i); - vde->Records->GetEntries(); - if ( vde->Records->GetEntries()>0 ){ + // vde->Records->GetEntries(); + if ( vde->Records->GetEntries()>5 ){ found = true; goto fill; }; @@ -1149,10 +1326,60 @@ this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); // } else { - if ( !this->GetBOOTnumber() ) return(4); + if ( !this->GetBOOTnumber() && !this->AutoBoot()) return(4); + }; + } else { + if ( !this->GetBOOTnumber() && !this->AutoBoot()) return(2); + }; + // + UInt_t bn = 0; + Bool_t afound = false; + if ( !found && this->AutoBoot()){ + afound = true; + // + // Search for other files with similar timesync + // + if ( IsDebug() ) printf(" tsync %u obt0 %u \n",tsync,obt0); + UInt_t upperts = tsync-(obt0/1000)+5; + UInt_t lowerts = tsync-(obt0/1000)-5; + oss.str(""); + oss << "select GL_RAW.BOOT_NUMBER from GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW where TIMESYNC-(OBT0/1000)<" + << upperts + << " AND TIMESYNC-(OBT0/1000)>" + << lowerts + << " AND GL_RAW.BOOT_NUMBER>0 GROUP BY GL_TIMESYNC.OBT0;"; + result = conn->Query(oss.str().c_str()); + if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to find boot number:\n %s \n",oss.str().c_str()); + // + if ( !result ) throw -4;; + found = true; + if ( result->GetRowCount()<3 ){ + if ( IsDebug() ) printf(" AGH! no results!\n"); + found = false; + } else { + row = result->Next(); + bn = (UInt_t)atoll(row->GetField(0)); + for ( Int_t r=1; rGetRowCount() ;r++){ + if ( !row ) throw -4; + if ( IsDebug() ) printf(" BOOT number is %s \n",row->GetField(0)); + if ( bn != (UInt_t)atoll(row->GetField(0)) ){ + if ( IsDebug() ) printf(" AGH! bn = %u here instead %u \n",bn,(UInt_t)atoll(row->GetField(0))); + found = false; + }; + row = result->Next(); + }; }; + }; + // + Int_t sgn = 0; + // + if ( !found ){ + throw -29; } else { - if ( !this->GetBOOTnumber() ) return(2); + if ( afound ){ + this->SetBOOTnumber(bn); + sgn = 8; + }; }; // oss.str(""); @@ -1162,7 +1389,7 @@ conn->Query(oss.str().c_str()); // delete result; - return(0); + return(sgn); }; /** @@ -1425,10 +1652,11 @@ if ( glrun->GetNEVENTS() > (UInt_t)atoll(row->GetField(1)) ){ // if ( IsDebug() ) printf(" The new run has more events than the old one \n"); - 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()); + 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()); if ( signal ) signal = false; goto gonext; // @@ -1442,10 +1670,11 @@ // if ( IsDebug() ) printf(" The new run has the same number of events and the runheader the old one miss the runheader \n"); // - 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()); + 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()); // if ( signal ) signal = false; goto gonext; @@ -1459,10 +1688,11 @@ // if ( IsDebug() ) printf(" The new run has the same number of events, the runheader and the runtrailer the old one miss the runtrailer \n"); // - 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()); + 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()); if ( signal ) signal = false; // }; @@ -1477,6 +1707,7 @@ delete result; // if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); + if ( !signal && IsDebug() ) printf(" The run existed and was deleted, fill the DB \n"); return(signal); }; @@ -1498,7 +1729,11 @@ // this->FillClass(); // - if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); + if ( !IsRunAlreadyInserted() ){ + glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(0); + glrun->Fill_GL_RUN(conn); + }; } else { // if ( IsDebug() ) printf(" oh no! the distance between runheader and runtrailer seems wrong: check %llu pktt %llu \n",chkpkt,pktt); @@ -1521,6 +1756,7 @@ UInt_t rhfirstev = firstev; UInt_t rtlastev = lastev; Bool_t found = false; + Bool_t foundinrun = false; // TSQLResult *result = 0; TSQLRow *row = 0; @@ -1547,6 +1783,48 @@ // if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n"); // + // 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"); + return; + }; + // + // // can we find the other piece of the run in the GL_RUN_FRAGMENTS table? // if ( mishead && rhfirstev == firstev ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is @@ -1555,7 +1833,8 @@ 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() + << " 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()); @@ -1565,6 +1844,26 @@ // 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; @@ -1639,9 +1938,14 @@ // 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)); + // UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); // oss.str(""); oss << " ID="<GetField(0)<<";"; @@ -1670,7 +1974,6 @@ }; if ( IsDebug() ) printf(" Check overlapping events done: %i %i %llu %llu firstev is %i\n",apkt,bpkt,aobt,bobt,firstev); // - glrun1->SetID(0); glrun1->SetPKT_COUNTER(glrun->GetPKT_COUNTER()); glrun1->SetPKT_READY_COUNTER(glrun->GetPKT_READY_COUNTER()); glrun1->SetRUNTRAILER_TIME(glrun->GetRUNTRAILER_TIME()); @@ -1679,6 +1982,7 @@ // 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()); @@ -1698,67 +2002,23 @@ // if ( !IsRunAlreadyInserted() ){ // + // glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(glrun1->GetID()); glrun->Fill_GL_RUN(conn); // - // get id number - // - oss.str(""); - oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<GetBOOTnumber()<<" AND " - << " RUNHEADER_OBT="<GetRUNHEADER_OBT()<<" AND " - << " RUNTRAILER_OBT="<GetRUNTRAILER_OBT()<<";"; - // - if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str()); - // - result = conn->Query(oss.str().c_str()); - if ( !result ) throw -4; - row = result->Next(); - // - UInt_t idrun0 = 0; - if ( !row ){ - throw -10; - } else { - idrun0 = (UInt_t)atoll(row->GetField(0)); - }; - // - glrun1->SetID_RUN_FRAG(idrun0); + // set id number // + glrun1->SetID_RUN_FRAG(glrun->GetID()); glrun1->Fill_GL_RUN(conn); // - oss.str(""); - oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<Query(oss.str().c_str()); - if ( !result ) throw -4; - row = result->Next(); - // - UInt_t idrun1 = 0; - if ( !row ){ - throw -10; - } else { - idrun1 = (UInt_t)atoll(row->GetField(0)); - }; - // - oss.str(""); - oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<Query(oss.str().c_str()); - if ( !result ) throw -4; - // }; - // - delete glrun1; - // // delete old entry in fragment table // - oss.str(""); + glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); + glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); // - oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";"; + delete glrun1; // - if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - if ( !result ) throw -4; // return; // @@ -1767,12 +2027,13 @@ }; // if ( mistrail && rtlastev == lastev ) { // 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 + // 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() + << " 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()); @@ -1782,6 +2043,25 @@ // row = result->Next(); // + 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 ( !row ){ if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); found = false; @@ -1855,9 +2135,14 @@ // 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)); + // UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); // oss.str(""); oss << " ID="<GetField(0)<<";"; @@ -1894,7 +2179,6 @@ glrun->SetRUNTRAILER_OBT(glrun1->GetRUNTRAILER_OBT()); glrun->SetRUNTRAILER_PKT(glrun1->GetRUNTRAILER_PKT()); // - glrun1->SetID(0); glrun1->SetRUNHEADER_TIME(glrun->GetRUNHEADER_TIME()); glrun1->SetRUNHEADER_OBT(glrun->GetRUNHEADER_OBT()); glrun1->SetRUNHEADER_PKT(glrun->GetRUNHEADER_PKT()); @@ -1914,68 +2198,24 @@ // if ( !IsRunAlreadyInserted() ){ // - glrun->Fill_GL_RUN(conn); - // - // get id number + // glrun->SetID(this->AssignRunID()); // - oss.str(""); - oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<GetBOOTnumber()<<" AND " - << " RUNHEADER_OBT="<GetRUNHEADER_OBT()<<" AND " - << " RUNTRAILER_OBT="<GetRUNTRAILER_OBT()<<";"; + glrun->SetID_RUN_FRAG(glrun1->GetID()); + glrun->Fill_GL_RUN(conn); // - if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str()); + // set id number // - result = conn->Query(oss.str().c_str()); - if ( !result ) throw -4; - row = result->Next(); - // - UInt_t idrun0 = 0; - if ( !row ){ - throw -10; - } else { - idrun0 = (UInt_t)atoll(row->GetField(0)); - }; - // - glrun1->SetID_RUN_FRAG(idrun0); - // - glrun1->Fill_GL_RUN(conn); - // - oss.str(""); - oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<Query(oss.str().c_str()); - if ( !result ) throw -4; - row = result->Next(); - // - UInt_t idrun1 = 0; - if ( !row ){ - throw -10; - } else { - idrun1 = (UInt_t)atoll(row->GetField(0)); - }; - // - oss.str(""); - oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<Query(oss.str().c_str()); - if ( !result ) throw -4; + glrun1->SetID_RUN_FRAG(glrun->GetID()); + glrun1->Fill_GL_RUN(conn); // }; // - delete glrun1; + // delete old entries in fragment table // - // delete old entry in fragment table - // - oss.str(""); - // - oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";"; - // - if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - if ( !result ) throw -4; + glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); + glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); // + delete glrun1; // return; // @@ -2012,45 +2252,14 @@ // row = result->Next(); // - if ( !row ){ - // - 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->Fill_GL_RUN_FRAGMENTS(conn); - // - } else { - if ( IsDebug() ) printf(" The run is already present in the fragment table \n"); - }; - } else { + if ( row ){ if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); + } else { + if ( NoFrag() ){ + glrun->SetID_RUN_FRAG(glrun->GetID()); + glrun->Fill_GL_RUN(conn); + glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); + }; }; }; // @@ -2076,7 +2285,11 @@ // this->FillClass(mishead,mistrail,firstev,lastev); // - if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); + if ( !IsRunAlreadyInserted() ){ + glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(0); + glrun->Fill_GL_RUN(conn); + }; // }; // @@ -2243,7 +2456,11 @@ // this->SetCommonGLRUN(firstTime,lastTime); // - if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); + if ( !IsRunAlreadyInserted() ){ + glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(0); + glrun->Fill_GL_RUN(conn); + }; // firstevno = lastentry + 1; // @@ -2319,7 +2536,11 @@ if ( IsDebug() ) printf(" Checking but no events in the run! \n"); // this->FillClass(); - if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); + if ( !IsRunAlreadyInserted() ){ + glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(0); + glrun->Fill_GL_RUN(conn); + }; // } else { // @@ -2347,7 +2568,11 @@ if ( IsDebug() ) printf(" No packets but physics inside the run, I will consider it as good\n"); // this->FillClass(); - if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); + if ( !IsRunAlreadyInserted() ){ + glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(0); + glrun->Fill_GL_RUN(conn); + }; // } else { // @@ -2445,7 +2670,11 @@ // this->SetCommonGLRUN(firstTime,lastTime); // - if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); + if ( !IsRunAlreadyInserted() ){ + glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(0); + glrun->Fill_GL_RUN(conn); + }; // if ( i == lastev && checkfirst < check ){ // if the last event gives a wrong check... // @@ -2480,7 +2709,11 @@ // this->SetCommonGLRUN(firstTime,lastTime); // - if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); + if ( !IsRunAlreadyInserted() ){ + glrun->SetID(this->AssignRunID()); + glrun->SetID_RUN_FRAG(0); + glrun->Fill_GL_RUN(conn); + }; }; // firstevno = lastentry + 1; @@ -2587,7 +2820,7 @@ // no calibrations in the db contain our calibration // if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB for section %i \n",section); - if ( fromtime < 1150863400 ){ + if ( fromtime < 1150871000 ){ //1150866904 if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime); fromtime = 0;// the first flight calibration was taken at about 1156429100 s, this line allow to analyze first runs in raw mode }; @@ -2732,7 +2965,7 @@ // no calibrations in the db contain our calibration // if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n"); - if ( fromtime < 1150863400 ) fromtime = 0; // the first flight calibration was taken at about 1150863300 s, this line allows to analyze first runs in raw mode + if ( fromtime < 1150871000 ) fromtime = 0; // the first flight calibration was taken at about 1150863300 s, this line allows to analyze first runs in raw mode // oss.str(""); oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE " @@ -2861,14 +3094,17 @@ 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->OBT(obt1) >= this->OBT(obtfirst) ){ // if ( IsDebug() ) printf(" Trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1); + // + valid = ValidateTrkCalib( caltrk1, eh1 ); + if ( IsDebug() ) cout << " pkt1 validation --> "<GetOrbitalTime(); pkt2 = ph2->GetCounter(); // - 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 { // @@ -2916,6 +3152,10 @@ // if ( IsDebug() ) printf(" The trk calibration2 at obt %i pkt %i t2 is %i is good \n",obt2,pkt2,t2); // + UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); + if ( IsDebug() ) cout << " pkt2 validation --> "<HandleTRK_CALIB(true,true); @@ -3088,7 +3328,7 @@ // no calibrations in the db contain our calibration // if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB \n"); - if ( fromtime < 1150863400 ){ + if ( fromtime < 1150871000 ){ if ( IsDebug() ) printf(" First PAMELA flight calibration at time %i \n",fromtime); fromtime = 0;// the first flight calibration was taken at about 1156429100 s, this line allow to analyze first runs in raw mode }; @@ -3161,6 +3401,13 @@ * Scan the fragment table and move old fragments to the GL_RUN table */ Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){ + return(this->CleanGL_RUN_FRAGMENTS("")); +}; + +/** + * Scan the fragment table and move old fragments to the GL_RUN table + */ +Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(TString fcleanfile){ // TSQLResult *result = 0; TSQLRow *row = 0; @@ -3168,39 +3415,50 @@ TSQLRow *row2 = 0; // UInt_t moved = 0; - UInt_t timelim = 0; - TDatime *time = new TDatime(); // stringstream oss; oss.str(""); // - // - // - if ( olderthan < 0 ){ - if ( IsDebug() ) printf(" Do not clean GL_RUN_FRAGMENTS table \n"); - return(1); + if ( !strcmp(fcleanfile.Data(),"") ){ + // + // check if there are entries older than "olderthan" seconds from now + // + oss.str(""); + oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" + << " INSERT_TIME <= '" << clean_time->AsSQLString() << "';"; + // + if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + // + } else { + oss.str(""); + oss << " SELECT ID FROM GL_ROOT WHERE NAME='" << fcleanfile.Data() << "';"; + if ( IsDebug() ) printf(" Getting ID_ROOT_L0 query %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + // + if ( result ){ + // + row = result->Next(); + // + if ( row ){ + oss.str(""); + oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" + << " ID_ROOT_L0=" << row->GetField(0) << ";"; + // + if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS for ROOT file query is \n %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + // + }; + } else { + return(2); + }; }; // - // timelim = now - olderthan - // - time->Set(); - timelim = (UInt_t)time->Convert() - olderthan; - time->Set(timelim,false); - // - // check if there are entries older than "olderthan" seconds from now - // - oss.str(""); - oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" - << " INSERT_TIME <= '" << time->AsSQLString() << "';"; - // - if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - // if ( result ){ // row = result->Next(); // - if ( row ){ + while ( row ){ // oss.str(""); oss << " ID= "<< row->GetField(0); @@ -3235,32 +3493,33 @@ if ( IsDebug() ) printf(" The run is new \n"); if ( IsDebug() ) printf(" -> fill the DB \n"); // - glrun->SetID(0); + // glrun->SetID(this->AssignRunID()); we use the old run number! + 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++; // @@ -3270,13 +3529,15 @@ if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0)); // // - 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; - // + 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; +// // + row = result->Next(); }; }; if ( IsDebug() ) printf(" Moved %u runs\n",moved); @@ -3287,85 +3548,139 @@ * Check if runs are good, i.e. if the tracker calibration is correctly associated.. */ Int_t PamelaDBOperations::ValidateRuns(){ + return(this->ValidateRuns("")); +}; + +/** + * Check if runs are good, i.e. if the tracker calibration is correctly associated.. + */ +Int_t PamelaDBOperations::ValidateRuns(TString valfile){ // TSQLResult *result = 0; TSQLRow *row = 0; // - UInt_t timelim = 0; - TDatime *time = new TDatime(); + UInt_t calibtime = 50; // stringstream oss; oss.str(""); // - // - // - if ( olderthan < 0 ){ - if ( IsDebug() ) printf(" Do not validate runs \n"); - return(1); - }; - // - // timelim = now - olderthan - // - time->Set(); - timelim = (UInt_t)time->Convert() - olderthan; - time->Set(timelim,false); - - printf("Validate runs older than %s \n",time->AsSQLString()); - // ======================================================= // validate runs by checking missing calibrations // ======================================================= UInt_t t_stop = 0; UInt_t t_start = 0; - // -------------------------------------------------------------- - // 1) get the OBT of the last run inserted after clean-time limit - // -------------------------------------------------------------- - oss.str(""); - oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << time->AsSQLString() - << "' ORDER BY INSERT_TIME DESC LIMIT 1;"; - printf(" Get start validation-time: query is \n %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - if ( !result ) throw -4; - if ( !result->GetRowCount() ) { - printf(" No runs to validate \n"); - return(1); - }else{ - row = result->Next(); - t_start = (UInt_t)atoll(row->GetField(4)); - printf("t_start %i\n",t_start); - }; - // -------------------------------------------------------------- - // 2) get the OBT of the last validated run - // -------------------------------------------------------------- - oss.str(""); - oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start - <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; - printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); - if ( !result ) throw -4; - if ( result->GetRowCount() ){ - row = result->Next(); - t_stop = (UInt_t)atoll(row->GetField(4)); + if ( !strcmp(valfile.Data(),"") ) { + // -------------------------------------------------------------- + // 1) get the OBT of the last run inserted after clean-time limit + // -------------------------------------------------------------- + oss.str(""); + oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << clean_time->AsSQLString() + << "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; + if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + if ( !result ) throw -4; + if ( !result->GetRowCount() ) { + printf(" No runs to validate \n"); + return(1); + }else{ + row = result->Next(); + t_start = (UInt_t)atoll(row->GetField(4)); + }; + // -------------------------------------------------------------- + // 2) get the OBT of the last validated run + // -------------------------------------------------------------- + oss.str(""); + oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start + <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; + if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + if ( !result ) throw -4; + if ( result->GetRowCount() ){ + row = result->Next(); + t_stop = (UInt_t)atoll(row->GetField(4)); + }; + if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start); + // -------------------------------------------------------------- + // now retrieves runs to be validated + // -------------------------------------------------------------- + oss.str(""); + oss << " SELECT * FROM GL_RUN WHERE RUNHEADER_TIME <=" << t_start; + oss << " AND RUNHEADER_TIME >="<< t_stop; + oss << " ORDER BY RUNHEADER_TIME DESC;"; + if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str()); + result = conn->Query(oss.str().c_str()); + } else { + // + stringstream myquery; + UInt_t myid = 0; + myquery.str(""); + myquery << " SELECT ID FROM GL_ROOT where NAME='"<Query(myquery.str().c_str()); + // + row = result->Next(); + if( !row ){ + if ( strcmp(valfile.Data(),GetRootName().Data()) ){ + if ( IsDebug() ) printf(" No file to be validated even if option \"-validate file\" was used!!\n"); + return(2); + }; + if ( IsDebug() ) printf(" No file to be validated (force mode)! \n"); + return(0); + }; + myid=(UInt_t)atoll(row->GetField(0)); + // + myquery.str(""); + myquery << " SELECT MAX(RUNTRAILER_TIME),MIN(RUNHEADER_TIME) FROM GL_RUN WHERE ID_ROOT_L0="<< myid <<";"; + // + result = conn->Query(myquery.str().c_str()); + // + row = result->Next(); + if( !row->GetField(0) || !row->GetField(1)){ + // + if ( IsDebug() ) printf(" NO RUN ASSOCIATED TO THIS FILE! \n"); + // + return(0); + // + } else { + // + UInt_t runhtime = (UInt_t)atoll(row->GetField(0)); + UInt_t runttime = (UInt_t)atoll(row->GetField(1)); + UInt_t caltime = 0; + // + myquery.str(""); + myquery << " SELECT FROM_TIME FROM GL_TRK_CALIB where FROM_TIME>" <Query(myquery.str().c_str()); + // + row = result->Next(); + if( !row ){ + caltime = runhtime; + } else { + caltime = (UInt_t)atoll(row->GetField(0)); + }; + // + myquery.str(""); + myquery << " SELECT * from GL_RUN where RUNHEADER_TIME>="<< runttime <<" AND RUNHEADER_TIME<=" ; + myquery << caltime << " order by RUNHEADER_TIME DESC"; + // + if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); + // + result = conn->Query(myquery.str().c_str()); + // + }; }; - printf("t_stop %i\n",t_stop); - // -------------------------------------------------------------- - // now retrieves runs to be validated - // -------------------------------------------------------------- - oss.str(""); - oss << " SELECT * FROM GL_RUN WHERE RUNHEADER_TIME <=" << t_start; - oss << " AND RUNHEADER_TIME >="<< t_stop; - oss << " ORDER BY RUNHEADER_TIME DESC;"; -// if ( IsDebug() ) - printf(" Check runs for validation: query is \n %s \n",oss.str().c_str()); - result = conn->Query(oss.str().c_str()); + // if ( !result ) throw -4; - if ( !result->GetRowCount() ) printf(" No runs to validate \n"); - printf("------------------------------------------------------------------------------- \n"); - + if ( !result->GetRowCount() && IsDebug() ) printf(" No runs to validate \n"); + // Int_t nrow = 0; GL_RUN* this_run = new GL_RUN(); GL_RUN* next_run = new GL_RUN(); - Int_t nseq_max = 100; + Int_t nseq_max = 1000; // UInt_t* sequence = new UInt_t[100]; vector sequence(nseq_max); Int_t nseq = 0; @@ -3375,7 +3690,7 @@ UInt_t t1=0,t2=0; // --------------------------------------------------------------------------------- // - loop over runs, back in time, - // - select sequences of runs close in time (less than 60 s apart), + // - select sequences of runs close in time (less than calibtime s apart), // which could be preceeded by a calibration // - check if there might be a missing calibration // --------------------------------------------------------------------------------- @@ -3388,14 +3703,12 @@ //get run info //------------ this_run->Set_GL_RUN(row); - - printf(" RUN ID %i --- TRK_CALIB_USED %i --- RM_ACQ_AFTER_CALIB %i --- TIME %i %i \n",this_run->ID,this_run->TRK_CALIB_USED,this_run->RM_ACQ_AFTER_CALIB,this_run->RUNHEADER_TIME, this_run->RUNTRAILER_TIME); - + 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"); +// printf("Missing or corrupted header!! \n"); this_ONLINE = false; this_BAD = true; }; @@ -3417,11 +3730,7 @@ if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0; //=> run fragments - if( interval >= 60 )CHECK = true; //more than 60 s => there might be a calibration - -/* if( CHECK && !next_run->GetRM_ACQ_AFTER_CALIB() ) - printf(" ValidateRuns ***WARNING*** : DT = %i but RM_ACQ_AFTER_CALIB = %i \n",(t2-t1),next_run->GetRM_ACQ_AFTER_CALIB());*/ - + 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); @@ -3431,7 +3740,6 @@ }else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE CHECK = true; -// if( interval < 60 ) printf(" ValidateRuns ***WARNING*** : kkkkkk DT = %i \n",interval); }else if( !next_ONLINE ){ // this:ANY + next:DEFAULT @@ -3445,11 +3753,11 @@ //---------------------------- if( CHECK ){ // check if calibration exists - printf("DT %i ===> CHECK Missing calibration\n",interval); + 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; - } else printf("DT %i\n",interval); + }; //-------------- //store run info //-------------- @@ -3462,6 +3770,7 @@ }else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); }; + if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID); nrow++; }; @@ -3490,7 +3799,7 @@ // which should be equal to the time between ascending-nodes. //============================================================== if ( t2 - trkcalib->FROM_TIME > 5700) { - printf("Long time to previous calib %i :-( \n",t2 - trkcalib->FROM_TIME); + if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME); //============================================================== // there might be a missing calibration, due to: // - MM full @@ -3511,7 +3820,7 @@ // it is enough to say that there are no missing calibrations //============================================================== // the long time interval bewteen runs might be due to download - printf("Short time to previous calib %i :-) \n",t2 - trkcalib->FROM_TIME); + if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); return(false); }; @@ -3524,15 +3833,711 @@ TSQLResult *result = 0; stringstream oss; oss.str(""); - oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << "';"; + oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";"; // // if ( IsDebug() ) - printf(" Set VALIDATION = %i for run %i \n",validation,idrun); -// printf(" Set VALIDATION = %i for run %i : query is \n %s \n",validation,idrun,oss.str().c_str()); -// result = conn->Query(oss.str().c_str()); -// if ( !result ) throw -4; +// 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); } +// Insert TLEs from file tlefilename in the table GL_TLE in the db +// opened by conn, sorting them by date from older to newer, if each +// TLE has not been alread inserted. +Int_t PamelaDBOperations::populateTLE()//(TSQLServer *conn, char *tleFile) +{ + fstream tlefile(tlefilename, ios::in); + + if ( !tlefile ) throw -7; + + vector ctles; + vector::iterator iter; + int present = 0; + + // Get three lines from tlefile, create a cTle object and put it + // into ctles + while(1) { + cTle *tlef; + string str1, str2, str3; + + getline(tlefile, str1); + if(tlefile.eof()) break; + + getline(tlefile, str2); + if(tlefile.eof()) break; + + getline(tlefile, str3); + if(tlefile.eof()) break; + + // We now have three good lines for a cTle. + tlef = new cTle(str1, str2, str3); + ctles.push_back(tlef); + } + + tlefile.close(); + + // Sort by date + sort(ctles.begin(), ctles.end(), compTLE); + + // Now we insert each TLE into the db + for(iter = ctles.begin(); iter != ctles.end(); iter++) { + cTle *tle = *iter; + + // Do nothing if it's already present in the db. Just increase + // the counter present. + if (! isTlePresent(tle)) + { + int status = insertTle(tle); + + // Insert query failed. Return 1. + if(status == EXIT_FAILURE) { + + if( IsDebug() ) { + cerr << "Error: inserting TLE:" << endl + << tle->getName() << endl + << tle->getLine1() << endl + << tle->getLine2() << endl; + } + + throw -4; + return 1; + } + + } + else + present++; + + } + + int inserted = ctles.size() - present; // Number of inserted TLE. + if ( IsDebug() ) + cout << "\nProcessed TLEs ranging from " << getTleDatetime(ctles[0]) << " to " << getTleDatetime(ctles[ctles.size()-1]) << "." << endl + << inserted << " newly inserted TLEs out of " << ctles.size() << " processed." << endl; + + ctles.clear(); + + + // Return 2 if no new TLE has been inserted. 0 otherwise. + if(! inserted ) return 2; + return 0; +} + + +// Insert tle in the table GL_TLE using the connection conn. +Int_t PamelaDBOperations::insertTle(cTle *tle) +{ + stringstream oss; + TSQLResult *result = 0; + + oss.str(""); + oss << " INSERT INTO GL_TLE (TLE1, TLE2, TLE3, FROM_TIME)" + << " VALUES ( '" + << tle->getName() << "', '" + << tle->getLine1() << "', '" + << tle->getLine2() << "', '" + << getTleDatetime(tle) << "')"; + + // cout << oss.str().c_str() << endl; + result = conn->Query(oss.str().c_str()); + if (result == NULL) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + + +// Return whether tle is already in the db connected by conn. +bool PamelaDBOperations::isTlePresent(cTle *tle) +{ + stringstream oss; + TSQLResult *result = 0; + + oss.str(""); + oss << "SELECT * FROM GL_TLE WHERE FROM_TIME = '" + << getTleDatetime(tle) << "'"; + + result = conn->Query(oss.str().c_str()); + if (result == NULL) throw -4; + + if (result->GetRowCount()) + return true; + else + return false; +} + + +// Return whether the first TLE is dated early than the second +bool compTLE (cTle *tle1, cTle *tle2) +{ + return getTleJulian(tle1) < getTleJulian(tle2); +} + + +// Return the date of the tle using the format (year-2000)*1e3 + +// julian day. e.g. 6365 is the 31th Dec 2006. +// It does *not* return a cJulian date. +float getTleJulian(cTle *tle) { + return tle->getField(cTle::FLD_EPOCHYEAR)*1e3 + tle->getField(cTle::FLD_EPOCHDAY); +} + + +// Return a string like YYYY-MM-DD hh:mm:ss, usable for mysql datetime +// format. +string getTleDatetime(cTle *tle) +{ + int year, mon, day, hh, mm, ss; + double dom; // day of month (is double!) + stringstream date; // date in datetime format + + // create a cJulian from the date in tle + cJulian jdate = cJulian( 2000 + (int) tle->getField(cTle::FLD_EPOCHYEAR), tle->getField(cTle::FLD_EPOCHDAY)); + + // get year, month, day of month + jdate.getComponent(&year, &mon, &dom); + + // build a datetime YYYY-MM-DD hh:mm:ss + date.str(""); + day = (int) floor(dom); + hh = (int) floor( (dom - day) * 24); + mm = (int) floor( ((dom - day) * 24 - hh) * 60); + ss = (int) floor( ((((dom - day) * 24 - hh) * 60 - mm) * 60)); + // ms = (int) floor( (((((dom - day) * 24 - hh) * 60 - mm) * 60) - ss) * 1000); + + date << year << "-" << mon << "-" << day << " " << hh << ":" << mm << ":" << ss; + + return date.str(); +} + +/** + * Remove a file from the DB, delete on cascade all entries related to that file + * rearrange GL_RUN and GL_XXX_CALIB tables, turn off validation till the following + * calibration + **/ +Int_t PamelaDBOperations::removeFile(TString remfile){ + // + // Determine ID_ROOT_L0 and ID_RAW + // + TSQLResult *pResult; + TSQLRow *Row; + stringstream myquery; + // + myquery.str(""); + myquery << " SELECT ID, ID_RAW FROM GL_ROOT where NAME='"<Query(myquery.str().c_str()); + // + Row = pResult->Next(); + if( !Row ){ + if ( strcmp(remfile.Data(),GetRootName().Data()) ){ + if ( IsDebug() ) printf(" No file to be removed even if option \"-remove file\" was used!!\n"); + return(1); + }; + if ( IsDebug() ) printf(" No file to be removed (force mode)! \n"); + return(0); + }; + // + this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); + this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); + // + this->ValidationOFF(); + // + this->RemoveCALIBS(); + // + this->RemoveRUNS(); + // + this->RemoveFILES(); + // + this->SetID_ROOT(0); + this->SetID_RAW(0); + // + return(0); +}; + +/** + * + * Set validation bit to zero for runs following the removing file till + * 1) a run with TRK_CALIB_USED=140 + * 2) a run with VALIDATION = 0 + * 3) the next calibration + * + **/ +void PamelaDBOperations::ValidationOFF(){ + TSQLResult *pResult; + TSQLRow *Row; + stringstream myquery; + Int_t unv = 0; + //select ID from GL_RUN where RUNHEADER_TIME>=1152671382 AND (VALIDATION=0 OR TRK_CALIB_USED=104) order by RUNHEADER_TIME asc limit 1; + myquery.str(""); + myquery << " SELECT MAX(RUNTRAILER_TIME) FROM GL_RUN WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";"; + // + pResult = conn->Query(myquery.str().c_str()); + // + Row = pResult->Next(); + if( !Row->GetField(0) ){ + // + if ( IsDebug() ) printf(" NO RUN ASSOCIATED TO THIS FILE! \n"); + // + } else { + // + UInt_t runhtime = (UInt_t)atoll(Row->GetField(0)); + UInt_t caltime = 0; + // + myquery.str(""); + myquery << " SELECT FROM_TIME FROM GL_TRK_CALIB where FROM_TIME>" <Query(myquery.str().c_str()); + // + Row = pResult->Next(); + if( !Row ){ + caltime = runhtime; + } else { + caltime = (UInt_t)atoll(Row->GetField(0)); + }; + // + myquery.str(""); + myquery << " SELECT ID,RUNHEADER_TIME from GL_RUN where RUNHEADER_TIME>="<< runhtime <<" AND (VALIDATION=0 OR TRK_CALIB_USED=104 OR RUNHEADER_TIME>" ; + myquery << caltime << ") order by RUNHEADER_TIME asc LIMIT 1"; + // + if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); + // + pResult = conn->Query(myquery.str().c_str()); + // + Row = pResult->Next(); + if( !Row ){ + // + if ( IsDebug() ) printf(" NO RUN NEED TO BE UNVALIDATED \n"); + // + } else { + myquery.str(""); + myquery << " SELECT ID from GL_RUN where RUNHEADER_TIME<"<< Row->GetField(1) <<" AND "; + myquery << " RUNHEADER_TIME>=" <Query(myquery.str().c_str()); + // + Row = pResult->Next(); + while ( Row ){ + // + unv++; + this->assignVALIDATION((UInt_t)atoll(Row->GetField(0)), false); + Row = pResult->Next(); + // + }; + }; + }; + if ( IsDebug() ) printf(" %i runs have been unvalidated \n",unv); +}; + +/** + * + * Rearrange GL_RUN table and remove runs + * + **/ +void PamelaDBOperations::RemoveRUNS(){ + TSQLResult *pResult; + TSQLRow *Row; + stringstream myquery; + UInt_t drun = 0; + GL_RUN *delrun = new GL_RUN(); + // + myquery.str(""); + myquery << " SELECT ID FROM GL_RUN where ID_RUN_FRAG=0 and ID_ROOT_L0=" <GetID_ROOT() <<";"; + // + if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); + // + pResult = conn->Query(myquery.str().c_str()); + // + Row = pResult->Next(); + // + // + if ( !Row ){ + if ( IsDebug() ) printf(" No run with ID_RUN_FRAG=0 belonged to this file \n"); + } else { + if ( IsDebug() ) printf(" Deleting run from GL_RUN table \n"); + while ( Row ){ + delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN"); + if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0))); + drun++; + Row = pResult->Next(); + }; + }; + // + // + myquery.str(""); + myquery << " SELECT ID,ID_RUN_FRAG FROM GL_RUN where ID_RUN_FRAG!=0 and ID_ROOT_L0=" <GetID_ROOT() <<";"; + // + if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); + // + pResult = conn->Query(myquery.str().c_str()); + // + Row = pResult->Next(); + // + if ( !Row ){ + if ( IsDebug() ) printf(" No run with ID_RUN_FRAG!=0 belonged to this file \n"); + } else { + if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN table \n"); + while ( Row ){ + if ( IsDebug() ) printf(" restore run %i \n",(UInt_t)atoll(Row->GetField(1))); + delrun->RestoreRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN_FRAGMENTS"); + if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(1))); + delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN"); + if ( (UInt_t)atoll(Row->GetField(1)) != (UInt_t)atoll(Row->GetField(0)) ){ + if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0))); + delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN"); + }; + drun++; + Row = pResult->Next(); + }; + }; + // + if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN table \n",drun); + // + // + // + drun = 0; + // + myquery.str(""); + myquery << " SELECT ID_TRASH FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID_ROOT_L0=" <GetID_ROOT() <<";"; + // + pResult = conn->Query(myquery.str().c_str()); + // + Row = pResult->Next(); + // + if ( !Row ){ + if ( IsDebug() ) printf(" No run from GL_RUN_FRAGMENTS table in the trash table for this file \n"); + } else { + if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_TRASH table \n"); + while ( Row ){ + if ( IsDebug() ) printf(" del run idtrash %i \n",(UInt_t)atoll(Row->GetField(0))); + myquery.str(""); + myquery << " DELETE FROM GL_RUN_TRASH where ID_TRASH=" << Row->GetField(0) <<";"; + conn->Query(myquery.str().c_str()); + drun++; + Row = pResult->Next(); + }; + }; + // + if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_TRASH table \n",drun); + // + // + // + drun = 0; + // + myquery.str(""); + myquery << " SELECT ID FROM GL_RUN_FRAGMENTS where ID_ROOT_L0=" <GetID_ROOT() <<";"; + // + pResult = conn->Query(myquery.str().c_str()); + // + Row = pResult->Next(); + // + if ( !Row ){ + if ( IsDebug() ) printf(" No run in the GL_RUN_FRAGMENTS table for this file \n"); + } else { + if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_FRAGMENTS table \n"); + while ( Row ){ + if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0))); + myquery.str(""); + myquery << " DELETE FROM GL_RUN_FRAGMENTS where ID=" << Row->GetField(0) <<";"; + conn->Query(myquery.str().c_str()); + drun++; + Row = pResult->Next(); + }; + }; + // + if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_FRAGMENTS table \n",drun); + // + // + // + delete delrun; + // +}; + + +/** + * + * Rearrange calibration tables + * + **/ +void PamelaDBOperations::RemoveFILES(){ + stringstream myquery; + // + myquery.str(""); + myquery << " DELETE FROM GL_RAW WHERE ID=" <GetID_RAW() <<";"; + // + if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); + // + conn->Query(myquery.str().c_str()); + // +}; + +/** + * + * Rearrange calibration tables + * + **/ +void PamelaDBOperations::RemoveCALIBS(){ + TSQLResult *pResult; + TSQLRow *Row; + stringstream myquery; + // + // + // Calorimeter + // + for (Int_t section = 0; section < 4; section++){ + myquery.str(""); + myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_CALO_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<" AND "; + myquery << " SECTION=" << section << ";"; + // + pResult = conn->Query(myquery.str().c_str()); + // + Row = pResult->Next(); + if( !Row->GetField(0) || !Row->GetField(1) ){ + // + if ( IsDebug() ) printf(" NO CALO CALIBRATION SECTION %i ASSOCIATED TO THIS FILE! \n",section); + // + } else { + // + myquery.str(""); + myquery << " UPDATE GL_CALO_CALIB SET TO_TIME=" << Row->GetField(1); + myquery << " WHERE TO_TIME="<< Row->GetField(0) << " AND "; + myquery << " SECTION=" << section << ";"; + // + pResult = conn->Query(myquery.str().c_str()); + // + if( !pResult ){ + // + if ( IsDebug() ) printf(" ERROR DELETING CALO CALIBRATIONS \n"); + // + throw -4; + // + }; + // + }; + }; + myquery.str(""); + myquery << " DELETE FROM GL_CALO_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT(); + // + pResult = conn->Query(myquery.str().c_str()); + // + if( !pResult ){ + // + if ( IsDebug() ) printf(" ERROR DELETING CALO CALIBRATIONS \n"); + // + throw -4; + // + }; + // + // Tracker + // + myquery.str(""); + myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_TRK_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";"; + // + pResult = conn->Query(myquery.str().c_str()); + // + Row = pResult->Next(); + if( !Row->GetField(0) || !Row->GetField(1) ){ + // + if ( IsDebug() ) printf(" NO TRK CALIBRATION ASSOCIATED TO THIS FILE! \n"); + // + } else { + // + myquery.str(""); + myquery << " UPDATE GL_TRK_CALIB SET TO_TIME=" << Row->GetField(1); + myquery << " WHERE TO_TIME="<< Row->GetField(0) << ";"; + // + pResult = conn->Query(myquery.str().c_str()); + // + if( !pResult ){ + // + if ( IsDebug() ) printf(" ERROR DELETING TRK CALIBRATIONS \n"); + // + throw -4; + // + }; + // + myquery.str(""); + myquery << " DELETE FROM GL_TRK_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT(); + // + pResult = conn->Query(myquery.str().c_str()); + // + if( !pResult ){ + // + if ( IsDebug() ) printf(" ERROR DELETING TRK CALIBRATIONS \n"); + // + throw -4; + // + }; + }; + // + // + // S4 + // + myquery.str(""); + myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_S4_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";"; + // + pResult = conn->Query(myquery.str().c_str()); + // + Row = pResult->Next(); + if( !Row->GetField(0) || !Row->GetField(1) ){ + // + if ( IsDebug() ) printf(" NO S4 CALIBRATION ASSOCIATED TO THIS FILE! \n"); + // + } else { + // + myquery.str(""); + myquery << " UPDATE GL_S4_CALIB SET TO_TIME=" << Row->GetField(1); + myquery << " WHERE TO_TIME="<< Row->GetField(0) << ";"; + // + pResult = conn->Query(myquery.str().c_str()); + // + if( !pResult ){ + // + if ( IsDebug() ) printf(" ERROR DELETING S4 CALIBRATIONS \n"); + // + throw -4; + // + }; + // + myquery.str(""); + myquery << " DELETE FROM GL_S4_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT(); + // + pResult = conn->Query(myquery.str().c_str()); + // + if( !pResult ){ + // + if ( IsDebug() ) printf(" ERROR DELETING S4 CALIBRATIONS \n"); + // + throw -4; + // + }; + // + }; +}; +/** + * + * Rearrange calibration tables + * + **/ +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; // :-) + +// cout << classname << " "<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 :-( "<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 ( "<ACQ_BUILD_INFO & mask) != build ){ + if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<ACQ_BUILD_INFO&mask) << " != "<< build << dec<