CMS 3D CMS Logo

List of all members | Static Public Member Functions | Static Private Member Functions
EcalWeightGroupXMLTranslator Class Reference

#include <EcalWeightGroupXMLTranslator.h>

Static Public Member Functions

static int readXML (const std::string &filename, EcalCondHeader &header, EcalWeightXtalGroups &record)
 
static int writeXML (const std::string &filename, const EcalCondHeader &header, const EcalWeightXtalGroups &record)
 

Static Private Member Functions

static std::string dumpXML (const EcalCondHeader &header, const EcalWeightXtalGroups &record)
 

Detailed Description

Translates a EcalWeightGroup record to XML and vice versa

Author
Stefano ARGIRO
Version
Id
EcalWeightGroupXMLTranslator.h,v 1.2 2009/06/30 14:40:11 argiro Exp
Date
20 Jun 2008

Definition at line 17 of file EcalWeightGroupXMLTranslator.h.

Member Function Documentation

◆ dumpXML()

std::string EcalWeightGroupXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalWeightXtalGroups record 
)
staticprivate

Definition at line 84 of file EcalWeightGroupXMLTranslator.cc.

References boostedTaus_cff::doc, submitPVValidationJobs::dump, RecoTauValidation_cfi::header, EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, AlCaHarvesting_cff::record, AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toString(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), cms::xerces::uStr(), EEDetId::validHashIndex(), xuti::WeightGroup_tag(), xuti::WeightGroups_tag(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), and convertToRaw::writer.

84  {
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 }
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
static bool validHashIndex(int i)
Definition: EEDetId.h:239
const std::string WeightGroup_tag("EcalWeightGroup")
std::string toString(XMLCh const *toTranscode)
static const int MIN_HASH
Definition: EBDetId.h:149
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
ZStr< XMLCh > uStr(char const *str)
const std::string WeightGroups_tag("EcalWeightGroups")
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.

◆ readXML()

int EcalWeightGroupXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalWeightXtalGroups record 
)
static

Definition at line 21 of file EcalWeightGroupXMLTranslator.cc.

References xuti::Cell_tag(), gather_cfg::cout, corrVsCorr::filename, xuti::getChildNode(), xuti::GetNodeData(), watchdog::group, RecoTauValidation_cfi::header, writedatasetfile::parser, xuti::readCellId(), xuti::readHeader(), AlCaHarvesting_cff::record, xuti::WeightGroup_tag(), cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

23  {
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 }
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18
const std::string WeightGroup_tag("EcalWeightGroup")
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
const std::string Cell_tag("cell")
Definition: DetId.h:17
void GetNodeData(xercesc::DOMNode *node, T &value)
get the node data
xercesc::DOMNode * getChildNode(xercesc::DOMNode *node, const std::string &nodename)
get the child of
const DetId readCellId(xercesc::DOMElement *node)
Assuming.

◆ writeXML()

int EcalWeightGroupXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalWeightXtalGroups record 
)
static