19 m_writeStmt =
nullptr;
39 this->checkConnection();
41 m_readStmt = m_conn->createStatement();
42 m_readStmt->setSQL(
"select ecal_dcc_config_sq.NextVal from dual");
43 ResultSet* rset = m_readStmt->executeQuery();
44 while (rset->next ()){
45 result= rset->getInt(1);
47 m_conn->terminateStatement(m_readStmt);
51 throw(std::runtime_error(
std::string(
"ODDCCConfig::fetchNextId(): ")+getOraMessage(&e)));
62 this->checkConnection();
64 int next_id=fetchNextId();
67 m_writeStmt = m_conn->createStatement();
68 m_writeStmt->setSQL(
"INSERT INTO ECAL_DCC_CONFIGURATION (dcc_configuration_id, dcc_tag, " 69 " DCC_CONFIGURATION_URL, TESTPATTERN_FILE_URL, " 70 " N_TESTPATTERNS_TO_LOAD , SM_HALF, weightsmode, " 71 " dcc_configuration) " 72 "VALUES (:1, :2, :3, :4, :5, :6 , :7 ,:8 )");
73 m_writeStmt->setInt(1, next_id);
74 m_writeStmt->setString(2, getConfigTag());
75 m_writeStmt->setString(3, getDCCConfigurationUrl());
76 m_writeStmt->setString(4, getTestPatternFileUrl());
77 m_writeStmt->setInt(5, getNTestPatternsToLoad());
78 m_writeStmt->setInt(6, getSMHalf());
79 m_writeStmt->setString(7, getDCCWeightsMode());
82 oracle::occi::Clob clob(m_conn);
84 m_writeStmt->setClob(8,clob);
85 m_writeStmt->executeUpdate ();
88 m_conn->terminateStatement(m_writeStmt);
89 std::cout<<
"DCC Clob inserted into CONFIGURATION with id="<<next_id<<std::endl;
92 m_writeStmt = m_conn->createStatement();
93 m_writeStmt->setSQL (
"SELECT dcc_configuration FROM ECAL_DCC_CONFIGURATION WHERE" 94 " dcc_configuration_id=:1 FOR UPDATE");
96 std::cout<<
"updating the clob 0"<<std::endl;
101 throw(std::runtime_error(
std::string(
"ODDCCConfig::prepareWrite(): ")+getOraMessage(&e)));
104 std::cout<<
"updating the clob 1 "<<std::endl;
115 for( std::map<std::string, std::string >::const_iterator ci=
116 my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
118 if(ci->first==
"DCC_CONFIGURATION_ID") setConfigTag(ci->second);
119 if(ci->first==
"TESTPATTERN_FILE_URL") setTestPatternFileUrl(ci->second );
120 if(ci->first==
"N_TESTPATTERNS_TO_LOAD") setNTestPatternsToLoad(atoi(ci->second.c_str() ));
121 if(ci->first==
"SM_HALF") setSMHalf(atoi(ci->second.c_str() ));
122 if(ci->first==
"WEIGHTSMODE") setDCCWeightsMode(ci->second );
123 if(ci->first==
"DCC_CONFIGURATION_URL") {
125 setDCCConfigurationUrl(fname );
128 std::cout <<
"Going to read DCC file: " << fname << endl;
131 inpFile.open(fname.c_str());
136 bufsize = inpFile.tellg();
137 std::cout <<
" bufsize ="<<bufsize<< std::endl;
139 inpFile.seekg( 0,ios::beg );
158 std::cout<<
"updating the clob "<<std::endl;
164 m_writeStmt->setInt(1, m_ID);
165 ResultSet* rset = m_writeStmt->executeQuery();
168 oracle::occi::Clob clob = rset->getClob (1);
170 cout <<
"Opening the clob in read write mode" << endl;
172 std::cout <<
"Populating the clob" << endl;
174 populateClob (clob, getDCCConfigurationUrl(), m_size);
175 int clobLength=clob.length ();
176 cout <<
"Length of the clob is: " << clobLength << endl;
178 m_writeStmt->executeUpdate();
180 m_writeStmt->closeResultSet (rset);
183 throw(std::runtime_error(
std::string(
"ODDCCConfig::writeDB(): ")+getOraMessage(&e)));
186 if (!this->fetchID()) {
187 throw(std::runtime_error(
"ODDCCConfig::writeDB: Failed to write"));
210 this->checkConnection();
212 if(
result->getId()==0 && (
result->getConfigTag().empty()) ){
219 m_readStmt->setSQL(
"SELECT * " 220 "FROM ECAL_DCC_CONFIGURATION " 221 " where dcc_configuration_id = :1 or dcc_tag=:2 " );
222 m_readStmt->setInt(1,
result->getId());
223 m_readStmt->setString(2,
result->getConfigTag());
224 ResultSet* rset = m_readStmt->executeQuery();
230 result->setId(rset->getInt(1));
231 result->setConfigTag(getOraString(rset,2));
232 result->setDCCConfigurationUrl(getOraString(rset,3));
233 result->setTestPatternFileUrl(getOraString(rset,4));
234 result->setNTestPatternsToLoad(rset->getInt(5));
235 result->setSMHalf(rset->getInt(6));
237 Clob clob = rset->getClob (7);
238 m_size = clob.length();
239 Stream *instream = clob.getStream (1,0);
240 unsigned char *
buffer =
new unsigned char[m_size];
241 memset (buffer, 0, m_size);
242 instream->readBuffer ((
char*)buffer, m_size);
258 result->setDCCClob(buffer );
259 result->setDCCWeightsMode(getOraString(rset,8));
263 throw(std::runtime_error(
std::string(
"ODDCCConfig::fetchData(): ")+getOraMessage(&e)));
275 this->checkConnection();
278 Statement* stmt = m_conn->createStatement();
279 stmt->setSQL(
"SELECT DCC_configuration_id FROM ecal_dcc_configuration " 280 "WHERE dcc_tag=:dcc_tag " 283 stmt->setString(1, getConfigTag() );
286 ResultSet* rset = stmt->executeQuery();
289 m_ID = rset->getInt(1);
293 m_conn->terminateStatement(stmt);
295 throw(std::runtime_error(
std::string(
"ODDCCConfig::fetchID: ")+getOraMessage(&e)));
oracle::occi::Stream Stream
void fetchData(ODDCCConfig *result) noexcept(false)
void prepareWrite() noexcept(false) override
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
int fetchNextId() noexcept(false)
oracle::occi::Statement Statement
oracle::occi::SQLException SQLException
int fetchID() noexcept(false)
void setParameters(const std::map< std::string, std::string > &my_keys_map)
void writeDB() noexcept(false)