CMS 3D CMS Logo

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

#include <DCUTag.h>

Inheritance diagram for DCUTag:
ITag IUniqueDBObject IDBObject

Public Member Functions

 DCUTag ()
 
int fetchID () noexcept(false) override
 
std::string getGeneralTag () const
 
LocationDef getLocationDef () const
 
bool operator!= (const DCUTag &t) const
 
bool operator== (const DCUTag &t) const
 
void setByID (int id) noexcept(false) override
 
void setGeneralTag (std::string tag)
 
void setLocationDef (const LocationDef &locDef)
 
 ~DCUTag () override
 
- 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 fetchAllTags (std::vector< DCUTag > *fillVec) noexcept(false)
 
void fetchParentIDs (int *locId) noexcept(false)
 
int writeDB () noexcept(false)
 

Private Attributes

std::string m_genTag
 
LocationDef m_locDef
 

Friends

class DCUIOV
 
class EcalCondDBInterface
 

Additional Inherited Members

- Static Public Attributes inherited from IDBObject
static int const ECALDB_NROWS =1024
 
- Protected Member Functions inherited from IDBObject
void checkConnection () const noexcept(false)
 
- Protected Attributes inherited from IUniqueDBObject
int m_ID
 
- Protected Attributes inherited from IDBObject
oracle::occi::Connection * m_conn
 
oracle::occi::Environment * m_env
 

Detailed Description

Tag for Run information

Definition at line 13 of file DCUTag.h.

Constructor & Destructor Documentation

DCUTag::DCUTag ( )

Definition at line 9 of file DCUTag.cc.

10 {
11  m_env = nullptr;
12  m_conn = nullptr;
13  m_ID = 0;
14  m_genTag = "default";
16 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
std::string m_genTag
Definition: DCUTag.h:43
LocationDef m_locDef
Definition: DCUTag.h:44
DCUTag::~DCUTag ( )
override

Definition at line 20 of file DCUTag.cc.

21 {
22 }

Member Function Documentation

void DCUTag::fetchAllTags ( std::vector< DCUTag > *  fillVec)
privatenoexcept

Definition at line 174 of file DCUTag.cc.

References MillePedeFileConverter_cfg::e, setByID(), and IDBObject::setConnection().

176 {
177  this->checkConnection();
178  try {
179  Statement* stmt = m_conn->createStatement();
180  stmt->setSQL("SELECT tag_id FROM dcu_tag ORDER BY tag_id");
181  ResultSet* rset = stmt->executeQuery();
182 
183  DCUTag dcutag;
184  dcutag.setConnection(m_env, m_conn);
185  while(rset->next()) {
186  dcutag.setByID( rset->getInt(1) );
187  fillVec->push_back( dcutag );
188  }
189  m_conn->terminateStatement(stmt);
190  } catch (SQLException &e) {
191  throw(std::runtime_error("DCUTag::fetchAllTags: "+e.getMessage()));
192  }
193 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
void setByID(int id) noexcept(false) override
Definition: DCUTag.cc:102
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
Definition: DCUTag.h:13
int DCUTag::fetchID ( )
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 62 of file DCUTag.cc.

References MillePedeFileConverter_cfg::e.

64 {
65  // Return tag from memory if available
66  if (m_ID) {
67  return m_ID;
68  }
69 
70  this->checkConnection();
71 
72  // fetch the parent IDs
73  int locID;
74  this->fetchParentIDs(&locID);
75 
76  // fetch this ID
77  try {
78  Statement* stmt = m_conn->createStatement();
79  stmt->setSQL("SELECT tag_id FROM dcu_tag WHERE "
80  "gen_tag = :1 AND "
81  "location_id = :2");
82  stmt->setString(1, m_genTag);
83  stmt->setInt(2, locID);
84 
85  ResultSet* rset = stmt->executeQuery();
86 
87  if (rset->next()) {
88  m_ID = rset->getInt(1);
89  } else {
90  m_ID = 0;
91  }
92  m_conn->terminateStatement(stmt);
93  } catch (SQLException &e) {
94  throw(std::runtime_error("DCUTag::fetchID: "+e.getMessage()));
95  }
96 
97  return m_ID;
98 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
std::string m_genTag
Definition: DCUTag.h:43
void fetchParentIDs(int *locId) noexcept(false)
Definition: DCUTag.cc:197
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
void DCUTag::fetchParentIDs ( int *  locId)
privatenoexcept

Definition at line 197 of file DCUTag.cc.

199 {
200  // get the location
202  *locID = m_locDef.fetchID();
203 
204  if (! *locID) {
205  throw(std::runtime_error("DCUTag::writeDB: Given location does not exist in DB"));
206  }
207 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
LocationDef m_locDef
Definition: DCUTag.h:44
int fetchID() noexcept(false) override
Definition: LocationDef.cc:43
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
string DCUTag::getGeneralTag ( ) const

Definition at line 26 of file DCUTag.cc.

27 {
28  return m_genTag;
29 }
std::string m_genTag
Definition: DCUTag.h:43
LocationDef DCUTag::getLocationDef ( ) const

Definition at line 45 of file DCUTag.cc.

46 {
47  return m_locDef;
48 }
LocationDef m_locDef
Definition: DCUTag.h:44
bool DCUTag::operator!= ( const DCUTag t) const
inline

Definition at line 39 of file DCUTag.h.

References protons_cff::t.

39 { return !(*this == t); }
bool DCUTag::operator== ( const DCUTag t) const
inline

Definition at line 33 of file DCUTag.h.

References m_genTag, and m_locDef.

34  {
35  return (m_genTag == t.m_genTag &&
36  m_locDef == t.m_locDef);
37  }
std::string m_genTag
Definition: DCUTag.h:43
LocationDef m_locDef
Definition: DCUTag.h:44
void DCUTag::setByID ( int  id)
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 102 of file DCUTag.cc.

References MillePedeFileConverter_cfg::e, and triggerObjects_cff::id.

Referenced by fetchAllTags().

104 {
105  this->checkConnection();
106 
107  try {
108  Statement* stmt = m_conn->createStatement();
109 
110  stmt->setSQL("SELECT gen_tag, location_id FROM dcu_tag WHERE tag_id = :1");
111  stmt->setInt(1, id);
112 
113  ResultSet* rset = stmt->executeQuery();
114  if (rset->next()) {
115  m_genTag = rset->getString(1);
116  int locID = rset->getInt(2);
117 
119  m_locDef.setByID(locID);
120 
121  m_ID = id;
122  } else {
123  throw(std::runtime_error("DCUTag::setByID: Given tag_id is not in the database"));
124  }
125 
126  m_conn->terminateStatement(stmt);
127  } catch (SQLException &e) {
128  throw(std::runtime_error("DCUTag::setByID: "+e.getMessage()));
129  }
130 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
std::string m_genTag
Definition: DCUTag.h:43
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
void setByID(int id) noexcept(false) override
Definition: LocationDef.cc:76
LocationDef m_locDef
Definition: DCUTag.h:44
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
void DCUTag::setGeneralTag ( std::string  tag)

Definition at line 35 of file DCUTag.cc.

36 {
37  if (genTag != m_genTag) {
38  m_ID = 0;
39  m_genTag = genTag;
40  }
41 }
std::string m_genTag
Definition: DCUTag.h:43
void DCUTag::setLocationDef ( const LocationDef locDef)

Definition at line 52 of file DCUTag.cc.

53 {
54  if (locDef != m_locDef) {
55  m_ID = 0;
56  m_locDef = locDef;
57  }
58 }
LocationDef m_locDef
Definition: DCUTag.h:44
int DCUTag::writeDB ( )
privatenoexcept

Definition at line 133 of file DCUTag.cc.

References MillePedeFileConverter_cfg::e.

135 {
136  // see if this data is already in the DB
137  if (this->fetchID()) {
138  return m_ID;
139  }
140 
141  // check the connectioin
142  this->checkConnection();
143 
144  // fetch the parent IDs
145  int locID;
146  this->fetchParentIDs(&locID);
147 
148  // write new tag to the DB
149  try {
150  Statement* stmt = m_conn->createStatement();
151 
152  stmt->setSQL("INSERT INTO dcu_tag (tag_id, gen_tag, location_id) "
153  "VALUES (dcu_tag_sq.NextVal, :1, :2)");
154  stmt->setString(1, m_genTag);
155  stmt->setInt(2, locID);
156 
157  stmt->executeUpdate();
158 
159  m_conn->terminateStatement(stmt);
160  } catch (SQLException &e) {
161  throw(std::runtime_error("DCUTag::writeDB: "+e.getMessage()));
162  }
163 
164  // now get the tag_id
165  if (!this->fetchID()) {
166  throw(std::runtime_error("DCUTag::writeDB: Failed to write"));
167  }
168 
169  return m_ID;
170 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
std::string m_genTag
Definition: DCUTag.h:43
void fetchParentIDs(int *locId) noexcept(false)
Definition: DCUTag.cc:197
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
int fetchID() noexcept(false) override
Definition: DCUTag.cc:62

Friends And Related Function Documentation

friend class DCUIOV
friend

Definition at line 15 of file DCUTag.h.

friend class EcalCondDBInterface
friend

Definition at line 16 of file DCUTag.h.

Member Data Documentation

std::string DCUTag::m_genTag
private

Definition at line 43 of file DCUTag.h.

Referenced by operator==().

LocationDef DCUTag::m_locDef
private

Definition at line 44 of file DCUTag.h.

Referenced by operator==().