CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MonPulseShapeDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
8 
9 using namespace std;
10 using namespace oracle::occi;
11 
13 {
14  m_env = NULL;
15  m_conn = NULL;
16  m_writeStmt = NULL;
17  m_readStmt = NULL;
18 
19  m_samplesG1.assign(10, 0);
20  m_samplesG6.assign(10, 0);
21  m_samplesG12.assign(10, 0);
22 
23 }
24 
25 
26 
28 {
29 }
30 
31 
32 
35 {
36  this->checkConnection();
37 
38  try {
39  m_writeStmt = m_conn->createStatement();
40  m_writeStmt->setSQL("INSERT INTO mon_pulse_shape_dat (iov_id, logic_id, "
41  "g1_avg_sample_01, g1_avg_sample_02, g1_avg_sample_03, g1_avg_sample_04, g1_avg_sample_05, g1_avg_sample_06, g1_avg_sample_07, g1_avg_sample_08, g1_avg_sample_09, g1_avg_sample_10, "
42  "g6_avg_sample_01, g6_avg_sample_02, g6_avg_sample_03, g6_avg_sample_04, g6_avg_sample_05, g6_avg_sample_06, g6_avg_sample_07, g6_avg_sample_08, g6_avg_sample_09, g6_avg_sample_10, "
43  "g12_avg_sample_01, g12_avg_sample_02, g12_avg_sample_03, g12_avg_sample_04, g12_avg_sample_05, g12_avg_sample_06, g12_avg_sample_07, g12_avg_sample_08, g12_avg_sample_09, g12_avg_sample_10) "
44  "VALUES (:iov_id, :logic_id, "
45  ":g1_avg_sample_01, :g1_avg_sample_02, :g1_avg_sample_03, :g1_avg_sample_04, :g1_avg_sample_05, :g1_avg_sample_06, :g1_avg_sample_07, :g1_avg_sample_08, :g1_avg_sample_09, :g1_avg_sample_10,"
46  ":g6_avg_sample_01, :g6_avg_sample_02, :g6_avg_sample_03, :g6_avg_sample_04, :g6_avg_sample_05, :g6_avg_sample_06, :g6_avg_sample_07, :g6_avg_sample_08, :g6_avg_sample_09, :g6_avg_sample_10,"
47  ":g12_avg_sample_01, :g12_avg_sample_02, :g12_avg_sample_03, :g12_avg_sample_04, :g12_avg_sample_05, :g12_avg_sample_06, :g12_avg_sample_07, :g12_avg_sample_08, :g12_avg_sample_09, :g12_avg_sample_10)"
48  );
49 
50  } catch (SQLException &e) {
51  throw(std::runtime_error("MonPulseShapeDat::prepareWrite(): "+e.getMessage()));
52  }
53 }
54 
55 
56 
58  noexcept(false)
59 {
60  this->checkConnection();
61  this->checkPrepare();
62 
63  int iovID = iov->fetchID();
64  if (!iovID) { throw(std::runtime_error("MonPulseShapeDat::writeDB: IOV not in DB")); }
65 
66  int logicID = ecid->getLogicID();
67  if (!logicID) { throw(std::runtime_error("MonPulseShapeDat::writeDB: Bad EcalLogicID")); }
68 
69  try {
70  m_writeStmt->setInt(1, iovID);
71  m_writeStmt->setInt(2, logicID);
72 
73  int gain[] = {1, 6, 12};
74  std::vector<float> samples;
75  for (int i=0; i<3; i++) {
76  samples = item->getSamples(gain[i]);
77  for (int j=0; j<10; j++) {
78  m_writeStmt->setFloat(3+(10*i)+j, samples.at(j));
79  }
80  }
81 
82  m_writeStmt->executeUpdate();
83  } catch (SQLException &e) {
84  throw(std::runtime_error("MonPulseShapeDat::writeDB: "+e.getMessage()));
85  } catch (exception &e) {
86  throw(std::runtime_error("MonPulseShapeDat::writeDB: " + string(e.what())));
87  }
88 }
89 
90 
91 
92 void MonPulseShapeDat::fetchData(std::map< EcalLogicID, MonPulseShapeDat >* fillMap, MonRunIOV* iov)
93  noexcept(false)
94 {
95  this->checkConnection();
96  fillMap->clear();
97 
98  iov->setConnection(m_env, m_conn);
99  int iovID = iov->fetchID();
100  if (!iovID) {
101  // throw(std::runtime_error("MonPulseShapeDat::writeDB: IOV not in DB"));
102  return;
103  }
104 
105  try {
106 
107  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
108  "d.g1_avg_sample_01, d.g1_avg_sample_02, d.g1_avg_sample_03, d.g1_avg_sample_04, d.g1_avg_sample_05, d.g1_avg_sample_06, d.g1_avg_sample_07, d.g1_avg_sample_08, d.g1_avg_sample_09, d.g1_avg_sample_10, "
109  "d.g6_avg_sample_01, d.g6_avg_sample_02, d.g6_avg_sample_03, d.g6_avg_sample_04, d.g6_avg_sample_05, d.g6_avg_sample_06, d.g6_avg_sample_07, d.g6_avg_sample_08, d.g6_avg_sample_09, d.g6_avg_sample_10, "
110  "d.g12_avg_sample_01, d.g12_avg_sample_02, d.g12_avg_sample_03, d.g12_avg_sample_04, d.g12_avg_sample_05, d.g12_avg_sample_06, d.g12_avg_sample_07, d.g12_avg_sample_08, d.g12_avg_sample_09, d.g12_avg_sample_10 "
111  "FROM channelview cv JOIN mon_pulse_shape_dat d "
112  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
113  "WHERE d.iov_id = :iov_id");
114  m_readStmt->setInt(1, iovID);
115  ResultSet* rset = m_readStmt->executeQuery();
116 
117  std::pair< EcalLogicID, MonPulseShapeDat > p;
118  MonPulseShapeDat dat;
119  while(rset->next()) {
120  p.first = EcalLogicID( rset->getString(1), // name
121  rset->getInt(2), // logic_id
122  rset->getInt(3), // id1
123  rset->getInt(4), // id2
124  rset->getInt(5), // id3
125  rset->getString(6)); // maps_to
126 
127  int gain[] = {1, 6, 12};
128  std::vector<float> samples(10);
129  for (int i=0; i<3; i++) {
130  samples.clear();
131  for (int j=0; j<10; j++) {
132  samples.push_back( rset->getFloat(7+(10*i)+j) );
133  }
134  dat.setSamples(samples, gain[i]);
135  }
136 
137  p.second = dat;
138  fillMap->insert(p);
139  }
140  } catch (SQLException &e) {
141  throw(std::runtime_error("MonPulseShapeDat::fetchData: "+e.getMessage()));
142  }
143 }
int i
Definition: DBlmapReader.cc:9
#define noexcept
#define NULL
Definition: scimark2.h:8
void setSamples(std::vector< float > &samples, int gain) noexcept(false)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
void fetchData(std::map< EcalLogicID, MonPulseShapeDat > *fillVec, MonRunIOV *iov) noexcept(false)
tuple iov
Definition: o2o.py:307
int j
Definition: DBlmapReader.cc:9
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
void prepareWrite() noexcept(false)
void writeDB(const EcalLogicID *ecid, const MonPulseShapeDat *item, MonRunIOV *iov) noexcept(false)
volatile std::atomic< bool > shutdown_flag false