56 |
* @param debug debug flag. |
* @param debug debug flag. |
57 |
* @param tlefilename ascii file with TLE 3 line elements. |
* @param tlefilename ascii file with TLE 3 line elements. |
58 |
*/ |
*/ |
59 |
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, UInt_t dwinput, Bool_t staticp){ |
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, UInt_t dwinput, Bool_t staticp, Bool_t gpamela){ |
60 |
// |
// |
61 |
STATIC=false; |
STATIC=false; |
62 |
if ( staticp ) STATIC=true; |
if ( staticp ) STATIC=true; |
68 |
glrun = new GL_RUN(); |
glrun = new GL_RUN(); |
69 |
// |
// |
70 |
if ( !boot ) SetNOBOOT(false); |
if ( !boot ) SetNOBOOT(false); |
71 |
SetBOOTnumber(boot); |
SetTsync(tsync,gpamela); |
72 |
SetTsync(tsync); |
SetBOOTnumber(boot,gpamela); |
73 |
SetObt0(obt0); |
SetObt0(obt0); |
74 |
// |
// |
75 |
SetTLEPath(tlefilename); |
SetTLEPath(tlefilename); |
179 |
* @param boot BOOT number of the RAW file |
* @param boot BOOT number of the RAW file |
180 |
*/ |
*/ |
181 |
void PamelaDBOperations::SetBOOTnumber(UInt_t boot){ |
void PamelaDBOperations::SetBOOTnumber(UInt_t boot){ |
182 |
|
this->SetBOOTnumber(boot,false); |
183 |
|
}; |
184 |
|
|
185 |
|
/** |
186 |
|
* Store the BOOT number of the RAW file. |
187 |
|
* @param boot BOOT number of the RAW file |
188 |
|
*/ |
189 |
|
void PamelaDBOperations::SetBOOTnumber(UInt_t boot, Bool_t gpamela){ |
190 |
BOOTNO=boot; |
BOOTNO=boot; |
191 |
|
if ( gpamela ){ |
192 |
|
stringstream oss; |
193 |
|
TSQLResult *result = 0; |
194 |
|
TSQLRow *row = 0; |
195 |
|
if ( !boot ){ |
196 |
|
// |
197 |
|
BOOTNO = 1; |
198 |
|
// |
199 |
|
// look in the DB for the last timesync and the last run |
200 |
|
// |
201 |
|
oss.str(""); |
202 |
|
oss << "SELECT BOOT_NUMBER FROM GL_RUN order by RUNHEADER_TIME desc limit 1;"; |
203 |
|
result = conn->Query(oss.str().c_str()); |
204 |
|
if ( result ){ |
205 |
|
row = result->Next(); |
206 |
|
if ( row ){ |
207 |
|
BOOTNO = (UInt_t)atoll(row->GetField(0)) + 1; |
208 |
|
}; |
209 |
|
}; |
210 |
|
}; |
211 |
|
}; |
212 |
}; |
}; |
213 |
|
|
214 |
/** |
/** |
216 |
* @param boot time sync |
* @param boot time sync |
217 |
*/ |
*/ |
218 |
void PamelaDBOperations::SetTsync(UInt_t ts){ |
void PamelaDBOperations::SetTsync(UInt_t ts){ |
219 |
|
this->SetTsync(ts,false); |
220 |
|
}; |
221 |
|
|
222 |
|
/** |
223 |
|
* Store the time sync of the RAW file. |
224 |
|
* @param boot time sync |
225 |
|
*/ |
226 |
|
void PamelaDBOperations::SetTsync(UInt_t ts, Bool_t gpamela){ |
227 |
|
// |
228 |
|
// if not gpamela or given tsync file set ts |
229 |
|
// |
230 |
tsync=ts; |
tsync=ts; |
231 |
|
if ( gpamela ){ |
232 |
|
stringstream oss; |
233 |
|
TSQLResult *result = 0; |
234 |
|
TSQLRow *row = 0; |
235 |
|
TSQLResult *result2 = 0; |
236 |
|
TSQLRow *row2 = 0; |
237 |
|
if ( !ts ){ |
238 |
|
// |
239 |
|
tsync = 1; |
240 |
|
// |
241 |
|
// look in the DB for the last timesync and the last run |
242 |
|
// |
243 |
|
oss.str(""); |
244 |
|
oss << "SELECT TIMESYNC FROM GL_TIMESYNC order by TIMESYNC desc limit 1;"; |
245 |
|
result = conn->Query(oss.str().c_str()); |
246 |
|
if ( result ){ |
247 |
|
row = result->Next(); |
248 |
|
if ( row ){ |
249 |
|
tsync = (UInt_t)atoll(row->GetField(0)) + 1; |
250 |
|
oss.str(""); |
251 |
|
oss << "SELECT (RUNTRAILER_TIME-RUNHEADER_TIME) FROM GL_RUN order by RUNHEADER_TIME desc limit 1;"; |
252 |
|
result2 = conn->Query(oss.str().c_str()); |
253 |
|
if ( result2 ){ |
254 |
|
row2 = result2->Next(); |
255 |
|
if ( row2 ){ |
256 |
|
tsync += (UInt_t)atoll(row2->GetField(0)); |
257 |
|
}; |
258 |
|
} |
259 |
|
}; |
260 |
|
}; |
261 |
|
}; |
262 |
|
}; |
263 |
}; |
}; |
264 |
|
|
265 |
/** |
/** |
1108 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
1109 |
UInt_t t0 = 0; |
UInt_t t0 = 0; |
1110 |
Int_t signal = 0; |
Int_t signal = 0; |
1111 |
|
UInt_t idresof = 0; |
1112 |
// |
// |
1113 |
signal = this->SetUpperLimits(); |
signal = this->SetUpperLimits(); |
1114 |
// |
// |
1117 |
if ( this->GetID_RAW() == 0 ) throw -11; |
if ( this->GetID_RAW() == 0 ) throw -11; |
1118 |
// |
// |
1119 |
oss.str(""); |
oss.str(""); |
1120 |
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='" |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
1121 |
<< this->GetRawFile().Data() << "';"; |
<< this->GetRawFile().Data() << "';"; |
1122 |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
1123 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1126 |
// |
// |
1127 |
if ( !row ){ |
if ( !row ){ |
1128 |
oss.str(""); |
oss.str(""); |
1129 |
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< " |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
1130 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
1131 |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
1132 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1135 |
if ( !row ) throw -10; |
if ( !row ) throw -10; |
1136 |
}; |
}; |
1137 |
// |
// |
1138 |
|
idresof = (UInt_t)atoll(row->GetField(6)); |
1139 |
|
// |
1140 |
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); |
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); |
1141 |
t0 = (UInt_t)tu.GetSec(); |
t0 = (UInt_t)tu.GetSec(); |
1142 |
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)); |
if ( IsDebug() ) printf(" t0 is %u ti is %s %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),row->GetField(6)); |
1143 |
// |
// |
1144 |
/* |
/* |
1145 |
* Verify that the TIMESYNC have been not already processed |
* Verify that the TIMESYNC have been not already processed |
1345 |
if ( !existsts ) throw -3; |
if ( !existsts ) throw -3; |
1346 |
// |
// |
1347 |
oss.str(""); |
oss.str(""); |
1348 |
oss << "INSERT INTO GL_TIMESYNC (ID_RAW,TYPE,OBT0,TIMESYNC) VALUES ('" |
oss << "INSERT INTO GL_TIMESYNC (ID_RAW,TYPE,OBT0,TIMESYNC,ID_RESURS_OFFSET) VALUES ('" |
1349 |
<< this->GetID_RAW() << "','"//224'" |
<< this->GetID_RAW() << "','"//224'" |
1350 |
<< dec << (UInt_t)TYPE << "','" |
<< dec << (UInt_t)TYPE << "','" |
1351 |
<< dec << (UInt_t)OBT << "','" |
<< dec << (UInt_t)OBT << "','" |
1352 |
<< dec << (UInt_t)TSYNC << "');"; |
<< dec << (UInt_t)TSYNC << "','" |
1353 |
|
<< dec << (UInt_t)idresof << "');"; |
1354 |
conn->Query(oss.str().c_str()); |
conn->Query(oss.str().c_str()); |
1355 |
if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to fill it:\n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to fill it:\n %s \n",oss.str().c_str()); |
1356 |
|
if ( conn->GetErrorCode() ){ |
1357 |
|
printf(" OK, you got an error because the database structure you are using is not up to date\n Using backward compability code, hence you can continue safetly \n"); |
1358 |
|
oss.str(""); |
1359 |
|
oss << "INSERT INTO GL_TIMESYNC (ID_RAW,TYPE,OBT0,TIMESYNC) VALUES ('" |
1360 |
|
<< this->GetID_RAW() << "','"//224'" |
1361 |
|
<< dec << (UInt_t)TYPE << "','" |
1362 |
|
<< dec << (UInt_t)OBT << "','" |
1363 |
|
<< dec << (UInt_t)TSYNC << "');"; |
1364 |
|
conn->Query(oss.str().c_str()); |
1365 |
|
if ( IsDebug() ) printf(" Query the GL_TIMESYNC table to fill it:\n %s \n",oss.str().c_str()); |
1366 |
|
}; |
1367 |
// |
// |
1368 |
if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0); |
if ( IsDebug() ) printf(" found a timesync t0 is %u \n",t0); |
1369 |
|
// |
1370 |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
1371 |
// |
// |
1372 |
tsync = TSYNC; |
tsync = TSYNC; |
1830 |
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
1831 |
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") OR " |
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") OR " |
1832 |
<< " (RUNHEADER_TIME=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " // these two lines in a certain way disable the patch below... |
<< " (RUNHEADER_TIME=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " // these two lines in a certain way disable the patch below... |
1833 |
<< " RUNTRAILER_TIME=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100)" // |
<< " RUNTRAILER_TIME=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100) OR" // |
1834 |
<< " (RUNHEADER_TIME=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " // |
<< " (RUNHEADER_TIME=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " // |
1835 |
<< " RUNTRAILER_TIME>" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100)" // |
<< " RUNTRAILER_TIME>" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100) OR" // |
1836 |
<< " (RUNHEADER_TIME<" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " // |
<< " (RUNHEADER_TIME<" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " // |
1837 |
<< " RUNTRAILER_TIME=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100)" // |
<< " RUNTRAILER_TIME=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100)" // |
1838 |
<< " ));"; |
<< " ));"; |
4792 |
if ( !result ) throw -4;; |
if ( !result ) throw -4;; |
4793 |
// |
// |
4794 |
row = result->Next(); |
row = result->Next(); |
4795 |
|
UInt_t nid = 0; |
4796 |
// |
// |
4797 |
while ( row ){ |
while ( row ){ |
4798 |
|
nid++; |
4799 |
|
if ( !(nid%1000) && nid ) printf(" %iK run scanned \n",nid/1000); |
4800 |
thisid = (UInt_t)atoll(row->GetField(0)); |
thisid = (UInt_t)atoll(row->GetField(0)); |
4801 |
thisl0id = (UInt_t)atoll(row->GetField(1)); |
thisl0id = (UInt_t)atoll(row->GetField(1)); |
4802 |
thisrht = (UInt_t)atoll(row->GetField(2)); |
thisrht = (UInt_t)atoll(row->GetField(2)); |
4808 |
// |
// |
4809 |
oss.str(""); |
oss.str(""); |
4810 |
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
4811 |
<< thisid << " AND RUNHEADER_TIME=" |
<< thisid << " AND ( RUNHEADER_TIME=" |
4812 |
<< thisrht << " AND RUNTRAILER_TIME!=" |
<< thisrht << " OR RUNTRAILER_TIME=" |
4813 |
<< thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; |
<< thisrtt << " ) AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; |
4814 |
result3 = conn->Query(oss.str().c_str()); |
result3 = conn->Query(oss.str().c_str()); |
4815 |
if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); |
4816 |
if ( result3 ){ |
if ( result3 ){ |
|
row3 = result3->Next(); |
|
4817 |
// |
// |
4818 |
while ( row3 ){ |
oss.str(""); |
4819 |
// |
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
4820 |
// 2 runs with same runheader |
<< thisid << " AND RUNHEADER_TIME=" |
4821 |
// |
<< thisrht << " AND RUNTRAILER_TIME!=" |
4822 |
printf(" CHECK n.4 RUNs %u and %u HAVE SAME RUNHEADER \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
<< thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; |
4823 |
|
result3 = conn->Query(oss.str().c_str()); |
4824 |
|
if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); |
4825 |
|
if ( result3 ){ |
4826 |
row3 = result3->Next(); |
row3 = result3->Next(); |
4827 |
|
// |
4828 |
|
while ( row3 ){ |
4829 |
|
// |
4830 |
|
// 2 runs with same runheader |
4831 |
|
// |
4832 |
|
printf(" CHECK n.4 RUNs %u and %u HAVE SAME RUNHEADER \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
4833 |
|
row3 = result3->Next(); |
4834 |
|
}; |
4835 |
}; |
}; |
|
}; |
|
|
// |
|
|
oss.str(""); |
|
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
|
|
<< thisid << " AND RUNHEADER_TIME!=" |
|
|
<< thisrht << " AND RUNTRAILER_TIME=" |
|
|
<< thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; |
|
|
result3 = conn->Query(oss.str().c_str()); |
|
|
if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); |
|
|
if ( result3 ){ |
|
|
row3 = result3->Next(); |
|
4836 |
// |
// |
4837 |
while ( row3 ){ |
oss.str(""); |
4838 |
// |
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
4839 |
// 2 runs with same runtrailer |
<< thisid << " AND RUNHEADER_TIME!=" |
4840 |
|
<< thisrht << " AND RUNTRAILER_TIME=" |
4841 |
|
<< thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; |
4842 |
|
result3 = conn->Query(oss.str().c_str()); |
4843 |
|
if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); |
4844 |
|
if ( result3 ){ |
4845 |
|
row3 = result3->Next(); |
4846 |
// |
// |
4847 |
printf(" CHECK n.5 RUNs %u and %u HAVE SAME RUNTRAILER \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
while ( row3 ){ |
4848 |
|
// |
4849 |
|
// 2 runs with same runtrailer |
4850 |
|
// |
4851 |
|
printf(" CHECK n.5 RUNs %u and %u HAVE SAME RUNTRAILER \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
4852 |
|
row3 = result3->Next(); |
4853 |
|
}; |
4854 |
|
}; |
4855 |
|
// |
4856 |
|
oss.str(""); |
4857 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
4858 |
|
<< thisid << " AND RUNHEADER_TIME=" |
4859 |
|
<< thisrht << " AND RUNTRAILER_TIME=" |
4860 |
|
<< thisrtt << " AND ID_RUN_FRAG!=" |
4861 |
|
<< thisid << " order by RUNHEADER_TIME asc;"; |
4862 |
|
result3 = conn->Query(oss.str().c_str()); |
4863 |
|
if ( result3 ){ |
4864 |
row3 = result3->Next(); |
row3 = result3->Next(); |
4865 |
|
// |
4866 |
|
while ( row3 ){ |
4867 |
|
// |
4868 |
|
// duplicated run |
4869 |
|
// |
4870 |
|
printf(" CHECK n.7 RUNs %u and %u HAVE SAME RUNTRAILER AND RUNHEADER (ARE THE SAME?) \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
4871 |
|
row3 = result3->Next(); |
4872 |
|
}; |
4873 |
}; |
}; |
4874 |
}; |
}; |
4875 |
// |
// |
4891 |
}; |
}; |
4892 |
}; |
}; |
4893 |
// |
// |
|
oss.str(""); |
|
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
|
|
<< thisid << " AND RUNHEADER_TIME=" |
|
|
<< thisrht << " AND RUNTRAILER_TIME=" |
|
|
<< thisrtt << " AND ID_RUN_FRAG!=" |
|
|
<< thisid << " order by RUNHEADER_TIME asc;"; |
|
|
result3 = conn->Query(oss.str().c_str()); |
|
|
if ( result3 ){ |
|
|
row3 = result3->Next(); |
|
|
// |
|
|
while ( row3 ){ |
|
|
// |
|
|
// duplicated run |
|
|
// |
|
|
printf(" CHECK n.7 RUNs %u and %u HAVE SAME RUNTRAILER AND RUNHEADER (ARE THE SAME?) \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
|
|
row3 = result3->Next(); |
|
|
}; |
|
|
}; |
|
4894 |
}; |
}; |
4895 |
// |
// |
4896 |
// if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ |
// if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ |