CMS 3D CMS Logo

ODLTSConfig.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <cstdlib>
3 #include <string>
5 
7 
8 using namespace std;
9 using namespace oracle::occi;
10 
12  m_env = nullptr;
13  m_conn = nullptr;
14  m_writeStmt = nullptr;
15  m_readStmt = nullptr;
16  m_config_tag = "";
17  m_ID = 0;
18  clear();
19 }
20 
22  m_trg_type = "";
23  m_num = 0;
24  m_rate = 0;
25  m_delay = 0;
26 }
27 
29 
30 void ODLTSConfig::setParameters(const std::map<string, string>& my_keys_map) {
31  // parses the result of the XML parser that is a map of
32  // string string with variable name variable value
33 
34  for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
35  if (ci->first == "LTS_CONFIGURATION_ID")
36  setConfigTag(ci->second);
37  if (ci->first == "NUM_OF_EVENTS")
38  setNumberOfEvents(atoi(ci->second.c_str()));
39  if (ci->first == "RATE")
40  setRate(atoi(ci->second.c_str()));
41  if (ci->first == "TRIGGER_TYPE")
42  setTriggerType(ci->second);
43  if (ci->first == "TRIG_LOC_L1_DELAY")
44  setTrigLocL1Delay(atoi(ci->second.c_str()));
45  }
46 }
47 
49  int result = 0;
50  try {
51  this->checkConnection();
52 
53  m_readStmt = m_conn->createStatement();
54  m_readStmt->setSQL("select ecal_lts_config_sq.NextVal from dual");
55  ResultSet* rset = m_readStmt->executeQuery();
56  while (rset->next()) {
57  result = rset->getInt(1);
58  }
59  m_conn->terminateStatement(m_readStmt);
60  return result;
61 
62  } catch (SQLException& e) {
63  throw(std::runtime_error(std::string("ODLTSConfig::fetchNextId(): ") + e.getMessage()));
64  }
65 }
66 
67 void ODLTSConfig::prepareWrite() noexcept(false) {
68  this->checkConnection();
69  int next_id = fetchNextId();
70 
71  try {
72  m_writeStmt = m_conn->createStatement();
73  m_writeStmt->setSQL(
74  "INSERT INTO ECAL_LTS_CONFIGURATION ( lts_configuration_id, lts_tag, "
75  "trigger_type, num_of_events, rate, trig_loc_l1_delay ) "
76  "VALUES ( "
77  ":1, :2, :3, :4 , :5, :6 )");
78  m_writeStmt->setInt(1, next_id);
79  m_ID = next_id;
80 
81  } catch (SQLException& e) {
82  throw(std::runtime_error(std::string("ODLTSConfig::prepareWrite(): ") + e.getMessage()));
83  }
84 }
85 
86 void ODLTSConfig::writeDB() noexcept(false) {
87  this->checkConnection();
88  this->checkPrepare();
89 
90  try {
91  m_writeStmt->setString(2, this->getConfigTag());
92  m_writeStmt->setString(3, this->getTriggerType());
93  m_writeStmt->setInt(4, this->getNumberOfEvents());
94  m_writeStmt->setInt(5, this->getRate());
95  m_writeStmt->setInt(6, this->getTrigLocL1Delay());
96 
97  m_writeStmt->executeUpdate();
98 
99  } catch (SQLException& e) {
100  throw(std::runtime_error(std::string("ODLTSConfig::writeDB(): ") + e.getMessage()));
101  }
102  // Now get the ID
103  if (!this->fetchID()) {
104  throw(std::runtime_error("ODLTSConfig::writeDB: Failed to write"));
105  }
106 }
107 
108 void ODLTSConfig::fetchData(ODLTSConfig* result) noexcept(false) {
109  this->checkConnection();
110  result->clear();
111  if (result->getId() == 0 && (result->getConfigTag().empty())) {
112  throw(std::runtime_error("ODLTSConfig::fetchData(): no Id defined for this ODLTSConfig "));
113  }
114 
115  try {
116  m_readStmt->setSQL(
117  "SELECT * "
118  "FROM ECAL_LTS_CONFIGURATION "
119  " where ( lts_configuration_id = :1 or lts_tag=:2 ) ");
120  m_readStmt->setInt(1, result->getId());
121  m_readStmt->setString(2, result->getConfigTag());
122  ResultSet* rset = m_readStmt->executeQuery();
123 
124  rset->next();
125  // 1 is the id and 2 is the config tag
126  result->setId(rset->getInt(1));
127  result->setConfigTag(rset->getString(2));
128 
129  result->setTriggerType(rset->getString(3));
130  result->setNumberOfEvents(rset->getInt(4));
131  result->setRate(rset->getInt(5));
132  result->setTrigLocL1Delay(rset->getInt(6));
133 
134  } catch (SQLException& e) {
135  throw(std::runtime_error(std::string("ODLTSConfig::fetchData(): ") + e.getMessage()));
136  }
137 }
138 
139 int ODLTSConfig::fetchID() noexcept(false) {
140  // Return from memory if available
141  if (m_ID != 0) {
142  return m_ID;
143  }
144 
145  this->checkConnection();
146 
147  try {
148  Statement* stmt = m_conn->createStatement();
149  stmt->setSQL(
150  "SELECT lts_configuration_id FROM ecal_lts_configuration "
151  "WHERE lts_tag=:lts_tag ");
152 
153  stmt->setString(1, getConfigTag());
154 
155  ResultSet* rset = stmt->executeQuery();
156 
157  if (rset->next()) {
158  m_ID = rset->getInt(1);
159  } else {
160  m_ID = 0;
161  }
162  m_conn->terminateStatement(stmt);
163  } catch (SQLException& e) {
164  throw(std::runtime_error(std::string("ODLTSConfig::fetchID: ") + e.getMessage()));
165  }
166 
167  return m_ID;
168 }
ODLTSConfig::writeDB
void writeDB() noexcept(false)
Definition: ODLTSConfig.cc:86
funct::false
false
Definition: Factorize.h:34
ODLTSConfig::clear
void clear()
Definition: ODLTSConfig.cc:21
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
ODLTSConfig::fetchData
void fetchData(ODLTSConfig *result) noexcept(false)
Definition: ODLTSConfig.cc:108
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
oracle::occi
Definition: ConnectionManager.h:7
ODLTSConfig::fetchNextId
int fetchNextId() noexcept(false)
Definition: ODLTSConfig.cc:48
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
clear
void clear(HadCaloObj &c)
Definition: data.h:124
ODLTSConfig::ODLTSConfig
ODLTSConfig()
Definition: ODLTSConfig.cc:11
ODLTSConfig::~ODLTSConfig
~ODLTSConfig() override
Definition: ODLTSConfig.cc:28
ODLTSConfig::fetchID
int fetchID() noexcept(false)
Definition: ODLTSConfig.cc:139
std
Definition: JetResolutionObject.h:76
ODLTSConfig::prepareWrite
void prepareWrite() noexcept(false) override
Definition: ODLTSConfig.cc:67
Oracle.h
mps_fire.result
result
Definition: mps_fire.py:303
ODLTSConfig
Definition: ODLTSConfig.h:9
ODLTSConfig.h
ODLTSConfig::setParameters
void setParameters(const std::map< std::string, std::string > &my_keys_map)
Definition: ODLTSConfig.cc:30
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37