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) {
12 #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");
51 xc_header[2]=XMLString::transcode(
"Pattern");
64 void startElement (
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname,
const Attributes &attrs)
override;
65 void endElement (
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname)
override;
66 void characters (
const XMLCh *
const chars,
const XMLSize_t length)
override;
70 if (val==
nullptr)
return false;
71 char* tool=XMLString::transcode(val);
82 std::list<ConfigurationDatabaseStandardXMLParser::Item>&
m_items;
90 if (!XMLString::compareIString(localname,xc_header[
i]))
return true;
103 }
else if (!XMLString::compareIString(localname,
xc_Parameter)) {
111 }
else if (!XMLString::compareIString(localname,
xc_Data)) {
124 for (
unsigned int jj=0;
jj<attrs.getLength();
jj++) {
125 if (!XMLString::compareIString(
xc_elements,attrs.getValue(
jj)) ||
147 if (entry.empty())
continue;
152 if (!entry.empty())
m_workitem.items.push_back(entry);
165 while (offset<length) {
167 for (i=0; i<length-offset && i<255; i++)
m_workx[i]=chars[i+offset];
177 std::list<Item> theItems;
181 if (m_parser==
nullptr) {
182 m_parser=xercesc::XMLReaderFactory::createXMLReader();
185 MemBufInputSource
src((
const unsigned char*)xmlDocument.c_str(), xmlDocument.length(),
"hcal::ConfigurationDatabase");
186 m_parser->setContentHandler(&handler);
187 m_parser->parse(
src);
189 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,ex.what());
191 if (theItems.empty()) {
192 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"No data found");
193 }
else if (theItems.size()>1) {
194 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Multiple items found");
197 items=theItems.front().items;
198 encoding=theItems.front().encoding;
204 void ConfigurationDatabaseStandardXMLParser::parseMultiple(
const std::string& xmlDocument, std::list<Item>&
items)
noexcept(
false) {
209 if (m_parser==
nullptr) {
210 m_parser=xercesc::XMLReaderFactory::createXMLReader();
213 MemBufInputSource
src((
const unsigned char*)xmlDocument.c_str(), xmlDocument.length(),
"hcal::ConfigurationDatabase");
214 m_parser->setContentHandler(&handler);
215 m_parser->parse(
src);
217 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,ex.what());
222 std::vector<unsigned int>
values;
224 if (encoding==
"hex") strtol_base=16;
225 else if (encoding==
"dec") strtol_base=10;
228 for (
unsigned int j=0; j<
items.size(); j++)
229 values.push_back(strtol(
items[j].c_str(),
nullptr,strtol_base));
bool cvt2String(const XMLCh *val, std::string &ou)
enum ConfigurationDBHandler::@67 m_mode
static const int ITEMELEMENTNAMES
ConfigurationDatabaseStandardXMLParser::Item m_workitem
void characters(const XMLCh *const chars, const XMLSize_t length) override
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