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

typedef XERCES_CPP_NAMESPACE::DOMDocument CalibrationXML::DOMDocument

Definition at line 16 of file CalibrationXML.h.

typedef XERCES_CPP_NAMESPACE::DOMElement CalibrationXML::DOMElement

Definition at line 17 of file CalibrationXML.h.

typedef XERCES_CPP_NAMESPACE::DOMNode CalibrationXML::DOMNode

Definition at line 18 of file CalibrationXML.h.

typedef XERCES_CPP_NAMESPACE::HandlerBase CalibrationXML::HandlerBase

Definition at line 19 of file CalibrationXML.h.

typedef XERCES_CPP_NAMESPACE::XercesDOMParser CalibrationXML::XercesDOMParser

Definition at line 20 of file CalibrationXML.h.

typedef XERCES_CPP_NAMESPACE::XMLPlatformUtils CalibrationXML::XMLPlatformUtils

Definition at line 21 of file CalibrationXML.h.

typedef XERCES_CPP_NAMESPACE::XMLString CalibrationXML::XMLString

Definition at line 22 of file CalibrationXML.h.

Constructor & Destructor Documentation

XERCES_CPP_NAMESPACE_USE CalibrationXML::CalibrationXML ( )

Definition at line 21 of file CalibrationXML.cc.

21  : errHandler(0), parser(0)
22 {
23 
24 }
HandlerBase * errHandler
XercesDOMParser * parser
CalibrationXML::~CalibrationXML ( )

Definition at line 26 of file CalibrationXML.cc.

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

27 {
28 //TODO: delete!!!!
29 if(errHandler) delete errHandler;
30 if(parser) {
31  delete parser;
33  }
34 }
void xercesTerminate()
Definition: Xerces.cc:23
HandlerBase * errHandler
XercesDOMParser * parser

Member Function Documentation

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 122 of file CalibrationXML.cc.

References class-composition::child, summarizeEdmComparisonLogfiles::indent, hcalDigis_cfi::level, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by readAttribute(), and CalibratedHistogramXML::write().

123 {
124  DOMNode *n1 = dom;
125  int level=0;
126  std::string indent="\n";
127  while(n1 && level < 100)
128  {
129  level++;
130  indent+=" ";
131  n1 = n1->getParentNode();
132  }
133  assert(dom);
134  if(dom->getFirstChild()==0)
135  dom->appendChild(dom->getOwnerDocument()->createTextNode(XMLString::transcode(indent.c_str())));
136 
137  DOMElement * child = (DOMElement *)dom->appendChild(dom->getOwnerDocument()->createElement(XMLString::transcode(name.c_str())));
138  dom->appendChild(dom->getOwnerDocument()->createTextNode(XMLString::transcode(indent.c_str())));
139  return child;
140 }
XERCES_CPP_NAMESPACE::DOMNode DOMNode
XERCES_CPP_NAMESPACE::DOMElement DOMElement
DOMElement* CalibrationXML::calibrationDOM ( )
inline

Return the root DOM Element of the opened XML calibration file

Definition at line 48 of file CalibrationXML.h.

References m_calibrationDOM.

48 { return m_calibrationDOM;}
DOMElement * m_calibrationDOM
void CalibrationXML::closeFile ( )
inline

Definition at line 38 of file CalibrationXML.h.

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

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

39  {
40  delete errHandler;
42  errHandler=0;
43  parser=0;
44  }
void xercesTerminate()
Definition: Xerces.cc:23
HandlerBase * errHandler
XercesDOMParser * parser
void CalibrationXML::openFile ( const std::string &  xmlFileName)

Open an XML file

Definition at line 36 of file CalibrationXML.cc.

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

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

References addChild(), dataset::name, fetchall_from_DQM_v2::release, AlCaHLTBitMon_QueryRunRegistry::string, and relativeConstraints::value.

70  {
71  XMLCh* nameStr = XMLString::transcode(name.c_str());
72  char * valueStr = XMLString::transcode(dom->getAttribute(nameStr));
73  std::istringstream buffer(valueStr);
74  T value;
75  buffer >> value;
76  XMLString::release(&nameStr);
77  XMLString::release(&valueStr);
78  return value;
79  }
long double T
void CalibrationXML::saveFile ( const std::string &  xmlFileName)

Save DOM to file

Definition at line 107 of file CalibrationXML.cc.

References doc.

108 {
109  DOMImplementation * theImpl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core"));
110  DOMLSSerializer * theSerializer = ((DOMImplementation*)theImpl)->createLSSerializer();
111  DOMConfiguration* dc = theSerializer->getDomConfig();
112  dc->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
113 
114  XMLFormatTarget* myFormTarget = new LocalFileFormatTarget(XMLString::transcode(xmlFileName.c_str()));
115  DOMLSOutput* outputDesc = ((DOMImplementationLS*)theImpl)->createLSOutput();
116  outputDesc->setByteStream(myFormTarget);
117 
118  theSerializer->write(doc, outputDesc);
119  delete myFormTarget;
120 }
DOMDocument * doc
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 55 of file CalibrationXML.h.

References fetchall_from_DQM_v2::release, and relativeConstraints::value.

Referenced by CalibratedHistogramXML::write().

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

Member Data Documentation

DOMDocument* CalibrationXML::doc
private

Definition at line 89 of file CalibrationXML.h.

Referenced by openFile(), and saveFile().

HandlerBase* CalibrationXML::errHandler
private

Definition at line 90 of file CalibrationXML.h.

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

DOMElement* CalibrationXML::m_calibrationDOM
private

Definition at line 88 of file CalibrationXML.h.

Referenced by calibrationDOM(), and openFile().

std::string CalibrationXML::m_xmlFileName
private

Definition at line 87 of file CalibrationXML.h.

Referenced by openFile().

XercesDOMParser* CalibrationXML::parser
private

Definition at line 91 of file CalibrationXML.h.

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