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