CMS 3D CMS Logo

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

#include <ODFEWeightsInfo.h>

Inheritance diagram for ODFEWeightsInfo:
IODConfig IDBObject

Public Member Functions

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

Constructor & Destructor Documentation

◆ ODFEWeightsInfo()

ODFEWeightsInfo::ODFEWeightsInfo ( )

Definition at line 12 of file ODFEWeightsInfo.cc.

References l1ct::clear().

12  {
13  m_env = nullptr;
14  m_conn = nullptr;
15  m_writeStmt = nullptr;
16  m_readStmt = nullptr;
17  m_config_tag = "";
18  m_ID = 0;
19  m_version = 0;
20  clear();
21 }
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

◆ ~ODFEWeightsInfo()

ODFEWeightsInfo::~ODFEWeightsInfo ( )
override

Definition at line 25 of file ODFEWeightsInfo.cc.

25 {}

Member Function Documentation

◆ clear()

void ODFEWeightsInfo::clear ( void  )
private

Definition at line 23 of file ODFEWeightsInfo.cc.

23 {}

◆ fetchData()

void ODFEWeightsInfo::fetchData ( ODFEWeightsInfo result)
privatenoexcept

Definition at line 108 of file ODFEWeightsInfo.cc.

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

108  {
109  this->checkConnection();
110  result->clear();
111  if (result->getId() == 0 && (result->getConfigTag().empty())) {
112  throw(std::runtime_error("ODFEWeightsInfo::fetchData(): no Id defined for this ODFEWeightsInfo "));
113  }
114 
115  try {
116  if (result->getId() != 0) {
117  m_readStmt->setSQL("SELECT * FROM " + getTable() + " where rec_id = :1 ");
118  m_readStmt->setInt(1, result->getId());
119  } else if (!result->getConfigTag().empty()) {
120  m_readStmt->setSQL("SELECT * FROM " + getTable() + " where tag=:1 AND version=:2 ");
121  m_readStmt->setString(1, result->getConfigTag());
122  m_readStmt->setInt(2, result->getVersion());
123  } else {
124  // we should never pass here
125  throw(std::runtime_error("ODFEWeightsInfo::fetchData(): no Id defined for this ODFEDelaysInfo "));
126  }
127 
128  ResultSet* rset = m_readStmt->executeQuery();
129 
130  rset->next();
131 
132  // 1 is the id and 2 is the config tag and 3 is the version
133 
134  result->setId(rset->getInt(1));
135  result->setConfigTag(rset->getString(2));
136  result->setVersion(rset->getInt(3));
137 
138  } catch (SQLException& e) {
139  throw(std::runtime_error(std::string("ODFEWeightsInfo::fetchData(): ") + e.getMessage()));
140  }
141 }
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
std::string getTable() override
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
Statement * m_readStmt
Definition: IODConfig.h:34

◆ fetchID()

int ODFEWeightsInfo::fetchID ( )
noexcept

Definition at line 143 of file ODFEWeightsInfo.cc.

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

143  {
144  // Return from memory if available
145  if (m_ID != 0) {
146  return m_ID;
147  }
148 
149  this->checkConnection();
150 
151  try {
152  Statement* stmt = m_conn->createStatement();
153  stmt->setSQL("SELECT rec_id FROM " + getTable() + "WHERE tag=:1 and version=:2 ");
154 
155  stmt->setString(1, getConfigTag());
156  stmt->setInt(2, getVersion());
157 
158  ResultSet* rset = stmt->executeQuery();
159 
160  if (rset->next()) {
161  m_ID = rset->getInt(1);
162  } else {
163  m_ID = 0;
164  }
165  m_conn->terminateStatement(stmt);
166  } catch (SQLException& e) {
167  throw(std::runtime_error(std::string("ODFEWeightsInfo::fetchID: ") + e.getMessage()));
168  }
169 
170  return m_ID;
171 }
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
int getVersion() const
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
std::string getConfigTag()
Definition: IODConfig.h:30

◆ fetchNextId()

int ODFEWeightsInfo::fetchNextId ( )
noexcept

Definition at line 27 of file ODFEWeightsInfo.cc.

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

27  {
28  int result = 0;
29  try {
30  this->checkConnection();
31 
32  m_readStmt = m_conn->createStatement();
33  m_readStmt->setSQL("select COND2CONF_INFO_SQ.NextVal from DUAL ");
34  ResultSet* rset = m_readStmt->executeQuery();
35  while (rset->next()) {
36  result = rset->getInt(1);
37  }
38  result++;
39  m_conn->terminateStatement(m_readStmt);
40  return result;
41 
42  } catch (SQLException& e) {
43  throw(std::runtime_error(std::string("ODFEWeightsInfo::fetchNextId(): ") + e.getMessage()));
44  }
45 }
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 ODFEWeightsInfo::getId ( void  ) const
inline

Definition at line 19 of file ODFEWeightsInfo.h.

References m_ID.

Referenced by EcalDccWeightBuilder::writeWeightToDB().

19 { return m_ID; }

◆ getTable()

std::string ODFEWeightsInfo::getTable ( )
inlineoverridevirtual

Implements IODConfig.

Definition at line 16 of file ODFEWeightsInfo.h.

16 { return "DCC_WEIGHTS_INFO"; }

◆ getVersion()

int ODFEWeightsInfo::getVersion ( ) const
inline

Definition at line 24 of file ODFEWeightsInfo.h.

References m_version.

24 { return m_version; }

◆ prepareWrite()

void ODFEWeightsInfo::prepareWrite ( )
overrideprivatevirtualnoexcept

Implements IODConfig.

Definition at line 47 of file ODFEWeightsInfo.cc.

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

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

◆ setId()

void ODFEWeightsInfo::setId ( int  id)
inline

Definition at line 18 of file ODFEWeightsInfo.h.

References l1ctLayer2EG_cff::id, and m_ID.

◆ setParameters()

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

Definition at line 69 of file ODFEWeightsInfo.cc.

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

◆ setVersion()

void ODFEWeightsInfo::setVersion ( int  id)
inline

◆ writeDB()

void ODFEWeightsInfo::writeDB ( )
privatenoexcept

Definition at line 81 of file ODFEWeightsInfo.cc.

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

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

Friends And Related Function Documentation

◆ EcalCondDBInterface

friend class EcalCondDBInterface
friend

Definition at line 11 of file ODFEWeightsInfo.h.

Member Data Documentation

◆ m_ID

int ODFEWeightsInfo::m_ID
private

Definition at line 40 of file ODFEWeightsInfo.h.

Referenced by getId(), and setId().

◆ m_version

int ODFEWeightsInfo::m_version
private

Definition at line 41 of file ODFEWeightsInfo.h.

Referenced by getVersion(), and setVersion().