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(); |
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 |
// |
// |
1589 |
T->GetEntry(0); |
T->GetEntry(0); |
1590 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1591 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
1592 |
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(); |
|
|
// // |
|
|
// }; |
|
|
// }; |
|
1593 |
// |
// |
1594 |
}; |
}; |
1595 |
// |
// |
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; |
obtfirst = OBT0; |
1621 |
for (Int_t i = 0; i<5; i++){ |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1622 |
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; |
|
|
}; |
|
|
}; |
|
1623 |
// |
// |
1624 |
oss.str(""); |
oss.str(""); |
1625 |
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=" |
1626 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< Row->GetField(3) << ";"; |
1627 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1628 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1629 |
|
delete pResult; |
1630 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1631 |
Row = pResult->Next(); |
if ( pResult ){ |
1632 |
if ( !Row ){ |
Row = pResult->Next(); |
1633 |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
if ( Row ){ |
1634 |
return; |
// printf(" GREAT! the DB structure is the new one! \n"); |
1635 |
|
fndit = true; |
1636 |
|
dworbit = 1; |
1637 |
|
}; |
1638 |
}; |
}; |
1639 |
}; |
}; |
1640 |
}; |
}; |
1641 |
|
if ( !fndit ){ |
1642 |
|
// |
1643 |
|
printf(" ERROR OLD DB! \n"); |
1644 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1645 |
|
// |
1646 |
|
}; |
1647 |
// |
// |
1648 |
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); |
1649 |
T0 = (UInt_t)tu.GetSec(); |
T0 = (UInt_t)tu.GetSec(); |
1650 |
// |
// |
1651 |
// look for the correct timesync entry |
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
1652 |
|
// |
1653 |
|
// printf(" T0 %u toffset is %u \n",T0,toffset); |
1654 |
|
// |
1655 |
|
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(""); |
myquery.str(""); |
1674 |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
myquery << "select "; |
1675 |
<< " WHERE ID_RAW = " << idraw |
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; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1682 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1683 |
pResult = dbc->Query(myquery.str().c_str()); |
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 ){ |
if ( pResult ){ |
1730 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1731 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( Row ){ |
1732 |
|
// |
1733 |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
1734 |
|
obtfirst = OBT0; |
1735 |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1736 |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
1737 |
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
// |
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 |
file->Close(); |
if ( file ) file->Close(); |
1770 |
delete pResult; |
delete pResult; |
1771 |
}; |
}; |
1772 |
|
|
1777 |
*/ |
*/ |
1778 |
UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ |
UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ |
1779 |
// |
// |
1780 |
|
// printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
1781 |
return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
1782 |
// |
// |
1783 |
}; |
}; |
1816 |
*/ |
*/ |
1817 |
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1818 |
// |
// |
1819 |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
1820 |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
1821 |
}; |
}; |
1822 |
// |
// |
1823 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt > ((Long64_t)obtfirst*2) && obt > (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 |
// |
// |