CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EcalTPGStripStatusXMLTranslator.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <fstream>
4 #include <xercesc/dom/DOMNode.hpp>
5 #include <xercesc/dom/DOM.hpp>
6 #include <xercesc/parsers/XercesDOMParser.hpp>
9 #include <xercesc/util/XMLString.hpp>
10 #include <xercesc/sax/SAXException.hpp>
11 #include <xercesc/framework/LocalFileFormatTarget.hpp>
12 
15 
19 
21 
22 using namespace XERCES_CPP_NAMESPACE;
23 using namespace xuti;
24 using namespace std;
25 
27  EcalCondHeader& header,
29  std::cout << " TPGStripStatus should not be filled out from an xml file ..." << std::endl;
31 
32  XercesDOMParser* parser = new XercesDOMParser;
33  parser->setValidationScheme(XercesDOMParser::Val_Never);
34  parser->setDoNamespaces(false);
35  parser->setDoSchema(false);
36 
37  parser->parse(filename.c_str());
38 
39  DOMDocument* xmlDoc = parser->getDocument();
40  if (!xmlDoc) {
41  std::cout << "EcalTPGStripStatusXMLTranslator::Error parsing document" << std::endl;
42  return -1;
43  }
44 
45  DOMElement* elementRoot = xmlDoc->getDocumentElement();
46 
47  xuti::readHeader(elementRoot, header);
48 
49  delete parser;
51  return 0;
52 }
53 
55  const EcalCondHeader& header,
56  const EcalTPGStripStatus& record) {
58 
59  std::fstream fs(filename.c_str(), ios::out);
60  fs << dumpXML(header, record);
61 
63 
64  return 0;
65 }
66 
68  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
69 
70  DOMLSSerializer* writer = impl->createLSSerializer();
71  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
72  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
73 
74  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
75  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(TPGStripStatus_tag.c_str()).ptr(), doctype);
76  DOMElement* root = doc->getDocumentElement();
77 
78  xuti::writeHeader(root, header);
79  std::string TCC_tag("TCC");
80  std::string TT_tag("TT");
81  std::string ST_tag("ST");
82  const EcalTPGStripStatusMap& stripMap = record.getMap();
83  std::cout << "EcalTPGStripStatusXMLTranslator::dumpXML strip map size " << stripMap.size() << std::endl;
85  for (itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
86  if (itSt->second > 0) {
87  int tccid = itSt->first / 8192 & 0x7F;
88  int tt = itSt->first / 64 & 0x7F;
89  int pseudostrip = itSt->first / 8 & 0x7;
90  // std::cout << "Bad strip ID = " << itSt->first
91  // << " TCC " << tccid << " TT " << tt << " ST " << pseudostrip
92  // << ", status = " << itSt->second << std::endl;
93  DOMElement* cell_node = root->getOwnerDocument()->createElement(cms::xerces::uStr(Cell_tag.c_str()).ptr());
94  stringstream value_s;
95  value_s << tccid;
96  cell_node->setAttribute(cms::xerces::uStr(TCC_tag.c_str()).ptr(), cms::xerces::uStr(value_s.str().c_str()).ptr());
97  value_s.str("");
98  value_s << tt;
99  cell_node->setAttribute(cms::xerces::uStr(TT_tag.c_str()).ptr(), cms::xerces::uStr(value_s.str().c_str()).ptr());
100  value_s.str("");
101  value_s << pseudostrip;
102  cell_node->setAttribute(cms::xerces::uStr(ST_tag.c_str()).ptr(), cms::xerces::uStr(value_s.str().c_str()).ptr());
103  root->appendChild(cell_node);
104 
105  WriteNodeWithValue(cell_node, TPGStripStatus_tag, 1);
106  }
107  }
108 
109  std::string dump = cms::xerces::toString(writer->writeToString(root));
110  doc->release();
111  doctype->release();
112  writer->release();
113  return dump;
114 }
void xercesTerminate()
Definition: Xerces.cc:23
const std::map< uint32_t, uint16_t > & getMap() const
static int readXML(const std::string &filename, EcalCondHeader &header, EcalTPGStripStatus &record)
void xercesInitialize()
Definition: Xerces.cc:18
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
std::string toString(XMLCh const *toTranscode)
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
const std::string Cell_tag("cell")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
ZStr< XMLCh > uStr(char const *str)
static std::string dumpXML(const EcalCondHeader &header, const EcalTPGStripStatus &record)
const std::string TPGStripStatus_tag("EcalTPGStripStatus")
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:144
std::map< uint32_t, uint16_t > EcalTPGStripStatusMap
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalTPGStripStatus &record)
tuple dump
OutputFilePath = cms.string(&#39;/tmp/zhokin/&#39;), OutputFileExt = cms.string(&#39;&#39;),.
std::map< uint32_t, uint16_t >::const_iterator EcalTPGStripStatusMapIterator