CMS 3D CMS Logo

ODCCSConfig.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
3 #include <cstring>
4 #include <cstdlib>
5 
7 
9 
10 #include <limits>
11 
12 #define MY_NULL 16777215 // numeric_limits<int>::quiet_NaN()
13 #define SET_INT(statement, paramNum, paramVal) \
14  if (paramVal != MY_NULL) { \
15  statement->setInt(paramNum, paramVal); \
16  } else { \
17  statement->setNull(paramNum, OCCINUMBER); \
18  }
19 #define SET_STRING(statement, paramNum, paramVal) \
20  if (!paramVal.empty()) { \
21  statement->setString(paramNum, paramVal); \
22  } else { \
23  statement->setNull(paramNum, OCCICHAR); \
24  }
25 
26 using namespace std;
27 using namespace oracle::occi;
28 
30  m_env = nullptr;
31  m_conn = nullptr;
32  m_writeStmt = nullptr;
33  m_readStmt = nullptr;
34  m_config_tag = "";
35  m_ID = 0;
36  clear();
37 }
38 
40  m_daccal = MY_NULL;
41  m_delay = MY_NULL;
42  m_gain = "";
43  m_memgain = "";
44  m_offset_high = MY_NULL;
45  m_offset_low = MY_NULL;
46  m_offset_mid = MY_NULL;
47  m_trg_mode = "";
48  m_trg_filter = "";
49  m_bgo = "";
50  m_tts_mask = MY_NULL;
51  m_daq = MY_NULL;
52  m_trg = MY_NULL;
53  m_bc0 = MY_NULL;
54  m_bc0_delay = MY_NULL;
55  m_te_delay = MY_NULL;
56 }
57 
59 
61  int result = 0;
62  try {
63  this->checkConnection();
64 
65  m_readStmt = m_conn->createStatement();
66  m_readStmt->setSQL("select ecal_CCS_config_sq.NextVal from dual");
67  ResultSet* rset = m_readStmt->executeQuery();
68  while (rset->next()) {
69  result = rset->getInt(1);
70  }
71  m_conn->terminateStatement(m_readStmt);
72  return result;
73 
74  } catch (SQLException& e) {
75  throw(std::runtime_error(std::string("ODCCSConfig::fetchNextId(): ") + e.getMessage()));
76  }
77 }
78 
79 void ODCCSConfig::prepareWrite() noexcept(false) {
80  this->checkConnection();
81  int next_id = fetchNextId();
82 
83  try {
84  m_writeStmt = m_conn->createStatement();
85  m_writeStmt->setSQL(
86  "INSERT INTO ECAL_CCS_CONFIGURATION ( ccs_configuration_id, ccs_tag ,"
87  " daccal, delay, gain, memgain, offset_high,offset_low,offset_mid, trg_mode, trg_filter, "
88  " clock, BGO_SOURCE, TTS_MASK, DAQ_BCID_PRESET , TRIG_BCID_PRESET, BC0_COUNTER, BC0_DELAY, TE_DELAY ) "
89  "VALUES ( "
90  " :ccs_configuration_id, :ccs_tag, :daccal, :delay, :gain, :memgain, :offset_high,:offset_low,"
91  " :offset_mid, :trg_mode, :trg_filter, :clock, :BGO_SOURCE, :TTS_MASK, "
92  " :DAQ_BCID_PRESET , :TRIG_BCID_PRESET, :BC0_COUNTER, :BC0_DELAY, :TE_DELAY) ");
93 
94  m_writeStmt->setInt(1, next_id);
95  m_ID = next_id;
96 
97  } catch (SQLException& e) {
98  throw(std::runtime_error(std::string("ODCCSConfig::prepareWrite(): ") + e.getMessage()));
99  }
100 }
101 
102 void ODCCSConfig::setParameters(const std::map<string, string>& my_keys_map) {
103  // parses the result of the XML parser that is a map of
104  // string string with variable name variable value
105 
106  for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
107  if (ci->first == "CCS_CONFIGURATION_ID")
108  setConfigTag(ci->second);
109  else if (ci->first == "DACCAL")
110  setDaccal(atoi(ci->second.c_str()));
111  else if (ci->first == "GAIN")
112  setGain(ci->second);
113  else if (ci->first == "MEMGAIN")
114  setMemGain(ci->second);
115  else if (ci->first == "OFFSET_HIGH")
116  setOffsetHigh(atoi(ci->second.c_str()));
117  else if (ci->first == "OFFSET_LOW")
118  setOffsetLow(atoi(ci->second.c_str()));
119  else if (ci->first == "OFFSET_MID")
120  setOffsetMid(atoi(ci->second.c_str()));
121  else if (ci->first == "TRG_MODE")
122  setTrgMode(ci->second);
123  else if (ci->first == "TRG_FILTER")
124  setTrgFilter(ci->second);
125  else if (ci->first == "CLOCK")
126  setClock(atoi(ci->second.c_str()));
127  else if (ci->first == "BGO_SOURCE")
128  setBGOSource(ci->second);
129  else if (ci->first == "TTS_MASK")
130  setTTSMask(atoi(ci->second.c_str()));
131  else if (ci->first == "DAQ_BCID_PRESET")
132  setDAQBCIDPreset(atoi(ci->second.c_str()));
133  else if (ci->first == "TRIG_BCID_PRESET")
134  setTrgBCIDPreset(atoi(ci->second.c_str()));
135  else if (ci->first == "BC0_COUNTER")
136  setBC0Counter(atoi(ci->second.c_str()));
137  else if (ci->first == "BC0_DELAY")
138  setBC0Delay(atoi(ci->second.c_str()));
139  else if (ci->first == "TE_DELAY")
140  setTEDelay(atoi(ci->second.c_str()));
141  else if (ci->first == "DELAY")
142  setDelay(atoi(ci->second.c_str()));
143  }
144 }
145 
146 void ODCCSConfig::writeDB() noexcept(false) {
147  this->checkConnection();
148  this->checkPrepare();
149 
150  try {
151  // number 1 is the id
152  // m_writeStmt->setString(2, this->getConfigTag());
153  // m_writeStmt->setInt(3, this->getDaccal());
154  // m_writeStmt->setInt(4, this->getDelay());
155  // m_writeStmt->setString(5, this->getGain());
156  // m_writeStmt->setString(6, this->getMemGain());
157  // m_writeStmt->setInt(7, this->getOffsetHigh());
158  // m_writeStmt->setInt(8, this->getOffsetLow());
159  // m_writeStmt->setInt(9, this->getOffsetMid());
160  // m_writeStmt->setString(10, this->getTrgMode() );
161  // m_writeStmt->setString(11, this->getTrgFilter() );
162  // m_writeStmt->setInt( 12, this->getClock() );
163  // m_writeStmt->setString(13, this->getBGOSource() );
164  // m_writeStmt->setInt(14, this->getTTSMask() );
165  // m_writeStmt->setInt(15, this->getDAQBCIDPreset() );
166  // m_writeStmt->setInt(16, this->getTrgBCIDPreset() );
167  // m_writeStmt->setInt(17, this->getBC0Counter() );
168 
169  SET_STRING(m_writeStmt, 2, this->getConfigTag());
170  SET_INT(m_writeStmt, 3, this->getDaccal());
171  SET_INT(m_writeStmt, 4, this->getDelay());
172  SET_STRING(m_writeStmt, 5, this->getGain());
173  SET_STRING(m_writeStmt, 6, this->getMemGain());
174  SET_INT(m_writeStmt, 7, this->getOffsetHigh());
175  SET_INT(m_writeStmt, 8, this->getOffsetLow());
176  SET_INT(m_writeStmt, 9, this->getOffsetMid());
177  SET_STRING(m_writeStmt, 10, this->getTrgMode());
178  SET_STRING(m_writeStmt, 11, this->getTrgFilter());
179  SET_INT(m_writeStmt, 12, this->getClock());
180  SET_STRING(m_writeStmt, 13, this->getBGOSource());
181  SET_INT(m_writeStmt, 14, this->getTTSMask());
182  SET_INT(m_writeStmt, 15, this->getDAQBCIDPreset());
183  SET_INT(m_writeStmt, 16, this->getTrgBCIDPreset());
184  SET_INT(m_writeStmt, 17, this->getBC0Counter());
185  SET_INT(m_writeStmt, 18, this->getBC0Delay());
186  SET_INT(m_writeStmt, 19, this->getTEDelay());
187 
188  m_writeStmt->executeUpdate();
189 
190  } catch (SQLException& e) {
191  throw(std::runtime_error(std::string("ODCCSConfig::writeDB(): ") + e.getMessage()));
192  }
193  // Now get the ID
194  if (!this->fetchID()) {
195  throw(std::runtime_error("ODCCSConfig::writeDB: Failed to write"));
196  }
197 }
198 
199 void ODCCSConfig::fetchData(ODCCSConfig* result) noexcept(false) {
200  this->checkConnection();
201  result->clear();
202  if (result->getId() == 0 && (result->getConfigTag().empty())) {
203  throw(std::runtime_error("ODCCSConfig::fetchData(): no Id defined for this ODCCSConfig "));
204  }
205 
206  try {
207  m_readStmt->setSQL(
208  "SELECT * "
209  "FROM ECAL_CCS_CONFIGURATION "
210  " where ( CCS_configuration_id = :1 or CCS_tag=:2 )");
211  m_readStmt->setInt(1, result->getId());
212  m_readStmt->setString(2, result->getConfigTag());
213  ResultSet* rset = m_readStmt->executeQuery();
214 
215  rset->next();
216 
217  // 1 is the id and 2 is the config tag
218 
219  result->setId(rset->getInt(1));
220  result->setConfigTag(rset->getString(2));
221 
222  result->setDaccal(rset->getInt(3));
223  result->setDelay(rset->getInt(4));
224  result->setGain(rset->getString(5));
225  result->setMemGain(rset->getString(6));
226  result->setOffsetHigh(rset->getInt(7));
227  result->setOffsetLow(rset->getInt(8));
228  result->setOffsetMid(rset->getInt(9));
229  result->setTrgMode(rset->getString(10));
230  result->setTrgFilter(rset->getString(11));
231  result->setClock(rset->getInt(12));
232  result->setBGOSource(rset->getString(13));
233  result->setTTSMask(rset->getInt(14));
234  result->setDAQBCIDPreset(rset->getInt(15));
235  result->setTrgBCIDPreset(rset->getInt(16));
236  result->setBC0Counter(rset->getInt(17));
237 
238  } catch (SQLException& e) {
239  throw(std::runtime_error(std::string("ODCCSConfig::fetchData(): ") + e.getMessage()));
240  }
241 }
242 
243 int ODCCSConfig::fetchID() noexcept(false) {
244  // Return from memory if available
245  if (m_ID != 0) {
246  return m_ID;
247  }
248 
249  this->checkConnection();
250 
251  try {
252  Statement* stmt = m_conn->createStatement();
253  stmt->setSQL(
254  "SELECT ccs_configuration_id FROM ecal_ccs_configuration "
255  "WHERE ccs_tag=:ccs_tag ");
256 
257  stmt->setString(1, getConfigTag());
258 
259  ResultSet* rset = stmt->executeQuery();
260 
261  if (rset->next()) {
262  m_ID = rset->getInt(1);
263  } else {
264  m_ID = 0;
265  }
266  m_conn->terminateStatement(stmt);
267  } catch (SQLException& e) {
268  throw(std::runtime_error(std::string("ODCCSConfig::fetchID: ") + e.getMessage()));
269  }
270 
271  return m_ID;
272 }
funct::false
false
Definition: Factorize.h:29
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
ODCCSConfig::ODCCSConfig
ODCCSConfig()
Definition: ODCCSConfig.cc:29
ODCCSConfig::prepareWrite
void prepareWrite() noexcept(false) override
Definition: ODCCSConfig.cc:79
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
SET_INT
#define SET_INT(statement, paramNum, paramVal)
Definition: ODCCSConfig.cc:13
oracle::occi
Definition: ConnectionManager.h:7
ODCCSConfig
Definition: ODCCSConfig.h:9
SET_STRING
#define SET_STRING(statement, paramNum, paramVal)
Definition: ODCCSConfig.cc:19
MY_NULL
#define MY_NULL
Definition: ODCCSConfig.cc:12
ODCCSConfig::setParameters
void setParameters(const std::map< std::string, std::string > &my_keys_map)
Definition: ODCCSConfig.cc:102
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
clear
void clear(HadCaloObj &c)
Definition: data.h:124
ODCCSConfig::~ODCCSConfig
~ODCCSConfig() override
Definition: ODCCSConfig.cc:58
ODCCSConfig::fetchData
void fetchData(ODCCSConfig *result) noexcept(false)
Definition: ODCCSConfig.cc:199
ODCCSConfig.h
ODCCSConfig::clear
void clear()
Definition: ODCCSConfig.cc:39
std
Definition: JetResolutionObject.h:76
ODCCSConfig::writeDB
void writeDB() noexcept(false)
Definition: ODCCSConfig.cc:146
Oracle.h
mps_fire.result
result
Definition: mps_fire.py:311
ODCCSConfig::fetchNextId
int fetchNextId() noexcept(false)
Definition: ODCCSConfig.cc:60
ODCCSConfig::fetchID
int fetchID() noexcept(false)
Definition: ODCCSConfig.cc:243
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37