154 |
obtfirst = 0; |
obtfirst = 0; |
155 |
pktfirst = 0; |
pktfirst = 0; |
156 |
toffset = 0; |
toffset = 0; |
157 |
ID = 0; |
// ID = 0; |
158 |
ID_RAW = 0; |
// ID_RAW = 0; |
159 |
OBT0 = 0; |
OBT0 = 0; |
160 |
TIMESYNC = 0; |
TIMESYNC = 0; |
161 |
TYPE = 0; |
TYPE = 0; |
1304 |
// |
// |
1305 |
// look for Resurs offset |
// look for Resurs offset |
1306 |
// |
// |
1307 |
UInt_t t0 = 0; |
T0 = 0; |
1308 |
// |
// |
1309 |
// |
// |
1310 |
stringstream oss; |
stringstream oss; |
1311 |
oss.str(""); |
oss.str(""); |
1312 |
oss << "SELECT 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) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
1313 |
<< rname.str().c_str() << "';"; |
<< rname.str().c_str() << "';"; |
|
// if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
|
1314 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1315 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1316 |
// |
// |
1331 |
}; |
}; |
1332 |
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
1333 |
}; |
}; |
|
// if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
|
1334 |
// |
// |
1335 |
if ( !Row ){ |
if ( !Row ){ |
1336 |
oss.str(""); |
oss.str(""); |
1337 |
oss << "SELECT 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) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
1338 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
|
// if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
|
1339 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1340 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1341 |
if ( !Row ){ |
if ( !Row ){ |
1344 |
}; |
}; |
1345 |
}; |
}; |
1346 |
// |
// |
1347 |
// |
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); |
1348 |
TDatime ti = TDatime(Row->GetField(0)); |
T0 = (UInt_t)tu.GetSec(); |
|
TTimeStamp tu = TTimeStamp((UInt_t)ti.GetYear(),(UInt_t)ti.GetMonth(),(UInt_t)ti.GetDay(),(UInt_t)ti.GetHour(),(UInt_t)ti.GetMinute(),(UInt_t)ti.GetSecond(),0,true,0); |
|
|
t0 = (UInt_t)tu.GetSec(); |
|
1349 |
// |
// |
1350 |
// look for the correct timesync entry |
// look for the correct timesync entry |
1351 |
// |
// |
1352 |
myquery.str(""); |
myquery.str(""); |
1353 |
myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC " |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
1354 |
<< " WHERE ID_RAW = " << idraw |
<< " WHERE ID_RAW = " << idraw |
1355 |
<< ";"; |
<< ";"; |
1356 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1357 |
if ( pResult ){ |
if ( pResult ){ |
1358 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1359 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
1360 |
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + t0; |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
1361 |
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1362 |
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
1363 |
|
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
1364 |
}; |
}; |
1365 |
}; |
}; |
1366 |
// |
// |
1379 |
// |
// |
1380 |
}; |
}; |
1381 |
|
|
1382 |
|
/** |
1383 |
|
* |
1384 |
|
* Returns the Resurs time given the OBT needed to process inclination and orbital infos |
1385 |
|
* |
1386 |
|
*/ |
1387 |
|
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
1388 |
|
// |
1389 |
|
return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC)); |
1390 |
|
// |
1391 |
|
}; |
1392 |
|
|
1393 |
ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
|
1394 |
|
/** |
1395 |
|
* Return the correct packet number if we went back to zero |
1396 |
|
*/ |
1397 |
|
Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1398 |
// |
// |
1399 |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ){ |
1400 |
|
return((Long64_t)pkt_num+16777215LL); |
1401 |
|
}; |
1402 |
// |
// |
1403 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1404 |
if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
return((Long64_t)pkt_num-16777215LL); |
|
return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
|
|
} else { |
|
|
return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
|
|
}; |
|
1405 |
}; |
}; |
1406 |
// |
// |
1407 |
return((ULong64_t)obt); |
return((Long64_t)pkt_num); |
1408 |
// |
// |
1409 |
}; |
}; |
1410 |
|
|
1411 |
UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
/** |
1412 |
|
* Return the correct On Board Time if we went back to zero |
1413 |
|
*/ |
1414 |
|
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1415 |
// |
// |
1416 |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((Long64_t)(obt+numeric_limits<UInt_t>::max())); |
1417 |
// |
// |
1418 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1419 |
if ( (pkt_num-16777215) < 0 ){ |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
|
return((16777215-pkt_num)); |
|
|
} else { |
|
|
return((pkt_num-16777215)); |
|
|
}; |
|
1420 |
}; |
}; |
1421 |
// |
// |
1422 |
return(pkt_num); |
return((Long64_t)obt); |
|
// |
|
1423 |
}; |
}; |
1424 |
|
|
1425 |
|
|
1426 |
|
|
1427 |
|
// ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1428 |
|
// // |
1429 |
|
// if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
1430 |
|
// // |
1431 |
|
// if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1432 |
|
// if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
1433 |
|
// return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
1434 |
|
// } else { |
1435 |
|
// return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
1436 |
|
// }; |
1437 |
|
// }; |
1438 |
|
// // |
1439 |
|
// return((ULong64_t)obt); |
1440 |
|
// // |
1441 |
|
// }; |
1442 |
|
|
1443 |
|
// UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1444 |
|
// // |
1445 |
|
// if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
1446 |
|
// // |
1447 |
|
// if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1448 |
|
// if ( (pkt_num-16777215) < 0 ){ |
1449 |
|
// return((16777215-pkt_num)); |
1450 |
|
// } else { |
1451 |
|
// return((pkt_num-16777215)); |
1452 |
|
// }; |
1453 |
|
// }; |
1454 |
|
// // |
1455 |
|
// return(pkt_num); |
1456 |
|
// // |
1457 |
|
// }; |
1458 |
|
|
1459 |
/* |
/* |
1460 |
* |
* |
1461 |
* Convert the time in the DB from UInt_t to a string |
* Convert the time in the DB from UInt_t to a string |