CMS 3D CMS Logo

EcalWeightGroupXMLTranslator.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 
16 
17 using namespace XERCES_CPP_NAMESPACE;
18 using namespace xuti;
19 using namespace std;
20 
25 
26  XercesDOMParser* parser = new XercesDOMParser;
27  parser->setValidationScheme(XercesDOMParser::Val_Never);
28  parser->setDoNamespaces(false);
29  parser->setDoSchema(false);
30 
31  parser->parse(filename.c_str());
32 
33  DOMDocument* xmlDoc = parser->getDocument();
34  if (!xmlDoc) {
35  std::cout << "EcalWeightGroupXMLTranslator::Error parsing document" << std::endl;
36  return -1;
37  }
38 
39  DOMElement* elementRoot = xmlDoc->getDocumentElement();
40 
41  xuti::readHeader(elementRoot, header);
42  // get the first cell node
43  DOMNode* cellnode = getChildNode(elementRoot, Cell_tag);
44 
45  // loop on cell nodes
46  while (cellnode) {
47  unsigned int group = 0;
48 
49  // read id
50  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
51 
52  // read constant
53  DOMNode* c_node = getChildNode(cellnode, WeightGroup_tag);
54  GetNodeData(c_node, group);
55 
56  // fill record
57  record[detid] = EcalXtalGroupId(group);
58 
59  // get next cell
60  cellnode = cellnode->getNextSibling();
61 
62  while (cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
63  cellnode = cellnode->getNextSibling();
64  }
65 
66  delete parser;
68  return 0;
69 }
70 
72  const EcalCondHeader& header,
75 
76  std::fstream fs(filename.c_str(), ios::out);
77  fs << dumpXML(header, record);
78 
80 
81  return 0;
82 }
83 
85  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
86 
87  DOMLSSerializer* writer = impl->createLSSerializer();
88  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
89  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
90 
91  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
92  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(WeightGroups_tag.c_str()).ptr(), doctype);
93  DOMElement* root = doc->getDocumentElement();
94 
96 
97  for (int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) { // loop on EB cells
98 
99  uint32_t rawid = EBDetId::unhashIndex(cellid);
100 
101  //if (!record[rawid]) continue; // cell absent from original record
102 
103  DOMElement* cellnode = writeCell(root, rawid);
104 
105  WriteNodeWithValue(cellnode, WeightGroup_tag, record[rawid].id());
106 
107  } // loop on EB cells
108 
109  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) { // loop on EE cells
110 
111  if (!EEDetId::validHashIndex(cellid))
112  continue;
113 
114  uint32_t rawid = EEDetId::unhashIndex(cellid);
115  //xif (!record[rawid]) continue; // cell absent from original record
116 
117  DOMElement* cellnode = writeCell(root, rawid);
118  WriteNodeWithValue(cellnode, WeightGroup_tag, record[rawid].id());
119 
120  } // loop on EE cells
121 
122  std::string dump = cms::xerces::toString(writer->writeToString(root));
123  doc->release();
124  doctype->release();
125  writer->release();
126 
127  return dump;
128 }
xuti::getChildNode
xercesc::DOMNode * getChildNode(xercesc::DOMNode *node, const std::string &nodename)
get the child of
XercesStrUtils.h
common_cff.doc
doc
Definition: common_cff.py:54
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
xuti::writeCell
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
Definition: DOMHelperFunctions.cc:71
EEDetId::unhashIndex
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EBDetId::unhashIndex
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
EcalWeightGroupXMLTranslator::dumpXML
static std::string dumpXML(const EcalCondHeader &header, const EcalWeightXtalGroups &record)
Definition: EcalWeightGroupXMLTranslator.cc:84
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
cscNeutronWriter_cfi.writer
writer
Definition: cscNeutronWriter_cfi.py:6
EcalCondObjectContainer
Definition: EcalCondObjectContainer.h:13
EcalXtalGroupId
Definition: EcalXtalGroupId.h:11
DetId
Definition: DetId.h:17
cms::xerces::toString
std::string toString(XMLCh const *toTranscode)
Definition: XercesStrUtils.h:34
EEDetId::kSizeForDenseIndexing
Definition: EEDetId.h:329
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
EcalXtalGroupId.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DOMHelperFunctions.h
EcalCondHeader
Definition: EcalCondHeader.h:16
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
Xerces.h
cms::concurrency::xercesTerminate
void xercesTerminate()
Definition: Xerces.cc:23
xuti
Definition: DOMHelperFunctions.h:21
root
Definition: RooFitFunction.h:10
EEDetId::validHashIndex
static bool validHashIndex(int i)
Definition: EEDetId.h:239
cms::xerces::uStr
ZStr< XMLCh > uStr(char const *str)
Definition: XercesStrUtils.h:30
xuti::WeightGroups_tag
const std::string WeightGroups_tag("EcalWeightGroups")
impl
Definition: trackAlgoPriorityOrder.h:18
std
Definition: JetResolutionObject.h:76
EcalWeightGroupXMLTranslator::readXML
static int readXML(const std::string &filename, EcalCondHeader &header, EcalWeightXtalGroups &record)
Definition: EcalWeightGroupXMLTranslator.cc:21
EBDetId::kSizeForDenseIndexing
Definition: EBDetId.h:155
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
xuti::readCellId
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
Definition: DOMHelperFunctions.cc:24
EBDetId::MIN_HASH
static const int MIN_HASH
Definition: EBDetId.h:149
EcalWeightGroupXMLTranslator.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")
xuti::WeightGroup_tag
const std::string WeightGroup_tag("EcalWeightGroup")
EcalWeightGroupXMLTranslator::writeXML
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalWeightXtalGroups &record)
Definition: EcalWeightGroupXMLTranslator.cc:71
xuti::GetNodeData
void GetNodeData(xercesc::DOMNode *node, T &value)
get the node data
Definition: DOMHelperFunctions.h:38
watchdog.group
group
Definition: watchdog.py:82