CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Static Public Member Functions
EcalWeightGroupXMLTranslator Class Reference

#include <EcalWeightGroupXMLTranslator.h>

Static Public Member Functions

static std::string dumpXML (const EcalCondHeader &header, const EcalWeightXtalGroups &record)
 
static int readXML (const std::string &filename, EcalCondHeader &header, EcalWeightXtalGroups &record)
 
static int writeXML (const std::string &filename, 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 21 of file EcalWeightGroupXMLTranslator.h.

Member Function Documentation

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

Definition at line 98 of file EcalWeightGroupXMLTranslator.cc.

References hcal_timing_source_file_cfg::dump, xuti::fromNative(), EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, pyrootRender::root, AlCaHLTBitMon_QueryRunRegistry::string, xuti::toNative(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), EEDetId::validHashIndex(), xuti::WeightGroup_tag(), xuti::WeightGroups_tag(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), and cms::concurrency::xercesInitialize().

99  {
100 
102 
103  DOMImplementation* impl =
104  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
105 
106  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
107  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
108 
109  DOMDocumentType* doctype = impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
110  DOMDocument * doc =
111  impl->createDocument( 0, fromNative(WeightGroups_tag).c_str(), doctype );
112 
113 
114  doc->setEncoding(fromNative("UTF-8").c_str() );
115  doc->setStandalone(true);
116  doc->setVersion(fromNative("1.0").c_str() );
117 
118 
119  DOMElement* root = doc->getDocumentElement();
120 
121  xuti::writeHeader(root,header);
122 
123  for (int cellid = EBDetId::MIN_HASH;
125  ++cellid){// loop on EB cells
126 
127  uint32_t rawid= EBDetId::unhashIndex(cellid);
128 
129  //if (!record[rawid]) continue; // cell absent from original record
130 
131  DOMElement* cellnode=writeCell(root,rawid);
132 
133  WriteNodeWithValue(cellnode,WeightGroup_tag,record[rawid].id());
134 
135 
136  } // loop on EB cells
137 
138 
139 
140  for (int cellid = 0;
142  ++cellid){// loop on EE cells
143 
144  if (!EEDetId::validHashIndex(cellid)) continue;
145 
146  uint32_t rawid= EEDetId::unhashIndex(cellid);
147  //xif (!record[rawid]) continue; // cell absent from original record
148 
149 
150  DOMElement* cellnode=writeCell(root,rawid);
151  WriteNodeWithValue(cellnode,WeightGroup_tag,record[rawid].id());
152 
153  } // loop on EE cells
154 
155 
156  std::string dump= toNative(writer->writeToString(*root));
157  doc->release();
158  // cms::concurrency::xercesTerminate();
159 
160  return dump;
161 
162 }
void xercesInitialize()
Definition: Xerces.cc:17
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
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")
static const int MIN_HASH
Definition: EBDetId.h:156
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
const std::string WeightGroups_tag("EcalWeightGroups")
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
XercesString fromNative(const char *str)
Definition: XercesString.h:31
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
int EcalWeightGroupXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalWeightXtalGroups record 
)
static

Definition at line 24 of file EcalWeightGroupXMLTranslator.cc.

References xuti::Cell_tag(), gather_cfg::cout, xuti::getChildNode(), xuti::GetNodeData(), watchdog::group, mps_alisetup::parser, xuti::readCellId(), xuti::readHeader(), xuti::WeightGroup_tag(), cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

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

Definition at line 86 of file EcalWeightGroupXMLTranslator.cc.

References EcalCondTools::dumpXML(), and GenerateHcalLaserBadRunList::out.

88  {
89  std::fstream fs(filename.c_str(),ios::out);
90  fs<< dumpXML(header,record);
91  return 0;
92 
93 }
static std::string dumpXML(const EcalCondHeader &header, const EcalWeightXtalGroups &record)
tuple filename
Definition: lut2db_cfg.py:20