CMS 3D CMS Logo

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 {
12  m_env = nullptr;
13  m_conn = nullptr;
14  m_writeStmt = nullptr;
15  m_readStmt = nullptr;
16  m_config_tag="";
17  m_ID=0;
18  clear();
19 }
20 
21 
22 
24 {
25 }
26 
28 
29  m_use_buffer=0;
30  m_hal_mod_file="";
31  m_hal_add_file="";
32  m_hal_tab_file="";
33  m_serial="";
34  m_caen1="";
35  m_caen2=0;
36  m_caen3=0;
37 
38 }
39 
40 
42 
43  int result=0;
44  try {
45  this->checkConnection();
46 
47  m_readStmt = m_conn->createStatement();
48  m_readStmt->setSQL("select ecal_JBH4_config_sq.NextVal from dual");
49  ResultSet* rset = m_readStmt->executeQuery();
50  while (rset->next ()){
51  result= rset->getInt(1);
52  }
53  m_conn->terminateStatement(m_readStmt);
54  return result;
55 
56  } catch (SQLException &e) {
57  throw(std::runtime_error("ODJBH4Config::fetchNextId(): "+e.getMessage()));
58  }
59 
60 }
61 
64 {
65  this->checkConnection();
66  int next_id=fetchNextId();
67 
68  try {
69  m_writeStmt = m_conn->createStatement();
70  m_writeStmt->setSQL("INSERT INTO ECAL_Jbh4_CONFIGURATION ( jbh4_configuration_id, jbh4_tag, "
71  " useBuffer, halModuleFile, halAddressTableFile, halStaticTableFile, halcbd8210serialnumber, "
72  " caenbridgetype, caenlinknumber, caenboardnumber) "
73  " VALUES ( :1, :2, :3, :4, :5, :6, :7, :8 , :9, :10 )");
74 
75  m_writeStmt->setInt(1, next_id);
76  m_ID=next_id;
77  } catch (SQLException &e) {
78  throw(std::runtime_error("ODJBH4Config::prepareWrite(): "+e.getMessage()));
79  }
80 }
81 
82 
83 
86 {
87  this->checkConnection();
88  this->checkPrepare();
89 
90  try {
91 
92  // number 1 is the id number 2 is the tag
93  m_writeStmt->setString(2, this->getConfigTag());
94 
95  m_writeStmt->setInt(3, this->getUseBuffer());
96  m_writeStmt->setString(4, this->getHalModuleFile() );
97  m_writeStmt->setString(5, this->getHalAddressTableFile() );
98  m_writeStmt->setString(6, this->getHalStaticTableFile() );
99  m_writeStmt->setString(7, this->getCbd8210SerialNumber() );
100  m_writeStmt->setString(8, this->getCaenBridgeType() );
101  m_writeStmt->setInt(9, this->getCaenLinkNumber() );
102  m_writeStmt->setInt(10, this->getCaenBoardNumber() );
103 
104  m_writeStmt->executeUpdate();
105 
106 
107  } catch (SQLException &e) {
108  throw(std::runtime_error("ODJBH4Config::writeDB(): "+e.getMessage()));
109  }
110  // Now get the ID
111  if (!this->fetchID()) {
112  throw(std::runtime_error("ODJBH4Config::writeDB: Failed to write"));
113  }
114 
115 }
116 
117 
119  noexcept(false)
120 {
121  this->checkConnection();
122  result->clear();
123  if(result->getId()==0){
124  throw(std::runtime_error("ODJBH4Config::fetchData(): no Id defined for this ODJBH4Config "));
125  }
126 
127  try {
128 
129  m_readStmt->setSQL("SELECT * FROM ECAL_Jbh4_CONFIGURATION "
130  " where ( jbh4_configuration_id = :1 or jbh4_tag=:2 )");
131  m_readStmt->setInt(1, result->getId());
132  m_readStmt->setString(2, result->getConfigTag());
133  ResultSet* rset = m_readStmt->executeQuery();
134 
135  rset->next();
136 
137  result->setId(rset->getInt(1));
138  result->setConfigTag(rset->getString(2));
139 
140  result->setUseBuffer( rset->getInt(3) );
141  result->setHalModuleFile( rset->getString(4) );
142  result->setHalAddressTableFile( rset->getString(5) );
143  result->setHalStaticTableFile( rset->getString(6) );
144  result->setCbd8210SerialNumber( rset->getString(7) );
145  result->setCaenBridgeType( rset->getString(8) );
146  result->setCaenLinkNumber( rset->getInt(9) );
147  result->setCaenBoardNumber( rset->getInt(10) );
148 
149  } catch (SQLException &e) {
150  throw(std::runtime_error("ODJBH4Config::fetchData(): "+e.getMessage()));
151  }
152 }
153 
155 {
156  // Return from memory if available
157  if (m_ID!=0) {
158  return m_ID;
159  }
160 
161  this->checkConnection();
162 
163  try {
164  Statement* stmt = m_conn->createStatement();
165  stmt->setSQL("SELECT jbh4_configuration_id FROM ecal_jbh4_configuration "
166  "WHERE jbh4_tag=:jbh4_tag ");
167 
168 
169  stmt->setString(1, getConfigTag());
170 
171  ResultSet* rset = stmt->executeQuery();
172 
173  if (rset->next()) {
174  m_ID = rset->getInt(1);
175  } else {
176  m_ID = 0;
177  }
178  m_conn->terminateStatement(stmt);
179  } catch (SQLException &e) {
180  throw(std::runtime_error("ODJBH4Config::fetchID: "+e.getMessage()));
181  }
182 
183  return m_ID;
184 }
int fetchID() noexcept(false)
void fetchData(ODJBH4Config *result) noexcept(false)
#define noexcept
void prepareWrite() noexcept(false) override
Definition: ODJBH4Config.cc:62
int fetchNextId() noexcept(false)
Definition: ODJBH4Config.cc:41
void writeDB() noexcept(false)
Definition: ODJBH4Config.cc:84
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
~ODJBH4Config() override
Definition: ODJBH4Config.cc:23
oracle::occi::Statement Statement
Definition: IODConfig.h:23
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22