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() {
15 ConfigurationDatabaseImplXMLFile::~ConfigurationDatabaseImplXMLFile() {
17 bool ConfigurationDatabaseImplXMLFile::canHandleMethod(
const std::string&
method)
const {
return method==
"xmlfile"; }
23 if (i!=std::string::npos) theFile.erase(0,i+2);
24 gzFile
f=gzopen(theFile.c_str(),
"rb");
27 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Unable to open file "+theFile);
30 while ((c=gzgetc(f))!=EOF) 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)
break;
39 std::map<std::string,std::string> params=extractParams(i,j);
42 std::pair<int,int> ptrs(i,j);
43 m_lookup.insert(std::pair<
std::string, std::pair<int,int> >(key,ptrs));
47 std::string ConfigurationDatabaseImplXMLFile::createKey(
const std::map<std::string,std::string>& params) {
49 if (params.find(
"PATTERN_SPEC_NAME")!=params.end()) {
50 retval=params.find(
"TAG")->second+
":"+
51 params.find(
"CRATE")->second+
":"+
52 params.find(
"SLOT")->second+
":"+
53 params.find(
"TOPBOTTOM")->second+
":"+
54 params.find(
"FIBER")->second;
55 }
else if (params.find(
"LUT_TYPE")!=params.end()) {
56 retval=params.find(
"TAG")->second+
":"+
57 params.find(
"CRATE")->second+
":"+
58 params.find(
"SLOT")->second+
":"+
59 params.find(
"TOPBOTTOM")->second+
":"+
60 params.find(
"LUT_TYPE")->second;
61 if (params.find(
"FIBER")!=params.end())
62 retval+=
":"+params.find(
"FIBER")->second+
":" +
63 params.find(
"FIBERCHAN")->second;
64 if (params.find(
"SLB")!=params.end())
65 retval+=
":"+params.find(
"SLB")->second+
":" +
66 params.find(
"SLBCHAN")->second;
67 }
else if (params.find(
"BOARD")!=params.end()) {
68 int ver=strtol(params.find(
"VERSION")->second.c_str(),0,0);
69 retval=params.find(
"BOARD")->second+
":"+
71 }
else if (params.find(
"ZS_TYPE")!=params.end()) {
72 retval=params.find(
"TAG")->second+
":"+
73 params.find(
"CRATE")->second+
":"+
74 params.find(
"SLOT")->second+
":"+
75 params.find(
"TOPBOTTOM")->second;
81 std::map<std::string, std::string> ConfigurationDatabaseImplXMLFile::extractParams(
int beg,
int end) {
82 std::map<std::string,std::string> pval;
86 while ((i=m_buffer.find(
"<Parameter",l))!=std::string::npos && i<(
unsigned int)
end) {
87 j=m_buffer.find(
"name=",i);
88 char separator=m_buffer[j+5];
89 i=m_buffer.find(separator,j+6);
90 name=m_buffer.substr(j+6,i-(j+6));
91 if (name==
"CREATIONTAG") name=
"TAG";
92 j=m_buffer.find(
'>',j);
93 i=m_buffer.find(
"</",j);
94 val=m_buffer.substr(j+1,i-j-1);
95 pval.insert(std::pair<std::string,std::string>(name,val));
102 void ConfigurationDatabaseImplXMLFile::disconnect() {
107 std::map<std::string, std::string> ConfigurationDatabaseImplXMLFile::parseWhere(
const std::string& where) {
109 std::map<std::string,std::string> itis;
111 while ((i=where.find(
'=',j))!=std::string::npos) {
112 k=where.rfind(
' ',i);
113 k2=where.rfind(
'(',i);
114 if (k2!=std::string::npos && k2>
k)
k=
k2;
115 if (
k==std::string::npos)
k=0;
118 if (where[i+1]==
'\'' || where[i+1]==
'\"') {
119 j=where.find(where[i+1],i+2);
120 value=where.substr(i+2,j-i-2);
124 if (
k!=std::string::npos &&
k<j) j=
k;
125 value=where.substr(i+1,j-i-1);
127 itis.insert(std::pair<std::string,std::string>(key,
value));
147 unsigned int ConfigurationDatabaseImplXMLFile::getFirmwareChecksum(
const std::string& board,
unsigned int version)
throw (hcal::exception::ConfigurationDatabaseException) {
148 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Unsupported");
151 void ConfigurationDatabaseImplXMLFile::getFirmwareMCS(
const std::string& board,
unsigned int version, std::vector<std::string>& mcsLines)
throw (hcal::exception::ConfigurationDatabaseException) {
155 std::map<std::string, std::pair<int,int> >::iterator j=m_lookup.find(key);
156 if (j==m_lookup.end()) {
157 XCEPT_RAISE(hcal::exception::ConfigurationItemNotFoundException,
"");
160 data+=m_buffer.substr(j->second.first,j->second.second-j->second.first);
162 std::map<std::string, std::string> params;
164 m_parser.parse(data.c_str(),params,mcsLines,encoding);
168 void ConfigurationDatabaseImplXMLFile::getLUTChecksums(
const std::string&
tag, std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::MD5Fingerprint>& checksums)
throw (hcal::exception::ConfigurationDatabaseException) {
169 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Unsupported");
172 void ConfigurationDatabaseImplXMLFile::getLUTs(
const std::string&
tag,
int crate,
int slot, std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::LUT >& LUTs)
throw (hcal::exception::ConfigurationDatabaseException) {
175 for (
int tb=0; tb<=1; tb++)
176 for (
int fiber=1; fiber<=8; fiber++)
177 for (
int fiberChan=0; fiberChan<=2; fiberChan++) {
181 tag.c_str(), crate, slot, tb, lut_type, fiber, fiberChan);
182 std::map<std::string, std::pair<int,int> >::iterator j=m_lookup.find(key);
183 if (j==m_lookup.end())
continue;
185 data+=m_buffer.substr(j->second.first,j->second.second-j->second.first);
187 std::map<std::string, std::string> params;
188 std::vector<std::string>
values;
190 m_parser.parse(data.c_str(),params,
values,encoding);
192 hcal::ConfigurationDatabase::LUTId id(crate,slot,(hcal::ConfigurationDatabase::FPGASelection)tb,fiber,fiberChan,(hcal::ConfigurationDatabase::LUTType)lut_type);
194 lut.reserve(values.size());
197 if (encoding==
"hex") strtol_base=16;
198 else if (encoding==
"dec") strtol_base=10;
201 for (
unsigned int j=0; j<values.size(); j++)
202 lut.push_back(strtol(values[j].c_str(),0,strtol_base));
204 for (
int tb=0; tb<=1; tb++)
212 std::map<std::string, std::pair<int,int> >::iterator j=m_lookup.find(key);
213 if (j==m_lookup.end())
continue;
215 data+=m_buffer.substr(j->second.first,j->second.second-j->second.first);
217 std::map<std::string, std::string> params;
218 std::vector<std::string>
values;
220 m_parser.parse(data.c_str(),params,
values,encoding);
222 hcal::ConfigurationDatabase::LUTId id(crate,slot,(hcal::ConfigurationDatabase::FPGASelection)tb,slb,
slbChan,(hcal::ConfigurationDatabase::LUTType)lut_type);
224 lut.reserve(values.size());
227 if (encoding==
"hex") strtol_base=16;
228 else if (encoding==
"dec") strtol_base=10;
231 for (
unsigned int j=0; j<values.size(); j++)
232 lut.push_back(strtol(values[j].c_str(),0,strtol_base));
236 void ConfigurationDatabaseImplXMLFile::getZSThresholds(
const std::string&
tag,
int crate,
int slot, std::map<hcal::ConfigurationDatabase::ZSChannelId, int>& thresholds)
throw (hcal::exception::ConfigurationDatabaseException) {
238 for (
int tb=0; tb<=1; tb++) {
241 tag.c_str(), crate, slot, tb);
242 std::map<std::string, std::pair<int,int> >::iterator j=m_lookup.find(key);
243 if (j==m_lookup.end())
continue;
245 data+=m_buffer.substr(j->second.first,j->second.second-j->second.first);
247 std::map<std::string, std::string> params;
248 std::vector<std::string>
values;
250 m_parser.parse(data.c_str(),params,
values,encoding);
252 if (values.size()!=24) {
253 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Must have 24 items in ZS list. Saw %d for %s",values.size(),key.c_str()));
255 for (
int fiber=1; fiber<=8; fiber++)
256 for (
int fc=0;
fc<3;
fc++) {
257 hcal::ConfigurationDatabase::ZSChannelId id(crate,slot,(hcal::ConfigurationDatabase::FPGASelection)tb,fiber,
fc);
260 if (encoding==
"hex") strtol_base=16;
261 else if (encoding==
"dec") strtol_base=10;
263 thresholds[id]=strtol(values[(fiber-1)*3+
fc].c_str(),0,strtol_base);
268 void ConfigurationDatabaseImplXMLFile::getPatterns(
const std::string&
tag,
int crate,
int slot, std::map<hcal::ConfigurationDatabase::PatternId, hcal::ConfigurationDatabase::HTRPattern >& patterns)
throw (hcal::exception::ConfigurationDatabaseException) {
270 for (
int tb=0; tb<=1; tb++)
271 for (
int fiber=1; fiber<=8; fiber++) {
273 tag.c_str(), crate, slot, tb, fiber);
274 std::map<std::string, std::pair<int,int> >::iterator j=m_lookup.find(key);
275 if (j==m_lookup.end())
continue;
277 data+=m_buffer.substr(j->second.first,j->second.second-j->second.first);
279 std::map<std::string, std::string> params;
280 std::vector<std::string>
values;
282 m_parser.parse(data.c_str(),params,
values,encoding);
284 hcal::ConfigurationDatabase::PatternId id(crate,slot,(hcal::ConfigurationDatabase::FPGASelection)tb,fiber);
285 hcal::ConfigurationDatabase::HTRPattern& lut=patterns[id];
286 lut.reserve(values.size());
289 if (encoding==
"hex") strtol_base=16;
290 else if (encoding==
"dec") strtol_base=10;
293 for (
unsigned int j=0; j<values.size(); j++)
294 lut.push_back(strtol(values[j].c_str(),0,strtol_base));
static int slb(const HcalTriggerPrimitiveSample &theSample)
static int slbChan(const HcalTriggerPrimitiveSample &theSample)
char data[epos_bytes_allocation]
std::vector< unsigned short int > LUT