CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes | Friends
ODTowersToByPassInfo Class Reference

#include <ODTowersToByPassInfo.h>

Inheritance diagram for ODTowersToByPassInfo:
IODConfig IDBObject

Public Member Functions

int fetchID () noexcept(false)
 
int fetchNextId () noexcept(false)
 
int getId () const
 
std::string getTable () override
 
int getVersion () const
 
 ODTowersToByPassInfo ()
 
void setId (int id)
 
void setParameters (const std::map< std::string, std::string > &my_keys_map)
 
void setVersion (int id)
 
 ~ODTowersToByPassInfo () 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 (ODTowersToByPassInfo *result) noexcept(false)
 
void prepareWrite () noexcept(false) override
 
void writeDB () noexcept(false)
 

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 () 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 9 of file ODTowersToByPassInfo.h.

Constructor & Destructor Documentation

ODTowersToByPassInfo::ODTowersToByPassInfo ( )

Definition at line 11 of file ODTowersToByPassInfo.cc.

References clear().

11  {
12  m_env = nullptr;
13  m_conn = nullptr;
14  m_writeStmt = nullptr;
15  m_readStmt = nullptr;
16  m_config_tag = "";
17  m_ID = 0;
18  m_version = 0;
19  clear();
20 }
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
Statement * m_readStmt
Definition: IODConfig.h:34
ODTowersToByPassInfo::~ODTowersToByPassInfo ( )
override

Definition at line 24 of file ODTowersToByPassInfo.cc.

24 {}

Member Function Documentation

void ODTowersToByPassInfo::clear ( void  )
private

Definition at line 22 of file ODTowersToByPassInfo.cc.

22 {}
void ODTowersToByPassInfo::fetchData ( ODTowersToByPassInfo result)
privatenoexcept

Definition at line 107 of file ODTowersToByPassInfo.cc.

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

107  {
108  this->checkConnection();
109  result->clear();
110  if (result->getId() == 0 && (result->getConfigTag().empty())) {
111  throw(std::runtime_error("ODTowersToByPassInfo::fetchData(): no Id defined for this ODTowersToByPassInfo "));
112  }
113 
114  try {
115  if (result->getId() != 0) {
116  m_readStmt->setSQL("SELECT * FROM " + getTable() + " where rec_id = :1 ");
117  m_readStmt->setInt(1, result->getId());
118  } else if (!result->getConfigTag().empty()) {
119  if (result->getVersion() != 0) {
120  m_readStmt->setSQL("SELECT * FROM " + getTable() +
121  " WHERE tag = :tag "
122  " and version = :version ");
123  m_readStmt->setString(1, result->getConfigTag());
124  m_readStmt->setInt(2, result->getVersion());
125  } else {
126  // always select the last inserted one with a given tag
127  m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE tag = :1 and version= (select max(version) from " +
128  getTable() + " where tag=:2) ");
129  m_readStmt->setString(1, result->getConfigTag());
130  m_readStmt->setString(2, result->getConfigTag());
131  }
132 
133  } else {
134  // we should never pass here
135  throw(std::runtime_error("ODTowersToByPassInfo::fetchData(): no Id defined for this record "));
136  }
137 
138  ResultSet* rset = m_readStmt->executeQuery();
139 
140  rset->next();
141 
142  // 1 is the id and 2 is the config tag and 3 is the version
143 
144  result->setId(rset->getInt(1));
145  result->setConfigTag(rset->getString(2));
146  result->setVersion(rset->getInt(3));
147 
148  } catch (SQLException& e) {
149  throw(std::runtime_error(std::string("ODTowersToByPassInfo::fetchData(): ") + e.getMessage()));
150  }
151 }
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
std::string getTable() override
void setConfigTag(std::string x)
Definition: IODConfig.h:29
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
Statement * m_readStmt
Definition: IODConfig.h:34
std::string getConfigTag()
Definition: IODConfig.h:30
int ODTowersToByPassInfo::fetchID ( )
noexcept

Definition at line 153 of file ODTowersToByPassInfo.cc.

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

153  {
154  // Return from memory if available
155  if (m_ID != 0) {
156  return m_ID;
157  }
158 
159  this->checkConnection();
160 
161  try {
162  Statement* stmt = m_conn->createStatement();
163  stmt->setSQL("SELECT rec_id FROM " + getTable() + " WHERE tag=:1 and version=:2 ");
164 
165  stmt->setString(1, getConfigTag());
166  stmt->setInt(2, getVersion());
167 
168  ResultSet* rset = stmt->executeQuery();
169 
170  if (rset->next()) {
171  m_ID = rset->getInt(1);
172  } else {
173  m_ID = 0;
174  }
175  m_conn->terminateStatement(stmt);
176  } catch (SQLException& e) {
177  throw(std::runtime_error(std::string("ODTowersToByPassInfo::fetchID: ") + e.getMessage()));
178  }
179 
180  return m_ID;
181 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
std::string getTable() override
oracle::occi::Statement Statement
Definition: IODConfig.h:21
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
std::string getConfigTag()
Definition: IODConfig.h:30
int ODTowersToByPassInfo::fetchNextId ( )
noexcept

Definition at line 26 of file ODTowersToByPassInfo.cc.

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

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

Definition at line 19 of file ODTowersToByPassInfo.h.

References m_ID.

19 { return m_ID; }
std::string ODTowersToByPassInfo::getTable ( )
inlineoverridevirtual

Implements IODConfig.

Definition at line 16 of file ODTowersToByPassInfo.h.

16 { return "TOWERS_TO_BYPASS_INFO"; }
int ODTowersToByPassInfo::getVersion ( ) const
inline

Definition at line 24 of file ODTowersToByPassInfo.h.

References m_version.

24 { return m_version; }
void ODTowersToByPassInfo::prepareWrite ( )
overrideprivatevirtualnoexcept

Implements IODConfig.

Definition at line 46 of file ODTowersToByPassInfo.cc.

References alignCSCRings::e, getId(), and AlCaHLTBitMon_QueryRunRegistry::string.

46  {
47  this->checkConnection();
48 
49  int next_id = 0;
50  if (getId() == 0) {
51  next_id = fetchNextId();
52  }
53 
54  try {
55  m_writeStmt = m_conn->createStatement();
56  m_writeStmt->setSQL("INSERT INTO " + getTable() +
57  " ( rec_id, tag, version) "
58  " VALUES ( :1, :2, :3 ) ");
59 
60  m_writeStmt->setInt(1, next_id);
61  m_ID = next_id;
62 
63  } catch (SQLException& e) {
64  throw(std::runtime_error(std::string("ODTowersToByPassInfo::prepareWrite(): ") + e.getMessage()));
65  }
66 }
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
int fetchNextId() noexcept(false)
std::string getTable() override
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
void ODTowersToByPassInfo::setId ( int  id)
inline

Definition at line 18 of file ODTowersToByPassInfo.h.

References gpuClustering::id, and m_ID.

18 { m_ID = id; }
uint16_t *__restrict__ id
void ODTowersToByPassInfo::setParameters ( const std::map< std::string, std::string > &  my_keys_map)

Definition at line 68 of file ODTowersToByPassInfo.cc.

68  {
69  // parses the result of the XML parser that is a map of
70  // string string with variable name variable value
71 
72  for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
73  if (ci->first == "VERSION")
74  setVersion(atoi(ci->second.c_str()));
75  if (ci->first == "TAG")
76  setConfigTag(ci->second);
77  }
78 }
void setConfigTag(std::string x)
Definition: IODConfig.h:29
void ODTowersToByPassInfo::setVersion ( int  id)
inline

Definition at line 23 of file ODTowersToByPassInfo.h.

References gpuClustering::id, and m_version.

23 { m_version = id; }
uint16_t *__restrict__ id
void ODTowersToByPassInfo::writeDB ( )
privatenoexcept

Definition at line 80 of file ODTowersToByPassInfo.cc.

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

80  {
81  this->checkConnection();
82  this->checkPrepare();
83 
84  try {
85  // number 1 is the id
86  m_writeStmt->setString(2, this->getConfigTag());
87  m_writeStmt->setInt(3, this->getVersion());
88 
89  m_writeStmt->executeUpdate();
90 
91  } catch (SQLException& e) {
92  throw(std::runtime_error(std::string("ODTowersToByPassInfo::writeDB(): ") + e.getMessage()));
93  }
94  // Now get the ID
95  if (!this->fetchID()) {
96  throw(std::runtime_error("ODTowersToByPassInfo::writeDB: Failed to write"));
97  } else {
98  int old_version = this->getVersion();
99  m_readStmt = m_conn->createStatement();
100  this->fetchData(this);
101  m_conn->terminateStatement(m_readStmt);
102  if (this->getVersion() != old_version)
103  std::cout << "ODTowersToByPassInfo>>WARNING version is " << getVersion() << endl;
104  }
105 }
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
void fetchData(ODTowersToByPassInfo *result) noexcept(false)
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
Statement * m_readStmt
Definition: IODConfig.h:34
std::string getConfigTag()
Definition: IODConfig.h:30
tuple cout
Definition: gather_cfg.py:144
void checkPrepare() noexcept(false)
Definition: IODConfig.h:36
int fetchID() noexcept(false)

Friends And Related Function Documentation

friend class EcalCondDBInterface
friend

Definition at line 11 of file ODTowersToByPassInfo.h.

Member Data Documentation

int ODTowersToByPassInfo::m_ID
private

Definition at line 40 of file ODTowersToByPassInfo.h.

Referenced by getId(), and setId().

int ODTowersToByPassInfo::m_version
private

Definition at line 41 of file ODTowersToByPassInfo.h.

Referenced by getVersion(), and setVersion().