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

Definition at line 12 of file ODFEWeightsInfo.cc.

References hitfit::clear().

13 {
14  m_env = nullptr;
15  m_conn = nullptr;
16  m_writeStmt = nullptr;
17  m_readStmt = nullptr;
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
std::string m_config_tag
Definition: IODConfig.h:27
Statement * m_readStmt
Definition: IODConfig.h:37
ODFEWeightsInfo::~ODFEWeightsInfo ( )
override

Definition at line 31 of file ODFEWeightsInfo.cc.

32 {
33 }

Member Function Documentation

void ODFEWeightsInfo::clear ( void  )
private

Definition at line 25 of file ODFEWeightsInfo.cc.

Referenced by getVersion().

25  {
26 
27 }
void ODFEWeightsInfo::fetchData ( ODFEWeightsInfo result)
privatenoexcept

Definition at line 131 of file ODFEWeightsInfo.cc.

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

Referenced by getVersion().

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

Definition at line 171 of file ODFEWeightsInfo.cc.

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

Referenced by getVersion().

172 {
173  // Return from memory if available
174  if (m_ID!=0) {
175  return m_ID;
176  }
177 
178  this->checkConnection();
179 
180  try {
181  Statement* stmt = m_conn->createStatement();
182  stmt->setSQL("SELECT rec_id FROM "+ getTable()+
183  "WHERE tag=:1 and version=:2 " );
184 
185  stmt->setString(1, getConfigTag() );
186  stmt->setInt(2, getVersion() );
187 
188  ResultSet* rset = stmt->executeQuery();
189 
190  if (rset->next()) {
191  m_ID = rset->getInt(1);
192  } else {
193  m_ID = 0;
194  }
195  m_conn->terminateStatement(stmt);
196  } catch (SQLException &e) {
197  throw(std::runtime_error(std::string("ODFEWeightsInfo::fetchID: ")+getOraMessage(&e)));
198  }
199 
200  return m_ID;
201 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
std::string getTable() override
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
oracle::occi::Statement Statement
Definition: IODConfig.h:23
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
std::string getConfigTag()
Definition: IODConfig.h:32
int getVersion() const
int ODFEWeightsInfo::fetchNextId ( )
noexcept

Definition at line 37 of file ODFEWeightsInfo.cc.

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

Referenced by getVersion().

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(std::string("ODFEWeightsInfo::fetchNextId(): ")+getOraMessage(&e)));
55  }
56 
57 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
Statement * m_readStmt
Definition: IODConfig.h:37
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; }
std::string ODFEWeightsInfo::getTable ( )
inlineoverridevirtual

Implements IODConfig.

Definition at line 16 of file ODFEWeightsInfo.h.

16 { return "DCC_WEIGHTS_INFO"; }
int ODFEWeightsInfo::getVersion ( ) const
inline
void ODFEWeightsInfo::prepareWrite ( )
overrideprivatevirtualnoexcept

Implements IODConfig.

Definition at line 59 of file ODFEWeightsInfo.cc.

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

Referenced by getVersion().

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(std::string("ODFEWeightsInfo::prepareWrite(): ")+getOraMessage(&e)));
79  }
80 
81 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Statement * m_writeStmt
Definition: IODConfig.h:36
std::string getTable() override
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
int getId() const
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
int fetchNextId() noexcept(false)
void ODFEWeightsInfo::setId ( int  id)
inline

Definition at line 18 of file ODFEWeightsInfo.h.

References triggerObjects_cff::id, and m_ID.

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

Definition at line 83 of file ODFEWeightsInfo.cc.

Referenced by getVersion().

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 >::const_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 setVersion(int id)
void setConfigTag(std::string x)
Definition: IODConfig.h:31
void ODFEWeightsInfo::setVersion ( int  id)
inline
void ODFEWeightsInfo::writeDB ( )
privatenoexcept

Definition at line 98 of file ODFEWeightsInfo.cc.

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

Referenced by getVersion().

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  m_writeStmt->executeUpdate();
110 
111 
112  } catch (SQLException &e) {
113  throw(std::runtime_error(std::string("ODFEWeightsInfo::writeDB(): ")+getOraMessage(&e)));
114  }
115 
116  // Now get the ID
117  if (!this->fetchID()) {
118  throw(std::runtime_error("ODFEWeightsInfo::writeDB: Failed to write"));
119  } else {
120  int old_version=this->getVersion();
121  m_readStmt = m_conn->createStatement();
122  this->fetchData (this);
123  m_conn->terminateStatement(m_readStmt);
124  if(this->getVersion()!=old_version) std::cout << "ODFEWeightsInfo>>WARNING version is "<< getVersion()<< endl;
125  }
126 
127 
128 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Statement * m_writeStmt
Definition: IODConfig.h:36
void fetchData(ODFEWeightsInfo *result) noexcept(false)
int fetchID() noexcept(false)
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
Statement * m_readStmt
Definition: IODConfig.h:37
std::string getConfigTag()
Definition: IODConfig.h:32
void checkPrepare() noexcept(false)
Definition: IODConfig.h:39
int getVersion() const

Friends And Related Function Documentation

friend class EcalCondDBInterface
friend

Definition at line 11 of file ODFEWeightsInfo.h.

Member Data Documentation

int ODFEWeightsInfo::m_ID
private

Definition at line 42 of file ODFEWeightsInfo.h.

Referenced by getId(), and setId().

int ODFEWeightsInfo::m_version
private

Definition at line 43 of file ODFEWeightsInfo.h.

Referenced by getVersion(), and setVersion().