μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NodeTreeBuilder.hpp
Go to the documentation of this file.
1/*
2---------------------------------------------------------------------------
3
4 This file is part of uHAL.
5
6 uHAL is a hardware access library and programming framework
7 originally developed for upgrades of the Level-1 trigger of the CMS
8 experiment at CERN.
9
10 uHAL is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 uHAL is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22
23
24 Andrew Rose, Imperial College, London
25 email: awr01 <AT> imperial.ac.uk
26
27 Marc Magrans de Abril, CERN
28 email: marc.magrans.de.abril <AT> cern.ch
29
30---------------------------------------------------------------------------
31*/
32
40#ifndef _uhal_NodeTreeBuilder_hpp_
41#define _uhal_NodeTreeBuilder_hpp_
42
43
44#include <memory>
45
46#include <boost/filesystem/path.hpp>
47#include <boost/spirit/include/qi.hpp>
48
49#include "pugixml.hpp"
50
51#include "uhal/definitions.hpp"
56#include "uhal/Node.hpp"
57#include "uhal/XmlParser.hpp"
58
59
60namespace uhal
61{
62 namespace exception
63 {
65 UHAL_DEFINE_EXCEPTION_CLASS ( NodeMustHaveUID , "Exception class to handle the case where creation of a node was attempted without it having a UID." )
67 UHAL_DEFINE_EXCEPTION_CLASS ( IncorrectAddressTableFileCount , "Exception class to handle the case where too many or two few address files are specified." )
69 UHAL_DEFINE_EXCEPTION_CLASS ( FailedToOpenAddressTableFile , "Exception class to handle the case where the address file failed to open." )
71 UHAL_DEFINE_EXCEPTION_CLASS ( IncrementalNodeRequiresSizeAttribute , "Exception class to handle the case where an incremental node is specified without a size attribute." )
73 UHAL_DEFINE_EXCEPTION_CLASS ( ArraySizeExceedsRegisterBound , "Exception class to handle the case where a memory block has a size which would exceed the available register space." )
74
76 UHAL_DEFINE_EXCEPTION_CLASS ( BlockAccessNodeCannotHaveChild , "Exception class to handle the case when someone tries to give a block access node a child." )
77
79 UHAL_DEFINE_EXCEPTION_CLASS ( MaskedNodeCannotHaveChild , "Exception class to handle the case when someone tries to give a bit-masked node a child." )
80 }
81
82
85 {
86 private:
92
93 public:
94
97
99 virtual ~NodeTreeBuilder ();
100
105 static NodeTreeBuilder& getInstance();
106
113 Node* getNodeTree ( const std::string& aFilenameExpr , const boost::filesystem::path& aPath );
114
116 void clearAddressFileCache();
117
118 Node* build(const pugi::xml_node& aNode, const boost::filesystem::path& aAddressFilePath);
119
120 private:
128 void CallBack ( const std::string& aProtocol , const boost::filesystem::path& aPath , std::vector<uint8_t>& aFile , std::vector< const Node* >& aAddressTable );
129
135 void calculateHierarchicalAddresses ( Node* aNode , const uint32_t& aAddr );
136
137 void checkForAddressCollisions ( Node* aNode , const boost::filesystem::path& aPath );
138
139 Node* plainNodeCreator ( const bool& aRequireId , const pugi::xml_node& aXmlNode );
140 // Node* classNodeCreator ( const bool& aRequireId , const pugi::xml_node& aXmlNode );
141 Node* moduleNodeCreator ( const bool& aRequireId , const pugi::xml_node& aXmlNode );
142 Node* bitmaskNodeCreator ( const bool& aRequireId , const pugi::xml_node& aXmlNode );
143
144 void setUid ( const bool& aRequireId , const pugi::xml_node& aXmlNode , Node* aNode );
145 void setClassName ( const pugi::xml_node& aXmlNode , Node* aNode );
146 void setPars ( const pugi::xml_node& aXmlNode , Node* aNode );
147 void setAddr ( const pugi::xml_node& aXmlNode , Node* aNode );
148 void setTags ( const pugi::xml_node& aXmlNode , Node* aNode );
149 void setDescription ( const pugi::xml_node& aXmlNode , Node* aNode );
150 void setModule ( const pugi::xml_node& aXmlNode , Node* aNode );
151 void setPermissions ( const pugi::xml_node& aXmlNode , Node* aNode );
152 void setMask ( const pugi::xml_node& aXmlNode , Node* aNode );
153 void setModeAndSize ( const pugi::xml_node& aXmlNode , Node* aNode );
154 void setFirmwareInfo ( const pugi::xml_node& aXmlNode , Node* aNode );
155 void addChildren ( const pugi::xml_node& aXmlNode , Node* aNode );
156
157 static const std::string mIdAttribute;
158 static const std::string mAddressAttribute;
159 static const std::string mParametersAttribute;
160 static const std::string mTagsAttribute;
161 static const std::string mDescriptionAttribute;
162 static const std::string mPermissionsAttribute;
163 static const std::string mMaskAttribute;
164 static const std::string mModeAttribute;
165 static const std::string mSizeAttribute;
166 static const std::string mClassAttribute;
167 static const std::string mModuleAttribute;
168 static const std::string mFirmwareInfo;
169
172
173 std::deque< boost::filesystem::path > mFileCallStack;
174
175 private:
177 static std::shared_ptr<NodeTreeBuilder> mInstance;
178
180 std::unordered_map< std::string , const Node* > mNodes;
181
183 static const struct permissions_lut : boost::spirit::qi::symbols<char, defs::NodePermission>
184 {
187 } mPermissionsLut;
188
189
191 static const struct mode_lut : boost::spirit::qi::symbols<char, defs::BlockReadWriteMode>
192 {
194 mode_lut();
195 } mModeLut;
196
197 grammars::NodeTreeClassAttributeGrammar mNodeTreeClassAttributeGrammar;
199 grammars::NodeTreeFirmwareinfoAttributeGrammar mNodeTreeFirmwareInfoAttributeGrammar;
200
201 };
202
203}
204
205#endif
Wrapper to generate a new Python exception type.
Definition: pybind11.h:2517
\rst Holds a reference to a Python object (no reference counting)
Definition: pytypes.h:194
A heirarchical node for navigating heirarchical firmwares.
Definition: Node.hpp:85
A class to build a node tree from an address table file.
NodeTreeBuilder & operator=(const NodeTreeBuilder &)=delete
static const std::string mModeAttribute
static const std::string mTagsAttribute
Parser< Node * > mTopLevelNodeParser
grammars::NodeTreeFirmwareinfoAttributeGrammar mNodeTreeFirmwareInfoAttributeGrammar
static const std::string mSizeAttribute
static const std::string mParametersAttribute
static const std::string mModuleAttribute
std::deque< boost::filesystem::path > mFileCallStack
grammars::NodeTreeClassAttributeGrammar mNodeTreeClassAttributeGrammar
static std::shared_ptr< NodeTreeBuilder > mInstance
The single instance of the class.
static const std::string mAddressAttribute
static const std::string mMaskAttribute
Parser< Node * > mNodeParser
static const std::string mFirmwareInfo
static const std::string mClassAttribute
static const std::string mDescriptionAttribute
std::unordered_map< std::string, const Node * > mNodes
Hash map associating a Node tree with a file name so that we do not need to repeatedly parse the xml ...
grammars::NodeTreeParametersGrammar mNodeTreeParametersGrammar
static const std::string mPermissionsAttribute
NodeTreeBuilder(const NodeTreeBuilder &)=delete
static const std::string mIdAttribute
Forward declaration of the Parser so we can declare it friend.
Definition: XmlParser.hpp:214
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:59
A look-up table that the boost qi parser uses for associating strings ("single","block",...
A look-up table that the boost qi parser uses for associating strings ("r","w","rw",...
A struct wrapping a set of rules as a grammar that can parse a NodeTreeParametersGrammar of the form ...