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 12 of file CalibrationXML.h.

Member Typedef Documentation

typedef XERCES_CPP_NAMESPACE::DOMDocument CalibrationXML::DOMDocument

Definition at line 15 of file CalibrationXML.h.

typedef XERCES_CPP_NAMESPACE::DOMElement CalibrationXML::DOMElement

Definition at line 16 of file CalibrationXML.h.

typedef XERCES_CPP_NAMESPACE::DOMNode CalibrationXML::DOMNode

Definition at line 17 of file CalibrationXML.h.

typedef XERCES_CPP_NAMESPACE::HandlerBase CalibrationXML::HandlerBase

Definition at line 18 of file CalibrationXML.h.

typedef XERCES_CPP_NAMESPACE::XercesDOMParser CalibrationXML::XercesDOMParser

Definition at line 19 of file CalibrationXML.h.

typedef XERCES_CPP_NAMESPACE::XMLPlatformUtils CalibrationXML::XMLPlatformUtils

Definition at line 20 of file CalibrationXML.h.

typedef XERCES_CPP_NAMESPACE::XMLString CalibrationXML::XMLString

Definition at line 21 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, and parser.

28 {
29 //TODO: delete!!!!
30 if(errHandler) delete errHandler;
31 if(parser) {
32  delete parser;
33  XMLPlatformUtils::Terminate();
34  }
35 }
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 123 of file CalibrationXML.cc.

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

Referenced by CalibratedHistogramXML::write().

124 {
125  DOMNode *n1 = dom;
126  int level=0;
127  std::string indent="\n";
128  while(n1 && level < 100)
129  {
130  level++;
131  indent+=" ";
132  n1 = n1->getParentNode();
133  }
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
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 47 of file CalibrationXML.h.

References m_calibrationDOM.

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

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

Definition at line 37 of file CalibrationXML.h.

References errHandler, and parser.

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

38  {
39  if(errHandler) delete errHandler;
40  if(parser) { delete parser; XMLPlatformUtils::Terminate(); }
41  errHandler=0;
42  parser=0;
43  }
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, and BuildIsoConfigs::xmlFileName.

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

38 {
39 if(errHandler) delete errHandler;
40 if(parser) { delete parser; XMLPlatformUtils::Terminate(); }
41 
43 // std::cout << "Opening.." << std::endl;
44  // Initialize the XML4C2 system
45  try
46  {
47  XMLPlatformUtils::Initialize();
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  catch (...)
81  {
82  std::cerr << "An unknown error occured during parsing\n " << std::endl;
83  errorsOccured = true;
84  }
85  // If the parse was successful, build the structure we want to have
86  if(errorsOccured) {
87  std::cerr << "An error occured during parsing\n"
88  << "Please check your input with SAXCount or a similar tool.\n Exiting!\n" << std::endl;
89 abort();
90 //FIXME throw GenTerminate("An error occured during parsing\n Please check your input with SAXCount or a similar tool.\n Exiting!\n");
91  }
92 
93  doc = parser->getDocument();
94  DOMNode* n1 = doc->getFirstChild();
95 
96  while(n1)
97  {
98  if (n1->getNodeType() == DOMNode::ELEMENT_NODE ) break;
99  n1 = n1->getNextSibling();
100  }
101 
102  if(strcmp("Calibration",XMLString::transcode(n1->getNodeName())))
103 abort();
104 //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.");
105  else { edm::LogInfo("XMLCalibration") << "Calibration found" ; }
106 
107  m_calibrationDOM = (DOMElement *) n1;
108 
109 
110 
111 }
DOMDocument * doc
DOMElement * m_calibrationDOM
XERCES_CPP_NAMESPACE::HandlerBase HandlerBase
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 68 of file CalibrationXML.h.

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

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

Save DOM to file

Definition at line 113 of file CalibrationXML.cc.

References doc.

114 {
115  DOMImplementation * theImpl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core"));
116  DOMWriter * theSerializer = ((DOMImplementation*)theImpl)->createDOMWriter();
117  theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
118  XMLFormatTarget* myFormTarget = new LocalFileFormatTarget(XMLString::transcode(xmlFileName.c_str()));
119  theSerializer->writeNode(myFormTarget, *doc);
120  delete myFormTarget;
121 
122 }
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 54 of file CalibrationXML.h.

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

Referenced by CalibratedHistogramXML::write().

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

Member Data Documentation

DOMDocument* CalibrationXML::doc
private

Definition at line 88 of file CalibrationXML.h.

Referenced by openFile(), and saveFile().

HandlerBase* CalibrationXML::errHandler
private

Definition at line 89 of file CalibrationXML.h.

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

DOMElement* CalibrationXML::m_calibrationDOM
private

Definition at line 87 of file CalibrationXML.h.

Referenced by calibrationDOM(), and openFile().

std::string CalibrationXML::m_xmlFileName
private

Definition at line 86 of file CalibrationXML.h.

Referenced by openFile().

XercesDOMParser* CalibrationXML::parser
private

Definition at line 90 of file CalibrationXML.h.

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