CMS 3D CMS Logo

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 
29 
30  std::cout << " TPGStripStatus should not be filled out from an xml file ..." << std::endl;
32 
33  XercesDOMParser* parser = new XercesDOMParser;
34  parser->setValidationScheme( XercesDOMParser::Val_Never );
35  parser->setDoNamespaces( false );
36  parser->setDoSchema( false );
37 
38  parser->parse(filename.c_str());
39 
40  DOMDocument* xmlDoc = parser->getDocument();
41  if (!xmlDoc) {
42  std::cout << "EcalTPGStripStatusXMLTranslator::Error parsing document" << std::endl;
43  return -1;
44  }
45 
46  DOMElement* elementRoot = xmlDoc->getDocumentElement();
47 
48  xuti::readHeader(elementRoot,header);
49 
50  delete parser;
52  return 0;
53  }
54 
56  const EcalCondHeader& header,
57  const EcalTPGStripStatus& record){
59 
60  std::fstream fs(filename.c_str(),ios::out);
61  fs<< dumpXML(header,record);
62 
64 
65  return 0;
66 }
67 
69 
70  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
71 
72  DOMLSSerializer* writer = impl->createLSSerializer();
73  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
74  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
75 
76  DOMDocumentType* doctype = impl->createDocumentType( cms::xerces::uStr("XML").ptr(), nullptr, nullptr );
77  DOMDocument* doc =
78  impl->createDocument( nullptr, cms::xerces::uStr(TPGStripStatus_tag.c_str()).ptr(), doctype );
79  DOMElement* root = doc->getDocumentElement();
80 
81  xuti::writeHeader(root,header);
82  std::string TCC_tag("TCC");
83  std::string TT_tag("TT");
84  std::string ST_tag("ST");
85  const EcalTPGStripStatusMap &stripMap = record.getMap();
86  std::cout << "EcalTPGStripStatusXMLTranslator::dumpXML strip map size " << stripMap.size() << std::endl;
88  for(itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
89  if(itSt->second > 0) {
90  int tccid = itSt->first/8192 & 0x7F;
91  int tt = itSt->first/64 & 0x7F;
92  int pseudostrip = itSt->first/8 & 0x7;
93  // std::cout << "Bad strip ID = " << itSt->first
94  // << " TCC " << tccid << " TT " << tt << " ST " << pseudostrip
95  // << ", status = " << itSt->second << std::endl;
96  DOMElement* cell_node =
97  root->getOwnerDocument()->createElement( cms::xerces::uStr(Cell_tag.c_str()).ptr());
98  stringstream value_s;
99  value_s << tccid ;
100  cell_node->setAttribute(cms::xerces::uStr(TCC_tag.c_str()).ptr(),
101  cms::xerces::uStr(value_s.str().c_str()).ptr());
102  value_s.str("");
103  value_s << tt ;
104  cell_node->setAttribute(cms::xerces::uStr(TT_tag.c_str()).ptr(),
105  cms::xerces::uStr(value_s.str().c_str()).ptr());
106  value_s.str("");
107  value_s << pseudostrip;
108  cell_node->setAttribute(cms::xerces::uStr(ST_tag.c_str()).ptr(),
109  cms::xerces::uStr(value_s.str().c_str()).ptr());
110  root->appendChild(cell_node);
111 
112  WriteNodeWithValue(cell_node, TPGStripStatus_tag, 1);
113  }
114  }
115 
116  std::string dump = cms::xerces::toString( writer->writeToString( root ));
117  doc->release();
118  doctype->release();
119  writer->release();
120  return dump;
121 }
def dumpXML(db, tag, since, filename='dump.xml')
JetCorrectorParameters::Record record
Definition: classes.h:7
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")
std::map< uint32_t, uint16_t > EcalTPGStripStatusMap
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalTPGStripStatus &record)
std::map< uint32_t, uint16_t >::const_iterator EcalTPGStripStatusMapIterator