ChimeraTK-ApplicationCore  04.01.00
ChimeraTK::ConfigReader Struct Reference

Generic module to read an XML config file and provide the defined values as constant variables. More...

#include <ConfigReader.h>

+ Inheritance diagram for ChimeraTK::ConfigReader:
+ Collaboration diagram for ChimeraTK::ConfigReader:

Classes

struct  Array
 Class holding the values and the accessor for one configuration array. More...
 
struct  Var
 Class holding the value and the accessor for one configuration variable. More...
 

Public Member Functions

 ConfigReader (ModuleGroup *owner, const std::string &name, const std::string &fileName, const std::unordered_set< std::string > &tags={})
 
 ~ConfigReader () override
 
void mainLoop () override
 To be implemented by the user: function called in a separate thread executing the main loop of the module. More...
 
void prepare () override
 Prepare the execution of the module. More...
 
template<typename T >
const T & get (const std::string &variableName) const
 Get value for given configuration variable. More...
 
template<typename T >
const T & get (const std::string &variableName, const T &defaultValue) const
 Version of get() which does not throw if the variable does not exist and instead returns the given default value. More...
 
std::list< std::string > getModules (const std::string &path={}) const
 Returns a list of names of modules which are direct children of path. More...
 
- Public Member Functions inherited from ChimeraTK::ApplicationModule
 ApplicationModule (ModuleGroup *owner, const std::string &name, const std::string &description, const std::unordered_set< std::string > &tags={})
 Create ApplicationModule and register it with its owner. More...
 
 ApplicationModule ()=default
 Default constructor: Allows late initialisation of modules (e.g. More...
 
 ApplicationModule (ApplicationModule &&other) noexcept
 Move operation with the move constructor. More...
 
ApplicationModuleoperator= (ApplicationModule &&other) noexcept
 Move assignment. More...
 
 ~ApplicationModule () override
 Destructor. More...
 
void run () override
 Execute the module. More...
 
void terminate () override
 Terminate the module. More...
 
ModuleType getModuleType () const override
 Return the module type of this module, or in case of a VirtualModule the module type this VirtualModule was derived from. More...
 
VersionNumber getCurrentVersionNumber () const override
 Return the current version number which has been received with the last push-type read operation. More...
 
DataValidity getDataValidity () const override
 Return the data validity flag. More...
 
void incrementDataFaultCounter () override
 Set the data validity flag to fault and increment the fault counter. More...
 
void decrementDataFaultCounter () override
 Decrement the fault counter and set the data validity flag to ok if the counter has reached 0. More...
 
size_t getDataFaultCounter () const
 Get the Number of inputs which report DataValidity::faulty. More...
 
void setCurrentVersionNumber (VersionNumber versionNumber) override
 Set the current version number. More...
 
std::list< EntityOwner * > getInputModulesRecursively (std::list< EntityOwner * > startList) override
 Use pointer to the module as unique identifier. More...
 
size_t getCircularNetworkHash () const override
 Get the ID of the circular dependency network (0 if none). More...
 
void setCircularNetworkHash (size_t circularNetworkHash)
 Set the ID of the circular dependency network. More...
 
ChimeraTK::Model::ApplicationModuleProxy getModel ()
 Return the application model proxy representing this module. More...
 
void unregisterModule (Module *module) override
 Unregister another module as a sub-module. More...
 
Logger::StreamProxy logger (Logger::Severity severity)
 Convenicene function to obtain a logger stream with the given Severity. More...
 
- Public Member Functions inherited from ChimeraTK::VariableGroup
 VariableGroup (VariableGroup *owner, const std::string &name, const std::string &description, const std::unordered_set< std::string > &tags={})
 Constructor: Create VariableGroup register it with its owner. More...
 
 VariableGroup ()=default
 Default constructor: Allows late initialisation of VariableGroups (e.g. More...
 
 VariableGroup (VariableGroup &&other) noexcept
 Move constructor. More...
 
 VariableGroup (const VariableGroup &other) noexcept=delete
 
VariableGroupoperator= (VariableGroup &&other) noexcept
 Move assignment. More...
 
VariableGroupoperator= (const VariableGroup &other) noexcept=delete
 
ModuleType getModuleType () const override
 Return the module type of this module, or in case of a VirtualModule the module type this VirtualModule was derived from. More...
 
ChimeraTK::Model::VariableGroupProxy getModel ()
 Return the application model proxy representing this module. More...
 
std::string getVirtualQualifiedName () const override
 
void unregisterModule (Module *module) override
 Unregister another module as a sub-module. More...
 
- Public Member Functions inherited from ChimeraTK::Module
 Module (EntityOwner *owner, const std::string &name, const std::string &description, const std::unordered_set< std::string > &tags={})
 Constructor: Create Module by the given name with the given description and register it with its owner. More...
 
 Module ()=default
 Default constructor: Allows late initialisation of modules (e.g. More...
 
 ~Module () override
 Destructor. More...
 
 Module (Module &&other) noexcept
 Move constructor. More...
 
Moduleoperator= (Module &&other) noexcept
 Move assignment operator. More...
 
ChimeraTK::ReadAnyGroup readAnyGroup ()
 Create a ChimeraTK::ReadAnyGroup for all readable variables in this Module. More...
 
void readAll (bool includeReturnChannels=false)
 Read all readable variables in the group. More...
 
void readAllNonBlocking (bool includeReturnChannels=false)
 Just call readNonBlocking() on all readable variables in the group. More...
 
void readAllLatest (bool includeReturnChannels=false)
 Just call readLatest() on all readable variables in the group. More...
 
void writeAll (bool includeReturnChannels=false)
 Just call write() on all writable variables in the group. More...
 
void writeAllDestructively (bool includeReturnChannels=false)
 Just call writeDestructively() on all writable variables in the group. More...
 
std::string getQualifiedName () const override
 Get the fully qualified name of the module instance, i.e. More...
 
std::string getFullDescription () const override
 Obtain the full description including the full description of the owner. More...
 
void setOwner (EntityOwner *newOwner)
 Set a new owner. More...
 
EntityOwnergetOwner () const
 
VersionNumber getCurrentVersionNumber () const override
 Return the current version number which has been received with the last push-type read operation. More...
 
void setCurrentVersionNumber (VersionNumber version) override
 Set the current version number. More...
 
DataValidity getDataValidity () const override
 Return the data validity flag. More...
 
void incrementDataFaultCounter () override
 Set the data validity flag to fault and increment the fault counter. More...
 
void decrementDataFaultCounter () override
 Decrement the fault counter and set the data validity flag to ok if the counter has reached 0. More...
 
std::list< EntityOwner * > getInputModulesRecursively (std::list< EntityOwner * > startList) override
 Use pointer to the module as unique identifier. More...
 
size_t getCircularNetworkHash () const override
 Get the ID of the circular dependency network (0 if none). More...
 
ModulefindApplicationModule ()
 Find ApplicationModule owner. More...
 
void disable ()
 Disable the module such that it is not part of the Application. More...
 
- Public Member Functions inherited from ChimeraTK::EntityOwner
 EntityOwner (std::string name, std::string description, std::unordered_set< std::string > tags={})
 Constructor: Create EntityOwner by the given name with the given description. More...
 
 EntityOwner ()
 Default constructor just for late initialisation. More...
 
virtual ~EntityOwner ()=default
 Virtual destructor to make the type polymorphic. More...
 
 EntityOwner (EntityOwner &&other) noexcept
 Move constructor. More...
 
 EntityOwner (const EntityOwner &other)=delete
 
EntityOwneroperator= (EntityOwner &&other) noexcept
 Move assignment operator. More...
 
EntityOwneroperator= (const EntityOwner &other)=delete
 
const std::string & getName () const
 Get the name of the module instance. More...
 
std::string getQualifiedNameWithType () const
 Get the fully qualified name of the module instance, followed by the C++ data type (in pointy brackets) More...
 
const std::string & getDescription () const
 Get the description of the module instance. More...
 
std::list< VariableNetworkNodegetAccessorList () const
 Obtain the list of accessors/variables directly associated with this instance. More...
 
std::list< Module * > getSubmoduleList () const
 Obtain the list of submodules associated with this instance. More...
 
std::list< VariableNetworkNodegetAccessorListRecursive () const
 Obtain the list of accessors/variables associated with this instance and any submodules. More...
 
std::list< Module * > getSubmoduleListRecursive () const
 Obtain the list of submodules associated with this instance and any submodules. More...
 
void registerAccessor (VariableNetworkNode accessor)
 Called inside the constructor of Accessor: adds the accessor to the list. More...
 
void unregisterAccessor (const VariableNetworkNode &accessor)
 Called inside the destructor of Accessor: removes the accessor from the list. More...
 
void registerModule (Module *module, bool addTags=true)
 Register another module as a sub-module. More...
 
void addTag (const std::string &tag)
 Add a tag to all Application-type nodes inside this group. More...
 
void dump (const std::string &prefix="", std::ostream &stream=std::cout) const
 Print the full hierarchy to given stream. More...
 
bool hasReachedTestableMode ()
 Check whether this module has declared that it reached the testable mode. More...
 
template<typename T >
std::string constant (T value)
 Create a variable name which will be automatically connected with a constant value. More...
 

Protected Types

template<typename T >
using MapOfVar = std::unordered_map< std::string, Var< T > >
 Define type for map of std::string to Var, so we can put it into the TemplateUserTypeMap. More...
 
template<typename T >
using MapOfArray = std::unordered_map< std::string, Array< T > >
 Define type for map of std::string to Array, so we can put it into the TemplateUserTypeMap. More...
 

Protected Member Functions

void construct (const std::string &fileName)
 Helper function to avoid code duplication in constructors. More...
 
void parsingError (const std::string &message)
 throw a parsing error with more information More...
 
template<typename T >
void createVar (const std::string &name, const std::string &value)
 Create an instance of Var<T> and place it on the variableMap. More...
 
template<typename T >
void createArray (const std::string &name, const std::map< size_t, std::string > &values)
 Create an instance of Array<T> and place it on the arrayMap. More...
 
void checkVariable (std::string const &name, std::string const &type) const
 Check if variable exists in the config and if type of var name in the config file matches the given type. More...
 
void checkArray (std::string const &name, std::string const &type) const
 Check if array exists in the config and if type of array name in the config file matches the given type. More...
 
template<typename T >
const T & getImpl (const std::string &variableName, T *) const
 Implementation of get() which can be overloaded for scalars and vectors. More...
 
template<typename T >
const std::vector< T > & getImpl (const std::string &variableName, std::vector< T > *) const
 
- Protected Member Functions inherited from ChimeraTK::ApplicationModule
void mainLoopWrapper ()
 Wrapper around mainLoop(), to execute additional tasks in the thread before entering the main loop. More...
 
std::string className ()
 Name of the module class, used for logging and debugging purposes. More...
 

Protected Attributes

std::string _fileName
 File name. More...
 
std::unique_ptr< ModuleTree_moduleTree
 List to hold VariableNodes corresponding to xml modules. More...
 
ChimeraTK::TemplateUserTypeMapNoVoid< MapOfVar_variableMap
 Type-depending map of vectors of variables. More...
 
ChimeraTK::TemplateUserTypeMapNoVoid< MapOfArray_arrayMap
 Type-depending map of vectors of arrays. More...
 
ChimeraTK::SingleTypeUserTypeMapNoVoid< const char * > _typeMap
 Map assigning string type identifyers to C++ types. More...
 
- Protected Attributes inherited from ChimeraTK::ApplicationModule
boost::thread _moduleThread
 The thread executing mainLoop() More...
 
VersionNumber _currentVersionNumber {nullptr}
 Version number of last push-type read operation - will be passed on to any write operations. More...
 
std::atomic< size_t > _dataFaultCounter {0}
 Number of inputs which report DataValidity::faulty. More...
 
size_t _circularNetworkHash {0}
 Unique ID for the circular dependency network. More...
 
detail::CircularDependencyDetectionRecursionStopper _recursionStopper
 Helper needed to stop the recursion when detecting circular dependency networks. More...
 
ChimeraTK::Model::ApplicationModuleProxy _model
 
- Protected Attributes inherited from ChimeraTK::VariableGroup
ChimeraTK::Model::VariableGroupProxy _model
 
- Protected Attributes inherited from ChimeraTK::Module
EntityOwner_owner {nullptr}
 Owner of this instance. More...
 
- Protected Attributes inherited from ChimeraTK::EntityOwner
std::string _name
 The name of this instance. More...
 
std::string _description
 The description of this instance. More...
 
std::list< VariableNetworkNode_accessorList
 List of accessors owned by this instance. More...
 
std::list< Module * > _moduleList
 List of modules owned by this instance. More...
 
std::unordered_set< std::string > _tags
 List of tags to be added to all accessors and modules inside this module. More...
 
std::atomic< bool > _testableModeReached {false}
 Flag used by the testable mode to identify whether a thread within the EntityOwner has reached the point where the testable mode lock is acquired. More...
 

Friends

struct FunctorFill
 
struct ArrayFunctorFill
 
struct FunctorSetValues
 
struct FunctorSetValuesArray
 
struct FunctorGetTypeForName
 

Additional Inherited Members

- Public Types inherited from ChimeraTK::EntityOwner
enum  ModuleType {
  ModuleType::ApplicationModule, ModuleType::ModuleGroup, ModuleType::VariableGroup, ModuleType::ControlSystem,
  ModuleType::Device, ModuleType::Invalid
}
 
- Static Public Member Functions inherited from ChimeraTK::Module
static ConfigReaderappConfig ()
 Obtain the ConfigReader instance of the application. More...
 
- Static Public Attributes inherited from ChimeraTK::EntityOwner
static constexpr std::string_view namePrefixConstant {"/@CONST@"}
 Prefix for constants created by constant(). More...
 

Detailed Description

Generic module to read an XML config file and provide the defined values as constant variables.

The config file should look like this:

<configuration>
<variable name="variableName" type="int32" value="42"/>
<variable name="anotherVariable" type="string" value="Hello world!"/>
<variable name="someArray" type="string">
<value i="0" v="StringEntry1" />
<value i="1" v="StringEntry2" />
<value i="2" v="StringEntry3" />
<value i="3" v="StringEntry4" />
<value i="4" v="StringEntry5" />
<value i="5" v="StringEntry6" />
</variable>
</configuration>

Outputs are created for each variable, so they can be connected to other modules. All values will be provided to the receivers already in the preparation phase, so no read() must be called. Updates will never be sent, so any blocking read operation on the receivers will block forever.

Configuration values can already be accessed during the Application::defineConnections() function by using the ConfigReader::get() function.

Examples
demoStatusMonitor.cc.

Definition at line 113 of file ConfigReader.h.

Member Typedef Documentation

◆ MapOfArray

template<typename T >
using ChimeraTK::ConfigReader::MapOfArray = std::unordered_map<std::string, Array<T> >
protected

Define type for map of std::string to Array, so we can put it into the TemplateUserTypeMap.

Definition at line 206 of file ConfigReader.h.

◆ MapOfVar

template<typename T >
using ChimeraTK::ConfigReader::MapOfVar = std::unordered_map<std::string, Var<T> >
protected

Define type for map of std::string to Var, so we can put it into the TemplateUserTypeMap.

Definition at line 198 of file ConfigReader.h.

Constructor & Destructor Documentation

◆ ConfigReader()

ChimeraTK::ConfigReader::ConfigReader ( ModuleGroup owner,
const std::string &  name,
const std::string &  fileName,
const std::unordered_set< std::string > &  tags = {} 
)

Definition at line 279 of file ConfigReader.cc.

+ Here is the call graph for this function:

◆ ~ConfigReader()

ChimeraTK::ConfigReader::~ConfigReader ( )
overridedefault

Member Function Documentation

◆ checkArray()

void ChimeraTK::ConfigReader::checkArray ( std::string const &  name,
std::string const &  type 
) const
protected

Check if array exists in the config and if type of array name in the config file matches the given type.

Throws logic_errors otherwise.

Definition at line 210 of file ConfigReader.cc.

+ Here is the caller graph for this function:

◆ checkVariable()

void ChimeraTK::ConfigReader::checkVariable ( std::string const &  name,
std::string const &  type 
) const
protected

Check if variable exists in the config and if type of var name in the config file matches the given type.

Throws logic_errors otherwise.

Definition at line 188 of file ConfigReader.cc.

+ Here is the caller graph for this function:

◆ construct()

void ChimeraTK::ConfigReader::construct ( const std::string &  fileName)
protected

Helper function to avoid code duplication in constructors.

Definition at line 358 of file ConfigReader.cc.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createArray()

template<typename T >
void ChimeraTK::ConfigReader::createArray ( const std::string &  name,
const std::map< size_t, std::string > &  values 
)
protected

Create an instance of Array<T> and place it on the arrayMap.

Definition at line 248 of file ConfigReader.cc.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createVar()

template<typename T >
void ChimeraTK::ConfigReader::createVar ( const std::string &  name,
const std::string &  value 
)
protected

Create an instance of Var<T> and place it on the variableMap.

Definition at line 231 of file ConfigReader.cc.

+ Here is the caller graph for this function:

◆ get() [1/2]

template<typename T >
const T & ChimeraTK::ConfigReader::get ( const std::string &  variableName) const

Get value for given configuration variable.

This is already accessible right after construction of this object. Throws ChimeraTK::logic_error if variable doesn't exist. To obtain the value of an array, use an std::vector<T> as template argument.

Definition at line 248 of file ConfigReader.h.

+ Here is the call graph for this function:

◆ get() [2/2]

template<typename T >
const T & ChimeraTK::ConfigReader::get ( const std::string &  variableName,
const T &  defaultValue 
) const

Version of get() which does not throw if the variable does not exist and instead returns the given default value.

FIXME: Do not implement with try-catch.

Definition at line 234 of file ConfigReader.h.

+ Here is the call graph for this function:

◆ getImpl() [1/2]

template<typename T >
const std::vector< T > & ChimeraTK::ConfigReader::getImpl ( const std::string &  variableName,
std::vector< T > *   
) const
protected

Definition at line 265 of file ConfigReader.h.

+ Here is the call graph for this function:

◆ getImpl() [2/2]

template<typename T >
const T & ChimeraTK::ConfigReader::getImpl ( const std::string &  variableName,
T *   
) const
protected

Implementation of get() which can be overloaded for scalars and vectors.

The second argument is a dummy only to distinguish the two overloaded functions.

Definition at line 256 of file ConfigReader.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getModules()

std::list< std::string > ChimeraTK::ConfigReader::getModules ( const std::string &  path = {}) const

Returns a list of names of modules which are direct children of path.

If path does not exist, will return an empty list.

Definition at line 402 of file ConfigReader.cc.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mainLoop()

void ChimeraTK::ConfigReader::mainLoop ( )
inlineoverridevirtual

To be implemented by the user: function called in a separate thread executing the main loop of the module.

Implements ChimeraTK::ApplicationModule.

Definition at line 118 of file ConfigReader.h.

◆ parsingError()

void ChimeraTK::ConfigReader::parsingError ( const std::string &  message)
protected

throw a parsing error with more information

Definition at line 396 of file ConfigReader.cc.

+ Here is the caller graph for this function:

◆ prepare()

void ChimeraTK::ConfigReader::prepare ( )
overridevirtual

Prepare the execution of the module.

This function is called before any module is started (including internal modules like FanOuts) and before the initial values of the variables are pushed into the queues. Reading and writing variables at this point may result in undefined behaviour.

Reimplemented from ChimeraTK::Module.

Definition at line 466 of file ConfigReader.cc.

Friends And Related Function Documentation

◆ ArrayFunctorFill

friend struct ArrayFunctorFill
friend

Definition at line 224 of file ConfigReader.h.

◆ FunctorFill

friend struct FunctorFill
friend

Definition at line 223 of file ConfigReader.h.

◆ FunctorGetTypeForName

friend struct FunctorGetTypeForName
friend

Definition at line 227 of file ConfigReader.h.

◆ FunctorSetValues

friend struct FunctorSetValues
friend

Definition at line 225 of file ConfigReader.h.

◆ FunctorSetValuesArray

friend struct FunctorSetValuesArray
friend

Definition at line 226 of file ConfigReader.h.

Member Data Documentation

◆ _arrayMap

ChimeraTK::TemplateUserTypeMapNoVoid<MapOfArray> ChimeraTK::ConfigReader::_arrayMap
protected

Type-depending map of vectors of arrays.

Definition at line 209 of file ConfigReader.h.

◆ _fileName

std::string ChimeraTK::ConfigReader::_fileName
protected

File name.

Definition at line 147 of file ConfigReader.h.

◆ _moduleTree

std::unique_ptr<ModuleTree> ChimeraTK::ConfigReader::_moduleTree
protected

List to hold VariableNodes corresponding to xml modules.

Definition at line 150 of file ConfigReader.h.

◆ _typeMap

ChimeraTK::SingleTypeUserTypeMapNoVoid<const char*> ChimeraTK::ConfigReader::_typeMap
protected
Initial value:
{"int8", "uint8", "int16", "uint16", "int32", "uint32",
"int64", "uint64", "float", "double", "string", "boolean"}

Map assigning string type identifyers to C++ types.

Definition at line 212 of file ConfigReader.h.

◆ _variableMap

ChimeraTK::TemplateUserTypeMapNoVoid<MapOfVar> ChimeraTK::ConfigReader::_variableMap
protected

Type-depending map of vectors of variables.

Definition at line 201 of file ConfigReader.h.


The documentation for this struct was generated from the following files: