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  m_env = nullptr;
17  m_conn = nullptr;
18  m_writeStmt = nullptr;
19  m_readStmt = nullptr;
20 
21  m_current = 0;
22  m_time = Tm();
23 }
24 
26 
27 void RunDCSMagnetDat::setTime(const Tm& start) { m_time = start; }
28 
29 Tm RunDCSMagnetDat::getTime() const { return m_time; }
30 
32 
33 void RunDCSMagnetDat::writeDB(const EcalLogicID* ecid, const RunDCSMagnetDat* item, RunIOV* iov) noexcept(false) {}
34 
35 void RunDCSMagnetDat::fetchData(map<EcalLogicID, RunDCSMagnetDat>* fillMap, RunIOV* iov) noexcept(false) {
36  std::cout << "going to call fetchLastData" << std::endl;
37  fetchLastData(fillMap);
38  std::cout << "returned from fetchLastData" << std::endl;
39 }
40 
42  DateHandler dh(m_env, m_conn);
43 
44  ResultSet* rset = nullptr;
45  string query = "SELECT c.name, c.logic_id, c.id1, c.id2, c.id3, c.maps_to , v.value_number, v.change_date from " +
46  getMagnetAccount() +
47  ".CMSFWMAGNET_LV v, channelview c where v.dpe_name= 'CURRENT' and c.name=maps_to and c.name='EB' ";
48  try {
49  std::cout << "query:" << query << std::endl;
50 
51  m_readStmt->setSQL(query);
52  rset = m_readStmt->executeQuery();
53  } catch (SQLException& e) {
54 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
55  throw(std::runtime_error(std::string("RunDCSMagnetDat::getBarrelRset(): ") + e.getMessage() + " " + query));
56 #else
57  throw(std::runtime_error(std::string("RunDCSMagnetDat::getBarrelRset(): error code ") +
58  std::to_string(e.getErrorCode()) + " " + query));
59 #endif
60  }
61  return rset;
62 }
63 
64 void RunDCSMagnetDat::fillTheMap(ResultSet* rset, map<EcalLogicID, RunDCSMagnetDat>* fillMap) {
65  // method for last value queries
66 
67  std::pair<EcalLogicID, RunDCSMagnetDat> p;
68  RunDCSMagnetDat dat;
69  DateHandler dh(m_env, m_conn);
70 
71  try {
72  while (rset->next()) {
73  p.first = EcalLogicID(rset->getString(1), // name
74  rset->getInt(2), // logic_id
75  rset->getInt(3), // id1
76  rset->getInt(4), // id2
77  rset->getInt(5), // id3
78  rset->getString(6)); // maps_to
79 
80  std::cout << "done the logic id" << std::endl;
81  dat.setMagnetCurrent(rset->getFloat(7));
82  std::cout << "done the magnet current" << std::endl;
83 
84  Date sinceDate = rset->getDate(8);
85  std::cout << "done the date" << std::endl;
86 
87  Tm sinceTm = dh.dateToTm(sinceDate);
88  dat.setTime(sinceTm);
89 
90  p.second = dat;
91  fillMap->insert(p);
92  }
93  } catch (SQLException& e) {
94 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
95  throw(std::runtime_error(std::string("RunDCSMagnetDat::fetchData(): ") + e.getMessage()));
96 #else
97  throw(std::runtime_error(std::string("RunDCSMagnetDat::fetchData(): error code ") +
98  std::to_string(e.getErrorCode())));
99 #endif
100  }
101 }
102 
104  Tm t_now_gmt;
105 
106  t_now_gmt.setToCurrentGMTime();
107  int t_now_gmt_micros = t_now_gmt.microsTime();
108  return t_now_gmt_micros;
109 }
110 
111 void RunDCSMagnetDat::fetchLastData(map<EcalLogicID, RunDCSMagnetDat>* fillMap) noexcept(false) {
112  this->checkConnection();
113 
114  std::cout << "fetchLastData>>1" << std::endl;
115 
116  fillMap->clear();
117 
118  std::cout << "fetchLastData>>2" << std::endl;
119 
120  try {
121  std::pair<EcalLogicID, RunDCSMagnetDat> p;
122  RunDCSMagnetDat dat;
123  std::cout << "fetchLastData>>3" << std::endl;
124 
125  ResultSet* rset = getMagnetRset();
126 
127  std::cout << "fetchLastData>>4" << std::endl;
128 
129  fillTheMap(rset, fillMap);
130  std::cout << "fetchLastData>>5" << std::endl;
131 
132  } catch (SQLException& e) {
133 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
134  throw(std::runtime_error(std::string("RunDCSMagnetDat::fetchData(): ") + e.getMessage()));
135 #else
136  throw(std::runtime_error(std::string("RunDCSMagnetDat::fetchData(): error code ") +
137  std::to_string(e.getErrorCode())));
138 #endif
139  }
140 }
Definition: start.py:1
void fetchData(std::map< EcalLogicID, RunDCSMagnetDat > *fillMap, RunIOV *iov) noexcept(false)
void setToCurrentGMTime()
Definition: Tm.cc:139
static std::string to_string(const XMLCh *ch)
Definition: query.py:1
Tm getTime() const
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 > *)
uint64_t microsTime() const
Definition: Tm.cc:94
void prepareWrite() noexcept(false) override
ResultSet * getMagnetRset()
void setTime(const Tm &start)
~RunDCSMagnetDat() override
dh
Definition: cuy.py:354
Definition: RunIOV.h:13
Definition: Tm.h:13