CMS 3D CMS Logo

EcalFloatCondObjectContainerXMLTranslator.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <fstream>
4 
5 #include <xercesc/dom/DOMNode.hpp>
6 #include <xercesc/dom/DOM.hpp>
7 #include <xercesc/parsers/XercesDOMParser.hpp>
10 #include <xercesc/util/XMLString.hpp>
11 #include <xercesc/sax/SAXException.hpp>
12 #include <xercesc/framework/LocalFileFormatTarget.hpp>
13 
16 
17 using namespace XERCES_CPP_NAMESPACE;
18 using namespace xuti;
19 using namespace std;
20 
21 const int kEBChannels = 61200, kEEChannels = 14648;
22 
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 }
139 
143  readXML(filename, header, record);
144 
145  return record.barrelItems();
146 }
147 
151  readXML(filename, header, record);
152 
153  return record.endcapItems();
154 }
155 
157  const std::vector<float>& eb,
158  const std::vector<float>& ee) {
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 }
190 
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 }
245 
247  const EcalCondHeader& header,
250 
251  std::fstream fs(filename.c_str(), ios::out);
252  fs << dumpXML(header, record);
253 
255 
256  return 0;
257 }
XercesStrUtils.h
submitPVValidationJobs.dump
dump
Definition: submitPVValidationJobs.py:55
mps_fire.i
i
Definition: mps_fire.py:428
EcalCondTools.dumpXML
def dumpXML(db, tag, since, filename='dump.xml')
Definition: EcalCondTools.py:44
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
boostedTaus_cff.doc
doc
Definition: boostedTaus_cff.py:20
EcalFloatCondObjectContainerXMLTranslator::barrelfromXML
static std::vector< float > barrelfromXML(const std::string &filename)
Definition: EcalFloatCondObjectContainerXMLTranslator.cc:140
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
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:35
xuti::WriteNodeWithValue
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
Definition: DOMHelperFunctions.h:46
EEDetId::kSizeForDenseIndexing
Definition: EEDetId.h:329
XERCES_CPP_NAMESPACE
Definition: XmlConfigParser.h:12
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
kEEChannels
const int kEEChannels
Definition: EcalFloatCondObjectContainerXMLTranslator.cc:21
EEDetId
Definition: EEDetId.h:14
DOMHelperFunctions.h
EcalCondHeader
Definition: EcalCondHeader.h:16
Xerces.h
EcalFloatCondObjectContainerXMLTranslator.h
cms::concurrency::xercesTerminate
void xercesTerminate()
Definition: Xerces.cc:23
xuti
Definition: DOMHelperFunctions.h:21
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:31
AlCaHarvesting_cff.record
record
Definition: AlCaHarvesting_cff.py:42
EcalFloatCondObjectContainerXMLTranslator::endcapfromXML
static std::vector< float > endcapfromXML(const std::string &filename)
Definition: EcalFloatCondObjectContainerXMLTranslator.cc:148
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
heppy_batch.val
val
Definition: heppy_batch.py:351
impl
Definition: trackAlgoPriorityOrder.h:18
std
Definition: JetResolutionObject.h:76
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
EBDetId::kSizeForDenseIndexing
Definition: EBDetId.h:155
xuti::Value_tag
const std::string Value_tag("Value")
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:291
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:52
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")
EcalFloatCondObjectContainerXMLTranslator::writeXML
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalFloatCondObjectContainer &record)
Definition: EcalFloatCondObjectContainerXMLTranslator.cc:246