15 |
#include <TTree.h> |
#include <TTree.h> |
16 |
#include <TGraph.h> |
#include <TGraph.h> |
17 |
#include <TDatime.h> |
#include <TDatime.h> |
18 |
|
#include <TTimeStamp.h> |
19 |
#include <TF1.h> |
#include <TF1.h> |
20 |
// |
// |
21 |
#include <EventHeader.h> |
#include <EventHeader.h> |
82 |
this->SetRootName(filerootname); |
this->SetRootName(filerootname); |
83 |
this->SetOrbitNo(); |
this->SetOrbitNo(); |
84 |
file = TFile::Open(this->GetRootName().Data()); |
file = TFile::Open(this->GetRootName().Data()); |
85 |
|
} else { |
86 |
|
this->SetRootName(""); |
87 |
}; |
}; |
88 |
// |
// |
89 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
113 |
// |
// |
114 |
void PamelaDBOperations::CheckValidate(Long64_t olderthan){ |
void PamelaDBOperations::CheckValidate(Long64_t olderthan){ |
115 |
clean_time = new TDatime(); |
clean_time = new TDatime(); |
116 |
|
// |
117 |
if(olderthan >= 0){ |
if(olderthan >= 0){ |
118 |
VALIDATE = true; |
VALIDATE = true; |
119 |
UInt_t timelim = 0; |
UInt_t timelim = 0; |
120 |
timelim = (UInt_t)clean_time->Convert() - olderthan; |
timelim = (UInt_t)clean_time->Convert(true) - olderthan; |
121 |
clean_time->Set(timelim,false); |
clean_time->Set(timelim,false); |
122 |
}; |
}; |
123 |
}; |
}; |
158 |
}; |
}; |
159 |
|
|
160 |
/** |
/** |
161 |
|
* Set the nofrag flag |
162 |
|
* |
163 |
|
*/ |
164 |
|
void PamelaDBOperations::SetNoFrag(Bool_t nf){ |
165 |
|
NOFRAG = nf; |
166 |
|
}; |
167 |
|
|
168 |
|
/** |
169 |
* Store the BOOT number of the RAW file. |
* Store the BOOT number of the RAW file. |
170 |
* @param boot BOOT number of the RAW file |
* @param boot BOOT number of the RAW file |
171 |
*/ |
*/ |
765 |
if( !conn ) throw -1; |
if( !conn ) throw -1; |
766 |
bool connect = conn->IsConnected(); |
bool connect = conn->IsConnected(); |
767 |
if( !connect ) throw -1; |
if( !connect ) throw -1; |
768 |
if ( !dworbit ) throw -27; |
if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27; |
769 |
|
// |
770 |
|
// set DB timezone to UTC |
771 |
|
// |
772 |
|
stringstream oss; |
773 |
|
// |
774 |
|
oss.str(""); |
775 |
|
oss << "SET time_zone='+0:00';"; |
776 |
|
conn->Query(oss.str().c_str()); |
777 |
|
// |
778 |
}; |
}; |
779 |
|
|
780 |
/** |
/** |
972 |
if ( !row ) throw -10; |
if ( !row ) throw -10; |
973 |
}; |
}; |
974 |
// |
// |
975 |
t0 = (UInt_t)TDatime(row->GetField(0)).Convert(); |
TDatime ti = TDatime(row->GetField(0)); |
976 |
|
TTimeStamp tu = TTimeStamp((UInt_t)ti.GetYear(),(UInt_t)ti.GetMonth(),(UInt_t)ti.GetDay(),(UInt_t)ti.GetHour(),(UInt_t)ti.GetMinute(),(UInt_t)ti.GetSecond(),0,true,0); |
977 |
|
t0 = (UInt_t)tu.GetSec(); |
978 |
|
// |
979 |
|
// t0 = (UInt_t)TDatime(row->GetField(0)).Convert(); |
980 |
/* |
/* |
981 |
* Verify that the TIMESYNC have been not already processed |
* Verify that the TIMESYNC have been not already processed |
982 |
*/ |
*/ |
1684 |
UInt_t rhfirstev = firstev; |
UInt_t rhfirstev = firstev; |
1685 |
UInt_t rtlastev = lastev; |
UInt_t rtlastev = lastev; |
1686 |
Bool_t found = false; |
Bool_t found = false; |
1687 |
|
Bool_t foundinrun = false; |
1688 |
// |
// |
1689 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1690 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
1711 |
// |
// |
1712 |
if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n"); |
if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n"); |
1713 |
// |
// |
1714 |
|
// First of all insert the run in the fragment table... |
1715 |
|
// |
1716 |
|
oss.str(""); |
1717 |
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE " |
1718 |
|
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" |
1719 |
|
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
1720 |
|
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
1721 |
|
<< " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " |
1722 |
|
<< " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
1723 |
|
<< " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " |
1724 |
|
<< " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " |
1725 |
|
<< " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
1726 |
|
<< " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" |
1727 |
|
<< " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " |
1728 |
|
<< " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
1729 |
|
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
1730 |
|
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; |
1731 |
|
// |
1732 |
|
if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); |
1733 |
|
result = conn->Query(oss.str().c_str()); |
1734 |
|
// |
1735 |
|
if ( !result ) throw -4; |
1736 |
|
// |
1737 |
|
row = result->Next(); |
1738 |
|
// |
1739 |
|
if ( !row ){ |
1740 |
|
// |
1741 |
|
// no, insert this run in the GL_RUN_FRAGMENTS table (check if exist before!) |
1742 |
|
// |
1743 |
|
if ( IsDebug() ) printf(" The run is new \n"); |
1744 |
|
if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n"); |
1745 |
|
// |
1746 |
|
glrun->SetID(this->AssignRunID()); |
1747 |
|
glrun->SetID_RUN_FRAG(0); |
1748 |
|
glrun->Fill_GL_RUN_FRAGMENTS(conn); |
1749 |
|
// |
1750 |
|
} else { |
1751 |
|
if ( IsDebug() ) printf(" The run is already present in the fragment table \n"); |
1752 |
|
}; |
1753 |
|
// |
1754 |
|
// |
1755 |
// can we find the other piece of the run in the GL_RUN_FRAGMENTS table? |
// can we find the other piece of the run in the GL_RUN_FRAGMENTS table? |
1756 |
// |
// |
1757 |
if ( mishead && rhfirstev == firstev ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is |
if ( mishead && rhfirstev == firstev ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is |
1760 |
oss.str(""); |
oss.str(""); |
1761 |
oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN_FRAGMENTS WHERE " |
oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN_FRAGMENTS WHERE " |
1762 |
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " |
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " |
1763 |
<< " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() |
<< " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
1764 |
|
<< " ID != " << glrun->ID |
1765 |
<< " ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! |
<< " ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! |
1766 |
// |
// |
1767 |
if ( IsDebug() ) printf(" look for runheader in the fragments table: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" look for runheader in the fragments table: query is \n %s \n",oss.str().c_str()); |
1771 |
// |
// |
1772 |
row = result->Next(); |
row = result->Next(); |
1773 |
// |
// |
1774 |
|
if ( !row && NoFrag() ){ |
1775 |
|
// |
1776 |
|
oss.str(""); |
1777 |
|
oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN WHERE " |
1778 |
|
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " |
1779 |
|
<< " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
1780 |
|
<< " ID != " << glrun->ID |
1781 |
|
<< " AND ID=ID_RUN_FRAG ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!! |
1782 |
|
// |
1783 |
|
if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str()); |
1784 |
|
result = conn->Query(oss.str().c_str()); |
1785 |
|
// |
1786 |
|
if ( !result ) throw -4; |
1787 |
|
// |
1788 |
|
foundinrun = true; |
1789 |
|
// |
1790 |
|
row = result->Next(); |
1791 |
|
// |
1792 |
|
}; |
1793 |
|
// |
1794 |
if ( !row ){ |
if ( !row ){ |
1795 |
if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); |
if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); |
1796 |
found = false; |
found = false; |
1865 |
// |
// |
1866 |
if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); |
if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); |
1867 |
// |
// |
1868 |
|
if ( foundinrun ){ |
1869 |
|
glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); |
1870 |
|
glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); |
1871 |
|
}; |
1872 |
|
// |
1873 |
GL_RUN *glrun1 = new GL_RUN(); |
GL_RUN *glrun1 = new GL_RUN(); |
1874 |
// |
// |
1875 |
UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); |
// UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); |
1876 |
// |
// |
1877 |
oss.str(""); |
oss.str(""); |
1878 |
oss << " ID="<<row->GetField(0)<<";"; |
oss << " ID="<<row->GetField(0)<<";"; |
1909 |
// |
// |
1910 |
glrun->SetEV_FROM(firstev); |
glrun->SetEV_FROM(firstev); |
1911 |
glrun->SetNEVENTS(lastev-firstev+1); |
glrun->SetNEVENTS(lastev-firstev+1); |
1912 |
|
// |
1913 |
glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); |
glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME()); |
1914 |
glrun->SetRUNHEADER_OBT(glrun1->GetRUNHEADER_OBT()); |
glrun->SetRUNHEADER_OBT(glrun1->GetRUNHEADER_OBT()); |
1915 |
glrun->SetRUNHEADER_PKT(glrun1->GetRUNHEADER_PKT()); |
glrun->SetRUNHEADER_PKT(glrun1->GetRUNHEADER_PKT()); |
1929 |
// |
// |
1930 |
if ( !IsRunAlreadyInserted() ){ |
if ( !IsRunAlreadyInserted() ){ |
1931 |
// |
// |
1932 |
glrun->SetID(this->AssignRunID()); |
// glrun->SetID(this->AssignRunID()); |
1933 |
glrun->SetID_RUN_FRAG(glrun1->GetID()); |
glrun->SetID_RUN_FRAG(glrun1->GetID()); |
1934 |
glrun->Fill_GL_RUN(conn); |
glrun->Fill_GL_RUN(conn); |
1935 |
// |
// |
1936 |
// get id number |
// set id number |
1937 |
// |
// |
|
// oss.str(""); |
|
|
// oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<<this->GetBOOTnumber()<<" AND " |
|
|
// << " RUNHEADER_OBT="<<glrun->GetRUNHEADER_OBT()<<" AND " |
|
|
// << " RUNTRAILER_OBT="<<glrun->GetRUNTRAILER_OBT()<<";"; |
|
|
// // |
|
|
// if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str()); |
|
|
// // |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// if ( !result ) throw -4; |
|
|
// row = result->Next(); |
|
|
// // |
|
|
// UInt_t idrun0 = 0; |
|
|
// if ( !row ){ |
|
|
// throw -10; |
|
|
// } else { |
|
|
// idrun0 = (UInt_t)atoll(row->GetField(0)); |
|
|
// }; |
|
|
// |
|
|
// glrun1->SetID_RUN_FRAG(idrun0); |
|
1938 |
glrun1->SetID_RUN_FRAG(glrun->GetID()); |
glrun1->SetID_RUN_FRAG(glrun->GetID()); |
1939 |
glrun1->Fill_GL_RUN(conn); |
glrun1->Fill_GL_RUN(conn); |
1940 |
// |
// |
|
// oss.str(""); |
|
|
// oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<<idrun0<<" ;"; |
|
|
// // |
|
|
// if ( IsDebug() ) printf(" search for idrun1 , query is : \n%s\n",oss.str().c_str()); |
|
|
// // |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// if ( !result ) throw -4; |
|
|
// row = result->Next(); |
|
|
// // |
|
|
// UInt_t idrun1 = 0; |
|
|
// if ( !row ){ |
|
|
// throw -10; |
|
|
// } else { |
|
|
// idrun1 = (UInt_t)atoll(row->GetField(0)); |
|
|
// }; |
|
|
// // |
|
|
// oss.str(""); |
|
|
// oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<<idrun1<<" WHERE ID="<<idrun0<<" ;"; |
|
|
// // |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// if ( !result ) throw -4; |
|
|
// |
|
1941 |
}; |
}; |
1942 |
|
// delete old entry in fragment table |
1943 |
|
// |
1944 |
|
glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
1945 |
|
glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
1946 |
// |
// |
1947 |
delete glrun1; |
delete glrun1; |
1948 |
// |
// |
|
// delete old entry in fragment table |
|
|
// |
|
|
glrun->DeleteRun(conn,idfrag,"GL_RUN_FRAGMENTS"); |
|
|
// oss.str(""); |
|
|
// // |
|
|
// oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";"; |
|
|
// // |
|
|
// if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str()); |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// if ( !result ) throw -4; |
|
1949 |
// |
// |
1950 |
return; |
return; |
1951 |
// |
// |
1954 |
}; |
}; |
1955 |
// |
// |
1956 |
if ( mistrail && rtlastev == lastev ) { // look for runtrailer (only when at the end of the file, if at the beginning and the runh is |
if ( mistrail && rtlastev == lastev ) { // look for runtrailer (only when at the end of the file, if at the beginning and the runh is |
1957 |
// missing it no way we can found a piece in the frag table |
// missing it no way we can found a piece in the frag table |
1958 |
// |
// |
1959 |
oss.str(""); |
oss.str(""); |
1960 |
oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN_FRAGMENTS WHERE " |
oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN_FRAGMENTS WHERE " |
1961 |
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " |
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " |
1962 |
<< " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() |
<< " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() << " AND " |
1963 |
|
<< " ID != " << glrun->ID |
1964 |
<< " ORDER BY RUNTRAILER_TIME ASC LIMIT 1;"; |
<< " ORDER BY RUNTRAILER_TIME ASC LIMIT 1;"; |
1965 |
// |
// |
1966 |
if ( IsDebug() ) printf(" look for runtrailer in the fragments table: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" look for runtrailer in the fragments table: query is \n %s \n",oss.str().c_str()); |
1970 |
// |
// |
1971 |
row = result->Next(); |
row = result->Next(); |
1972 |
// |
// |
1973 |
|
if ( !row && NoFrag() ){ |
1974 |
|
// |
1975 |
|
oss.str(""); |
1976 |
|
oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN WHERE " |
1977 |
|
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND " |
1978 |
|
<< " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() << " AND " |
1979 |
|
<< " ID != " << glrun->ID |
1980 |
|
<< " AND ID=ID_RUN_FRAG ORDER BY RUNTRAILER_TIME ASC LIMIT 1;"; |
1981 |
|
// |
1982 |
|
if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str()); |
1983 |
|
result = conn->Query(oss.str().c_str()); |
1984 |
|
// |
1985 |
|
if ( !result ) throw -4; |
1986 |
|
// |
1987 |
|
foundinrun = true; |
1988 |
|
row = result->Next(); |
1989 |
|
// |
1990 |
|
}; |
1991 |
|
// |
1992 |
if ( !row ){ |
if ( !row ){ |
1993 |
if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); |
if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n"); |
1994 |
found = false; |
found = false; |
2062 |
// |
// |
2063 |
if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); |
if ( IsDebug() ) printf(" now you can handle the piece of the run \n "); |
2064 |
// |
// |
2065 |
|
if ( foundinrun ){ |
2066 |
|
glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS"); |
2067 |
|
glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN"); |
2068 |
|
}; |
2069 |
|
// |
2070 |
GL_RUN *glrun1 = new GL_RUN(); |
GL_RUN *glrun1 = new GL_RUN(); |
2071 |
// |
// |
2072 |
UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); |
// UInt_t idfrag = (UInt_t)atoll(row->GetField(0)); |
2073 |
// |
// |
2074 |
oss.str(""); |
oss.str(""); |
2075 |
oss << " ID="<<row->GetField(0)<<";"; |
oss << " ID="<<row->GetField(0)<<";"; |
2125 |
// |
// |
2126 |
if ( !IsRunAlreadyInserted() ){ |
if ( !IsRunAlreadyInserted() ){ |
2127 |
// |
// |
2128 |
glrun->SetID(this->AssignRunID()); |
// glrun->SetID(this->AssignRunID()); |
2129 |
// |
// |
2130 |
glrun->SetID_RUN_FRAG(glrun1->GetID()); |
glrun->SetID_RUN_FRAG(glrun1->GetID()); |
2131 |
glrun->Fill_GL_RUN(conn); |
glrun->Fill_GL_RUN(conn); |
2132 |
// |
// |
2133 |
// get id number |
// set id number |
2134 |
// |
// |
|
// oss.str(""); |
|
|
// oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<<this->GetBOOTnumber()<<" AND " |
|
|
// << " RUNHEADER_OBT="<<glrun->GetRUNHEADER_OBT()<<" AND " |
|
|
// << " RUNTRAILER_OBT="<<glrun->GetRUNTRAILER_OBT()<<";"; |
|
|
// // |
|
|
// if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str()); |
|
|
// // |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// if ( !result ) throw -4; |
|
|
// row = result->Next(); |
|
|
// // |
|
|
// UInt_t idrun0 = 0; |
|
|
// if ( !row ){ |
|
|
// throw -10; |
|
|
// } else { |
|
|
// idrun0 = (UInt_t)atoll(row->GetField(0)); |
|
|
// }; |
|
|
// // |
|
|
// glrun1->SetID_RUN_FRAG(idrun0); |
|
|
// |
|
2135 |
glrun1->SetID_RUN_FRAG(glrun->GetID()); |
glrun1->SetID_RUN_FRAG(glrun->GetID()); |
2136 |
glrun1->Fill_GL_RUN(conn); |
glrun1->Fill_GL_RUN(conn); |
2137 |
// |
// |
|
// oss.str(""); |
|
|
// oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<<idrun0<<" ;"; |
|
|
// // |
|
|
// if ( IsDebug() ) printf(" search for idrun1 , query is : \n%s\n",oss.str().c_str()); |
|
|
// // |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// if ( !result ) throw -4; |
|
|
// row = result->Next(); |
|
|
// // |
|
|
// UInt_t idrun1 = 0; |
|
|
// if ( !row ){ |
|
|
// throw -10; |
|
|
// } else { |
|
|
// idrun1 = (UInt_t)atoll(row->GetField(0)); |
|
|
// }; |
|
|
// // |
|
|
// oss.str(""); |
|
|
// oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<<idrun1<<" WHERE ID="<<idrun0<<" ;"; |
|
|
// // |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// if ( !result ) throw -4; |
|
|
// |
|
2138 |
}; |
}; |
2139 |
// |
// |
2140 |
delete glrun1; |
// delete old entries in fragment table |
|
// |
|
|
// delete old entry in fragment table |
|
2141 |
// |
// |
2142 |
glrun->DeleteRun(conn,idfrag,"GL_RUN_FRAGMENTS"); |
glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
2143 |
// oss.str(""); |
glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
|
// // |
|
|
// oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";"; |
|
|
// // |
|
|
// if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str()); |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// if ( !result ) throw -4; |
|
2144 |
// |
// |
2145 |
|
delete glrun1; |
2146 |
// |
// |
2147 |
return; |
return; |
2148 |
// |
// |
2179 |
// |
// |
2180 |
row = result->Next(); |
row = result->Next(); |
2181 |
// |
// |
2182 |
if ( !row ){ |
if ( row ){ |
|
// |
|
|
oss.str(""); |
|
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE " |
|
|
<< " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND (" |
|
|
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
|
|
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
|
|
<< " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " |
|
|
<< " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
|
|
<< " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " |
|
|
<< " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " |
|
|
<< " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
|
|
<< " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" |
|
|
<< " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " |
|
|
<< " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
|
|
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
|
|
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
// |
|
|
if ( !result ) throw -4; |
|
|
// |
|
|
row = result->Next(); |
|
|
// |
|
|
if ( !row ){ |
|
|
// |
|
|
// no, insert this run in the GL_RUN_FRAGMENTS table (check if exist before!) |
|
|
// |
|
|
if ( IsDebug() ) printf(" The run is new \n"); |
|
|
if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n"); |
|
|
// |
|
|
glrun->SetID(this->AssignRunID()); |
|
|
glrun->SetID_RUN_FRAG(0); |
|
|
glrun->Fill_GL_RUN_FRAGMENTS(conn); |
|
|
// |
|
|
} else { |
|
|
if ( IsDebug() ) printf(" The run is already present in the fragment table \n"); |
|
|
}; |
|
|
} else { |
|
2183 |
if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); |
if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n"); |
2184 |
|
} else { |
2185 |
|
if ( NoFrag() ){ |
2186 |
|
glrun->SetID_RUN_FRAG(glrun->GetID()); |
2187 |
|
glrun->Fill_GL_RUN(conn); |
2188 |
|
glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS"); |
2189 |
|
}; |
2190 |
}; |
}; |
2191 |
}; |
}; |
2192 |
// |
// |
3321 |
* Scan the fragment table and move old fragments to the GL_RUN table |
* Scan the fragment table and move old fragments to the GL_RUN table |
3322 |
*/ |
*/ |
3323 |
Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){ |
Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){ |
3324 |
|
return(this->CleanGL_RUN_FRAGMENTS("")); |
3325 |
|
}; |
3326 |
|
|
3327 |
|
/** |
3328 |
|
* Scan the fragment table and move old fragments to the GL_RUN table |
3329 |
|
*/ |
3330 |
|
Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(TString fcleanfile){ |
3331 |
// |
// |
3332 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
3333 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
3335 |
TSQLRow *row2 = 0; |
TSQLRow *row2 = 0; |
3336 |
// |
// |
3337 |
UInt_t moved = 0; |
UInt_t moved = 0; |
|
// UInt_t timelim = 0; |
|
|
// TDatime *time = new TDatime(); |
|
3338 |
// |
// |
3339 |
stringstream oss; |
stringstream oss; |
3340 |
oss.str(""); |
oss.str(""); |
3341 |
// |
// |
3342 |
// |
if ( !strcmp(fcleanfile.Data(),"") ){ |
3343 |
// check if there are entries older than "olderthan" seconds from now |
// |
3344 |
// |
// check if there are entries older than "olderthan" seconds from now |
3345 |
oss.str(""); |
// |
3346 |
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
oss.str(""); |
3347 |
<< " INSERT_TIME <= '" << clean_time->AsSQLString() << "';"; |
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
3348 |
// |
<< " INSERT_TIME <= '" << clean_time->AsSQLString() << "';"; |
3349 |
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str()); |
// |
3350 |
result = conn->Query(oss.str().c_str()); |
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str()); |
3351 |
|
result = conn->Query(oss.str().c_str()); |
3352 |
|
// |
3353 |
|
} else { |
3354 |
|
oss.str(""); |
3355 |
|
oss << " SELECT ID FROM GL_ROOT WHERE NAME='" << fcleanfile.Data() << "';"; |
3356 |
|
if ( IsDebug() ) printf(" Getting ID_ROOT_L0 query %s \n",oss.str().c_str()); |
3357 |
|
result = conn->Query(oss.str().c_str()); |
3358 |
|
// |
3359 |
|
if ( result ){ |
3360 |
|
// |
3361 |
|
row = result->Next(); |
3362 |
|
// |
3363 |
|
if ( row ){ |
3364 |
|
oss.str(""); |
3365 |
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
3366 |
|
<< " ID_ROOT_L0=" << row->GetField(0) << ";"; |
3367 |
|
// |
3368 |
|
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS for ROOT file query is \n %s \n",oss.str().c_str()); |
3369 |
|
result = conn->Query(oss.str().c_str()); |
3370 |
|
// |
3371 |
|
}; |
3372 |
|
} else { |
3373 |
|
return(2); |
3374 |
|
}; |
3375 |
|
}; |
3376 |
// |
// |
3377 |
if ( result ){ |
if ( result ){ |
3378 |
// |
// |
3468 |
* Check if runs are good, i.e. if the tracker calibration is correctly associated.. |
* Check if runs are good, i.e. if the tracker calibration is correctly associated.. |
3469 |
*/ |
*/ |
3470 |
Int_t PamelaDBOperations::ValidateRuns(){ |
Int_t PamelaDBOperations::ValidateRuns(){ |
3471 |
|
return(this->ValidateRuns("")); |
3472 |
|
}; |
3473 |
|
|
3474 |
|
/** |
3475 |
|
* Check if runs are good, i.e. if the tracker calibration is correctly associated.. |
3476 |
|
*/ |
3477 |
|
Int_t PamelaDBOperations::ValidateRuns(TString valfile){ |
3478 |
// |
// |
3479 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
3480 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
3481 |
// |
// |
3482 |
|
UInt_t calibtime = 50; |
3483 |
|
// |
3484 |
stringstream oss; |
stringstream oss; |
3485 |
oss.str(""); |
oss.str(""); |
3486 |
// |
// |
3489 |
// ======================================================= |
// ======================================================= |
3490 |
UInt_t t_stop = 0; |
UInt_t t_stop = 0; |
3491 |
UInt_t t_start = 0; |
UInt_t t_start = 0; |
3492 |
// -------------------------------------------------------------- |
if ( !strcmp(valfile.Data(),"") ) { |
3493 |
// 1) get the OBT of the last run inserted after clean-time limit |
// -------------------------------------------------------------- |
3494 |
// -------------------------------------------------------------- |
// 1) get the OBT of the last run inserted after clean-time limit |
3495 |
oss.str(""); |
// -------------------------------------------------------------- |
3496 |
oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << clean_time->AsSQLString() |
oss.str(""); |
3497 |
<< "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << clean_time->AsSQLString() |
3498 |
if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str()); |
<< "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3499 |
result = conn->Query(oss.str().c_str()); |
if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str()); |
3500 |
if ( !result ) throw -4; |
result = conn->Query(oss.str().c_str()); |
3501 |
if ( !result->GetRowCount() ) { |
if ( !result ) throw -4; |
3502 |
printf(" No runs to validate \n"); |
if ( !result->GetRowCount() ) { |
3503 |
return(1); |
printf(" No runs to validate \n"); |
3504 |
}else{ |
return(1); |
3505 |
row = result->Next(); |
}else{ |
3506 |
t_start = (UInt_t)atoll(row->GetField(4)); |
row = result->Next(); |
3507 |
}; |
t_start = (UInt_t)atoll(row->GetField(4)); |
3508 |
// -------------------------------------------------------------- |
}; |
3509 |
// 2) get the OBT of the last validated run |
// -------------------------------------------------------------- |
3510 |
// -------------------------------------------------------------- |
// 2) get the OBT of the last validated run |
3511 |
oss.str(""); |
// -------------------------------------------------------------- |
3512 |
oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
oss.str(""); |
3513 |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
3514 |
if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3515 |
result = conn->Query(oss.str().c_str()); |
if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
3516 |
if ( !result ) throw -4; |
result = conn->Query(oss.str().c_str()); |
3517 |
if ( result->GetRowCount() ){ |
if ( !result ) throw -4; |
3518 |
row = result->Next(); |
if ( result->GetRowCount() ){ |
3519 |
t_stop = (UInt_t)atoll(row->GetField(4)); |
row = result->Next(); |
3520 |
|
t_stop = (UInt_t)atoll(row->GetField(4)); |
3521 |
|
}; |
3522 |
|
if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start); |
3523 |
|
// -------------------------------------------------------------- |
3524 |
|
// now retrieves runs to be validated |
3525 |
|
// -------------------------------------------------------------- |
3526 |
|
oss.str(""); |
3527 |
|
oss << " SELECT * FROM GL_RUN WHERE RUNHEADER_TIME <=" << t_start; |
3528 |
|
oss << " AND RUNHEADER_TIME >="<< t_stop; |
3529 |
|
oss << " ORDER BY RUNHEADER_TIME DESC;"; |
3530 |
|
if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str()); |
3531 |
|
result = conn->Query(oss.str().c_str()); |
3532 |
|
} else { |
3533 |
|
// |
3534 |
|
stringstream myquery; |
3535 |
|
UInt_t myid = 0; |
3536 |
|
myquery.str(""); |
3537 |
|
myquery << " SELECT ID FROM GL_ROOT where NAME='"<<valfile.Data() <<"';"; |
3538 |
|
// |
3539 |
|
result = conn->Query(myquery.str().c_str()); |
3540 |
|
// |
3541 |
|
row = result->Next(); |
3542 |
|
if( !row ){ |
3543 |
|
if ( strcmp(valfile.Data(),GetRootName().Data()) ){ |
3544 |
|
if ( IsDebug() ) printf(" No file to be validated even if option \"-validate file\" was used!!\n"); |
3545 |
|
return(2); |
3546 |
|
}; |
3547 |
|
if ( IsDebug() ) printf(" No file to be validated (force mode)! \n"); |
3548 |
|
return(0); |
3549 |
|
}; |
3550 |
|
myid=(UInt_t)atoll(row->GetField(0)); |
3551 |
|
// |
3552 |
|
myquery.str(""); |
3553 |
|
myquery << " SELECT MAX(RUNTRAILER_TIME),MIN(RUNHEADER_TIME) FROM GL_RUN WHERE ID_ROOT_L0="<< myid <<";"; |
3554 |
|
// |
3555 |
|
result = conn->Query(myquery.str().c_str()); |
3556 |
|
// |
3557 |
|
row = result->Next(); |
3558 |
|
if( !row->GetField(0) || !row->GetField(1)){ |
3559 |
|
// |
3560 |
|
if ( IsDebug() ) printf(" NO RUN ASSOCIATED TO THIS FILE! \n"); |
3561 |
|
// |
3562 |
|
return(0); |
3563 |
|
// |
3564 |
|
} else { |
3565 |
|
// |
3566 |
|
UInt_t runhtime = (UInt_t)atoll(row->GetField(0)); |
3567 |
|
UInt_t runttime = (UInt_t)atoll(row->GetField(1)); |
3568 |
|
UInt_t caltime = 0; |
3569 |
|
// |
3570 |
|
myquery.str(""); |
3571 |
|
myquery << " SELECT FROM_TIME FROM GL_TRK_CALIB where FROM_TIME>" <<runhtime; |
3572 |
|
myquery << " order by FROM_TIME asc limit 1;"; |
3573 |
|
// |
3574 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
3575 |
|
// |
3576 |
|
// |
3577 |
|
result = conn->Query(myquery.str().c_str()); |
3578 |
|
// |
3579 |
|
row = result->Next(); |
3580 |
|
if( !row ){ |
3581 |
|
caltime = runhtime; |
3582 |
|
} else { |
3583 |
|
caltime = (UInt_t)atoll(row->GetField(0)); |
3584 |
|
}; |
3585 |
|
// |
3586 |
|
myquery.str(""); |
3587 |
|
myquery << " SELECT * from GL_RUN where RUNHEADER_TIME>="<< runttime <<" AND RUNHEADER_TIME<=" ; |
3588 |
|
myquery << caltime << " order by RUNHEADER_TIME DESC"; |
3589 |
|
// |
3590 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
3591 |
|
// |
3592 |
|
result = conn->Query(myquery.str().c_str()); |
3593 |
|
// |
3594 |
|
}; |
3595 |
}; |
}; |
3596 |
if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start); |
// |
|
// -------------------------------------------------------------- |
|
|
// now retrieves runs to be validated |
|
|
// -------------------------------------------------------------- |
|
|
oss.str(""); |
|
|
oss << " SELECT * FROM GL_RUN WHERE RUNHEADER_TIME <=" << t_start; |
|
|
oss << " AND RUNHEADER_TIME >="<< t_stop; |
|
|
oss << " ORDER BY RUNHEADER_TIME DESC;"; |
|
|
// if ( IsDebug() ) |
|
|
if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
3597 |
if ( !result ) throw -4; |
if ( !result ) throw -4; |
3598 |
if ( !result->GetRowCount() ) printf(" No runs to validate \n"); |
if ( !result->GetRowCount() && IsDebug() ) printf(" No runs to validate \n"); |
3599 |
// printf("------------------------------------------------------------------------------- \n"); |
// |
|
|
|
3600 |
Int_t nrow = 0; |
Int_t nrow = 0; |
3601 |
GL_RUN* this_run = new GL_RUN(); |
GL_RUN* this_run = new GL_RUN(); |
3602 |
GL_RUN* next_run = new GL_RUN(); |
GL_RUN* next_run = new GL_RUN(); |
3610 |
UInt_t t1=0,t2=0; |
UInt_t t1=0,t2=0; |
3611 |
// --------------------------------------------------------------------------------- |
// --------------------------------------------------------------------------------- |
3612 |
// - loop over runs, back in time, |
// - loop over runs, back in time, |
3613 |
// - select sequences of runs close in time (less than 60 s apart), |
// - select sequences of runs close in time (less than calibtime s apart), |
3614 |
// which could be preceeded by a calibration |
// which could be preceeded by a calibration |
3615 |
// - check if there might be a missing calibration |
// - check if there might be a missing calibration |
3616 |
// --------------------------------------------------------------------------------- |
// --------------------------------------------------------------------------------- |
3650 |
|
|
3651 |
if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0; //=> run fragments |
if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0; //=> run fragments |
3652 |
|
|
3653 |
if( interval >= 60 )CHECK = true; //more than 60 s => there might be a calibration |
if( interval >= calibtime )CHECK = true; //more than calibtime s => there might be a calibration |
3654 |
|
|
3655 |
if( !CHECK && this_run->VALIDATION ){ |
if( !CHECK && this_run->VALIDATION ){ |
3656 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
3848 |
|
|
3849 |
|
|
3850 |
// Insert tle in the table GL_TLE using the connection conn. |
// Insert tle in the table GL_TLE using the connection conn. |
3851 |
int PamelaDBOperations::insertTle(cTle *tle) |
Int_t PamelaDBOperations::insertTle(cTle *tle) |
3852 |
{ |
{ |
3853 |
stringstream oss; |
stringstream oss; |
3854 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
3931 |
|
|
3932 |
return date.str(); |
return date.str(); |
3933 |
} |
} |
3934 |
|
|
3935 |
|
/** |
3936 |
|
* Remove a file from the DB, delete on cascade all entries related to that file |
3937 |
|
* rearrange GL_RUN and GL_XXX_CALIB tables, turn off validation till the following |
3938 |
|
* calibration |
3939 |
|
**/ |
3940 |
|
Int_t PamelaDBOperations::removeFile(TString remfile){ |
3941 |
|
// |
3942 |
|
// Determine ID_ROOT_L0 and ID_RAW |
3943 |
|
// |
3944 |
|
TSQLResult *pResult; |
3945 |
|
TSQLRow *Row; |
3946 |
|
stringstream myquery; |
3947 |
|
// |
3948 |
|
myquery.str(""); |
3949 |
|
myquery << " SELECT ID, ID_RAW FROM GL_ROOT where NAME='"<<remfile.Data() <<"';"; |
3950 |
|
// |
3951 |
|
pResult = conn->Query(myquery.str().c_str()); |
3952 |
|
// |
3953 |
|
Row = pResult->Next(); |
3954 |
|
if( !Row ){ |
3955 |
|
if ( strcmp(remfile.Data(),GetRootName().Data()) ){ |
3956 |
|
if ( IsDebug() ) printf(" No file to be removed even if option \"-remove file\" was used!!\n"); |
3957 |
|
return(1); |
3958 |
|
}; |
3959 |
|
if ( IsDebug() ) printf(" No file to be removed (force mode)! \n"); |
3960 |
|
return(0); |
3961 |
|
}; |
3962 |
|
// |
3963 |
|
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
3964 |
|
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
3965 |
|
// |
3966 |
|
this->ValidationOFF(); |
3967 |
|
// |
3968 |
|
this->RemoveCALIBS(); |
3969 |
|
// |
3970 |
|
this->RemoveRUNS(); |
3971 |
|
// |
3972 |
|
this->RemoveFILES(); |
3973 |
|
// |
3974 |
|
this->SetID_ROOT(0); |
3975 |
|
this->SetID_RAW(0); |
3976 |
|
// |
3977 |
|
return(0); |
3978 |
|
}; |
3979 |
|
|
3980 |
|
/** |
3981 |
|
* |
3982 |
|
* Set validation bit to zero for runs following the removing file till |
3983 |
|
* 1) a run with TRK_CALIB_USED=140 |
3984 |
|
* 2) a run with VALIDATION = 0 |
3985 |
|
* 3) the next calibration |
3986 |
|
* |
3987 |
|
**/ |
3988 |
|
void PamelaDBOperations::ValidationOFF(){ |
3989 |
|
TSQLResult *pResult; |
3990 |
|
TSQLRow *Row; |
3991 |
|
stringstream myquery; |
3992 |
|
Int_t unv = 0; |
3993 |
|
//select ID from GL_RUN where RUNHEADER_TIME>=1152671382 AND (VALIDATION=0 OR TRK_CALIB_USED=104) order by RUNHEADER_TIME asc limit 1; |
3994 |
|
myquery.str(""); |
3995 |
|
myquery << " SELECT MAX(RUNTRAILER_TIME) FROM GL_RUN WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";"; |
3996 |
|
// |
3997 |
|
pResult = conn->Query(myquery.str().c_str()); |
3998 |
|
// |
3999 |
|
Row = pResult->Next(); |
4000 |
|
if( !Row->GetField(0) ){ |
4001 |
|
// |
4002 |
|
if ( IsDebug() ) printf(" NO RUN ASSOCIATED TO THIS FILE! \n"); |
4003 |
|
// |
4004 |
|
} else { |
4005 |
|
// |
4006 |
|
UInt_t runhtime = (UInt_t)atoll(Row->GetField(0)); |
4007 |
|
UInt_t caltime = 0; |
4008 |
|
// |
4009 |
|
myquery.str(""); |
4010 |
|
myquery << " SELECT FROM_TIME FROM GL_TRK_CALIB where FROM_TIME>" <<runhtime; |
4011 |
|
myquery << " order by FROM_TIME asc limit 1;"; |
4012 |
|
// |
4013 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
4014 |
|
// |
4015 |
|
// |
4016 |
|
delete pResult; |
4017 |
|
pResult = conn->Query(myquery.str().c_str()); |
4018 |
|
// |
4019 |
|
Row = pResult->Next(); |
4020 |
|
if( !Row ){ |
4021 |
|
caltime = runhtime; |
4022 |
|
} else { |
4023 |
|
caltime = (UInt_t)atoll(Row->GetField(0)); |
4024 |
|
}; |
4025 |
|
// |
4026 |
|
myquery.str(""); |
4027 |
|
myquery << " SELECT ID,RUNHEADER_TIME from GL_RUN where RUNHEADER_TIME>="<< runhtime <<" AND (VALIDATION=0 OR TRK_CALIB_USED=104 OR RUNHEADER_TIME>" ; |
4028 |
|
myquery << caltime << ") order by RUNHEADER_TIME asc LIMIT 1"; |
4029 |
|
// |
4030 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
4031 |
|
// |
4032 |
|
pResult = conn->Query(myquery.str().c_str()); |
4033 |
|
// |
4034 |
|
Row = pResult->Next(); |
4035 |
|
if( !Row ){ |
4036 |
|
// |
4037 |
|
if ( IsDebug() ) printf(" NO RUN NEED TO BE UNVALIDATED \n"); |
4038 |
|
// |
4039 |
|
} else { |
4040 |
|
myquery.str(""); |
4041 |
|
myquery << " SELECT ID from GL_RUN where RUNHEADER_TIME<"<< Row->GetField(1) <<" AND "; |
4042 |
|
myquery << " RUNHEADER_TIME>=" <<runhtime; |
4043 |
|
myquery << " order by RUNHEADER_TIME asc;"; |
4044 |
|
// |
4045 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
4046 |
|
// |
4047 |
|
pResult = conn->Query(myquery.str().c_str()); |
4048 |
|
// |
4049 |
|
Row = pResult->Next(); |
4050 |
|
while ( Row ){ |
4051 |
|
// |
4052 |
|
unv++; |
4053 |
|
this->assignVALIDATION((UInt_t)atoll(Row->GetField(0)), false); |
4054 |
|
Row = pResult->Next(); |
4055 |
|
// |
4056 |
|
}; |
4057 |
|
}; |
4058 |
|
}; |
4059 |
|
if ( IsDebug() ) printf(" %i runs have been unvalidated \n",unv); |
4060 |
|
}; |
4061 |
|
|
4062 |
|
/** |
4063 |
|
* |
4064 |
|
* Rearrange GL_RUN table and remove runs |
4065 |
|
* |
4066 |
|
**/ |
4067 |
|
void PamelaDBOperations::RemoveRUNS(){ |
4068 |
|
TSQLResult *pResult; |
4069 |
|
TSQLRow *Row; |
4070 |
|
stringstream myquery; |
4071 |
|
UInt_t drun = 0; |
4072 |
|
GL_RUN *delrun = new GL_RUN(); |
4073 |
|
// |
4074 |
|
myquery.str(""); |
4075 |
|
myquery << " SELECT ID FROM GL_RUN where ID_RUN_FRAG=0 and ID_ROOT_L0=" <<this->GetID_ROOT() <<";"; |
4076 |
|
// |
4077 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
4078 |
|
// |
4079 |
|
pResult = conn->Query(myquery.str().c_str()); |
4080 |
|
// |
4081 |
|
Row = pResult->Next(); |
4082 |
|
// |
4083 |
|
// |
4084 |
|
if ( !Row ){ |
4085 |
|
if ( IsDebug() ) printf(" No run with ID_RUN_FRAG=0 belonged to this file \n"); |
4086 |
|
} else { |
4087 |
|
if ( IsDebug() ) printf(" Deleting run from GL_RUN table \n"); |
4088 |
|
while ( Row ){ |
4089 |
|
delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN"); |
4090 |
|
if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0))); |
4091 |
|
drun++; |
4092 |
|
Row = pResult->Next(); |
4093 |
|
}; |
4094 |
|
}; |
4095 |
|
// |
4096 |
|
// |
4097 |
|
myquery.str(""); |
4098 |
|
myquery << " SELECT ID,ID_RUN_FRAG FROM GL_RUN where ID_RUN_FRAG!=0 and ID_ROOT_L0=" <<this->GetID_ROOT() <<";"; |
4099 |
|
// |
4100 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
4101 |
|
// |
4102 |
|
pResult = conn->Query(myquery.str().c_str()); |
4103 |
|
// |
4104 |
|
Row = pResult->Next(); |
4105 |
|
// |
4106 |
|
if ( !Row ){ |
4107 |
|
if ( IsDebug() ) printf(" No run with ID_RUN_FRAG!=0 belonged to this file \n"); |
4108 |
|
} else { |
4109 |
|
if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN table \n"); |
4110 |
|
while ( Row ){ |
4111 |
|
if ( IsDebug() ) printf(" restore run %i \n",(UInt_t)atoll(Row->GetField(1))); |
4112 |
|
delrun->RestoreRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN_FRAGMENTS"); |
4113 |
|
if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(1))); |
4114 |
|
delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN"); |
4115 |
|
if ( (UInt_t)atoll(Row->GetField(1)) != (UInt_t)atoll(Row->GetField(0)) ){ |
4116 |
|
if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0))); |
4117 |
|
delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN"); |
4118 |
|
}; |
4119 |
|
drun++; |
4120 |
|
Row = pResult->Next(); |
4121 |
|
}; |
4122 |
|
}; |
4123 |
|
// |
4124 |
|
if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN table \n",drun); |
4125 |
|
// |
4126 |
|
// |
4127 |
|
// |
4128 |
|
drun = 0; |
4129 |
|
// |
4130 |
|
myquery.str(""); |
4131 |
|
myquery << " SELECT ID_TRASH FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID_ROOT_L0=" <<this->GetID_ROOT() <<";"; |
4132 |
|
// |
4133 |
|
pResult = conn->Query(myquery.str().c_str()); |
4134 |
|
// |
4135 |
|
Row = pResult->Next(); |
4136 |
|
// |
4137 |
|
if ( !Row ){ |
4138 |
|
if ( IsDebug() ) printf(" No run from GL_RUN_FRAGMENTS table in the trash table for this file \n"); |
4139 |
|
} else { |
4140 |
|
if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_TRASH table \n"); |
4141 |
|
while ( Row ){ |
4142 |
|
if ( IsDebug() ) printf(" del run idtrash %i \n",(UInt_t)atoll(Row->GetField(0))); |
4143 |
|
myquery.str(""); |
4144 |
|
myquery << " DELETE FROM GL_RUN_TRASH where ID_TRASH=" << Row->GetField(0) <<";"; |
4145 |
|
conn->Query(myquery.str().c_str()); |
4146 |
|
drun++; |
4147 |
|
Row = pResult->Next(); |
4148 |
|
}; |
4149 |
|
}; |
4150 |
|
// |
4151 |
|
if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_TRASH table \n",drun); |
4152 |
|
// |
4153 |
|
// |
4154 |
|
// |
4155 |
|
drun = 0; |
4156 |
|
// |
4157 |
|
myquery.str(""); |
4158 |
|
myquery << " SELECT ID FROM GL_RUN_FRAGMENTS where ID_ROOT_L0=" <<this->GetID_ROOT() <<";"; |
4159 |
|
// |
4160 |
|
pResult = conn->Query(myquery.str().c_str()); |
4161 |
|
// |
4162 |
|
Row = pResult->Next(); |
4163 |
|
// |
4164 |
|
if ( !Row ){ |
4165 |
|
if ( IsDebug() ) printf(" No run in the GL_RUN_FRAGMENTS table for this file \n"); |
4166 |
|
} else { |
4167 |
|
if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_FRAGMENTS table \n"); |
4168 |
|
while ( Row ){ |
4169 |
|
if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0))); |
4170 |
|
myquery.str(""); |
4171 |
|
myquery << " DELETE FROM GL_RUN_FRAGMENTS where ID=" << Row->GetField(0) <<";"; |
4172 |
|
conn->Query(myquery.str().c_str()); |
4173 |
|
drun++; |
4174 |
|
Row = pResult->Next(); |
4175 |
|
}; |
4176 |
|
}; |
4177 |
|
// |
4178 |
|
if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_FRAGMENTS table \n",drun); |
4179 |
|
// |
4180 |
|
// |
4181 |
|
// |
4182 |
|
delete delrun; |
4183 |
|
// |
4184 |
|
}; |
4185 |
|
|
4186 |
|
|
4187 |
|
/** |
4188 |
|
* |
4189 |
|
* Rearrange calibration tables |
4190 |
|
* |
4191 |
|
**/ |
4192 |
|
void PamelaDBOperations::RemoveFILES(){ |
4193 |
|
stringstream myquery; |
4194 |
|
// |
4195 |
|
myquery.str(""); |
4196 |
|
myquery << " DELETE FROM GL_RAW WHERE ID=" <<this->GetID_RAW() <<";"; |
4197 |
|
// |
4198 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
4199 |
|
// |
4200 |
|
conn->Query(myquery.str().c_str()); |
4201 |
|
// |
4202 |
|
}; |
4203 |
|
|
4204 |
|
/** |
4205 |
|
* |
4206 |
|
* Rearrange calibration tables |
4207 |
|
* |
4208 |
|
**/ |
4209 |
|
void PamelaDBOperations::RemoveCALIBS(){ |
4210 |
|
TSQLResult *pResult; |
4211 |
|
TSQLRow *Row; |
4212 |
|
stringstream myquery; |
4213 |
|
// |
4214 |
|
// |
4215 |
|
// Calorimeter |
4216 |
|
// |
4217 |
|
for (Int_t section = 0; section < 4; section++){ |
4218 |
|
myquery.str(""); |
4219 |
|
myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_CALO_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<" AND "; |
4220 |
|
myquery << " SECTION=" << section << ";"; |
4221 |
|
// |
4222 |
|
pResult = conn->Query(myquery.str().c_str()); |
4223 |
|
// |
4224 |
|
Row = pResult->Next(); |
4225 |
|
if( !Row->GetField(0) || !Row->GetField(1) ){ |
4226 |
|
// |
4227 |
|
if ( IsDebug() ) printf(" NO CALO CALIBRATION SECTION %i ASSOCIATED TO THIS FILE! \n",section); |
4228 |
|
// |
4229 |
|
} else { |
4230 |
|
// |
4231 |
|
myquery.str(""); |
4232 |
|
myquery << " UPDATE GL_CALO_CALIB SET TO_TIME=" << Row->GetField(1); |
4233 |
|
myquery << " WHERE TO_TIME="<< Row->GetField(0) << " AND "; |
4234 |
|
myquery << " SECTION=" << section << ";"; |
4235 |
|
// |
4236 |
|
pResult = conn->Query(myquery.str().c_str()); |
4237 |
|
// |
4238 |
|
if( !pResult ){ |
4239 |
|
// |
4240 |
|
if ( IsDebug() ) printf(" ERROR DELETING CALO CALIBRATIONS \n"); |
4241 |
|
// |
4242 |
|
throw -4; |
4243 |
|
// |
4244 |
|
}; |
4245 |
|
// |
4246 |
|
}; |
4247 |
|
}; |
4248 |
|
myquery.str(""); |
4249 |
|
myquery << " DELETE FROM GL_CALO_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT(); |
4250 |
|
// |
4251 |
|
pResult = conn->Query(myquery.str().c_str()); |
4252 |
|
// |
4253 |
|
if( !pResult ){ |
4254 |
|
// |
4255 |
|
if ( IsDebug() ) printf(" ERROR DELETING CALO CALIBRATIONS \n"); |
4256 |
|
// |
4257 |
|
throw -4; |
4258 |
|
// |
4259 |
|
}; |
4260 |
|
// |
4261 |
|
// Tracker |
4262 |
|
// |
4263 |
|
myquery.str(""); |
4264 |
|
myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_TRK_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";"; |
4265 |
|
// |
4266 |
|
pResult = conn->Query(myquery.str().c_str()); |
4267 |
|
// |
4268 |
|
Row = pResult->Next(); |
4269 |
|
if( !Row->GetField(0) || !Row->GetField(1) ){ |
4270 |
|
// |
4271 |
|
if ( IsDebug() ) printf(" NO TRK CALIBRATION ASSOCIATED TO THIS FILE! \n"); |
4272 |
|
// |
4273 |
|
} else { |
4274 |
|
// |
4275 |
|
myquery.str(""); |
4276 |
|
myquery << " UPDATE GL_TRK_CALIB SET TO_TIME=" << Row->GetField(1); |
4277 |
|
myquery << " WHERE TO_TIME="<< Row->GetField(0) << ";"; |
4278 |
|
// |
4279 |
|
pResult = conn->Query(myquery.str().c_str()); |
4280 |
|
// |
4281 |
|
if( !pResult ){ |
4282 |
|
// |
4283 |
|
if ( IsDebug() ) printf(" ERROR DELETING TRK CALIBRATIONS \n"); |
4284 |
|
// |
4285 |
|
throw -4; |
4286 |
|
// |
4287 |
|
}; |
4288 |
|
// |
4289 |
|
myquery.str(""); |
4290 |
|
myquery << " DELETE FROM GL_TRK_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT(); |
4291 |
|
// |
4292 |
|
pResult = conn->Query(myquery.str().c_str()); |
4293 |
|
// |
4294 |
|
if( !pResult ){ |
4295 |
|
// |
4296 |
|
if ( IsDebug() ) printf(" ERROR DELETING TRK CALIBRATIONS \n"); |
4297 |
|
// |
4298 |
|
throw -4; |
4299 |
|
// |
4300 |
|
}; |
4301 |
|
}; |
4302 |
|
// |
4303 |
|
// |
4304 |
|
// S4 |
4305 |
|
// |
4306 |
|
myquery.str(""); |
4307 |
|
myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_S4_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";"; |
4308 |
|
// |
4309 |
|
pResult = conn->Query(myquery.str().c_str()); |
4310 |
|
// |
4311 |
|
Row = pResult->Next(); |
4312 |
|
if( !Row->GetField(0) || !Row->GetField(1) ){ |
4313 |
|
// |
4314 |
|
if ( IsDebug() ) printf(" NO S4 CALIBRATION ASSOCIATED TO THIS FILE! \n"); |
4315 |
|
// |
4316 |
|
} else { |
4317 |
|
// |
4318 |
|
myquery.str(""); |
4319 |
|
myquery << " UPDATE GL_S4_CALIB SET TO_TIME=" << Row->GetField(1); |
4320 |
|
myquery << " WHERE TO_TIME="<< Row->GetField(0) << ";"; |
4321 |
|
// |
4322 |
|
pResult = conn->Query(myquery.str().c_str()); |
4323 |
|
// |
4324 |
|
if( !pResult ){ |
4325 |
|
// |
4326 |
|
if ( IsDebug() ) printf(" ERROR DELETING S4 CALIBRATIONS \n"); |
4327 |
|
// |
4328 |
|
throw -4; |
4329 |
|
// |
4330 |
|
}; |
4331 |
|
// |
4332 |
|
myquery.str(""); |
4333 |
|
myquery << " DELETE FROM GL_S4_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT(); |
4334 |
|
// |
4335 |
|
pResult = conn->Query(myquery.str().c_str()); |
4336 |
|
// |
4337 |
|
if( !pResult ){ |
4338 |
|
// |
4339 |
|
if ( IsDebug() ) printf(" ERROR DELETING S4 CALIBRATIONS \n"); |
4340 |
|
// |
4341 |
|
throw -4; |
4342 |
|
// |
4343 |
|
}; |
4344 |
|
// |
4345 |
|
}; |
4346 |
|
}; |