![]() |
|
|||
File indexing completed on 2024-04-06 12:05:31
0001 #ifndef DETECTOR_DESCRIPTION_PARSER_DDL_PARSER_H 0002 #define DETECTOR_DESCRIPTION_PARSER_DDL_PARSER_H 0003 0004 #include "DetectorDescription/Parser/interface/DDLSAX2ExpressionHandler.h" 0005 #include "DetectorDescription/Parser/interface/DDLSAX2FileHandler.h" 0006 #include "DetectorDescription/Parser/interface/DDLSAX2Handler.h" 0007 #include "Utilities/Xerces/interface/Xerces.h" 0008 #include <xercesc/sax/SAXException.hpp> 0009 #include <xercesc/sax2/SAX2XMLReader.hpp> 0010 #include <xercesc/sax2/XMLReaderFactory.hpp> 0011 #include <xercesc/util/XercesDefs.hpp> 0012 #include <xercesc/util/XercesVersion.hpp> 0013 #include <iosfwd> 0014 #include <map> 0015 #include <string> 0016 #include <utility> 0017 #include <vector> 0018 #include <cstddef> 0019 0020 class DDCompactView; 0021 class DDLDocumentProvider; 0022 class DDLElementRegistry; 0023 0024 /// DDLParser is the main class of Detector Description Language Parser. 0025 /** @class DDLParser 0026 * @author Michael Case 0027 * 0028 * DDLParser.h - description 0029 * ------------------- 0030 * begin: Mon Oct 22 2001 0031 * email: case@ucdhep.ucdavis.edu 0032 * 0033 * Singleton which controls the parsing of XML files (DDL). It guarantees 0034 * that a given filename will only be parsed once regardless of its path. 0035 * It now relies on a DDLDocumentProvider class which provides a list of 0036 * file names and URLs to be parsed. 0037 * 0038 * It uses the Xerces C++ Parser from the Apache Group straight-forwardly. 0039 * One main thing to note is that only one DDLParser can ever be made. This 0040 * allows for sub-components of the parser to easily find out information from 0041 * the parser during run-time. 0042 * 0043 * There is an interface to parse just one file. If one uses this method 0044 * and does not use the default DDLDocumentProvider 0045 * user is responsible for also setting the DDRootDef. 0046 * 0047 * Modification: 0048 * 2003-02-13: Michael Case, Stepan Wynhoff and Martin Liendl 0049 * 2003-02-24: same. 0050 * DDLParser will use DDLDocumentProvider (abstract). One of these 0051 * and will be defaulted to DDLConfiguration. This will read 0052 * the "configuration.xml" file provided and will be used by the Parser 0053 * to "get" the files. 0054 * 2005-11-13: Michael Case 0055 * removed some of the un-necessary methods that were deprecated. 0056 * 2010-01 to 2010-04 sometime: Michael Case 0057 * removed singleton-ness. MUST have a DDCompactView to refer to 0058 * and no more default constructor at the moment. 0059 * 2010-07-29: removed DDLConfiguration; use FIPConfiguration, it is easier. 0060 * for CMSSW Framework example see XMLIdealGeometryESSource (different 0061 * DDLDocumentProvider completely 0062 */ 0063 class DDLParser { 0064 public: 0065 typedef XERCES_CPP_NAMESPACE::SAX2XMLReader SAX2XMLReader; 0066 0067 typedef std::map<int, std::pair<std::string, std::string> > FileNameHolder; 0068 0069 DDLParser(DDCompactView& cpv); 0070 0071 DDLParser() = delete; 0072 0073 ~DDLParser(); 0074 0075 /// Parse all files. Return is meaningless. 0076 int parse(const DDLDocumentProvider& dp); 0077 0078 /// Process a single files. 0079 /** 0080 * This method allows a user to add to an existing DDD by 0081 * parsing a new XML file. Ideally, these would be in addition 0082 * to an existing DDD configuration which was processed using 0083 * Parse(...). 0084 * 0085 * The idea is based on whether users decide that the configuration 0086 * will only hold "standard geometry files" and that any ancillary 0087 * parameter files, filters and so forth will be unknown to the main 0088 * configuration file. For me, this seems to go against the principle 0089 * of knowing what files are relevant because now, there is no central 0090 * way to find out (externally) what XML files generate the DDD in memory. 0091 * 0092 * On the other hand, if on any run, a dumpFileList is run, then 0093 * the user will at least know what files were used from where in 0094 * a given run. 0095 * 0096 * 2007-04-06: filename is now relative to src directory of checkout 0097 * (or share). edm:FileInPath used internally. 0098 **/ 0099 bool parseOneFile(const std::string& filename); 0100 0101 // I ASSUME I take ownership of this blob 0102 // void parse( std::vector<unsigned char>* ablob, unsigned int bsize ) ; 0103 //old way void parse( const std::vector<unsigned char>& ablob, unsigned int bsize ) ; 0104 void parse(const std::vector<unsigned char>& ablob, unsigned int bsize); 0105 0106 /// Get the SAX2Parser from the DDLParser. USE WITH CAUTION. Set your own handler, etc. 0107 SAX2XMLReader* getXMLParser(); 0108 0109 /// To get the parent this class allows access to the handler. 0110 /** 0111 * In order to retrieve the name of the parent element from DDLSAX2Handlers. 0112 */ 0113 DDLSAX2FileHandler* getDDLSAX2FileHandler(); 0114 0115 /// Clear the file list - see Warning! 0116 /** 0117 * This could result in mangled geometry if the Core has not been cleared. 0118 **/ 0119 void clearFiles(); 0120 0121 private: 0122 /// Parse File. Just to hold some common looking code. 0123 void parseFile(const int& numtoproc); 0124 0125 /// Is the file already known by the DDLParser? Returns 0 if not found, and index if found. 0126 size_t isFound(const std::string& filename); 0127 0128 /// Is the file already parsed? 0129 bool isParsed(const std::string& filename); 0130 0131 std::string const extractFileName(const std::string& fullname); 0132 0133 std::string const getNameSpace(const std::string& fname); 0134 0135 /// reference to storage 0136 DDCompactView& cpv_; 0137 0138 /// List of files to be processed, obtained from the DDLDocumentProvider. 0139 FileNameHolder fileNames_; 0140 0141 /// Parse status of a given file. 0142 std::map<int, bool> parsed_; 0143 0144 /// Number of files + 1. 0145 size_t nFiles_; 0146 0147 /// Which file is currently being processed. 0148 std::string currFileName_; 0149 0150 /// SAX2XMLReader is one way of parsing. 0151 SAX2XMLReader* SAX2Parser_; 0152 0153 DDLElementRegistry* elementRegistry_; 0154 DDLSAX2FileHandler* fileHandler_; 0155 DDLSAX2ExpressionHandler* expHandler_; 0156 DDLSAX2Handler* errHandler_; 0157 }; 0158 0159 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.2.1 LXR engine. The LXR team |
![]() ![]() |