CMS 3D CMS Logo

MiscalibReaderXML.cc
Go to the documentation of this file.
5 #include <cstdio>
6 #include <cstdlib>
7 #include <string>
8 #include <vector>
9 
10 using namespace xercesc;
11 
12 int MiscalibReaderFromXML::s_numberOfInstances = 0; //to check that there is only 1 instance
13 
14 inline std::string _toString(const XMLCh* toTranscode) {
15  std::string tmp(XMLString::transcode(toTranscode));
16  return tmp;
17 }
18 
19 inline XMLCh* _toDOMS(std::string temp) {
20  XMLCh* buff = XMLString::transcode(temp.c_str());
21  return buff;
22 }
23 
25  try {
26  //std::cout << "Xerces-c initialization Number "
27  //<< s_numberOfInstances<<std::endl;
28  if (s_numberOfInstances == 0)
30  } catch (const XMLException& e) {
31  std::cout << "Xerces-c error in initialization \n"
32  << "Exception message is: \n"
33  << _toString(e.getMessage()) << std::endl;
34  // throw an exception here
35  }
36 
38 }
40 
41 int MiscalibReaderFromXML::getIntAttribute(DOMNamedNodeMap* attribute, const std::string& attribute_name) {
42  bool well_formed_string;
43  int retval = MiscalibReaderFromXMLDomUtils::getIntAttribute(attribute, attribute_name, well_formed_string);
44  if (!well_formed_string)
45  std::cout << "MiscalibReaderFromXML::getIntAttribute PROBLEMS ...!!!" << std::endl;
46 
47  return retval;
48 }
49 
51 
52 double MiscalibReaderFromXML::getScalingFactor(XERCES_CPP_NAMESPACE::DOMNamedNodeMap* attribute) {
53  return MiscalibReaderFromXML::getFloatAttribute(attribute, "scale_factor");
54 }
55 
57 
58 double MiscalibReaderFromXML::getFloatAttribute(DOMNamedNodeMap* attribute, const std::string& attribute_name) {
59  bool well_formed_string;
60  double retval = MiscalibReaderFromXMLDomUtils::getFloatAttribute(attribute, attribute_name, well_formed_string);
61  if (!well_formed_string)
62  std::cout << "MiscalibReaderFromXML::getFloatAttribute PROBLEMS ...!!!" << std::endl;
63 
64  return retval;
65 }
66 
68 
70  XercesDOMParser* parser = new XercesDOMParser;
71  parser->setValidationScheme(XercesDOMParser::Val_Auto);
72  parser->setDoNamespaces(false);
73  parser->parse(configFile.c_str());
74  DOMDocument* doc = parser->getDocument();
75  assert(doc);
76 
77  unsigned int linkTagsNum = doc->getElementsByTagName(_toDOMS("Cell"))->getLength();
78  // The following should be on LogInfo
79  //std::cout << "Read number of Cells = " << linkTagsNum << std::endl;
80 
81  if (linkTagsNum == 0)
82  std::cout << "Number of Cells in file is 0 - probably bad file format" << std::endl;
83 
84  int count = 0;
85  for (unsigned int i = 0; i < linkTagsNum; i++) {
86  DOMNode* linkNode = doc->getElementsByTagName(_toDOMS("Cell"))->item(i);
88  if (!linkNode) {
89  std::cout << "Node LINK does not exist, i=" << i << std::endl;
90  return true;
91  }
92  DOMElement* linkElement = static_cast<DOMElement*>(linkNode);
93  if (!linkElement) {
94  std::cout << "Element LINK does not exist, i=" << i << std::endl;
95  return true;
96  }
97 
98  DOMNamedNodeMap* attributes = linkNode->getAttributes();
99  double scalingfactor = getScalingFactor(attributes);
100 
101  DetId cell = parseCellEntry(attributes);
102 
103  if (cell != DetId(0)) {
104  count++;
105  caloMap_.addCell(cell, scalingfactor);
106  } else {
107  // std::cout << "Null received" << std::endl;
108  }
109  }
110 
111  // The following should be on LogInfo
112  // std::cout << "Number of good Cells = " << count << std::endl;
113  return false;
114 }
mps_fire.i
i
Definition: mps_fire.py:428
boostedTaus_cff.doc
doc
Definition: boostedTaus_cff.py:20
gather_cfg.cout
cout
Definition: gather_cfg.py:144
cms::cuda::assert
assert(be >=bs)
MiscalibReaderFromXMLDomUtils::getFloatAttribute
static double getFloatAttribute(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attributes, std::string attr_name, bool &well_formed_string)
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
MiscalibReaderFromXML::getFloatAttribute
double getFloatAttribute(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attribute, const std::string &attribute_name)
Definition: MiscalibReaderXML.cc:58
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
_toDOMS
XMLCh * _toDOMS(std::string temp)
Definition: MiscalibReaderXML.cc:19
MiscalibReaderFromXMLDomUtils::getIntAttribute
static int getIntAttribute(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attributes, std::string attr_name, bool &well_formed_string)
DetId
Definition: DetId.h:17
MiscalibReaderFromXML::MiscalibReaderFromXML
MiscalibReaderFromXML(CaloMiscalibMap &)
Definition: MiscalibReaderXML.cc:24
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
MiscalibReaderFromXML::getScalingFactor
double getScalingFactor(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attribute)
Definition: MiscalibReaderXML.cc:52
MiscalibReaderFromXMLDomUtils.h
MiscalibReaderFromXML.h
Xerces.h
_toString
std::string _toString(const XMLCh *toTranscode)
Definition: MiscalibReaderXML.cc:14
MiscalibReaderFromXML::getIntAttribute
int getIntAttribute(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attribute, const std::string &attribute_name)
Definition: MiscalibReaderXML.cc:41
beamspotdip_dqm_sourceclient-live_cfg.configFile
configFile
Definition: beamspotdip_dqm_sourceclient-live_cfg.py:8
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MiscalibReaderFromXML::caloMap_
CaloMiscalibMap & caloMap_
Definition: MiscalibReaderFromXML.h:40
CaloMiscalibMap.h
MiscalibReaderFromXML::parseCellEntry
virtual DetId parseCellEntry(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attribute)=0
MiscalibReaderFromXML::s_numberOfInstances
static int s_numberOfInstances
Definition: MiscalibReaderFromXML.h:39
CaloMiscalibMap
Definition: CaloMiscalibMap.h:8
MiscalibReaderFromXML::parseXMLMiscalibFile
bool parseXMLMiscalibFile(std::string configFile)
Definition: MiscalibReaderXML.cc:69
CaloMiscalibMap::addCell
virtual void addCell(const DetId &cell, float scaling_factor)=0
cms::concurrency::xercesInitialize
void xercesInitialize()
Definition: Xerces.cc:18
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37