CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
33  throw(std::runtime_error)
34 {
35 
36 
37 }
38 
39 
40 
41 void RunDCSLVDat::writeDB(const EcalLogicID* ecid, const RunDCSLVDat* item, RunIOV* iov)
42  throw(std::runtime_error)
43 {
44 }
45 
46 
47 
48 void RunDCSLVDat::fetchData(map< EcalLogicID, RunDCSLVDat >* fillMap, RunIOV* iov)
49  throw(std::runtime_error)
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  throw(std::runtime_error("RunDCSLVDat::getBarrelRset(): " + e.getMessage() + " " + query));
68  }
69  return rset;
70 }
71 
73  ResultSet* rset = NULL;
74  string query = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
75  " d.VALUE_NUMBER, '5' NOMINAL_VALUE , d.VALUE_TIMESTAMP "
76  "FROM "+ getEEAccount()+".FWWIENERMARATHONCHANNEL_LV d "
77  " JOIN "+ getEEAccount()+".EE_LV_MAPPING h on "
78  " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and dpe_name='MEASUREMENTSENSEVOLTAGE' ";
79  try {
80  m_readStmt->setSQL(query);
81  rset = m_readStmt->executeQuery();
82  }
83  catch (SQLException e) {
84  throw(std::runtime_error("RunDCSLVDat::getEndcapRset(): " + e.getMessage() + " " + query));
85  }
86  return rset;
87 }
88 
90  map< EcalLogicID, RunDCSLVDat >* fillMap) {
91  std::pair< EcalLogicID, RunDCSLVDat > p;
92  RunDCSLVDat dat;
93  DateHandler dh(m_env, m_conn);
94 
95  try {
96  while(rset->next()) {
97  p.first = EcalLogicID( rset->getString(1), // name
98  rset->getInt(2), // logic_id
99  rset->getInt(3), // id1
100  rset->getInt(4), // id2
101  rset->getInt(5), // id3
102  rset->getString(6)); // maps_to
103 
104  dat.setLV( rset->getFloat(7) );
105  dat.setLVNominal( rset->getFloat(8) );
106  Date sinceDate = rset->getDate(9);
107  Tm sinceTm = dh.dateToTm( sinceDate );
108  dat.setStatus(0);
109  if (p.first.getName() == "EB_LV_channel") {
110  setStatusForBarrel(dat, sinceTm);
111  } else {
112  setStatusForEndcaps(dat, sinceTm);
113  }
114  p.second = dat;
115  fillMap->insert(p);
116  }
117  }
118  catch (SQLException &e) {
119  throw(std::runtime_error("RunDCSLVDat::fetchData(): "+e.getMessage()));
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 
131 
132 void RunDCSLVDat::setStatusForBarrel(RunDCSLVDat &dat, const Tm& sinceTm) {
133  int t_now_gmt_micros = nowMicroseconds();
134 
135  if (fabs(dat.getLV() - dat.getLVNominal())*1000 > maxLVDifferenceEB) {
136  dat.setStatus(LVNOTNOMINAL);
137  }
138  if (dat.getLV()*1000 < minLV) {
139  dat.setStatus(LVOFF);
140  }
141 
142  int result=0;
143  int d= ((int)t_now_gmt_micros - (int)sinceTm.microsTime()) ;
144  if (d> maxDifference) {
145  result= -d/1000000 ;
146  }
147  dat.setTimeStatus(result);
148 
149 
150 }
151 
152 void RunDCSLVDat::setStatusForEndcaps(RunDCSLVDat &dat, const Tm& sinceTm) {
153  int t_now_gmt_micros = nowMicroseconds();
154 
155  if (fabs(dat.getLV() - dat.getLVNominal())*1000 > maxLVDifferenceEE) {
156  dat.setStatus(LVNOTNOMINAL);
157  }
158  if (dat.getLV()*1000 < minLV) {
159  dat.setStatus(LVOFF);
160  }
161 
162  int result=0;
163  int d= ((int)t_now_gmt_micros - (int)sinceTm.microsTime()) ;
164  if (d> maxDifference) {
165  result= -d/1000000 ;
166  }
167  dat.setTimeStatus(result);
168 
169 
170 }
171 
172 void RunDCSLVDat::fetchLastData(map< EcalLogicID, RunDCSLVDat >* fillMap )
173  throw(std::runtime_error)
174 {
175  this->checkConnection();
176 
177  fillMap->clear();
178 
179  try {
180  std::pair< EcalLogicID, RunDCSLVDat > p;
181  RunDCSLVDat dat;
182 
183  ResultSet* rset = getBarrelRset();
184 
185  fillTheMap(rset, fillMap);
186  rset = getEndcapRset();
187 
188  fillTheMap(rset, fillMap);
189  }
190  catch (SQLException &e) {
191  throw(std::runtime_error("RunDCSLVDat::fetchData(): "+e.getMessage()));
192  }
193 }
int nowMicroseconds()
Definition: RunDCSLVDat.cc:123
float getLV() const
Definition: RunDCSLVDat.h:37
#define NULL
Definition: scimark2.h:8
void setLV(float t)
Definition: RunDCSLVDat.h:34
void setToCurrentGMTime()
Definition: Tm.cc:177
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
tuple result
Definition: mps_fire.py:95
uint64_t microsTime() const
Definition: Tm.cc:126
tuple d
Definition: ztail.py:151
void writeDB(const EcalLogicID *ecid, const RunDCSLVDat *item, RunIOV *iov)
Definition: RunDCSLVDat.cc:41
tuple iov
Definition: o2o.py:307
float getLVNominal() const
Definition: RunDCSLVDat.h:38
void fetchLastData(std::map< EcalLogicID, RunDCSLVDat > *fillMap)
Definition: RunDCSLVDat.cc:172
void fetchData(std::map< EcalLogicID, RunDCSLVDat > *fillMap, RunIOV *iov)
Definition: RunDCSLVDat.cc:48
oracle::occi::ResultSet ResultSet
Definition: RunDCSLVDat.h:16
void fillTheMap(ResultSet *, std::map< EcalLogicID, RunDCSLVDat > *)
Definition: RunDCSLVDat.cc:89
void setStatus(int t)
Definition: RunDCSLVDat.h:35
void setStatusForEndcaps(RunDCSLVDat &, const Tm &)
Definition: RunDCSLVDat.cc:152
ResultSet * getBarrelRset()
Definition: RunDCSLVDat.cc:55
ResultSet * getEndcapRset()
Definition: RunDCSLVDat.cc:72
void prepareWrite()
Definition: RunDCSLVDat.cc:32
tuple query
Definition: o2o.py:269
void setLVNominal(float t)
Definition: RunDCSLVDat.h:36
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:132
tuple dh
Definition: cuy.py:353