218 |
NAME = ""; |
NAME = ""; |
219 |
} |
} |
220 |
|
|
221 |
|
GL_RAW::GL_RAW(){ |
222 |
|
ID = 0; |
223 |
|
PATH = ""; |
224 |
|
NAME = ""; |
225 |
|
BOOT_NUMBER = 0; |
226 |
|
} |
227 |
|
|
228 |
GL_PARAM::GL_PARAM(){ |
GL_PARAM::GL_PARAM(){ |
229 |
ID = 0; |
ID = 0; |
230 |
PATH = ""; |
PATH = ""; |
1316 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1317 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1318 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1319 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1320 |
// |
// |
1321 |
if( !pResult->GetRowCount() ) return(-54); |
if( !pResult->GetRowCount() ) return(-54); |
1322 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1354 |
// |
// |
1355 |
// if the selected calibration is too old (more than 5 orbits old) try to take the closest not corrupted one |
// if the selected calibration is too old (more than 5 orbits old) try to take the closest not corrupted one |
1356 |
// |
// |
1357 |
if ( (time-myfromtime)>28500 ){ |
if ( (time-myfromtime)>28500 && myfromtime > 0 ){ |
1358 |
// |
// |
1359 |
myquery.str(""); |
myquery.str(""); |
1360 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALO_CALIB where SECTION=" << section; |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALO_CALIB where SECTION=" << section; |
1546 |
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ |
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ |
1547 |
// MySQL variables |
// MySQL variables |
1548 |
TFile *file = 0; |
TFile *file = 0; |
1549 |
UInt_t idraw = 0; |
UInt_t idtsy = 0; |
1550 |
// |
// |
1551 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1552 |
TSQLRow *Row; |
TSQLRow *Row = 0; |
1553 |
stringstream myquery; |
stringstream myquery; |
1554 |
stringstream rname; |
stringstream rname; |
1555 |
// pcksList packetsNames; |
// pcksList packetsNames; |
1560 |
myquery.str(""); |
myquery.str(""); |
1561 |
myquery << "select "; |
myquery << "select "; |
1562 |
myquery << "PATH"; |
myquery << "PATH"; |
1563 |
myquery << ",NAME,ID_RAW"; |
myquery << ",NAME,ID_TIMESYNC"; |
1564 |
myquery << " from GL_ROOT where "; |
myquery << " from GL_ROOT where "; |
1565 |
myquery << type.Data(); |
myquery << type.Data(); |
1566 |
myquery << "=" << id << ";"; |
myquery << "=" << id << ";"; |
1576 |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
1577 |
rname << Row->GetField(1); |
rname << Row->GetField(1); |
1578 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
1579 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idtsy = (UInt_t)atoll(Row->GetField(2)); |
1580 |
}; |
}; |
1581 |
}; |
}; |
1582 |
// |
// |
1591 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
1592 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
1593 |
// |
// |
|
// code = eh->GetCounter(); |
|
|
// UInt_t en = 0; |
|
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
|
|
// en = code->Get(GetPacketType(*Iter)); |
|
|
// if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){ |
|
|
// // |
|
|
// TTree *TC = 0; |
|
|
// TC = (TTree*)file->Get("CalibCalPed"); |
|
|
// if ( !TC || TC->IsZombie() ) return; |
|
|
// EventHeader *ehc = 0; |
|
|
// PscuHeader *phc = 0; |
|
|
// TC->SetBranchAddress("Header", &ehc); |
|
|
// TC->GetEntry(0); |
|
|
// phc = ehc->GetPscuHeader(); |
|
|
// pktfirst = phc->GetCounter(); |
|
|
// obtfirst = phc->GetOrbitalTime(); |
|
|
// // |
|
|
// }; |
|
|
// }; |
|
|
// |
|
1594 |
}; |
}; |
1595 |
// |
// |
1596 |
// look for Resurs offset |
// look for Resurs offset |
1597 |
// |
// |
1598 |
T0 = 0; |
T0 = 0; |
1599 |
// |
// |
|
// |
|
1600 |
stringstream oss; |
stringstream oss; |
|
TString frn = rname.str().c_str(); |
|
|
frn = frn.ReplaceAll(".root",5,".pam",4); |
|
|
oss.str(""); |
|
|
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='" |
|
|
<< frn.Data() << "';"; |
|
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
|
|
this->GetGLTABLES()->AddQ(); |
|
|
pResult = dbc->Query(oss.str().c_str()); |
|
|
Row = pResult->Next(); |
|
1601 |
// |
// |
1602 |
TString name=rname.str().c_str(); |
TString name=rname.str().c_str(); |
1603 |
UInt_t dworbit = 0; |
UInt_t dworbit = 0; |
1604 |
Int_t nlength = name.Length(); |
// Int_t nlength = name.Length(); |
1605 |
|
delete pResult; |
1606 |
// |
// |
1607 |
// Is not a special file |
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
1608 |
// |
// |
1609 |
if ( !Row ){ |
oss.str(""); |
1610 |
delete pResult; |
oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; |
1611 |
// |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1612 |
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
this->GetGLTABLES()->AddQ(); |
1613 |
// |
pResult = dbc->Query(oss.str().c_str()); |
1614 |
oss.str(""); |
Bool_t fndit = false; |
1615 |
oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";"; |
if ( pResult ){ |
1616 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
Row = pResult->Next(); |
1617 |
this->GetGLTABLES()->AddQ(); |
if ( Row ){ |
|
pResult = dbc->Query(oss.str().c_str()); |
|
|
Bool_t fndit = false; |
|
|
if ( pResult ){ |
|
|
Row = pResult->Next(); |
|
|
if ( Row ){ |
|
|
oss.str(""); |
|
|
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 ID=" |
|
|
<< Row->GetField(0) << ";"; |
|
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
|
|
this->GetGLTABLES()->AddQ(); |
|
|
pResult = dbc->Query(oss.str().c_str()); |
|
|
if ( pResult ){ |
|
|
Row = pResult->Next(); |
|
|
if ( Row ){ |
|
|
// printf(" GREAT! the DB structure is the new one! \n"); |
|
|
fndit = true; |
|
|
dworbit = 1; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
if ( !fndit ){ |
|
|
delete pResult; |
|
|
// |
|
|
printf(" OK, you got an error because this is the old database\n Using backward compability code, hence you can continue safetly \n"); |
|
|
// |
|
|
// Old code, we must trust the filename |
|
1618 |
// |
// |
1619 |
if ( nlength < 5 ) return; |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
1620 |
TString dwo = 0; |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1621 |
for (Int_t i = 0; i<5; i++){ |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
|
dwo.Append(name[i],1); |
|
|
}; |
|
|
if ( dwo.IsDigit() ){ |
|
|
dworbit = (UInt_t)dwo.Atoi(); |
|
|
} else { |
|
|
dwo=""; |
|
|
for (Int_t i = 8; i<13; i++){ |
|
|
dwo.Append(name[i],1); |
|
|
}; |
|
|
if ( dwo.IsDigit() ){ |
|
|
dworbit = (UInt_t)dwo.Atoi(); |
|
|
} else { |
|
|
dworbit = 1; |
|
|
}; |
|
|
}; |
|
1622 |
// |
// |
1623 |
oss.str(""); |
oss.str(""); |
1624 |
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) FROM GL_RESURS_OFFSET WHERE ID=" |
1625 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< Row->GetField(3) << ";"; |
1626 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1627 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1628 |
|
delete pResult; |
1629 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1630 |
Row = pResult->Next(); |
if ( pResult ){ |
1631 |
if ( !Row ){ |
Row = pResult->Next(); |
1632 |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
if ( Row ){ |
1633 |
return; |
// printf(" GREAT! the DB structure is the new one! \n"); |
1634 |
|
fndit = true; |
1635 |
|
dworbit = 1; |
1636 |
|
}; |
1637 |
}; |
}; |
1638 |
}; |
}; |
1639 |
}; |
}; |
1640 |
|
if ( !fndit ){ |
1641 |
|
// |
1642 |
|
printf(" ERROR OLD DB! \n"); |
1643 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1644 |
|
// |
1645 |
|
}; |
1646 |
// |
// |
1647 |
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); |
1648 |
T0 = (UInt_t)tu.GetSec(); |
T0 = (UInt_t)tu.GetSec(); |
1649 |
// |
// |
1650 |
// look for the correct timesync entry |
toffset = TIMESYNC - (UInt_t)(this->DBobt(OBT0/1000)) + T0; |
1651 |
// |
// |
1652 |
myquery.str(""); |
// printf(" T0 %u toffset is %u \n",T0,toffset); |
|
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
|
|
<< " WHERE ID_RAW = " << idraw |
|
|
<< ";"; |
|
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
|
|
this->GetGLTABLES()->AddQ(); |
|
|
pResult = dbc->Query(myquery.str().c_str()); |
|
|
if ( pResult ){ |
|
|
Row = pResult->Next(); |
|
|
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
|
|
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
|
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
|
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
|
|
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
|
|
}; |
|
|
}; |
|
1653 |
// |
// |
1654 |
file->Close(); |
file->Close(); |
1655 |
delete pResult; |
delete pResult; |
1662 |
*/ |
*/ |
1663 |
UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ |
UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ |
1664 |
// |
// |
1665 |
|
// printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
1666 |
return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
1667 |
// |
// |
1668 |
}; |
}; |
1701 |
*/ |
*/ |
1702 |
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1703 |
// |
// |
1704 |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
1705 |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
1706 |
}; |
}; |
1707 |
// |
// |
1708 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt > ((Long64_t)obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1709 |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
1710 |
}; |
}; |
1711 |
// |
// |