Go to the documentation of this file.00001 #include "CalibCalorimetry/CaloMiscalibTools/interface/MiscalibReaderFromXML.h"
00002 #include "CalibCalorimetry/CaloMiscalibTools/interface/MiscalibReaderFromXMLDomUtils.h"
00003 #include "CalibCalorimetry/CaloMiscalibTools/interface/CaloMiscalibMap.h"
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <string>
00007 #include <vector>
00008
00009 using namespace xercesc;
00010
00011 int MiscalibReaderFromXML::s_numberOfInstances = 0;
00012
00013 inline std::string _toString(const XMLCh *toTranscode){
00014 std::string tmp(XMLString::transcode(toTranscode));
00015 return tmp;
00016 }
00017
00018 inline XMLCh* _toDOMS( std::string temp ){
00019 XMLCh* buff = XMLString::transcode(temp.c_str());
00020 return buff;
00021 }
00022
00023
00024
00025 MiscalibReaderFromXML::MiscalibReaderFromXML(CaloMiscalibMap & caloMap):caloMap_(caloMap){
00026
00027
00028 try {
00029
00030
00031 if (s_numberOfInstances==0)
00032 XMLPlatformUtils::Initialize();
00033 }
00034 catch (const XMLException& e) {
00035 std::cout << "Xerces-c error in initialization \n"
00036 << "Exception message is: \n"
00037 << _toString(e.getMessage()) <<std::endl;
00038
00039 }
00040
00041 ++s_numberOfInstances;
00042
00043
00044
00045
00046 }
00048
00049
00050 int MiscalibReaderFromXML::getIntAttribute(DOMNamedNodeMap * attribute, const std::string & attribute_name)
00051 {
00052 bool well_formed_string;
00053 int retval = MiscalibReaderFromXMLDomUtils::getIntAttribute(attribute,attribute_name,well_formed_string);
00054 if(!well_formed_string) std::cout << "MiscalibReaderFromXML::getIntAttribute PROBLEMS ...!!!" << std::endl;
00055
00056 return retval;
00057 }
00058
00060
00061 double MiscalibReaderFromXML::getScalingFactor(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *attribute)
00062 {
00063 return MiscalibReaderFromXML::getFloatAttribute(attribute,"scale_factor");
00064 }
00065
00067
00068 double MiscalibReaderFromXML::getFloatAttribute(DOMNamedNodeMap * attribute, const std::string & attribute_name)
00069 {
00070 bool well_formed_string;
00071 double retval = MiscalibReaderFromXMLDomUtils::getFloatAttribute(attribute,attribute_name,well_formed_string);
00072 if(!well_formed_string) std::cout << "MiscalibReaderFromXML::getFloatAttribute PROBLEMS ...!!!" << std::endl;
00073
00074 return retval;
00075 }
00076
00078
00079 bool MiscalibReaderFromXML::parseXMLMiscalibFile(std::string configFile){
00080
00081 XercesDOMParser* parser = new XercesDOMParser;
00082 parser->setValidationScheme(XercesDOMParser::Val_Auto);
00083 parser->setDoNamespaces(false);
00084 parser->parse(configFile.c_str());
00085 DOMDocument* doc = parser->getDocument();
00086 assert(doc);
00087
00088 unsigned int linkTagsNum = doc->getElementsByTagName(_toDOMS("Cell"))->getLength();
00089
00090
00091
00092 if(linkTagsNum==0) std::cout <<"Number of Cells in file is 0 - probably bad file format"<<std::endl;
00093
00094 int count=0;
00095 for (unsigned int i=0; i<linkTagsNum; i++){
00096
00097
00098 DOMNode* linkNode = doc->getElementsByTagName(_toDOMS("Cell"))->item(i);
00100 if (! linkNode){
00101 std::cout<<"Node LINK does not exist, i="<<i<<std::endl;
00102 return true;
00103 }
00104 DOMElement* linkElement = static_cast<DOMElement *>(linkNode);
00105 if (! linkElement){
00106 std::cout<<"Element LINK does not exist, i="<<i<<std::endl;
00107 return true;
00108 }
00109
00110
00111 DOMNamedNodeMap *attributes = linkNode->getAttributes();
00112 double scalingfactor= getScalingFactor(attributes);
00113
00114
00115
00116 DetId cell = parseCellEntry(attributes);
00117
00118 if(cell!= DetId(0))
00119 {
00120 count++;
00121 caloMap_.addCell(cell,scalingfactor);
00122 } else
00123 {
00124
00125 }
00126
00127 }
00128
00129
00130
00131 return false;
00132
00133 }
00134