10 #include "xgi/Utils.h"
11 #include "toolbox/string.h"
17 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabase.hh"
18 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseImplOracle.hh"
19 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseImplXMLFile.hh"
20 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationItemNotFoundException.hh"
24 using namespace oracle::occi;
59 if ( i!=std::string::npos )
61 database =
new ConfigurationDatabaseImplOracle();
62 database ->
connect( accessor );
66 database =
new ConfigurationDatabaseImplXMLFile();
67 database ->
connect( accessor );
78 accessor2 = _accessor2;
81 if ( i!=std::string::npos )
83 database2 =
new ConfigurationDatabaseImplOracle();
84 database2 ->
connect( accessor2 );
88 database2 =
new ConfigurationDatabaseImplXMLFile();
89 database2 ->
connect( accessor2 );
98 if ( database !=
NULL ) database -> disconnect();
99 if ( database2 !=
NULL ) database2 -> disconnect();
109 std::vector<unsigned int>
result;
111 hcal::ConfigurationDatabase::FPGASelection _fpga;
112 if ( topbottom == 0 ) _fpga = hcal::ConfigurationDatabase::Bottom;
116 std::cout <<
"topbottom out of range" << std::endl;
120 hcal::ConfigurationDatabase::LUTType _lt;
121 if ( luttype == 1 ) _lt = hcal::ConfigurationDatabase::LinearizerLUT;
122 else if ( luttype == 2 ) _lt = hcal::ConfigurationDatabase::CompressionLUT;
125 std::cout <<
"LUT type out of range" << std::endl;
129 hcal::ConfigurationDatabase::LUTId _lutid( crate, slot, _fpga, fiber, channel, _lt );
130 std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::LUT> testLUTs;
135 database -> getLUTs(tag, crate, slot, testLUTs);
136 }
catch (hcal::exception::ConfigurationItemNotFoundException&
e) {
137 std::cout <<
"Found nothing!" << std::endl;
139 std::cout <<
"Exception: " << e2.what() << std::endl;
142 result = testLUTs[_lutid];
151 std::vector<unsigned int>
result;
154 double _condition_data_set_id;
155 unsigned int _crate, _slot, _fiber, _channel;
156 hcal::ConfigurationDatabase::FPGASelection _fpga;
158 int side = _id . zside();
159 int etaAbs = _id . ietaAbs();
160 int phi = _id . iphi();
161 int depth = _id . depth();
162 std::string subdetector;
163 if ( _id . subdet() ==
HcalBarrel) subdetector =
"HB";
164 else if ( _id . subdet() ==
HcalEndcap) subdetector =
"HE";
165 else if ( _id . subdet() ==
HcalOuter) subdetector =
"HO";
166 else if ( _id . subdet() ==
HcalForward) subdetector =
"HF";
168 oracle::occi::Connection * _connection = database -> getConnection();
171 Statement* stmt = _connection -> createStatement();
172 std::string
query = (
"SELECT RECORD_ID, CRATE, HTR_SLOT, HTR_FPGA, HTR_FIBER, FIBER_CHANNEL ");
173 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V3 ";
174 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() );
177 ResultSet *rs = stmt->executeQuery(query.c_str());
179 _condition_data_set_id = 0.0;
182 double _cdsi = rs -> getDouble(1);
183 if ( _condition_data_set_id < _cdsi )
185 _condition_data_set_id = _cdsi;
188 std::string fpga_ = rs -> getString(4);
190 else _fpga = hcal::ConfigurationDatabase::Bottom;
192 _channel = rs ->
getInt(6);
194 int topbottom, luttype;
197 if ( _lt == hcal::ConfigurationDatabase::LinearizerLUT ) luttype = 1;
200 result = getOnlineLUT( tag, _crate, _slot, topbottom, _fiber, _channel, luttype );
204 _connection -> terminateStatement(stmt);
206 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
214 std::vector<unsigned int>
result;
216 if ( database && database2 ){
220 double _condition_data_set_id;
221 unsigned int _crate, _slot, _fiber, _channel;
222 hcal::ConfigurationDatabase::FPGASelection _fpga;
224 int side = _id . zside();
225 int etaAbs = _id . ietaAbs();
226 int phi = _id . iphi();
227 int depth = _id . depth();
228 std::string subdetector;
229 if ( _id . subdet() ==
HcalBarrel) subdetector =
"HB";
230 else if ( _id . subdet() ==
HcalEndcap) subdetector =
"HE";
231 else if ( _id . subdet() ==
HcalOuter) subdetector =
"HO";
232 else if ( _id . subdet() ==
HcalForward) subdetector =
"HF";
234 oracle::occi::Connection * _connection = database2 -> getConnection();
237 Statement* stmt = _connection -> createStatement();
238 std::string
query = (
"SELECT RECORD_ID, CRATE, HTR_SLOT, HTR_FPGA, HTR_FIBER, FIBER_CHANNEL ");
239 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V3 ";
240 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() );
243 ResultSet *rs = stmt->executeQuery(query.c_str());
245 _condition_data_set_id = 0.0;
248 double _cdsi = rs -> getDouble(1);
249 if ( _condition_data_set_id < _cdsi )
251 _condition_data_set_id = _cdsi;
254 std::string fpga_ = rs -> getString(4);
256 else _fpga = hcal::ConfigurationDatabase::Bottom;
258 _channel = rs ->
getInt(6);
261 int topbottom, luttype;
264 if ( _lt == hcal::ConfigurationDatabase::LinearizerLUT ) luttype = 1;
266 result = getOnlineLUT( tag, _crate, _slot, topbottom, _fiber, _channel, luttype );
270 _connection -> terminateStatement(stmt);
273 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
277 std::cout <<
"Either the XML file with LUTs or the database with LMap are not defined" << std::endl;
285 return database -> getConnection();
289 return database -> getEnvironment();
297 Stream *instream = clob.getStream (1,0);
298 unsigned int size = clob.length();
299 char *cbuffer =
new char[
size];
300 memset (cbuffer, 0, size);
301 instream->readBuffer (cbuffer, size);
302 std::string str(cbuffer,size);
int getInt(ResultSet *rset, int ipar)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
oracle::occi::SQLException SQLException
static const std::string Top
oracle::occi::Environment * getEnvironment(void)
oracle::occi::Connection * getConnection(void)
std::string toString(const std::pair< T, T > &aT)
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)
oracle::occi::ResultSet ResultSet
void setAccessor(std::string _accessor)
std::vector< unsigned int > getOnlineLUTFromXML(std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt=hcal::ConfigurationDatabase::LinearizerLUT)
tuple size
Write out results.
static XMLProcessor * getInstance()
std::string clobToString(oracle::occi::Clob)