CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes | Friends
ODLTCConfig Class Reference

#include <ODLTCConfig.h>

Inheritance diagram for ODLTCConfig:
IODConfig IDBObject

Public Member Functions

int getId () const
 
unsigned char * getLTCClob () const
 
std::string getLTCConfigurationFile () const
 
unsigned int getSize () const
 
std::string getTable ()
 
 ODLTCConfig ()
 
void setId (int id)
 
void setLTCClob (unsigned char *x)
 
void setLTCConfigurationFile (std::string x)
 
void setParameters (const std::map< std::string, std::string > &my_keys_map)
 
void setSize (unsigned int id)
 
 ~ODLTCConfig ()
 
- Public Member Functions inherited from IODConfig
std::string getConfigTag ()
 
void setConfigTag (std::string x)
 
- Public Member Functions inherited from IDBObject
oracle::occi::Connection * getConn () const
 
oracle::occi::Environment * getEnv () const
 
void setConnection (oracle::occi::Environment *env, oracle::occi::Connection *conn)
 
virtual ~IDBObject ()
 

Private Member Functions

void clear ()
 
void fetchData (ODLTCConfig *result) noexcept(false)
 
int fetchID () noexcept(false)
 
int fetchNextId () noexcept(false)
 
void prepareWrite () noexcept(false)
 
void writeDB () noexcept(false)
 

Private Attributes

int m_ID
 
unsigned char * m_ltc_clob
 
std::string m_ltc_file
 
int m_size
 

Friends

class EcalCondDBInterface
 

Additional Inherited Members

- Public Types inherited from IODConfig
typedef oracle::occi::Clob Clob
 
typedef oracle::occi::SQLException SQLException
 
typedef oracle::occi::Statement Statement
 
typedef oracle::occi::Stream Stream
 
- Public Attributes inherited from IODConfig
std::string m_config_tag
 
- Static Public Attributes inherited from IDBObject
static int const ECALDB_NROWS =1024
 
- Protected Member Functions inherited from IODConfig
void checkPrepare () noexcept(false)
 
void createReadStatement () noexcept(false)
 
void populateClob (Clob &clob, std::string fname, unsigned int bufsize) noexcept(false)
 
unsigned char * readClob (Clob &clob, int size) noexcept(false)
 
void setPrefetchRowCount (int ncount) noexcept(false)
 
void terminateReadStatement () noexcept(false)
 
void terminateWriteStatement () noexcept(false)
 
- Protected Member Functions inherited from IDBObject
void checkConnection () const noexcept(false)
 
- Protected Attributes inherited from IODConfig
Statementm_readStmt
 
Statementm_writeStmt
 
- Protected Attributes inherited from IDBObject
oracle::occi::Connection * m_conn
 
oracle::occi::Environment * m_env
 

Detailed Description

Definition at line 15 of file ODLTCConfig.h.

Constructor & Destructor Documentation

ODLTCConfig::ODLTCConfig ( )

Definition at line 13 of file ODLTCConfig.cc.

References hitfit::clear(), and NULL.

14 {
15  m_env = NULL;
16  m_conn = NULL;
17  m_writeStmt = NULL;
18  m_readStmt = NULL;
19  m_config_tag="";
20  m_size=0;
21 
22  m_ID=0;
23  clear();
24 
25 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Statement * m_writeStmt
Definition: IODConfig.h:36
#define NULL
Definition: scimark2.h:8
std::string m_config_tag
Definition: IODConfig.h:27
void clear()
Definition: ODLTCConfig.cc:190
Statement * m_readStmt
Definition: IODConfig.h:37
ODLTCConfig::~ODLTCConfig ( )

Definition at line 29 of file ODLTCConfig.cc.

30 {
31  // delete [] m_ltc_clob;
32 }

Member Function Documentation

void ODLTCConfig::clear ( void  )
private

Definition at line 190 of file ODLTCConfig.cc.

Referenced by getLTCClob().

190  {
191  // strcpy((char *)m_ltc_clob, "");
192 
193  m_ltc_file="";
194 
195 }
std::string m_ltc_file
Definition: ODLTCConfig.h:51
void ODLTCConfig::fetchData ( ODLTCConfig result)
privatenoexcept

Definition at line 199 of file ODLTCConfig.cc.

References edmScanValgrind::buffer, gather_cfg::cout, MillePedeFileConverter_cfg::e, mps_fire::i, and mps_fire::result.

Referenced by getLTCClob().

201 {
202  this->checkConnection();
203  result->clear();
204  if(result->getId()==0 && result->getConfigTag()==""){
205  throw(std::runtime_error("ODLTCConfig::fetchData(): no Id defined for this ODLTCConfig "));
206  }
207 
208  try {
209 
210  m_readStmt->setSQL("SELECT * "
211  "FROM ECAL_LTC_CONFIGURATION "
212  " where (ltc_configuration_id = :1 or LTC_tag=:2 )" );
213  m_readStmt->setInt(1, result->getId());
214  m_readStmt->setString(2, result->getConfigTag());
215  ResultSet* rset = m_readStmt->executeQuery();
216 
217  rset->next();
218  // 1 is the id and 2 is the config tag
219 
220  result->setId(rset->getInt(1));
221  result->setConfigTag(rset->getString(2));
222  result->setLTCConfigurationFile(rset->getString(3));
223 
224 
225  Clob clob = rset->getClob (4);
226  cout << "Opening the clob in Read only mode" << endl;
227  clob.open (OCCI_LOB_READONLY);
228  int clobLength=clob.length ();
229  cout << "Length of the clob is: " << clobLength << endl;
230  m_size=clobLength;
231  unsigned char* buffer = readClob (clob, clobLength);
232  clob.close ();
233  cout<< "the clob buffer is:"<<endl;
234  for (int i = 0; i < clobLength; ++i)
235  cout << (char) buffer[i];
236  cout << endl;
237 
238 
239  result->setLTCClob(buffer );
240 
241  } catch (SQLException &e) {
242  throw(std::runtime_error("ODLTCConfig::fetchData(): "+e.getMessage()));
243  }
244 }
unsigned char * readClob(Clob &clob, int size) noexcept(false)
Definition: IODConfig.h:154
int getId() const
Definition: ODLTCConfig.h:25
void setLTCConfigurationFile(std::string x)
Definition: ODLTCConfig.h:30
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
void setLTCClob(unsigned char *x)
Definition: ODLTCConfig.h:33
void setId(int id)
Definition: ODLTCConfig.h:24
oracle::occi::Clob Clob
Definition: IODConfig.h:25
void clear()
Definition: ODLTCConfig.cc:190
void setConfigTag(std::string x)
Definition: IODConfig.h:31
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
Statement * m_readStmt
Definition: IODConfig.h:37
std::string getConfigTag()
Definition: IODConfig.h:32
int ODLTCConfig::fetchID ( )
privatenoexcept

Definition at line 248 of file ODLTCConfig.cc.

References MillePedeFileConverter_cfg::e.

Referenced by getLTCClob().

249 {
250  if (m_ID!=0) {
251  return m_ID;
252  }
253 
254  this->checkConnection();
255 
256  try {
257  Statement* stmt = m_conn->createStatement();
258  stmt->setSQL("SELECT ltc_configuration_id FROM ecal_ltc_configuration "
259  "WHERE ltc_tag=:ltc_tag "
260  );
261 
262  stmt->setString(1, getConfigTag() );
263 
264  ResultSet* rset = stmt->executeQuery();
265 
266  if (rset->next()) {
267  m_ID = rset->getInt(1);
268  } else {
269  m_ID = 0;
270  }
271  m_conn->terminateStatement(stmt);
272  } catch (SQLException &e) {
273  throw(std::runtime_error("ODLTCConfig::fetchID: "+e.getMessage()));
274  }
275 
276  return m_ID;
277 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
oracle::occi::Statement Statement
Definition: IODConfig.h:23
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
std::string getConfigTag()
Definition: IODConfig.h:32
int ODLTCConfig::fetchNextId ( )
privatenoexcept

Definition at line 34 of file ODLTCConfig.cc.

References MillePedeFileConverter_cfg::e, and mps_fire::result.

Referenced by getLTCClob().

34  {
35 
36  int result=0;
37  try {
38  this->checkConnection();
39 
40  m_readStmt = m_conn->createStatement();
41  m_readStmt->setSQL("select ecal_ltc_config_sq.NextVal from dual");
42  ResultSet* rset = m_readStmt->executeQuery();
43  while (rset->next ()){
44  result= rset->getInt(1);
45  }
46  m_conn->terminateStatement(m_readStmt);
47  return result;
48 
49  } catch (SQLException &e) {
50  throw(std::runtime_error("ODLTCConfig::fetchNextId(): "+e.getMessage()));
51  }
52 
53 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
Statement * m_readStmt
Definition: IODConfig.h:37
int ODLTCConfig::getId ( void  ) const
inline

Definition at line 25 of file ODLTCConfig.h.

References m_ID.

25 { return m_ID; }
unsigned char* ODLTCConfig::getLTCClob ( ) const
inline

Definition at line 34 of file ODLTCConfig.h.

References clear(), fetchData(), fetchID(), fetchNextId(), m_ltc_clob, noexcept, prepareWrite(), mps_fire::result, setParameters(), and writeDB().

34 { return m_ltc_clob; }
unsigned char * m_ltc_clob
Definition: ODLTCConfig.h:50
std::string ODLTCConfig::getLTCConfigurationFile ( ) const
inline

Definition at line 31 of file ODLTCConfig.h.

References m_ltc_file.

31 { return m_ltc_file; }
std::string m_ltc_file
Definition: ODLTCConfig.h:51
unsigned int ODLTCConfig::getSize ( ) const
inline

Definition at line 28 of file ODLTCConfig.h.

References m_size.

28 { return m_size; }
std::string ODLTCConfig::getTable ( )
inlinevirtual

Implements IODConfig.

Definition at line 22 of file ODLTCConfig.h.

22 { return "ECAL_LTC_CONFIGURATION"; }
void ODLTCConfig::prepareWrite ( )
privatevirtualnoexcept

Implements IODConfig.

Definition at line 58 of file ODLTCConfig.cc.

References gather_cfg::cout, and MillePedeFileConverter_cfg::e.

Referenced by getLTCClob().

60 {
61  this->checkConnection();
62 
63  int next_id=fetchNextId();
64 
65  try {
66  m_writeStmt = m_conn->createStatement();
67  m_writeStmt->setSQL("INSERT INTO ECAL_LTC_CONFIGURATION (ltc_configuration_id, ltc_tag, "
68  " LTC_CONFIGURATION_file, "
69  " Configuration ) "
70  "VALUES (:1, :2, :3, :4 )");
71  m_writeStmt->setInt(1, next_id);
72  m_writeStmt->setString(2, this->getConfigTag());
73  m_writeStmt->setString(3, getLTCConfigurationFile());
74 
75 
76  // and now the clob
77  oracle::occi::Clob clob(m_conn);
78  clob.setEmpty();
79  m_writeStmt->setClob(4,clob);
80  m_writeStmt->executeUpdate ();
81  m_ID=next_id;
82 
83  m_conn->terminateStatement(m_writeStmt);
84  std::cout<<"LTC Clob inserted into CONFIGURATION with id="<<next_id<<std::endl;
85 
86  // now we read and update it
87  m_writeStmt = m_conn->createStatement();
88  m_writeStmt->setSQL ("SELECT Configuration FROM ECAL_LTC_CONFIGURATION WHERE"
89  " ltc_configuration_id=:1 FOR UPDATE");
90 
91  std::cout<<"updating the clob 0"<<std::endl;
92 
93 
94  } catch (SQLException &e) {
95  throw(std::runtime_error("ODLTCConfig::prepareWrite(): "+e.getMessage()));
96  }
97 
98  std::cout<<"updating the clob 1 "<<std::endl;
99 
100 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Statement * m_writeStmt
Definition: IODConfig.h:36
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
std::string getLTCConfigurationFile() const
Definition: ODLTCConfig.h:31
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
int fetchNextId() noexcept(false)
Definition: ODLTCConfig.cc:34
std::string getConfigTag()
Definition: IODConfig.h:32
void ODLTCConfig::setId ( int  id)
inline

Definition at line 24 of file ODLTCConfig.h.

References triggerObjects_cff::id, and m_ID.

void ODLTCConfig::setLTCClob ( unsigned char *  x)
inline

Definition at line 33 of file ODLTCConfig.h.

References m_ltc_clob, and x.

33 { m_ltc_clob = x; }
unsigned char * m_ltc_clob
Definition: ODLTCConfig.h:50
void ODLTCConfig::setLTCConfigurationFile ( std::string  x)
inline

Definition at line 30 of file ODLTCConfig.h.

References m_ltc_file, and x.

30 { m_ltc_file = x; }
std::string m_ltc_file
Definition: ODLTCConfig.h:51
void ODLTCConfig::setParameters ( const std::map< std::string, std::string > &  my_keys_map)

Definition at line 102 of file ODLTCConfig.cc.

References gather_cfg::cout, end, alignmentValidation::fname, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getLTCClob().

102  {
103 
104  // parses the result of the XML parser that is a map of
105  // string string with variable name variable value
106 
107  for( std::map<std::string, std::string >::const_iterator ci=
108  my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
109 
110  if(ci->first== "LTC_CONFIGURATION_ID") setConfigTag(ci->second);
111  if(ci->first== "Configuration") {
112  std::string fname=ci->second ;
113  string str3;
114  size_t pos, pose;
115 
116  pos = fname.find("="); // position of "live" in str
117  pose = fname.size(); // position of "]" in str
118  str3 = fname.substr (pos+1, pose-pos-2);
119 
120  cout << "fname="<<fname<< " and reduced is: "<<str3 << endl;
122 
123 
124  // here we must open the file and read the LTC Clob
125  std::cout << "Going to read LTC file: " << fname << endl;
126 
127  ifstream inpFile;
128  inpFile.open(str3.c_str());
129 
130  // tell me size of file
131  int bufsize = 0;
132  inpFile.seekg( 0,ios::end );
133  bufsize = inpFile.tellg();
134  std::cout <<" bufsize ="<<bufsize<< std::endl;
135  // set file pointer to start again
136  inpFile.seekg( 0,ios::beg );
137 
138  m_size=bufsize;
139 
140  inpFile.close();
141 
142  }
143  }
144 
145 }
void setLTCConfigurationFile(std::string x)
Definition: ODLTCConfig.h:30
#define end
Definition: vmac.h:37
string fname
main script
void setConfigTag(std::string x)
Definition: IODConfig.h:31
void ODLTCConfig::setSize ( unsigned int  id)
inline

Definition at line 27 of file ODLTCConfig.h.

References triggerObjects_cff::id, and m_size.

void ODLTCConfig::writeDB ( )
privatenoexcept

Definition at line 148 of file ODLTCConfig.cc.

References gather_cfg::cout, and MillePedeFileConverter_cfg::e.

Referenced by getLTCClob().

150 {
151 
152  std::cout<<"updating the clob "<<std::endl;
153 
154 
155 
156  try {
157 
158 
159  m_writeStmt->setInt(1, m_ID);
160  ResultSet* rset = m_writeStmt->executeQuery();
161 
162  rset->next ();
163  oracle::occi::Clob clob = rset->getClob (1);
164 
165  cout << "Opening the clob in read write mode" << endl;
166 
167  std::cout << "Populating the clob" << endl;
168 
170  int clobLength=clob.length ();
171  cout << "Length of the clob is: " << clobLength << endl;
172  // clob.close ();
173 
174  m_writeStmt->executeUpdate();
175 
176  m_writeStmt->closeResultSet (rset);
177 
178  } catch (SQLException &e) {
179  throw(std::runtime_error("ODLTCConfig::writeDB(): "+e.getMessage()));
180  }
181  // Now get the ID
182  if (!this->fetchID()) {
183  throw(std::runtime_error("ODLTCConfig::writeDB: Failed to write"));
184  }
185 
186 
187 }
Statement * m_writeStmt
Definition: IODConfig.h:36
void populateClob(Clob &clob, std::string fname, unsigned int bufsize) noexcept(false)
Definition: IODConfig.h:83
int fetchID() noexcept(false)
Definition: ODLTCConfig.cc:248
std::string getLTCConfigurationFile() const
Definition: ODLTCConfig.h:31
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22

Friends And Related Function Documentation

friend class EcalCondDBInterface
friend

Definition at line 17 of file ODLTCConfig.h.

Member Data Documentation

int ODLTCConfig::m_ID
private

Definition at line 49 of file ODLTCConfig.h.

Referenced by getId(), and setId().

unsigned char* ODLTCConfig::m_ltc_clob
private

Definition at line 50 of file ODLTCConfig.h.

Referenced by getLTCClob(), and setLTCClob().

std::string ODLTCConfig::m_ltc_file
private

Definition at line 51 of file ODLTCConfig.h.

Referenced by getLTCConfigurationFile(), and setLTCConfigurationFile().

int ODLTCConfig::m_size
private

Definition at line 52 of file ODLTCConfig.h.

Referenced by getSize(), and setSize().