CMS 3D CMS Logo

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  m_env = nullptr;
14  m_conn = nullptr;
15  m_writeStmt = nullptr;
16  m_readStmt = nullptr;
17 
18  m_samplesG1.assign(10, 0);
19  m_samplesG6.assign(10, 0);
20  m_samplesG12.assign(10, 0);
21 }
22 
24 
26  this->checkConnection();
27 
28  try {
29  m_writeStmt = m_conn->createStatement();
30  m_writeStmt->setSQL(
31  "INSERT INTO mon_pulse_shape_dat (iov_id, logic_id, "
32  "g1_avg_sample_01, g1_avg_sample_02, g1_avg_sample_03, g1_avg_sample_04, g1_avg_sample_05, g1_avg_sample_06, "
33  "g1_avg_sample_07, g1_avg_sample_08, g1_avg_sample_09, g1_avg_sample_10, "
34  "g6_avg_sample_01, g6_avg_sample_02, g6_avg_sample_03, g6_avg_sample_04, g6_avg_sample_05, g6_avg_sample_06, "
35  "g6_avg_sample_07, g6_avg_sample_08, g6_avg_sample_09, g6_avg_sample_10, "
36  "g12_avg_sample_01, g12_avg_sample_02, g12_avg_sample_03, g12_avg_sample_04, g12_avg_sample_05, "
37  "g12_avg_sample_06, g12_avg_sample_07, g12_avg_sample_08, g12_avg_sample_09, g12_avg_sample_10) "
38  "VALUES (:iov_id, :logic_id, "
39  ":g1_avg_sample_01, :g1_avg_sample_02, :g1_avg_sample_03, :g1_avg_sample_04, :g1_avg_sample_05, "
40  ":g1_avg_sample_06, :g1_avg_sample_07, :g1_avg_sample_08, :g1_avg_sample_09, :g1_avg_sample_10,"
41  ":g6_avg_sample_01, :g6_avg_sample_02, :g6_avg_sample_03, :g6_avg_sample_04, :g6_avg_sample_05, "
42  ":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, "
44  ":g12_avg_sample_06, :g12_avg_sample_07, :g12_avg_sample_08, :g12_avg_sample_09, :g12_avg_sample_10)");
45 
46  } catch (SQLException& e) {
47  throw(std::runtime_error("MonPulseShapeDat::prepareWrite(): " + e.getMessage()));
48  }
49 }
50 
51 void MonPulseShapeDat::writeDB(const EcalLogicID* ecid, const MonPulseShapeDat* item, MonRunIOV* iov) noexcept(false) {
52  this->checkConnection();
53  this->checkPrepare();
54 
55  int iovID = iov->fetchID();
56  if (!iovID) {
57  throw(std::runtime_error("MonPulseShapeDat::writeDB: IOV not in DB"));
58  }
59 
60  int logicID = ecid->getLogicID();
61  if (!logicID) {
62  throw(std::runtime_error("MonPulseShapeDat::writeDB: Bad EcalLogicID"));
63  }
64 
65  try {
66  m_writeStmt->setInt(1, iovID);
67  m_writeStmt->setInt(2, logicID);
68 
69  int gain[] = {1, 6, 12};
70  std::vector<float> samples;
71  for (int i = 0; i < 3; i++) {
72  samples = item->getSamples(gain[i]);
73  for (int j = 0; j < 10; j++) {
74  m_writeStmt->setFloat(3 + (10 * i) + j, samples.at(j));
75  }
76  }
77 
78  m_writeStmt->executeUpdate();
79  } catch (SQLException& e) {
80  throw(std::runtime_error("MonPulseShapeDat::writeDB: " + e.getMessage()));
81  } catch (exception& e) {
82  throw(std::runtime_error("MonPulseShapeDat::writeDB: " + string(e.what())));
83  }
84 }
85 
86 void MonPulseShapeDat::fetchData(std::map<EcalLogicID, MonPulseShapeDat>* fillMap, MonRunIOV* iov) noexcept(false) {
87  this->checkConnection();
88  fillMap->clear();
89 
90  iov->setConnection(m_env, m_conn);
91  int iovID = iov->fetchID();
92  if (!iovID) {
93  // throw(std::runtime_error("MonPulseShapeDat::writeDB: IOV not in DB"));
94  return;
95  }
96 
97  try {
98  m_readStmt->setSQL(
99  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
100  "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, "
101  "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, "
102  "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, "
103  "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, "
104  "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, "
105  "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 "
106  "FROM channelview cv JOIN mon_pulse_shape_dat d "
107  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
108  "WHERE d.iov_id = :iov_id");
109  m_readStmt->setInt(1, iovID);
110  ResultSet* rset = m_readStmt->executeQuery();
111 
112  std::pair<EcalLogicID, MonPulseShapeDat> p;
113  MonPulseShapeDat dat;
114  while (rset->next()) {
115  p.first = EcalLogicID(rset->getString(1), // name
116  rset->getInt(2), // logic_id
117  rset->getInt(3), // id1
118  rset->getInt(4), // id2
119  rset->getInt(5), // id3
120  rset->getString(6)); // maps_to
121 
122  int gain[] = {1, 6, 12};
123  std::vector<float> samples(10);
124  for (int i = 0; i < 3; i++) {
125  samples.clear();
126  for (int j = 0; j < 10; j++) {
127  samples.push_back(rset->getFloat(7 + (10 * i) + j));
128  }
129  dat.setSamples(samples, gain[i]);
130  }
131 
132  p.second = dat;
133  fillMap->insert(p);
134  }
135  } catch (SQLException& e) {
136  throw(std::runtime_error("MonPulseShapeDat::fetchData: " + e.getMessage()));
137  }
138 }
mps_fire.i
i
Definition: mps_fire.py:428
MonPulseShapeDat::prepareWrite
void prepareWrite() noexcept(false) override
Definition: MonPulseShapeDat.cc:25
funct::false
false
Definition: Factorize.h:29
MonPulseShapeDat.h
EgammaValidation_cff.samples
samples
Definition: EgammaValidation_cff.py:18
oracle::occi
Definition: ConnectionManager.h:7
EcalLogicID
Definition: EcalLogicID.h:7
MonPulseShapeDat::writeDB
void writeDB(const EcalLogicID *ecid, const MonPulseShapeDat *item, MonRunIOV *iov) noexcept(false)
Definition: MonPulseShapeDat.cc:51
MonPulseShapeDat::~MonPulseShapeDat
~MonPulseShapeDat() override
Definition: MonPulseShapeDat.cc:23
MonRunIOV.h
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
MonPulseShapeDat::MonPulseShapeDat
MonPulseShapeDat()
Definition: MonPulseShapeDat.cc:12
MonRunIOV
Definition: MonRunIOV.h:14
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
PedestalClient_cfi.gain
gain
Definition: PedestalClient_cfi.py:37
MonRunTag.h
std
Definition: JetResolutionObject.h:76
MonPulseShapeDat::setSamples
void setSamples(std::vector< float > &samples, int gain) noexcept(false)
Definition: MonPulseShapeDat.h:22
MonPulseShapeDat::fetchData
void fetchData(std::map< EcalLogicID, MonPulseShapeDat > *fillVec, MonRunIOV *iov) noexcept(false)
Definition: MonPulseShapeDat.cc:86
Oracle.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
MonPulseShapeDat
Definition: MonPulseShapeDat.h:13
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37