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

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

Definition at line 89 of file EcalWeightGroupXMLTranslator.cc.

References boostedTaus_cff::doc, FrontierConditions_GlobalTag_cff::dump, EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, 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 cscNeutronWriter_cfi::writer.

90  {
91 
92  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
93 
94  DOMLSSerializer* writer = impl->createLSSerializer();
95  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
96  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
97 
98  DOMDocumentType* doctype = impl->createDocumentType( cms::xerces::uStr("XML").ptr(), nullptr, nullptr );
99  DOMDocument* doc = impl->createDocument( nullptr, cms::xerces::uStr(WeightGroups_tag.c_str()).ptr(), doctype );
100  DOMElement* root = doc->getDocumentElement();
101 
102  xuti::writeHeader(root,header);
103 
104  for (int cellid = EBDetId::MIN_HASH;
106  ++cellid){// loop on EB cells
107 
108  uint32_t rawid= EBDetId::unhashIndex(cellid);
109 
110  //if (!record[rawid]) continue; // cell absent from original record
111 
112  DOMElement* cellnode=writeCell(root,rawid);
113 
114  WriteNodeWithValue(cellnode,WeightGroup_tag,record[rawid].id());
115 
116 
117  } // loop on EB cells
118 
119 
120 
121  for (int cellid = 0;
123  ++cellid){// loop on EE cells
124 
125  if (!EEDetId::validHashIndex(cellid)) continue;
126 
127  uint32_t rawid= EEDetId::unhashIndex(cellid);
128  //xif (!record[rawid]) continue; // cell absent from original record
129 
130 
131  DOMElement* cellnode=writeCell(root,rawid);
132  WriteNodeWithValue(cellnode,WeightGroup_tag,record[rawid].id());
133 
134  } // loop on EE cells
135 
136  std::string dump = cms::xerces::toString( writer->writeToString( root ));
137  doc->release();
138  doctype->release();
139  writer->release();
140 
141  return dump;
142 }
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.
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, xuti::getChildNode(), xuti::GetNodeData(), edmIntegrityCheck::group, writedatasetfile::parser, xuti::readCellId(), xuti::readHeader(), xuti::WeightGroup_tag(), cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

23  {
24 
26 
27  XercesDOMParser* parser = new XercesDOMParser;
28  parser->setValidationScheme( XercesDOMParser::Val_Never );
29  parser->setDoNamespaces( false );
30  parser->setDoSchema( false );
31 
32  parser->parse(filename.c_str());
33 
34  DOMDocument* xmlDoc = parser->getDocument();
35  if (!xmlDoc) {
36  std::cout << "EcalWeightGroupXMLTranslator::Error parsing document" << std::endl;
37  return -1;
38  }
39 
40  DOMElement* elementRoot = xmlDoc->getDocumentElement();
41 
42  xuti::readHeader(elementRoot,header);
43  // get the first cell node
44  DOMNode * cellnode=getChildNode(elementRoot,Cell_tag);
45 
46  // loop on cell nodes
47  while (cellnode){
48 
49  unsigned int group=0;
50 
51  // read id
52  DetId detid= readCellId(dynamic_cast<DOMElement*> (cellnode));
53 
54  // read constant
55  DOMNode * c_node = getChildNode(cellnode,WeightGroup_tag);
56  GetNodeData(c_node,group);
57 
58  // fill record
59  record[detid]=EcalXtalGroupId(group);
60 
61  // get next cell
62  cellnode= cellnode->getNextSibling();
63 
64  while (cellnode&& cellnode->getNodeType( ) != DOMNode::ELEMENT_NODE)
65  cellnode= cellnode->getNextSibling();
66 
67  }
68 
69  delete parser;
71  return 0;
72 
73 }
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:18
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.
int EcalWeightGroupXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalWeightXtalGroups record 
)
static

Definition at line 75 of file EcalWeightGroupXMLTranslator.cc.

References EcalCondTools::dumpXML(), MillePedeFileConverter_cfg::out, AlCaHLTBitMon_QueryRunRegistry::string, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

77  {
79 
80  std::fstream fs(filename.c_str(),ios::out);
81  fs<< dumpXML(header,record);
82 
84 
85  return 0;
86 }
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18
static std::string dumpXML(const EcalCondHeader &header, const EcalWeightXtalGroups &record)