11 using namespace oracle::occi;
45 this->checkConnection();
47 m_readStmt = m_conn->createStatement();
48 m_readStmt->setSQL(
"select ecal_srp_config_sq.NextVal from dual");
49 ResultSet* rset = m_readStmt->executeQuery();
50 while (rset->next ()){
51 result= rset->getInt(1);
53 m_conn->terminateStatement(m_readStmt);
57 throw(std::runtime_error(
"ODSRPConfig::fetchNextId(): "+e.getMessage()));
71 for( std::map<std::string, std::string >::iterator ci=
72 my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
74 std::string
name = ci->first;
75 std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))std::toupper);
77 if( name ==
"SRP_CONFIGURATION_ID") setConfigTag(ci->second);
78 if( name ==
"DEBUGMODE") setDebugMode(atoi(ci->second.c_str()));
79 if( name ==
"DUMMYMODE") setDummyMode(atoi(ci->second.c_str()));
80 if( name ==
"PATTERNDIRECTORY") setPatternDirectory(ci->second);
81 if( name ==
"PATTERN_DIRECTORY") setPatternDirectory(ci->second);
82 if( name ==
"AUTOMATICMASKS") setAutomaticMasks(atoi(ci->second.c_str()));
83 if( name ==
"AUTOMATIC_MASKS") setAutomaticMasks(atoi(ci->second.c_str()));
84 if( name ==
"AUTOMATICSRPSELECT") setAutomaticSrpSelect(atoi(ci->second.c_str()));
85 if( name ==
"SRP0BUNCHADJUSTPOSITION") setSRP0BunchAdjustPosition(atoi(ci->second.c_str()));
86 if( name ==
"SRP_CONFIG_FILE") {
87 std::string
fname=ci->second ;
89 cout <<
"fname="<<fname << endl;
94 std::cout <<
"Going to read SRP file: " << fname << endl;
97 inpFile.open(fname.c_str());
102 bufsize = inpFile.tellg();
103 std::cout <<
" bufsize ="<<bufsize<< std::endl;
105 inpFile.seekg( 0,ios::beg );
117 throw(std::runtime_error)
119 this->checkConnection();
121 int next_id=fetchNextId();
124 m_writeStmt = m_conn->createStatement();
125 m_writeStmt->setSQL(
"INSERT INTO ECAL_SRP_CONFIGURATION (srp_configuration_id, srp_tag, "
126 " DEBUGMODE, DUMMYMODE, PATTERN_DIRECTORY, AUTOMATIC_MASKS,"
127 " SRP0BUNCHADJUSTPOSITION, SRP_CONFIG_FILE, SRP_CONFIGURATION, AUTOMATICSRPSELECT ) "
128 "VALUES (:1, :2, :3, :4, :5, :6, :7, :8, :9, :10 )");
129 m_writeStmt->setInt(1, next_id);
130 m_writeStmt->setString(2, getConfigTag());
131 m_writeStmt->setInt(3, getDebugMode());
132 m_writeStmt->setInt(4, getDummyMode());
133 m_writeStmt->setString(5, getPatternDirectory());
134 m_writeStmt->setInt(6, getAutomaticMasks());
135 m_writeStmt->setInt(10, getAutomaticSrpSelect());
136 m_writeStmt->setInt(7, getSRP0BunchAdjustPosition());
137 m_writeStmt->setString(8, getConfigFile());
140 oracle::occi::Clob clob(m_conn);
142 m_writeStmt->setClob(9,clob);
143 m_writeStmt->executeUpdate ();
146 m_conn->terminateStatement(m_writeStmt);
147 std::cout<<
"SRP Clob inserted into CONFIGURATION with id="<<next_id<<std::endl;
150 m_writeStmt = m_conn->createStatement();
151 m_writeStmt->setSQL (
"SELECT srp_configuration FROM ECAL_SRP_CONFIGURATION WHERE"
152 " srp_configuration_id=:1 FOR UPDATE");
154 std::cout<<
"updating the clob 0"<<std::endl;
158 throw(std::runtime_error(
"ODSRPConfig::prepareWrite(): "+e.getMessage()));
161 std::cout<<
"updating the clob 1 "<<std::endl;
167 throw(std::runtime_error)
170 std::cout<<
"updating the clob 2"<<std::endl;
173 m_writeStmt->setInt(1, m_ID);
174 ResultSet* rset = m_writeStmt->executeQuery();
176 while (rset->next ())
178 oracle::occi::Clob clob = rset->getClob (1);
179 cout <<
"Opening the clob in read write mode" << endl;
180 cout <<
"Populating the clob" << endl;
181 populateClob (clob, getConfigFile(), m_size );
182 int clobLength=clob.length ();
183 cout <<
"Length of the clob after writing is: " << clobLength << endl;
187 m_writeStmt->executeUpdate();
189 m_writeStmt->closeResultSet (rset);
192 throw(std::runtime_error(
"ODSRPConfig::writeDB(): "+e.getMessage()));
195 if (!this->fetchID()) {
196 throw(std::runtime_error(
"ODSRPConfig::writeDB: Failed to write"));
204 throw(std::runtime_error)
206 this->checkConnection();
208 if(
result->getId()==0 && (
result->getConfigTag()==
"") ){
215 m_readStmt->setSQL(
"SELECT * "
216 " FROM ECAL_SRP_CONFIGURATION "
217 " where (srp_configuration_id = :1 or srp_tag=:2 )" );
218 m_readStmt->setInt(1,
result->getId());
219 m_readStmt->setString(2,
result->getConfigTag());
220 ResultSet* rset = m_readStmt->executeQuery();
225 result->setId(rset->getInt(1));
226 result->setConfigTag(rset->getString(2));
228 result->setDebugMode(rset->getInt(3));
229 result->setDummyMode(rset->getInt(4));
230 result->setPatternDirectory(rset->getString(5));
231 result->setAutomaticMasks(rset->getInt(6));
232 result->setSRP0BunchAdjustPosition(rset->getInt(7));
233 result->setConfigFile(rset->getString(8));
235 Clob clob = rset->getClob(9);
236 m_size = clob.length();
237 Stream *instream = clob.getStream (1,0);
238 unsigned char *buffer =
new unsigned char[m_size];
239 memset (buffer, 0, m_size);
240 instream->readBuffer ((
char*)buffer, m_size);
255 result->setSRPClob(buffer );
256 result->setAutomaticSrpSelect(rset->getInt(10));
259 throw(std::runtime_error(
"ODSRPConfig::fetchData(): "+e.getMessage()));
272 this->checkConnection();
275 Statement* stmt = m_conn->createStatement();
276 stmt->setSQL(
"SELECT srp_configuration_id FROM ecal_srp_configuration "
277 "WHERE srp_tag=:srp_tag "
280 stmt->setString(1, getConfigTag() );
285 m_ID = rset->getInt(1);
289 m_conn->terminateStatement(stmt);
291 throw(std::runtime_error(
"ODSRPConfig::fetchID: "+e.getMessage()));
oracle::occi::Stream Stream
void fetchData(ODSRPConfig *result)
void setParameters(std::map< std::string, std::string > my_keys_map)
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