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

#include <EcalFloatCondObjectContainerXMLTranslator.h>

Static Public Member Functions

static std::vector< float > barrelfromXML (const std::string &filename)
 
static std::string dumpXML (const EcalCondHeader &header, const EcalFloatCondObjectContainer &record)
 
static std::string dumpXML (const EcalCondHeader &header, const std::vector< float > &eb, const std::vector< float > &ee)
 
static std::vector< float > endcapfromXML (const std::string &filename)
 
static int readXML (const std::string &filename, EcalCondHeader &header, EcalFloatCondObjectContainer &record)
 
static int writeXML (const std::string &filename, const EcalCondHeader &header, const EcalFloatCondObjectContainer &record)
 

Detailed Description

Translates a EcalFloatCondObjectContainer record to XML and vice versa

Author
Stefano ARGIRO
Version
Id:
EcalFloatCondObjectContainerXMLTranslator.h,v 1.4 2011/05/04 12:38:10 argiro Exp
Date
20 Jun 2008

Definition at line 21 of file EcalFloatCondObjectContainerXMLTranslator.h.

Member Function Documentation

std::vector< float > EcalFloatCondObjectContainerXMLTranslator::barrelfromXML ( const std::string &  filename)
static

Definition at line 86 of file EcalFloatCondObjectContainerXMLTranslator.cc.

References EcalCondObjectContainer< T >::barrelItems(), insertMaterial::readXML(), and record.

Referenced by BOOST_PYTHON_MODULE().

86  {
87  EcalCondHeader header;
89  readXML(filename,header,record);
90 
91  return record.barrelItems();
92 
93 }
JetCorrectorParameters::Record record
Definition: classes.h:13
const Items & barrelItems() const
static int readXML(const std::string &filename, EcalCondHeader &header, EcalFloatCondObjectContainer &record)
tuple filename
Definition: lut2db_cfg.py:20
std::string EcalFloatCondObjectContainerXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalFloatCondObjectContainer record 
)
static

Definition at line 156 of file EcalFloatCondObjectContainerXMLTranslator.cc.

References asciidump::doc, hcal_timing_source_file_cfg::dump, xuti::EcalFloatCondObjectContainer_tag(), EcalCondObjectContainer< T >::end(), EcalCondObjectContainer< T >::find(), xuti::fromNative(), EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, dbtoconf::root, AlCaHLTBitMon_QueryRunRegistry::string, xuti::toNative(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), EEDetId::validHashIndex(), xuti::Value_tag(), xuti::writeCell(), xuti::writeHeader(), and xuti::WriteNodeWithValue().

Referenced by ecalpyutils::arraystoXML(), and cond::PayLoadInspector< DataT >::dump().

158  {
159 
160 
161 
162 
163  XMLPlatformUtils::Initialize();
164 
165  DOMImplementation* impl =
166  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
167 
168  DOMWriter* writer =
169  static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
170  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
171 
172  DOMDocumentType* doctype =
173  impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
174  DOMDocument * doc =
175  impl->createDocument( 0, fromNative(EcalFloatCondObjectContainer_tag).c_str(), doctype );
176 
177 
178  doc->setEncoding(fromNative("UTF-8").c_str() );
179  doc->setStandalone(true);
180  doc->setVersion(fromNative("1.0").c_str() );
181 
182 
183  DOMElement* root = doc->getDocumentElement();
184  xuti::writeHeader(root, header);
185 
186  for (int cellid = EBDetId::MIN_HASH;
188  ++cellid){// loop on EB cells
189 
190  uint32_t rawid= EBDetId::unhashIndex(cellid);
192  record.find(rawid);
193  if (value_ptr==record.end()) continue; // cell absent from original record
194 
195  DOMElement* cellnode=writeCell(root,rawid);
196 
197  WriteNodeWithValue(cellnode,Value_tag,*value_ptr);
198 
199 
200  } // loop on EB cells
201 
202 
203 
204  for (int cellid = 0;
206  ++cellid){// loop on EE cells
207 
208  if (!EEDetId::validHashIndex(cellid)) continue;
209 
210  uint32_t rawid= EEDetId::unhashIndex(cellid);
212  record.find(rawid);
213  if (value_ptr==record.end()) continue; // cell absent from original record
214 
215 
216  DOMElement* cellnode= writeCell(root,rawid);
217  WriteNodeWithValue(cellnode,Value_tag,*value_ptr);
218 
219 
220  } // loop on EE cells
221 
222 
223  std::string dump= toNative(writer->writeToString(*root));
224  doc->release();
225  return dump;
226 }
const std::string EcalFloatCondObjectContainer_tag("EcalFloatCondObjectContainer")
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
const std::string Value_tag("Value")
static bool validHashIndex(int i)
Definition: EEDetId.h:240
static const int MIN_HASH
Definition: EBDetId.h:157
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
tuple doc
Definition: asciidump.py:381
std::vector< Item >::const_iterator const_iterator
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:115
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.
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
string root
initialization
Definition: dbtoconf.py:70
std::string EcalFloatCondObjectContainerXMLTranslator::dumpXML ( const EcalCondHeader header,
const std::vector< float > &  eb,
const std::vector< float > &  ee 
)
static

Definition at line 109 of file EcalFloatCondObjectContainerXMLTranslator.cc.

References dtNoiseDBValidation_cfg::cerr, EcalCondTools::dumpXML(), EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, record, AlCaHLTBitMon_QueryRunRegistry::string, EBDetId::unhashIndex(), EEDetId::unhashIndex(), and EEDetId::validHashIndex().

112  {
113 
114 
115  if (eb.size() != EBDetId::kSizeForDenseIndexing){
116  std::cerr<<"Error in EcalFloatCondObjectContainerXMLTranslator::dumpXML, invalid Barrel array size: "
117  <<eb.size() << " should be "<< EBDetId::kSizeForDenseIndexing<< std::endl;
118  return std::string("");
119  }
120 
121  if (ee.size() != EEDetId::kSizeForDenseIndexing){
122  std::cerr<<"Error in EcalFloatCondObjectContainerXMLTranslator::dumpXML, invalid Endcap array size: "
123  <<ee.size() << " should be "<< EEDetId::kSizeForDenseIndexing<< std::endl;
124  return std::string("");
125  }
126 
128 
129  for (int cellid = 0;
131  ++cellid){// loop on EB cells
132 
133  uint32_t rawid = EBDetId::unhashIndex(cellid);
134  record[rawid] = eb[cellid];
135  }
136 
137  for (int cellid = 0;
139  ++cellid){// loop on EE cells
140 
141 
142 
143  if (EEDetId::validHashIndex(cellid)){
144  uint32_t rawid = EEDetId::unhashIndex(cellid);
145 
146  record[rawid]=ee[cellid];
147  } // if
148  }
149 
150  return dumpXML(header,record);
151 
152 
153 }
JetCorrectorParameters::Record record
Definition: classes.h:13
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
static bool validHashIndex(int i)
Definition: EEDetId.h:240
static std::string dumpXML(const EcalCondHeader &header, const EcalFloatCondObjectContainer &record)
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:115
std::vector< float > EcalFloatCondObjectContainerXMLTranslator::endcapfromXML ( const std::string &  filename)
static

Definition at line 97 of file EcalFloatCondObjectContainerXMLTranslator.cc.

References EcalCondObjectContainer< T >::endcapItems(), insertMaterial::readXML(), and record.

Referenced by BOOST_PYTHON_MODULE().

97  {
98  EcalCondHeader header;
100  readXML(filename,header,record);
101 
102  return record.endcapItems();
103 
104 }
JetCorrectorParameters::Record record
Definition: classes.h:13
static int readXML(const std::string &filename, EcalCondHeader &header, EcalFloatCondObjectContainer &record)
tuple filename
Definition: lut2db_cfg.py:20
const Items & endcapItems() const
int EcalFloatCondObjectContainerXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalFloatCondObjectContainer record 
)
static

Definition at line 24 of file EcalFloatCondObjectContainerXMLTranslator.cc.

References xuti::Cell_tag(), gather_cfg::cout, cond::rpcobgas::detid, xuti::getChildNode(), xuti::GetNodeData(), geometryXMLtoCSV::parser, xuti::readCellId(), xuti::readHeader(), and xuti::Value_tag().

Referenced by EcalTrivialConditionRetriever::getIntercalibConstantsFromConfiguration(), EcalTrivialConditionRetriever::getIntercalibConstantsMCFromConfiguration(), EcalFloatCondObjectContainerHandler::getNewObjects(), popcon::EcalIntercalibHandler::getNewObjects(), PhiSymmetryCalibration_step2::setUp(), PhiSymmetryCalibration_step2_SM::setUp(), and PhiSymmetryCalibration::setUp().

26  {
27 
28  XMLPlatformUtils::Initialize();
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 
39 
40  if (!xmlDoc) {
41  std::cout << "EcalFloatCondObjectContainerXMLTranslator::Error parsing document" << std::endl;
42  return -1;
43  }
44 
45  DOMElement* elementRoot = xmlDoc->getDocumentElement();
46 
47  xuti::readHeader(elementRoot, header);
48 
49  // get the first cell node
50  DOMNode * cellnode=getChildNode(elementRoot,Cell_tag);
51 
52  // loop on cell nodes
53  while (cellnode){
54 
55  float val=0;
56 
57  // read id
58  DetId detid= readCellId(dynamic_cast<DOMElement*>(cellnode));
59 
60  // read value
61  DOMNode * c_node = getChildNode(cellnode,Value_tag);
62  GetNodeData(c_node,val);
63 
64  // fill record
65  record[detid]=val;
66 
67  // get next cell
68  cellnode= cellnode->getNextSibling();
69 
70  while (cellnode&& cellnode->getNodeType( ) != DOMNode::ELEMENT_NODE)
71  cellnode= cellnode->getNextSibling();
72 
73 
74  }
75 
76 
77  delete parser;
78  XMLPlatformUtils::Terminate();
79  return 0;
80 
81 }
const std::string Value_tag("Value")
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
const std::string Cell_tag("cell")
Definition: DetId.h:20
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 DetId readCellId(xercesc::DOMElement *node)
Assuming.
int EcalFloatCondObjectContainerXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalFloatCondObjectContainer record 
)
static

Definition at line 231 of file EcalFloatCondObjectContainerXMLTranslator.cc.

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

Referenced by PhiSymmetryCalibration_step2::endJob(), PhiSymmetryCalibration_step2_SM::endJob(), and main().

233  {
234 
235  std::fstream fs(filename.c_str(),ios::out);
236  fs<< dumpXML(header,record);
237  return 0;
238 }
static std::string dumpXML(const EcalCondHeader &header, const EcalFloatCondObjectContainer &record)
tuple out
Definition: dbtoconf.py:99
tuple filename
Definition: lut2db_cfg.py:20