CMS 3D CMS Logo

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