1 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseImplXMLFile.hh"
2 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationItemNotFoundException.hh"
6 #include <toolbox/string.h>
11 DECLARE_PLUGGABLE(hcal::ConfigurationDatabaseImpl, ConfigurationDatabaseImplXMLFile)
13 ConfigurationDatabaseImplXMLFile::ConfigurationDatabaseImplXMLFile() {}
14 ConfigurationDatabaseImplXMLFile::~ConfigurationDatabaseImplXMLFile() {}
15 bool ConfigurationDatabaseImplXMLFile::canHandleMethod(
const std::string& method)
const {
return method ==
"xmlfile"; }
21 if (i != std::string::npos)
22 theFile.erase(0, i + 2);
23 gzFile
f = gzopen(theFile.c_str(),
"rb");
26 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Unable to open file " + theFile);
29 while ((c = gzgetc(f)) != EOF)
30 m_buffer += (
unsigned char)c;
35 while ((i = m_buffer.find(
"<CFGBrick>", j)) != std::string::npos) {
36 j = m_buffer.find(
"</CFGBrick>", i) + strlen(
"</CFGBrick>");
37 if (j == std::string::npos)
40 std::map<std::string, std::string>
params = extractParams(i, j);
43 std::pair<int, int> ptrs(i, j);
44 m_lookup.insert(std::pair<
std::string, std::pair<int, int> >(key, ptrs));
48 std::string ConfigurationDatabaseImplXMLFile::createKey(
const std::map<std::string, std::string>& params) {
50 if (params.find(
"PATTERN_SPEC_NAME") != params.end()) {
51 retval = params.find(
"TAG")->second +
":" + params.find(
"CRATE")->second +
":" + params.find(
"SLOT")->second +
":" +
52 params.find(
"TOPBOTTOM")->second +
":" + params.find(
"FIBER")->second;
53 }
else if (params.find(
"LUT_TYPE") != params.end()) {
54 retval = params.find(
"TAG")->second +
":" + params.find(
"CRATE")->second +
":" + params.find(
"SLOT")->second +
":" +
55 params.find(
"TOPBOTTOM")->second +
":" + params.find(
"LUT_TYPE")->second;
56 if (params.find(
"FIBER") != params.end())
57 retval +=
":" + params.find(
"FIBER")->second +
":" + params.find(
"FIBERCHAN")->second;
58 if (params.find(
"SLB") != params.end())
59 retval +=
":" + params.find(
"SLB")->second +
":" + params.find(
"SLBCHAN")->second;
60 }
else if (params.find(
"BOARD") != params.end()) {
61 int ver = strtol(params.find(
"VERSION")->second.c_str(),
nullptr, 0);
63 }
else if (params.find(
"ZS_TYPE") != params.end()) {
64 retval = params.find(
"TAG")->second +
":" + params.find(
"CRATE")->second +
":" + params.find(
"SLOT")->second +
":" +
65 params.find(
"TOPBOTTOM")->second;
71 std::map<std::string, std::string> ConfigurationDatabaseImplXMLFile::extractParams(
int beg,
int end) {
72 std::map<std::string, std::string> pval;
76 while ((i = m_buffer.find(
"<Parameter", l)) != std::string::npos && i < (
unsigned int)
end) {
77 j = m_buffer.find(
"name=", i);
79 i = m_buffer.find(separator, j + 6);
80 name = m_buffer.substr(j + 6, i - (j + 6));
81 if (name ==
"CREATIONTAG")
83 j = m_buffer.find(
'>', j);
84 i = m_buffer.find(
"</", j);
85 val = m_buffer.substr(j + 1, i - j - 1);
86 pval.insert(std::pair<std::string, std::string>(name, val));
93 void ConfigurationDatabaseImplXMLFile::disconnect() {
98 std::map<std::string, std::string> ConfigurationDatabaseImplXMLFile::parseWhere(
const std::string& where) {
100 std::map<std::string, std::string> itis;
102 while ((i = where.find(
'=', j)) != std::string::npos) {
103 k = where.rfind(
' ', i);
104 k2 = where.rfind(
'(', i);
105 if (k2 != std::string::npos && k2 >
k)
107 if (
k == std::string::npos)
112 if (where[i + 1] ==
'\'' || where[i + 1] ==
'\"') {
113 j = where.find(where[i + 1], i + 2);
114 value = where.substr(i + 2, j - i - 2);
116 j = where.find(
' ', i);
117 k = where.find(
')', i);
118 if (
k != std::string::npos &&
k < j)
120 value = where.substr(i + 1, j - i - 1);
122 itis.insert(std::pair<std::string, std::string>(key,
value));
142 unsigned int ConfigurationDatabaseImplXMLFile::getFirmwareChecksum(
const std::string& board,
143 unsigned int version) noexcept(
false) {
144 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Unsupported");
147 void ConfigurationDatabaseImplXMLFile::getFirmwareMCS(
const std::string& board,
149 std::vector<std::string>& mcsLines) noexcept(
false) {
152 std::map<std::string, std::pair<int, int> >::iterator j = m_lookup.find(key);
153 if (j == m_lookup.end()) {
154 XCEPT_RAISE(hcal::exception::ConfigurationItemNotFoundException,
"");
157 data += m_buffer.substr(j->second.first, j->second.second - j->second.first);
159 std::map<std::string, std::string>
params;
161 m_parser.parse(data, params, mcsLines, encoding);
164 void ConfigurationDatabaseImplXMLFile::getLUTChecksums(
166 std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::MD5Fingerprint>&
167 checksums) noexcept(
false) {
168 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Unsupported");
171 void ConfigurationDatabaseImplXMLFile::getLUTs(
175 std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::LUT>& LUTs) noexcept(
false) {
178 for (
int tb = 0; tb <= 1; tb++)
179 for (
int fiber = 1; fiber <= 8; fiber++)
180 for (
int fiberChan = 0; fiberChan <= 2; fiberChan++) {
184 toolbox::toString(
"%s:%d:%d:%d:%d:%d:%d",
tag.c_str(), crate, slot, tb, lut_type, fiber, fiberChan);
185 std::map<std::string, std::pair<int, int> >::iterator j = m_lookup.find(key);
186 if (j == m_lookup.end())
189 data += m_buffer.substr(j->second.first, j->second.second - j->second.first);
191 std::map<std::string, std::string>
params;
192 std::vector<std::string>
values;
194 m_parser.parse(data, params, values, encoding);
196 hcal::ConfigurationDatabase::LUTId
id(crate,
198 (hcal::ConfigurationDatabase::FPGASelection)tb,
201 (hcal::ConfigurationDatabase::LUTType)lut_type);
203 lut.reserve(values.size());
206 if (encoding ==
"hex")
208 else if (encoding ==
"dec")
212 for (
unsigned int j = 0; j < values.size(); j++)
213 lut.push_back(strtol(values[j].c_str(),
nullptr, strtol_base));
215 for (
int tb = 0; tb <= 1; tb++)
223 std::map<std::string, std::pair<int, int> >::iterator j = m_lookup.find(key);
224 if (j == m_lookup.end())
227 data += m_buffer.substr(j->second.first, j->second.second - j->second.first);
229 std::map<std::string, std::string>
params;
230 std::vector<std::string>
values;
232 m_parser.parse(data, params, values, encoding);
234 hcal::ConfigurationDatabase::LUTId
id(crate,
236 (hcal::ConfigurationDatabase::FPGASelection)tb,
239 (hcal::ConfigurationDatabase::LUTType)lut_type);
241 lut.reserve(values.size());
244 if (encoding ==
"hex")
246 else if (encoding ==
"dec")
250 for (
unsigned int j = 0; j < values.size(); j++)
251 lut.push_back(strtol(values[j].c_str(),
nullptr, strtol_base));
255 void ConfigurationDatabaseImplXMLFile::getZSThresholds(
259 std::map<hcal::ConfigurationDatabase::ZSChannelId, int>&
thresholds) noexcept(
false) {
261 for (
int tb = 0; tb <= 1; tb++) {
263 std::map<std::string, std::pair<int, int> >::iterator j = m_lookup.find(key);
264 if (j == m_lookup.end())
267 data += m_buffer.substr(j->second.first, j->second.second - j->second.first);
269 std::map<std::string, std::string>
params;
270 std::vector<std::string>
values;
272 m_parser.parse(data, params, values, encoding);
274 if (values.size() != 24) {
275 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
276 ::
toolbox::toString(
"Must have 24 items in ZS list. Saw %d for %s", values.size(), key.c_str()));
278 for (
int fiber = 1; fiber <= 8; fiber++)
279 for (
int fc = 0; fc < 3; fc++) {
280 hcal::ConfigurationDatabase::ZSChannelId
id(
281 crate, slot, (hcal::ConfigurationDatabase::FPGASelection)tb, fiber, fc);
284 if (encoding ==
"hex")
286 else if (encoding ==
"dec")
289 thresholds[
id] = strtol(values[(fiber - 1) * 3 + fc].c_str(),
nullptr, strtol_base);
294 void ConfigurationDatabaseImplXMLFile::getPatterns(
298 std::map<hcal::ConfigurationDatabase::PatternId, hcal::ConfigurationDatabase::HTRPattern>& patterns) noexcept(
false) {
300 for (
int tb = 0; tb <= 1; tb++)
301 for (
int fiber = 1; fiber <= 8; fiber++) {
303 std::map<std::string, std::pair<int, int> >::iterator j = m_lookup.find(key);
304 if (j == m_lookup.end())
307 data += m_buffer.substr(j->second.first, j->second.second - j->second.first);
309 std::map<std::string, std::string>
params;
310 std::vector<std::string>
values;
312 m_parser.parse(data, params, values, encoding);
314 hcal::ConfigurationDatabase::PatternId
id(crate, slot, (hcal::ConfigurationDatabase::FPGASelection)tb, fiber);
315 hcal::ConfigurationDatabase::HTRPattern& lut = patterns[
id];
316 lut.reserve(values.size());
319 if (encoding ==
"hex")
321 else if (encoding ==
"dec")
325 for (
unsigned int j = 0; j < values.size(); j++)
326 lut.push_back(strtol(values[j].c_str(),
nullptr, strtol_base));
const edm::EventSetup & c
uint16_t *__restrict__ id
static int slb(const HcalTriggerPrimitiveSample &theSample)
static int slbChan(const HcalTriggerPrimitiveSample &theSample)
tuple key
prepare the HTCondor submission files and eventually submit them
char data[epos_bytes_allocation]
static std::string const separator(":")
std::vector< unsigned short int > LUT