3 #include <pdbcalbase/RunToTime.h>
8 #include <odbc++/connection.h>
9 #include <odbc++/drivermanager.h>
10 #include <odbc++/resultset.h>
11 #include <odbc++/statement.h>
12 #include <odbc++/types.h>
38 mySpecificCopy =
nullptr;
40 while (beginruntimes.begin() != beginruntimes.end())
42 delete beginruntimes.begin()->second;
43 beginruntimes.erase(beginruntimes.begin());
45 while (endruntimes.begin() != endruntimes.end())
47 delete endruntimes.begin()->second;
48 endruntimes.erase(endruntimes.begin());
60 __instance = mySpecificCopy;
70 con = DriverManager::getConnection(
"daq",
"phnxrc",
"");
72 catch (SQLException&
e)
75 <<
" Fatal Exception caught during DriverManager::getConnection" << endl;
76 cout <<
"Message: " << e.getMessage() << endl;
96 Statement* stmt = con->createStatement();
98 std::ostringstream cmd;
99 cmd <<
"select brunixtime,erunixtime,updateunixtime from run where runnumber = " << runNumber
104 cout << cmd.str() << endl;
108 ResultSet* rs =
nullptr;
111 rs = stmt->executeQuery(cmd.str());
113 catch (SQLException&
e)
115 cout <<
"Fatal Exception caught during stmt->executeQuery(" << cmd.str() <<
")" << endl;
116 cout <<
"Message: " << e.getMessage() << endl;
131 map<const int, PHTimeStamp*>::reverse_iterator iter = beginruntimes.rbegin();
134 int delrun = iter->first;
136 beginruntimes.erase(delrun);
137 map<const int, PHTimeStamp*>::iterator iter2;
138 iter2 = endruntimes.find(delrun);
139 if (iter2 != endruntimes.end())
141 delete iter2->second;
142 endruntimes.erase(iter2);
148 whatTime =
new PHTimeStamp(rs->getInt(
"brunixtime"));
150 catch (SQLException& e)
152 cout <<
"Fatal Exception caught during rs->getInt(\"brunixtime\")" << endl;
153 cout <<
"Message: " << e.getMessage() << endl;
156 beginruntimes[runNumber] = whatTime;
160 unsigned int eruntics = rs->getInt(
"erunixtime");
164 eruntics = rs->getInt(
"updateunixtime");
168 catch (SQLException& e)
170 cout <<
"Fatal Exception caught during rs->getInt(\"brunixtime\")" << endl;
171 cout <<
"Message: " << e.getMessage() << endl;
174 endruntimes[runNumber] = whatTime;
175 if (what ==
"brunixtime")
178 return beginruntimes[runNumber];
180 else if (what ==
"erunixtime")
183 return endruntimes[runNumber];
187 cout <<
"invalid time selection " << what << endl;
199 map<const int, PHTimeStamp*>::const_iterator iter = beginruntimes.find(runNumber);
200 if (iter == beginruntimes.end())
202 BeginRunTime = getTime(runNumber,
"brunixtime");
206 BeginRunTime = iter->second;
220 map<const int, PHTimeStamp*>::const_iterator iter = endruntimes.find(runNumber);
221 if (iter == endruntimes.end())
223 EndRunTime = getTime(runNumber,
"erunixtime");
227 EndRunTime = iter->second;
240 Statement* stmt = con->createStatement();
243 std::ostringstream cmd;
245 Timestamp timestp(ts.
getTics());
249 cmd <<
"select runnumber from run where brunixtime <= " << tics
250 <<
" order by runnumber desc limit 1";
253 ResultSet* rs =
nullptr;
256 rs = stmt->executeQuery(cmd.str().c_str());
258 catch (SQLException&
e)
260 cout <<
"Fatal Exception caught during stmt->executeQuery(" << cmd.str() <<
")" << endl;
261 cout <<
"Message: " << e.getMessage() << endl;
270 runnumber = rs->getInt(
"runnumber");
279 cmd <<
"select erunixtime from run where runnumber = " << runnumber;
283 rs = stmt->executeQuery(cmd.str().c_str());
285 catch (SQLException& e)
287 cout <<
"Fatal Exception caught during stmt->executeQuery(" << cmd.str() <<
")" << endl;
288 cout <<
"Message: " << e.getMessage() << endl;
295 eruntics = rs->getInt(
"erunixtime");
296 if (eruntics > 0 && eruntics < tics)
298 cout <<
"Timestamp " << tics
299 <<
" not covered by any run, closest smaller begin run time is from run "
300 << runnumber << endl;