CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MonRunTag.cc
Go to the documentation of this file.
1 #include <string>
3 
5 
6 using namespace std;
7 using namespace oracle::occi;
8 
10 {
11  m_env = NULL;
12  m_conn = NULL;
13  m_ID = 0;
14  m_genTag = "default";
15  m_monVersionDef = MonVersionDef();
16 }
17 
18 
19 
21 {
22 }
23 
24 
25 
27 {
28  return m_genTag;
29 }
30 
31 
32 
33 void MonRunTag::setGeneralTag(string genTag)
34 {
35  if (genTag != m_genTag) {
36  m_ID = 0;
37  m_genTag = genTag;
38  }
39 }
40 
41 
42 
44 {
45  return m_monVersionDef;
46 }
47 
48 
50 {
51  if (ver != m_monVersionDef) {
52  m_ID = 0;
53  m_monVersionDef = ver;
54  }
55 }
56 
57 
58 
60  throw(std::runtime_error)
61 {
62  // Return tag from memory if available
63  if (m_ID) {
64  return m_ID;
65  }
66 
67  this->checkConnection();
68 
69  // fetch parent IDs
70  int verID;
71  this->fetchParentIDs(&verID);
72 
73  // fetch this ID
74  try {
75  Statement* stmt = m_conn->createStatement();
76  stmt->setSQL("SELECT tag_id FROM mon_run_tag WHERE "
77  "gen_tag = :1 AND "
78  "mon_ver_id = :2");
79 
80  stmt->setString(1, m_genTag);
81  stmt->setInt(2, verID);
82 
83  ResultSet* rset = stmt->executeQuery();
84 
85  if (rset->next()) {
86  m_ID = rset->getInt(1);
87  } else {
88  m_ID = 0;
89  }
90  m_conn->terminateStatement(stmt);
91  } catch (SQLException &e) {
92  throw(std::runtime_error("MonRunTag::fetchID: "+e.getMessage()));
93  }
94 
95  return m_ID;
96 }
97 
98 
99 
100 void MonRunTag::setByID(int id)
101  throw(std::runtime_error)
102 {
103  this->checkConnection();
104 
105  try {
106  Statement* stmt = m_conn->createStatement();
107 
108  stmt->setSQL("SELECT gen_tag, mon_ver_id FROM mon_run_tag WHERE tag_id = :1");
109  stmt->setInt(1, id);
110 
111  ResultSet* rset = stmt->executeQuery();
112  if (rset->next()) {
113  m_genTag = rset->getString(1);
114  int verID = rset->getInt(2);
115  m_monVersionDef.setByID(verID);
116  m_ID = id;
117  } else {
118  throw(std::runtime_error("MonRunTag::setByID: Given tag_id is not in the database"));
119  }
120 
121  m_conn->terminateStatement(stmt);
122  } catch (SQLException &e) {
123  throw(std::runtime_error("MonRunTag::setByID: "+e.getMessage()));
124  }
125 }
126 
127 
129  throw(std::runtime_error)
130 {
131  // see if this data is already in the DB
132  if (this->fetchID()) {
133  return m_ID;
134  }
135 
136  // check the connectioin
137  this->checkConnection();
138 
139  // fetch parent IDs
140  int verID;
141  this->fetchParentIDs(&verID);
142 
143  // write new tag to the DB
144  try {
145  Statement* stmt = m_conn->createStatement();
146 
147  stmt->setSQL("INSERT INTO mon_run_tag (tag_id, gen_tag, mon_ver_id) "
148  "VALUES (mon_run_tag_sq.NextVal, :1, :2)");
149  stmt->setString(1, m_genTag);
150  stmt->setInt(2, verID);
151 
152  stmt->executeUpdate();
153 
154  m_conn->terminateStatement(stmt);
155  } catch (SQLException &e) {
156  throw(std::runtime_error("MonRunTag::writeDB: "+e.getMessage()));
157  }
158 
159  // now get the tag_id
160  if (!this->fetchID()) {
161  throw(std::runtime_error("MonRunTag::writeDB: Failed to write"));
162  }
163 
164  return m_ID;
165 }
166 
167 
168 
169 void MonRunTag::fetchAllTags( std::vector<MonRunTag>* fillVec)
170  throw(std::runtime_error)
171 {
172  this->checkConnection();
173  try {
174  Statement* stmt = m_conn->createStatement();
175  stmt->setSQL("SELECT tag_id FROM mon_run_tag ORDER BY tag_id");
176  ResultSet* rset = stmt->executeQuery();
177 
178  MonRunTag runtag;
179  runtag.setConnection(m_env, m_conn);
180  while(rset->next()) {
181  runtag.setByID( rset->getInt(1) );
182  fillVec->push_back( runtag );
183  }
184  m_conn->terminateStatement(stmt);
185  } catch (SQLException &e) {
186  throw(std::runtime_error("MonRunTag::fetchAllTags: "+e.getMessage()));
187  }
188 }
189 
190 
191 
193  throw(std::runtime_error)
194 {
195  // get the monitoring version
196  m_monVersionDef.setConnection(m_env, m_conn);
197  *verID = m_monVersionDef.fetchID();
198 
199  if (! *verID) {
200  throw(std::runtime_error("MonRunTag::writeDB: Given monitoring version does not exist in DB"));
201  }
202 }
int fetchID()
Definition: MonRunTag.cc:59
void fetchParentIDs(int *verID)
Definition: MonRunTag.cc:192
int writeDB()
Definition: MonRunTag.cc:128
#define NULL
Definition: scimark2.h:8
void setGeneralTag(std::string tag)
Definition: MonRunTag.cc:33
~MonRunTag()
Definition: MonRunTag.cc:20
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
void setByID(int id)
Definition: MonRunTag.cc:100
void fetchAllTags(std::vector< MonRunTag > *fillVec)
Definition: MonRunTag.cc:169
MonVersionDef getMonVersionDef() const
Definition: MonRunTag.cc:43
void setMonVersionDef(const MonVersionDef &ver)
Definition: MonRunTag.cc:49
std::string getGeneralTag() const
Definition: MonRunTag.cc:26
MonRunTag()
Definition: MonRunTag.cc:9
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23