4 #include <xercesc/dom/DOMNode.hpp>
5 #include <xercesc/dom/DOM.hpp>
6 #include <xercesc/parsers/XercesDOMParser.hpp>
7 #include <xercesc/util/PlatformUtils.hpp>
8 #include <xercesc/util/XMLString.hpp>
9 #include <xercesc/sax/SAXException.hpp>
10 #include <xercesc/framework/LocalFileFormatTarget.hpp>
18 using namespace XERCES_CPP_NAMESPACE;
36 XMLPlatformUtils::Initialize();
38 XercesDOMParser*
parser =
new XercesDOMParser;
39 parser->setValidationScheme( XercesDOMParser::Val_Never );
40 parser->setDoNamespaces(
false );
41 parser->setDoSchema(
false );
43 parser->parse(filename.c_str());
45 DOMDocument* xmlDoc = parser->getDocument();
47 std::cout <<
"EcalLaserAPDPNRatiosXMLTranslator::Error parsing document" << std::endl;
51 DOMElement* elementRoot = xmlDoc->getDocumentElement();
95 cellnode = cellnode->getNextSibling();
97 while(cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
98 cellnode = cellnode->getNextSibling();
104 XMLPlatformUtils::Terminate();
117 std::fstream fs(filename.c_str(),
ios::out);
128 XMLPlatformUtils::Initialize();
130 DOMImplementation* impl =
131 DOMImplementationRegistry::getDOMImplementation(
fromNative(
"LS").c_str());
133 DOMWriter* writer =
static_cast<DOMImplementationLS*
>(impl)->createDOMWriter( );
134 writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
136 DOMDocumentType* doctype = impl->createDocumentType(
fromNative(
"XML").c_str(), 0, 0 );
141 doc->setEncoding(
fromNative(
"UTF-8").c_str() );
142 doc->setStandalone(
true);
146 DOMElement*
root = doc->getDocumentElement();
150 string Lasertag =
"Laser", LMtag =
"LM";
151 for(
int cellid = 0; cellid < (int)record.
getTimeMap().size(); cellid++) {
153 DOMElement* cellnode = doc->createElement(
fromNative(Lasertag).c_str());
154 root->appendChild(cellnode);
155 stringstream value_s;
157 cellnode->setAttribute(
fromNative(LMtag).c_str(),
161 t123[0]=(record.
getTimeMap())[cellid].t1.value();
163 t123[2]=(record.
getTimeMap())[cellid].t3.value();
164 string Laser_t_tag[3] = {
"t1",
"t2",
"t3"};
165 for(
int i = 0;
i < 3;
i++) {
166 time_t
t = t123[
i] >> 32;
169 localtime_r(&t, <);
170 strftime(buf,
sizeof(buf),
"%F %R:%S", <);
171 buf[
sizeof(buf)-1] = 0;
172 DOMDocument* subdoc = cellnode->getOwnerDocument();
173 DOMElement* new_node = subdoc->createElement(
fromNative(Laser_t_tag[
i]).c_str());
174 cellnode->appendChild(new_node);
175 std::stringstream value_ss;
177 string newstr = value_ss.str() +
" [" +
string(buf) +
"]";
179 subdoc->createTextNode(
fromNative(newstr).c_str());
180 new_node->appendChild(tvalue);
191 DOMElement* cellnode=
writeCell(root,rawid);
216 DOMElement* cellnode=
writeCell(root,rawid);
static int readXML(const std::string &filename, EcalCondHeader &header, EcalLaserAPDPNRatios &record)
static std::string dumpXML(const EcalCondHeader &header, const EcalLaserAPDPNRatios &record)
const std::string Laser_p3_tag("p3")
static EEDetId unhashIndex(int hi)
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
static bool validHashIndex(int i)
const EcalLaserAPDPNRatiosMap & getLaserMap() const
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
auto const T2 &decltype(t1.eta()) t2
static const int MIN_HASH
const std::string Cell_tag("cell")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
const std::string Laser_p1_tag("p1")
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalLaserAPDPNRatios &record)
const std::string Laser_tag("EcalLaserAPDPNRatios")
const EcalLaserTimeStampMap & getTimeMap() const
void GetNodeData(xercesc::DOMNode *node, T &value)
get the node data
xercesc::DOMNode * getChildNode(xercesc::DOMNode *node, const std::string &nodename)
get the child of
void setValue(uint32_t rawId, const EcalLaserAPDPNpair &value)
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
const std::string Laser_p2_tag("p2")
XercesString fromNative(const char *str)
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
std::string toNative(const XMLCh *str)
string root
initialization