| 48 |
* @param tsync file timesync. |
* @param tsync file timesync. |
| 49 |
* @param debug debug flag. |
* @param debug debug flag. |
| 50 |
*/ |
*/ |
| 51 |
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, Long64_t olderthan){ |
| 52 |
// |
// |
| 53 |
// |
// |
| 54 |
SetConnection(host,user,password); |
SetConnection(host,user,password); |
| 63 |
SetObt0(obt0); |
SetObt0(obt0); |
| 64 |
// |
// |
| 65 |
// |
// |
| 66 |
SetRootName(filerootname); |
INSERT_RAW =!filerawname.IsNull(); |
| 67 |
SetRawName(filerawname); |
if(INSERT_RAW)SetRawName(filerawname); |
| 68 |
// |
// |
| 69 |
this->OpenFile(); |
INSERT_ROOT = !filerootname.IsNull(); |
| 70 |
|
if(INSERT_ROOT){ |
| 71 |
|
file = TFile::Open(this->GetRootName().Data()); |
| 72 |
|
if ( !file ) INSERT_ROOT = false; |
| 73 |
|
}; |
| 74 |
|
// this->OpenFile(); |
| 75 |
// |
// |
| 76 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
| 77 |
this->SetID_ROOT(0); |
this->SetID_ROOT(0); |
| 78 |
// |
|
| 79 |
|
VALIDATE = false; |
| 80 |
|
clean_time = new TDatime(); |
| 81 |
|
if(olderthan >= 0){ |
| 82 |
|
VALIDATE = true; |
| 83 |
|
UInt_t timelim = 0; |
| 84 |
|
// timelim = now - olderthan |
| 85 |
|
timelim = (UInt_t)clean_time->Convert() - olderthan; |
| 86 |
|
clean_time->Set(timelim,false); |
| 87 |
|
}; |
| 88 |
|
|
| 89 |
|
// |
| 90 |
}; |
}; |
| 91 |
|
|
| 92 |
/** |
/** |
| 94 |
*/ |
*/ |
| 95 |
void PamelaDBOperations::Close(){ |
void PamelaDBOperations::Close(){ |
| 96 |
if( conn && conn->IsConnected() ) conn->Close(); |
if( conn && conn->IsConnected() ) conn->Close(); |
| 97 |
|
delete clean_time; |
| 98 |
delete glrun; |
delete glrun; |
| 99 |
delete this; |
delete this; |
| 100 |
}; |
}; |
| 189 |
* Store the olderthan variable |
* Store the olderthan variable |
| 190 |
* @param olderthan |
* @param olderthan |
| 191 |
*/ |
*/ |
| 192 |
void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
// void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
| 193 |
olderthan = oldthan; |
// olderthan = oldthan; |
| 194 |
}; |
// }; |
| 195 |
|
|
| 196 |
/** |
/** |
| 197 |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
| 645 |
// PRIVATE FUNCTIONS |
// PRIVATE FUNCTIONS |
| 646 |
// |
// |
| 647 |
|
|
| 648 |
/** |
// /** |
| 649 |
* Open the ROOT filename for reading |
// * Open the ROOT filename for reading |
| 650 |
*/ |
// */ |
| 651 |
void PamelaDBOperations::OpenFile(){ |
// void PamelaDBOperations::OpenFile(){ |
| 652 |
file = TFile::Open(this->GetRootName().Data()); |
// file = TFile::Open(this->GetRootName().Data()); |
| 653 |
}; |
// // |
| 654 |
|
// if ( !file ) throw -12; |
| 655 |
|
// }; |
| 656 |
|
|
| 657 |
|
|
| 658 |
/** |
/** |
| 659 |
* Check if LEVEL0 file and DB connection have really be opened |
* Check if LEVEL0 file and DB connection have really be opened |
| 660 |
*/ |
*/ |
| 661 |
void PamelaDBOperations::CheckFile(){ |
void PamelaDBOperations::CheckConnection(){ |
|
// |
|
|
if ( !file ) throw -12; |
|
| 662 |
// |
// |
| 663 |
// check connection |
// check connection |
| 664 |
// |
// |
| 665 |
if( !conn ) throw -1; |
if( !conn ) throw -1; |
| 666 |
bool connect = conn->IsConnected(); |
bool connect = conn->IsConnected(); |
| 667 |
if( !connect ) throw -1; |
if( !connect ) throw -1; |
| 668 |
}; |
}; |
| 669 |
|
|
| 670 |
/** |
/** |
| 3185 |
TSQLRow *row2 = 0; |
TSQLRow *row2 = 0; |
| 3186 |
// |
// |
| 3187 |
UInt_t moved = 0; |
UInt_t moved = 0; |
| 3188 |
UInt_t timelim = 0; |
// UInt_t timelim = 0; |
| 3189 |
TDatime *time = new TDatime(); |
// TDatime *time = new TDatime(); |
| 3190 |
// |
// |
| 3191 |
stringstream oss; |
stringstream oss; |
| 3192 |
oss.str(""); |
oss.str(""); |
| 3193 |
// |
// |
| 3194 |
// |
// |
|
// |
|
|
if ( olderthan < 0 ){ |
|
|
if ( IsDebug() ) printf(" Do not clean GL_RUN_FRAGMENTS table \n"); |
|
|
return(1); |
|
|
}; |
|
|
// |
|
|
// timelim = now - olderthan |
|
|
// |
|
|
time->Set(); |
|
|
timelim = (UInt_t)time->Convert() - olderthan; |
|
|
time->Set(timelim,false); |
|
|
// |
|
| 3195 |
// check if there are entries older than "olderthan" seconds from now |
// check if there are entries older than "olderthan" seconds from now |
| 3196 |
// |
// |
| 3197 |
oss.str(""); |
oss.str(""); |
| 3198 |
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
| 3199 |
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
<< " INSERT_TIME <= '" << clean_time->AsSQLString() << "';"; |
| 3200 |
// |
// |
| 3201 |
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); |
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str()); |
| 3202 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 3203 |
// |
// |
| 3204 |
if ( result ){ |
if ( result ){ |
| 3296 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
| 3297 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
| 3298 |
// |
// |
|
UInt_t timelim = 0; |
|
|
TDatime *time = new TDatime(); |
|
|
// |
|
| 3299 |
stringstream oss; |
stringstream oss; |
| 3300 |
oss.str(""); |
oss.str(""); |
| 3301 |
// |
// |
|
// |
|
|
// |
|
|
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()); |
|
|
|
|
| 3302 |
// ======================================================= |
// ======================================================= |
| 3303 |
// validate runs by checking missing calibrations |
// validate runs by checking missing calibrations |
| 3304 |
// ======================================================= |
// ======================================================= |
| 3308 |
// 1) get the OBT of the last run inserted after clean-time limit |
// 1) get the OBT of the last run inserted after clean-time limit |
| 3309 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
| 3310 |
oss.str(""); |
oss.str(""); |
| 3311 |
oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << time->AsSQLString() |
oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << clean_time->AsSQLString() |
| 3312 |
<< "' ORDER BY INSERT_TIME DESC LIMIT 1;"; |
<< "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
| 3313 |
printf(" Get start validation-time: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str()); |
| 3314 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 3315 |
if ( !result ) throw -4; |
if ( !result ) throw -4; |
| 3316 |
if ( !result->GetRowCount() ) { |
if ( !result->GetRowCount() ) { |
| 3319 |
}else{ |
}else{ |
| 3320 |
row = result->Next(); |
row = result->Next(); |
| 3321 |
t_start = (UInt_t)atoll(row->GetField(4)); |
t_start = (UInt_t)atoll(row->GetField(4)); |
|
printf("t_start %i\n",t_start); |
|
| 3322 |
}; |
}; |
| 3323 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
| 3324 |
// 2) get the OBT of the last validated run |
// 2) get the OBT of the last validated run |
| 3326 |
oss.str(""); |
oss.str(""); |
| 3327 |
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 |
| 3328 |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
| 3329 |
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()); |
| 3330 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 3331 |
if ( !result ) throw -4; |
if ( !result ) throw -4; |
| 3332 |
if ( result->GetRowCount() ){ |
if ( result->GetRowCount() ){ |
| 3333 |
row = result->Next(); |
row = result->Next(); |
| 3334 |
t_stop = (UInt_t)atoll(row->GetField(4)); |
t_stop = (UInt_t)atoll(row->GetField(4)); |
| 3335 |
}; |
}; |
| 3336 |
printf("t_stop %i\n",t_stop); |
if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start); |
| 3337 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
| 3338 |
// now retrieves runs to be validated |
// now retrieves runs to be validated |
| 3339 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
| 3342 |
oss << " AND RUNHEADER_TIME >="<< t_stop; |
oss << " AND RUNHEADER_TIME >="<< t_stop; |
| 3343 |
oss << " ORDER BY RUNHEADER_TIME DESC;"; |
oss << " ORDER BY RUNHEADER_TIME DESC;"; |
| 3344 |
// if ( IsDebug() ) |
// if ( IsDebug() ) |
| 3345 |
printf(" Check runs for validation: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str()); |
| 3346 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 3347 |
if ( !result ) throw -4; |
if ( !result ) throw -4; |
| 3348 |
if ( !result->GetRowCount() ) printf(" No runs to validate \n"); |
if ( !result->GetRowCount() ) printf(" No runs to validate \n"); |
| 3349 |
printf("------------------------------------------------------------------------------- \n"); |
// printf("------------------------------------------------------------------------------- \n"); |
| 3350 |
|
|
| 3351 |
Int_t nrow = 0; |
Int_t nrow = 0; |
| 3352 |
GL_RUN* this_run = new GL_RUN(); |
GL_RUN* this_run = new GL_RUN(); |
| 3353 |
GL_RUN* next_run = new GL_RUN(); |
GL_RUN* next_run = new GL_RUN(); |
| 3354 |
Int_t nseq_max = 100; |
Int_t nseq_max = 1000; |
| 3355 |
// UInt_t* sequence = new UInt_t[100]; |
// UInt_t* sequence = new UInt_t[100]; |
| 3356 |
vector<UInt_t> sequence(nseq_max); |
vector<UInt_t> sequence(nseq_max); |
| 3357 |
Int_t nseq = 0; |
Int_t nseq = 0; |
| 3374 |
//get run info |
//get run info |
| 3375 |
//------------ |
//------------ |
| 3376 |
this_run->Set_GL_RUN(row); |
this_run->Set_GL_RUN(row); |
| 3377 |
|
|
|
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); |
|
|
|
|
| 3378 |
Bool_t this_BAD = false; |
Bool_t this_BAD = false; |
| 3379 |
if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true; |
if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true; |
| 3380 |
else if (this_run->GetTRK_CALIB_USED() == 104) this_ONLINE = false; |
else if (this_run->GetTRK_CALIB_USED() == 104) this_ONLINE = false; |
| 3381 |
else{ |
else{ |
| 3382 |
printf("Missing or corrupted header!! \n"); |
// printf("Missing or corrupted header!! \n"); |
| 3383 |
this_ONLINE = false; |
this_ONLINE = false; |
| 3384 |
this_BAD = true; |
this_BAD = true; |
| 3385 |
}; |
}; |
| 3403 |
|
|
| 3404 |
if( interval >= 60 )CHECK = true; //more than 60 s => there might be a calibration |
if( interval >= 60 )CHECK = true; //more than 60 s => there might be a calibration |
| 3405 |
|
|
|
/* 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());*/ |
|
|
|
|
|
|
|
| 3406 |
if( !CHECK && this_run->VALIDATION ){ |
if( !CHECK && this_run->VALIDATION ){ |
| 3407 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
| 3408 |
nseq=0; |
nseq=0; |
| 3411 |
}else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE |
}else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE |
| 3412 |
|
|
| 3413 |
CHECK = true; |
CHECK = true; |
|
// if( interval < 60 ) printf(" ValidateRuns ***WARNING*** : kkkkkk DT = %i \n",interval); |
|
| 3414 |
|
|
| 3415 |
}else if( !next_ONLINE ){ // this:ANY + next:DEFAULT |
}else if( !next_ONLINE ){ // this:ANY + next:DEFAULT |
| 3416 |
|
|
| 3424 |
//---------------------------- |
//---------------------------- |
| 3425 |
if( CHECK ){ |
if( CHECK ){ |
| 3426 |
// check if calibration exists |
// check if calibration exists |
| 3427 |
printf("DT %i ===> CHECK Missing calibration\n",interval); |
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
| 3428 |
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
| 3429 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
| 3430 |
nseq=0; |
nseq=0; |
| 3431 |
} else printf("DT %i\n",interval); |
}; |
| 3432 |
//-------------- |
//-------------- |
| 3433 |
//store run info |
//store run info |
| 3434 |
//-------------- |
//-------------- |
| 3441 |
}else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); |
}else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); |
| 3442 |
}; |
}; |
| 3443 |
|
|
| 3444 |
|
if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID); |
| 3445 |
nrow++; |
nrow++; |
| 3446 |
|
|
| 3447 |
}; |
}; |
| 3470 |
// which should be equal to the time between ascending-nodes. |
// which should be equal to the time between ascending-nodes. |
| 3471 |
//============================================================== |
//============================================================== |
| 3472 |
if ( t2 - trkcalib->FROM_TIME > 5700) { |
if ( t2 - trkcalib->FROM_TIME > 5700) { |
| 3473 |
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); |
| 3474 |
//============================================================== |
//============================================================== |
| 3475 |
// there might be a missing calibration, due to: |
// there might be a missing calibration, due to: |
| 3476 |
// - MM full |
// - MM full |
| 3491 |
// it is enough to say that there are no missing calibrations |
// it is enough to say that there are no missing calibrations |
| 3492 |
//============================================================== |
//============================================================== |
| 3493 |
// the long time interval bewteen runs might be due to download |
// the long time interval bewteen runs might be due to download |
| 3494 |
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); |
| 3495 |
return(false); |
return(false); |
| 3496 |
|
|
| 3497 |
}; |
}; |
| 3504 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
| 3505 |
stringstream oss; |
stringstream oss; |
| 3506 |
oss.str(""); |
oss.str(""); |
| 3507 |
oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << "';"; |
oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";"; |
| 3508 |
// |
// |
| 3509 |
// if ( IsDebug() ) |
// if ( IsDebug() ) |
| 3510 |
printf(" Set VALIDATION = %i for run %i \n",validation,idrun); |
// printf(" Set VALIDATION = %i for run %i \n",validation,idrun); |
| 3511 |
// printf(" Set VALIDATION = %i for run %i : query is \n %s \n",validation,idrun,oss.str().c_str()); |
if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str()); |
| 3512 |
// result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 3513 |
// if ( !result ) throw -4; |
if ( !result ) throw -4; |
| 3514 |
return(0); |
return(0); |
| 3515 |
} |
} |
| 3516 |
|
|