CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RunDCSLVDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
3 #include <cmath>
4 
7 
8 using namespace std;
9 using namespace oracle::occi;
10 
12  m_env = nullptr;
13  m_conn = nullptr;
14  m_writeStmt = nullptr;
15  m_readStmt = nullptr;
16 
17  m_lv = 0;
18  m_lvnom = 0;
19  m_status = 0;
20  m_tstatus = 0;
21 }
22 
24 
25 void RunDCSLVDat::prepareWrite() noexcept(false) {}
26 
27 void RunDCSLVDat::writeDB(const EcalLogicID* ecid, const RunDCSLVDat* item, RunIOV* iov) noexcept(false) {}
28 
29 void RunDCSLVDat::fetchData(map<EcalLogicID, RunDCSLVDat>* fillMap, RunIOV* iov) noexcept(false) {
30  fetchLastData(fillMap);
31 }
32 
34  ResultSet* rset = nullptr;
35  string query =
36  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
37  " d.value_number , '5' NOMINAL_VALUE , d.VALUE_TIMESTAMP "
38  "FROM " +
39  getEBAccount() +
40  ".FWWIENERMARATHONCHANNEL_LV d "
41  " JOIN " +
42  getEBAccount() +
43  ".LV_MAPPING h on "
44  " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and "
45  "dpe_name='MEASUREMENTSENSEVOLTAGE' ";
46  try {
47  m_readStmt->setSQL(query);
48  rset = m_readStmt->executeQuery();
49  } catch (SQLException& e) {
50 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
51  throw(std::runtime_error(std::string("RunDCSLVDat::getBarrelRset(): ") + e.getMessage() + " " + query));
52 #else
53  throw(std::runtime_error(std::string("RunDCSLVDat::getBarrelRset(): error code ") +
54  std::to_string(e.getErrorCode()) + " " + query));
55 #endif
56  }
57  return rset;
58 }
59 
61  ResultSet* rset = nullptr;
62  string query =
63  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
64  " d.VALUE_NUMBER, '5' NOMINAL_VALUE , d.VALUE_TIMESTAMP "
65  "FROM " +
66  getEEAccount() +
67  ".FWWIENERMARATHONCHANNEL_LV d "
68  " JOIN " +
69  getEEAccount() +
70  ".EE_LV_MAPPING h on "
71  " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and "
72  "dpe_name='MEASUREMENTSENSEVOLTAGE' ";
73  try {
74  m_readStmt->setSQL(query);
75  rset = m_readStmt->executeQuery();
76  } catch (SQLException& e) {
77 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
78  throw(std::runtime_error(std::string("RunDCSLVDat::getEndcapRset(): ") + e.getMessage() + " " + query));
79 #else
80  throw(std::runtime_error(std::string("RunDCSLVDat::getEndcapRset(): error code ") +
81  std::to_string(e.getErrorCode()) + " " + query));
82 #endif
83  }
84  return rset;
85 }
86 
87 void RunDCSLVDat::fillTheMap(ResultSet* rset, map<EcalLogicID, RunDCSLVDat>* fillMap) {
88  std::pair<EcalLogicID, RunDCSLVDat> p;
90  DateHandler dh(m_env, m_conn);
91 
92  try {
93  while (rset->next()) {
94  p.first = EcalLogicID(rset->getString(1), // name
95  rset->getInt(2), // logic_id
96  rset->getInt(3), // id1
97  rset->getInt(4), // id2
98  rset->getInt(5), // id3
99  rset->getString(6)); // maps_to
100 
101  dat.setLV(rset->getFloat(7));
102  dat.setLVNominal(rset->getFloat(8));
103  Date sinceDate = rset->getDate(9);
104  Tm sinceTm = dh.dateToTm(sinceDate);
105  dat.setStatus(0);
106  if (p.first.getName() == "EB_LV_channel") {
107  setStatusForBarrel(dat, sinceTm);
108  } else {
109  setStatusForEndcaps(dat, sinceTm);
110  }
111  p.second = dat;
112  fillMap->insert(p);
113  }
114  } catch (SQLException& e) {
115 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
116  throw(std::runtime_error(std::string("RunDCSLVDat::fetchData(): ") + e.getMessage()));
117 #else
118  throw(std::runtime_error(std::string("RunDCSLVDat::fetchData(): error code ") + std::to_string(e.getErrorCode())));
119 #endif
120  }
121 }
122 
124  Tm t_now_gmt;
125 
126  t_now_gmt.setToCurrentGMTime();
127  int t_now_gmt_micros = t_now_gmt.microsTime();
128  return t_now_gmt_micros;
129 }
130 
132  int t_now_gmt_micros = nowMicroseconds();
133 
134  if (fabs(dat.getLV() - dat.getLVNominal()) * 1000 > maxLVDifferenceEB) {
135  dat.setStatus(LVNOTNOMINAL);
136  }
137  if (dat.getLV() * 1000 < minLV) {
138  dat.setStatus(LVOFF);
139  }
140 
141  int result = 0;
142  int d = ((int)t_now_gmt_micros - (int)sinceTm.microsTime());
143  if (d > maxDifference) {
144  result = -d / 1000000;
145  }
146  dat.setTimeStatus(result);
147 }
148 
150  int t_now_gmt_micros = nowMicroseconds();
151 
152  if (fabs(dat.getLV() - dat.getLVNominal()) * 1000 > maxLVDifferenceEE) {
153  dat.setStatus(LVNOTNOMINAL);
154  }
155  if (dat.getLV() * 1000 < minLV) {
156  dat.setStatus(LVOFF);
157  }
158 
159  int result = 0;
160  int d = ((int)t_now_gmt_micros - (int)sinceTm.microsTime());
161  if (d > maxDifference) {
162  result = -d / 1000000;
163  }
164  dat.setTimeStatus(result);
165 }
166 
167 void RunDCSLVDat::fetchLastData(map<EcalLogicID, RunDCSLVDat>* fillMap) noexcept(false) {
168  this->checkConnection();
169 
170  fillMap->clear();
171 
172  try {
173  std::pair<EcalLogicID, RunDCSLVDat> p;
175 
176  ResultSet* rset = getBarrelRset();
177 
178  fillTheMap(rset, fillMap);
179  rset = getEndcapRset();
180 
181  fillTheMap(rset, fillMap);
182  } catch (SQLException& e) {
183 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
184  throw(std::runtime_error(std::string("RunDCSLVDat::fetchData(): ") + e.getMessage()));
185 #else
186  throw(std::runtime_error(std::string("RunDCSLVDat::fetchData(): error code ") + std::to_string(e.getErrorCode())));
187 #endif
188  }
189 }
int nowMicroseconds()
Definition: RunDCSLVDat.cc:123
float getLV() const
Definition: RunDCSLVDat.h:37
void setLV(float t)
Definition: RunDCSLVDat.h:34
void fetchData(std::map< EcalLogicID, RunDCSLVDat > *fillMap, RunIOV *iov) noexcept(false)
Definition: RunDCSLVDat.cc:29
void setToCurrentGMTime()
Definition: Tm.cc:141
tuple result
Definition: mps_fire.py:311
uint64_t microsTime() const
Definition: Tm.cc:96
~RunDCSLVDat() override
Definition: RunDCSLVDat.cc:23
tuple d
Definition: ztail.py:151
float getLVNominal() const
Definition: RunDCSLVDat.h:38
oracle::occi::ResultSet ResultSet
Definition: RunDCSLVDat.h:16
void fillTheMap(ResultSet *, std::map< EcalLogicID, RunDCSLVDat > *)
Definition: RunDCSLVDat.cc:87
void setStatus(int t)
Definition: RunDCSLVDat.h:35
void setStatusForEndcaps(RunDCSLVDat &, const Tm &)
Definition: RunDCSLVDat.cc:149
void writeDB(const EcalLogicID *ecid, const RunDCSLVDat *item, RunIOV *iov) noexcept(false)
Definition: RunDCSLVDat.cc:27
static std::vector< std::string > checklist dat
ResultSet * getBarrelRset()
Definition: RunDCSLVDat.cc:33
ResultSet * getEndcapRset()
Definition: RunDCSLVDat.cc:60
void prepareWrite() noexcept(false) override
Definition: RunDCSLVDat.cc:25
void fetchLastData(std::map< EcalLogicID, RunDCSLVDat > *fillMap) noexcept(false)
Definition: RunDCSLVDat.cc:167
void setLVNominal(float t)
Definition: RunDCSLVDat.h:36
Definition: RunIOV.h:13
Tm dateToTm(oracle::occi::Date &date) const
Definition: DateHandler.cc:28
Definition: Tm.h:13
void setTimeStatus(int t)
Definition: RunDCSLVDat.h:41
void setStatusForBarrel(RunDCSLVDat &, const Tm &)
Definition: RunDCSLVDat.cc:131
tuple dh
Definition: cuy.py:354