CMS 3D CMS Logo

EcalPulseSymmCovariancesXMLTranslator.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <fstream>
4 #include <vector>
5 #include <xercesc/dom/DOMNode.hpp>
6 #include <xercesc/dom/DOM.hpp>
7 #include <xercesc/parsers/XercesDOMParser.hpp>
10 #include <xercesc/util/XMLString.hpp>
11 #include <xercesc/sax/SAXException.hpp>
12 #include <xercesc/framework/LocalFileFormatTarget.hpp>
13 #include <TString.h>
14 
19 
20 using namespace XERCES_CPP_NAMESPACE;
21 using namespace xuti;
22 using namespace std;
23 
28 
29  XercesDOMParser* parser = new XercesDOMParser;
30  parser->setValidationScheme(XercesDOMParser::Val_Never);
31  parser->setDoNamespaces(false);
32  parser->setDoSchema(false);
33 
34  parser->parse(filename.c_str());
35 
36  DOMDocument* xmlDoc = parser->getDocument();
37  if (!xmlDoc) {
38  std::cout << "EcalPulseSymmCovariancesXMLTranslator::Error parsing document" << std::endl;
39  return -1;
40  }
41 
42  DOMElement* elementRoot = xmlDoc->getDocumentElement();
43 
44  xuti::readHeader(elementRoot, header);
45 
46  DOMNode* cellnode = getChildNode(elementRoot, Cell_tag);
47 
48  int chan = 0;
49  while (cellnode) {
50  // std::cout << " Channel " << chan << std::endl;
52 
53  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
54  // std::cout << " readCell Id Channel " << chan << " tag " << mean12_tag << std::endl;
55 
56  std::vector<std::string> pulsecov_tag(
57  static_cast<size_t>(EcalPulseShape::TEMPLATESAMPLES * (EcalPulseShape::TEMPLATESAMPLES + 1) / 2));
58  for (int i = 0; i < EcalPulseShape::TEMPLATESAMPLES; ++i) {
59  for (int j = 0; j < EcalPulseShape::TEMPLATESAMPLES; ++j) {
60  int k = -1;
61  if (j >= i)
63  else
65  pulsecov_tag[k] = Form("samplecov_%d_%d", i, j);
66  }
67  }
68 
69  DOMNode** covs_node =
71  for (int k = 0; k < EcalPulseShape::TEMPLATESAMPLES * (EcalPulseShape::TEMPLATESAMPLES + 1) / 2; ++k) {
72  covs_node[k] = getChildNode(cellnode, pulsecov_tag[k]);
73  GetNodeData(covs_node[k], covs[k]);
74  }
75 
77  record[detid].covval[k] = covs[k];
78 
79  cellnode = cellnode->getNextSibling();
80 
81  while (cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
82  cellnode = cellnode->getNextSibling();
83  chan++;
84  }
85 
86  delete parser;
88  std::cout << " nb of channels found in xml file " << chan << std::endl;
89  return 0;
90 }
91 
93  const EcalCondHeader& header,
96 
97  std::fstream fs(filename.c_str(), ios::out);
98  fs << dumpXML(header, record);
99 
101 
102  return 0;
103 }
104 
107  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
108 
109  DOMLSSerializer* writer = impl->createLSSerializer();
110  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
111  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
112 
113  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
114  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(PulseSymmCovariances_tag.c_str()).ptr(), doctype);
115 
116  DOMElement* root = doc->getDocumentElement();
117 
118  std::vector<std::string> pulsecov_tag(static_cast<size_t>(std::pow(EcalPulseShape::TEMPLATESAMPLES, 2)));
119  for (int k = 0; k < std::pow(EcalPulseShape::TEMPLATESAMPLES, 2); ++k) {
122  int linK = -1;
123  if (j >= i)
124  linK = j + (EcalPulseShape::TEMPLATESAMPLES - 1) * i;
125  else
126  linK = i + (EcalPulseShape::TEMPLATESAMPLES - 1) * j;
127  pulsecov_tag[linK] = Form("samplecov_%d_%d", i, j);
128  }
129 
131  if (record.barrelItems().empty())
132  return std::string();
133  for (int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {
134  uint32_t rawid = EBDetId::unhashIndex(cellid);
135 
136  if (record.find(rawid) == record.end())
137  continue;
138 
139  DOMElement* cellnode = writeCell(root, rawid);
140 
141  for (int k = 0; k < std::pow(EcalPulseShape::TEMPLATESAMPLES, 2); ++k) {
142  WriteNodeWithValue(cellnode, pulsecov_tag[k], record[rawid].covval[k]);
143  }
144  }
145  if (record.endcapItems().empty())
146  return std::string();
147  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {
148  if (!EEDetId::validHashIndex(cellid))
149  continue;
150 
151  uint32_t rawid = EEDetId::unhashIndex(cellid);
152 
153  if (record.find(rawid) == record.end())
154  continue;
155 
156  DOMElement* cellnode = writeCell(root, rawid);
157 
158  for (int k = 0; k < std::pow(EcalPulseShape::TEMPLATESAMPLES, 2); ++k) {
159  WriteNodeWithValue(cellnode, pulsecov_tag[k], record[rawid].covval[k]);
160  }
161  }
162 
163  std::string dump = cms::xerces::toString(writer->writeToString(root));
164  doc->release();
165  doctype->release();
166  writer->release();
167 
168  return dump;
169 }
xuti::getChildNode
xercesc::DOMNode * getChildNode(xercesc::DOMNode *node, const std::string &nodename)
get the child of
XercesStrUtils.h
EcalPulseSymmCovariancesXMLTranslator::dumpXML
static std::string dumpXML(const EcalCondHeader &header, const EcalPulseSymmCovariances &record)
Definition: EcalPulseSymmCovariancesXMLTranslator.cc:105
common_cff.doc
doc
Definition: common_cff.py:54
mps_fire.i
i
Definition: mps_fire.py:428
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
EcalPulseSymmCovariancesXMLTranslator.h
EcalPulseSymmCovariancesXMLTranslator::readXML
static int readXML(const std::string &filename, EcalCondHeader &header, EcalPulseSymmCovariances &record)
Definition: EcalPulseSymmCovariancesXMLTranslator.cc:24
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
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
xuti::PulseSymmCovariances_tag
const std::string PulseSymmCovariances_tag("EcalPulseSymmCovariances")
EcalPulseSymmCovariancesXMLTranslator::writeXML
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalPulseSymmCovariances &record)
Definition: EcalPulseSymmCovariancesXMLTranslator.cc:92
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
dqmdumpme.k
k
Definition: dqmdumpme.py:60
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
createfilelist.int
int
Definition: createfilelist.py:10
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
impl
Definition: trackAlgoPriorityOrder.h:18
std
Definition: JetResolutionObject.h:76
officialStyle.chan
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi....
Definition: officialStyle.py:106
EcalPulseSymmCovariances.h
EcalPulseShape::TEMPLATESAMPLES
static const int TEMPLATESAMPLES
Definition: EcalPulseShapes.h:10
EBDetId::kSizeForDenseIndexing
Definition: EBDetId.h:155
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
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
XMLTags.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
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::GetNodeData
void GetNodeData(xercesc::DOMNode *node, T &value)
get the node data
Definition: DOMHelperFunctions.h:38