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 145 of file EcalFloatCondObjectContainerXMLTranslator.cc.

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

Referenced by BOOST_PYTHON_MODULE().

145  {
148  readXML(filename,header,record);
149 
150  return record.barrelItems();
151 
152 }
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 168 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().

171  {
172 
173 
174  if (eb.size() != EBDetId::kSizeForDenseIndexing){
175  std::cerr<<"Error in EcalFloatCondObjectContainerXMLTranslator::dumpXML, invalid Barrel array size: "
176  <<eb.size() << " should be "<< EBDetId::kSizeForDenseIndexing<< std::endl;
177  return std::string("");
178  }
179 
180  if (ee.size() != EEDetId::kSizeForDenseIndexing){
181  std::cerr<<"Error in EcalFloatCondObjectContainerXMLTranslator::dumpXML, invalid Endcap array size: "
182  <<ee.size() << " should be "<< EEDetId::kSizeForDenseIndexing<< std::endl;
183  return std::string("");
184  }
185 
187 
188  for (int cellid = 0;
190  ++cellid){// loop on EB cells
191 
192  uint32_t rawid = EBDetId::unhashIndex(cellid);
193  record[rawid] = eb[cellid];
194  }
195 
196  for (int cellid = 0;
198  ++cellid){// loop on EE cells
199 
200 
201 
202  if (EEDetId::validHashIndex(cellid)){
203  uint32_t rawid = EEDetId::unhashIndex(cellid);
204 
205  record[rawid]=ee[cellid];
206  } // if
207  }
208 
209  return dumpXML(header,record);
210 
211 
212 }
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 215 of file EcalFloatCondObjectContainerXMLTranslator.cc.

References common_cff::doc, 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().

217  {
218 
220 
221  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
222 
223  DOMLSSerializer* writer = impl->createLSSerializer();
224  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
225  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
226 
227  DOMDocumentType* doctype = impl->createDocumentType( cms::xerces::uStr("XML").ptr(), nullptr, nullptr );
228  DOMDocument* doc = impl->createDocument( nullptr, cms::xerces::uStr(EcalFloatCondObjectContainer_tag.c_str()).ptr(), doctype );
229  DOMElement* root = doc->getDocumentElement();
230 
231  xuti::writeHeader(root, header);
232 
233  for (int cellid = EBDetId::MIN_HASH;
235  ++cellid){// loop on EB cells
236 
237  uint32_t rawid= EBDetId::unhashIndex(cellid);
239  record.find(rawid);
240  if (value_ptr==record.end()) continue; // cell absent from original record
241 
242  DOMElement* cellnode=writeCell(root,rawid);
243 
244  WriteNodeWithValue(cellnode,Value_tag,*value_ptr);
245 
246 
247  } // loop on EB cells
248 
249 
250 
251  for (int cellid = 0;
253  ++cellid){// loop on EE cells
254 
255  if (!EEDetId::validHashIndex(cellid)) continue;
256 
257  uint32_t rawid= EEDetId::unhashIndex(cellid);
259  record.find(rawid);
260  if (value_ptr==record.end()) continue; // cell absent from original record
261 
262 
263  DOMElement* cellnode= writeCell(root,rawid);
264  WriteNodeWithValue(cellnode,Value_tag,*value_ptr);
265 
266 
267  } // loop on EE cells
268 
269 
270  std::string dump = cms::xerces::toString( writer->writeToString( root ));
271  doc->release();
272  doctype->release();
273  writer->release();
274 
276 
277  return dump;
278 }
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 156 of file EcalFloatCondObjectContainerXMLTranslator.cc.

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

Referenced by BOOST_PYTHON_MODULE().

156  {
159  readXML(filename,header,record);
160 
161  return record.endcapItems();
162 
163 }
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 24 of file EcalFloatCondObjectContainerXMLTranslator.cc.

References gather_cfg::cout, cmsRelvalreport::exit, runEdmFileComparison::found, mps_fire::i, kEBChannels, kEEChannels, AlCaHLTBitMon_QueryRunRegistry::string, EBDetId::unhashIndex(), EEDetId::unhashIndex(), and heppy_batch::val.

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

26  {
27  std::cout << "EcalFloatCondObjectContainerXMLTranslatorr::readXML filename " << filename << std::endl;
28  /* old method for DBv1
29  cms::concurrency::xercesInitialize();
30 
31  XercesDOMParser* parser = new XercesDOMParser;
32  parser->setValidationScheme( XercesDOMParser::Val_Never );
33  parser->setDoNamespaces( false );
34  parser->setDoSchema( false );
35 
36  parser->parse(filename.c_str());
37 
38  DOMDocument* xmlDoc = parser->getDocument();
39 
40 
41  if (!xmlDoc) {
42  std::cout << "EcalFloatCondObjectContainerXMLTranslator::Error parsing document" << std::endl;
43  return -1;
44  }
45 
46  DOMElement* elementRoot = xmlDoc->getDocumentElement();
47 
48  xuti::readHeader(elementRoot, header);
49 
50  // get the first cell node
51  DOMNode * cellnode=getChildNode(elementRoot,Cell_tag);
52 
53  // loop on cell nodes
54  while (cellnode){
55 
56  float val=0;
57 
58  // read id
59  DetId detid= readCellId(dynamic_cast<DOMElement*>(cellnode));
60 
61  // read value
62  DOMNode * c_node = getChildNode(cellnode,Value_tag);
63  GetNodeData(c_node,val);
64 
65  // fill record
66  record[detid]=val;
67 
68  // get next cell
69  cellnode= cellnode->getNextSibling();
70 
71  while (cellnode&& cellnode->getNodeType( ) != DOMNode::ELEMENT_NODE)
72  cellnode= cellnode->getNextSibling();
73 
74 
75  }
76 
77 
78  delete parser;
79  cms::concurrency::xercesTerminate();
80  */
81  // new method for DBv2
82  std::string dummyLine, bid;
83  std::ifstream fxml;
84  fxml.open(filename);
85  if(!fxml.is_open()) {
86  std::cout << "ERROR : cannot open file " << filename << std::endl;
87  exit (1);
88  }
89  // header
90  for( int i=0; i< 6; i++) {
91  getline(fxml, dummyLine); // skip first lines
92  // std::cout << dummyLine << std::endl;
93  }
94  fxml >> bid;
95  // std::cout << bid << std::endl;
96  std::string stt = bid.substr(7,5);
97  std::istringstream iEB(stt);
98  int nEB;
99  iEB >> nEB;
100  if(nEB != kEBChannels) {
101  std::cout << " strange number of EB channels " << nEB << std::endl;
102  exit(-1);
103  }
104  fxml >> bid; // <item_version>0</item_version>
105  for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
106  EBDetId myEBDetId = EBDetId::unhashIndex(iChannel);
107  fxml >> bid;
108  std::size_t found = bid.find("</");
109  stt = bid.substr(6, found - 6);
110  float val = std::stof(stt);
111  record[myEBDetId] = val;
112  }
113  for( int i=0; i< 5; i++) {
114  getline(fxml, dummyLine); // skip first lines
115  // std::cout << dummyLine << std::endl;
116  }
117  fxml >> bid;
118  // cout << bid << endl;
119  stt = bid.substr(7,5);
120  std::istringstream iEE(stt);
121  int nEE;
122  iEE >> nEE;
123  if(nEE != kEEChannels) {
124  std::cout << " strange number of EE channels " << nEE << std::endl;
125  exit(-1);
126  }
127  fxml >> bid; // <item_version>0</item_version>
128  // now endcaps
129  for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
130  EEDetId myEEDetId = EEDetId::unhashIndex(iChannel);
131  fxml >> bid;
132  std::size_t found = bid.find("</");
133  stt = bid.substr(6, found - 6);
134  float val = std::stof(stt);
135  record[myEEDetId] = val;
136  }
137 
138  return 0;
139 
140 }
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
int EcalFloatCondObjectContainerXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalFloatCondObjectContainer record 
)
static

Definition at line 283 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().

285  {
286 
288 
289  std::fstream fs(filename.c_str(),ios::out);
290  fs<< dumpXML(header,record);
291 
293 
294  return 0;
295 }
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)