Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Use new type
* Use transcoder for UTF-8 text
(cherry picked from commit 75ebcf5)
  • Loading branch information
ianna authored and smuzaffar committed Jun 7, 2016
1 parent 5f41039 commit ba54b9d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 46 deletions.
1 change: 1 addition & 0 deletions DQM/CSCMonitorModule/plugins/BuildFile.xml
Expand Up @@ -10,4 +10,5 @@
<use name="FWCore/ParameterSet"/>
<use name="FWCore/PluginManager"/>
<use name="xerces-c"/>
<use name="boost"/>
</library>
70 changes: 38 additions & 32 deletions DQM/CSCMonitorModule/plugins/CSCDQM_Collection.cc
Expand Up @@ -18,6 +18,9 @@
#include "CSCDQM_Collection.h"
#include "FWCore/Concurrency/interface/Xerces.h"
#include <cstdio>
#include <string>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/TransService.hpp>

namespace cscdqm {

Expand All @@ -35,7 +38,6 @@ namespace cscdqm {
* @return
*/
void Collection::load() {

LOG_INFO << "Reading histograms from " << config->getBOOKING_XML_FILE();

if (config->getBOOKING_XML_FILE().empty()) {
Expand All @@ -45,33 +47,30 @@ namespace cscdqm {
try {

cms::concurrency::xercesInitialize();

{

XercesDOMParser parser;

parser.setValidationScheme(XercesDOMParser::Val_Always);
parser.setDoNamespaces(true);
parser.setDoSchema(true);
parser.setExitOnFirstFatalError(true);
parser.setValidationConstraintFatal(true);
XMLFileErrorHandler eh;
parser.setErrorHandler(&eh);

parser.parse(config->getBOOKING_XML_FILE().c_str());
DOMDocument *doc = parser.getDocument();
DOMNode *docNode = (DOMNode*) doc->getDocumentElement();

DOMNodeList *itemList = docNode->getChildNodes();

CoHisto definitions;
for (uint32_t i = 0; i < itemList->getLength(); i++) {
XercesDOMParser parser;

parser.setValidationScheme(XercesDOMParser::Val_Always);
parser.setDoNamespaces(true);
parser.setDoSchema(true);
parser.setExitOnFirstFatalError(true);
parser.setValidationConstraintFatal(true);
XMLFileErrorHandler eh;
parser.setErrorHandler(&eh);
parser.parse(config->getBOOKING_XML_FILE().c_str());

DOMDocument *doc = parser.getDocument();
DOMElement *docNode = doc->getDocumentElement();
DOMNodeList *itemList = docNode->getChildNodes();

CoHisto definitions;
for (XMLSize_t i = 0; i < itemList->getLength(); i++) {

DOMNode* node = itemList->item(i);
if (node->getNodeType() != DOMNode::ELEMENT_NODE) { continue; }

std::string nodeName = XMLString::transcode(node->getNodeName());

///
/// Load histogram definition
///
Expand All @@ -96,6 +95,7 @@ namespace cscdqm {
DOMElement* el = dynamic_cast<DOMElement*>(node);
if (el->hasAttribute(XMLString::transcode(XML_BOOK_DEFINITION_REF))) {
std::string id(XMLString::transcode(el->getAttribute(XMLString::transcode(XML_BOOK_DEFINITION_REF))));

CoHistoProps d = definitions[id];
for (CoHistoProps::iterator it = d.begin(); it != d.end(); it++) {
hp[it->first] = it->second;
Expand All @@ -110,8 +110,8 @@ namespace cscdqm {
// Check if this histogram is an ON DEMAND histogram?
hp[XML_BOOK_ONDEMAND] = (Utility::regexMatch(REGEXP_ONDEMAND, name) ? XML_BOOK_ONDEMAND_TRUE : XML_BOOK_ONDEMAND_FALSE );

LOG_DEBUG << "[Collection::load] loading " << prefix << "::" << name << " XML_BOOK_ONDEMAND = " << hp[XML_BOOK_ONDEMAND];

LOG_DEBUG << "[Collection::load] loading " << prefix << "::" << name << " XML_BOOK_ONDEMAND = " << hp[XML_BOOK_ONDEMAND];
CoHistoMap::iterator it = collection.find(prefix);
if (it == collection.end()) {
CoHisto h;
Expand All @@ -120,10 +120,8 @@ namespace cscdqm {
} else {
it->second.insert(make_pair(name, hp));
}

}
}

}

cms::concurrency::xercesTerminate();
Expand All @@ -136,7 +134,6 @@ namespace cscdqm {
for (CoHistoMap::const_iterator i = collection.begin(); i != collection.end(); i++) {
LOG_INFO << i->second.size() << " " << i->first << " histograms defined";
}

}

/**
Expand All @@ -146,18 +143,27 @@ namespace cscdqm {
* @param p List of properties to fill
* @return
*/

void Collection::getNodeProperties(DOMNode*& node, CoHistoProps& p) {
DOMNodeList *props = node->getChildNodes();
for(uint32_t j = 0; j < props->getLength(); j++) {

for(XMLSize_t j = 0; j < props->getLength(); j++) {
DOMNode* node = props->item(j);
if (node->getNodeType() != DOMNode::ELEMENT_NODE) { continue; }
std::string name = XMLString::transcode(node->getNodeName());
std::string value = XMLString::transcode(node->getTextContent());
DOMElement* element = dynamic_cast<DOMElement*>(node);
std::string name = XMLString::transcode(element->getNodeName());

const XMLCh *content = element->getTextContent();
XERCES_CPP_NAMESPACE_QUALIFIER TranscodeToStr tc(content, "UTF-8");
std::istringstream buffer((const char*)tc.str());
std::string value;
buffer >> value;

DOMNamedNodeMap* attributes = node->getAttributes();
if (attributes) {
for (uint32_t i = 0; i < attributes->getLength(); i++) {
for (XMLSize_t i = 0; i < attributes->getLength(); i++) {
DOMNode* attribute = attributes->item(i);
std::string aname = XMLString::transcode(attribute->getNodeName());
std::string aname = XMLString::transcode(attribute->getNodeName());
std::string avalue = XMLString::transcode(attribute->getNodeValue());
p[name + "_" + aname] = avalue;
}
Expand Down
4 changes: 2 additions & 2 deletions DQM/CSCMonitorModule/plugins/CSCDQM_Configuration.h
Expand Up @@ -323,7 +323,7 @@ namespace cscdqm {
DOMNode *docNode = (DOMNode*) doc->getDocumentElement();

DOMNodeList *itemList = docNode->getChildNodes();
for(uint32_t i = 0; i < itemList->getLength(); i++) {
for(XMLSize_t i = 0; i < itemList->getLength(); i++) {
DOMNode* node = itemList->item(i);
if (node->getNodeType() != DOMNode::ELEMENT_NODE) { continue; }

Expand All @@ -335,7 +335,7 @@ namespace cscdqm {

if (nodeName.compare("MO_FILTER") == 0) {
DOMNodeList *filterList = node->getChildNodes();
for(uint32_t j = 0; j < filterList->getLength(); j++) {
for(XMLSize_t j = 0; j < filterList->getLength(); j++) {
DOMNode* filter = filterList->item(j);
if (filter->getNodeType() != DOMNode::ELEMENT_NODE) { continue; }
std::string filterName = XMLString::transcode(filter->getNodeName());
Expand Down
8 changes: 4 additions & 4 deletions FWCore/Catalog/src/FileLocator.cc
Expand Up @@ -221,21 +221,21 @@ namespace edm {
/*first of all do the lfn-to-pfn bit*/
{
DOMNodeList* rules = doc->getElementsByTagName(_toDOMS("lfn-to-pfn"));
unsigned int const ruleTagsNum = rules->getLength();
XMLSize_t const ruleTagsNum = rules->getLength();

// FIXME: we should probably use a DTD for checking validity

for (unsigned int i = 0; i < ruleTagsNum; ++i) {
for (XMLSize_t i = 0; i < ruleTagsNum; ++i) {
DOMNode* ruleNode = rules->item(i);
parseRule(ruleNode, m_directRules);
}
}
/*Then we handle the pfn-to-lfn bit*/
{
DOMNodeList* rules = doc->getElementsByTagName(_toDOMS("pfn-to-lfn"));
unsigned int ruleTagsNum = rules->getLength();
XMLSize_t ruleTagsNum = rules->getLength();

for (unsigned int i = 0; i < ruleTagsNum; ++i) {
for (XMLSize_t i = 0; i < ruleTagsNum; ++i) {
DOMNode* ruleNode = rules->item(i);
parseRule(ruleNode, m_inverseRules);
}
Expand Down
16 changes: 8 additions & 8 deletions FWCore/Services/src/SiteLocalConfigService.cc
Expand Up @@ -64,17 +64,17 @@ namespace {

DOMNodeList *childList = nodeToConvert.getChildNodes();

unsigned int numNodes = childList->getLength();
for (unsigned int i = 0; i < numNodes; ++i) {
XMLSize_t numNodes = childList->getLength();
for (XMLSize_t i = 0; i < numNodes; ++i) {
DOMNode *childNode = childList->item(i);
if (childNode->getNodeType() != DOMNode::ELEMENT_NODE) {
continue;
}
DOMElement *child = static_cast<DOMElement *>(childNode);

DOMNamedNodeMap *attributes = child->getAttributes();
unsigned int numAttributes = attributes->getLength();
for (unsigned int j = 0; j < numAttributes; ++j) {
XMLSize_t numAttributes = attributes->getLength();
for (XMLSize_t j = 0; j < numAttributes; ++j) {
DOMNode *attributeNode = attributes->item(j);
if (attributeNode->getNodeType() != DOMNode::ATTRIBUTE_NODE) {
continue;
Expand Down Expand Up @@ -391,8 +391,8 @@ namespace edm {
// FIXME: should probably use the parser for validating the XML.

DOMNodeList *sites = doc->getElementsByTagName(_toDOMS("site"));
unsigned int numSites = sites->getLength();
for (unsigned int i = 0; i < numSites; ++i) {
XMLSize_t numSites = sites->getLength();
for (XMLSize_t i = 0; i < numSites; ++i) {
DOMElement *site = static_cast<DOMElement *>(sites->item(i));

// Parse the site name
Expand Down Expand Up @@ -529,8 +529,8 @@ namespace edm {
DOMNodeList *childList = nativeProtocol->getChildNodes();

XMLCh* prefixXMLCh = _toDOMS("prefix");
unsigned int numNodes = childList->getLength();
for (unsigned int i = 0; i < numNodes; ++i) {
XMLSize_t numNodes = childList->getLength();
for (XMLSize_t i = 0; i < numNodes; ++i) {
DOMNode *childNode = childList->item(i);
if (childNode->getNodeType() != DOMNode::ELEMENT_NODE) {
continue;
Expand Down

0 comments on commit ba54b9d

Please sign in to comment.