CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RunDCSHVDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
3 #include <math.h>
4 #include <list>
5 #include <string>
6 #include <map>
7 
11 
12 using namespace std;
13 using namespace oracle::occi;
14 
16 {
17  m_env = NULL;
18  m_conn = NULL;
19  m_writeStmt = NULL;
20  m_readStmt = NULL;
21 
22  m_hv = 0;
23  m_hvnom = 0;
24  m_status= 0;
25  m_tstatus= 0;
26 }
27 
28 
29 
31 {
32 }
33 
34 
35 
37  throw(std::runtime_error)
38 {
39 
40 
41 }
42 
43 
44 
45 void RunDCSHVDat::writeDB(const EcalLogicID* ecid, const RunDCSHVDat* item, RunIOV* iov)
46  throw(std::runtime_error)
47 {
48 }
49 
50 
51 
52 void RunDCSHVDat::fetchData(map< EcalLogicID, RunDCSHVDat >* fillMap, RunIOV* iov)
53  throw(std::runtime_error)
54 {
55  fetchLastData(fillMap);
56 
57 }
58 
59 
60 
62 
63  DateHandler dh(m_env, m_conn);
64 
65  ResultSet* rset = NULL;
66  string query="SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
67  " d.actual_vmon, h.nominal_value , d.change_date "
68  " FROM "+ getEBAccount()+".FWCAENCHANNEL d "
69  " JOIN "+ getEBAccount()+".HV_MAPPING h on h.DPID = d.DPID "
70  " join "+ getEBAccount()+".CHANNELVIEW cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name "
71  " AND d.change_date> :1 AND d.actual_vmon is not null order by change_date " ;
72  try {
73  m_readStmt->setSQL(query);
74 
75  m_readStmt->setDate(1, dh.tmToDate(timeStart));
76 
77  rset = m_readStmt->executeQuery();
78  }
79  catch (SQLException e) {
80  throw(std::runtime_error("RunDCSHVDat::getBarrelRset(): " + e.getMessage() + " " + query));
81  }
82  return rset;
83 }
84 
86 
87  DateHandler dh(m_env, m_conn);
88 
89  ResultSet* rset = NULL;
90  string query="SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
91  " d.actual_vmon, '800' nominal_value , d.change_date "
92  " FROM "+ getEEAccount()+".FWCAENCHANNEL d "
93  " JOIN "+ getEEAccount()+".EE_HVA_MAPPING h on h.DPID = d.DPID "
94  " join "+ getEEAccount()+".CHANNELVIEW cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name "
95  " AND d.change_date> :1 AND d.actual_vmon is not null order by change_date " ;
96  try {
97  m_readStmt->setSQL(query);
98 
99  m_readStmt->setDate(1, dh.tmToDate(timeStart));
100 
101  rset = m_readStmt->executeQuery();
102  }
103  catch (SQLException e) {
104  throw(std::runtime_error("RunDCSHVDat::getBarrelRset(): " + e.getMessage() + " " + query));
105  }
106  return rset;
107 }
108 
110 
111  DateHandler dh(m_env, m_conn);
112 
113  ResultSet* rset = NULL;
114  string query="SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
115  " d.actual_vmon, '600' nominal_value , d.change_date "
116  " FROM "+ getEEAccount()+".FWCAENCHANNEL d "
117  " JOIN "+ getEEAccount()+".EE_HVD_MAPPING h on h.DPID = d.DPID "
118  " join "+ getEEAccount()+".CHANNELVIEW cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name "
119  " AND d.change_date> :1 AND d.actual_vmon is not null order by change_date " ;
120  try {
121  m_readStmt->setSQL(query);
122 
123  m_readStmt->setDate(1, dh.tmToDate(timeStart));
124 
125  rset = m_readStmt->executeQuery();
126  }
127  catch (SQLException e) {
128  throw(std::runtime_error("RunDCSHVDat::getBarrelRset(): " + e.getMessage() + " " + query));
129  }
130  return rset;
131 }
132 
133 
134 /*
135 ResultSet *RunDCSHVDat::getBarrelRset() {
136  ResultSet* rset = NULL;
137  string query = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
138  " d.value, h.nominal_value , d.since "
139  "FROM "+ getEBAccount()+".DCSLASTVALUE_VOLTAGE_VMON d "
140  " JOIN "+ getEBAccount()+".HV_MAPPING h on "
141  " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name";
142  try {
143  m_readStmt->setSQL(query);
144  rset = m_readStmt->executeQuery();
145  }
146  catch (SQLException e) {
147  throw(std::runtime_error("RunDCSHVDat::getBarrelRset(): " + e.getMessage() + " " + query));
148  }
149  return rset;
150 }
151 */
152 
154  ResultSet* rset = NULL;
155  string query = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
156  " d.VALUE_NUMBER, h.nominal_value , d.CHANGE_DATE "
157  "FROM "+ getEBAccount()+".FWCAENCHANNEL_LV d "
158  " JOIN "+ getEBAccount()+".HV_MAPPING h on "
159  " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and DPE_NAME='ACTUAL_VMON' ";
160  try {
161  m_readStmt->setSQL(query);
162  rset = m_readStmt->executeQuery();
163  }
164  catch (SQLException e) {
165  throw(std::runtime_error("RunDCSHVDat::getBarrelRset(): " + e.getMessage() + " " + query));
166  }
167  return rset;
168 }
169 
171  ResultSet* rset = NULL;
172  string query = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
173  " d.value_number, '800' NOMINAL_VALUE , d.CHANGE_DATE "
174  "FROM "+ getEEAccount()+".FWCAENCHANNEL_LV d "
175  " JOIN "+ getEEAccount()+".EE_HVA_MAPPING h on "
176  " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and dpe_name='ACTUAL_VMON' ";
177  try {
178  m_readStmt->setSQL(query);
179  rset = m_readStmt->executeQuery();
180  }
181  catch (SQLException e) {
182  throw(std::runtime_error("RunDCSHVDat::getEndcapAnodeRset(): " + e.getMessage() + " " + query));
183  }
184  return rset;
185 }
186 
188  ResultSet* rset = NULL;
189  string query = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
190  " d.value_number, '600' NOMINAL_VALUE , d.CHANGE_DATE "
191  "FROM "+ getEEAccount()+".FWCAENCHANNEL_LV d "
192  " JOIN "+ getEEAccount()+".EE_HVD_MAPPING h on "
193  " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and dpe_name='ACTUAL_VMON' ";
194  try {
195  m_readStmt->setSQL(query);
196  rset = m_readStmt->executeQuery();
197  }
198  catch (SQLException e) {
199  throw(std::runtime_error("RunDCSHVDat::getEndcapDynodeRset(): " + e.getMessage() + " " + query));
200  }
201  return rset;
202 }
203 
205  map< EcalLogicID, RunDCSHVDat >* fillMap) {
206 
207  // method for last value queries
208 
209  std::pair< EcalLogicID, RunDCSHVDat > p;
210  RunDCSHVDat dat;
211  DateHandler dh(m_env, m_conn);
212 
213  try {
214  while(rset->next()) {
215  p.first = EcalLogicID( rset->getString(1), // name
216  rset->getInt(2), // logic_id
217  rset->getInt(3), // id1
218  rset->getInt(4), // id2
219  rset->getInt(5), // id3
220  rset->getString(6)); // maps_to
221 
222  dat.setHV( rset->getFloat(7) );
223  dat.setHVNominal( rset->getFloat(8) );
224  Date sinceDate = rset->getDate(9);
225  Tm sinceTm = dh.dateToTm( sinceDate );
226  dat.setStatus(0);
227  if (p.first.getName() == "EB_HV_channel") {
228  setStatusForBarrel(dat, sinceTm);
229  } else {
230  setStatusForEndcaps(dat, sinceTm);
231  }
232  p.second = dat;
233  fillMap->insert(p);
234  }
235  }
236  catch (SQLException &e) {
237  throw(std::runtime_error("RunDCSHVDat::fetchData(): "+e.getMessage()));
238  }
239 }
240 
241 
242 
243 
246 
247  // std::list< std::pair< Tm, std::map< EcalLogicID, RunDCSHVDat > > >* fillMap) {
248 
249  // method for historic queries
250 
251  RunDCSHVDat dat;
252  DateHandler dh(m_env, m_conn);
253 
254 
255  try {
256  int count=-1;
257  while(rset->next()) {
258  EcalLogicID ec = EcalLogicID( rset->getString(1), // name
259  rset->getInt(2), // logic_id
260  rset->getInt(3), // id1
261  rset->getInt(4), // id2
262  rset->getInt(5), // id3
263  rset->getString(6)); // maps_to
264 
265 
266  dat.setHV( rset->getFloat(7) );
267  dat.setHVNominal( rset->getFloat(8) );
268  // Date sinceDate = rset->getDate(9);
269  // Tm sinceTm = dh.dateToTm( sinceDate );
270  // Date sinceDate = rset->getDate(9);
271  Timestamp ora_timestamp = rset->getTimestamp(9);
272  Tm sinceTm; // YYYY-MM-DD HH:MM:SS
273  sinceTm.setToString(ora_timestamp.toText("yyyy-mm-dd hh24:mi:ss",0));
274 
275  dat.setStatus(0);
276  if (ec.getName() == "EB_HV_channel") {
277  setStatusForBarrel(dat, sinceTm);
278  } else {
279  setStatusForEndcaps(dat, sinceTm);
280  }
281 
282  std::pair< EcalLogicID, RunDCSHVDat > d;
283  d.first=ec;
284  d.second=dat;
285  std::pair< Tm, std::pair< EcalLogicID, RunDCSHVDat > > p;
286  p.first=sinceTm;
287  p.second = d;
288 
290  pp.m_iData=p;
291 
292  my_data_list->push_back(pp);
293  count++;
294  if(count<100) std::cout<<"DCS DB : size:"<< my_data_list->size()<<" Tm " <<sinceTm.str()<<" "<<ec.getID1()<<" "<<ec.getID2()<<" "<<dat.getHV()<<std::endl;
295  }
296  std::cout<<"DCS DB : size:"<< my_data_list->size()<<std::endl;
297 
298 
299  }
300  catch (SQLException &e) {
301  throw(std::runtime_error("RunDCSHVDat::fetchData(): "+e.getMessage()));
302  }
303 }
304 
306  Tm t_now_gmt;
307 
308  t_now_gmt.setToCurrentGMTime();
309  int t_now_gmt_micros = t_now_gmt.microsTime();
310  return t_now_gmt_micros;
311 }
312 
313 
314 
316  int t_now_gmt_micros = nowMicroseconds();
317 
318  float hv_diff=dat.getHV() - dat.getHVNominal();
319  if(hv_diff<0) hv_diff=-hv_diff;
320  if (hv_diff*1000 > maxHVDifferenceEB) {
321  dat.setStatus(HVNOTNOMINAL);
322  }
323  if (dat.getHV()*1000 < minHV) {
324  dat.setStatus(HVOFF);
325  }
326 
327  int result=0;
328  long long d= (t_now_gmt_micros - sinceTm.microsTime()) ;
329  if (d> maxDifference) {
330  result= -d/1000000 ;
331  }
332  dat.setTimeStatus(result);
333 
334 
335 }
336 
338  int t_now_gmt_micros = nowMicroseconds();
339 
340  if (fabs(dat.getHV() - dat.getHVNominal())*1000 > maxHVDifferenceEE) {
341  dat.setStatus(HVNOTNOMINAL);
342  }
343  if (dat.getHV()*1000 < minHV) {
344  dat.setStatus(HVOFF);
345  }
346 
347  int result=0;
348  long long d= (t_now_gmt_micros - sinceTm.microsTime()) ;
349  if (d> maxDifference) {
350  result= -d/1000000 ;
351  }
352  dat.setTimeStatus(result);
353 }
354 
355 void RunDCSHVDat::fetchLastData(map< EcalLogicID, RunDCSHVDat >* fillMap )
356  throw(std::runtime_error)
357 {
358  this->checkConnection();
359 
360  fillMap->clear();
361 
362  try {
363  std::pair< EcalLogicID, RunDCSHVDat > p;
364  RunDCSHVDat dat;
365 
366  ResultSet* rset = getBarrelRset();
367 
368  fillTheMap(rset, fillMap);
369  rset = getEndcapAnodeRset();
370 
371  fillTheMap(rset, fillMap);
372  rset = getEndcapDynodeRset();
373 
374  fillTheMap(rset, fillMap);
375  }
376  catch (SQLException &e) {
377  throw(std::runtime_error("RunDCSHVDat::fetchData(): "+e.getMessage()));
378  }
379 }
380 
381 void RunDCSHVDat::fetchHistoricalData(std::list< std::pair<Tm, std::map< EcalLogicID, RunDCSHVDat > > >* fillMap, Tm timeStart )
382  throw(std::runtime_error)
383 {
384  this->checkConnection();
385 
386  fillMap->clear();
387 
388  std::list< DataReducer<RunDCSHVDat>::MyData<RunDCSHVDat> > my_data_list;
389 
390 
391  try {
392 
393  std::pair< EcalLogicID, RunDCSHVDat > p;
394  RunDCSHVDat dat;
395 
396  ResultSet* rset1 = getBarrelRset(timeStart);
397  fillTheMapByTime(rset1, &my_data_list);
398 
399  ResultSet* rset2 = getEndcapAnodeRset(timeStart);
400  fillTheMapByTime(rset2, &my_data_list);
401 
402  ResultSet* rset3 = getEndcapDynodeRset(timeStart);
403  fillTheMapByTime(rset3, &my_data_list);
404 
405 
407  my_dr.setDataList(my_data_list);
409 
410 
411  }
412  catch (SQLException &e) {
413  throw(std::runtime_error("RunDCSHVDat::fetchData(): "+e.getMessage()));
414  }
415 }
void setDataList(std::list< MyData< T > > _list)
Definition: DataReducer.h:60
oracle::occi::ResultSet ResultSet
Definition: RunDCSHVDat.h:17
float getHVNominal() const
Definition: RunDCSHVDat.h:39
void setStatusForEndcaps(RunDCSHVDat &, Tm)
Definition: RunDCSHVDat.cc:337
ResultSet * getEndcapDynodeRset()
Definition: RunDCSHVDat.cc:187
tuple pp
Definition: createTree.py:15
ResultSet * getEndcapAnodeRset()
Definition: RunDCSHVDat.cc:170
void prepareWrite()
Definition: RunDCSHVDat.cc:36
void fetchData(std::map< EcalLogicID, RunDCSHVDat > *fillMap, RunIOV *iov)
Definition: RunDCSHVDat.cc:52
#define NULL
Definition: scimark2.h:8
ResultSet * getBarrelRset()
Definition: RunDCSHVDat.cc:153
void setToCurrentGMTime()
Definition: Tm.cc:156
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
int getID2() const
Definition: EcalLogicID.cc:52
uint64_t microsTime() const
Definition: Tm.cc:109
void fetchHistoricalData(std::list< std::pair< Tm, std::map< EcalLogicID, RunDCSHVDat > > > *fillMap, Tm timeStart)
Definition: RunDCSHVDat.cc:381
std::string getName() const
Definition: EcalLogicID.cc:37
tuple iov
Definition: o2o.py:307
void fetchLastData(std::map< EcalLogicID, RunDCSHVDat > *fillMap)
Definition: RunDCSHVDat.cc:355
tuple result
Definition: query.py:137
void setToString(const std::string s)
Definition: Tm.cc:172
int getID1() const
Definition: EcalLogicID.cc:47
oracle::occi::Date tmToDate(const Tm &inTm) const
Definition: DateHandler.cc:20
void setStatusForBarrel(RunDCSHVDat &, Tm)
Definition: RunDCSHVDat.cc:315
void getReducedDataList(std::list< std::pair< Tm, DataMap > > *my_new_list)
Definition: DataReducer.h:67
void setTimeStatus(int t)
Definition: RunDCSHVDat.h:42
void setStatus(int t)
Definition: RunDCSHVDat.h:36
void setHVNominal(float t)
Definition: RunDCSHVDat.h:37
void fillTheMapByTime(ResultSet *rset, std::list< DataReducer< RunDCSHVDat >::MyData< RunDCSHVDat > > *my_data_list)
Definition: RunDCSHVDat.cc:244
std::string str() const
Definition: Tm.cc:82
tuple query
Definition: o2o.py:269
tuple cout
Definition: gather_cfg.py:41
void fillTheMap(ResultSet *, std::map< EcalLogicID, RunDCSHVDat > *)
Definition: RunDCSHVDat.cc:204
int nowMicroseconds()
Definition: RunDCSHVDat.cc:305
void writeDB(const EcalLogicID *ecid, const RunDCSHVDat *item, RunIOV *iov)
Definition: RunDCSHVDat.cc:45
void setHV(float t)
Definition: RunDCSHVDat.h:35
void fillMap(Registry *reg, regmap_type &fillme)
Definition: Registry.cc:24
Definition: RunIOV.h:13
Tm dateToTm(oracle::occi::Date &date) const
Definition: DateHandler.cc:31
Definition: Tm.h:14
float getHV() const
Definition: RunDCSHVDat.h:38
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run