CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MiscalibReaderXML.cc
Go to the documentation of this file.
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string>
7 #include <vector>
8 
9 using namespace xercesc;
10 
11 int MiscalibReaderFromXML::s_numberOfInstances = 0; //to check that there is only 1 instance
12 
13 inline std::string _toString(const XMLCh *toTranscode){
14  std::string tmp(XMLString::transcode(toTranscode));
15  return tmp;
16 }
17 
18 inline XMLCh* _toDOMS( std::string temp ){
19  XMLCh* buff = XMLString::transcode(temp.c_str());
20  return buff;
21 }
22 
23 
24 
26 
27 
28  try {
29  //std::cout << "Xerces-c initialization Number "
30  //<< s_numberOfInstances<<std::endl;
31  if (s_numberOfInstances==0)
32  XMLPlatformUtils::Initialize();
33  }
34  catch (const XMLException& e) {
35  std::cout << "Xerces-c error in initialization \n"
36  << "Exception message is: \n"
37  << _toString(e.getMessage()) <<std::endl;
38  // throw an exception here
39  }
40 
42 
43 
44 
45 
46 }
48 
49 
50 int MiscalibReaderFromXML::getIntAttribute(DOMNamedNodeMap * attribute, const std::string & attribute_name)
51 {
52 bool well_formed_string;
53 int retval = MiscalibReaderFromXMLDomUtils::getIntAttribute(attribute,attribute_name,well_formed_string);
54 if(!well_formed_string) std::cout << "MiscalibReaderFromXML::getIntAttribute PROBLEMS ...!!!" << std::endl;
55 
56  return retval;
57 }
58 
60 
61 double MiscalibReaderFromXML::getScalingFactor(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attribute)
62 {
63 return MiscalibReaderFromXML::getFloatAttribute(attribute,"scale_factor");
64 }
65 
67 
68 double MiscalibReaderFromXML::getFloatAttribute(DOMNamedNodeMap * attribute, const std::string & attribute_name)
69 {
70 bool well_formed_string;
71 double retval = MiscalibReaderFromXMLDomUtils::getFloatAttribute(attribute,attribute_name,well_formed_string);
72 if(!well_formed_string) std::cout << "MiscalibReaderFromXML::getFloatAttribute PROBLEMS ...!!!" << std::endl;
73 
74  return retval;
75 }
76 
78 
80 
81  XercesDOMParser* parser = new XercesDOMParser;
82  parser->setValidationScheme(XercesDOMParser::Val_Auto);
83  parser->setDoNamespaces(false);
84  parser->parse(configFile.c_str());
85  DOMDocument* doc = parser->getDocument();
86  assert(doc);
87 
88  unsigned int linkTagsNum = doc->getElementsByTagName(_toDOMS("Cell"))->getLength();
89  // The following should be on LogInfo
90  //std::cout << "Read number of Cells = " << linkTagsNum << std::endl;
91 
92  if(linkTagsNum==0) std::cout <<"Number of Cells in file is 0 - probably bad file format"<<std::endl;
93 
94  int count=0;
95  for (unsigned int i=0; i<linkTagsNum; i++){
96 
97 
98  DOMNode* linkNode = doc->getElementsByTagName(_toDOMS("Cell"))->item(i);
100  if (! linkNode){
101  std::cout<<"Node LINK does not exist, i="<<i<<std::endl;
102  return true;
103  }
104  DOMElement* linkElement = static_cast<DOMElement *>(linkNode);
105  if (! linkElement){
106  std::cout<<"Element LINK does not exist, i="<<i<<std::endl;
107  return true;
108  }
109 
110 
111  DOMNamedNodeMap *attributes = linkNode->getAttributes();
112  double scalingfactor= getScalingFactor(attributes);
113 
114 
115 
116  DetId cell = parseCellEntry(attributes);
117 
118  if(cell!= DetId(0))
119  {
120  count++;
121  caloMap_.addCell(cell,scalingfactor);
122  } else
123  {
124  // std::cout << "Null received" << std::endl;
125  }
126 
127  }
128 
129  // The following should be on LogInfo
130  // std::cout << "Number of good Cells = " << count << std::endl;
131  return false;
132 
133 }
134 
int i
Definition: DBlmapReader.cc:9
static double getFloatAttribute(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attributes, std::string attr_name, bool &well_formed_string)
static int getIntAttribute(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attributes, std::string attr_name, bool &well_formed_string)
std::string _toString(const XMLCh *toTranscode)
CaloMiscalibMap & caloMap_
bool parseXMLMiscalibFile(std::string configFile)
MiscalibReaderFromXML(CaloMiscalibMap &)
virtual void addCell(const DetId &cell, float scaling_factor)=0
double getScalingFactor(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attribute)
list attributes
Definition: asciidump.py:415
double getFloatAttribute(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attribute, const std::string &attribute_name)
tuple doc
Definition: asciidump.py:381
Definition: DetId.h:20
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
XMLCh * _toDOMS(std::string temp)
tuple cout
Definition: gather_cfg.py:121
virtual DetId parseCellEntry(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attribute)=0
int getIntAttribute(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attribute, const std::string &attribute_name)