14 #include <xercesc/parsers/AbstractDOMParser.hpp>
15 #include <xercesc/dom/DOM.hpp>
38 validAxisName(
const std::string& proposedName,
const std::array<std::string, 3>& allowedNames) {
39 return((proposedName == allowedNames[0])or(proposedName == allowedNames[1])or(proposedName == allowedNames[2]));
70 if (not
i.validType()) {
73 bool thisIsOk = (usersmap.insert(std::pair<std::string, SingleHistogramDefinition>(
i.stringIndex(),
i))).
second;
76 std::string
msg =
"You have attempted to add a duplicate histogram definition: " +
i.stringIndex();
77 throw std::runtime_error(
msg);
80 return(ok and(not usersmap.empty()));
96 std::cerr <<
"Could not open file " <<
m_source <<
" in ReadFromXmlDom initialize" << std::endl;
100 static const XMLCh gLS[] = {
101 xercesc::chLatin_L, xercesc::chLatin_S, xercesc::chNull
103 xercesc::DOMImplementation*
impl = xercesc::DOMImplementationRegistry::getDOMImplementation(gLS);
104 xercesc::DOMLSParser*
parser = ((xercesc::DOMImplementationLS*)
impl)->createLSParser(
105 xercesc::DOMImplementationLS::MODE_SYNCHRONOUS,
nullptr);
106 xercesc::DOMConfiguration*
config =
parser->getDomConfig();
107 if (
config->canSetParameter(xercesc::XMLUni::fgXercesDoXInclude,
true)) {
108 config->setParameter(xercesc::XMLUni::fgXercesDoXInclude,
true);
111 config->setParameter(xercesc::XMLUni::fgDOMErrorHandler, &errorHandler);
114 xercesc::DOMNodeList*
list =
doc->getElementsByTagName(temp.c_str());
115 const auto nElements =
list->getLength();
116 for (
unsigned long i(0);
i != nElements; ++
i) {
117 xercesc::DOMNode
const* thisNode =
list->item(
i);
118 const auto *thisElement =
dynamic_cast<xercesc::DOMElement
const*
> (thisNode);
137 enum RegXHistoGroups {
138 TYPE, NAME, TITLE, NX, NY, NZ, XLO, YLO, ZLO, XHI, YHI, ZHI, XAXIS, YAXIS, ZAXIS, FOLDER, NGROUPS
140 const std::array<std::string, NGROUPS> attrNames = {
141 "type",
"id",
"title",
"n",
"n",
"n",
"lo",
"lo",
"lo",
"hi",
"hi",
"hi",
"title",
"title",
"title",
"folder"
145 std::array<XercesString, NGROUPS> xercesNames;
146 std::transform(attrNames.begin(), attrNames.end(), xercesNames.begin(), [](
const std::string&
s) {
147 return fromNative(s);
150 std::array<XercesString, NGROUPS> xercesValues;
152 constexpr
unsigned int NAXES = 3;
153 const std::array<std::string, NAXES> allowedAxisNames = {
158 xercesValues[NAME] = element->getAttribute(xercesNames[NAME].c_str());
159 xercesValues[TITLE] = element->getAttribute(xercesNames[TITLE].c_str());
160 xercesValues[
TYPE] = element->getAttribute(xercesNames[
TYPE].c_str());
161 xercesValues[FOLDER] = element->getAttribute(xercesNames[FOLDER].c_str());
163 const bool isTProfile = (
type ==
"TProfile");
165 const xercesc::DOMElement* axisDef0 = element->getFirstElementChild();
166 if (!axisDef0 and element->hasChildNodes()) {
168 const std::string textContent =
toNative(xercesContent);
169 if (textContent.empty()) {
178 if (not axisDef0)
return s;
179 const xercesc::DOMElement* axisDef1 = axisDef0->getNextElementSibling();
180 if (not axisDef1)
return s;
182 std::string axisName0 =
toNative(axisDef0->getTagName());
183 std::string axisName1 =
toNative(axisDef1->getTagName());
184 const xercesc::DOMElement* axisDef2 = axisDef1->getNextElementSibling();
185 std::string axisName2 = axisDef2 ?
toNative(axisDef2->getTagName()) :
"z";
186 if (validAxisName(axisName0, allowedAxisNames)
187 and validAxisName(axisName1,allowedAxisNames)
188 and validAxisName(axisName2,allowedAxisNames)
189 and (axisName1 != axisName0) and (axisName2 != axisName1)) {
192 if (axisName0 == allowedAxisNames[1]) {
197 xercesValues[NX +
xIndex] = axisDef0->getAttribute(xercesNames[NX +
xIndex].c_str());
198 xercesValues[NX +
yIndex] = axisDef1->getAttribute(xercesNames[NX +
yIndex].c_str());
200 xercesValues[XLO +
xIndex] = axisDef0->getAttribute(xercesNames[XLO +
xIndex].c_str());
201 xercesValues[XLO +
yIndex] = axisDef1->getAttribute(xercesNames[XLO +
yIndex].c_str());
203 xercesValues[XHI +
xIndex] = axisDef0->getAttribute(xercesNames[XHI +
xIndex].c_str());
204 xercesValues[XHI +
yIndex] = axisDef1->getAttribute(xercesNames[XHI +
yIndex].c_str());
206 xercesValues[XAXIS +
xIndex] = axisDef0->getAttribute(xercesNames[XAXIS +
xIndex].c_str());
207 xercesValues[XAXIS +
yIndex] = axisDef1->getAttribute(xercesNames[XAXIS +
yIndex].c_str());
208 xercesValues[XAXIS +
zIndex] = axisDef2 ? axisDef2->getAttribute(xercesNames[XAXIS +
zIndex].c_str()) :
XercesString();
210 std::array<std::string, NGROUPS> stringValues {
217 const float NaN = std::nanf(
"");
218 const unsigned int nx = stringValues[NX].empty() ? 0 : (
unsigned int) (std::stoul(stringValues[NX]));
219 const unsigned int ny = stringValues[NY].empty() ? 0 : (
unsigned int) (std::stoul(stringValues[NY]));
220 const unsigned int nz = stringValues[NZ].empty() ? 0 : (
unsigned int) (std::stoul(stringValues[NZ]));
221 const float xlo = stringValues[XLO].empty() ? NaN : std::stof(stringValues[XLO]);
222 const float ylo = stringValues[YLO].empty() ? NaN : std::stof(stringValues[YLO]);
223 const float zlo = stringValues[ZLO].empty() ? NaN : std::stof(stringValues[ZLO]);
224 const float xhi = stringValues[XHI].empty() ? NaN : std::stof(stringValues[XHI]);
225 const float yhi = stringValues[YHI].empty() ? NaN : std::stof(stringValues[YHI]);
226 const float zhi = stringValues[ZHI].empty() ? NaN : std::stof(stringValues[ZHI]);
230 stringValues[XAXIS], stringValues[YAXIS], stringValues[ZAXIS],
231 stringValues[FOLDER]);
240 enum RegXHistoGroups {
245 R
"delim(^\s+"([^"]+)"\s+(\d+)\s+([-+.0-9eE]+)\s+([-+.0-9eE]+)\s+"([^"]+)"\s+"([^"]+)"\s*(.*)\s*$)delim";
249 if (std::regex_match(
line,
m, reg)) {
250 const bool hasFolder = (
m.size() == NGROUPS);
251 s.title =
m[TITLE].str();
252 s.xTitle =
m[XAXIS].str();
253 s.yTitle =
m[YAXIS].str();
257 s.folder =
m[FOLDER].str();
267 enum RegXHistoGroups {
268 TOTAL, TITLE,
NBINS, XLO, XHI, YLO, YHI, XAXIS, YAXIS,
DUMMY, FOLDER, NGROUPS
273 R
"delim(^\s+"([^"]+)"\s+(\d+)\s+([-+.0-9eE]+)\s+([-+.0-9eE]+)\s+([-+.0-9eE]+)\s+([-+.0-9eE]+)\s+"([^"]+)"\s+"([^"]+)"\s*(.*)\s*$)delim";
277 if (std::regex_match(
line,
m, reg)) {
278 const bool hasFolder = (
m.size() == NGROUPS);
279 s.title =
m[TITLE].str();
280 s.xTitle =
m[XAXIS].str();
281 s.yTitle =
m[YAXIS].str();
286 s.folder =
m[FOLDER].str();