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) {}

◆ ~CalibrationXML()

CalibrationXML::~CalibrationXML ( )

Definition at line 22 of file CalibrationXML.cc.

22  {
23  //TODO: delete!!!!
24  if (errHandler)
25  delete errHandler;
26  if (parser) {
27  delete parser;
29  }
30 }

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

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.

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 }

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

Referenced by CalibratedHistogramXML::write().

◆ calibrationDOM()

DOMElement* CalibrationXML::calibrationDOM ( )
inline

Return the root DOM Element of the opened XML calibration file

Definition at line 46 of file CalibrationXML.h.

46 { return m_calibrationDOM; }

References m_calibrationDOM.

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

◆ closeFile()

void CalibrationXML::closeFile ( )
inline

Definition at line 36 of file CalibrationXML.h.

36  {
37  delete errHandler;
38  delete parser;
40  errHandler = nullptr;
41  parser = nullptr;
42  }

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

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

◆ openFile()

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

Open an XML file

Definition at line 32 of file CalibrationXML.cc.

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 }

References beam_dqm_sourceclient-live_cfg::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().

◆ 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.

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  }

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

◆ saveFile()

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

Save DOM to file

Definition at line 100 of file CalibrationXML.cc.

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 }

References 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.

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  }

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

Referenced by CalibratedHistogramXML::write().

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().

personalPlayback.level
level
Definition: personalPlayback.py:22
contentValuesFiles.dom
dom
Definition: contentValuesFiles.py:50
edm::LogInfo
Definition: MessageLogger.h:254
cms::cuda::assert
assert(be >=bs)
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
CalibrationXML::errHandler
HandlerBase * errHandler
Definition: CalibrationXML.h:87
CalibrationXML::DOMNode
XERCES_CPP_NAMESPACE::DOMNode DOMNode
Definition: CalibrationXML.h:17
CalibrationXML::doc
DOMDocument * doc
Definition: CalibrationXML.h:86
CalibrationXML::XercesDOMParser
XERCES_CPP_NAMESPACE::XercesDOMParser XercesDOMParser
Definition: CalibrationXML.h:19
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
CalibrationXML::HandlerBase
XERCES_CPP_NAMESPACE::HandlerBase HandlerBase
Definition: CalibrationXML.h:18
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
createfilelist.int
int
Definition: createfilelist.py:10
cms::concurrency::xercesTerminate
void xercesTerminate()
Definition: Xerces.cc:23
CalibrationXML::parser
XercesDOMParser * parser
Definition: CalibrationXML.h:88
CalibrationXML::DOMElement
XERCES_CPP_NAMESPACE::DOMElement DOMElement
Definition: CalibrationXML.h:16
T
long double T
Definition: Basic3DVectorLD.h:48
relativeConstraints.value
value
Definition: relativeConstraints.py:53
util.rrClient.indent
indent
Definition: rrClient.py:41
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
class-composition.child
child
Definition: class-composition.py:91
CalibrationXML::m_calibrationDOM
DOMElement * m_calibrationDOM
Definition: CalibrationXML.h:85
child
Definition: simpleInheritance.h:11
cms::concurrency::xercesInitialize
void xercesInitialize()
Definition: Xerces.cc:18
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
CalibrationXML::m_xmlFileName
std::string m_xmlFileName
Definition: CalibrationXML.h:84