CMS 3D CMS Logo

ODRunConfigInfo.cc
Go to the documentation of this file.
1 #include <stdexcept>
3 
7 
8 using namespace std;
9 using namespace oracle::occi;
10 
12  m_env = nullptr;
13  m_conn = nullptr;
14  m_ID = 0;
15  //
16  m_tag = "";
17  m_version = 0;
18  m_num_seq = 0;
19  m_runTypeDef = RunTypeDef();
20  m_runModeDef = RunModeDef();
21  m_defaults = 0;
22  m_trigger_mode = "";
23  m_num_events = 0;
24 }
25 
27 
28 //
29 RunTypeDef ODRunConfigInfo::getRunTypeDef() const { return m_runTypeDef; }
30 void ODRunConfigInfo::setRunTypeDef(const RunTypeDef& runTypeDef) {
31  if (runTypeDef != m_runTypeDef) {
32  m_ID = 0;
33  m_runTypeDef = runTypeDef;
34  }
35 }
36 //
37 RunModeDef ODRunConfigInfo::getRunModeDef() const { return m_runModeDef; }
38 void ODRunConfigInfo::setRunModeDef(const RunModeDef& runModeDef) {
39  if (runModeDef != m_runModeDef) {
40  m_ID = 0;
41  m_runModeDef = runModeDef;
42  }
43 }
44 //
45 
47  int result = 0;
48  try {
49  this->checkConnection();
50 
51  m_readStmt = m_conn->createStatement();
52  m_readStmt->setSQL("select ecal_run_sq.NextVal from dual");
53  ResultSet* rset = m_readStmt->executeQuery();
54  while (rset->next()) {
55  result = rset->getInt(1);
56  }
57  m_conn->terminateStatement(m_readStmt);
58  return result;
59 
60  } catch (SQLException& e) {
61  throw(std::runtime_error("ODDCCConfig::fetchNextId(): " + e.getMessage()));
62  }
63 }
64 
66  // Return from memory if available
67  if (m_ID > 0) {
68  return m_ID;
69  }
70 
71  this->checkConnection();
72 
73  DateHandler dh(m_env, m_conn);
74 
75  try {
76  Statement* stmt = m_conn->createStatement();
77  stmt->setSQL(
78  "SELECT config_id from ECAL_RUN_CONFIGURATION_DAT "
79  "WHERE tag = :tag "
80  " and version = :version ");
81  stmt->setString(1, m_tag);
82  stmt->setInt(2, m_version);
83 
84  ResultSet* rset = stmt->executeQuery();
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("ODRunConfigInfo::fetchID: " + e.getMessage()));
93  }
94  setByID(m_ID);
95  return m_ID;
96 }
97 
99  this->checkConnection();
100 
101  DateHandler dh(m_env, m_conn);
102 
103  try {
104  Statement* stmt = m_conn->createStatement();
105  stmt->setSQL("SELECT max(config_id) FROM ecal_run_configuration_dat ");
106  ResultSet* rset = stmt->executeQuery();
107 
108  if (rset->next()) {
109  m_ID = rset->getInt(1);
110  } else {
111  m_ID = 0;
112  }
113  m_conn->terminateStatement(stmt);
114  } catch (SQLException& e) {
115  throw(std::runtime_error("ODRunConfigInfo::fetchIDLast: " + e.getMessage()));
116  }
117 
118  setByID(m_ID);
119  return m_ID;
120 }
121 
122 //
124  fetchID();
125  return m_ID;
126 }
127 
128 void ODRunConfigInfo::setByID(int id) noexcept(false) {
129  this->checkConnection();
130 
131  DateHandler dh(m_env, m_conn);
132 
133  try {
134  Statement* stmt = m_conn->createStatement();
135 
136  stmt->setSQL(
137  "SELECT tag, version, run_type_def_id, run_mode_def_id, num_of_sequences, description, defaults,"
138  " trg_mode,num_of_events, db_timestamp, usage_status"
139  " FROM ECAL_RUN_CONFIGURATION_DAT WHERE config_id = :1");
140  stmt->setInt(1, id);
141 
142  ResultSet* rset = stmt->executeQuery();
143  if (rset->next()) {
144  m_tag = rset->getString(1);
145  m_version = rset->getInt(2);
146  int run_type_id = rset->getInt(3);
147  int run_mode_id = rset->getInt(4);
148  m_num_seq = rset->getInt(5);
149  m_description = rset->getString(6);
150  m_defaults = rset->getInt(7);
151  m_trigger_mode = rset->getString(8);
152  m_num_events = rset->getInt(9);
153  Date dbdate = rset->getDate(10);
154  m_db_time = dh.dateToTm(dbdate);
155  m_ID = id;
156  m_runModeDef.setConnection(m_env, m_conn);
157  m_runModeDef.setByID(run_mode_id);
158  m_runTypeDef.setConnection(m_env, m_conn);
159  m_runTypeDef.setByID(run_type_id);
160  m_usage_status = rset->getString(11);
161  } else {
162  throw(std::runtime_error("ODRunConfigInfo::setByID: Given config_id is not in the database"));
163  }
164  m_conn->terminateStatement(stmt);
165  } catch (SQLException& e) {
166  throw(std::runtime_error("ODRunConfigInfo::setByID: " + e.getMessage()));
167  }
168 }
169 
171  this->checkConnection();
172 
173  int next_id = fetchNextId();
174 
175  try {
176  m_writeStmt = m_conn->createStatement();
177  m_writeStmt->setSQL(
178  "INSERT INTO ECAL_RUN_CONFIGURATION_DAT (CONFIG_ID, tag, version, run_type_def_id, "
179  " run_mode_def_id, num_of_sequences, defaults, trg_mode, num_of_events, description, usage_status ) "
180  " VALUES (:1, :2, :3 , :4, :5, :6 ,:7, :8, :9, :10 , :11)");
181 
182  m_writeStmt->setInt(1, next_id);
183  m_ID = next_id;
184 
185  } catch (SQLException& e) {
186  throw(std::runtime_error("ODRunConfigInfo::prepareWrite(): " + e.getMessage()));
187  }
188 }
189 
190 void ODRunConfigInfo::writeDB() noexcept(false) {
191  this->checkConnection();
192  this->checkPrepare();
193 
194  // Validate the data, use infinity-till convention
195  DateHandler dh(m_env, m_conn);
196 
197  try {
198  // get the run mode
199  m_runModeDef.setConnection(m_env, m_conn);
200  int run_mode_id = m_runModeDef.fetchID();
201 
202  // get the run type
203  m_runTypeDef.setConnection(m_env, m_conn);
204  int run_type_id = m_runTypeDef.fetchID();
205 
206  // now insert
207 
208  m_writeStmt->setString(2, this->getTag());
209  m_writeStmt->setInt(3, this->getVersion());
210  m_writeStmt->setInt(4, run_type_id);
211  m_writeStmt->setInt(5, run_mode_id);
212  m_writeStmt->setInt(6, this->getNumberOfSequences());
213  m_writeStmt->setInt(7, this->getDefaults());
214  m_writeStmt->setString(8, this->getTriggerMode());
215  m_writeStmt->setInt(9, this->getNumberOfEvents());
216  m_writeStmt->setString(10, this->getDescription());
217  m_writeStmt->setString(11, this->getUsageStatus());
218 
219  m_writeStmt->executeUpdate();
220 
221  } catch (SQLException& e) {
222  throw(std::runtime_error("ODRunConfigInfo::writeDB: " + e.getMessage()));
223  }
224  // Now get the ID
225  if (!this->fetchID()) {
226  throw(std::runtime_error("ODRunConfigInfo::writeDB Failed to write"));
227  }
228 
229  this->setByID(m_ID);
230 
231  cout << "ODRunConfigInfo::writeDB>> done inserting ODRunConfigInfo with id=" << m_ID << endl;
232 }
233 
235  this->checkConnection();
236 
237  // Check if this has already been written
238  if (!this->fetchID()) {
239  this->writeDB();
240  }
241 
242  try {
243  Statement* stmt = m_conn->createStatement();
244 
245  stmt->setSQL("UPDATE ecal_run_configuration_dat set defaults=:1 where config_id=:2 ");
246 
247  stmt->setInt(1, m_defaults);
248  stmt->setInt(2, m_ID);
249 
250  stmt->executeUpdate();
251 
252  m_conn->terminateStatement(stmt);
253  } catch (SQLException& e) {
254  throw(std::runtime_error("ODRunConfigInfo::writeDB: " + e.getMessage()));
255  }
256 
257  return m_ID;
258 }
259 
261  m_num_seq = 0;
262  m_runTypeDef = RunTypeDef();
263  m_runModeDef = RunModeDef();
264  m_defaults = 0;
265  m_trigger_mode = "";
266  m_num_events = 0;
267 }
268 
270  this->checkConnection();
271  DateHandler dh(m_env, m_conn);
272  // result->clear();
273 
274  if (result->getId() == 0) {
275  //throw(std::runtime_error("FEConfigMainInfo::fetchData(): no Id defined for this FEConfigMainInfo "));
276  result->fetchID();
277  }
278  try {
279  m_readStmt->setSQL(
280  "SELECT config_id, tag, version, run_type_def_id, run_mode_def_id, \
281  num_of_sequences, description, defaults, trg_mode, num_of_events, db_timestamp, usage_status \
282  FROM ECAL_RUN_CONFIGURATION_DAT WHERE config_id = :1 ");
283  m_readStmt->setInt(1, result->getId());
284 
285  ResultSet* rset = m_readStmt->executeQuery();
286  rset->next();
287 
288  result->setId(rset->getInt(1));
289  result->setTag(rset->getString(2));
290  result->setVersion(rset->getInt(3));
291  // RunTypeDef myRunType = rset->getInt(4);
292  // result->setRunTypeDef( myRunType );
293  // RunModeDef myRunMode = rset->getInt(5);
294  // result->setRunModeDef( myRunMode );
295  result->setNumberOfSequences(rset->getInt(6));
296  result->setDescription(rset->getString(7));
297  result->setDefaults(rset->getInt(8));
298  result->setTriggerMode(rset->getString(9));
299  result->setNumberOfEvents(rset->getInt(10));
300  Date dbdate = rset->getDate(11);
301  result->setDBTime(dh.dateToTm(dbdate));
302  result->setUsageStatus(rset->getString(12));
303 
304  } catch (SQLException& e) {
305  cout << " ODRunConfigInfo::fetchData(): " << e.getMessage() << endl;
306  throw(std::runtime_error("ODRunConfigInfo::fetchData(): " + e.getMessage()));
307  }
308 }
ODRunConfigInfo::updateDefaultCycle
int updateDefaultCycle() noexcept(false)
Definition: ODRunConfigInfo.cc:234
funct::false
false
Definition: Factorize.h:34
RunModeDef
Definition: RunModeDef.h:12
ODRunConfigInfo::getRunTypeDef
RunTypeDef getRunTypeDef() const
Definition: ODRunConfigInfo.cc:29
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ODRunConfigInfo::~ODRunConfigInfo
~ODRunConfigInfo() override
Definition: ODRunConfigInfo.cc:26
ODRunConfigInfo::fetchData
void fetchData(ODRunConfigInfo *result) noexcept(false)
Definition: ODRunConfigInfo.cc:269
ODRunConfigInfo::clear
void clear()
Definition: ODRunConfigInfo.cc:260
ODRunConfigInfo::getRunModeDef
RunModeDef getRunModeDef() const
Definition: ODRunConfigInfo.cc:37
ODRunConfigInfo::setByID
void setByID(int id) noexcept(false)
Definition: ODRunConfigInfo.cc:128
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
ODRunConfigInfo::fetchNextId
int fetchNextId() noexcept(false)
Definition: ODRunConfigInfo.cc:46
ODRunConfigInfo::ODRunConfigInfo
ODRunConfigInfo()
Definition: ODRunConfigInfo.cc:11
ODRunConfigInfo.h
oracle::occi
Definition: ConnectionManager.h:7
ODRunConfigInfo::writeDB
void writeDB() noexcept(false)
Definition: ODRunConfigInfo.cc:190
RunTypeDef
Definition: RunTypeDef.h:12
ODRunConfigInfo::prepareWrite
void prepareWrite() noexcept(false) override
Definition: ODRunConfigInfo.cc:170
ODRunConfigInfo::fetchIDLast
int fetchIDLast() noexcept(false)
Definition: ODRunConfigInfo.cc:98
Tm.h
ODRunConfigInfo
Definition: ODRunConfigInfo.h:12
GlobalTrackerMuonAlignment_cfi.writeDB
writeDB
Definition: GlobalTrackerMuonAlignment_cfi.py:10
ODRunConfigInfo::fetchID
int fetchID() noexcept(false)
Definition: ODRunConfigInfo.cc:65
std
Definition: JetResolutionObject.h:76
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
ODRunConfigInfo::setRunTypeDef
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: ODRunConfigInfo.cc:30
ODRunConfigInfo::fetchIDFromTagAndVersion
int fetchIDFromTagAndVersion() noexcept(false)
Definition: ODRunConfigInfo.cc:123
Oracle.h
DateHandler.h
mps_fire.result
result
Definition: mps_fire.py:303
DateHandler
Definition: DateHandler.h:7
cuy.dh
dh
Definition: cuy.py:355
ODRunConfigInfo::setRunModeDef
void setRunModeDef(const RunModeDef &runModeDef)
Definition: ODRunConfigInfo.cc:38
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37