7 |
// |
// |
8 |
#include <sstream> |
#include <sstream> |
9 |
#include <iostream> |
#include <iostream> |
10 |
|
#include <limits.h> |
11 |
// |
// |
12 |
#include <TFile.h> |
#include <TFile.h> |
13 |
#include <TTree.h> |
#include <TTree.h> |
57 |
mp = psw.Data(); |
mp = psw.Data(); |
58 |
}; |
}; |
59 |
|
|
60 |
Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
//Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
61 |
|
Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){ |
62 |
// |
// |
63 |
// |
// |
64 |
// |
// |
94 |
TString host = fHost->Data(); |
TString host = fHost->Data(); |
95 |
TString user = fUser->Data(); |
TString user = fUser->Data(); |
96 |
TString psw = fPsw->Data(); |
TString psw = fPsw->Data(); |
97 |
dbc->Close(); |
if ( dbc ){ |
98 |
delete dbc; |
dbc->Close(); |
99 |
|
delete dbc; |
100 |
|
}; |
101 |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
102 |
// |
// |
103 |
myquery.str(""); |
myquery.str(""); |
222 |
NAME = ""; |
NAME = ""; |
223 |
} |
} |
224 |
|
|
225 |
|
GL_RAW::GL_RAW(){ |
226 |
|
ID = 0; |
227 |
|
PATH = ""; |
228 |
|
NAME = ""; |
229 |
|
BOOT_NUMBER = 0; |
230 |
|
} |
231 |
|
|
232 |
GL_PARAM::GL_PARAM(){ |
GL_PARAM::GL_PARAM(){ |
233 |
ID = 0; |
ID = 0; |
234 |
PATH = ""; |
PATH = ""; |
1320 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1321 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1322 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1323 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1324 |
// |
// |
1325 |
if( !pResult->GetRowCount() ) return(-54); |
if( !pResult->GetRowCount() ) return(-54); |
1326 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1550 |
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ |
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ |
1551 |
// MySQL variables |
// MySQL variables |
1552 |
TFile *file = 0; |
TFile *file = 0; |
1553 |
UInt_t idraw = 0; |
UInt_t idtsy = 0; |
1554 |
// |
// |
1555 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1556 |
TSQLRow *Row; |
TSQLRow *Row = 0; |
1557 |
stringstream myquery; |
stringstream myquery; |
1558 |
stringstream rname; |
stringstream rname; |
1559 |
// pcksList packetsNames; |
// pcksList packetsNames; |
1564 |
myquery.str(""); |
myquery.str(""); |
1565 |
myquery << "select "; |
myquery << "select "; |
1566 |
myquery << "PATH"; |
myquery << "PATH"; |
1567 |
myquery << ",NAME,ID_RAW"; |
myquery << ",NAME,ID_TIMESYNC"; |
1568 |
myquery << " from GL_ROOT where "; |
myquery << " from GL_ROOT where "; |
1569 |
myquery << type.Data(); |
myquery << type.Data(); |
1570 |
myquery << "=" << id << ";"; |
myquery << "=" << id << ";"; |
1580 |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
1581 |
rname << Row->GetField(1); |
rname << Row->GetField(1); |
1582 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
1583 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idtsy = (UInt_t)atoll(Row->GetField(2)); |
1584 |
}; |
}; |
1585 |
}; |
}; |
1586 |
// |
// |
1593 |
T->GetEntry(0); |
T->GetEntry(0); |
1594 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1595 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
1596 |
obtfirst = ph->GetOrbitalTime(); |
// obtfirst = ph->GetOrbitalTime(); |
|
// |
|
|
// 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(); |
|
|
// // |
|
|
// }; |
|
|
// }; |
|
1597 |
// |
// |
1598 |
}; |
}; |
1599 |
// |
// |
1601 |
// |
// |
1602 |
T0 = 0; |
T0 = 0; |
1603 |
// |
// |
|
// |
|
1604 |
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(); |
|
1605 |
// |
// |
1606 |
TString name=rname.str().c_str(); |
TString name=rname.str().c_str(); |
1607 |
UInt_t dworbit = 0; |
UInt_t dworbit = 0; |
1608 |
Int_t nlength = name.Length(); |
// Int_t nlength = name.Length(); |
1609 |
|
delete pResult; |
1610 |
// |
// |
1611 |
// 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 |
1612 |
// |
// |
1613 |
if ( !Row ){ |
oss.str(""); |
1614 |
delete pResult; |
oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; |
1615 |
// |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1616 |
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
this->GetGLTABLES()->AddQ(); |
1617 |
// |
pResult = dbc->Query(oss.str().c_str()); |
1618 |
oss.str(""); |
Bool_t fndit = false; |
1619 |
oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";"; |
if ( pResult ){ |
1620 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
Row = pResult->Next(); |
1621 |
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 |
|
1622 |
// |
// |
1623 |
if ( nlength < 5 ) return; |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
1624 |
TString dwo = 0; |
obtfirst = OBT0; |
1625 |
for (Int_t i = 0; i<5; i++){ |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1626 |
dwo.Append(name[i],1); |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
|
}; |
|
|
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; |
|
|
}; |
|
|
}; |
|
1627 |
// |
// |
1628 |
oss.str(""); |
oss.str(""); |
1629 |
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=" |
1630 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< Row->GetField(3) << ";"; |
1631 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1632 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1633 |
|
delete pResult; |
1634 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1635 |
Row = pResult->Next(); |
if ( pResult ){ |
1636 |
if ( !Row ){ |
Row = pResult->Next(); |
1637 |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
if ( Row ){ |
1638 |
return; |
// printf(" GREAT! the DB structure is the new one! \n"); |
1639 |
|
fndit = true; |
1640 |
|
dworbit = 1; |
1641 |
|
}; |
1642 |
}; |
}; |
1643 |
}; |
}; |
1644 |
}; |
}; |
1645 |
|
if ( !fndit ){ |
1646 |
|
// |
1647 |
|
printf(" ERROR OLD DB! \n"); |
1648 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1649 |
|
// |
1650 |
|
}; |
1651 |
// |
// |
1652 |
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); |
1653 |
T0 = (UInt_t)tu.GetSec(); |
T0 = (UInt_t)tu.GetSec(); |
1654 |
// |
// |
1655 |
// look for the correct timesync entry |
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
1656 |
|
// |
1657 |
|
// printf(" T0 %u toffset is %u \n",T0,toffset); |
1658 |
|
// |
1659 |
|
if ( file ) file->Close(); |
1660 |
|
delete pResult; |
1661 |
|
}; |
1662 |
|
|
1663 |
|
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc, Bool_t usel0file){ |
1664 |
|
// MySQL variables |
1665 |
|
TFile *file = 0; |
1666 |
|
UInt_t idtsy = 0; |
1667 |
// |
// |
1668 |
|
TSQLResult *pResult; |
1669 |
|
TSQLRow *Row = 0; |
1670 |
|
stringstream myquery; |
1671 |
|
stringstream rname; |
1672 |
|
// pcksList packetsNames; |
1673 |
|
// pcksList::iterator Iter; |
1674 |
|
// getPacketsNames(packetsNames); |
1675 |
|
rname.str(""); |
1676 |
|
// ---------------- |
1677 |
myquery.str(""); |
myquery.str(""); |
1678 |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
myquery << "select "; |
1679 |
<< " WHERE ID_RAW = " << idraw |
myquery << "PATH"; |
1680 |
<< ";"; |
myquery << ",NAME,ID_TIMESYNC"; |
1681 |
|
myquery << " from GL_ROOT where "; |
1682 |
|
myquery << type.Data(); |
1683 |
|
myquery << "=" << id << ";"; |
1684 |
|
// |
1685 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1686 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1687 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1688 |
|
if( pResult->GetRowCount() ){ |
1689 |
|
Row = pResult->Next(); |
1690 |
|
if( Row ){ |
1691 |
|
stringstream fname; |
1692 |
|
fname.str(""); |
1693 |
|
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
1694 |
|
rname << Row->GetField(1); |
1695 |
|
if ( usel0file ) file = new TFile(fname.str().c_str(),"READ"); |
1696 |
|
idtsy = (UInt_t)atoll(Row->GetField(2)); |
1697 |
|
}; |
1698 |
|
}; |
1699 |
|
// |
1700 |
|
if ( usel0file && file && file->IsOpen() ){ |
1701 |
|
TTree *T=(TTree*)file->Get("Physics"); |
1702 |
|
pamela::EventHeader *eh = 0; |
1703 |
|
pamela::PscuHeader *ph = 0; |
1704 |
|
T->SetBranchAddress("Header", &eh); |
1705 |
|
// |
1706 |
|
T->GetEntry(0); |
1707 |
|
ph = eh->GetPscuHeader(); |
1708 |
|
pktfirst = ph->GetCounter(); |
1709 |
|
// obtfirst = ph->GetOrbitalTime(); |
1710 |
|
// |
1711 |
|
}; |
1712 |
|
if ( !usel0file ) pktfirst = 0; |
1713 |
|
// |
1714 |
|
// look for Resurs offset |
1715 |
|
// |
1716 |
|
T0 = 0; |
1717 |
|
// |
1718 |
|
stringstream oss; |
1719 |
|
// |
1720 |
|
TString name=rname.str().c_str(); |
1721 |
|
UInt_t dworbit = 0; |
1722 |
|
// Int_t nlength = name.Length(); |
1723 |
|
delete pResult; |
1724 |
|
// |
1725 |
|
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
1726 |
|
// |
1727 |
|
oss.str(""); |
1728 |
|
oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; |
1729 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1730 |
|
this->GetGLTABLES()->AddQ(); |
1731 |
|
pResult = dbc->Query(oss.str().c_str()); |
1732 |
|
Bool_t fndit = false; |
1733 |
if ( pResult ){ |
if ( pResult ){ |
1734 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1735 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( Row ){ |
1736 |
|
// |
1737 |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
1738 |
|
obtfirst = OBT0; |
1739 |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1740 |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
1741 |
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
// |
1742 |
|
oss.str(""); |
1743 |
|
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=" |
1744 |
|
<< Row->GetField(3) << ";"; |
1745 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1746 |
|
this->GetGLTABLES()->AddQ(); |
1747 |
|
delete pResult; |
1748 |
|
pResult = dbc->Query(oss.str().c_str()); |
1749 |
|
if ( pResult ){ |
1750 |
|
Row = pResult->Next(); |
1751 |
|
if ( Row ){ |
1752 |
|
// printf(" GREAT! the DB structure is the new one! \n"); |
1753 |
|
fndit = true; |
1754 |
|
dworbit = 1; |
1755 |
|
}; |
1756 |
|
}; |
1757 |
}; |
}; |
1758 |
}; |
}; |
1759 |
|
if ( !fndit ){ |
1760 |
|
// |
1761 |
|
printf(" ERROR OLD DB! \n"); |
1762 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1763 |
|
// |
1764 |
|
}; |
1765 |
|
// |
1766 |
|
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); |
1767 |
|
T0 = (UInt_t)tu.GetSec(); |
1768 |
|
// |
1769 |
|
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
1770 |
|
// |
1771 |
|
// printf(" T0 %u toffset is %u \n",T0,toffset); |
1772 |
// |
// |
1773 |
file->Close(); |
if ( file ) file->Close(); |
1774 |
delete pResult; |
delete pResult; |
1775 |
}; |
}; |
1776 |
|
|
1781 |
*/ |
*/ |
1782 |
UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ |
UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ |
1783 |
// |
// |
1784 |
|
// printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
1785 |
return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
1786 |
// |
// |
1787 |
}; |
}; |
1820 |
*/ |
*/ |
1821 |
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1822 |
// |
// |
1823 |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
1824 |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
1825 |
}; |
}; |
1826 |
// |
// |
1827 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt > ((Long64_t)obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1828 |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
1829 |
}; |
}; |
1830 |
// |
// |