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 () override
 
 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 () override
 
- 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) override
 
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::ODLTCConfig ( )

Definition at line 13 of file ODLTCConfig.cc.

References l1ct::clear().

13  {
14  m_env = nullptr;
15  m_conn = nullptr;
16  m_writeStmt = nullptr;
17  m_readStmt = nullptr;
18  m_config_tag = "";
19  m_size = 0;
20 
21  m_ID = 0;
22  clear();
23 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
Statement * m_writeStmt
Definition: IODConfig.h:33
std::string m_config_tag
Definition: IODConfig.h:25
void clear()
Definition: ODLTCConfig.cc:161
Statement * m_readStmt
Definition: IODConfig.h:34

◆ ~ODLTCConfig()

ODLTCConfig::~ODLTCConfig ( )
override

Definition at line 25 of file ODLTCConfig.cc.

25  {
26  // delete [] m_ltc_clob;
27 }

Member Function Documentation

◆ clear()

void ODLTCConfig::clear ( void  )
private

Definition at line 161 of file ODLTCConfig.cc.

161  {
162  // strcpy((char *)m_ltc_clob, "");
163 
164  m_ltc_file = "";
165 }
std::string m_ltc_file
Definition: ODLTCConfig.h:50

◆ fetchData()

void ODLTCConfig::fetchData ( ODLTCConfig result)
privatenoexcept

Definition at line 167 of file ODLTCConfig.cc.

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

167  {
168  this->checkConnection();
169  result->clear();
170  if (result->getId() == 0 && result->getConfigTag().empty()) {
171  throw(std::runtime_error("ODLTCConfig::fetchData(): no Id defined for this ODLTCConfig "));
172  }
173 
174  try {
175  m_readStmt->setSQL(
176  "SELECT * "
177  "FROM ECAL_LTC_CONFIGURATION "
178  " where (ltc_configuration_id = :1 or LTC_tag=:2 )");
179  m_readStmt->setInt(1, result->getId());
180  m_readStmt->setString(2, result->getConfigTag());
181  ResultSet* rset = m_readStmt->executeQuery();
182 
183  rset->next();
184  // 1 is the id and 2 is the config tag
185 
186  result->setId(rset->getInt(1));
187  result->setConfigTag(rset->getString(2));
188  result->setLTCConfigurationFile(rset->getString(3));
189 
190  Clob clob = rset->getClob(4);
191  cout << "Opening the clob in Read only mode" << endl;
192  clob.open(OCCI_LOB_READONLY);
193  int clobLength = clob.length();
194  cout << "Length of the clob is: " << clobLength << endl;
195  m_size = clobLength;
196  unsigned char* buffer = readClob(clob, clobLength);
197  clob.close();
198  cout << "the clob buffer is:" << endl;
199  for (int i = 0; i < clobLength; ++i)
200  cout << (char)buffer[i];
201  cout << endl;
202 
203  result->setLTCClob(buffer);
204 
205  } catch (SQLException& e) {
206  throw(std::runtime_error(std::string("ODLTCConfig::fetchData(): ") + e.getMessage()));
207  }
208 }
unsigned char * readClob(Clob &clob, int size) noexcept(false)
Definition: IODConfig.h:124
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
oracle::occi::Clob Clob
Definition: IODConfig.h:23
void clear()
Definition: ODLTCConfig.cc:161
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
Statement * m_readStmt
Definition: IODConfig.h:34

◆ fetchID()

int ODLTCConfig::fetchID ( )
privatenoexcept

Definition at line 210 of file ODLTCConfig.cc.

References MillePedeFileConverter_cfg::e, and AlCaHLTBitMon_QueryRunRegistry::string.

210  {
211  if (m_ID != 0) {
212  return m_ID;
213  }
214 
215  this->checkConnection();
216 
217  try {
218  Statement* stmt = m_conn->createStatement();
219  stmt->setSQL(
220  "SELECT ltc_configuration_id FROM ecal_ltc_configuration "
221  "WHERE ltc_tag=:ltc_tag ");
222 
223  stmt->setString(1, getConfigTag());
224 
225  ResultSet* rset = stmt->executeQuery();
226 
227  if (rset->next()) {
228  m_ID = rset->getInt(1);
229  } else {
230  m_ID = 0;
231  }
232  m_conn->terminateStatement(stmt);
233  } catch (SQLException& e) {
234  throw(std::runtime_error(std::string("ODLTCConfig::fetchID: ") + e.getMessage()));
235  }
236 
237  return m_ID;
238 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
oracle::occi::Statement Statement
Definition: IODConfig.h:21
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
std::string getConfigTag()
Definition: IODConfig.h:30

◆ fetchNextId()

int ODLTCConfig::fetchNextId ( )
privatenoexcept

Definition at line 29 of file ODLTCConfig.cc.

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

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

◆ getId()

int ODLTCConfig::getId ( void  ) const
inline

Definition at line 25 of file ODLTCConfig.h.

References m_ID.

25 { return m_ID; }

◆ getLTCClob()

unsigned char* ODLTCConfig::getLTCClob ( ) const
inline

Definition at line 34 of file ODLTCConfig.h.

References m_ltc_clob.

34 { return m_ltc_clob; }
unsigned char * m_ltc_clob
Definition: ODLTCConfig.h:49

◆ getLTCConfigurationFile()

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:50

◆ getSize()

unsigned int ODLTCConfig::getSize ( ) const
inline

Definition at line 28 of file ODLTCConfig.h.

References m_size.

28 { return m_size; }

◆ getTable()

std::string ODLTCConfig::getTable ( )
inlineoverridevirtual

Implements IODConfig.

Definition at line 22 of file ODLTCConfig.h.

22 { return "ECAL_LTC_CONFIGURATION"; }

◆ prepareWrite()

void ODLTCConfig::prepareWrite ( )
overrideprivatevirtualnoexcept

Implements IODConfig.

Definition at line 48 of file ODLTCConfig.cc.

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

48  {
49  this->checkConnection();
50 
51  int next_id = fetchNextId();
52 
53  try {
54  m_writeStmt = m_conn->createStatement();
55  m_writeStmt->setSQL(
56  "INSERT INTO ECAL_LTC_CONFIGURATION (ltc_configuration_id, ltc_tag, "
57  " LTC_CONFIGURATION_file, "
58  " Configuration ) "
59  "VALUES (:1, :2, :3, :4 )");
60  m_writeStmt->setInt(1, next_id);
61  m_writeStmt->setString(2, this->getConfigTag());
62  m_writeStmt->setString(3, getLTCConfigurationFile());
63 
64  // and now the clob
65  oracle::occi::Clob clob(m_conn);
66  clob.setEmpty();
67  m_writeStmt->setClob(4, clob);
68  m_writeStmt->executeUpdate();
69  m_ID = next_id;
70 
71  m_conn->terminateStatement(m_writeStmt);
72  std::cout << "LTC Clob inserted into CONFIGURATION with id=" << next_id << std::endl;
73 
74  // now we read and update it
75  m_writeStmt = m_conn->createStatement();
76  m_writeStmt->setSQL(
77  "SELECT Configuration FROM ECAL_LTC_CONFIGURATION WHERE"
78  " ltc_configuration_id=:1 FOR UPDATE");
79 
80  std::cout << "updating the clob 0" << std::endl;
81 
82  } catch (SQLException& e) {
83  throw(std::runtime_error(std::string("ODLTCConfig::prepareWrite(): ") + e.getMessage()));
84  }
85 
86  std::cout << "updating the clob 1 " << std::endl;
87 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
Statement * m_writeStmt
Definition: IODConfig.h:33
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
std::string getLTCConfigurationFile() const
Definition: ODLTCConfig.h:31
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
int fetchNextId() noexcept(false)
Definition: ODLTCConfig.cc:29
std::string getConfigTag()
Definition: IODConfig.h:30

◆ setId()

void ODLTCConfig::setId ( int  id)
inline

◆ setLTCClob()

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:49

◆ setLTCConfigurationFile()

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:50

◆ setParameters()

void ODLTCConfig::setParameters ( const std::map< std::string, std::string > &  my_keys_map)

Definition at line 89 of file ODLTCConfig.cc.

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

89  {
90  // parses the result of the XML parser that is a map of
91  // string string with variable name variable value
92 
93  for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
94  if (ci->first == "LTC_CONFIGURATION_ID")
95  setConfigTag(ci->second);
96  if (ci->first == "Configuration") {
97  std::string fname = ci->second;
98  string str3;
99  size_t pos, pose;
100 
101  pos = fname.find('='); // position of "live" in str
102  pose = fname.size(); // position of "]" in str
103  str3 = fname.substr(pos + 1, pose - pos - 2);
104 
105  cout << "fname=" << fname << " and reduced is: " << str3 << endl;
107 
108  // here we must open the file and read the LTC Clob
109  std::cout << "Going to read LTC file: " << fname << endl;
110 
111  ifstream inpFile;
112  inpFile.open(str3.c_str());
113 
114  // tell me size of file
115  int bufsize = 0;
116  inpFile.seekg(0, ios::end);
117  bufsize = inpFile.tellg();
118  std::cout << " bufsize =" << bufsize << std::endl;
119  // set file pointer to start again
120  inpFile.seekg(0, ios::beg);
121 
122  m_size = bufsize;
123 
124  inpFile.close();
125  }
126  }
127 }
void setLTCConfigurationFile(std::string x)
Definition: ODLTCConfig.h:30
string fname
main script
void setConfigTag(std::string x)
Definition: IODConfig.h:29

◆ setSize()

void ODLTCConfig::setSize ( unsigned int  id)
inline

◆ writeDB()

void ODLTCConfig::writeDB ( )
privatenoexcept

Definition at line 129 of file ODLTCConfig.cc.

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

129  {
130  std::cout << "updating the clob " << std::endl;
131 
132  try {
133  m_writeStmt->setInt(1, m_ID);
134  ResultSet* rset = m_writeStmt->executeQuery();
135 
136  rset->next();
137  oracle::occi::Clob clob = rset->getClob(1);
138 
139  cout << "Opening the clob in read write mode" << endl;
140 
141  std::cout << "Populating the clob" << endl;
142 
144  int clobLength = clob.length();
145  cout << "Length of the clob is: " << clobLength << endl;
146  // clob.close ();
147 
148  m_writeStmt->executeUpdate();
149 
150  m_writeStmt->closeResultSet(rset);
151 
152  } catch (SQLException& e) {
153  throw(std::runtime_error(std::string("ODLTCConfig::writeDB(): ") + e.getMessage()));
154  }
155  // Now get the ID
156  if (!this->fetchID()) {
157  throw(std::runtime_error("ODLTCConfig::writeDB: Failed to write"));
158  }
159 }
Statement * m_writeStmt
Definition: IODConfig.h:33
std::string getLTCConfigurationFile() const
Definition: ODLTCConfig.h:31
void populateClob(Clob &clob, std::string fname, unsigned int bufsize) noexcept(false)
Definition: IODConfig.h:67
int fetchID() noexcept(false)
Definition: ODLTCConfig.cc:210
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20

Friends And Related Function Documentation

◆ EcalCondDBInterface

friend class EcalCondDBInterface
friend

Definition at line 17 of file ODLTCConfig.h.

Member Data Documentation

◆ m_ID

int ODLTCConfig::m_ID
private

Definition at line 48 of file ODLTCConfig.h.

Referenced by getId(), and setId().

◆ m_ltc_clob

unsigned char* ODLTCConfig::m_ltc_clob
private

Definition at line 49 of file ODLTCConfig.h.

Referenced by getLTCClob(), and setLTCClob().

◆ m_ltc_file

std::string ODLTCConfig::m_ltc_file
private

Definition at line 50 of file ODLTCConfig.h.

Referenced by getLTCConfigurationFile(), and setLTCConfigurationFile().

◆ m_size

int ODLTCConfig::m_size
private

Definition at line 51 of file ODLTCConfig.h.

Referenced by getSize(), and setSize().