CMS 3D CMS Logo

MiscalibReaderXML.cc

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 
00010 
00011 int MiscalibReaderFromXML::s_numberOfInstances = 0; //to check that there is only 1 instance
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                 std::cout << "Xerces-c initialization Number "
00030                 << s_numberOfInstances<<std::endl;
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;
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         std::cout<<" Begin Parsing File "<<configFile <<std::endl; 
00082 
00083         XercesDOMParser* parser = new XercesDOMParser;     
00084         parser->setValidationScheme(XercesDOMParser::Val_Auto);
00085         parser->setDoNamespaces(false);
00086         parser->parse(configFile.c_str()); 
00087         DOMDocument* doc = parser->getDocument();
00088         assert(doc);
00089 
00090         unsigned int linkTagsNum = doc->getElementsByTagName(_toDOMS("Cell"))->getLength();
00091         std::cout << "Read number of Cells = " << linkTagsNum << std::endl;
00092 
00093         if(linkTagsNum==0) std::cout <<"Number of Cells in file is 0 - probably bad file format"<<std::endl;
00094 
00095         int count=0;    
00096         for (unsigned int i=0; i<linkTagsNum; i++){
00097                         
00098                 
00099                 DOMNode* linkNode = doc->getElementsByTagName(_toDOMS("Cell"))->item(i);
00101                 if (! linkNode){
00102                         std::cout<<"Node LINK does not exist, i="<<i<<std::endl;
00103                         return true;
00104                 }
00105                 DOMElement* linkElement = static_cast<DOMElement *>(linkNode);          
00106                 if (! linkElement){
00107                         std::cout<<"Element LINK does not exist, i="<<i<<std::endl;
00108                         return true;             
00109                 }
00110 
00111 
00112                 DOMNamedNodeMap *attributes = linkNode->getAttributes();
00113                 double scalingfactor= getScalingFactor(attributes);
00114                 
00115                 
00116                 
00117                 DetId cell = parseCellEntry(attributes);
00118                 
00119                 if(cell!= (DetId) NULL) 
00120                 { 
00121                 count++;
00122                 caloMap_.addCell(cell,scalingfactor);
00123                 } else  
00124                 {
00125                   //            std::cout << "Null received" << std::endl;
00126                 }
00127                 
00128         }
00129  
00130                std::cout << "Number of good Cells =" << count << std::endl;
00131         return false;
00132 
00133 }
00134 

Generated on Tue Jun 9 17:25:12 2009 for CMSSW by  doxygen 1.5.4