13 #define SET_INT( statement, paramNum, paramVal ) if( paramVal != MY_NULL ) { statement->setInt(paramNum, paramVal); } else { statement->setNull(paramNum,OCCINUMBER); } 14 #define SET_STRING( statement, paramNum, paramVal ) if( ! paramVal.empty() ) { statement->setString(paramNum, paramVal); } else { statement->setNull(paramNum,OCCICHAR); } 16 int getInt(ResultSet * rset,
int ipar )
18 return rset->isNull(ipar) ?
MY_NULL : rset->getInt(ipar) ;
25 m_writeStmt =
nullptr;
59 this->checkConnection();
61 m_readStmt = m_conn->createStatement();
62 m_readStmt->setSQL(
"select fe_daq_conDfig_sq.nextVal from dual");
63 ResultSet* rset = m_readStmt->executeQuery();
64 while (rset->next ()){
65 result= rset->getInt(1);
67 m_conn->terminateStatement(m_readStmt);
71 throw(std::runtime_error(
std::string(
"ODFEDAQConfig::fetchNextId(): ")+getOraMessage(&e)));
79 this->checkConnection();
80 int next_id=fetchNextId();
83 m_writeStmt = m_conn->createStatement();
84 m_writeStmt->setSQL(
"INSERT INTO FE_DAQ_CONFIG ( config_id, tag, version, ped_id, " 85 " del_id, wei_id,bxt_id, btt_id, tr_bxt_id, tr_btt_id, user_comment ) " 86 "VALUES ( :1, :2, :3, :4, :5, :6, :7 ,:8, :9, :10, :11 )" );
88 m_writeStmt->setInt(1, next_id);
92 throw(std::runtime_error(
std::string(
"ODFEDAQConfig::prepareWrite(): ")+getOraMessage(&e)));
102 for( std::map<std::string, std::string >::const_iterator ci=
103 my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
105 if(ci->first==
"VERSION") setVersion(atoi(ci->second.c_str()) );
106 if(ci->first==
"PED_ID") setPedestalId(atoi(ci->second.c_str()) );
107 if(ci->first==
"DEL_ID") setDelayId(atoi(ci->second.c_str()));
108 if(ci->first==
"WEI_ID") setWeightId(atoi(ci->second.c_str()));
110 if(ci->first==
"BXT_ID") setBadXtId(atoi(ci->second.c_str()));
111 if(ci->first==
"BTT_ID") setBadTTId(atoi(ci->second.c_str()));
112 if(ci->first==
"TRIG_BXT_ID") setTriggerBadXtId(atoi(ci->second.c_str()));
113 if(ci->first==
"TRIG_BTT_ID") setTriggerBadTTId(atoi(ci->second.c_str()));
115 if(ci->first==
"COMMENT" || ci->first==
"USER_COMMENT") setComment(ci->second);
124 this->checkConnection();
125 this->checkPrepare();
130 m_writeStmt->setString(2, this->getConfigTag());
131 m_writeStmt->setInt(3, this->getVersion());
132 SET_INT(m_writeStmt,4, this->getPedestalId());
133 SET_INT(m_writeStmt,5, this->getDelayId());
134 SET_INT(m_writeStmt,6, this->getWeightId());
135 SET_INT(m_writeStmt,7, this->getBadXtId());
136 SET_INT(m_writeStmt,8, this->getBadTTId());
137 SET_INT(m_writeStmt,9, this->getTriggerBadXtId());
138 SET_INT(m_writeStmt,10,this->getTriggerBadTTId());
140 m_writeStmt->setString(11, this->getComment());
142 m_writeStmt->executeUpdate();
146 throw(std::runtime_error(
std::string(
"ODFEDAQConfig::writeDB(): ")+getOraMessage(&e)));
149 if (!this->fetchID()) {
150 throw(std::runtime_error(
"ODFEDAQConfig::writeDB: Failed to write"));
160 this->checkConnection();
162 if(
result->getId()==0 && (
result->getConfigTag().empty()) ){
163 throw(std::runtime_error(
"ODFEDAQConfig::fetchData(): no Id defined for this ODFEDAQConfig "));
166 m_readStmt = m_conn->createStatement();
167 if(!
result->getConfigTag().empty() &&
result->getVersion() ==0 ){
169 std::cout<<
"using new method : retrieving last version for this tag "<<endl;
171 this->checkConnection();
173 m_readStmt->setSQL(
"select max(version) from "+getTable()+
" where tag=:tag " );
174 m_readStmt->setString(1,
result->getConfigTag());
175 std::cout <<
"Getting last ver" << std::endl << std::flush;
176 ResultSet* rset = m_readStmt->executeQuery();
177 while (rset->next ()){
178 new_version= rset->getInt(1);
180 m_conn->terminateStatement(m_readStmt);
184 result->setVersion(new_version);
187 throw(std::runtime_error(
std::string(
"ODFEDAQConfig::fetchData(): ")+getOraMessage(&e)));
196 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
197 " where ( config_id = :1 or (tag=:2 AND version=:3 ) )" );
198 m_readStmt->setInt(1,
result->getId());
199 m_readStmt->setString(2,
result->getConfigTag());
200 m_readStmt->setInt(3,
result->getVersion());
201 ResultSet* rset = m_readStmt->executeQuery();
207 result->setId(rset->getInt(1));
208 result->setConfigTag(getOraString(rset,2));
209 result->setVersion(rset->getInt(3));
218 result->setComment( getOraString(rset,11) );
221 throw(std::runtime_error(
std::string(
"ODFEDAQConfig::fetchData(): ")+getOraMessage(&e)));
232 this->checkConnection();
235 Statement* stmt = m_conn->createStatement();
236 stmt->setSQL(
"SELECT config_id FROM "+ getTable()+
237 "WHERE tag=:1 and version=:2 " );
239 stmt->setString(1, getConfigTag() );
240 stmt->setInt(2, getVersion() );
242 ResultSet* rset = stmt->executeQuery();
245 m_ID = rset->getInt(1);
249 m_conn->terminateStatement(stmt);
251 throw(std::runtime_error(
std::string(
"ODFEDAQConfig::fetchID: ")+getOraMessage(&e)));
int fetchNextId() noexcept(false)
void setParameters(const std::map< std::string, std::string > &my_keys_map)
void prepareWrite() noexcept(false) override
int getInt(ResultSet *rset, int ipar)
~ODFEDAQConfig() override
int fetchID() noexcept(false)
#define SET_INT(statement, paramNum, paramVal)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
oracle::occi::Statement Statement
void fetchData(ODFEDAQConfig *result) noexcept(false)
oracle::occi::SQLException SQLException
void writeDB() noexcept(false)