CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 22 of file CalibrationXML.cc.

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

Definition at line 27 of file CalibrationXML.cc.

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

28 {
29 //TODO: delete!!!!
30 if(errHandler) delete errHandler;
31 if(parser) {
32  delete parser;
34  }
35 }
void xercesTerminate()
Definition: Xerces.cc:22
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 118 of file CalibrationXML.cc.

References dataformats::indent(), testEve_cfg::level, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by CalibratedHistogramXML::write().

119 {
120  DOMNode *n1 = dom;
121  int level=0;
122  std::string indent="\n";
123  while(n1 && level < 100)
124  {
125  level++;
126  indent+=" ";
127  n1 = n1->getParentNode();
128  }
129  if(dom->getFirstChild()==0)
130  dom->appendChild(dom->getOwnerDocument()->createTextNode(XMLString::transcode(indent.c_str())));
131 
132  DOMElement * child = (DOMElement *)dom->appendChild(dom->getOwnerDocument()->createElement(XMLString::transcode(name.c_str())));
133  dom->appendChild(dom->getOwnerDocument()->createTextNode(XMLString::transcode(indent.c_str())));
134  return child;
135 }
XERCES_CPP_NAMESPACE::DOMNode DOMNode
tuple level
Definition: testEve_cfg.py:34
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.

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

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:22
HandlerBase * errHandler
XercesDOMParser * parser
void CalibrationXML::openFile ( const std::string &  xmlFileName)

Open an XML file

Definition at line 37 of file CalibrationXML.cc.

References dtNoiseDBValidation_cfg::cerr, doc, alignCSCRings::e, errHandler, m_calibrationDOM, m_xmlFileName, parser, cms::concurrency::xercesInitialize(), cms::concurrency::xercesTerminate(), and BuildIsoConfigs::xmlFileName.

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

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

References doc.

109 {
110  DOMImplementation * theImpl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core"));
111  DOMWriter * theSerializer = ((DOMImplementation*)theImpl)->createDOMWriter();
112  theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
113  XMLFormatTarget* myFormTarget = new LocalFileFormatTarget(XMLString::transcode(xmlFileName.c_str()));
114  theSerializer->writeNode(myFormTarget, *doc);
115  delete myFormTarget;
116 
117 }
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().