File indexing completed on 2025-01-18 10:17:34
0001
0002
0003
0004
0005
0006 #pragma once
0007 #include <iostream>
0008
0009 #include <JANA/JLogger.h>
0010 #include <JANA/Geometry/JGeometry.h>
0011 #include <JANA/Calibrations/JCalibration.h>
0012 #include <JANA/JVersion.h>
0013
0014
0015 #if JANA2_HAVE_XERCES
0016 #if !defined(__CINT__) && !defined(__CLING__)
0017
0018 #include <xercesc/parsers/XercesDOMParser.hpp>
0019 #include <xercesc/dom/DOM.hpp>
0020 #include <xercesc/sax/HandlerBase.hpp>
0021 #include <xercesc/util/XMLString.hpp>
0022 #include <xercesc/util/PlatformUtils.hpp>
0023 #include <xercesc/framework/MemBufInputSource.hpp>
0024
0025 #else
0026 namespace xercesc{
0027 class xercesc::DOMBuilder;
0028 class xercesc::DOMDocument;
0029 class xercesc::DOMNode;
0030 class xercesc::DOMErrorHandler;
0031 class xercesc::DOMError;
0032 }
0033 #endif
0034 #endif
0035
0036
0037 class JGeometryXML:public JGeometry{
0038 public:
0039
0040 typedef pair<string, map<string,string> > node_t;
0041 typedef vector<node_t>::iterator node_iter_t;
0042
0043 JGeometryXML(string url, int run, string context="default");
0044 void Init(string xmlfile, string xml);
0045
0046 virtual ~JGeometryXML();
0047 virtual const char* className(void){return static_className();}
0048 static const char* static_className(void){return "JGeometryXML";}
0049
0050 #if JANA2_HAVE_XERCES
0051 void MapNodeNames(xercesc::DOMNode *current_node);
0052 #endif
0053 bool Get(string xpath, string &sval);
0054 bool Get(string xpath, map<string, string> &svals);
0055 bool GetMultiple(string xpath, vector<string> &vsval);
0056 bool GetMultiple(string xpath, vector<map<string, string> >&vsvals);
0057 void GetXPaths(vector<string> &xpaths, ATTR_LEVEL_t level, const string &filter="");
0058 string GetChecksum(void) const {return md5_checksum;}
0059
0060 void ParseXPath(string xpath, vector<node_t > &nodes, string &attribute, unsigned int &attr_depth) const;
0061 bool NodeCompare(node_iter_t iter1, node_iter_t end1, node_iter_t iter2, node_iter_t end2);
0062
0063
0064 private:
0065 JGeometryXML();
0066
0067 protected:
0068 string xmlfile;
0069 bool valid_xmlfile;
0070 JCalibration *jcalib;
0071 string md5_checksum;
0072 map<string, string> found_xpaths;
0073 pthread_mutex_t found_xpaths_mutex;
0074 #if JANA2_HAVE_XERCES
0075 map<xercesc::DOMNode*, string> node_names;
0076 #endif
0077
0078 #if JANA2_HAVE_XERCES
0079
0080 class SearchParameters{
0081 public:
0082
0083 vector<node_t> nodes;
0084 string attribute_name;
0085 unsigned int attr_depth;
0086 unsigned int max_values;
0087
0088
0089 std::multimap<xercesc::DOMNode*, string> attributes;
0090
0091
0092 unsigned int depth;
0093 string attr_value;
0094 xercesc::DOMNode *current_node;
0095
0096 void SearchTree(map<xercesc::DOMNode*, string> &node_names);
0097 };
0098
0099
0100 xercesc::XercesDOMParser *parser;
0101 xercesc::DOMDocument *doc;
0102
0103 void AddNodeToList(xercesc::DOMNode* start, string start_path, vector<string> &xpaths, JGeometry::ATTR_LEVEL_t level);
0104
0105
0106
0107 void FindAttributeValues(string &xpath, std::multimap<xercesc::DOMNode*, string> &attributes, unsigned int max_values=0);
0108 static void GetAttributes(xercesc::DOMNode* node, map<string,string> &attributes);
0109
0110
0111 class ErrorHandler : public xercesc::ErrorHandler
0112 {
0113 public:
0114
0115 ErrorHandler(){}
0116 ~ErrorHandler(){}
0117 bool handleError(const xercesc::DOMError& ){jerr<<"Got Error!!"<<std::endl; return false;}
0118 void resetErrors(){}
0119
0120
0121 void warning(const xercesc::SAXParseException& ){}
0122 void error(const xercesc::SAXParseException& ){}
0123 void fatalError(const xercesc::SAXParseException& ){}
0124
0125 private :
0126
0127 ErrorHandler(const ErrorHandler&);
0128 void operator=(const ErrorHandler&);
0129 };
0130
0131
0132
0133
0134 class EntityResolver : public xercesc::EntityResolver
0135 {
0136 public:
0137 EntityResolver(const std::string &xmlFile, JCalibration *jcalib);
0138 ~EntityResolver();
0139 xercesc::InputSource* resolveEntity(const XMLCh* const publicId, const XMLCh* const systemId);
0140
0141
0142 std::vector<std::string> GetXMLFilenames(void);
0143 std::string GetMD5_checksum(void);
0144
0145 private:
0146 std::vector<std::string> xml_filenames;
0147 std::vector<std::string> xml_content;
0148 std::string path;
0149 JCalibration *jcalib;
0150 bool PRINT_CHECKSUM_INPUT_FILES;
0151 };
0152 #endif
0153
0154 };
0155
0156
0157 #ifdef G__DICTIONARY
0158 typedef JGeometryXML::node_t node_t;
0159 #endif
0160
0161