CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
CalibrationXML Class Reference

#include <CalibrationXML.h>

Public Types

typedef XERCES_CPP_NAMESPACE::DOMDocument DOMDocument
 
typedef XERCES_CPP_NAMESPACE::DOMElement DOMElement
 
typedef XERCES_CPP_NAMESPACE::DOMNode DOMNode
 
typedef XERCES_CPP_NAMESPACE::HandlerBase HandlerBase
 
typedef XERCES_CPP_NAMESPACE::XercesDOMParser XercesDOMParser
 
typedef XERCES_CPP_NAMESPACE::XMLPlatformUtils XMLPlatformUtils
 
typedef XERCES_CPP_NAMESPACE::XMLString XMLString
 

Public Member Functions

DOMElementcalibrationDOM ()
 
 CalibrationXML ()
 
void closeFile ()
 
void openFile (const std::string &xmlFileName)
 
void saveFile (const std::string &xmlFileName)
 
 ~CalibrationXML ()
 

Static Public Member Functions

static DOMElementaddChild (DOMNode *dom, const std::string &name)
 
template<class T >
static T readAttribute (DOMElement *dom, const std::string &name)
 
template<class T >
static void writeAttribute (DOMElement *dom, const std::string &name, const T &value)
 

Private Attributes

DOMDocumentdoc
 
HandlerBaseerrHandler
 
DOMElementm_calibrationDOM
 
std::string m_xmlFileName
 
XercesDOMParserparser
 

Detailed Description

Definition at line 13 of file CalibrationXML.h.

Member Typedef Documentation

◆ DOMDocument

typedef XERCES_CPP_NAMESPACE::DOMDocument CalibrationXML::DOMDocument

Definition at line 15 of file CalibrationXML.h.

◆ DOMElement

typedef XERCES_CPP_NAMESPACE::DOMElement CalibrationXML::DOMElement

Definition at line 16 of file CalibrationXML.h.

◆ DOMNode

typedef XERCES_CPP_NAMESPACE::DOMNode CalibrationXML::DOMNode

Definition at line 17 of file CalibrationXML.h.

◆ HandlerBase

typedef XERCES_CPP_NAMESPACE::HandlerBase CalibrationXML::HandlerBase

Definition at line 18 of file CalibrationXML.h.

◆ XercesDOMParser

typedef XERCES_CPP_NAMESPACE::XercesDOMParser CalibrationXML::XercesDOMParser

Definition at line 19 of file CalibrationXML.h.

◆ XMLPlatformUtils

typedef XERCES_CPP_NAMESPACE::XMLPlatformUtils CalibrationXML::XMLPlatformUtils

Definition at line 20 of file CalibrationXML.h.

◆ XMLString

typedef XERCES_CPP_NAMESPACE::XMLString CalibrationXML::XMLString

Definition at line 21 of file CalibrationXML.h.

Constructor & Destructor Documentation

◆ CalibrationXML()

XERCES_CPP_NAMESPACE_USE CalibrationXML::CalibrationXML ( )

Definition at line 20 of file CalibrationXML.cc.

20 : errHandler(nullptr), parser(nullptr) {}
HandlerBase * errHandler
XercesDOMParser * parser

◆ ~CalibrationXML()

CalibrationXML::~CalibrationXML ( )

Definition at line 22 of file CalibrationXML.cc.

References errHandler, parser, and cms::concurrency::xercesTerminate().

22  {
23  //TODO: delete!!!!
24  if (errHandler)
25  delete errHandler;
26  if (parser) {
27  delete parser;
29  }
30 }
void xercesTerminate()
Definition: Xerces.cc:23
HandlerBase * errHandler
XercesDOMParser * parser

Member Function Documentation

◆ addChild()

DOMElement * CalibrationXML::addChild ( DOMNode dom,
const std::string &  name 
)
static

Helper static function to add a child in a DOM Element with indentation

Definition at line 114 of file CalibrationXML.cc.

References cms::cuda::assert(), submitPVValidationJobs::child, contentValuesFiles::dom, util.rrClient::indent, personalPlayback::level, Skims_PA_cff::name, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by CalibratedHistogramXML::write().

114  {
115  DOMNode* n1 = dom;
116  int level = 0;
117  std::string indent = "\n";
118  while (n1 && level < 100) {
119  level++;
120  indent += " ";
121  n1 = n1->getParentNode();
122  }
123  assert(dom);
124  if (dom->getFirstChild() == nullptr)
125  dom->appendChild(dom->getOwnerDocument()->createTextNode(XMLString::transcode(indent.c_str())));
126 
127  DOMElement* child =
128  (DOMElement*)dom->appendChild(dom->getOwnerDocument()->createElement(XMLString::transcode(name.c_str())));
129  dom->appendChild(dom->getOwnerDocument()->createTextNode(XMLString::transcode(indent.c_str())));
130  return child;
131 }
assert(be >=bs)
XERCES_CPP_NAMESPACE::DOMNode DOMNode
XERCES_CPP_NAMESPACE::DOMElement DOMElement

◆ calibrationDOM()

DOMElement* CalibrationXML::calibrationDOM ( )
inline

Return the root DOM Element of the opened XML calibration file

Definition at line 46 of file CalibrationXML.h.

References m_calibrationDOM.

Referenced by AlgorithmCalibration< T, CO >::dom().

46 { return m_calibrationDOM; }
DOMElement * m_calibrationDOM

◆ closeFile()

void CalibrationXML::closeFile ( )
inline

Definition at line 36 of file CalibrationXML.h.

References errHandler, parser, and cms::concurrency::xercesTerminate().

Referenced by AlgorithmCalibration< T, CO >::AlgorithmCalibration().

36  {
37  delete errHandler;
38  delete parser;
40  errHandler = nullptr;
41  parser = nullptr;
42  }
void xercesTerminate()
Definition: Xerces.cc:23
HandlerBase * errHandler
XercesDOMParser * parser

◆ openFile()

void CalibrationXML::openFile ( const std::string &  xmlFileName)

Open an XML file

Definition at line 32 of file CalibrationXML.cc.

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, doc, MillePedeFileConverter_cfg::e, errHandler, createfilelist::int, m_calibrationDOM, m_xmlFileName, parser, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

Referenced by AlgorithmCalibration< T, CO >::dom().

32  {
33  if (errHandler)
34  delete errHandler;
35  if (parser) {
36  delete parser;
38  }
39 
40  m_xmlFileName = xmlFileName;
41  // std::cout << "Opening.." << std::endl;
42  // Initialize the XML4C2 system
43  try {
45  } catch (const XMLException& toCatch) {
46  std::cerr << "Error during Xerces-c Initialization.\n"
47  << " Exception message:" << XMLString::transcode(toCatch.getMessage()) << std::endl;
48  abort();
49  //FIXME throw GenTerminate("Error during Xerces-c Initialization.");
50  }
51  parser = new XercesDOMParser;
52  parser->setValidationScheme(XercesDOMParser::Val_Auto);
53  parser->setDoNamespaces(false);
54  parser->setDoSchema(false);
55  parser->setValidationSchemaFullChecking(false);
56  errHandler = new HandlerBase;
57  parser->setErrorHandler(errHandler);
58  parser->setCreateEntityReferenceNodes(false);
59  // Parse the XML file, catching any XML exceptions that might propogate out of it.
60  bool errorsOccured = false;
61  try {
62  edm::LogInfo("XMLCalibration") << "Calibration XML: parsing " << m_xmlFileName.c_str() << std::endl;
63  parser->parse(m_xmlFileName.c_str());
64  int errorCount = parser->getErrorCount();
65  if (errorCount > 0)
66  errorsOccured = true;
67  } catch (const XMLException& e) {
68  std::cerr << "A DOM error occured during parsing\n DOMException code: " << (long unsigned int)e.getCode()
69  << std::endl;
70  errorsOccured = true;
71  }
72  // If the parse was successful, build the structure we want to have
73  if (errorsOccured) {
74  std::cerr << "An error occured during parsing\n"
75  << "Please check your input with SAXCount or a similar tool.\n Exiting!\n"
76  << std::endl;
77  abort();
78  //FIXME throw GenTerminate("An error occured during parsing\n Please check your input with SAXCount or a similar tool.\n Exiting!\n");
79  }
80 
81  doc = parser->getDocument();
82  DOMNode* n1 = doc->getFirstChild();
83 
84  while (n1) {
85  if (n1->getNodeType() == DOMNode::ELEMENT_NODE)
86  break;
87  n1 = n1->getNextSibling();
88  }
89 
90  if (n1 == nullptr || strcmp("Calibration", XMLString::transcode(n1->getNodeName())))
91  abort();
92  //FIXME throw GenTerminate("The root element in the XML Calibration file is not a Calibration element.\n This should be forbidden at the DTD level.");
93  else {
94  edm::LogInfo("XMLCalibration") << "Calibration found";
95  }
96 
98 }
DOMDocument * doc
DOMElement * m_calibrationDOM
XERCES_CPP_NAMESPACE::HandlerBase HandlerBase
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18
XERCES_CPP_NAMESPACE::DOMNode DOMNode
HandlerBase * errHandler
Log< level::Info, false > LogInfo
std::string m_xmlFileName
XercesDOMParser * parser
XERCES_CPP_NAMESPACE::DOMElement DOMElement
XERCES_CPP_NAMESPACE::XercesDOMParser XercesDOMParser

◆ readAttribute()

template<class T >
static T CalibrationXML::readAttribute ( DOMElement dom,
const std::string &  name 
)
inlinestatic

Helper static function to read an attribute in a DOM Element

Definition at line 67 of file CalibrationXML.h.

References edmScanValgrind::buffer, contentValuesFiles::dom, Skims_PA_cff::name, fetchall_from_DQM_v2::release, and relativeConstraints::value.

67  {
68  XMLCh *nameStr = XMLString::transcode(name.c_str());
69  char *valueStr = XMLString::transcode(dom->getAttribute(nameStr));
70  std::istringstream buffer(valueStr);
71  T value;
72  buffer >> value;
73  XMLString::release(&nameStr);
74  XMLString::release(&valueStr);
75  return value;
76  }
long double T

◆ saveFile()

void CalibrationXML::saveFile ( const std::string &  xmlFileName)

Save DOM to file

Definition at line 100 of file CalibrationXML.cc.

References doc.

100  {
101  DOMImplementation* theImpl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core"));
102  DOMLSSerializer* theSerializer = ((DOMImplementation*)theImpl)->createLSSerializer();
103  DOMConfiguration* dc = theSerializer->getDomConfig();
104  dc->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
105 
106  XMLFormatTarget* myFormTarget = new LocalFileFormatTarget(XMLString::transcode(xmlFileName.c_str()));
107  DOMLSOutput* outputDesc = ((DOMImplementationLS*)theImpl)->createLSOutput();
108  outputDesc->setByteStream(myFormTarget);
109 
110  theSerializer->write(doc, outputDesc);
111  delete myFormTarget;
112 }
DOMDocument * doc

◆ writeAttribute()

template<class T >
static void CalibrationXML::writeAttribute ( DOMElement dom,
const std::string &  name,
const T value 
)
inlinestatic

Helper static function to write an attribute in a DOM Element

Definition at line 53 of file CalibrationXML.h.

References edmScanValgrind::buffer, contentValuesFiles::dom, Skims_PA_cff::name, fetchall_from_DQM_v2::release, and relativeConstraints::value.

Referenced by CalibratedHistogramXML::write().

53  {
54  std::ostringstream buffer;
55  buffer << value;
56  XMLCh *nameStr = XMLString::transcode(name.c_str());
57  XMLCh *valueStr = XMLString::transcode(buffer.str().c_str());
58  dom->setAttribute(nameStr, valueStr);
59  XMLString::release(&nameStr);
60  XMLString::release(&valueStr);
61  }

Member Data Documentation

◆ doc

DOMDocument* CalibrationXML::doc
private

Definition at line 86 of file CalibrationXML.h.

Referenced by openFile(), and saveFile().

◆ errHandler

HandlerBase* CalibrationXML::errHandler
private

Definition at line 87 of file CalibrationXML.h.

Referenced by closeFile(), openFile(), and ~CalibrationXML().

◆ m_calibrationDOM

DOMElement* CalibrationXML::m_calibrationDOM
private

Definition at line 85 of file CalibrationXML.h.

Referenced by calibrationDOM(), and openFile().

◆ m_xmlFileName

std::string CalibrationXML::m_xmlFileName
private

Definition at line 84 of file CalibrationXML.h.

Referenced by openFile().

◆ parser

XercesDOMParser* CalibrationXML::parser
private

Definition at line 88 of file CalibrationXML.h.

Referenced by closeFile(), openFile(), and ~CalibrationXML().