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> |
18 |
#include <GLTables.h> |
#include <GLTables.h> |
19 |
#include <sgp4.h> |
#include <sgp4.h> |
20 |
// |
// |
21 |
|
ClassImp(Q2TH); |
22 |
ClassImp(GL_TABLES); |
ClassImp(GL_TABLES); |
23 |
ClassImp(GL_TRK_CALIB); |
ClassImp(GL_TRK_CALIB); |
24 |
ClassImp(GL_RUN); |
ClassImp(GL_RUN); |
32 |
// |
// |
33 |
using namespace std; |
using namespace std; |
34 |
|
|
35 |
|
Q2TH::Q2TH(TString host, TString user, TString psw){ |
36 |
|
fh = gSystem->ExpandPathName(host.Data()); |
37 |
|
fu = gSystem->ExpandPathName(user.Data()); |
38 |
|
fp = gSystem->ExpandPathName(psw.Data()); |
39 |
|
dbc = TSQLServer::Connect(fh.Data(),fu.Data(),fp.Data()); |
40 |
|
}; |
41 |
|
|
42 |
|
TObject *Q2TH::Draw(TString query, Bool_t verbose, TString hname){ |
43 |
|
// |
44 |
|
pResult = dbc->Query(query.Data()); |
45 |
|
// |
46 |
|
Row = pResult->Next(); |
47 |
|
// |
48 |
|
Int_t dim = pResult->GetFieldCount(); |
49 |
|
if ( dim < 1 || dim > 2 ){ |
50 |
|
printf(" Dim == %i not supported yet \n",dim); |
51 |
|
return NULL; |
52 |
|
}; |
53 |
|
// |
54 |
|
TH1D *h1 = NULL; |
55 |
|
TH2D *h2 = NULL; |
56 |
|
Double_t f1 = 0.; |
57 |
|
Double_t minf1 = numeric_limits<Double_t>::max(); |
58 |
|
Double_t maxf1 = numeric_limits<Double_t>::min(); |
59 |
|
Double_t f2 = 0.; |
60 |
|
Double_t minf2 = numeric_limits<Double_t>::max(); |
61 |
|
Double_t maxf2 = numeric_limits<Double_t>::min(); |
62 |
|
// |
63 |
|
while ( Row ){ |
64 |
|
f1 = (Double_t)atof(Row->GetField(0)); |
65 |
|
if ( f1 > maxf1 ) maxf1 = f1; |
66 |
|
if ( f1 < minf1 ) minf1 = f1; |
67 |
|
if ( dim == 2 ){ |
68 |
|
f2 = (Double_t)atof(Row->GetField(1)); |
69 |
|
if ( f2 > maxf2 ) maxf2 = f2; |
70 |
|
if ( f2 < minf2 ) minf2 = f2; |
71 |
|
|
72 |
|
}; |
73 |
|
Row = pResult->Next(); |
74 |
|
}; |
75 |
|
pResult->Delete(); |
76 |
|
// |
77 |
|
Int_t f1bin = 70; |
78 |
|
Int_t f2bin = 70; |
79 |
|
if ( dim == 1 ){ |
80 |
|
f1bin = int((maxf1-minf1)/1000.); |
81 |
|
if ( f1bin < 70 ) f1bin = 70; |
82 |
|
if ( f1bin > 1000 ) f1bin = 1000; |
83 |
|
h1 = new TH1D(Form("%s1",hname.Data()),Form("%s1",hname.Data()),f1bin,minf1*0.98,maxf1*1.02); |
84 |
|
// h1->SetBit(TH1::kCanRebin); |
85 |
|
if ( verbose ) printf("\n\n Row %s \n",pResult->GetFieldName(0)); |
86 |
|
}; |
87 |
|
if ( dim == 2 ){ |
88 |
|
f2bin = int((maxf2-minf2)/1000.); |
89 |
|
if ( f2bin < 70 ) f2bin = 70; |
90 |
|
if ( f2bin > 1000 ) f2bin = 1000; |
91 |
|
h2 = new TH2D(Form("%s2",hname.Data()),Form("%s2",hname.Data()),f1bin,minf1*0.98,maxf1*1.02,f2bin,minf2*0.98,maxf2*1.02); |
92 |
|
// h2->SetBit(TH2::kCanRebin); |
93 |
|
if ( verbose ) printf("\n\n Row %s %s \n",pResult->GetFieldName(0),pResult->GetFieldName(1)); |
94 |
|
}; |
95 |
|
// |
96 |
|
pResult = dbc->Query(query.Data()); |
97 |
|
// |
98 |
|
Row = pResult->Next(); |
99 |
|
// |
100 |
|
Int_t r = 0; |
101 |
|
// |
102 |
|
while ( Row ){ |
103 |
|
f1 = (Double_t)atof(Row->GetField(0)); |
104 |
|
if ( dim == 1 ){ |
105 |
|
if ( verbose ) printf(" %f \n",r,f1); |
106 |
|
h1->Fill(f1); |
107 |
|
} else { |
108 |
|
f2 = (Double_t)atof(Row->GetField(1)); |
109 |
|
if ( verbose ) printf(" %f %f \n",r,f1,f2); |
110 |
|
h2->Fill(f1,f2); |
111 |
|
}; |
112 |
|
r++; |
113 |
|
Row = pResult->Next(); |
114 |
|
}; |
115 |
|
// |
116 |
|
TCanvas *c = new TCanvas(Form("%sc",hname.Data())); |
117 |
|
c->cd(); |
118 |
|
if ( dim == 1 ) h1->Draw(); |
119 |
|
if ( dim == 2 ) h2->Draw(); |
120 |
|
// |
121 |
|
pResult->Delete(); |
122 |
|
if ( dim == 1 ) return h1; |
123 |
|
if ( dim == 2 ) return h2; |
124 |
|
// |
125 |
|
return NULL; |
126 |
|
}; |
127 |
|
|
128 |
GL_TABLES::GL_TABLES(){ |
GL_TABLES::GL_TABLES(){ |
129 |
}; |
}; |
130 |
|
|
151 |
mp = psw.Data(); |
mp = psw.Data(); |
152 |
}; |
}; |
153 |
|
|
154 |
Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
//Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
155 |
|
Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){ |
156 |
// |
// |
157 |
// |
// |
158 |
// |
// |
188 |
TString host = fHost->Data(); |
TString host = fHost->Data(); |
189 |
TString user = fUser->Data(); |
TString user = fUser->Data(); |
190 |
TString psw = fPsw->Data(); |
TString psw = fPsw->Data(); |
191 |
dbc->Close(); |
if ( dbc ){ |
192 |
delete dbc; |
dbc->Close(); |
193 |
|
delete dbc; |
194 |
|
}; |
195 |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
196 |
// |
// |
197 |
myquery.str(""); |
myquery.str(""); |
316 |
NAME = ""; |
NAME = ""; |
317 |
} |
} |
318 |
|
|
319 |
|
GL_RAW::GL_RAW(){ |
320 |
|
ID = 0; |
321 |
|
PATH = ""; |
322 |
|
NAME = ""; |
323 |
|
BOOT_NUMBER = 0; |
324 |
|
} |
325 |
|
|
326 |
GL_PARAM::GL_PARAM(){ |
GL_PARAM::GL_PARAM(){ |
327 |
ID = 0; |
ID = 0; |
328 |
PATH = ""; |
PATH = ""; |
1414 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1415 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1416 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1417 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1418 |
// |
// |
1419 |
if( !pResult->GetRowCount() ) return(-54); |
if( !pResult->GetRowCount() ) return(-54); |
1420 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1452 |
// |
// |
1453 |
// if the selected calibration is too old (more than 5 orbits old) try to take the closest not corrupted one |
// if the selected calibration is too old (more than 5 orbits old) try to take the closest not corrupted one |
1454 |
// |
// |
1455 |
if ( (time-myfromtime)>28500 ){ |
if ( (time-myfromtime)>28500 && myfromtime > 0 ){ |
1456 |
// |
// |
1457 |
myquery.str(""); |
myquery.str(""); |
1458 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALO_CALIB where SECTION=" << section; |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALO_CALIB where SECTION=" << section; |
1644 |
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ |
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ |
1645 |
// MySQL variables |
// MySQL variables |
1646 |
TFile *file = 0; |
TFile *file = 0; |
1647 |
UInt_t idraw = 0; |
UInt_t idtsy = 0; |
1648 |
// |
// |
1649 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1650 |
TSQLRow *Row; |
TSQLRow *Row = 0; |
1651 |
stringstream myquery; |
stringstream myquery; |
1652 |
stringstream rname; |
stringstream rname; |
1653 |
// pcksList packetsNames; |
// pcksList packetsNames; |
1658 |
myquery.str(""); |
myquery.str(""); |
1659 |
myquery << "select "; |
myquery << "select "; |
1660 |
myquery << "PATH"; |
myquery << "PATH"; |
1661 |
myquery << ",NAME,ID_RAW"; |
myquery << ",NAME,ID_TIMESYNC"; |
1662 |
myquery << " from GL_ROOT where "; |
myquery << " from GL_ROOT where "; |
1663 |
myquery << type.Data(); |
myquery << type.Data(); |
1664 |
myquery << "=" << id << ";"; |
myquery << "=" << id << ";"; |
1674 |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
1675 |
rname << Row->GetField(1); |
rname << Row->GetField(1); |
1676 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
1677 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idtsy = (UInt_t)atoll(Row->GetField(2)); |
1678 |
}; |
}; |
1679 |
}; |
}; |
1680 |
// |
// |
1687 |
T->GetEntry(0); |
T->GetEntry(0); |
1688 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1689 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
1690 |
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(); |
|
|
// // |
|
|
// }; |
|
|
// }; |
|
1691 |
// |
// |
1692 |
}; |
}; |
1693 |
// |
// |
1695 |
// |
// |
1696 |
T0 = 0; |
T0 = 0; |
1697 |
// |
// |
|
// |
|
1698 |
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(); |
|
1699 |
// |
// |
1700 |
TString name=rname.str().c_str(); |
TString name=rname.str().c_str(); |
1701 |
UInt_t dworbit = 0; |
UInt_t dworbit = 0; |
1702 |
Int_t nlength = name.Length(); |
// Int_t nlength = name.Length(); |
1703 |
|
delete pResult; |
1704 |
// |
// |
1705 |
// 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 |
1706 |
// |
// |
1707 |
if ( !Row ){ |
oss.str(""); |
1708 |
delete pResult; |
oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; |
1709 |
// |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1710 |
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
this->GetGLTABLES()->AddQ(); |
1711 |
// |
pResult = dbc->Query(oss.str().c_str()); |
1712 |
oss.str(""); |
Bool_t fndit = false; |
1713 |
oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";"; |
if ( pResult ){ |
1714 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
Row = pResult->Next(); |
1715 |
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 |
|
1716 |
// |
// |
1717 |
if ( nlength < 5 ) return; |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
1718 |
TString dwo = 0; |
obtfirst = OBT0; |
1719 |
for (Int_t i = 0; i<5; i++){ |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1720 |
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; |
|
|
}; |
|
|
}; |
|
1721 |
// |
// |
1722 |
oss.str(""); |
oss.str(""); |
1723 |
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=" |
1724 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< Row->GetField(3) << ";"; |
1725 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1726 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1727 |
|
delete pResult; |
1728 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1729 |
Row = pResult->Next(); |
if ( pResult ){ |
1730 |
if ( !Row ){ |
Row = pResult->Next(); |
1731 |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
if ( Row ){ |
1732 |
return; |
// printf(" GREAT! the DB structure is the new one! \n"); |
1733 |
|
fndit = true; |
1734 |
|
dworbit = 1; |
1735 |
|
}; |
1736 |
}; |
}; |
1737 |
}; |
}; |
1738 |
}; |
}; |
1739 |
|
if ( !fndit ){ |
1740 |
|
// |
1741 |
|
printf(" ERROR OLD DB! \n"); |
1742 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1743 |
|
// |
1744 |
|
}; |
1745 |
// |
// |
1746 |
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); |
1747 |
T0 = (UInt_t)tu.GetSec(); |
T0 = (UInt_t)tu.GetSec(); |
1748 |
// |
// |
1749 |
// look for the correct timesync entry |
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
1750 |
|
// |
1751 |
|
// printf(" T0 %u toffset is %u \n",T0,toffset); |
1752 |
|
// |
1753 |
|
if ( file ) file->Close(); |
1754 |
|
delete pResult; |
1755 |
|
}; |
1756 |
|
|
1757 |
|
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc, Bool_t usel0file){ |
1758 |
|
// MySQL variables |
1759 |
|
TFile *file = 0; |
1760 |
|
UInt_t idtsy = 0; |
1761 |
// |
// |
1762 |
|
TSQLResult *pResult; |
1763 |
|
TSQLRow *Row = 0; |
1764 |
|
stringstream myquery; |
1765 |
|
stringstream rname; |
1766 |
|
// pcksList packetsNames; |
1767 |
|
// pcksList::iterator Iter; |
1768 |
|
// getPacketsNames(packetsNames); |
1769 |
|
rname.str(""); |
1770 |
|
// ---------------- |
1771 |
myquery.str(""); |
myquery.str(""); |
1772 |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
myquery << "select "; |
1773 |
<< " WHERE ID_RAW = " << idraw |
myquery << "PATH"; |
1774 |
<< ";"; |
myquery << ",NAME,ID_TIMESYNC"; |
1775 |
|
myquery << " from GL_ROOT where "; |
1776 |
|
myquery << type.Data(); |
1777 |
|
myquery << "=" << id << ";"; |
1778 |
|
// |
1779 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1780 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1781 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1782 |
|
if( pResult->GetRowCount() ){ |
1783 |
|
Row = pResult->Next(); |
1784 |
|
if( Row ){ |
1785 |
|
stringstream fname; |
1786 |
|
fname.str(""); |
1787 |
|
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
1788 |
|
rname << Row->GetField(1); |
1789 |
|
if ( usel0file ) file = new TFile(fname.str().c_str(),"READ"); |
1790 |
|
idtsy = (UInt_t)atoll(Row->GetField(2)); |
1791 |
|
}; |
1792 |
|
}; |
1793 |
|
// |
1794 |
|
if ( usel0file && file && file->IsOpen() ){ |
1795 |
|
TTree *T=(TTree*)file->Get("Physics"); |
1796 |
|
pamela::EventHeader *eh = 0; |
1797 |
|
pamela::PscuHeader *ph = 0; |
1798 |
|
T->SetBranchAddress("Header", &eh); |
1799 |
|
// |
1800 |
|
T->GetEntry(0); |
1801 |
|
ph = eh->GetPscuHeader(); |
1802 |
|
pktfirst = ph->GetCounter(); |
1803 |
|
// obtfirst = ph->GetOrbitalTime(); |
1804 |
|
// |
1805 |
|
}; |
1806 |
|
if ( !usel0file ) pktfirst = 0; |
1807 |
|
// |
1808 |
|
// look for Resurs offset |
1809 |
|
// |
1810 |
|
T0 = 0; |
1811 |
|
// |
1812 |
|
stringstream oss; |
1813 |
|
// |
1814 |
|
TString name=rname.str().c_str(); |
1815 |
|
UInt_t dworbit = 0; |
1816 |
|
// Int_t nlength = name.Length(); |
1817 |
|
delete pResult; |
1818 |
|
// |
1819 |
|
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
1820 |
|
// |
1821 |
|
oss.str(""); |
1822 |
|
oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; |
1823 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1824 |
|
this->GetGLTABLES()->AddQ(); |
1825 |
|
pResult = dbc->Query(oss.str().c_str()); |
1826 |
|
Bool_t fndit = false; |
1827 |
if ( pResult ){ |
if ( pResult ){ |
1828 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1829 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( Row ){ |
1830 |
|
// |
1831 |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
1832 |
|
obtfirst = OBT0; |
1833 |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1834 |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
1835 |
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
// |
1836 |
|
oss.str(""); |
1837 |
|
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=" |
1838 |
|
<< Row->GetField(3) << ";"; |
1839 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1840 |
|
this->GetGLTABLES()->AddQ(); |
1841 |
|
delete pResult; |
1842 |
|
pResult = dbc->Query(oss.str().c_str()); |
1843 |
|
if ( pResult ){ |
1844 |
|
Row = pResult->Next(); |
1845 |
|
if ( Row ){ |
1846 |
|
// printf(" GREAT! the DB structure is the new one! \n"); |
1847 |
|
fndit = true; |
1848 |
|
dworbit = 1; |
1849 |
|
}; |
1850 |
|
}; |
1851 |
}; |
}; |
1852 |
}; |
}; |
1853 |
|
if ( !fndit ){ |
1854 |
|
// |
1855 |
|
printf(" ERROR OLD DB! \n"); |
1856 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1857 |
|
// |
1858 |
|
}; |
1859 |
|
// |
1860 |
|
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); |
1861 |
|
T0 = (UInt_t)tu.GetSec(); |
1862 |
|
// |
1863 |
|
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
1864 |
|
// |
1865 |
|
// printf(" T0 %u toffset is %u \n",T0,toffset); |
1866 |
// |
// |
1867 |
file->Close(); |
if ( file ) file->Close(); |
1868 |
delete pResult; |
delete pResult; |
1869 |
}; |
}; |
1870 |
|
|
1875 |
*/ |
*/ |
1876 |
UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ |
UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ |
1877 |
// |
// |
1878 |
|
// printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
1879 |
return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
1880 |
// |
// |
1881 |
}; |
}; |
1914 |
*/ |
*/ |
1915 |
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1916 |
// |
// |
1917 |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
1918 |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
1919 |
}; |
}; |
1920 |
// |
// |
1921 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt > ((Long64_t)obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1922 |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
1923 |
}; |
}; |
1924 |
// |
// |