CMS 3D CMS Logo

List of all members | Static Public Member Functions | Static Private 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 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)
 

Static Private Member Functions

static std::string dumpXML (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.3 2009/07/09 22:56:14 argiro Exp
Date
20 Jun 2008

Definition at line 18 of file EcalFloatCondObjectContainerXMLTranslator.h.

Member Function Documentation

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

Definition at line 85 of file EcalFloatCondObjectContainerXMLTranslator.cc.

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

Referenced by BOOST_PYTHON_MODULE().

85  {
88  readXML(filename,header,record);
89 
90  return record.barrelItems();
91 
92 }
JetCorrectorParameters::Record record
Definition: classes.h:7
const Items & barrelItems() const
static int readXML(const std::string &filename, EcalCondHeader &header, EcalFloatCondObjectContainer &record)
std::string EcalFloatCondObjectContainerXMLTranslator::dumpXML ( const EcalCondHeader header,
const std::vector< float > &  eb,
const std::vector< float > &  ee 
)
static

Definition at line 108 of file EcalFloatCondObjectContainerXMLTranslator.cc.

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

Referenced by ecalpyutils::arraystoXML().

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

Definition at line 155 of file EcalFloatCondObjectContainerXMLTranslator.cc.

References FrontierConditions_GlobalTag_cff::dump, xuti::EcalFloatCondObjectContainer_tag(), EcalCondObjectContainer< T >::end(), EcalCondObjectContainer< T >::find(), EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toString(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), cms::xerces::uStr(), EEDetId::validHashIndex(), xuti::Value_tag(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), cscNeutronWriter_cfi::writer, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

157  {
158 
160 
161  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
162 
163  DOMLSSerializer* writer = impl->createLSSerializer();
164  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
165  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
166 
167  DOMDocumentType* doctype = impl->createDocumentType( cms::xerces::uStr("XML").ptr(), 0, 0 );
168  DOMDocument* doc = impl->createDocument( 0, cms::xerces::uStr(EcalFloatCondObjectContainer_tag.c_str()).ptr(), doctype );
169  DOMElement* root = doc->getDocumentElement();
170 
171  xuti::writeHeader(root, header);
172 
173  for (int cellid = EBDetId::MIN_HASH;
175  ++cellid){// loop on EB cells
176 
177  uint32_t rawid= EBDetId::unhashIndex(cellid);
179  record.find(rawid);
180  if (value_ptr==record.end()) continue; // cell absent from original record
181 
182  DOMElement* cellnode=writeCell(root,rawid);
183 
184  WriteNodeWithValue(cellnode,Value_tag,*value_ptr);
185 
186 
187  } // loop on EB cells
188 
189 
190 
191  for (int cellid = 0;
193  ++cellid){// loop on EE cells
194 
195  if (!EEDetId::validHashIndex(cellid)) continue;
196 
197  uint32_t rawid= EEDetId::unhashIndex(cellid);
199  record.find(rawid);
200  if (value_ptr==record.end()) continue; // cell absent from original record
201 
202 
203  DOMElement* cellnode= writeCell(root,rawid);
204  WriteNodeWithValue(cellnode,Value_tag,*value_ptr);
205 
206 
207  } // loop on EE cells
208 
209 
210  std::string dump = cms::xerces::toString( writer->writeToString( root ));
211  doc->release();
212  doctype->release();
213  writer->release();
214 
216 
217  return dump;
218 }
void xercesTerminate()
Definition: Xerces.cc:23
const std::string EcalFloatCondObjectContainer_tag("EcalFloatCondObjectContainer")
void xercesInitialize()
Definition: Xerces.cc:18
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:239
std::string toString(XMLCh const *toTranscode)
static const int MIN_HASH
Definition: EBDetId.h:156
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
ZStr< XMLCh > uStr(char const *str)
std::vector< Item >::const_iterator const_iterator
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
const_iterator end() const
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
std::vector< float > EcalFloatCondObjectContainerXMLTranslator::endcapfromXML ( const std::string &  filename)
static

Definition at line 96 of file EcalFloatCondObjectContainerXMLTranslator.cc.

References EcalCondObjectContainer< T >::endcapItems(), RecoTauValidation_cfi::header, insertMaterial::readXML(), record, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by BOOST_PYTHON_MODULE().

96  {
99  readXML(filename,header,record);
100 
101  return record.endcapItems();
102 
103 }
JetCorrectorParameters::Record record
Definition: classes.h:7
static int readXML(const std::string &filename, EcalCondHeader &header, EcalFloatCondObjectContainer &record)
const Items & endcapItems() const
int EcalFloatCondObjectContainerXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalFloatCondObjectContainer record 
)
static

Definition at line 23 of file EcalFloatCondObjectContainerXMLTranslator.cc.

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

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

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

Definition at line 223 of file EcalFloatCondObjectContainerXMLTranslator.cc.

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

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

225  {
226 
228 
229  std::fstream fs(filename.c_str(),ios::out);
230  fs<< dumpXML(header,record);
231 
233 
234  return 0;
235 }
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18
static std::string dumpXML(const EcalCondHeader &header, const std::vector< float > &eb, const std::vector< float > &ee)