Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:34

0001 
0002 // Copyright 2008-2025, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 // Author: David Lawrence
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 // XERCES3
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 // __CINT__  __CLING__
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 // __CINT__  __CLING__
0034 #endif // JANA2_HAVE_XERCES
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  // JANA2_HAVE_XERCES
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; // used to store xpaths already found to speed up subsequent requests
0073         pthread_mutex_t found_xpaths_mutex;
0074 #if JANA2_HAVE_XERCES
0075         map<xercesc::DOMNode*, string> node_names;
0076 #endif  // JANA2_HAVE_XERCES
0077 
0078 #if JANA2_HAVE_XERCES
0079 
0080         class SearchParameters{
0081             public:
0082                 // Inputs
0083                 vector<node_t> nodes;       // parsed xpath (see ParseXPath() )
0084                 string attribute_name;      // Name of attribute of interest
0085                 unsigned int attr_depth;    // index of nodes vector containing attribute of interest
0086                 unsigned int max_values;    // return up to max_values attributes (0 means return all)
0087 
0088                 // Outputs
0089                 std::multimap<xercesc::DOMNode*, string> attributes; // DOMnode* is deepest level matched to xpath, string is value of specified attribute
0090 
0091                 // Recursion variables (used to pass state through recursive calls)
0092                 unsigned int depth;     // keeps track of depth in nodes tree
0093                 string attr_value;      // value of attribute of interest in current branch
0094                 xercesc::DOMNode *current_node; // current DOMnode being searched
0095 
0096                 void SearchTree(map<xercesc::DOMNode*, string> &node_names);    // Returns true if a matching node was found
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         //xercesc::DOMNode* FindNode(string xpath, string &attribute, xercesc::DOMNode *after_node=NULL);
0105         //xercesc::DOMNode* SearchTree(xercesc::DOMNode* current_node, unsigned int depth, vector<pair<string, map<string,string> > > &nodes, unsigned int attr_depth, bool find_all=false, vector<xercesc::DOMNode*> *dom_nodes=NULL);
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         // Error handler callback class
0111    class ErrorHandler : public xercesc::ErrorHandler
0112    {
0113             public:
0114                  //  Constructors and Destructor
0115                  ErrorHandler(){}
0116                  ~ErrorHandler(){}
0117                  bool handleError(const xercesc::DOMError& /*domError*/){jerr<<"Got Error!!"<<std::endl; return false;}
0118              void resetErrors(){}
0119       
0120             // Purely virtual methods
0121       void warning(const xercesc::SAXParseException& /*exc*/){}
0122       void error(const xercesc::SAXParseException& /*exc*/){}
0123       void fatalError(const xercesc::SAXParseException& /*exc*/){}
0124 
0125             private :
0126                  //  Unimplemented constructors and operators
0127                  ErrorHandler(const ErrorHandler&);
0128                  void operator=(const ErrorHandler&);
0129         };
0130 
0131     // A simple entity resolver to keep track of files being
0132     // included from the top-level XML file so a full MD5 sum
0133     // can be made
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  // JANA2_HAVE_XERCES
0153 
0154 };
0155 
0156 // The following is here just so we can use ROOT's THtml class to generate documentation.
0157 #ifdef G__DICTIONARY
0158 typedef JGeometryXML::node_t node_t;
0159 #endif
0160 
0161