101 |
if (INSERT_RAW) SetRawName(filerawname); |
if (INSERT_RAW) SetRawName(filerawname); |
102 |
// |
// |
103 |
INSERT_ROOT = !filerootname.IsNull(); |
INSERT_ROOT = !filerootname.IsNull(); |
104 |
|
if ( INSERT_ROOT ) this->SetRootName(filerootname); |
105 |
this->SetOrbitNo(dwinput); |
this->SetOrbitNo(dwinput); |
106 |
// |
// |
107 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
190 |
throw -85; |
throw -85; |
191 |
}; |
}; |
192 |
filerootname = chpath + chfile;// + ".root"; |
filerootname = chpath + chfile;// + ".root"; |
|
if ( debug ) printf(" chewbacca: filename is %s \n",filerootname.Data()); |
|
193 |
}; |
}; |
194 |
this->SetRootName(filerootname); |
this->SetRootName(filerootname); |
|
file = TFile::Open(this->GetRootName().Data()); |
|
|
} else { |
|
|
this->SetRootName(""); |
|
195 |
}; |
}; |
196 |
|
if ( debug ) printf(" Filename is %s \n",filerootname.Data()); |
197 |
|
file = TFile::Open(this->GetRootName().Data()); |
198 |
|
// } else { |
199 |
|
// this->SetRootName(""); |
200 |
|
// this->SetRootName(filerootname); |
201 |
|
// }; |
202 |
} |
} |
203 |
|
|
204 |
// |
// |
398 |
return; |
return; |
399 |
}; |
}; |
400 |
// |
// |
401 |
TString name = this->GetRootFile(); |
if ( !chewbacca ){ |
402 |
Int_t nlength = name.Length(); |
TString name = this->GetRootFile(); |
403 |
if ( nlength < 5 ) return; |
Int_t nlength = name.Length(); |
404 |
TString dwo = 0; |
if ( nlength < 5 ){ |
405 |
for (Int_t i = 0; i<5; i++){ |
if ( IsDebug() ) printf(" Agh problems determining the orbit number! name = %s \n",name.Data()); |
406 |
dwo.Append(name[i],1); |
return; |
407 |
}; |
}; |
408 |
if ( dwo.IsDigit() ){ |
TString dwo = 0; |
409 |
dworbit = (UInt_t)dwo.Atoi(); |
for (Int_t i = 0; i<5; i++){ |
|
} else { |
|
|
dwo=""; |
|
|
for (Int_t i = 8; i<13; i++){ |
|
410 |
dwo.Append(name[i],1); |
dwo.Append(name[i],1); |
411 |
}; |
}; |
412 |
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
if ( dwo.IsDigit() ){ |
413 |
|
dworbit = (UInt_t)dwo.Atoi(); |
414 |
|
} else { |
415 |
|
dwo=""; |
416 |
|
for (Int_t i = 8; i<13; i++){ |
417 |
|
dwo.Append(name[i],1); |
418 |
|
}; |
419 |
|
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
420 |
|
}; |
421 |
|
if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
422 |
}; |
}; |
|
if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
|
423 |
return; |
return; |
424 |
}; |
}; |
425 |
|
|
668 |
UInt_t tjump = 50000; |
UInt_t tjump = 50000; |
669 |
//UInt_t tjump = 100; |
//UInt_t tjump = 100; |
670 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
671 |
pktlast = numeric_limits<UInt_t>::max(); |
// pktlast = numeric_limits<UInt_t>::max(); |
672 |
while ( pktlast > chpktmax && (Int_t)(nevent-1-it) >= 0 ){ |
pktlast = chpktmax + 1; |
673 |
|
while ( PKT(pktlast) > PKT(chpktmax) && (Int_t)(nevent-1-it) >= 0 ){ |
674 |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
675 |
T->GetEntry(nevent-1-it); |
T->GetEntry(nevent-1-it); |
676 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
678 |
} else { |
} else { |
679 |
pktlast = chpktmax + 1; |
pktlast = chpktmax + 1; |
680 |
}; |
}; |
681 |
if ( (!(it%1000) || abs((int)pktlast - (int)chpktmax)<1000 ) && debug ) printf(" look for up %i %i %i nevent %u (nevent-1-it) %i \n",it,pktlast,chpktmax,nevent,(Int_t)(nevent-1-it)); |
if ( (!(it%1000) || abs((int)(PKT(pktlast) - PKT(chpktmax)))<1000 ) && debug ) printf(" look for up %i %i %i nevent %u (nevent-1-it) %i \n",it,pktlast,chpktmax,nevent,(Int_t)(nevent-1-it)); |
682 |
it += tjump; |
it += tjump; |
683 |
}; |
}; |
684 |
if ( tjump > 1 ) it -= 2*tjump; |
if ( tjump > 1 ) it -= 2*tjump; |
702 |
tjump = 50000; |
tjump = 50000; |
703 |
//tjump = 100; |
//tjump = 100; |
704 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
705 |
pktlast = 0; |
// pktlast = 0; |
706 |
while ( pktlast < chpktmin && it < (Int_t)nevent ){ |
pktlast = chpktmin - 1; |
707 |
|
if ( debug ) printf("LLlook for down %i %i %llu %llu \n",it,pktlast,PKT(pktlast),PKT(chpktmin)); |
708 |
|
while ( PKT(pktlast) < PKT(chpktmin) && it < (Int_t)nevent ){ |
709 |
if ( it < (Int_t)nevent ){ |
if ( it < (Int_t)nevent ){ |
710 |
T->GetEntry(it); |
T->GetEntry(it); |
711 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1360 |
// |
// |
1361 |
// if ( IsDebug() ) printf(" obt conversion: obt is %u obtfirst is %u (numeric_limits<UInt_t>::max()/2) is %u \n",obt,pobtfirst,(UInt_t)(numeric_limits<UInt_t>::max()/2)); |
// if ( IsDebug() ) printf(" obt conversion: obt is %u obtfirst is %u (numeric_limits<UInt_t>::max()/2) is %u \n",obt,pobtfirst,(UInt_t)(numeric_limits<UInt_t>::max()/2)); |
1362 |
// |
// |
1363 |
if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt < ((Long64_t)pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
1364 |
// if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
// if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
1365 |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
1366 |
}; |
}; |
1585 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1586 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1587 |
row = result->Next(); |
row = result->Next(); |
1588 |
|
if ( !row ) throw -92; |
1589 |
idresof = (UInt_t)atoll(row->GetField(0)); |
idresof = (UInt_t)atoll(row->GetField(0)); |
1590 |
existsts = true; |
existsts = true; |
1591 |
goto eout; |
goto eout; |
2326 |
// |
// |
2327 |
this->HandleRunFragments(true,true,chminentry,(evbefh)); |
this->HandleRunFragments(true,true,chminentry,(evbefh)); |
2328 |
// |
// |
2329 |
|
// what about pth=ptht-1 |
2330 |
}; |
}; |
2331 |
}; |
}; |
2332 |
// |
// |
2389 |
// if ( ptt+1 == rtev){ |
// if ( ptt+1 == rtev){ |
2390 |
if ( conptt+1 == nrtev ){ |
if ( conptt+1 == nrtev ){ |
2391 |
// if ( conptt+1 == (nrtev+nrtbef )){ |
// if ( conptt+1 == (nrtev+nrtbef )){ |
2392 |
|
if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt); |
2393 |
ptht++; |
ptht++; |
2394 |
if ( ptht < rhev ){ |
if ( ptht < rhev ){ |
2395 |
rh->GetEntry(ptht); |
rh->GetEntry(ptht); |
2396 |
|
//pth++; |
2397 |
|
//if ( pth < rhev ){ |
2398 |
|
//rh->GetEntry(pth); |
2399 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
2400 |
pkth = phh->GetCounter(); |
pkth = phh->GetCounter(); |
2401 |
obth = phh->GetOrbitalTime(); |
obth = phh->GetOrbitalTime(); |
2420 |
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 ( 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); |
2421 |
// |
// |
2422 |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
2423 |
rt->GetEntry(ptt-1); |
// rt->GetEntry(ptt-1); |
2424 |
|
rt->GetEntry(rtev-1); |
2425 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
2426 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics)+1; |
2427 |
evbefh = TMath::Max(chminentry,tcod); |
evbefh = TMath::Max(chminentry,tcod); |
2428 |
// evbefh = cod->Get(pctp->Physics); |
// evbefh = cod->Get(pctp->Physics); |
2429 |
rt->GetEntry(ptt); |
rt->GetEntry(ptt); |
3257 |
// |
// |
3258 |
} else { |
} else { |
3259 |
// |
// |
3260 |
if ( IsDebug() ) printf(" There are no-phyics packets inside the run!\n"); |
if ( IsDebug() ) printf(" There are no-physics packets inside the run!\n"); |
3261 |
// |
// |
3262 |
// HERE WE MUST HANDLE THAT RUNS AND GO BACK |
// HERE WE MUST HANDLE THAT RUNS AND GO BACK |
3263 |
// |
// |
3267 |
UInt_t check = 0; |
UInt_t check = 0; |
3268 |
UInt_t lastevtemp = lastev; |
UInt_t lastevtemp = lastev; |
3269 |
UInt_t firstevno = firstev; |
UInt_t firstevno = firstev; |
3270 |
|
UInt_t rhchko=0; |
3271 |
|
UInt_t rhchk=0; |
3272 |
// |
// |
3273 |
for (UInt_t i=firstev; i<=lastev; i++){ |
for (UInt_t i=firstev; i<=lastev; i++){ |
3274 |
// |
// |
3277 |
// |
// |
3278 |
check = 0; |
check = 0; |
3279 |
// |
// |
3280 |
|
|
3281 |
|
// if we have a runheader set lastev then exit |
3282 |
|
// |
3283 |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
3284 |
if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); |
if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); |
3285 |
}; |
}; |
3286 |
|
// check here if we have a runheader |
3287 |
|
rhchko = rhchk; |
3288 |
|
rhchk = code->Get(GetPacketType("RunHeader")); |
3289 |
// |
// |
3290 |
if ( checkfirst < check || i == lastev ){ |
if ( checkfirst < check || i == lastev ){ |
3291 |
// |
// |
3702 |
// |
// |
3703 |
}; |
}; |
3704 |
// |
// |
3705 |
|
if ( i > firstev ){ |
3706 |
|
if ( rhchko != rhchk ){ |
3707 |
|
if ( IsDebug() ) printf("oh oh... we have a runheader! stop here and handle later the remaining piece\n"); |
3708 |
|
lastev = i; |
3709 |
|
return(false); |
3710 |
|
}; |
3711 |
|
}; |
3712 |
|
// |
3713 |
if ( check == checklast && i != lastev ){ |
if ( check == checklast && i != lastev ){ |
3714 |
lastevtemp = i - 1; |
lastevtemp = i - 1; |
3715 |
i = lastev - 1; |
i = lastev - 1; |
6091 |
// 2) get the OBT of the last validated run |
// 2) get the OBT of the last validated run |
6092 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
6093 |
oss.str(""); |
oss.str(""); |
6094 |
oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
// oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
6095 |
|
oss << " SELECT * FROM GL_RUN WHERE VALIDATION>0 AND RUNHEADER_TIME<="<< t_start |
6096 |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
6097 |
if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
6098 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
6235 |
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 |
6236 |
|
|
6237 |
if( !CHECK && this_run->VALIDATION ){ |
if( !CHECK && this_run->VALIDATION ){ |
6238 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
// for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
6239 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],this_run->VALIDATION); |
6240 |
nseq=0; |
nseq=0; |
6241 |
} |
} |
6242 |
|
|
6257 |
if( CHECK ){ |
if( CHECK ){ |
6258 |
// check if calibration exists |
// check if calibration exists |
6259 |
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
6260 |
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
// Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
6261 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
UInt_t MISSING = MissingTRK_CALIB(t1,t2); |
6262 |
|
UInt_t val = 0; |
6263 |
|
if ( MISSING == 1 ) val = 0; |
6264 |
|
if ( MISSING == 0 ) val = 1; |
6265 |
|
if ( MISSING == 2 ) val = 2; |
6266 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],val); |
6267 |
nseq=0; |
nseq=0; |
6268 |
}; |
}; |
6269 |
//-------------- |
//-------------- |
6293 |
* @param t2 To absolute time |
* @param t2 To absolute time |
6294 |
* @return true if there might be a missing calibration |
* @return true if there might be a missing calibration |
6295 |
*/ |
*/ |
6296 |
Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
//Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
6297 |
|
UInt_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
6298 |
|
|
6299 |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
6300 |
|
|
6301 |
// get the closest calibration before the run start (t2) |
// get the closest calibration before the run start (t2) |
6302 |
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
// if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
6303 |
|
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(1); //>>> missing |
6304 |
|
|
6305 |
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
// if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
6306 |
|
if ( trkcalib->TO_TIME < t2 ) return(1); //>>> missing |
6307 |
|
|
6308 |
//============================================================== |
//============================================================== |
6309 |
// Check is done first on the basis of time between calibration, |
// Check is done first on the basis of time between calibration, |
6320 |
//============================================================== |
//============================================================== |
6321 |
Bool_t DOWNLOAD = false; |
Bool_t DOWNLOAD = false; |
6322 |
// check if the calib was skipped becouse of download .... DA FARE!! |
// check if the calib was skipped becouse of download .... DA FARE!! |
6323 |
if(DOWNLOAD)return(false); |
// if(DOWNLOAD)return(false); |
6324 |
|
if(DOWNLOAD)return(0); |
6325 |
|
|
6326 |
return(true); //>>> missing |
// return(true); //>>> missing |
6327 |
|
return(1); //>>> missing |
6328 |
|
|
6329 |
}; |
}; |
6330 |
|
|
6334 |
//============================================================== |
//============================================================== |
6335 |
// the long time interval bewteen runs might be due to download |
// the long time interval bewteen runs might be due to download |
6336 |
if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
6337 |
return(false); |
if ( trkcalib->VALIDATION ) return(0); |
6338 |
|
if ( IsDebug() )printf("Calibration is not validated... :-/ ==> OK but with VALIDATION=2! \n"); |
6339 |
|
return(2); |
6340 |
|
|
6341 |
}; |
}; |
6342 |
/** |
/** |
6345 |
* @param validation true/false |
* @param validation true/false |
6346 |
*/ |
*/ |
6347 |
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
6348 |
|
return(this->assignVALIDATION(idrun,(UInt_t)validation)); |
6349 |
|
} |
6350 |
|
|
6351 |
|
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, UInt_t validation){ |
6352 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
6353 |
stringstream oss; |
stringstream oss; |
6354 |
oss.str(""); |
oss.str(""); |
6545 |
stringstream myquery; |
stringstream myquery; |
6546 |
// |
// |
6547 |
myquery.str(""); |
myquery.str(""); |
6548 |
myquery << " SELECT ID, ID_RAW FROM GL_ROOT where NAME='"<<remfile.Data() <<"';"; |
myquery << " SELECT ID,ID_RAW,ID_TIMESYNC FROM GL_ROOT where NAME='"<<remfile.Data() <<"';"; |
6549 |
// |
// |
6550 |
pResult = conn->Query(myquery.str().c_str()); |
pResult = conn->Query(myquery.str().c_str()); |
6551 |
// |
// |
6561 |
// |
// |
6562 |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
6563 |
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
6564 |
|
UInt_t idtsy=(UInt_t)atoll(Row->GetField(2)); |
6565 |
// |
// |
6566 |
this->ValidationOFF(); |
this->ValidationOFF(); |
6567 |
// |
// |
6569 |
// |
// |
6570 |
this->RemoveRUNS(); |
this->RemoveRUNS(); |
6571 |
// |
// |
6572 |
this->RemoveFILES(); |
this->RemoveFILES(idtsy); |
6573 |
// |
// |
6574 |
this->SetID_ROOT(0); |
this->SetID_ROOT(0); |
6575 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
6789 |
* Rearrange calibration tables |
* Rearrange calibration tables |
6790 |
* |
* |
6791 |
**/ |
**/ |
6792 |
void PamelaDBOperations::RemoveFILES(){ |
void PamelaDBOperations::RemoveFILES(UInt_t idtsy){ |
6793 |
stringstream myquery; |
stringstream myquery; |
6794 |
// |
// |
6795 |
myquery.str(""); |
myquery.str(""); |
6799 |
// |
// |
6800 |
conn->Query(myquery.str().c_str()); |
conn->Query(myquery.str().c_str()); |
6801 |
// |
// |
6802 |
|
myquery.str(""); |
6803 |
|
myquery << " DELETE FROM GL_ROOT WHERE ID=" <<this->GetID_ROOT() <<";"; |
6804 |
|
// |
6805 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
6806 |
|
// |
6807 |
|
conn->Query(myquery.str().c_str()); // |
6808 |
|
// |
6809 |
|
if ( !chewbacca ){ |
6810 |
|
myquery.str(""); |
6811 |
|
myquery << " DELETE FROM GL_TIMESYNC WHERE ID=" << idtsy <<";"; |
6812 |
|
// |
6813 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
6814 |
|
// |
6815 |
|
conn->Query(myquery.str().c_str()); |
6816 |
|
}; |
6817 |
|
// |
6818 |
}; |
}; |
6819 |
|
|
6820 |
/** |
/** |