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
EcalGainRatiosXMLTranslator Class Reference

#include <EcalGainRatiosXMLTranslator.h>

Static Public Member Functions

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

Detailed Description

Translates a EcalGainRatio record to XML and vice versa

Author
Francesco RUBBO
Version
Id:
EcalGainRatiosXMLTranslator.h,v 1.1 2008/11/14 15:46:05 argiro Exp
Date
29 Jul 2008

Definition at line 20 of file EcalGainRatiosXMLTranslator.h.

Member Function Documentation

std::string EcalGainRatiosXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalGainRatios record 
)
static

Definition at line 97 of file EcalGainRatiosXMLTranslator.cc.

References EcalCondObjectContainer< T >::barrelItems(), hcal_timing_source_file_cfg::dump, EcalCondObjectContainer< T >::end(), EcalCondObjectContainer< T >::endcapItems(), EcalCondObjectContainer< T >::find(), xuti::fromNative(), xuti::Gain12Over6_tag(), xuti::Gain6Over1_tag(), xuti::GainRatios_tag(), EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, pyrootRender::root, AlCaHLTBitMon_QueryRunRegistry::string, xuti::toNative(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), EEDetId::validHashIndex(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), and cms::concurrency::xercesInitialize().

97  {
98 
100 
101  DOMImplementation* impl =
102  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
103 
104  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
105  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
106 
107  DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
108  DOMDocument * doc =
109  impl->createDocument( 0, fromNative(GainRatios_tag).c_str(), doctype );
110 
111 
112  doc->setEncoding(fromNative("UTF-8").c_str() );
113  doc->setStandalone(true);
114  doc->setVersion(fromNative("1.0").c_str() );
115 
116 
117  DOMElement* root = doc->getDocumentElement();
118 
119 
120 
121  xuti::writeHeader(root,header);
122  if (!record.barrelItems().size()) return std::string();
123  for(int cellid = EBDetId::MIN_HASH;
125  ++cellid)
126  {
127 
128  uint32_t rawid = EBDetId::unhashIndex(cellid);
129 
130  if (record.find(rawid) == record.end()) continue;
131  if(!record[rawid].gain12Over6() && !record[rawid].gain6Over1()) continue;
132 
133  DOMElement* cellnode=writeCell(root,rawid);
134 
135  WriteNodeWithValue(cellnode,Gain12Over6_tag,record[rawid].gain12Over6());
136  WriteNodeWithValue(cellnode,Gain6Over1_tag,record[rawid].gain6Over1());
137  }
138 
139  if (!record.endcapItems().size()) return std::string();
140  for(int cellid = 0;
142  ++cellid)
143  {
144  if(!EEDetId::validHashIndex(cellid)) continue;
145 
146  uint32_t rawid = EEDetId::unhashIndex(cellid);
147 
148  if (record.find(rawid) == record.end()) continue;
149  if(!record[rawid].gain12Over6() && !record[rawid].gain6Over1()) continue;
150 
151  DOMElement* cellnode=writeCell(root,rawid);
152 
153  WriteNodeWithValue(cellnode,Gain12Over6_tag,record[rawid].gain12Over6());
154  WriteNodeWithValue(cellnode,Gain6Over1_tag,record[rawid].gain6Over1());
155 
156 
157  }
158 
159 
160  std::string dump= toNative(writer->writeToString(*root));
161  doc->release();
162  return dump;
163 }
const std::string Gain6Over1_tag("Gain6Over1")
const Items & barrelItems() const
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
static const int MIN_HASH
Definition: EBDetId.h:156
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
const_iterator find(uint32_t rawId) const
XercesString fromNative(const char *str)
Definition: XercesString.h:31
const_iterator end() const
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
const std::string GainRatios_tag("EcalGainRatios")
const Items & endcapItems() const
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
const std::string Gain12Over6_tag("Gain12Over6")
int EcalGainRatiosXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalGainRatios record 
)
static

Definition at line 28 of file EcalGainRatiosXMLTranslator.cc.

References xuti::Cell_tag(), gather_cfg::cout, xuti::Gain12Over6_tag(), xuti::Gain6Over1_tag(), xuti::getChildNode(), xuti::GetNodeData(), createfilelist::parser, xuti::readCellId(), xuti::readHeader(), cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

30  {
31 
32 
33 
35 
36  XercesDOMParser* parser = new XercesDOMParser;
37  parser->setValidationScheme( XercesDOMParser::Val_Never );
38  parser->setDoNamespaces( false );
39  parser->setDoSchema( false );
40 
41  parser->parse(filename.c_str());
42 
43  DOMDocument* xmlDoc = parser->getDocument();
44  if (!xmlDoc) {
45  std::cout << "EcalGainRatiosXMLTranslator::Error parsing document" << std::endl;
46  return -1;
47  }
48 
49  DOMElement* elementRoot = xmlDoc->getDocumentElement();
50 
51  xuti::readHeader(elementRoot,header);
52 
53  DOMNode * cellnode = getChildNode(elementRoot,Cell_tag);
54 
55  while(cellnode)
56  {
57  float g12_6 = 0;
58  float g6_1 = 0;
59  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
60 
61  DOMNode* g12_6_node = getChildNode(cellnode,Gain12Over6_tag);
62  GetNodeData(g12_6_node,g12_6);
63 
64  DOMNode* g6_1_node = getChildNode(cellnode,Gain6Over1_tag);
65  GetNodeData(g6_1_node,g6_1);
66 
67  record[detid].setGain12Over6(g12_6);
68  record[detid].setGain6Over1(g6_1);
69 
70  cellnode = cellnode->getNextSibling();
71 
72  while(cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
73  cellnode = cellnode->getNextSibling();
74 
75  }
76 
77  delete parser;
79  return 0;
80 
81 
82 }
const std::string Gain6Over1_tag("Gain6Over1")
void xercesTerminate()
Definition: Xerces.cc:22
void xercesInitialize()
Definition: Xerces.cc:17
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
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:145
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
const std::string Gain12Over6_tag("Gain12Over6")
int EcalGainRatiosXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalGainRatios record 
)
static

Definition at line 88 of file EcalGainRatiosXMLTranslator.cc.

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

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