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  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 
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 }
XercesStrUtils.h
submitPVValidationJobs.dump
dump
Definition: submitPVValidationJobs.py:55
EcalTPGStripStatusMap
std::map< uint32_t, uint16_t > EcalTPGStripStatusMap
Definition: EcalTPGStripStatus.h:24
EcalTPGStripStatusXMLTranslator.h
EcalCondTools.dumpXML
def dumpXML(db, tag, since, filename='dump.xml')
Definition: EcalCondTools.py:44
xuti::writeHeader
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
Definition: DOMHelperFunctions.cc:151
EcalTPGStripStatusRcd.h
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
boostedTaus_cff.doc
doc
Definition: boostedTaus_cff.py:20
gather_cfg.cout
cout
Definition: gather_cfg.py:144
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
cscNeutronWriter_cfi.writer
writer
Definition: cscNeutronWriter_cfi.py:6
EcalTPGStripStatusXMLTranslator::dumpXML
static std::string dumpXML(const EcalCondHeader &header, const EcalTPGStripStatus &record)
Definition: EcalTPGStripStatusXMLTranslator.cc:67
xuti::TPGStripStatus_tag
const std::string TPGStripStatus_tag("EcalTPGStripStatus")
cms::xerces::toString
std::string toString(XMLCh const *toTranscode)
Definition: XercesStrUtils.h:35
xuti::WriteNodeWithValue
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
Definition: DOMHelperFunctions.h:46
XERCES_CPP_NAMESPACE
Definition: XmlConfigParser.h:12
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
EcalSubdetector.h
DOMHelperFunctions.h
EcalCondHeader
Definition: EcalCondHeader.h:16
Xerces.h
cms::concurrency::xercesTerminate
void xercesTerminate()
Definition: Xerces.cc:23
EcalTPGStripStatusMapIterator
std::map< uint32_t, uint16_t >::const_iterator EcalTPGStripStatusMapIterator
Definition: EcalTPGStripStatus.h:25
xuti
Definition: DOMHelperFunctions.h:21
root
Definition: RooFitFunction.h:10
cms::xerces::uStr
ZStr< XMLCh > uStr(char const *str)
Definition: XercesStrUtils.h:31
AlCaHarvesting_cff.record
record
Definition: AlCaHarvesting_cff.py:42
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
impl
Definition: trackAlgoPriorityOrder.h:18
std
Definition: JetResolutionObject.h:76
EcalTPGStripStatusXMLTranslator::readXML
static int readXML(const std::string &filename, EcalCondHeader &header, EcalTPGStripStatus &record)
Definition: EcalTPGStripStatusXMLTranslator.cc:26
DetId.h
EcalTPGStripStatus
Definition: EcalTPGStripStatus.h:9
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:291
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
EcalTPGStripStatusXMLTranslator::writeXML
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalTPGStripStatus &record)
Definition: EcalTPGStripStatusXMLTranslator.cc:54
XMLTags.h
cms::concurrency::xercesInitialize
void xercesInitialize()
Definition: Xerces.cc:18
xuti::readHeader
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
Definition: DOMHelperFunctions.cc:164
xuti::Cell_tag
const std::string Cell_tag("cell")