| 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(""); |
| 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(); |
| 1691 |
|
// |
| 1692 |
|
}; |
| 1693 |
|
// |
| 1694 |
|
// look for Resurs offset |
| 1695 |
|
// |
| 1696 |
|
T0 = 0; |
| 1697 |
|
// |
| 1698 |
|
stringstream oss; |
| 1699 |
|
// |
| 1700 |
|
TString name=rname.str().c_str(); |
| 1701 |
|
UInt_t dworbit = 0; |
| 1702 |
|
// Int_t nlength = name.Length(); |
| 1703 |
|
delete pResult; |
| 1704 |
|
// |
| 1705 |
|
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
| 1706 |
|
// |
| 1707 |
|
oss.str(""); |
| 1708 |
|
oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; |
| 1709 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1710 |
|
this->GetGLTABLES()->AddQ(); |
| 1711 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1712 |
|
Bool_t fndit = false; |
| 1713 |
|
if ( pResult ){ |
| 1714 |
|
Row = pResult->Next(); |
| 1715 |
|
if ( Row ){ |
| 1716 |
|
// |
| 1717 |
|
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
| 1718 |
|
obtfirst = OBT0; |
| 1719 |
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
| 1720 |
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
| 1721 |
|
// |
| 1722 |
|
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 ID=" |
| 1724 |
|
<< Row->GetField(3) << ";"; |
| 1725 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1726 |
|
this->GetGLTABLES()->AddQ(); |
| 1727 |
|
delete pResult; |
| 1728 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1729 |
|
if ( pResult ){ |
| 1730 |
|
Row = pResult->Next(); |
| 1731 |
|
if ( Row ){ |
| 1732 |
|
// 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); |
| 1747 |
|
T0 = (UInt_t)tu.GetSec(); |
| 1748 |
|
// |
| 1749 |
|
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(""); |
| 1772 |
|
myquery << "select "; |
| 1773 |
|
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; |
| 1780 |
|
this->GetGLTABLES()->AddQ(); |
| 1781 |
|
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 |
// look for Resurs offset |
| 1809 |
// |
// |
| 1829 |
if ( Row ){ |
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 |
// |
// |
| 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); |
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(); |
T0 = (UInt_t)tu.GetSec(); |
| 1862 |
// |
// |
| 1863 |
toffset = TIMESYNC - (UInt_t)(this->DBobt(OBT0/1000)) + T0; |
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
| 1864 |
// |
// |
| 1865 |
// printf(" T0 %u toffset is %u \n",T0,toffset); |
// printf(" T0 %u toffset is %u \n",T0,toffset); |
| 1866 |
// |
// |
| 1867 |
file->Close(); |
if ( file ) file->Close(); |
| 1868 |
delete pResult; |
delete pResult; |
| 1869 |
}; |
}; |
| 1870 |
|
|