CMS 3D CMS Logo

RunDCSMagnetDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
3 #include <cmath>
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 = nullptr;
18  m_conn = nullptr;
19  m_writeStmt = nullptr;
20  m_readStmt = nullptr;
21 
22  m_current = 0;
23  m_time=Tm();
24 }
25 
26 
27 
29 {
30 }
31 
33 {
34  m_time = start;
35 }
36 
38 {
39  return m_time;
40 }
41 
42 
43 
44 
45 
48 {
49 
50 
51 }
52 
53 
54 
55 void RunDCSMagnetDat::writeDB(const EcalLogicID* ecid, const RunDCSMagnetDat* item, RunIOV* iov)
56  noexcept(false)
57 {
58 }
59 
60 
61 
62 void RunDCSMagnetDat::fetchData(map< EcalLogicID, RunDCSMagnetDat >* fillMap, RunIOV* iov)
63  noexcept(false)
64 {
65 
66  std::cout<<"going to call fetchLastData"<<std::endl;
67  fetchLastData(fillMap);
68  std::cout<<"returned from fetchLastData"<<std::endl;
69 
70 }
71 
72 
74 
75  DateHandler dh(m_env, m_conn);
76 
77  ResultSet* rset = nullptr;
78  string query="SELECT c.name, c.logic_id, c.id1, c.id2, c.id3, c.maps_to , v.value_number, v.change_date from "+ getMagnetAccount()+
79  ".CMSFWMAGNET_LV v, channelview c where v.dpe_name= 'CURRENT' and c.name=maps_to and c.name='EB' " ;
80  try {
81 
82  std::cout<<"query:"<<query<<std::endl;
83 
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(std::string("RunDCSMagnetDat::getBarrelRset(): ") + e.getMessage() + " " + query));
90 #else
91  throw(std::runtime_error(std::string("RunDCSMagnetDat::getBarrelRset(): error code ") + std::to_string(e.getErrorCode()) + " " + query));
92 #endif
93  }
94  return rset;
95 }
96 
97 
98 
100  map< EcalLogicID, RunDCSMagnetDat >* fillMap) {
101 
102  // method for last value queries
103 
104  std::pair< EcalLogicID, RunDCSMagnetDat > p;
105  RunDCSMagnetDat dat;
106  DateHandler dh(m_env, m_conn);
107 
108  try {
109  while(rset->next()) {
110  p.first = EcalLogicID( rset->getString(1), // name
111  rset->getInt(2), // logic_id
112  rset->getInt(3), // id1
113  rset->getInt(4), // id2
114  rset->getInt(5), // id3
115  rset->getString(6)); // maps_to
116 
117  std::cout<<"done the logic id"<<std::endl;
118  dat.setMagnetCurrent( rset->getFloat(7) );
119  std::cout<<"done the magnet current"<<std::endl;
120 
121  Date sinceDate = rset->getDate(8);
122  std::cout<<"done the date"<<std::endl;
123 
124  Tm sinceTm = dh.dateToTm( sinceDate );
125  dat.setTime(sinceTm);
126 
127  p.second = dat;
128  fillMap->insert(p);
129  }
130  }
131  catch (SQLException &e) {
132 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
133  throw(std::runtime_error(std::string("RunDCSMagnetDat::fetchData(): ")+e.getMessage()));
134 #else
135  throw(std::runtime_error(std::string("RunDCSMagnetDat::fetchData(): error code ") + std::to_string(e.getErrorCode())));
136 #endif
137  }
138 }
139 
140 
141 
142 
144  Tm t_now_gmt;
145 
146  t_now_gmt.setToCurrentGMTime();
147  int t_now_gmt_micros = t_now_gmt.microsTime();
148  return t_now_gmt_micros;
149 }
150 
151 
152 
153 void RunDCSMagnetDat::fetchLastData(map< EcalLogicID, RunDCSMagnetDat >* fillMap )
154  noexcept(false)
155 {
156  this->checkConnection();
157 
158  std::cout<<"fetchLastData>>1"<<std::endl;
159 
160  fillMap->clear();
161 
162  std::cout<<"fetchLastData>>2"<<std::endl;
163 
164 
165  try {
166  std::pair< EcalLogicID, RunDCSMagnetDat > p;
167  RunDCSMagnetDat dat;
168  std::cout<<"fetchLastData>>3"<<std::endl;
169 
170  ResultSet* rset = getMagnetRset();
171 
172  std::cout<<"fetchLastData>>4"<<std::endl;
173 
174  fillTheMap(rset, fillMap);
175  std::cout<<"fetchLastData>>5"<<std::endl;
176 
177 
178  }
179  catch (SQLException &e) {
180 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
181  throw(std::runtime_error(std::string("RunDCSMagnetDat::fetchData(): ")+e.getMessage()));
182 #else
183  throw(std::runtime_error(std::string("RunDCSMagnetDat::fetchData(): error code ") + std::to_string(e.getErrorCode())));
184 #endif
185  }
186 }
187 
Definition: start.py:1
void fetchData(std::map< EcalLogicID, RunDCSMagnetDat > *fillMap, RunIOV *iov) noexcept(false)
#define noexcept
void setToCurrentGMTime()
Definition: Tm.cc:177
def query(query_str, verbose=False)
Definition: das.py:6
Definition: query.py:1
uint64_t microsTime() const
Definition: Tm.cc:126
void fetchLastData(std::map< EcalLogicID, RunDCSMagnetDat > *fillMap) noexcept(false)
void setMagnetCurrent(float t)
oracle::occi::ResultSet ResultSet
void writeDB(const EcalLogicID *ecid, const RunDCSMagnetDat *item, RunIOV *iov) noexcept(false)
void fillTheMap(ResultSet *, std::map< EcalLogicID, RunDCSMagnetDat > *)
void prepareWrite() noexcept(false) override
ResultSet * getMagnetRset()
void setTime(const Tm &start)
~RunDCSMagnetDat() override
dh
Definition: cuy.py:355
Definition: RunIOV.h:13
Tm dateToTm(oracle::occi::Date &date) const
Definition: DateHandler.cc:31
Definition: Tm.h:13
Tm getTime() const