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 EcalFloatCondObjectContainer record 
)
staticprivate

Definition at line 191 of file EcalFloatCondObjectContainerXMLTranslator.cc.

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 }

References common_cff::doc, FrontierConditions_GlobalTag_cff::dump, xuti::EcalFloatCondObjectContainer_tag(), RecoTauValidation_cfi::header, EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, GlobalPosition_Frontier_DevDB_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(), cscNeutronWriter_cfi::writer, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

◆ dumpXML() [2/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.

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 }

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

Referenced by ecalpyutils::arraystoXML().

◆ 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.

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 }

References gather_cfg::cout, beamvalidation::exit(), corrVsCorr::filename, newFWLiteAna::found, mps_fire::i, kEBChannels, kEEChannels, GlobalPosition_Frontier_DevDB_cff::record, 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().

◆ writeXML()

int EcalFloatCondObjectContainerXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalFloatCondObjectContainer record 
)
static
common_cff.doc
doc
Definition: common_cff.py:54
mps_fire.i
i
Definition: mps_fire.py:428
xuti::writeHeader
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
Definition: DOMHelperFunctions.cc:151
xuti::writeCell
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
Definition: DOMHelperFunctions.cc:71
EBDetId
Definition: EBDetId.h:17
EEDetId::unhashIndex
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EBDetId::unhashIndex
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
cscNeutronWriter_cfi.writer
writer
Definition: cscNeutronWriter_cfi.py:6
EcalCondObjectContainer
Definition: EcalCondObjectContainer.h:13
EcalFloatCondObjectContainerXMLTranslator::readXML
static int readXML(const std::string &filename, EcalCondHeader &header, EcalFloatCondObjectContainer &record)
Definition: EcalFloatCondObjectContainerXMLTranslator.cc:23
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
cms::xerces::toString
std::string toString(XMLCh const *toTranscode)
Definition: XercesStrUtils.h:34
EEDetId::kSizeForDenseIndexing
Definition: EEDetId.h:329
xuti::WriteNodeWithValue
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
Definition: DOMHelperFunctions.h:46
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
kEEChannels
const int kEEChannels
Definition: EcalFloatCondObjectContainerXMLTranslator.cc:21
EEDetId
Definition: EEDetId.h:14
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalCondHeader
Definition: EcalCondHeader.h:16
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
cms::concurrency::xercesTerminate
void xercesTerminate()
Definition: Xerces.cc:23
root
Definition: RooFitFunction.h:10
EEDetId::validHashIndex
static bool validHashIndex(int i)
Definition: EEDetId.h:239
cms::xerces::uStr
ZStr< XMLCh > uStr(char const *str)
Definition: XercesStrUtils.h:30
heppy_batch.val
val
Definition: heppy_batch.py:351
impl
Definition: trackAlgoPriorityOrder.h:18
EcalFloatCondObjectContainerXMLTranslator::dumpXML
static std::string dumpXML(const EcalCondHeader &header, const std::vector< float > &eb, const std::vector< float > &ee)
Definition: EcalFloatCondObjectContainerXMLTranslator.cc:156
kEBChannels
const int kEBChannels
Definition: EcalFloatCondObjectContainerXMLTranslator.cc:21
xuti::Value_tag
const std::string Value_tag("Value")
EBDetId::kSizeForDenseIndexing
Definition: EBDetId.h:155
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
EcalCondObjectContainer::const_iterator
std::vector< Item >::const_iterator const_iterator
Definition: EcalCondObjectContainer.h:19
EBDetId::MIN_HASH
static const int MIN_HASH
Definition: EBDetId.h:149
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
cms::concurrency::xercesInitialize
void xercesInitialize()
Definition: Xerces.cc:18
xuti::EcalFloatCondObjectContainer_tag
const std::string EcalFloatCondObjectContainer_tag("EcalFloatCondObjectContainer")