1 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseStandardXMLParser.hh" 2 #include <xercesc/sax2/SAX2XMLReader.hpp> 3 #include <xercesc/sax2/XMLReaderFactory.hpp> 4 #include "xercesc/sax2/DefaultHandler.hpp" 5 #include "xercesc/sax2/Attributes.hpp" 10 ConfigurationDatabaseStandardXMLParser::ConfigurationDatabaseStandardXMLParser() : m_parser(nullptr) {}
11 #include <xercesc/framework/MemBufInputSource.hpp> 44 xc_Data = XMLString::transcode(
"Data");
45 xc_name = XMLString::transcode(
"name");
46 xc_type = XMLString::transcode(
"type");
49 xc_header[0] = XMLString::transcode(
"CFGBrick");
50 xc_header[1] = XMLString::transcode(
"LUT");
51 xc_header[2] = XMLString::transcode(
"Pattern");
65 const XMLCh *
const localname,
66 const XMLCh *
const qname,
67 const Attributes &attrs)
override;
68 void endElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname)
override;
69 void characters(
const XMLCh *
const chars,
const XMLSize_t length)
override;
76 char *tool = XMLString::transcode(
val);
87 std::list<ConfigurationDatabaseStandardXMLParser::Item> &
m_items;
95 if (!XMLString::compareIString(localname,
xc_header[
i]))
102 const XMLCh *
const localname,
103 const XMLCh *
const qname,
104 const Attributes &attrs) {
113 }
else if (!XMLString::compareIString(localname,
xc_Parameter)) {
123 }
else if (!XMLString::compareIString(localname,
xc_Data)) {
137 for (
unsigned int jj = 0;
jj < attrs.getLength();
jj++) {
138 if (!XMLString::compareIString(
xc_elements, attrs.getValue(
jj)) ||
149 const XMLCh *
const localname,
150 const XMLCh *
const qname) {
160 for (std::string::iterator
q =
m_text.begin();
q !=
m_text.end();
q++) {
187 for (
i = 0;
i < length -
offset &&
i < 255;
i++)
197 std::map<std::string, std::string> &
parameters,
198 std::vector<std::string> &
items,
201 std::list<Item> theItems;
205 if (m_parser ==
nullptr) {
206 m_parser = xercesc::XMLReaderFactory::createXMLReader();
209 MemBufInputSource
src(
210 (
const unsigned char *)xmlDocument.c_str(), xmlDocument.length(),
"hcal::ConfigurationDatabase");
211 m_parser->setContentHandler(&handler);
212 m_parser->parse(
src);
214 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, ex.what());
216 if (theItems.empty()) {
217 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"No data found");
218 }
else if (theItems.size() > 1) {
219 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Multiple items found");
222 items = theItems.front().items;
223 encoding = theItems.front().encoding;
227 void ConfigurationDatabaseStandardXMLParser::parseMultiple(
const std::string &xmlDocument,
228 std::list<Item> &
items) noexcept(
false) {
233 if (m_parser ==
nullptr) {
234 m_parser = xercesc::XMLReaderFactory::createXMLReader();
237 MemBufInputSource
src(
238 (
const unsigned char *)xmlDocument.c_str(), xmlDocument.length(),
"hcal::ConfigurationDatabase");
239 m_parser->setContentHandler(&handler);
240 m_parser->parse(
src);
242 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, ex.what());
247 std::vector<unsigned int>
values;
249 if (encoding ==
"hex")
251 else if (encoding ==
"dec")
255 for (
unsigned int j = 0;
j <
items.size();
j++)
256 values.push_back(strtol(
items[
j].c_str(),
nullptr, strtol_base));
vector< string > parse(string line, const string &delimiter)
bool cvt2String(const XMLCh *val, std::string &ou)
static const int ITEMELEMENTNAMES
ConfigurationDatabaseStandardXMLParser::Item m_workitem
void characters(const XMLCh *const chars, const XMLSize_t length) override
ROOT::VecOps::RVec< UChar_t > chars
enum ConfigurationDBHandler::@72 m_mode
XMLCh * xc_header[ITEMELEMENTNAMES]
void ignorableWhitespace(const XMLCh *const chars, const XMLSize_t length) override
def convert(infile, ofile)
std::list< ConfigurationDatabaseStandardXMLParser::Item > & m_items
bool isItemElement(const XMLCh *const localname)
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs) override
ConfigurationDBHandler(std::list< ConfigurationDatabaseStandardXMLParser::Item > &items)
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) override
~ConfigurationDBHandler() override