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); \ 17 statement->setNull(paramNum, OCCINUMBER); \ 19 #define SET_STRING(statement, paramNum, paramVal) \ 20 if (!paramVal.empty()) { \ 21 statement->setString(paramNum, paramVal); \ 23 statement->setNull(paramNum, OCCICHAR); \ 32 m_writeStmt =
nullptr;
63 this->checkConnection();
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()) {
71 m_conn->terminateStatement(m_readStmt);
75 throw(std::runtime_error(
std::string(
"ODCCSConfig::fetchNextId(): ") +
e.getMessage()));
80 this->checkConnection();
81 int next_id = fetchNextId();
84 m_writeStmt = m_conn->createStatement();
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 ) " 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) ");
94 m_writeStmt->setInt(1, next_id);
98 throw(std::runtime_error(
std::string(
"ODCCSConfig::prepareWrite(): ") +
e.getMessage()));
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")
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()));
147 this->checkConnection();
148 this->checkPrepare();
169 SET_STRING(m_writeStmt, 2, this->getConfigTag());
170 SET_INT(m_writeStmt, 3, this->getDaccal());
171 SET_INT(m_writeStmt, 4, this->getDelay());
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());
188 m_writeStmt->executeUpdate();
191 throw(std::runtime_error(
std::string(
"ODCCSConfig::writeDB(): ") +
e.getMessage()));
194 if (!this->fetchID()) {
195 throw(std::runtime_error(
"ODCCSConfig::writeDB: Failed to write"));
200 this->checkConnection();
202 if (
result->getId() == 0 && (
result->getConfigTag().empty())) {
203 throw(std::runtime_error(
"ODCCSConfig::fetchData(): no Id defined for this ODCCSConfig "));
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();
219 result->setId(rset->getInt(1));
220 result->setConfigTag(rset->getString(2));
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));
239 throw(std::runtime_error(
std::string(
"ODCCSConfig::fetchData(): ") +
e.getMessage()));
249 this->checkConnection();
252 Statement* stmt = m_conn->createStatement();
254 "SELECT ccs_configuration_id FROM ecal_ccs_configuration " 255 "WHERE ccs_tag=:ccs_tag ");
257 stmt->setString(1, getConfigTag());
259 ResultSet* rset = stmt->executeQuery();
262 m_ID = rset->getInt(1);
266 m_conn->terminateStatement(stmt);
268 throw(std::runtime_error(
std::string(
"ODCCSConfig::fetchID: ") +
e.getMessage()));
void writeDB() noexcept(false)
int fetchID() noexcept(false)
void fetchData(ODCCSConfig *result) noexcept(false)
int fetchNextId() noexcept(false)
void setParameters(const std::map< std::string, std::string > &my_keys_map)
#define SET_STRING(statement, paramNum, paramVal)
void prepareWrite() noexcept(false) override
oracle::occi::Statement Statement
oracle::occi::SQLException SQLException
void clear(HadCaloObj &c)
#define SET_INT(statement, paramNum, paramVal)