ChimeraTK-ApplicationCore  04.01.00
ChimeraTK::Module Class Referenceabstract

Base class for ApplicationModule and DeviceModule, to have a common interface for these module types. More...

#include <Module.h>

+ Inheritance diagram for ChimeraTK::Module:
+ Collaboration diagram for ChimeraTK::Module:

Public Member Functions

 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...
 
virtual void prepare ()
 Prepare the execution of the module. More...
 
virtual void run ()
 Execute the module. More...
 
virtual void terminate ()
 Terminate the module. 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...
 
virtual std::string getVirtualQualifiedName () const =0
 
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...
 
virtual void unregisterModule (Module *module)
 Unregister 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...
 
virtual ModuleType getModuleType () const =0
 Return the module type of this module, or in case of a VirtualModule the module type this VirtualModule was derived from. 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...
 

Static Public Member Functions

static ConfigReaderappConfig ()
 Obtain the ConfigReader instance of the application. More...
 

Protected Attributes

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...
 

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 Attributes inherited from ChimeraTK::EntityOwner
static constexpr std::string_view namePrefixConstant {"/@CONST@"}
 Prefix for constants created by constant(). More...
 

Detailed Description

Base class for ApplicationModule and DeviceModule, to have a common interface for these module types.

Definition at line 21 of file Module.h.

Constructor & Destructor Documentation

◆ Module() [1/3]

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.

The specified list of tags will be added to all elements directly or indirectly owned by this instance.

Definition at line 13 of file Module.cc.

+ Here is the call graph for this function:

◆ Module() [2/3]

ChimeraTK::Module::Module ( )
default

Default constructor: Allows late initialisation of modules (e.g.

when creating arrays of modules).

This constructor also has to be here to mitigate a bug in gcc. It is needed to allow constructor inheritance of modules owning other modules. This constructor will not actually be called then. See this bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67054

◆ ~Module()

ChimeraTK::Module::~Module ( )
override

Destructor.

Definition at line 23 of file Module.cc.

+ Here is the call graph for this function:

◆ Module() [3/3]

ChimeraTK::Module::Module ( Module &&  other)
inlinenoexcept

Move constructor.

Definition at line 41 of file Module.h.

+ Here is the call graph for this function:

Member Function Documentation

◆ appConfig()

ConfigReader & ChimeraTK::Module::appConfig ( )
static

Obtain the ConfigReader instance of the application.

If no or multiple ConfigReader instances are found, a ChimeraTK::logic_error is thrown. Note: This function is expensive. It should be called only during the constructor of the ApplicationModule and the obtained configuration values should be stored for later use in member variables. Beware that the ConfigReader instance can only be found if it has been constructed before calling this function. Hence, the Application should have the ConfigReader as its first member.

Definition at line 251 of file Module.cc.

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

◆ decrementDataFaultCounter()

void ChimeraTK::Module::decrementDataFaultCounter ( )
inlineoverridevirtual

Decrement the fault counter and set the data validity flag to ok if the counter has reached 0.

This function will be called by all input accessors when receiving the an ok update if the previous update was faulty. The caller of this function must ensure that calles to this function are paired to a previous call to incrementDataFaultCounter().

Implements ChimeraTK::EntityOwner.

Reimplemented in Tests::testDataValidityPropagation::TestModule1.

Definition at line 106 of file Module.h.

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

◆ disable()

void ChimeraTK::Module::disable ( )

Disable the module such that it is not part of the Application.

This function can be called in the constructor, e.g. if the module should be disabled based on the configuration (c.f. ConfigReader). The module will then behave like if it were default-constructed.

Definition at line 257 of file Module.cc.

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

◆ findApplicationModule()

Module * ChimeraTK::Module::findApplicationModule ( )

Find ApplicationModule owner.

If "this" is an ApplicationModule, "this" is returned. If "this" is a VariableGroup, the tree of owners is followed, until the ApplicationModule is found. If "this" is neither an ApplicationModule nor a VariableGroup, a ChimeraTK::logic_error is thrown.

Note: This function treats ApplicationModules and DeviceModules the same (hence the return type must be the common base class).

Definition at line 197 of file Module.cc.

+ Here is the call graph for this function:

◆ getCircularNetworkHash()

size_t ChimeraTK::Module::getCircularNetworkHash ( ) const
inlineoverridevirtual

Get the ID of the circular dependency network (0 if none).

This information is only available after the Application has finalised all connections.

Implements ChimeraTK::EntityOwner.

Definition at line 110 of file Module.h.

+ Here is the call graph for this function:

◆ getCurrentVersionNumber()

VersionNumber ChimeraTK::Module::getCurrentVersionNumber ( ) const
inlineoverridevirtual

Return the current version number which has been received with the last push-type read operation.

Implements ChimeraTK::EntityOwner.

Definition at line 98 of file Module.h.

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

◆ getDataValidity()

DataValidity ChimeraTK::Module::getDataValidity ( ) const
inlineoverridevirtual

Return the data validity flag.

If any This function will be called by all output accessors in their write functions.

Implements ChimeraTK::EntityOwner.

Reimplemented in ChimeraTK::StatusAggregator.

Definition at line 102 of file Module.h.

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

◆ getFullDescription()

std::string ChimeraTK::Module::getFullDescription ( ) const
overridevirtual

Obtain the full description including the full description of the owner.

Implements ChimeraTK::EntityOwner.

Definition at line 225 of file Module.cc.

+ Here is the call graph for this function:

◆ getInputModulesRecursively()

std::list< EntityOwner * > ChimeraTK::Module::getInputModulesRecursively ( std::list< EntityOwner * >  startList)
overridevirtual

Use pointer to the module as unique identifier.

Implements ChimeraTK::EntityOwner.

Definition at line 241 of file Module.cc.

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

◆ getOwner()

EntityOwner* ChimeraTK::Module::getOwner ( ) const
inline

Definition at line 96 of file Module.h.

+ Here is the caller graph for this function:

◆ getQualifiedName()

std::string ChimeraTK::Module::getQualifiedName ( ) const
overridevirtual

Get the fully qualified name of the module instance, i.e.

the name containing all module names further up in the hierarchy.

Implements ChimeraTK::EntityOwner.

Definition at line 219 of file Module.cc.

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

◆ getVirtualQualifiedName()

virtual std::string ChimeraTK::Module::getVirtualQualifiedName ( ) const
pure virtual

◆ incrementDataFaultCounter()

void ChimeraTK::Module::incrementDataFaultCounter ( )
inlineoverridevirtual

Set the data validity flag to fault and increment the fault counter.

This function will be called by all input accessors when receiving the a faulty update if the previous update was ok. The caller of this function must ensure that calls to this function are paired to a subsequent call to decrementDataFaultCounter().

Implements ChimeraTK::EntityOwner.

Reimplemented in Tests::testDataValidityPropagation::TestModule1.

Definition at line 104 of file Module.h.

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

◆ operator=()

Module & ChimeraTK::Module::operator= ( Module &&  other)
noexcept

Move assignment operator.

Definition at line 31 of file Module.cc.

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

◆ prepare()

virtual void ChimeraTK::Module::prepare ( )
inlinevirtual

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 in Tests::testCircularDependencyFaultyFlags::GG, Tests::testInitialValues::WriterModule, Tests::testTrigger::TestModule, Tests::testCircularDependencyFaultyFlags::AA, Tests::testBidirectionalVariables::TestApplication2::Module< ACCESSOR >, Tests::testBidirectionalVariables::TestApplication2::Module< ChimeraTK::ScalarOutputPushRB< int > >, Tests::testBidirectionalVariables::TestApplication2::Module< ChimeraTK::ScalarPushInputWB< int > >, Tests::testInitialValues::ConstantModule, Tests::testAppModuleConnections::ConstantTestModule< T >, Tests::testTestFacilities::PollingThroughFanoutsModule, Tests::testVersionpropagation::TheOutputModule, Tests::testTestFacilities::PollingReadModule, ChimeraTK::ConfigReader, Tests::testUserInputValidator::UpstreamTwinOut, Tests::testAppModuleConnections::TestModuleConsume< T >, OutputModule, Tests::testTestFacilities::ReadAnyTestModule, Tests::testUserInputValidator::UpstreamSingleOut, Tests::testBidirectionalVariables::ModuleB, Tests::testCircularDependencyFaultyFlags::ModuleA, Tests::testUserInputValidator::ModuleAwithSecondInput, Tests::testDataValidityPropagation::TestModule1, Tests::testDeviceExceptionFlagPropagation::TestApplication::Module, Tests::testVariableGroup::OutputModule, Tests::testStatusAggregator::StatusWithMessageGenerator, Tests::testAppModuleConnections::TestModuleFeed< T >, Tests::testDeviceAccessors::TestModule, ChimeraTK::PeriodicTrigger, ChimeraTK::PythonApplicationModuleTrampoline, Tests::testDeviceExceptionFlagPropagation::TestApplication::Name, Tests::testInitialValues::NotifyingModule, Tests::testVariableGroup::InputModule, ChimeraTK::DeviceManager, Tests::testBidirectionalVariables::ModuleA, Tests::testStatusAggregator::StatusGenerator, and Tests::testUserInputValidator::ModuleA.

Definition at line 49 of file Module.h.

◆ readAll()

void ChimeraTK::Module::readAll ( bool  includeReturnChannels = false)

Read all readable variables in the group.

If there are push-type variables in the group, this call will block until all of the variables have received an update. All push-type variables are read first, the poll-type variables are therefore updated with the latest values upon return. includeReturnChannels determines whether return channels of *OutputRB accessors are included in the read.

Definition at line 72 of file Module.cc.

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

◆ readAllLatest()

void ChimeraTK::Module::readAllLatest ( bool  includeReturnChannels = false)

Just call readLatest() on all readable variables in the group.

includeReturnChannels determines whether return channels of *OutputRB accessors are included in the read.

Definition at line 138 of file Module.cc.

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

◆ readAllNonBlocking()

void ChimeraTK::Module::readAllNonBlocking ( bool  includeReturnChannels = false)

Just call readNonBlocking() on all readable variables in the group.

includeReturnChannels determines whether return channels of *OutputRB accessors are included in the read.

Definition at line 106 of file Module.cc.

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

◆ readAnyGroup()

ChimeraTK::ReadAnyGroup ChimeraTK::Module::readAnyGroup ( )

Create a ChimeraTK::ReadAnyGroup for all readable variables in this Module.

Definition at line 54 of file Module.cc.

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

◆ run()

void ChimeraTK::Module::run ( )
virtual

◆ setCurrentVersionNumber()

void ChimeraTK::Module::setCurrentVersionNumber ( VersionNumber  versionNumber)
inlineoverridevirtual

Set the current version number.

This function is called by the push-type input accessors in their read functions.

Implements ChimeraTK::EntityOwner.

Definition at line 100 of file Module.h.

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

◆ setOwner()

void ChimeraTK::Module::setOwner ( EntityOwner newOwner)
inline

Set a new owner.

The caller has to take care himself that the Module gets unregistered with the old owner and registered with the new one. Do not use in user code!

Definition at line 94 of file Module.h.

◆ terminate()

virtual void ChimeraTK::Module::terminate ( )
inlinevirtual

Terminate the module.

Must/will be called before destruction, if run() was called previously.

Reimplemented in ChimeraTK::DeviceManager, ChimeraTK::ApplicationModule, and ChimeraTK::PyApplicationModule.

Definition at line 56 of file Module.h.

◆ writeAll()

void ChimeraTK::Module::writeAll ( bool  includeReturnChannels = false)

Just call write() on all writable variables in the group.

includeReturnChannels determines whether return channels of *InputWB accessors are included in the write.

Definition at line 157 of file Module.cc.

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

◆ writeAllDestructively()

void ChimeraTK::Module::writeAllDestructively ( bool  includeReturnChannels = false)

Just call writeDestructively() on all writable variables in the group.

includeReturnChannels determines whether return channels of *InputWB accessors are included in the write.

Definition at line 177 of file Module.cc.

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

Member Data Documentation

◆ _owner

EntityOwner* ChimeraTK::Module::_owner {nullptr}
protected

Owner of this instance.

Definition at line 139 of file Module.h.


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