14 using namespace oracle::occi;
19 m_writeStmt =
nullptr;
35 fetchLastData(fillMap);
43 "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
44 " d.actual_vmon, h.nominal_value , d.change_date "
50 ".HV_MAPPING h on h.DPID = d.DPID "
53 ".CHANNELVIEW cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name "
54 " AND d.change_date> :1 AND d.actual_vmon is not null order by change_date ";
56 m_readStmt->setSQL(query);
58 m_readStmt->setDate(1, dh.
tmToDate(timeStart));
60 rset = m_readStmt->executeQuery();
61 }
catch (SQLException&
e) {
62 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
63 throw(std::runtime_error(
std::string(
"RunDCSHVDat::getBarrelRset(): ") + e.getMessage() +
" " +
query));
65 throw(std::runtime_error(
std::string(
"RunDCSHVDat::getBarrelRset(): error code ") +
77 "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
78 " d.actual_vmon, '800' nominal_value , d.change_date "
84 ".EE_HVA_MAPPING h on h.DPID = d.DPID "
87 ".CHANNELVIEW cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name "
88 " AND d.change_date> :1 AND d.actual_vmon is not null order by change_date ";
90 m_readStmt->setSQL(query);
92 m_readStmt->setDate(1, dh.
tmToDate(timeStart));
94 rset = m_readStmt->executeQuery();
95 }
catch (SQLException&
e) {
96 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
97 throw(std::runtime_error(
std::string(
"RunDCSHVDat::getBarrelRset(): ") + e.getMessage() +
" " +
query));
99 throw(std::runtime_error(
std::string(
"RunDCSHVDat::getBarrelRset(): error code ") +
111 "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
112 " d.actual_vmon, '600' nominal_value , d.change_date "
118 ".EE_HVD_MAPPING h on h.DPID = d.DPID "
121 ".CHANNELVIEW cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name "
122 " AND d.change_date> :1 AND d.actual_vmon is not null order by change_date ";
124 m_readStmt->setSQL(query);
126 m_readStmt->setDate(1, dh.
tmToDate(timeStart));
128 rset = m_readStmt->executeQuery();
129 }
catch (SQLException&
e) {
130 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
131 throw(std::runtime_error(
std::string(
"RunDCSHVDat::getBarrelRset(): ") + e.getMessage() +
" " +
query));
133 throw(std::runtime_error(
std::string(
"RunDCSHVDat::getBarrelRset(): error code ") +
162 "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
163 " d.VALUE_NUMBER, h.nominal_value , d.CHANGE_DATE "
166 ".FWCAENCHANNEL_LV d "
170 " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and "
171 "DPE_NAME='ACTUAL_VMON' ";
173 m_readStmt->setSQL(query);
174 rset = m_readStmt->executeQuery();
175 }
catch (SQLException&
e) {
176 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
177 throw(std::runtime_error(
std::string(
"RunDCSHVDat::getBarrelRset(): ") + e.getMessage() +
" " +
query));
179 throw(std::runtime_error(
std::string(
"RunDCSHVDat::getBarrelRset(): error code ") +
189 "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
190 " d.value_number, '800' NOMINAL_VALUE , d.CHANGE_DATE "
193 ".FWCAENCHANNEL_LV d "
196 ".EE_HVA_MAPPING h on "
197 " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and "
198 "dpe_name='ACTUAL_VMON' ";
200 m_readStmt->setSQL(query);
201 rset = m_readStmt->executeQuery();
202 }
catch (SQLException&
e) {
203 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
204 throw(std::runtime_error(
std::string(
"RunDCSHVDat::getEndcapAnodeRset(): ") + e.getMessage() +
" " +
query));
206 throw(std::runtime_error(
std::string(
"RunDCSHVDat::getEndcapAnodeRset(): error code ") +
216 "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
217 " d.value_number, '600' NOMINAL_VALUE , d.CHANGE_DATE "
220 ".FWCAENCHANNEL_LV d "
223 ".EE_HVD_MAPPING h on "
224 " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and "
225 "dpe_name='ACTUAL_VMON' ";
227 m_readStmt->setSQL(query);
228 rset = m_readStmt->executeQuery();
229 }
catch (SQLException&
e) {
230 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
231 throw(std::runtime_error(
std::string(
"RunDCSHVDat::getEndcapDynodeRset(): ") + e.getMessage() +
" " +
query));
233 throw(std::runtime_error(
std::string(
"RunDCSHVDat::getEndcapDynodeRset(): error code ") +
243 std::pair<EcalLogicID, RunDCSHVDat>
p;
248 while (rset->next()) {
256 dat.
setHV(rset->getFloat(7));
258 Date sinceDate = rset->getDate(9);
261 if (p.first.getName() ==
"EB_HV_channel") {
262 setStatusForBarrel(dat, sinceTm);
264 setStatusForEndcaps(dat, sinceTm);
269 }
catch (SQLException&
e) {
270 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
271 throw(std::runtime_error(
std::string(
"RunDCSHVDat::fetchData(): ") + e.getMessage()));
289 while (rset->next()) {
297 dat.
setHV(rset->getFloat(7));
302 Timestamp ora_timestamp = rset->getTimestamp(9);
304 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
305 sinceTm.
setToString(ora_timestamp.toText(
"yyyy-mm-dd hh24:mi:ss", 0));
308 unsigned int month = 0;
309 unsigned int day = 0;
310 unsigned int hour = 0;
311 unsigned int minute = 0;
314 ora_timestamp.getDate(year, month, day);
315 ora_timestamp.getTime(hour, minute, second, fs);
316 const std::tm
tt = {.tm_sec =
static_cast<int>(
second),
317 .tm_min = static_cast<int>(minute),
318 .tm_hour =
static_cast<int>(hour),
319 .tm_mday = static_cast<int>(day),
320 .tm_mon =
static_cast<int>(month),
321 .tm_year = year - 1900,
327 char tt_str[30] = {0};
328 if (std::strftime(tt_str,
sizeof(tt_str),
"%F %T", &
tt)) {
331 throw std::runtime_error(
"RunDCSHVDat::fillTheMapByTime: failed to generate the date string");
336 if (ec.
getName() ==
"EB_HV_channel") {
337 setStatusForBarrel(dat, sinceTm);
339 setStatusForEndcaps(dat, sinceTm);
342 std::pair<EcalLogicID, RunDCSHVDat>
d;
345 std::pair<Tm, std::pair<EcalLogicID, RunDCSHVDat> >
p;
352 my_data_list->push_back(pp);
355 std::cout <<
"DCS DB : size:" << my_data_list->size() <<
" Tm " << sinceTm.
str() <<
" " << ec.
getID1() <<
" "
358 std::cout <<
"DCS DB : size:" << my_data_list->size() << std::endl;
360 }
catch (SQLException&
e) {
361 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
362 throw(std::runtime_error(
std::string(
"RunDCSHVDat::fetchData(): ") + e.getMessage()));
373 int t_now_gmt_micros = t_now_gmt.
microsTime();
374 return t_now_gmt_micros;
378 int t_now_gmt_micros = nowMicroseconds();
383 if (hv_diff * 1000 > maxHVDifferenceEB) {
386 if (dat.
getHV() * 1000 < minHV) {
391 long long d = (t_now_gmt_micros - sinceTm.
microsTime());
392 if (d > maxDifference) {
393 result = -d / 1000000;
399 int t_now_gmt_micros = nowMicroseconds();
404 if (dat.
getHV() * 1000 < minHV) {
409 long long d = (t_now_gmt_micros - sinceTm.
microsTime());
410 if (d > maxDifference) {
411 result = -d / 1000000;
417 this->checkConnection();
422 std::pair<EcalLogicID, RunDCSHVDat>
p;
427 fillTheMap(rset, fillMap);
428 rset = getEndcapAnodeRset();
430 fillTheMap(rset, fillMap);
431 rset = getEndcapDynodeRset();
433 fillTheMap(rset, fillMap);
434 }
catch (SQLException&
e) {
435 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
436 throw(std::runtime_error(
std::string(
"RunDCSHVDat::fetchData(): ") + e.getMessage()));
444 const Tm& timeStart) noexcept(
false) {
445 this->checkConnection();
449 std::list<DataReducer<RunDCSHVDat>::MyData<
RunDCSHVDat> > my_data_list;
452 std::pair<EcalLogicID, RunDCSHVDat>
p;
455 ResultSet* rset1 = getBarrelRset(timeStart);
456 fillTheMapByTime(rset1, &my_data_list);
458 ResultSet* rset2 = getEndcapAnodeRset(timeStart);
459 fillTheMapByTime(rset2, &my_data_list);
461 ResultSet* rset3 = getEndcapDynodeRset(timeStart);
462 fillTheMapByTime(rset3, &my_data_list);
468 }
catch (SQLException&
e) {
469 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
470 throw(std::runtime_error(
std::string(
"RunDCSHVDat::fetchData(): ") + e.getMessage()));
void setDataList(std::list< MyData< T > > _list)
oracle::occi::ResultSet ResultSet
float getHVNominal() const
void setStatusForEndcaps(RunDCSHVDat &, const Tm &)
ResultSet * getEndcapDynodeRset()
void writeDB(const EcalLogicID *ecid, const RunDCSHVDat *item, RunIOV *iov) noexcept(false)
ResultSet * getEndcapAnodeRset()
std::string to_string(const V &value)
ResultSet * getBarrelRset()
void fetchHistoricalData(std::list< std::pair< Tm, std::map< EcalLogicID, RunDCSHVDat > > > *fillMap, const Tm &timeStart) noexcept(false)
void setToCurrentGMTime()
void fetchData(std::map< EcalLogicID, RunDCSHVDat > *fillMap, RunIOV *iov) noexcept(false)
void setStatusForBarrel(RunDCSHVDat &, const Tm &)
uint64_t microsTime() const
U second(std::pair< T, U > const &p)
std::string getName() const
oracle::occi::Date tmToDate(const Tm &inTm) const
void getReducedDataList(std::list< std::pair< Tm, DataMap > > *my_new_list)
void fetchLastData(std::map< EcalLogicID, RunDCSHVDat > *fillMap) noexcept(false)
void prepareWrite() noexcept(false) override
void setTimeStatus(int t)
void setToString(const std::string s) noexcept(false)
void setHVNominal(float t)
static std::vector< std::string > checklist dat
void fillTheMapByTime(ResultSet *rset, std::list< DataReducer< RunDCSHVDat >::MyData< RunDCSHVDat > > *my_data_list)
void fillTheMap(ResultSet *, std::map< EcalLogicID, RunDCSHVDat > *)
Tm dateToTm(oracle::occi::Date &date) const