CMS 3D CMS Logo

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

#include <EcalGainRatiosXMLTranslator.h>

Static Public Member Functions

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

Static Private Member Functions

static std::string dumpXML (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 16 of file EcalGainRatiosXMLTranslator.h.

Member Function Documentation

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

Definition at line 88 of file EcalGainRatiosXMLTranslator.cc.

References EcalCondObjectContainer< T >::barrelItems(), common_cff::doc, FrontierConditions_GlobalTag_cff::dump, EcalCondObjectContainer< T >::end(), EcalCondObjectContainer< T >::endcapItems(), EcalCondObjectContainer< T >::find(), xuti::Gain12Over6_tag(), xuti::Gain6Over1_tag(), xuti::GainRatios_tag(), EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toString(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), cms::xerces::uStr(), EEDetId::validHashIndex(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), and cscNeutronWriter_cfi::writer.

88  {
89 
90  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
91 
92  DOMLSSerializer* writer = impl->createLSSerializer();
93  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
94  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
95 
96  DOMDocumentType* doctype = impl->createDocumentType( cms::xerces::uStr("XML").ptr(), nullptr, nullptr );
97  DOMDocument* doc = impl->createDocument( nullptr, cms::xerces::uStr(GainRatios_tag.c_str()).ptr(), doctype );
98  DOMElement* root = doc->getDocumentElement();
99 
100  xuti::writeHeader(root,header);
101  if (record.barrelItems().empty()) return std::string();
102  for(int cellid = EBDetId::MIN_HASH;
104  ++cellid)
105  {
106 
107  uint32_t rawid = EBDetId::unhashIndex(cellid);
108 
109  if (record.find(rawid) == record.end()) continue;
110  if(!record[rawid].gain12Over6() && !record[rawid].gain6Over1()) continue;
111 
112  DOMElement* cellnode=writeCell(root,rawid);
113 
114  WriteNodeWithValue(cellnode,Gain12Over6_tag,record[rawid].gain12Over6());
115  WriteNodeWithValue(cellnode,Gain6Over1_tag,record[rawid].gain6Over1());
116  }
117 
118  if (record.endcapItems().empty()) return std::string();
119  for(int cellid = 0;
121  ++cellid)
122  {
123  if(!EEDetId::validHashIndex(cellid)) continue;
124 
125  uint32_t rawid = EEDetId::unhashIndex(cellid);
126 
127  if (record.find(rawid) == record.end()) continue;
128  if(!record[rawid].gain12Over6() && !record[rawid].gain6Over1()) continue;
129 
130  DOMElement* cellnode=writeCell(root,rawid);
131 
132  WriteNodeWithValue(cellnode,Gain12Over6_tag,record[rawid].gain12Over6());
133  WriteNodeWithValue(cellnode,Gain6Over1_tag,record[rawid].gain6Over1());
134 
135 
136  }
137 
138 
139  std::string dump = cms::xerces::toString( writer->writeToString( root ));
140  doc->release();
141  doctype->release();
142  writer->release();
143 
144  return dump;
145 }
const std::string Gain6Over1_tag("Gain6Over1")
const Items & barrelItems() const
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
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)
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
const_iterator find(uint32_t rawId) const
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
const std::string Gain12Over6_tag("Gain12Over6")
int EcalGainRatiosXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalGainRatios record 
)
static

Definition at line 22 of file EcalGainRatiosXMLTranslator.cc.

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

24  {
25 
27 
28  XercesDOMParser* parser = new XercesDOMParser;
29  parser->setValidationScheme( XercesDOMParser::Val_Never );
30  parser->setDoNamespaces( false );
31  parser->setDoSchema( false );
32 
33  parser->parse(filename.c_str());
34 
35  DOMDocument* xmlDoc = parser->getDocument();
36  if (!xmlDoc) {
37  std::cout << "EcalGainRatiosXMLTranslator::Error parsing document" << std::endl;
38  return -1;
39  }
40 
41  DOMElement* elementRoot = xmlDoc->getDocumentElement();
42 
43  xuti::readHeader(elementRoot,header);
44 
45  DOMNode * cellnode = getChildNode(elementRoot,Cell_tag);
46 
47  while(cellnode)
48  {
49  float g12_6 = 0;
50  float g6_1 = 0;
51  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
52 
53  DOMNode* g12_6_node = getChildNode(cellnode,Gain12Over6_tag);
54  GetNodeData(g12_6_node,g12_6);
55 
56  DOMNode* g6_1_node = getChildNode(cellnode,Gain6Over1_tag);
57  GetNodeData(g6_1_node,g6_1);
58 
59  record[detid].setGain12Over6(g12_6);
60  record[detid].setGain6Over1(g6_1);
61 
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 }
const std::string Gain6Over1_tag("Gain6Over1")
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18
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.
const std::string Gain12Over6_tag("Gain12Over6")
int EcalGainRatiosXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalGainRatios record 
)
static

Definition at line 74 of file EcalGainRatiosXMLTranslator.cc.

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

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