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