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

#include <EcalPulseCovariancesXMLTranslator.h>

Static Public Member Functions

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

Detailed Description

Translates a EcalGainRatio record to XML and vice versa

Author
Francesco RUBBO
Version
Id:
EcalPulseCovariancesXMLTranslator.h,v 0 2010/04/26 fay Exp
Date
26 Apr 2010

Definition at line 20 of file EcalPulseCovariancesXMLTranslator.h.

Member Function Documentation

std::string EcalPulseCovariancesXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalPulseCovariances record 
)
static

Definition at line 92 of file EcalPulseCovariancesXMLTranslator.cc.

References EcalCondObjectContainer< T >::barrelItems(), asciidump::doc, hcal_timing_source_file_cfg::dump, EcalCondObjectContainer< T >::end(), EcalCondObjectContainer< T >::endcapItems(), EcalCondObjectContainer< T >::find(), xuti::fromNative(), i, j, relval_steps::k, EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, funct::pow(), xuti::PulseCovariances_tag(), dbtoconf::root, AlCaHLTBitMon_QueryRunRegistry::string, EcalPulseShape::TEMPLATESAMPLES, xuti::toNative(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), EEDetId::validHashIndex(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), and cms::concurrency::xercesInitialize().

Referenced by cond::PayLoadInspector< DataT >::dump().

92  {
93 
95  DOMImplementation* impl =
96  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
97 
98  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
99  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
100 
101  DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
102  DOMDocument * doc =
103  impl->createDocument( 0, fromNative(PulseCovariances_tag).c_str(), doctype );
104 
105  doc->setEncoding(fromNative("UTF-8").c_str() );
106  doc->setStandalone(true);
107  doc->setVersion(fromNative("1.0").c_str() );
108 
109  DOMElement* root = doc->getDocumentElement();
110 
111  std::vector<std::string> pulsecov_tag(static_cast<size_t>(std::pow(EcalPulseShape::TEMPLATESAMPLES,2)));
112  for(int k=0; k<std::pow(EcalPulseShape::TEMPLATESAMPLES,2); ++k) {
115  pulsecov_tag[k] = Form("samplecov_%d_%d",i,j);
116  }
117 
118  xuti::writeHeader(root,header);
119  if (!record.barrelItems().size()) return std::string();
120  for(int cellid = EBDetId::MIN_HASH;
122  ++cellid) {
123  uint32_t rawid = EBDetId::unhashIndex(cellid);
124 
125  if (record.find(rawid) == record.end()) continue;
126 
127  DOMElement* cellnode=writeCell(root,rawid);
128 
130  WriteNodeWithValue(cellnode,pulsecov_tag[i*EcalPulseShape::TEMPLATESAMPLES+j],record[rawid].covval[i][j]);
131 
132  }
133 
134  if (!record.endcapItems().size()) return std::string();
135  for(int cellid = 0;
137  ++cellid) {
138  if(!EEDetId::validHashIndex(cellid)) continue;
139 
140  uint32_t rawid = EEDetId::unhashIndex(cellid);
141 
142  if (record.find(rawid) == record.end()) continue;
143 
144  DOMElement* cellnode=writeCell(root,rawid);
145 
147  WriteNodeWithValue(cellnode,pulsecov_tag[i*EcalPulseShape::TEMPLATESAMPLES+j],record[rawid].covval[i][j]);
148 
149  }
150 
151  std::string dump= toNative(writer->writeToString(*root));
152  doc->release();
153  return dump;
154 }
int i
Definition: DBlmapReader.cc:9
const Items & barrelItems() const
static const int TEMPLATESAMPLES
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
int j
Definition: DBlmapReader.cc:9
tuple doc
Definition: asciidump.py:381
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
const std::string PulseCovariances_tag("EcalPulseCovariances")
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 Items & endcapItems() const
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
string root
initialization
Definition: dbtoconf.py:70
int EcalPulseCovariancesXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalPulseCovariances record 
)
static

Definition at line 24 of file EcalPulseCovariancesXMLTranslator.cc.

References xuti::Cell_tag(), gather_cfg::cout, cond::rpcobgas::detid, xuti::getChildNode(), i, j, relval_steps::k, geometryXMLtoCSV::parser, funct::pow(), xuti::readCellId(), xuti::readHeader(), EcalPulseShape::TEMPLATESAMPLES, 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 << "EcalPulseCovariancesXMLTranslator::Error parsing document" << std::endl;
40  return -1;
41  }
42 
43  DOMElement* elementRoot = xmlDoc->getDocumentElement();
44 
45  xuti::readHeader(elementRoot,header);
46 
47  DOMNode * cellnode = getChildNode(elementRoot,Cell_tag);
48 
49  int chan = 0;
50  while(cellnode) {
51  // std::cout << " Channel " << chan << std::endl;
53 
54  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
55  // std::cout << " readCell Id Channel " << chan << " tag " << mean12_tag << std::endl;
56 
57  std::vector<std::string> pulsecov_tag(static_cast<size_t>(std::pow(EcalPulseShape::TEMPLATESAMPLES,2)));
58  for(int k=0; k<std::pow(EcalPulseShape::TEMPLATESAMPLES,2); ++k) {
61  pulsecov_tag[k] = Form("samplecov_%d_%d",i,j);
62  }
63 
64  DOMNode** covs_node = new DOMNode*[int(std::pow(EcalPulseShape::TEMPLATESAMPLES,2))];
65  for(int k=0; k<std::pow(EcalPulseShape::TEMPLATESAMPLES,2); ++k)
66  covs_node[k] = getChildNode(cellnode,pulsecov_tag[k]);
67 
68  for(int i=0; i<EcalPulseShape::TEMPLATESAMPLES; ++i) for(int j=0; j<EcalPulseShape::TEMPLATESAMPLES; ++j) record[detid].covval[i][j] = covs[i][j];
69 
70  cellnode = cellnode->getNextSibling();
71 
72  while(cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
73  cellnode = cellnode->getNextSibling();
74  chan++;
75  }
76 
77  delete parser;
79  std::cout << " nb of channels found in xml file " << chan << std::endl;
80  return 0;
81  }
int i
Definition: DBlmapReader.cc:9
void xercesTerminate()
Definition: Xerces.cc:22
static const int TEMPLATESAMPLES
void xercesInitialize()
Definition: Xerces.cc:17
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
const std::string Cell_tag("cell")
int j
Definition: DBlmapReader.cc:9
Definition: DetId.h:18
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:121
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
int EcalPulseCovariancesXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalPulseCovariances record 
)
static

Definition at line 83 of file EcalPulseCovariancesXMLTranslator.cc.

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

85  {
86  std::fstream fs(filename.c_str(),ios::out);
87  fs<< dumpXML(header,record);
88  return 0;
89 }
static std::string dumpXML(const EcalCondHeader &header, const EcalPulseCovariances &record)
tuple out
Definition: dbtoconf.py:99
tuple filename
Definition: lut2db_cfg.py:20