test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HCALConfigDB.cc
Go to the documentation of this file.
1 
2 //
3 // Gena Kukartsev (Brown), Feb 1, 2008
4 // $Id:
5 //
6 
7 #include <iostream>
8 #include <string.h>
9 
10 #ifdef HAVE_XDAQ
11 #include <toolbox/string.h>
12 #else
13 #include "CaloOnlineTools/HcalOnlineDb/interface/xdaq_compat.h" // Replaces toolbox::toString
14 #endif
15 
16 
18 
21 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabase.hh"
22 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseImplOracle.hh"
23 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseImplXMLFile.hh"
24 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationItemNotFoundException.hh"
26 
27 using namespace std;
28 using namespace oracle::occi;
29 using namespace hcal;
30 
32 {
33  database = 0;
34  database2 = 0;
35 }
36 
38 {
39  database = 0;
40  database2 = 0;
41  accessor = _accessor;
42 }
43 
44 
46 {
47  delete database;
48  delete database2;
49 }
50 
51 
53 {
54  accessor = _accessor;
55 }
56 
58 {
59 
60  accessor = _accessor;
61 
62  std::string::size_type i = accessor . find( "occi://" );
63  if ( i!=std::string::npos )
64  {
65  database = new ConfigurationDatabaseImplOracle();
66  database -> connect( accessor );
67  }
68  else
69  {
70  database = new ConfigurationDatabaseImplXMLFile();
71  database -> connect( accessor );
72  }
73 }
74 
75 
76 
77 void HCALConfigDB::connect( std::string _accessor1, std::string _accessor2 )
78 {
79 
80  connect (_accessor1 );
81 
82  accessor2 = _accessor2;
83 
84  std::string::size_type i = accessor2 . find( "occi://" );
85  if ( i!=std::string::npos )
86  {
87  database2 = new ConfigurationDatabaseImplOracle();
88  database2 -> connect( accessor2 );
89  }
90  else
91  {
92  database2 = new ConfigurationDatabaseImplXMLFile();
93  database2 -> connect( accessor2 );
94  }
95 }
96 
97 
98 
99 
101 {
102  if ( database != NULL ) database -> disconnect();
103  if ( database2 != NULL ) database2 -> disconnect();
104 }
105 
106 
107 
108 std::vector<unsigned int> HCALConfigDB::getOnlineLUT( std::string tag, int crate, int slot, int topbottom, int fiber, int channel, int luttype )
109 {
110 
111  //connect( accessor );
112 
113  std::vector<unsigned int> result;
114 
115  hcal::ConfigurationDatabase::FPGASelection _fpga;
116  if ( topbottom == 0 ) _fpga = hcal::ConfigurationDatabase::Bottom;
117  else if ( topbottom == 1 ) _fpga = hcal::ConfigurationDatabase::Top;
118  else
119  {
120  std::cout << "topbottom out of range" << std::endl;
121  exit(-1);
122  }
123 
124  hcal::ConfigurationDatabase::LUTType _lt;
125  if ( luttype == 1 ) _lt = hcal::ConfigurationDatabase::LinearizerLUT;
126  else if ( luttype == 2 ) _lt = hcal::ConfigurationDatabase::CompressionLUT;
127  else
128  {
129  std::cout << "LUT type out of range" << std::endl;
130  exit(-1);
131  }
132 
133  hcal::ConfigurationDatabase::LUTId _lutid( crate, slot, _fpga, fiber, channel, _lt );
134  std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::LUT> testLUTs;
135 
137 
138  try {
139  database -> getLUTs(tag, crate, slot, testLUTs);
140  } catch (hcal::exception::ConfigurationItemNotFoundException& e) {
141  std::cout << "Found nothing!" << std::endl;
142  } catch (hcal::exception::Exception& e2) {
143  std::cout << "Exception: " << e2.what() << std::endl;
144  }
145 
146  result = testLUTs[_lutid];
147 
148  //database -> disconnect();
149 
150  return result;
151 }
152 
153 std::vector<unsigned int> HCALConfigDB::getOnlineLUT( std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt )
154 {
155  std::vector<unsigned int> result;
156  HcalDetId _id( _rawid );
157 
158  double _condition_data_set_id;
159  unsigned int _crate, _slot, _fiber, _channel;
160  hcal::ConfigurationDatabase::FPGASelection _fpga;
161 
162  int side = _id . zside();
163  int etaAbs = _id . ietaAbs();
164  int phi = _id . iphi();
165  int depth = _id . depth();
167  if ( _id . subdet() == HcalBarrel) subdetector = "HB";
168  else if ( _id . subdet() == HcalEndcap) subdetector = "HE";
169  else if ( _id . subdet() == HcalOuter) subdetector = "HO";
170  else if ( _id . subdet() == HcalForward) subdetector = "HF";
171 
172  oracle::occi::Connection * _connection = database -> getConnection();
173 
174  try {
175  Statement* stmt = _connection -> createStatement();
176  std::string query = ("SELECT RECORD_ID, CRATE, HTR_SLOT, HTR_FPGA, HTR_FIBER, FIBER_CHANNEL ");
177  query += " FROM CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V3 ";
178  query += toolbox::toString(" WHERE SIDE=%d AND ETA=%d AND PHI=%d AND DEPTH=%d AND SUBDETECTOR='%s'", side, etaAbs, phi, depth, subdetector . c_str() );
179 
180  //SELECT
181  ResultSet *rs = stmt->executeQuery(query.c_str());
182 
183  _condition_data_set_id = 0.0;
184 
185  while (rs->next()) {
186  double _cdsi = rs -> getDouble(1);
187  if ( _condition_data_set_id < _cdsi )
188  {
189  _condition_data_set_id = _cdsi;
190  _crate = rs -> getInt(2);
191  _slot = rs -> getInt(3);
192  std::string fpga_ = rs -> getString(4);
193  if ( fpga_ == "top" ) _fpga = hcal::ConfigurationDatabase::Top;
194  else _fpga = hcal::ConfigurationDatabase::Bottom;
195  _fiber = rs -> getInt(5);
196  _channel = rs -> getInt(6);
197 
198  int topbottom, luttype;
199  if ( _fpga == hcal::ConfigurationDatabase::Top ) topbottom = 1;
200  else topbottom = 0;
201  if ( _lt == hcal::ConfigurationDatabase::LinearizerLUT ) luttype = 1;
202  else luttype = 2;
203 
204  result = getOnlineLUT( tag, _crate, _slot, topbottom, _fiber, _channel, luttype );
205  }
206  }
207  //Always terminate statement
208  _connection -> terminateStatement(stmt);
209  } catch (SQLException& e) {
210  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()));
211  }
212  return result;
213 }
214 
215 
216 std::vector<unsigned int> HCALConfigDB::getOnlineLUTFromXML( std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt ){
217 
218  std::vector<unsigned int> result;
219 
220  if ( database && database2 ){
221 
222  HcalDetId _id( _rawid );
223 
224  double _condition_data_set_id;
225  unsigned int _crate, _slot, _fiber, _channel;
226  hcal::ConfigurationDatabase::FPGASelection _fpga;
227 
228  int side = _id . zside();
229  int etaAbs = _id . ietaAbs();
230  int phi = _id . iphi();
231  int depth = _id . depth();
233  if ( _id . subdet() == HcalBarrel) subdetector = "HB";
234  else if ( _id . subdet() == HcalEndcap) subdetector = "HE";
235  else if ( _id . subdet() == HcalOuter) subdetector = "HO";
236  else if ( _id . subdet() == HcalForward) subdetector = "HF";
237 
238  oracle::occi::Connection * _connection = database2 -> getConnection();
239 
240  try {
241  Statement* stmt = _connection -> createStatement();
242  std::string query = ("SELECT RECORD_ID, CRATE, HTR_SLOT, HTR_FPGA, HTR_FIBER, FIBER_CHANNEL ");
243  query += " FROM CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V3 ";
244  query += toolbox::toString(" WHERE SIDE=%d AND ETA=%d AND PHI=%d AND DEPTH=%d AND SUBDETECTOR='%s'", side, etaAbs, phi, depth, subdetector . c_str() );
245 
246  //SELECT
247  ResultSet *rs = stmt->executeQuery(query.c_str());
248 
249  _condition_data_set_id = 0.0;
250 
251  while (rs->next()) {
252  double _cdsi = rs -> getDouble(1);
253  if ( _condition_data_set_id < _cdsi )
254  {
255  _condition_data_set_id = _cdsi;
256  _crate = rs -> getInt(2);
257  _slot = rs -> getInt(3);
258  std::string fpga_ = rs -> getString(4);
259  if ( fpga_ == "top" ) _fpga = hcal::ConfigurationDatabase::Top;
260  else _fpga = hcal::ConfigurationDatabase::Bottom;
261  _fiber = rs -> getInt(5);
262  _channel = rs -> getInt(6);
263 
264  //
265  int topbottom, luttype;
266  if ( _fpga == hcal::ConfigurationDatabase::Top ) topbottom = 1;
267  else topbottom = 0;
268  if ( _lt == hcal::ConfigurationDatabase::LinearizerLUT ) luttype = 1;
269  else luttype = 2;
270  result = getOnlineLUT( tag, _crate, _slot, topbottom, _fiber, _channel, luttype );
271  }
272  }
273  //Always terminate statement
274  _connection -> terminateStatement(stmt);
275 
276  } catch (SQLException& e) {
277  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()));
278  }
279  }
280  else{
281  std::cout << "Either the XML file with LUTs or the database with LMap are not defined" << std::endl;
282  }
283 
284  return result;
285 }
286 
287 
288 oracle::occi::Connection * HCALConfigDB::getConnection( void ){
289  return database -> getConnection();
290 }
291 
292 oracle::occi::Environment * HCALConfigDB::getEnvironment( void ){
293  return database -> getEnvironment();
294 }
295 
296 
297 
298 //Utility function that cnverts oracle::occi::Clob to std::string
299 string HCALConfigDB::clobToString(const oracle::occi::Clob& _clob){
300  oracle::occi::Clob clob = _clob;
301  Stream *instream = clob.getStream (1,0);
302  unsigned int size = clob.length();
303  char *cbuffer = new char[size];
304  memset (cbuffer, 0, size);
305  instream->readBuffer (cbuffer, size);
306  std::string str(cbuffer,size);
307  return str;
308 }
int i
Definition: DBlmapReader.cc:9
void disconnect(void)
TString subdetector
#define NULL
Definition: scimark2.h:8
int zside(DetId const &)
int getInt(ResultSet *rset, int ipar)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
uint16_t size_type
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
tuple result
Definition: mps_fire.py:83
static const std::string Top
oracle::occi::Environment * getEnvironment(void)
oracle::occi::Connection * getConnection(void)
std::string toString(const char *format,...)
Definition: xdaq_compat.cc:4
std::vector< unsigned int > getOnlineLUT(std::string tag, int crate, int slot, int topbottom, int fiber, int channel, int luttype)
void connect(std::string _accessor)
Definition: HCALConfigDB.cc:57
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
Float e2
Definition: deltaR.h:21
void setAccessor(std::string _accessor)
Definition: HCALConfigDB.cc:52
tuple query
Definition: o2o.py:269
std::vector< unsigned int > getOnlineLUTFromXML(std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt=hcal::ConfigurationDatabase::LinearizerLUT)
tuple cout
Definition: gather_cfg.py:145
std::string clobToString(const oracle::occi::Clob &)
tuple size
Write out results.
static XMLProcessor * getInstance()
Definition: XMLProcessor.h:145