Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:49

0001 #ifndef _CondTools_Ecal_XMLHelperFunctions_
0002 #define _CondTools_Ecal_XMLHelperFunctions_
0003 
0004 /**
0005  * Helper function for converting Ecal DB Objects to XML
0006  *
0007  * \author S. Argiro, F. Rubbo
0008  *
0009  * $Id: DOMHelperFunctions.h,v 1.1 2008/11/14 15:46:05 argiro Exp $
0010  */
0011 
0012 #include <xercesc/dom/DOMNode.hpp>
0013 #include "DataFormats/DetId/interface/DetId.h"
0014 #include <string>
0015 #include "CondTools/Ecal/interface/EcalCondHeader.h"
0016 #include "CondTools/Ecal/interface/XMLTags.h"
0017 #include "Utilities/Xerces/interface/XercesStrUtils.h"
0018 #include <xercesc/dom/DOM.hpp>
0019 #include <sstream>
0020 
0021 namespace xuti {
0022 
0023   /// Assuming \param node is a  <cell> node, read the id
0024   const DetId readCellId(xercesc::DOMElement* node);
0025 
0026   /// Append a Cell node with attributes to \param node
0027   xercesc::DOMElement* writeCell(xercesc::DOMNode* node, const DetId& detid);
0028 
0029   /// get the child of \param node called \param nodedame,return 0 if not found
0030   xercesc::DOMNode* getChildNode(xercesc::DOMNode* node, const std::string& nodename);
0031 
0032   /// get the node data as string. Needs to be used to avoid splitting
0033   //  white spaces instead of the templatized GetNodeData
0034   void GetNodeStringData(xercesc::DOMNode* node, std::string& value);
0035 
0036   /// get the node data
0037   template <class T>
0038   void GetNodeData(xercesc::DOMNode* node, T& value) {
0039     std::string value_s = cms::xerces::toString(node->getTextContent());
0040     std::stringstream value_ss(value_s);
0041     value_ss >> value;
0042   }
0043 
0044   /// write a node with \param tag and \param value under \param parentNode
0045   template <class T>
0046   void WriteNodeWithValue(xercesc::DOMNode* parentNode, const std::string& tag, const T& value) {
0047     xercesc::DOMDocument* doc = parentNode->getOwnerDocument();
0048     xercesc::DOMElement* new_node = doc->createElement(cms::xerces::uStr(tag.c_str()).ptr());
0049     parentNode->appendChild(new_node);
0050 
0051     std::stringstream value_ss;
0052     value_ss << value;
0053 
0054     xercesc::DOMText* tvalue = doc->createTextNode(cms::xerces::uStr(value_ss.str().c_str()).ptr());
0055     new_node->appendChild(tvalue);
0056   }
0057 
0058   /// write \param header under \param parentNode
0059   void writeHeader(xercesc::DOMNode* parentNode, const EcalCondHeader& header);
0060 
0061   /// read header from \param parentNode
0062   void readHeader(xercesc::DOMNode* parentNode, EcalCondHeader& header);
0063 
0064   /// read header from any xml file, return -1 in case of error
0065   int readHeader(const std::string& filename, EcalCondHeader& header);
0066 }  // namespace xuti
0067 
0068 #endif