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

#include <EcalPulseShapesXMLTranslator.h>

Static Public Member Functions

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

Detailed Description

Translates a EcalGainRatio record to XML and vice versa

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

Definition at line 20 of file EcalPulseShapesXMLTranslator.h.

Member Function Documentation

std::string EcalPulseShapesXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalPulseShapes record 
)
static

Definition at line 128 of file EcalPulseShapesXMLTranslator.cc.

References EcalCondObjectContainer< T >::barrelItems(), asciidump::doc, hcal_timing_source_file_cfg::dump, EcalCondObjectContainer< T >::end(), EcalCondObjectContainer< T >::endcapItems(), EcalCondObjectContainer< T >::find(), xuti::fromNative(), EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, xuti::PulseShapes_tag(), dbtoconf::root, xuti::sample0_tag(), xuti::sample10_tag(), xuti::sample11_tag(), xuti::sample1_tag(), xuti::sample2_tag(), xuti::sample3_tag(), xuti::sample4_tag(), xuti::sample5_tag(), xuti::sample6_tag(), xuti::sample7_tag(), xuti::sample8_tag(), xuti::sample9_tag(), AlCaHLTBitMon_QueryRunRegistry::string, xuti::toNative(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), EEDetId::validHashIndex(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), and cms::concurrency::xercesInitialize().

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

128  {
129 
131  DOMImplementation* impl =
132  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
133 
134  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
135  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
136 
137  DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
138  DOMDocument * doc =
139  impl->createDocument( 0, fromNative(PulseShapes_tag).c_str(), doctype );
140 
141  doc->setEncoding(fromNative("UTF-8").c_str() );
142  doc->setStandalone(true);
143  doc->setVersion(fromNative("1.0").c_str() );
144 
145  DOMElement* root = doc->getDocumentElement();
146 
147  xuti::writeHeader(root,header);
148  if (!record.barrelItems().size()) return std::string();
149  for(int cellid = EBDetId::MIN_HASH;
151  ++cellid) {
152  uint32_t rawid = EBDetId::unhashIndex(cellid);
153 
154  if (record.find(rawid) == record.end()) continue;
155  if(!record[rawid].pdfval[5]) continue;
156 
157  DOMElement* cellnode=writeCell(root,rawid);
158 
159  WriteNodeWithValue(cellnode,sample0_tag,record[rawid].pdfval[0]);
160  WriteNodeWithValue(cellnode,sample1_tag,record[rawid].pdfval[1]);
161  WriteNodeWithValue(cellnode,sample2_tag,record[rawid].pdfval[2]);
162  WriteNodeWithValue(cellnode,sample3_tag,record[rawid].pdfval[3]);
163  WriteNodeWithValue(cellnode,sample4_tag,record[rawid].pdfval[4]);
164  WriteNodeWithValue(cellnode,sample5_tag,record[rawid].pdfval[5]);
165  WriteNodeWithValue(cellnode,sample6_tag,record[rawid].pdfval[6]);
166  WriteNodeWithValue(cellnode,sample7_tag,record[rawid].pdfval[7]);
167  WriteNodeWithValue(cellnode,sample8_tag,record[rawid].pdfval[8]);
168  WriteNodeWithValue(cellnode,sample9_tag,record[rawid].pdfval[9]);
169  WriteNodeWithValue(cellnode,sample10_tag,record[rawid].pdfval[10]);
170  WriteNodeWithValue(cellnode,sample11_tag,record[rawid].pdfval[11]);
171 
172  }
173 
174  if (!record.endcapItems().size()) return std::string();
175  for(int cellid = 0;
177  ++cellid) {
178  if(!EEDetId::validHashIndex(cellid)) continue;
179 
180  uint32_t rawid = EEDetId::unhashIndex(cellid);
181 
182  if (record.find(rawid) == record.end()) continue;
183  if(!record[rawid].pdfval[5]) continue;
184 
185  DOMElement* cellnode=writeCell(root,rawid);
186 
187  WriteNodeWithValue(cellnode,sample0_tag,record[rawid].pdfval[0]);
188  WriteNodeWithValue(cellnode,sample1_tag,record[rawid].pdfval[1]);
189  WriteNodeWithValue(cellnode,sample2_tag,record[rawid].pdfval[2]);
190  WriteNodeWithValue(cellnode,sample3_tag,record[rawid].pdfval[3]);
191  WriteNodeWithValue(cellnode,sample4_tag,record[rawid].pdfval[4]);
192  WriteNodeWithValue(cellnode,sample5_tag,record[rawid].pdfval[5]);
193  WriteNodeWithValue(cellnode,sample6_tag,record[rawid].pdfval[6]);
194  WriteNodeWithValue(cellnode,sample7_tag,record[rawid].pdfval[7]);
195  WriteNodeWithValue(cellnode,sample8_tag,record[rawid].pdfval[8]);
196  WriteNodeWithValue(cellnode,sample9_tag,record[rawid].pdfval[9]);
197  WriteNodeWithValue(cellnode,sample10_tag,record[rawid].pdfval[10]);
198  WriteNodeWithValue(cellnode,sample11_tag,record[rawid].pdfval[11]);
199 
200  }
201 
202  std::string dump= toNative(writer->writeToString(*root));
203  doc->release();
204  return dump;
205 }
const std::string sample9_tag("sample_9")
const std::string sample10_tag("sample_10")
const std::string sample0_tag("sample_0")
const std::string PulseShapes_tag("EcalPulseShapes")
const std::string sample2_tag("sample_2")
const Items & barrelItems() const
const std::string sample11_tag("sample_11")
const std::string sample5_tag("sample_5")
void xercesInitialize()
Definition: Xerces.cc:17
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
const std::string sample7_tag("sample_7")
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 sample3_tag("sample_3")
static const int MIN_HASH
Definition: EBDetId.h:156
const std::string sample8_tag("sample_8")
const std::string sample1_tag("sample_1")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
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_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 sample6_tag("sample_6")
const Items & endcapItems() const
const std::string sample4_tag("sample_4")
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
string root
initialization
Definition: dbtoconf.py:70
int EcalPulseShapesXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalPulseShapes record 
)
static

Definition at line 23 of file EcalPulseShapesXMLTranslator.cc.

References xuti::Cell_tag(), gather_cfg::cout, cond::rpcobgas::detid, xuti::getChildNode(), xuti::GetNodeData(), geometryXMLtoCSV::parser, xuti::readCellId(), xuti::readHeader(), alignCSCRings::s, xuti::sample0_tag(), xuti::sample10_tag(), xuti::sample11_tag(), xuti::sample1_tag(), xuti::sample2_tag(), xuti::sample3_tag(), xuti::sample4_tag(), xuti::sample5_tag(), xuti::sample6_tag(), xuti::sample7_tag(), xuti::sample8_tag(), xuti::sample9_tag(), EcalPulseShape::TEMPLATESAMPLES, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

25  {
26 
28 
29  XercesDOMParser* parser = new XercesDOMParser;
30  parser->setValidationScheme( XercesDOMParser::Val_Never );
31  parser->setDoNamespaces( false );
32  parser->setDoSchema( false );
33 
34  parser->parse(filename.c_str());
35 
36  DOMDocument* xmlDoc = parser->getDocument();
37  if (!xmlDoc) {
38  std::cout << "EcalPulseShapesXMLTranslator::Error parsing document" << std::endl;
39  return -1;
40  }
41 
42  DOMElement* elementRoot = xmlDoc->getDocumentElement();
43 
44  xuti::readHeader(elementRoot,header);
45 
46  DOMNode * cellnode = getChildNode(elementRoot,Cell_tag);
47 
48  int chan = 0;
49  while(cellnode) {
50  // std::cout << " Channel " << chan << std::endl;
51  float samples[EcalPulseShape::TEMPLATESAMPLES];
52 
53  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
54  // std::cout << " readCell Id Channel " << chan << " tag " << mean12_tag << std::endl;
55 
56  DOMNode* sample0_node = getChildNode(cellnode,sample0_tag);
57  GetNodeData(sample0_node,samples[0]);
58  // std::cout << " tag " << sample0_tag << " sample0 " << sample0 << std::endl;
59 
60  DOMNode* sample1_node = getChildNode(cellnode,sample1_tag);
61  GetNodeData(sample1_node,samples[1]);
62  // std::cout << " tag " << sample1_tag << " sample1 " << sample1 << std::endl;
63 
64  DOMNode* sample2_node = getChildNode(cellnode,sample2_tag);
65  GetNodeData(sample2_node,samples[2]);
66  // std::cout << " tag " << sample2_tag << " sample2 " << sample2 << std::endl;
67 
68  DOMNode* sample3_node = getChildNode(cellnode,sample3_tag);
69  GetNodeData(sample3_node,samples[3]);
70  // std::cout << " tag " << sample3_tag << " sample3 " << sample3 << std::endl;
71 
72  DOMNode* sample4_node = getChildNode(cellnode,sample4_tag);
73  GetNodeData(sample4_node,samples[4]);
74  // std::cout << " tag " << sample4_tag << " sample4 " << sample4 << std::endl;
75 
76  DOMNode* sample5_node = getChildNode(cellnode,sample5_tag);
77  GetNodeData(sample5_node,samples[5]);
78  // std::cout << " tag " << sample5_tag << " sample5 " << sample5 << std::endl;
79 
80  DOMNode* sample6_node = getChildNode(cellnode,sample6_tag);
81  GetNodeData(sample6_node,samples[6]);
82  // std::cout << " tag " << sample6_tag << " sample6 " << sample6 << std::endl;
83 
84  DOMNode* sample7_node = getChildNode(cellnode,sample7_tag);
85  GetNodeData(sample7_node,samples[7]);
86  // std::cout << " tag " << sample7_tag << " sample7 " << sample7 << std::endl;
87 
88  DOMNode* sample8_node = getChildNode(cellnode,sample8_tag);
89  GetNodeData(sample8_node,samples[8]);
90  // std::cout << " tag " << sample8_tag << " sample8 " << sample8 << std::endl;
91 
92  DOMNode* sample9_node = getChildNode(cellnode,sample9_tag);
93  GetNodeData(sample9_node,samples[9]);
94  // std::cout << " tag " << sample9_tag << " sample9 " << sample9 << std::endl;
95 
96  DOMNode* sample10_node = getChildNode(cellnode,sample10_tag);
97  GetNodeData(sample10_node,samples[10]);
98  // std::cout << " tag " << sample10_tag << " sample10 " << sample10 << std::endl;
99 
100  DOMNode* sample11_node = getChildNode(cellnode,sample11_tag);
101  GetNodeData(sample11_node,samples[11]);
102  // std::cout << " tag " << sample11_tag << " sample11 " << sample11 << std::endl;
103 
104  for(int s = 0; s<EcalPulseShape::TEMPLATESAMPLES; ++s) record[detid].pdfval[s] = samples[s];
105 
106  cellnode = cellnode->getNextSibling();
107 
108  while(cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
109  cellnode = cellnode->getNextSibling();
110  chan++;
111  }
112 
113  delete parser;
115  std::cout << " nb of channels found in xml file " << chan << std::endl;
116  return 0;
117  }
const std::string sample9_tag("sample_9")
const std::string sample10_tag("sample_10")
const std::string sample0_tag("sample_0")
const std::string sample2_tag("sample_2")
void xercesTerminate()
Definition: Xerces.cc:22
static const int TEMPLATESAMPLES
const std::string sample11_tag("sample_11")
const std::string sample5_tag("sample_5")
void xercesInitialize()
Definition: Xerces.cc:17
const std::string sample7_tag("sample_7")
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
const std::string sample3_tag("sample_3")
const std::string Cell_tag("cell")
const std::string sample8_tag("sample_8")
const std::string sample1_tag("sample_1")
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:121
const std::string sample6_tag("sample_6")
const std::string sample4_tag("sample_4")
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
int EcalPulseShapesXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalPulseShapes record 
)
static

Definition at line 119 of file EcalPulseShapesXMLTranslator.cc.

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

121  {
122  std::fstream fs(filename.c_str(),ios::out);
123  fs<< dumpXML(header,record);
124  return 0;
125 }
tuple out
Definition: dbtoconf.py:99
static std::string dumpXML(const EcalCondHeader &header, const EcalPulseShapes &record)
tuple filename
Definition: lut2db_cfg.py:20