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
ODFEPedestalOffsetInfo Class Reference

#include <ODFEPedestalOffsetInfo.h>

Inheritance diagram for ODFEPedestalOffsetInfo:
IODConfig IDBObject

Public Member Functions

int fetchID () throw (std::runtime_error)
 
int fetchNextId () throw (std::runtime_error)
 
int getId () const
 
std::string getTable ()
 
int getVersion () const
 
 ODFEPedestalOffsetInfo ()
 
void setId (int id)
 
void setParameters (std::map< std::string, std::string > my_keys_map)
 
void setVersion (int id)
 
 ~ODFEPedestalOffsetInfo ()
 
- 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 (ODFEPedestalOffsetInfo *result) throw (std::runtime_error)
 
void fetchLastData (ODFEPedestalOffsetInfo *result) throw (std::runtime_error)
 
void prepareWrite () throw (std::runtime_error)
 
void writeDB () throw (std::runtime_error)
 

Private Attributes

int m_ID
 
int m_version
 

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 9 of file ODFEPedestalOffsetInfo.h.

Constructor & Destructor Documentation

ODFEPedestalOffsetInfo::ODFEPedestalOffsetInfo ( )

Definition at line 12 of file ODFEPedestalOffsetInfo.cc.

References hitfit::clear(), and NULL.

13 {
14  m_env = NULL;
15  m_conn = NULL;
16  m_writeStmt = NULL;
17  m_readStmt = NULL;
18  m_config_tag="";
19  m_ID=0;
20  m_version=0;
21  clear();
22 }
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
Statement * m_readStmt
Definition: IODConfig.h:37
ODFEPedestalOffsetInfo::~ODFEPedestalOffsetInfo ( )

Definition at line 31 of file ODFEPedestalOffsetInfo.cc.

32 {
33 }

Member Function Documentation

void ODFEPedestalOffsetInfo::clear ( void  )
private

Definition at line 25 of file ODFEPedestalOffsetInfo.cc.

25  {
26 
27 }
void ODFEPedestalOffsetInfo::fetchData ( ODFEPedestalOffsetInfo result)
throw (std::runtime_error
)
private

Definition at line 134 of file ODFEPedestalOffsetInfo.cc.

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

136 {
137  this->checkConnection();
138  result->clear();
139  if(result->getId()==0 && (result->getConfigTag()=="") ){
140  throw(std::runtime_error("ODFEPedestalOffsetInfo::fetchData(): no Id defined for this ODFEPedestalOffsetInfo "));
141  }
142 
143  try {
144  if(result->getId()!=0) {
145  m_readStmt->setSQL("SELECT * FROM " + getTable() +
146  " where rec_id = :1 ");
147  m_readStmt->setInt(1, result->getId());
148  } else if (result->getConfigTag()!="") {
149  m_readStmt->setSQL("SELECT * FROM " + getTable() +
150  " where tag=:1 AND version=:2 " );
151  m_readStmt->setString(1, result->getConfigTag());
152  m_readStmt->setInt(2, result->getVersion());
153  } else {
154  // we should never pass here
155  throw(std::runtime_error("ODFEPedestalOffsetInfo::fetchData(): no Id defined for this record "));
156  }
157 
158  ResultSet* rset = m_readStmt->executeQuery();
159 
160  rset->next();
161 
162  // 1 is the id and 2 is the config tag and 3 is the version
163 
164  result->setId(rset->getInt(1));
165  result->setConfigTag(rset->getString(2));
166  result->setVersion(rset->getInt(3));
167 
168  } catch (SQLException &e) {
169  throw(std::runtime_error("ODFEPedestalOffsetInfo::fetchData(): "+e.getMessage()));
170  }
171 }
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
void setConfigTag(std::string x)
Definition: IODConfig.h:31
Statement * m_readStmt
Definition: IODConfig.h:37
std::string getConfigTag()
Definition: IODConfig.h:32
void checkConnection() const
Definition: IDBObject.h:41
int ODFEPedestalOffsetInfo::fetchID ( )
throw (std::runtime_error
)

Definition at line 195 of file ODFEPedestalOffsetInfo.cc.

References alignCSCRings::e.

196 {
197  // Return from memory if available
198  if (m_ID!=0) {
199  return m_ID;
200  }
201 
202  this->checkConnection();
203 
204  try {
205  Statement* stmt = m_conn->createStatement();
206  stmt->setSQL("SELECT rec_id FROM "+ getTable()+
207  "WHERE tag=:1 and version=:2 " );
208 
209  stmt->setString(1, getConfigTag() );
210  stmt->setInt(2, getVersion() );
211 
212  ResultSet* rset = stmt->executeQuery();
213 
214  if (rset->next()) {
215  m_ID = rset->getInt(1);
216  } else {
217  m_ID = 0;
218  }
219  m_conn->terminateStatement(stmt);
220  } catch (SQLException &e) {
221  throw(std::runtime_error("ODFEPedestalOffsetInfo::fetchID: "+e.getMessage()));
222  }
223 
224  return m_ID;
225 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
oracle::occi::Statement Statement
Definition: IODConfig.h:23
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
std::string getConfigTag()
Definition: IODConfig.h:32
void checkConnection() const
Definition: IDBObject.h:41
void ODFEPedestalOffsetInfo::fetchLastData ( ODFEPedestalOffsetInfo result)
throw (std::runtime_error
)
private

Definition at line 173 of file ODFEPedestalOffsetInfo.cc.

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

175 {
176  this->checkConnection();
177  result->clear();
178  try {
179 
180  m_readStmt->setSQL("SELECT * FROM " + getTable() +
181  " where rec_id = ( select max(rec_id) from "+ getTable() +" ) " );
182  ResultSet* rset = m_readStmt->executeQuery();
183 
184  rset->next();
185 
186  result->setId(rset->getInt(1));
187  result->setConfigTag(rset->getString(2));
188  result->setVersion(rset->getInt(3));
189 
190  } catch (SQLException &e) {
191  throw(std::runtime_error("ODFEPedestalOffsetInfo::fetchData(): "+e.getMessage()));
192  }
193 }
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
void setConfigTag(std::string x)
Definition: IODConfig.h:31
Statement * m_readStmt
Definition: IODConfig.h:37
void checkConnection() const
Definition: IDBObject.h:41
int ODFEPedestalOffsetInfo::fetchNextId ( )
throw (std::runtime_error
)

Definition at line 37 of file ODFEPedestalOffsetInfo.cc.

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

37  {
38 
39  int result=0;
40  try {
41  this->checkConnection();
42 
43  m_readStmt = m_conn->createStatement();
44  m_readStmt->setSQL("select COND2CONF_INFO_SQ.NextVal from DUAL ");
45  ResultSet* rset = m_readStmt->executeQuery();
46  while (rset->next ()){
47  result= rset->getInt(1);
48  }
49  result++;
50  m_conn->terminateStatement(m_readStmt);
51  return result;
52 
53  } catch (SQLException &e) {
54  throw(std::runtime_error("ODFEPedestalOffsetInfo::fetchNextId(): "+e.getMessage()));
55  }
56 
57 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
tuple result
Definition: query.py:137
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
Statement * m_readStmt
Definition: IODConfig.h:37
void checkConnection() const
Definition: IDBObject.h:41
int ODFEPedestalOffsetInfo::getId ( ) const
inline

Definition at line 19 of file ODFEPedestalOffsetInfo.h.

References m_ID.

std::string ODFEPedestalOffsetInfo::getTable ( )
inlinevirtual

Implements IODConfig.

Definition at line 16 of file ODFEPedestalOffsetInfo.h.

16 { return "PEDESTAL_OFFSETS_INFO"; }
int ODFEPedestalOffsetInfo::getVersion ( ) const
inline

Definition at line 24 of file ODFEPedestalOffsetInfo.h.

References m_version.

void ODFEPedestalOffsetInfo::prepareWrite ( )
throw (std::runtime_error
)
privatevirtual

Implements IODConfig.

Definition at line 59 of file ODFEPedestalOffsetInfo.cc.

References alignCSCRings::e, and getId().

61 {
62  this->checkConnection();
63 
64  int next_id=0;
65  if(getId()==0){
66  next_id=fetchNextId();
67  }
68 
69  try {
70  m_writeStmt = m_conn->createStatement();
71  m_writeStmt->setSQL("INSERT INTO "+getTable()+" ( rec_id, tag, version) "
72  " VALUES ( :1, :2, :3 ) " );
73 
74  m_writeStmt->setInt(1, next_id);
75  m_ID=next_id;
76 
77  } catch (SQLException &e) {
78  throw(std::runtime_error("ODFEPedestalOffsetInfo::prepareWrite(): "+e.getMessage()));
79  }
80 
81 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Statement * m_writeStmt
Definition: IODConfig.h:36
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
void checkConnection() const
Definition: IDBObject.h:41
void ODFEPedestalOffsetInfo::setId ( int  id)
inline
void ODFEPedestalOffsetInfo::setParameters ( std::map< std::string, std::string >  my_keys_map)

Definition at line 83 of file ODFEPedestalOffsetInfo.cc.

83  {
84 
85  // parses the result of the XML parser that is a map of
86  // string string with variable name variable value
87 
88  for( std::map<std::string, std::string >::iterator ci=
89  my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
90 
91  if(ci->first== "VERSION") setVersion(atoi(ci->second.c_str()) );
92  if(ci->first== "TAG") setConfigTag(ci->second);
93 
94  }
95 
96 }
void setConfigTag(std::string x)
Definition: IODConfig.h:31
void ODFEPedestalOffsetInfo::setVersion ( int  id)
inline
void ODFEPedestalOffsetInfo::writeDB ( )
throw (std::runtime_error
)
private

Definition at line 98 of file ODFEPedestalOffsetInfo.cc.

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

100 {
101  this->checkConnection();
102  this->checkPrepare();
103 
104  try {
105 
106  // number 1 is the id
107  m_writeStmt->setString(2, this->getConfigTag());
108  m_writeStmt->setInt(3, this->getVersion());
109 
110  m_writeStmt->executeUpdate();
111 
112 
113  } catch (SQLException &e) {
114  throw(std::runtime_error("ODFEPedestalOffsetInfo::writeDB(): "+e.getMessage()));
115  }
116 
117 
118  // Now get the ID
119  if (!this->fetchID()) {
120  throw(std::runtime_error("ODFEPedestalOffsetInfo::writeDB: Failed to write"));
121  } else {
122  int old_version=this->getVersion();
123  m_readStmt = m_conn->createStatement();
124  this->fetchData (this);
125  m_conn->terminateStatement(m_readStmt);
126  if(this->getVersion()!=old_version) std::cout << "ODFEPedestalOffsetInfo>>WARNING version is "<< getVersion()<< endl;
127  }
128 
129 
130 
131 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Statement * m_writeStmt
Definition: IODConfig.h:36
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
void checkPrepare()
Definition: IODConfig.h:39
Statement * m_readStmt
Definition: IODConfig.h:37
std::string getConfigTag()
Definition: IODConfig.h:32
tuple cout
Definition: gather_cfg.py:121
void fetchData(ODFEPedestalOffsetInfo *result)
void checkConnection() const
Definition: IDBObject.h:41

Friends And Related Function Documentation

friend class EcalCondDBInterface
friend

Definition at line 11 of file ODFEPedestalOffsetInfo.h.

Member Data Documentation

int ODFEPedestalOffsetInfo::m_ID
private

Definition at line 43 of file ODFEPedestalOffsetInfo.h.

Referenced by getId(), and setId().

int ODFEPedestalOffsetInfo::m_version
private

Definition at line 44 of file ODFEPedestalOffsetInfo.h.

Referenced by getVersion(), and setVersion().