test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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) throw (std::runtime_error)
 
int fetchID () throw (std::runtime_error)
 
int fetchNextId () throw (std::runtime_error)
 
void prepareWrite () throw (std::runtime_error)
 
void writeDB () throw (std::runtime_error)
 

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 () throw (std::runtime_error)
 
void createReadStatement () throw (std::runtime_error)
 
void populateClob (Clob &clob, std::string fname, unsigned int bufsize) throw (std::runtime_error)
 
unsigned char * readClob (Clob &clob, int size) throw (std::runtime_error)
 
void setPrefetchRowCount (int ncount) throw (std::runtime_error)
 
void terminateReadStatement () throw (std::runtime_error)
 
void terminateWriteStatement () throw (std::runtime_error)
 
- Protected Member Functions inherited from IDBObject
void checkConnection () const throw (std::runtime_error)
 
- 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.

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)
throw (std::runtime_error
)
private

Definition at line 199 of file ODLTCConfig.cc.

References gather_cfg::cout, alignCSCRings::e, i, and query::result.

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 }
int i
Definition: DBlmapReader.cc:9
unsigned char * readClob(Clob &clob, int size)
Definition: IODConfig.h:160
int getId() const
Definition: ODLTCConfig.h:25
void setLTCConfigurationFile(std::string x)
Definition: ODLTCConfig.h:30
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
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
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
void setConfigTag(std::string x)
Definition: IODConfig.h:31
Statement * m_readStmt
Definition: IODConfig.h:37
std::string getConfigTag()
Definition: IODConfig.h:32
tuple cout
Definition: gather_cfg.py:121
void checkConnection() const
Definition: IDBObject.h:41
int ODLTCConfig::fetchID ( )
throw (std::runtime_error
)
private

Definition at line 248 of file ODLTCConfig.cc.

References alignCSCRings::e.

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
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
oracle::occi::Statement Statement
Definition: IODConfig.h:23
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
std::string getConfigTag()
Definition: IODConfig.h:32
void checkConnection() const
Definition: IDBObject.h:41
int ODLTCConfig::fetchNextId ( )
throw (std::runtime_error
)
private

Definition at line 34 of file ODLTCConfig.cc.

References alignCSCRings::e, and query::result.

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
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
tuple result
Definition: query.py:137
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
Statement * m_readStmt
Definition: IODConfig.h:37
void checkConnection() const
Definition: IDBObject.h:41
int ODLTCConfig::getId ( ) 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 m_ltc_clob.

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 ( )
throw (std::runtime_error
)
privatevirtual

Implements IODConfig.

Definition at line 58 of file ODLTCConfig.cc.

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

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
int fetchNextId()
Definition: ODLTCConfig.cc:34
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
std::string getLTCConfigurationFile() const
Definition: ODLTCConfig.h:31
std::string getConfigTag()
Definition: IODConfig.h:32
tuple cout
Definition: gather_cfg.py:121
void checkConnection() const
Definition: IDBObject.h:41
void ODLTCConfig::setId ( int  id)
inline

Definition at line 24 of file ODLTCConfig.h.

References m_ID.

24 { m_ID = 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
Definition: DDAxes.h:10
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
Definition: DDAxes.h:10
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.

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
tuple cout
Definition: gather_cfg.py:121
void ODLTCConfig::setSize ( unsigned int  id)
inline

Definition at line 27 of file ODLTCConfig.h.

References m_size.

27 { m_size = id; }
void ODLTCConfig::writeDB ( )
throw (std::runtime_error
)
private

Definition at line 148 of file ODLTCConfig.cc.

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

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 }
void populateClob(Clob &clob, std::string fname, unsigned int bufsize)
Definition: IODConfig.h:88
Statement * m_writeStmt
Definition: IODConfig.h:36
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
std::string getLTCConfigurationFile() const
Definition: ODLTCConfig.h:31
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
tuple cout
Definition: gather_cfg.py:121

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().