| 31 |
#include <varDump/VarDumpRecord.h> |
#include <varDump/VarDumpRecord.h> |
| 32 |
#include <physics/S4/S4Event.h> |
#include <physics/S4/S4Event.h> |
| 33 |
// |
// |
| 34 |
|
#include <cTle.h> |
| 35 |
|
#include <cEci.h> |
| 36 |
|
#include <cJulian.h> |
| 37 |
|
|
| 38 |
#include <PamelaDBOperations.h> |
#include <PamelaDBOperations.h> |
| 39 |
// |
// |
| 40 |
using namespace std; |
using namespace std; |
| 41 |
using namespace pamela; |
using namespace pamela; |
| 42 |
|
|
| 43 |
|
// Some function to work with cTle stuff. |
| 44 |
|
bool compTLE(cTle* tle1, cTle *tle2); |
| 45 |
|
float getTleJulian(cTle *); |
| 46 |
|
string getTleDatetime(cTle*); |
| 47 |
|
|
| 48 |
/** |
/** |
| 49 |
* Constructor. |
* Constructor. |
| 50 |
* @param host hostname for the SQL connection. |
* @param host hostname for the SQL connection. |
| 56 |
* @param obt0 file obt0. |
* @param obt0 file obt0. |
| 57 |
* @param tsync file timesync. |
* @param tsync file timesync. |
| 58 |
* @param debug debug flag. |
* @param debug debug flag. |
| 59 |
|
* @param tlefilename ascii file with TLE 3 line elements. |
| 60 |
*/ |
*/ |
| 61 |
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){ |
| 62 |
// |
// |
| 63 |
// |
// |
| 64 |
SetConnection(host,user,password); |
SetConnection(host,user,password); |
| 72 |
SetTsync(tsync); |
SetTsync(tsync); |
| 73 |
SetObt0(obt0); |
SetObt0(obt0); |
| 74 |
// |
// |
| 75 |
|
SetTLEPath(tlefilename); |
| 76 |
// |
// |
|
SetRootName(filerootname); |
|
|
SetRawName(filerawname); |
|
| 77 |
// |
// |
| 78 |
this->OpenFile(); |
INSERT_RAW =!filerawname.IsNull(); |
| 79 |
|
if(INSERT_RAW)SetRawName(filerawname); |
| 80 |
|
// |
| 81 |
|
INSERT_ROOT = !filerootname.IsNull(); |
| 82 |
|
if( INSERT_ROOT ){ |
| 83 |
|
this->SetRootName(filerootname); |
| 84 |
|
file = TFile::Open(this->GetRootName().Data()); |
| 85 |
|
}; |
| 86 |
// |
// |
| 87 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
| 88 |
this->SetID_ROOT(0); |
this->SetID_ROOT(0); |
| 89 |
|
|
| 90 |
|
VALIDATE = false; |
| 91 |
|
|
| 92 |
// |
// |
| 93 |
}; |
}; |
| 94 |
|
|
| 97 |
*/ |
*/ |
| 98 |
void PamelaDBOperations::Close(){ |
void PamelaDBOperations::Close(){ |
| 99 |
if( conn && conn->IsConnected() ) conn->Close(); |
if( conn && conn->IsConnected() ) conn->Close(); |
| 100 |
|
delete clean_time; |
| 101 |
delete glrun; |
delete glrun; |
| 102 |
delete this; |
delete this; |
| 103 |
}; |
}; |
| 106 |
// SETTERS |
// SETTERS |
| 107 |
// |
// |
| 108 |
|
|
| 109 |
|
// |
| 110 |
|
// 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 |
| 111 |
|
// |
| 112 |
|
void PamelaDBOperations::CheckValidate(Long64_t olderthan){ |
| 113 |
|
clean_time = new TDatime(); |
| 114 |
|
if(olderthan >= 0){ |
| 115 |
|
VALIDATE = true; |
| 116 |
|
UInt_t timelim = 0; |
| 117 |
|
timelim = (UInt_t)clean_time->Convert() - olderthan; |
| 118 |
|
clean_time->Set(timelim,false); |
| 119 |
|
}; |
| 120 |
|
}; |
| 121 |
|
|
| 122 |
/** |
/** |
| 123 |
* Open the DB connection |
* Open the DB connection |
| 124 |
* @param host hostname for the SQL connection. |
* @param host hostname for the SQL connection. |
| 202 |
}; |
}; |
| 203 |
|
|
| 204 |
/** |
/** |
| 205 |
|
* Store path to the TLE file. |
| 206 |
|
*/ |
| 207 |
|
void PamelaDBOperations::SetTLEPath(TString str){ |
| 208 |
|
tlefilename = str; |
| 209 |
|
}; |
| 210 |
|
|
| 211 |
|
/** |
| 212 |
* Store the olderthan variable |
* Store the olderthan variable |
| 213 |
* @param olderthan |
* @param olderthan |
| 214 |
*/ |
*/ |
| 215 |
void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
// void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
| 216 |
olderthan = oldthan; |
// olderthan = oldthan; |
| 217 |
}; |
// }; |
| 218 |
|
|
| 219 |
/** |
/** |
| 220 |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
| 668 |
// PRIVATE FUNCTIONS |
// PRIVATE FUNCTIONS |
| 669 |
// |
// |
| 670 |
|
|
| 671 |
/** |
// /** |
| 672 |
* Open the ROOT filename for reading |
// * Open the ROOT filename for reading |
| 673 |
*/ |
// */ |
| 674 |
void PamelaDBOperations::OpenFile(){ |
// void PamelaDBOperations::OpenFile(){ |
| 675 |
file = TFile::Open(this->GetRootName().Data()); |
// file = TFile::Open(this->GetRootName().Data()); |
| 676 |
|
// // |
| 677 |
|
|
| 678 |
|
void PamelaDBOperations::CheckFile(){ |
| 679 |
|
if ( !file ) throw -12; |
| 680 |
}; |
}; |
| 681 |
|
|
| 682 |
|
|
| 683 |
/** |
/** |
| 684 |
* Check if LEVEL0 file and DB connection have really be opened |
* Check if LEVEL0 file and DB connection have really be opened |
| 685 |
*/ |
*/ |
| 686 |
void PamelaDBOperations::CheckFile(){ |
void PamelaDBOperations::CheckConnection(){ |
|
// |
|
|
if ( !file ) throw -12; |
|
| 687 |
// |
// |
| 688 |
// check connection |
// check connection |
| 689 |
// |
// |
| 690 |
if( !conn ) throw -1; |
if( !conn ) throw -1; |
| 691 |
bool connect = conn->IsConnected(); |
bool connect = conn->IsConnected(); |
| 692 |
if( !connect ) throw -1; |
if( !connect ) throw -1; |
| 693 |
}; |
}; |
| 694 |
|
|
| 695 |
/** |
/** |
| 950 |
// |
// |
| 951 |
TYPE = 55;//224; |
TYPE = 55;//224; |
| 952 |
// |
// |
| 953 |
|
if ( IsDebug() ) printf("mcmd tsync %i tsync %u obt %u \n",i,TSYNC,OBT); |
| 954 |
|
// |
| 955 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
| 956 |
existsts = true; |
existsts = true; |
| 957 |
goto eout; |
goto eout; |
| 974 |
// |
// |
| 975 |
rt->SetBranchAddress("RunTrailer", &runt); |
rt->SetBranchAddress("RunTrailer", &runt); |
| 976 |
// |
// |
| 977 |
if ( rhev > 0 ){ |
Int_t nrhev = rh->GetEntries(); |
| 978 |
rh->GetEntry(0); |
Int_t nrtev = rt->GetEntries(); |
| 979 |
// |
if ( IsDebug() ) printf(" ou nevent %i rhev %i rtev %i \n",nevent,nrhev,nrtev); |
| 980 |
TSYNC = runh->LAST_TIME_SYNC_INFO; |
// |
| 981 |
OBT = runh->OBT_TIME_SYNC * 1000; |
if ( nrhev > 0 ){ |
| 982 |
// |
for (Int_t i=0; i<nrhev; i++){ |
| 983 |
TYPE = 20; |
// |
| 984 |
// |
rh->GetEntry(i); |
| 985 |
if ( TSYNC && OBT ){ |
// |
| 986 |
existsts = true; |
TSYNC = runh->LAST_TIME_SYNC_INFO; |
| 987 |
goto eout; |
OBT = runh->OBT_TIME_SYNC * 1000; |
| 988 |
|
// |
| 989 |
|
TYPE = 20; |
| 990 |
|
// |
| 991 |
|
if ( IsDebug() ) printf("runheader %i tsync %u obt %u \n",i,TSYNC,OBT); |
| 992 |
|
// |
| 993 |
|
if ( TSYNC && OBT ){ |
| 994 |
|
existsts = true; |
| 995 |
|
goto eout; |
| 996 |
|
}; |
| 997 |
}; |
}; |
| 998 |
// |
// |
| 999 |
}; |
}; |
| 1000 |
if ( rtev > 0 ){ |
if ( nrtev > 0 ){ |
| 1001 |
// |
// |
| 1002 |
if ( IsDebug() ) printf(" No runheader \n"); |
if ( IsDebug() ) printf(" No runheader \n"); |
| 1003 |
signal = 6; |
signal = 6; |
| 1004 |
// |
// |
| 1005 |
rt->GetEntry(0); |
for (Int_t i=0; i<nrtev; i++){ |
| 1006 |
// |
// |
| 1007 |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
rt->GetEntry(i); |
| 1008 |
OBT = runt->OBT_TYME_SYNC * 1000; |
// |
| 1009 |
// |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
| 1010 |
TYPE = 21; |
OBT = runt->OBT_TYME_SYNC * 1000; |
| 1011 |
// |
// |
| 1012 |
if ( TSYNC && OBT ){ |
TYPE = 21; |
| 1013 |
existsts = true; |
// |
| 1014 |
goto eout; |
if ( IsDebug() ) printf("runtrailer %i tsync %u obt %u \n",i,TSYNC,OBT); |
| 1015 |
|
// |
| 1016 |
|
if ( TSYNC && OBT ){ |
| 1017 |
|
existsts = true; |
| 1018 |
|
goto eout; |
| 1019 |
|
}; |
| 1020 |
}; |
}; |
| 1021 |
// |
// |
| 1022 |
} else { |
} else { |
| 3226 |
TSQLRow *row2 = 0; |
TSQLRow *row2 = 0; |
| 3227 |
// |
// |
| 3228 |
UInt_t moved = 0; |
UInt_t moved = 0; |
| 3229 |
UInt_t timelim = 0; |
// UInt_t timelim = 0; |
| 3230 |
TDatime *time = new TDatime(); |
// TDatime *time = new TDatime(); |
| 3231 |
// |
// |
| 3232 |
stringstream oss; |
stringstream oss; |
| 3233 |
oss.str(""); |
oss.str(""); |
| 3234 |
// |
// |
| 3235 |
// |
// |
|
// |
|
|
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); |
|
|
// |
|
| 3236 |
// check if there are entries older than "olderthan" seconds from now |
// check if there are entries older than "olderthan" seconds from now |
| 3237 |
// |
// |
| 3238 |
oss.str(""); |
oss.str(""); |
| 3239 |
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
| 3240 |
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
<< " INSERT_TIME <= '" << clean_time->AsSQLString() << "';"; |
| 3241 |
// |
// |
| 3242 |
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()); |
| 3243 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 3244 |
// |
// |
| 3245 |
if ( result ){ |
if ( result ){ |
| 3246 |
// |
// |
| 3247 |
row = result->Next(); |
row = result->Next(); |
| 3248 |
// |
// |
| 3249 |
if ( row ){ |
while ( row ){ |
| 3250 |
// |
// |
| 3251 |
oss.str(""); |
oss.str(""); |
| 3252 |
oss << " ID= "<< row->GetField(0); |
oss << " ID= "<< row->GetField(0); |
| 3323 |
// |
// |
| 3324 |
if ( !result2 ) throw -4; |
if ( !result2 ) throw -4; |
| 3325 |
// |
// |
| 3326 |
|
row = result->Next(); |
| 3327 |
}; |
}; |
| 3328 |
}; |
}; |
| 3329 |
if ( IsDebug() ) printf(" Moved %u runs\n",moved); |
if ( IsDebug() ) printf(" Moved %u runs\n",moved); |
| 3338 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
| 3339 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
| 3340 |
// |
// |
|
UInt_t timelim = 0; |
|
|
TDatime *time = new TDatime(); |
|
|
// |
|
| 3341 |
stringstream oss; |
stringstream oss; |
| 3342 |
oss.str(""); |
oss.str(""); |
| 3343 |
// |
// |
|
// |
|
|
// |
|
|
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()); |
|
|
|
|
| 3344 |
// ======================================================= |
// ======================================================= |
| 3345 |
// validate runs by checking missing calibrations |
// validate runs by checking missing calibrations |
| 3346 |
// ======================================================= |
// ======================================================= |
| 3350 |
// 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 |
| 3351 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
| 3352 |
oss.str(""); |
oss.str(""); |
| 3353 |
oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << time->AsSQLString() |
oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << clean_time->AsSQLString() |
| 3354 |
<< "' ORDER BY INSERT_TIME DESC LIMIT 1;"; |
<< "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
| 3355 |
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()); |
| 3356 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 3357 |
if ( !result ) throw -4; |
if ( !result ) throw -4; |
| 3358 |
if ( !result->GetRowCount() ) { |
if ( !result->GetRowCount() ) { |
| 3361 |
}else{ |
}else{ |
| 3362 |
row = result->Next(); |
row = result->Next(); |
| 3363 |
t_start = (UInt_t)atoll(row->GetField(4)); |
t_start = (UInt_t)atoll(row->GetField(4)); |
|
printf("t_start %i\n",t_start); |
|
| 3364 |
}; |
}; |
| 3365 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
| 3366 |
// 2) get the OBT of the last validated run |
// 2) get the OBT of the last validated run |
| 3368 |
oss.str(""); |
oss.str(""); |
| 3369 |
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 |
| 3370 |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
| 3371 |
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()); |
| 3372 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 3373 |
if ( !result ) throw -4; |
if ( !result ) throw -4; |
| 3374 |
if ( result->GetRowCount() ){ |
if ( result->GetRowCount() ){ |
| 3375 |
row = result->Next(); |
row = result->Next(); |
| 3376 |
t_stop = (UInt_t)atoll(row->GetField(4)); |
t_stop = (UInt_t)atoll(row->GetField(4)); |
| 3377 |
}; |
}; |
| 3378 |
printf("t_stop %i\n",t_stop); |
if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start); |
| 3379 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
| 3380 |
// now retrieves runs to be validated |
// now retrieves runs to be validated |
| 3381 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
| 3384 |
oss << " AND RUNHEADER_TIME >="<< t_stop; |
oss << " AND RUNHEADER_TIME >="<< t_stop; |
| 3385 |
oss << " ORDER BY RUNHEADER_TIME DESC;"; |
oss << " ORDER BY RUNHEADER_TIME DESC;"; |
| 3386 |
// if ( IsDebug() ) |
// if ( IsDebug() ) |
| 3387 |
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()); |
| 3388 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 3389 |
if ( !result ) throw -4; |
if ( !result ) throw -4; |
| 3390 |
if ( !result->GetRowCount() ) printf(" No runs to validate \n"); |
if ( !result->GetRowCount() ) printf(" No runs to validate \n"); |
| 3391 |
printf("------------------------------------------------------------------------------- \n"); |
// printf("------------------------------------------------------------------------------- \n"); |
| 3392 |
|
|
| 3393 |
Int_t nrow = 0; |
Int_t nrow = 0; |
| 3394 |
GL_RUN* this_run = new GL_RUN(); |
GL_RUN* this_run = new GL_RUN(); |
| 3395 |
GL_RUN* next_run = new GL_RUN(); |
GL_RUN* next_run = new GL_RUN(); |
| 3396 |
Int_t nseq_max = 100; |
Int_t nseq_max = 1000; |
| 3397 |
// UInt_t* sequence = new UInt_t[100]; |
// UInt_t* sequence = new UInt_t[100]; |
| 3398 |
vector<UInt_t> sequence(nseq_max); |
vector<UInt_t> sequence(nseq_max); |
| 3399 |
Int_t nseq = 0; |
Int_t nseq = 0; |
| 3416 |
//get run info |
//get run info |
| 3417 |
//------------ |
//------------ |
| 3418 |
this_run->Set_GL_RUN(row); |
this_run->Set_GL_RUN(row); |
| 3419 |
|
|
|
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); |
|
|
|
|
| 3420 |
Bool_t this_BAD = false; |
Bool_t this_BAD = false; |
| 3421 |
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; |
| 3422 |
else if (this_run->GetTRK_CALIB_USED() == 104) this_ONLINE = false; |
else if (this_run->GetTRK_CALIB_USED() == 104) this_ONLINE = false; |
| 3423 |
else{ |
else{ |
| 3424 |
printf("Missing or corrupted header!! \n"); |
// printf("Missing or corrupted header!! \n"); |
| 3425 |
this_ONLINE = false; |
this_ONLINE = false; |
| 3426 |
this_BAD = true; |
this_BAD = true; |
| 3427 |
}; |
}; |
| 3445 |
|
|
| 3446 |
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 |
| 3447 |
|
|
|
/* 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());*/ |
|
|
|
|
|
|
|
| 3448 |
if( !CHECK && this_run->VALIDATION ){ |
if( !CHECK && this_run->VALIDATION ){ |
| 3449 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
| 3450 |
nseq=0; |
nseq=0; |
| 3453 |
}else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE |
}else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE |
| 3454 |
|
|
| 3455 |
CHECK = true; |
CHECK = true; |
|
// if( interval < 60 ) printf(" ValidateRuns ***WARNING*** : kkkkkk DT = %i \n",interval); |
|
| 3456 |
|
|
| 3457 |
}else if( !next_ONLINE ){ // this:ANY + next:DEFAULT |
}else if( !next_ONLINE ){ // this:ANY + next:DEFAULT |
| 3458 |
|
|
| 3466 |
//---------------------------- |
//---------------------------- |
| 3467 |
if( CHECK ){ |
if( CHECK ){ |
| 3468 |
// check if calibration exists |
// check if calibration exists |
| 3469 |
printf("DT %i ===> CHECK Missing calibration\n",interval); |
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
| 3470 |
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
| 3471 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
| 3472 |
nseq=0; |
nseq=0; |
| 3473 |
} else printf("DT %i\n",interval); |
}; |
| 3474 |
//-------------- |
//-------------- |
| 3475 |
//store run info |
//store run info |
| 3476 |
//-------------- |
//-------------- |
| 3483 |
}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); |
| 3484 |
}; |
}; |
| 3485 |
|
|
| 3486 |
|
if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID); |
| 3487 |
nrow++; |
nrow++; |
| 3488 |
|
|
| 3489 |
}; |
}; |
| 3512 |
// which should be equal to the time between ascending-nodes. |
// which should be equal to the time between ascending-nodes. |
| 3513 |
//============================================================== |
//============================================================== |
| 3514 |
if ( t2 - trkcalib->FROM_TIME > 5700) { |
if ( t2 - trkcalib->FROM_TIME > 5700) { |
| 3515 |
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); |
| 3516 |
//============================================================== |
//============================================================== |
| 3517 |
// there might be a missing calibration, due to: |
// there might be a missing calibration, due to: |
| 3518 |
// - MM full |
// - MM full |
| 3533 |
// it is enough to say that there are no missing calibrations |
// it is enough to say that there are no missing calibrations |
| 3534 |
//============================================================== |
//============================================================== |
| 3535 |
// the long time interval bewteen runs might be due to download |
// the long time interval bewteen runs might be due to download |
| 3536 |
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); |
| 3537 |
return(false); |
return(false); |
| 3538 |
|
|
| 3539 |
}; |
}; |
| 3546 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
| 3547 |
stringstream oss; |
stringstream oss; |
| 3548 |
oss.str(""); |
oss.str(""); |
| 3549 |
oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << "';"; |
oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";"; |
| 3550 |
// |
// |
| 3551 |
// if ( IsDebug() ) |
// if ( IsDebug() ) |
| 3552 |
printf(" Set VALIDATION = %i for run %i \n",validation,idrun); |
// printf(" Set VALIDATION = %i for run %i \n",validation,idrun); |
| 3553 |
// 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()); |
| 3554 |
// result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 3555 |
// if ( !result ) throw -4; |
if ( !result ) throw -4; |
| 3556 |
return(0); |
return(0); |
| 3557 |
} |
} |
| 3558 |
|
|
| 3559 |
|
|
| 3560 |
|
|
| 3561 |
|
// Insert TLEs from file tlefilename in the table GL_TLE in the db |
| 3562 |
|
// opened by conn, sorting them by date from older to newer, if each |
| 3563 |
|
// TLE has not been alread inserted. |
| 3564 |
|
Int_t PamelaDBOperations::populateTLE()//(TSQLServer *conn, char *tleFile) |
| 3565 |
|
{ |
| 3566 |
|
fstream tlefile(tlefilename, ios::in); |
| 3567 |
|
|
| 3568 |
|
if ( !tlefile ) throw -7; |
| 3569 |
|
|
| 3570 |
|
vector<cTle*> ctles; |
| 3571 |
|
vector<cTle*>::iterator iter; |
| 3572 |
|
int present = 0; |
| 3573 |
|
|
| 3574 |
|
// Get three lines from tlefile, create a cTle object and put it |
| 3575 |
|
// into ctles |
| 3576 |
|
while(1) { |
| 3577 |
|
cTle *tlef; |
| 3578 |
|
string str1, str2, str3; |
| 3579 |
|
|
| 3580 |
|
getline(tlefile, str1); |
| 3581 |
|
if(tlefile.eof()) break; |
| 3582 |
|
|
| 3583 |
|
getline(tlefile, str2); |
| 3584 |
|
if(tlefile.eof()) break; |
| 3585 |
|
|
| 3586 |
|
getline(tlefile, str3); |
| 3587 |
|
if(tlefile.eof()) break; |
| 3588 |
|
|
| 3589 |
|
// We now have three good lines for a cTle. |
| 3590 |
|
tlef = new cTle(str1, str2, str3); |
| 3591 |
|
ctles.push_back(tlef); |
| 3592 |
|
} |
| 3593 |
|
|
| 3594 |
|
tlefile.close(); |
| 3595 |
|
|
| 3596 |
|
// Sort by date |
| 3597 |
|
sort(ctles.begin(), ctles.end(), compTLE); |
| 3598 |
|
|
| 3599 |
|
// Now we insert each TLE into the db |
| 3600 |
|
for(iter = ctles.begin(); iter != ctles.end(); iter++) { |
| 3601 |
|
cTle *tle = *iter; |
| 3602 |
|
|
| 3603 |
|
// Do nothing if it's already present in the db. Just increase |
| 3604 |
|
// the counter present. |
| 3605 |
|
if (! isTlePresent(tle)) |
| 3606 |
|
{ |
| 3607 |
|
int status = insertTle(tle); |
| 3608 |
|
|
| 3609 |
|
// Insert query failed. Return 1. |
| 3610 |
|
if(status == EXIT_FAILURE) { |
| 3611 |
|
|
| 3612 |
|
if( IsDebug() ) { |
| 3613 |
|
cerr << "Error: inserting TLE:" << endl |
| 3614 |
|
<< tle->getName() << endl |
| 3615 |
|
<< tle->getLine1() << endl |
| 3616 |
|
<< tle->getLine2() << endl; |
| 3617 |
|
} |
| 3618 |
|
|
| 3619 |
|
throw -4; |
| 3620 |
|
return 1; |
| 3621 |
|
} |
| 3622 |
|
|
| 3623 |
|
} |
| 3624 |
|
else |
| 3625 |
|
present++; |
| 3626 |
|
|
| 3627 |
|
} |
| 3628 |
|
|
| 3629 |
|
int inserted = ctles.size() - present; // Number of inserted TLE. |
| 3630 |
|
if ( IsDebug() ) |
| 3631 |
|
cout << "\nProcessed TLEs ranging from " << getTleDatetime(ctles[0]) << " to " << getTleDatetime(ctles[ctles.size()-1]) << "." << endl |
| 3632 |
|
<< inserted << " newly inserted TLEs out of " << ctles.size() << " processed." << endl; |
| 3633 |
|
|
| 3634 |
|
ctles.clear(); |
| 3635 |
|
|
| 3636 |
|
|
| 3637 |
|
// Return 2 if no new TLE has been inserted. 0 otherwise. |
| 3638 |
|
if(! inserted ) return 2; |
| 3639 |
|
return 0; |
| 3640 |
|
} |
| 3641 |
|
|
| 3642 |
|
|
| 3643 |
|
// Insert tle in the table GL_TLE using the connection conn. |
| 3644 |
|
int PamelaDBOperations::insertTle(cTle *tle) |
| 3645 |
|
{ |
| 3646 |
|
stringstream oss; |
| 3647 |
|
TSQLResult *result = 0; |
| 3648 |
|
|
| 3649 |
|
oss.str(""); |
| 3650 |
|
oss << " INSERT INTO GL_TLE (TLE1, TLE2, TLE3, FROM_TIME)" |
| 3651 |
|
<< " VALUES ( '" |
| 3652 |
|
<< tle->getName() << "', '" |
| 3653 |
|
<< tle->getLine1() << "', '" |
| 3654 |
|
<< tle->getLine2() << "', '" |
| 3655 |
|
<< getTleDatetime(tle) << "')"; |
| 3656 |
|
|
| 3657 |
|
// cout << oss.str().c_str() << endl; |
| 3658 |
|
result = conn->Query(oss.str().c_str()); |
| 3659 |
|
if (result == NULL) |
| 3660 |
|
return EXIT_FAILURE; |
| 3661 |
|
|
| 3662 |
|
return EXIT_SUCCESS; |
| 3663 |
|
} |
| 3664 |
|
|
| 3665 |
|
|
| 3666 |
|
// Return whether tle is already in the db connected by conn. |
| 3667 |
|
bool PamelaDBOperations::isTlePresent(cTle *tle) |
| 3668 |
|
{ |
| 3669 |
|
stringstream oss; |
| 3670 |
|
TSQLResult *result = 0; |
| 3671 |
|
|
| 3672 |
|
oss.str(""); |
| 3673 |
|
oss << "SELECT * FROM GL_TLE WHERE FROM_TIME = '" |
| 3674 |
|
<< getTleDatetime(tle) << "'"; |
| 3675 |
|
|
| 3676 |
|
result = conn->Query(oss.str().c_str()); |
| 3677 |
|
if (result == NULL) throw -4; |
| 3678 |
|
|
| 3679 |
|
if (result->GetRowCount()) |
| 3680 |
|
return true; |
| 3681 |
|
else |
| 3682 |
|
return false; |
| 3683 |
|
} |
| 3684 |
|
|
| 3685 |
|
|
| 3686 |
|
// Return whether the first TLE is dated early than the second |
| 3687 |
|
bool compTLE (cTle *tle1, cTle *tle2) |
| 3688 |
|
{ |
| 3689 |
|
return getTleJulian(tle1) < getTleJulian(tle2); |
| 3690 |
|
} |
| 3691 |
|
|
| 3692 |
|
|
| 3693 |
|
// Return the date of the tle using the format (year-2000)*1e3 + |
| 3694 |
|
// julian day. e.g. 6365 is the 31th Dec 2006. |
| 3695 |
|
// It does *not* return a cJulian date. |
| 3696 |
|
float getTleJulian(cTle *tle) { |
| 3697 |
|
return tle->getField(cTle::FLD_EPOCHYEAR)*1e3 + tle->getField(cTle::FLD_EPOCHDAY); |
| 3698 |
|
} |
| 3699 |
|
|
| 3700 |
|
|
| 3701 |
|
// Return a string like YYYY-MM-DD hh:mm:ss, usable for mysql datetime |
| 3702 |
|
// format. |
| 3703 |
|
string getTleDatetime(cTle *tle) |
| 3704 |
|
{ |
| 3705 |
|
int year, mon, day, hh, mm, ss; |
| 3706 |
|
double dom; // day of month (is double!) |
| 3707 |
|
stringstream date; // date in datetime format |
| 3708 |
|
|
| 3709 |
|
// create a cJulian from the date in tle |
| 3710 |
|
cJulian jdate = cJulian( 2000 + (int) tle->getField(cTle::FLD_EPOCHYEAR), tle->getField(cTle::FLD_EPOCHDAY)); |
| 3711 |
|
|
| 3712 |
|
// get year, month, day of month |
| 3713 |
|
jdate.getComponent(&year, &mon, &dom); |
| 3714 |
|
|
| 3715 |
|
// build a datetime YYYY-MM-DD hh:mm:ss |
| 3716 |
|
date.str(""); |
| 3717 |
|
day = (int) floor(dom); |
| 3718 |
|
hh = (int) floor( (dom - day) * 24); |
| 3719 |
|
mm = (int) floor( ((dom - day) * 24 - hh) * 60); |
| 3720 |
|
ss = (int) floor( ((((dom - day) * 24 - hh) * 60 - mm) * 60)); |
| 3721 |
|
// ms = (int) floor( (((((dom - day) * 24 - hh) * 60 - mm) * 60) - ss) * 1000); |
| 3722 |
|
|
| 3723 |
|
date << year << "-" << mon << "-" << day << " " << hh << ":" << mm << ":" << ss; |
| 3724 |
|
|
| 3725 |
|
return date.str(); |
| 3726 |
|
} |