CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ODJBH4Config.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
6 
7 using namespace std;
8 using namespace oracle::occi;
9 
11  m_env = nullptr;
12  m_conn = nullptr;
13  m_writeStmt = nullptr;
14  m_readStmt = nullptr;
15  m_config_tag = "";
16  m_ID = 0;
17  clear();
18 }
19 
21 
23  m_use_buffer = 0;
24  m_hal_mod_file = "";
25  m_hal_add_file = "";
26  m_hal_tab_file = "";
27  m_serial = "";
28  m_caen1 = "";
29  m_caen2 = 0;
30  m_caen3 = 0;
31 }
32 
34  int result = 0;
35  try {
36  this->checkConnection();
37 
38  m_readStmt = m_conn->createStatement();
39  m_readStmt->setSQL("select ecal_JBH4_config_sq.NextVal from dual");
40  ResultSet *rset = m_readStmt->executeQuery();
41  while (rset->next()) {
42  result = rset->getInt(1);
43  }
44  m_conn->terminateStatement(m_readStmt);
45  return result;
46 
47  } catch (SQLException &e) {
48  throw(std::runtime_error("ODJBH4Config::fetchNextId(): " + e.getMessage()));
49  }
50 }
51 
53  this->checkConnection();
54  int next_id = fetchNextId();
55 
56  try {
57  m_writeStmt = m_conn->createStatement();
58  m_writeStmt->setSQL(
59  "INSERT INTO ECAL_Jbh4_CONFIGURATION ( jbh4_configuration_id, jbh4_tag, "
60  " useBuffer, halModuleFile, halAddressTableFile, halStaticTableFile, halcbd8210serialnumber, "
61  " caenbridgetype, caenlinknumber, caenboardnumber) "
62  " VALUES ( :1, :2, :3, :4, :5, :6, :7, :8 , :9, :10 )");
63 
64  m_writeStmt->setInt(1, next_id);
65  m_ID = next_id;
66  } catch (SQLException &e) {
67  throw(std::runtime_error("ODJBH4Config::prepareWrite(): " + e.getMessage()));
68  }
69 }
70 
71 void ODJBH4Config::writeDB() noexcept(false) {
72  this->checkConnection();
73  this->checkPrepare();
74 
75  try {
76  // number 1 is the id number 2 is the tag
77  m_writeStmt->setString(2, this->getConfigTag());
78 
79  m_writeStmt->setInt(3, this->getUseBuffer());
80  m_writeStmt->setString(4, this->getHalModuleFile());
81  m_writeStmt->setString(5, this->getHalAddressTableFile());
82  m_writeStmt->setString(6, this->getHalStaticTableFile());
83  m_writeStmt->setString(7, this->getCbd8210SerialNumber());
84  m_writeStmt->setString(8, this->getCaenBridgeType());
85  m_writeStmt->setInt(9, this->getCaenLinkNumber());
86  m_writeStmt->setInt(10, this->getCaenBoardNumber());
87 
88  m_writeStmt->executeUpdate();
89 
90  } catch (SQLException &e) {
91  throw(std::runtime_error("ODJBH4Config::writeDB(): " + e.getMessage()));
92  }
93  // Now get the ID
94  if (!this->fetchID()) {
95  throw(std::runtime_error("ODJBH4Config::writeDB: Failed to write"));
96  }
97 }
98 
100  this->checkConnection();
101  result->clear();
102  if (result->getId() == 0) {
103  throw(std::runtime_error("ODJBH4Config::fetchData(): no Id defined for this ODJBH4Config "));
104  }
105 
106  try {
107  m_readStmt->setSQL(
108  "SELECT * FROM ECAL_Jbh4_CONFIGURATION "
109  " where ( jbh4_configuration_id = :1 or jbh4_tag=:2 )");
110  m_readStmt->setInt(1, result->getId());
111  m_readStmt->setString(2, result->getConfigTag());
112  ResultSet *rset = m_readStmt->executeQuery();
113 
114  rset->next();
115 
116  result->setId(rset->getInt(1));
117  result->setConfigTag(rset->getString(2));
118 
119  result->setUseBuffer(rset->getInt(3));
120  result->setHalModuleFile(rset->getString(4));
121  result->setHalAddressTableFile(rset->getString(5));
122  result->setHalStaticTableFile(rset->getString(6));
123  result->setCbd8210SerialNumber(rset->getString(7));
124  result->setCaenBridgeType(rset->getString(8));
125  result->setCaenLinkNumber(rset->getInt(9));
126  result->setCaenBoardNumber(rset->getInt(10));
127 
128  } catch (SQLException &e) {
129  throw(std::runtime_error("ODJBH4Config::fetchData(): " + e.getMessage()));
130  }
131 }
132 
133 int ODJBH4Config::fetchID() noexcept(false) {
134  // Return from memory if available
135  if (m_ID != 0) {
136  return m_ID;
137  }
138 
139  this->checkConnection();
140 
141  try {
142  Statement *stmt = m_conn->createStatement();
143  stmt->setSQL(
144  "SELECT jbh4_configuration_id FROM ecal_jbh4_configuration "
145  "WHERE jbh4_tag=:jbh4_tag ");
146 
147  stmt->setString(1, getConfigTag());
148 
149  ResultSet *rset = stmt->executeQuery();
150 
151  if (rset->next()) {
152  m_ID = rset->getInt(1);
153  } else {
154  m_ID = 0;
155  }
156  m_conn->terminateStatement(stmt);
157  } catch (SQLException &e) {
158  throw(std::runtime_error("ODJBH4Config::fetchID: " + e.getMessage()));
159  }
160 
161  return m_ID;
162 }
funct::false
false
Definition: Factorize.h:29
ODJBH4Config.h
ODJBH4Config
Definition: ODJBH4Config.h:9
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
ODJBH4Config::prepareWrite
void prepareWrite() noexcept(false) override
Definition: ODJBH4Config.cc:52
oracle::occi
Definition: ConnectionManager.h:7
clear
void clear(HadCaloObj &c)
Definition: data.h:124
ODJBH4Config::fetchID
int fetchID() noexcept(false)
Definition: ODJBH4Config.cc:133
ODJBH4Config::writeDB
void writeDB() noexcept(false)
Definition: ODJBH4Config.cc:71
ODJBH4Config::fetchData
void fetchData(ODJBH4Config *result) noexcept(false)
Definition: ODJBH4Config.cc:99
std
Definition: JetResolutionObject.h:76
ODJBH4Config::~ODJBH4Config
~ODJBH4Config() override
Definition: ODJBH4Config.cc:20
ODJBH4Config::ODJBH4Config
ODJBH4Config()
Definition: ODJBH4Config.cc:10
Oracle.h
mps_fire.result
result
Definition: mps_fire.py:311
ODJBH4Config::clear
void clear()
Definition: ODJBH4Config.cc:22
ODJBH4Config::fetchNextId
int fetchNextId() noexcept(false)
Definition: ODJBH4Config.cc:33
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37