CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ODCCSConfig.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
3 #include <string.h>
4 #include <cstdlib>
5 
7 
9 
10 #include <limits>
11 
12 #define MY_NULL 16777215 // numeric_limits<int>::quiet_NaN()
13 #define SET_INT( statement, paramNum, paramVal ) if( paramVal != MY_NULL ) { statement->setInt(paramNum, paramVal); } else { statement->setNull(paramNum,OCCINUMBER); }
14 #define SET_STRING( statement, paramNum, paramVal ) if( ! paramVal.empty() ) { statement->setString(paramNum, paramVal); } else { statement->setNull(paramNum,OCCICHAR); }
15 
16 using namespace std;
17 using namespace oracle::occi;
18 
20 {
21  m_env = NULL;
22  m_conn = NULL;
23  m_writeStmt = NULL;
24  m_readStmt = NULL;
25  m_config_tag="";
26  m_ID=0;
27  clear();
28 }
29 
30 
32  m_daccal=MY_NULL;
33  m_delay=MY_NULL;
34  m_gain="";
35  m_memgain="";
36  m_offset_high=MY_NULL;
37  m_offset_low=MY_NULL;
38  m_offset_mid=MY_NULL;
39  m_trg_mode="";
40  m_trg_filter="";
41  m_bgo="";
42  m_tts_mask=MY_NULL;
43  m_daq=MY_NULL;
44  m_trg=MY_NULL;
45  m_bc0=MY_NULL;
46  m_bc0_delay=MY_NULL;
47  m_te_delay=MY_NULL;
48 }
49 
50 
51 
53 {
54 }
55 
56 
57 
58 int ODCCSConfig::fetchNextId() throw(std::runtime_error) {
59 
60  int result=0;
61  try {
62  this->checkConnection();
63 
64  m_readStmt = m_conn->createStatement();
65  m_readStmt->setSQL("select ecal_CCS_config_sq.NextVal from dual");
66  ResultSet* rset = m_readStmt->executeQuery();
67  while (rset->next ()){
68  result= rset->getInt(1);
69  }
70  m_conn->terminateStatement(m_readStmt);
71  return result;
72 
73  } catch (SQLException &e) {
74  throw(std::runtime_error("ODCCSConfig::fetchNextId(): "+e.getMessage()));
75  }
76 
77 }
78 
80  throw(std::runtime_error)
81 {
82  this->checkConnection();
83  int next_id=fetchNextId();
84 
85  try {
86  m_writeStmt = m_conn->createStatement();
87  m_writeStmt->setSQL("INSERT INTO ECAL_CCS_CONFIGURATION ( ccs_configuration_id, ccs_tag ,"
88  " daccal, delay, gain, memgain, offset_high,offset_low,offset_mid, trg_mode, trg_filter, "
89  " clock, BGO_SOURCE, TTS_MASK, DAQ_BCID_PRESET , TRIG_BCID_PRESET, BC0_COUNTER, BC0_DELAY, TE_DELAY ) "
90  "VALUES ( "
91  " :ccs_configuration_id, :ccs_tag, :daccal, :delay, :gain, :memgain, :offset_high,:offset_low,"
92  " :offset_mid, :trg_mode, :trg_filter, :clock, :BGO_SOURCE, :TTS_MASK, "
93  " :DAQ_BCID_PRESET , :TRIG_BCID_PRESET, :BC0_COUNTER, :BC0_DELAY, :TE_DELAY) ");
94 
95  m_writeStmt->setInt(1, next_id);
96  m_ID=next_id;
97 
98  } catch (SQLException &e) {
99  throw(std::runtime_error("ODCCSConfig::prepareWrite(): "+e.getMessage()));
100  }
101 
102 }
103 
104 void ODCCSConfig::setParameters(std::map<string,string> my_keys_map){
105 
106  // parses the result of the XML parser that is a map of
107  // string string with variable name variable value
108 
109  for( std::map<std::string, std::string >::iterator ci=
110  my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
111 
112  if(ci->first== "CCS_CONFIGURATION_ID") setConfigTag(ci->second);
113  else if(ci->first== "DACCAL") setDaccal(atoi(ci->second.c_str()) );
114  else if(ci->first== "GAIN") setGain(ci->second);
115  else if(ci->first== "MEMGAIN") setMemGain(ci->second);
116  else if(ci->first== "OFFSET_HIGH") setOffsetHigh(atoi(ci->second.c_str() ));
117  else if(ci->first== "OFFSET_LOW") setOffsetLow(atoi(ci->second.c_str() ));
118  else if(ci->first== "OFFSET_MID") setOffsetMid(atoi(ci->second.c_str() ));
119  else if(ci->first== "TRG_MODE") setTrgMode(ci->second );
120  else if(ci->first== "TRG_FILTER") setTrgFilter(ci->second );
121  else if(ci->first== "CLOCK") setClock(atoi(ci->second.c_str()) );
122  else if(ci->first== "BGO_SOURCE") setBGOSource(ci->second) ;
123  else if(ci->first== "TTS_MASK") setTTSMask(atoi(ci->second.c_str()) );
124  else if(ci->first== "DAQ_BCID_PRESET") setDAQBCIDPreset(atoi(ci->second.c_str() ));
125  else if(ci->first== "TRIG_BCID_PRESET") setTrgBCIDPreset(atoi(ci->second.c_str()) );
126  else if(ci->first== "BC0_COUNTER") setBC0Counter(atoi(ci->second.c_str() ));
127  else if(ci->first== "BC0_DELAY") setBC0Delay(atoi(ci->second.c_str() ));
128  else if(ci->first== "TE_DELAY") setTEDelay(atoi(ci->second.c_str() ));
129  else if(ci->first== "DELAY") setDelay(atoi(ci->second.c_str() ));
130 
131  }
132 
133 }
134 
136  throw(std::runtime_error)
137 {
138  this->checkConnection();
139  this->checkPrepare();
140 
141  try {
142 
143  // number 1 is the id
144  // m_writeStmt->setString(2, this->getConfigTag());
145  // m_writeStmt->setInt(3, this->getDaccal());
146  // m_writeStmt->setInt(4, this->getDelay());
147  // m_writeStmt->setString(5, this->getGain());
148  // m_writeStmt->setString(6, this->getMemGain());
149  // m_writeStmt->setInt(7, this->getOffsetHigh());
150  // m_writeStmt->setInt(8, this->getOffsetLow());
151  // m_writeStmt->setInt(9, this->getOffsetMid());
152  // m_writeStmt->setString(10, this->getTrgMode() );
153  // m_writeStmt->setString(11, this->getTrgFilter() );
154  // m_writeStmt->setInt( 12, this->getClock() );
155  // m_writeStmt->setString(13, this->getBGOSource() );
156  // m_writeStmt->setInt(14, this->getTTSMask() );
157  // m_writeStmt->setInt(15, this->getDAQBCIDPreset() );
158  // m_writeStmt->setInt(16, this->getTrgBCIDPreset() );
159  // m_writeStmt->setInt(17, this->getBC0Counter() );
160 
161  SET_STRING(m_writeStmt, 2, this->getConfigTag());
162  SET_INT (m_writeStmt, 3, this->getDaccal());
163  SET_INT (m_writeStmt, 4, this->getDelay());
164  SET_STRING(m_writeStmt, 5, this->getGain());
165  SET_STRING(m_writeStmt, 6, this->getMemGain());
166  SET_INT (m_writeStmt, 7, this->getOffsetHigh());
167  SET_INT (m_writeStmt, 8, this->getOffsetLow());
168  SET_INT (m_writeStmt, 9, this->getOffsetMid());
169  SET_STRING(m_writeStmt, 10, this->getTrgMode());
170  SET_STRING(m_writeStmt, 11, this->getTrgFilter());
171  SET_INT (m_writeStmt, 12, this->getClock());
172  SET_STRING(m_writeStmt, 13, this->getBGOSource());
173  SET_INT (m_writeStmt, 14, this->getTTSMask());
174  SET_INT (m_writeStmt, 15, this->getDAQBCIDPreset());
175  SET_INT (m_writeStmt, 16, this->getTrgBCIDPreset());
176  SET_INT (m_writeStmt, 17, this->getBC0Counter());
177  SET_INT (m_writeStmt, 18, this->getBC0Delay());
178  SET_INT (m_writeStmt, 19, this->getTEDelay());
179 
180  m_writeStmt->executeUpdate();
181 
182 
183  } catch (SQLException &e) {
184  throw(std::runtime_error("ODCCSConfig::writeDB(): "+e.getMessage()));
185  }
186  // Now get the ID
187  if (!this->fetchID()) {
188  throw(std::runtime_error("ODCCSConfig::writeDB: Failed to write"));
189  }
190 
191 
192 }
193 
194 
196  throw(std::runtime_error)
197 {
198  this->checkConnection();
199  result->clear();
200  if(result->getId()==0 && (result->getConfigTag()=="") ){
201  throw(std::runtime_error("ODCCSConfig::fetchData(): no Id defined for this ODCCSConfig "));
202  }
203 
204  try {
205 
206  m_readStmt->setSQL("SELECT * "
207  "FROM ECAL_CCS_CONFIGURATION "
208  " where ( CCS_configuration_id = :1 or CCS_tag=:2 )" );
209  m_readStmt->setInt(1, result->getId());
210  m_readStmt->setString(2, result->getConfigTag());
211  ResultSet* rset = m_readStmt->executeQuery();
212 
213  rset->next();
214 
215  // 1 is the id and 2 is the config tag
216 
217  result->setId(rset->getInt(1));
218  result->setConfigTag(rset->getString(2));
219 
220  result->setDaccal( rset->getInt(3) );
221  result->setDelay( rset->getInt(4) );
222  result->setGain( rset->getString(5) );
223  result->setMemGain( rset->getString(6) );
224  result->setOffsetHigh( rset->getInt(7) );
225  result->setOffsetLow( rset->getInt(8) );
226  result->setOffsetMid( rset->getInt(9) );
227  result->setTrgMode( rset->getString(10) );
228  result->setTrgFilter( rset->getString(11) );
229  result->setClock( rset->getInt(12) );
230  result->setBGOSource( rset->getString(13) );
231  result->setTTSMask( rset->getInt(14) );
232  result->setDAQBCIDPreset( rset->getInt(15) );
233  result->setTrgBCIDPreset( rset->getInt(16) );
234  result->setBC0Counter( rset->getInt(17) );
235 
236 
237  } catch (SQLException &e) {
238  throw(std::runtime_error("ODCCSConfig::fetchData(): "+e.getMessage()));
239  }
240 }
241 
242 int ODCCSConfig::fetchID() throw(std::runtime_error)
243 {
244  // Return from memory if available
245  if (m_ID!=0) {
246  return m_ID;
247  }
248 
249  this->checkConnection();
250 
251  try {
252  Statement* stmt = m_conn->createStatement();
253  stmt->setSQL("SELECT ccs_configuration_id FROM ecal_ccs_configuration "
254  "WHERE ccs_tag=:ccs_tag "
255  );
256 
257  stmt->setString(1, getConfigTag() );
258 
259  ResultSet* rset = stmt->executeQuery();
260 
261  if (rset->next()) {
262  m_ID = rset->getInt(1);
263  } else {
264  m_ID = 0;
265  }
266  m_conn->terminateStatement(stmt);
267  } catch (SQLException &e) {
268  throw(std::runtime_error("ODCCSConfig::fetchID: "+e.getMessage()));
269  }
270 
271  return m_ID;
272 }
void fetchData(ODCCSConfig *result)
Definition: ODCCSConfig.cc:195
#define NULL
Definition: scimark2.h:8
int fetchNextId()
Definition: ODCCSConfig.cc:58
#define MY_NULL
Definition: ODCCSConfig.cc:12
void writeDB()
Definition: ODCCSConfig.cc:135
#define SET_STRING(statement, paramNum, paramVal)
Definition: ODCCSConfig.cc:14
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:168
tuple result
Definition: query.py:137
oracle::occi::Statement Statement
Definition: IODConfig.h:23
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
void setParameters(std::map< std::string, std::string > my_keys_map)
Definition: ODCCSConfig.cc:104
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
void prepareWrite()
Definition: ODCCSConfig.cc:79
void clear()
Definition: ODCCSConfig.cc:31
#define SET_INT(statement, paramNum, paramVal)
Definition: ODCCSConfig.cc:13