12 #define MY_NULL 16777215 // numeric_limits<int>::quiet_NaN()
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); }
17 using namespace oracle::occi;
62 this->checkConnection();
64 m_readStmt = m_conn->createStatement();
65 m_readStmt->setSQL(
"select ecal_CCS_config_sq.NextVal from dual");
66 ResultSet* rset = m_readStmt->executeQuery();
67 while (rset->next ()){
68 result= rset->getInt(1);
70 m_conn->terminateStatement(m_readStmt);
74 throw(std::runtime_error(
"ODCCSConfig::fetchNextId(): "+e.getMessage()));
80 throw(std::runtime_error)
82 this->checkConnection();
83 int next_id=fetchNextId();
86 m_writeStmt = m_conn->createStatement();
87 m_writeStmt->setSQL(
"INSERT INTO ECAL_CCS_CONFIGURATION ( ccs_configuration_id, ccs_tag ,"
88 " daccal, delay, gain, memgain, offset_high,offset_low,offset_mid, trg_mode, trg_filter, "
89 " clock, BGO_SOURCE, TTS_MASK, DAQ_BCID_PRESET , TRIG_BCID_PRESET, BC0_COUNTER, BC0_DELAY, TE_DELAY ) "
91 " :ccs_configuration_id, :ccs_tag, :daccal, :delay, :gain, :memgain, :offset_high,:offset_low,"
92 " :offset_mid, :trg_mode, :trg_filter, :clock, :BGO_SOURCE, :TTS_MASK, "
93 " :DAQ_BCID_PRESET , :TRIG_BCID_PRESET, :BC0_COUNTER, :BC0_DELAY, :TE_DELAY) ");
95 m_writeStmt->setInt(1, next_id);
99 throw(std::runtime_error(
"ODCCSConfig::prepareWrite(): "+e.getMessage()));
109 for( std::map<std::string, std::string >::const_iterator ci=
110 my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
112 if(ci->first==
"CCS_CONFIGURATION_ID") setConfigTag(ci->second);
113 else if(ci->first==
"DACCAL") setDaccal(atoi(ci->second.c_str()) );
114 else if(ci->first==
"GAIN") setGain(ci->second);
115 else if(ci->first==
"MEMGAIN") setMemGain(ci->second);
116 else if(ci->first==
"OFFSET_HIGH") setOffsetHigh(atoi(ci->second.c_str() ));
117 else if(ci->first==
"OFFSET_LOW") setOffsetLow(atoi(ci->second.c_str() ));
118 else if(ci->first==
"OFFSET_MID") setOffsetMid(atoi(ci->second.c_str() ));
119 else if(ci->first==
"TRG_MODE") setTrgMode(ci->second );
120 else if(ci->first==
"TRG_FILTER") setTrgFilter(ci->second );
121 else if(ci->first==
"CLOCK") setClock(atoi(ci->second.c_str()) );
122 else if(ci->first==
"BGO_SOURCE") setBGOSource(ci->second) ;
123 else if(ci->first==
"TTS_MASK") setTTSMask(atoi(ci->second.c_str()) );
124 else if(ci->first==
"DAQ_BCID_PRESET") setDAQBCIDPreset(atoi(ci->second.c_str() ));
125 else if(ci->first==
"TRIG_BCID_PRESET") setTrgBCIDPreset(atoi(ci->second.c_str()) );
126 else if(ci->first==
"BC0_COUNTER") setBC0Counter(atoi(ci->second.c_str() ));
127 else if(ci->first==
"BC0_DELAY") setBC0Delay(atoi(ci->second.c_str() ));
128 else if(ci->first==
"TE_DELAY") setTEDelay(atoi(ci->second.c_str() ));
129 else if(ci->first==
"DELAY") setDelay(atoi(ci->second.c_str() ));
136 throw(std::runtime_error)
138 this->checkConnection();
139 this->checkPrepare();
161 SET_STRING(m_writeStmt, 2, this->getConfigTag());
162 SET_INT (m_writeStmt, 3, this->getDaccal());
163 SET_INT (m_writeStmt, 4, this->getDelay());
165 SET_STRING(m_writeStmt, 6, this->getMemGain());
166 SET_INT (m_writeStmt, 7, this->getOffsetHigh());
167 SET_INT (m_writeStmt, 8, this->getOffsetLow());
168 SET_INT (m_writeStmt, 9, this->getOffsetMid());
169 SET_STRING(m_writeStmt, 10, this->getTrgMode());
170 SET_STRING(m_writeStmt, 11, this->getTrgFilter());
171 SET_INT (m_writeStmt, 12, this->getClock());
172 SET_STRING(m_writeStmt, 13, this->getBGOSource());
173 SET_INT (m_writeStmt, 14, this->getTTSMask());
174 SET_INT (m_writeStmt, 15, this->getDAQBCIDPreset());
175 SET_INT (m_writeStmt, 16, this->getTrgBCIDPreset());
176 SET_INT (m_writeStmt, 17, this->getBC0Counter());
177 SET_INT (m_writeStmt, 18, this->getBC0Delay());
178 SET_INT (m_writeStmt, 19, this->getTEDelay());
180 m_writeStmt->executeUpdate();
184 throw(std::runtime_error(
"ODCCSConfig::writeDB(): "+e.getMessage()));
187 if (!this->fetchID()) {
188 throw(std::runtime_error(
"ODCCSConfig::writeDB: Failed to write"));
196 throw(std::runtime_error)
198 this->checkConnection();
200 if(
result->getId()==0 && (
result->getConfigTag()==
"") ){
201 throw(std::runtime_error(
"ODCCSConfig::fetchData(): no Id defined for this ODCCSConfig "));
206 m_readStmt->setSQL(
"SELECT * "
207 "FROM ECAL_CCS_CONFIGURATION "
208 " where ( CCS_configuration_id = :1 or CCS_tag=:2 )" );
209 m_readStmt->setInt(1,
result->getId());
210 m_readStmt->setString(2,
result->getConfigTag());
211 ResultSet* rset = m_readStmt->executeQuery();
217 result->setId(rset->getInt(1));
218 result->setConfigTag(rset->getString(2));
220 result->setDaccal( rset->getInt(3) );
221 result->setDelay( rset->getInt(4) );
222 result->setGain( rset->getString(5) );
223 result->setMemGain( rset->getString(6) );
224 result->setOffsetHigh( rset->getInt(7) );
225 result->setOffsetLow( rset->getInt(8) );
226 result->setOffsetMid( rset->getInt(9) );
227 result->setTrgMode( rset->getString(10) );
228 result->setTrgFilter( rset->getString(11) );
229 result->setClock( rset->getInt(12) );
230 result->setBGOSource( rset->getString(13) );
231 result->setTTSMask( rset->getInt(14) );
232 result->setDAQBCIDPreset( rset->getInt(15) );
233 result->setTrgBCIDPreset( rset->getInt(16) );
234 result->setBC0Counter( rset->getInt(17) );
238 throw(std::runtime_error(
"ODCCSConfig::fetchData(): "+e.getMessage()));
249 this->checkConnection();
252 Statement* stmt = m_conn->createStatement();
253 stmt->setSQL(
"SELECT ccs_configuration_id FROM ecal_ccs_configuration "
254 "WHERE ccs_tag=:ccs_tag "
257 stmt->setString(1, getConfigTag() );
262 m_ID = rset->getInt(1);
266 m_conn->terminateStatement(stmt);
268 throw(std::runtime_error(
"ODCCSConfig::fetchID: "+e.getMessage()));
void fetchData(ODCCSConfig *result)
void setParameters(const std::map< std::string, std::string > &my_keys_map)
#define SET_STRING(statement, paramNum, paramVal)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
oracle::occi::Statement Statement
oracle::occi::ResultSet ResultSet
oracle::occi::SQLException SQLException
#define SET_INT(statement, paramNum, paramVal)