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

◆ barrelfromXML()

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

◆ dumpXML() [1/2]

std::string EcalFloatCondObjectContainerXMLTranslator::dumpXML ( const EcalCondHeader header,
const std::vector< float > &  eb,
const std::vector< float > &  ee 
)
static

Definition at line 156 of file EcalFloatCondObjectContainerXMLTranslator.cc.

References DMR_cfg::cerr, EcalCondTools::dumpXML(), RecoTauValidation_cfi::header, EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, Hcal_FrontierConditions_cff::record, AlCaHLTBitMon_QueryRunRegistry::string, EBDetId::unhashIndex(), EEDetId::unhashIndex(), and EEDetId::validHashIndex().

Referenced by ecalpyutils::arraystoXML().

158  {
159  if (eb.size() != EBDetId::kSizeForDenseIndexing) {
160  std::cerr << "Error in EcalFloatCondObjectContainerXMLTranslator::dumpXML, invalid Barrel array size: " << eb.size()
161  << " should be " << EBDetId::kSizeForDenseIndexing << std::endl;
162  return std::string("");
163  }
164 
165  if (ee.size() != EEDetId::kSizeForDenseIndexing) {
166  std::cerr << "Error in EcalFloatCondObjectContainerXMLTranslator::dumpXML, invalid Endcap array size: " << ee.size()
167  << " should be " << EEDetId::kSizeForDenseIndexing << std::endl;
168  return std::string("");
169  }
170 
172 
173  for (int cellid = 0; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) { // loop on EB cells
174 
175  uint32_t rawid = EBDetId::unhashIndex(cellid);
176  record[rawid] = eb[cellid];
177  }
178 
179  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) { // loop on EE cells
180 
181  if (EEDetId::validHashIndex(cellid)) {
182  uint32_t rawid = EEDetId::unhashIndex(cellid);
183 
184  record[rawid] = ee[cellid];
185  } // if
186  }
187 
188  return dumpXML(header, record);
189 }
static constexpr int kSizeForDenseIndexing
Definition: EEDetId.h:328
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
static bool validHashIndex(int i)
Definition: EEDetId.h:239
static constexpr int kSizeForDenseIndexing
Definition: EBDetId.h:155
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:110

◆ dumpXML() [2/2]

std::string EcalFloatCondObjectContainerXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalFloatCondObjectContainer record 
)
staticprivate

Definition at line 191 of file EcalFloatCondObjectContainerXMLTranslator.cc.

References ALCARECOEcalPhiSym_cff::doc, GCP_Ntuples_cfg::dump, xuti::EcalFloatCondObjectContainer_tag(), RecoTauValidation_cfi::header, EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, Hcal_FrontierConditions_cff::record, AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toString(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), cms::xerces::uStr(), EEDetId::validHashIndex(), xuti::Value_tag(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), convertToRaw::writer, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

192  {
194 
195  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
196 
197  DOMLSSerializer* writer = impl->createLSSerializer();
198  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
199  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
200 
201  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
202  DOMDocument* doc =
203  impl->createDocument(nullptr, cms::xerces::uStr(EcalFloatCondObjectContainer_tag.c_str()).ptr(), doctype);
204  DOMElement* root = doc->getDocumentElement();
205 
207 
208  for (int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) { // loop on EB cells
209 
210  uint32_t rawid = EBDetId::unhashIndex(cellid);
212  if (value_ptr == record.end())
213  continue; // cell absent from original record
214 
215  DOMElement* cellnode = writeCell(root, rawid);
216 
217  WriteNodeWithValue(cellnode, Value_tag, *value_ptr);
218 
219  } // loop on EB cells
220 
221  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) { // loop on EE cells
222 
223  if (!EEDetId::validHashIndex(cellid))
224  continue;
225 
226  uint32_t rawid = EEDetId::unhashIndex(cellid);
228  if (value_ptr == record.end())
229  continue; // cell absent from original record
230 
231  DOMElement* cellnode = writeCell(root, rawid);
232  WriteNodeWithValue(cellnode, Value_tag, *value_ptr);
233 
234  } // loop on EE cells
235 
236  std::string dump = cms::xerces::toString(writer->writeToString(root));
237  doc->release();
238  doctype->release();
239  writer->release();
240 
242 
243  return dump;
244 }
static constexpr int kSizeForDenseIndexing
Definition: EEDetId.h:328
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:65
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 constexpr int kSizeForDenseIndexing
Definition: EBDetId.h:155
static const int MIN_HASH
Definition: EBDetId.h:149
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:110
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.

◆ endcapfromXML()

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

◆ readXML()

int EcalFloatCondObjectContainerXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalFloatCondObjectContainer record 
)
static

Definition at line 23 of file EcalFloatCondObjectContainerXMLTranslator.cc.

References gather_cfg::cout, beamvalidation::exit(), corrVsCorr::filename, newFWLiteAna::found, mps_fire::i, kEBChannels, kEEChannels, Hcal_FrontierConditions_cff::record, AlCaHLTBitMon_QueryRunRegistry::string, EBDetId::unhashIndex(), EEDetId::unhashIndex(), and heppy_batch::val.

Referenced by EcalTrivialConditionRetriever::getIntercalibConstantsFromConfiguration(), EcalTrivialConditionRetriever::getIntercalibConstantsMCFromConfiguration(), and EcalFloatCondObjectContainerHandler::getNewObjects().

25  {
26  std::cout << "EcalFloatCondObjectContainerXMLTranslatorr::readXML filename " << filename << std::endl;
27  /* old method for DBv1
28  cms::concurrency::xercesInitialize();
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  cms::concurrency::xercesTerminate();
79  */
80  // new method for DBv2
81  std::string dummyLine, bid;
82  std::ifstream fxml;
83  fxml.open(filename);
84  if (!fxml.is_open()) {
85  std::cout << "ERROR : cannot open file " << filename << std::endl;
86  exit(1);
87  }
88  // header
89  for (int i = 0; i < 6; i++) {
90  getline(fxml, dummyLine); // skip first lines
91  // std::cout << dummyLine << std::endl;
92  }
93  fxml >> bid;
94  // std::cout << bid << std::endl;
95  std::string stt = bid.substr(7, 5);
96  std::istringstream iEB(stt);
97  int nEB;
98  iEB >> nEB;
99  if (nEB != kEBChannels) {
100  std::cout << " strange number of EB channels " << nEB << std::endl;
101  exit(-1);
102  }
103  fxml >> bid; // <item_version>0</item_version>
104  for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
105  EBDetId myEBDetId = EBDetId::unhashIndex(iChannel);
106  fxml >> bid;
107  std::size_t found = bid.find("</");
108  stt = bid.substr(6, found - 6);
109  float val = std::stof(stt);
110  record[myEBDetId] = val;
111  }
112  for (int i = 0; i < 5; i++) {
113  getline(fxml, dummyLine); // skip first lines
114  // std::cout << dummyLine << std::endl;
115  }
116  fxml >> bid;
117  // cout << bid << endl;
118  stt = bid.substr(7, 5);
119  std::istringstream iEE(stt);
120  int nEE;
121  iEE >> nEE;
122  if (nEE != kEEChannels) {
123  std::cout << " strange number of EE channels " << nEE << std::endl;
124  exit(-1);
125  }
126  fxml >> bid; // <item_version>0</item_version>
127  // now endcaps
128  for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
129  EEDetId myEEDetId = EEDetId::unhashIndex(iChannel);
130  fxml >> bid;
131  std::size_t found = bid.find("</");
132  stt = bid.substr(6, found - 6);
133  float val = std::stof(stt);
134  record[myEEDetId] = val;
135  }
136 
137  return 0;
138 }
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
def exit(msg="")

◆ writeXML()

int EcalFloatCondObjectContainerXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalFloatCondObjectContainer record 
)
static