| 1652 |
// |
// |
| 1653 |
// printf(" T0 %u toffset is %u \n",T0,toffset); |
// printf(" T0 %u toffset is %u \n",T0,toffset); |
| 1654 |
// |
// |
| 1655 |
file->Close(); |
if ( file ) file->Close(); |
| 1656 |
|
delete pResult; |
| 1657 |
|
}; |
| 1658 |
|
|
| 1659 |
|
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc, Bool_t usel0file){ |
| 1660 |
|
// MySQL variables |
| 1661 |
|
TFile *file = 0; |
| 1662 |
|
UInt_t idtsy = 0; |
| 1663 |
|
// |
| 1664 |
|
TSQLResult *pResult; |
| 1665 |
|
TSQLRow *Row = 0; |
| 1666 |
|
stringstream myquery; |
| 1667 |
|
stringstream rname; |
| 1668 |
|
// pcksList packetsNames; |
| 1669 |
|
// pcksList::iterator Iter; |
| 1670 |
|
// getPacketsNames(packetsNames); |
| 1671 |
|
rname.str(""); |
| 1672 |
|
// ---------------- |
| 1673 |
|
myquery.str(""); |
| 1674 |
|
myquery << "select "; |
| 1675 |
|
myquery << "PATH"; |
| 1676 |
|
myquery << ",NAME,ID_TIMESYNC"; |
| 1677 |
|
myquery << " from GL_ROOT where "; |
| 1678 |
|
myquery << type.Data(); |
| 1679 |
|
myquery << "=" << id << ";"; |
| 1680 |
|
// |
| 1681 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1682 |
|
this->GetGLTABLES()->AddQ(); |
| 1683 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 1684 |
|
if( pResult->GetRowCount() ){ |
| 1685 |
|
Row = pResult->Next(); |
| 1686 |
|
if( Row ){ |
| 1687 |
|
stringstream fname; |
| 1688 |
|
fname.str(""); |
| 1689 |
|
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
| 1690 |
|
rname << Row->GetField(1); |
| 1691 |
|
if ( usel0file ) file = new TFile(fname.str().c_str(),"READ"); |
| 1692 |
|
idtsy = (UInt_t)atoll(Row->GetField(2)); |
| 1693 |
|
}; |
| 1694 |
|
}; |
| 1695 |
|
// |
| 1696 |
|
if ( usel0file && file && file->IsOpen() ){ |
| 1697 |
|
TTree *T=(TTree*)file->Get("Physics"); |
| 1698 |
|
pamela::EventHeader *eh = 0; |
| 1699 |
|
pamela::PscuHeader *ph = 0; |
| 1700 |
|
T->SetBranchAddress("Header", &eh); |
| 1701 |
|
// |
| 1702 |
|
T->GetEntry(0); |
| 1703 |
|
ph = eh->GetPscuHeader(); |
| 1704 |
|
pktfirst = ph->GetCounter(); |
| 1705 |
|
// obtfirst = ph->GetOrbitalTime(); |
| 1706 |
|
// |
| 1707 |
|
}; |
| 1708 |
|
if ( !usel0file ) pktfirst = 0; |
| 1709 |
|
// |
| 1710 |
|
// look for Resurs offset |
| 1711 |
|
// |
| 1712 |
|
T0 = 0; |
| 1713 |
|
// |
| 1714 |
|
stringstream oss; |
| 1715 |
|
// |
| 1716 |
|
TString name=rname.str().c_str(); |
| 1717 |
|
UInt_t dworbit = 0; |
| 1718 |
|
// Int_t nlength = name.Length(); |
| 1719 |
|
delete pResult; |
| 1720 |
|
// |
| 1721 |
|
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
| 1722 |
|
// |
| 1723 |
|
oss.str(""); |
| 1724 |
|
oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; |
| 1725 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1726 |
|
this->GetGLTABLES()->AddQ(); |
| 1727 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1728 |
|
Bool_t fndit = false; |
| 1729 |
|
if ( pResult ){ |
| 1730 |
|
Row = pResult->Next(); |
| 1731 |
|
if ( Row ){ |
| 1732 |
|
// |
| 1733 |
|
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
| 1734 |
|
obtfirst = OBT0; |
| 1735 |
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
| 1736 |
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
| 1737 |
|
// |
| 1738 |
|
oss.str(""); |
| 1739 |
|
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=" |
| 1740 |
|
<< Row->GetField(3) << ";"; |
| 1741 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1742 |
|
this->GetGLTABLES()->AddQ(); |
| 1743 |
|
delete pResult; |
| 1744 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1745 |
|
if ( pResult ){ |
| 1746 |
|
Row = pResult->Next(); |
| 1747 |
|
if ( Row ){ |
| 1748 |
|
// printf(" GREAT! the DB structure is the new one! \n"); |
| 1749 |
|
fndit = true; |
| 1750 |
|
dworbit = 1; |
| 1751 |
|
}; |
| 1752 |
|
}; |
| 1753 |
|
}; |
| 1754 |
|
}; |
| 1755 |
|
if ( !fndit ){ |
| 1756 |
|
// |
| 1757 |
|
printf(" ERROR OLD DB! \n"); |
| 1758 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
| 1759 |
|
// |
| 1760 |
|
}; |
| 1761 |
|
// |
| 1762 |
|
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); |
| 1763 |
|
T0 = (UInt_t)tu.GetSec(); |
| 1764 |
|
// |
| 1765 |
|
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
| 1766 |
|
// |
| 1767 |
|
// printf(" T0 %u toffset is %u \n",T0,toffset); |
| 1768 |
|
// |
| 1769 |
|
if ( file ) file->Close(); |
| 1770 |
delete pResult; |
delete pResult; |
| 1771 |
}; |
}; |
| 1772 |
|
|