ChimeraTK-ApplicationCore  04.01.00
ApplicationModule.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2 // SPDX-License-Identifier: LGPL-3.0-or-later
3 #pragma once
4 
6 #include "Logger.h"
7 #include "Model.h"
8 #include "VariableGroup.h"
9 
10 #include <boost/thread.hpp>
11 
12 #include <list>
13 
14 namespace ChimeraTK {
15 
16  /*********************************************************************************************************************/
17 
18  class Application;
19  class ModuleGroup;
20  struct ConfigReader;
21 
22  /********************************************************************************************************************/
23 
25  public:
38  ApplicationModule(ModuleGroup* owner, const std::string& name, const std::string& description,
39  const std::unordered_set<std::string>& tags = {});
40 
42  ApplicationModule() = default;
43 
45  ApplicationModule(ApplicationModule&& other) noexcept { operator=(std::move(other)); }
46 
49 
51  ~ApplicationModule() override;
52 
55  virtual void mainLoop() = 0;
56 
57  void run() override;
58 
59  void terminate() override;
60 
62 
63  VersionNumber getCurrentVersionNumber() const override { return _currentVersionNumber; }
64 
65  DataValidity getDataValidity() const override;
66 
67  void incrementDataFaultCounter() override;
68  void decrementDataFaultCounter() override;
69 
71  size_t getDataFaultCounter() const { return _dataFaultCounter; }
72 
73  void setCurrentVersionNumber(VersionNumber versionNumber) override;
74 
75  std::list<EntityOwner*> getInputModulesRecursively(std::list<EntityOwner*> startList) override;
76 
77  size_t getCircularNetworkHash() const override;
78 
82  void setCircularNetworkHash(size_t circularNetworkHash);
83 
86 
87  void unregisterModule(Module* module) override;
88 
94 
95  protected:
98  void mainLoopWrapper();
99 
101  boost::thread _moduleThread;
102 
105  VersionNumber _currentVersionNumber{nullptr};
106 
111  std::atomic<size_t> _dataFaultCounter{0};
112 
119 
123  detail::CircularDependencyDetectionRecursionStopper _recursionStopper;
124 
128  std::string className() {
129  auto name = boost::core::demangle(typeid(*this).name());
130  return name.substr(name.find_last_of(':') + 1);
131  }
132 
135  };
136 
137  /********************************************************************************************************************/
138 
140  return ChimeraTK::logger(severity, className());
141  }
142 
143  /********************************************************************************************************************/
144 
145 } /* namespace ChimeraTK */
ChimeraTK::EntityOwner::ModuleType::ApplicationModule
@ ApplicationModule
ChimeraTK::Model::Impl
Implementation class for the model.
Definition: Model.h:1358
ChimeraTK::Model::ApplicationModuleProxy
Definition: Model.h:300
ChimeraTK::ApplicationModule::_dataFaultCounter
std::atomic< size_t > _dataFaultCounter
Number of inputs which report DataValidity::faulty.
Definition: ApplicationModule.h:111
VariableGroup.h
ChimeraTK::ModuleGroup
Definition: ModuleGroup.h:16
ChimeraTK::ApplicationModule::getModel
ChimeraTK::Model::ApplicationModuleProxy getModel()
Return the application model proxy representing this module.
Definition: ApplicationModule.h:85
ChimeraTK::ApplicationModule::ApplicationModule
ApplicationModule(ApplicationModule &&other) noexcept
Move operation with the move constructor.
Definition: ApplicationModule.h:45
pybind11::module
module_ module
Definition: PyModuleGroup.h:12
ChimeraTK::Logger::Severity
Severity
Severity levels used by the Logger.
Definition: Logger.h:27
ChimeraTK::ApplicationModule::_currentVersionNumber
VersionNumber _currentVersionNumber
Version number of last push-type read operation - will be passed on to any write operations.
Definition: ApplicationModule.h:105
CircularDependencyDetectionRecursionStopper.h
ChimeraTK::ApplicationModule::setCurrentVersionNumber
void setCurrentVersionNumber(VersionNumber versionNumber) override
Set the current version number.
Definition: ApplicationModule.cc:89
ChimeraTK::logger
Logger::StreamProxy logger(Logger::Severity severity, std::string context)
Convenience function to obtain the logger stream.
Definition: Logger.h:124
ChimeraTK::ApplicationModule::terminate
void terminate() override
Terminate the module.
Definition: ApplicationModule.cc:63
Logger.h
ChimeraTK::ApplicationModule::logger
Logger::StreamProxy logger(Logger::Severity severity)
Convenicene function to obtain a logger stream with the given Severity.
Definition: ApplicationModule.h:139
ChimeraTK::ApplicationModule::_recursionStopper
detail::CircularDependencyDetectionRecursionStopper _recursionStopper
Helper needed to stop the recursion when detecting circular dependency networks.
Definition: ApplicationModule.h:123
ChimeraTK::EntityOwner::ModuleType
ModuleType
Definition: EntityOwner.h:117
ChimeraTK::ApplicationModule::setCircularNetworkHash
void setCircularNetworkHash(size_t circularNetworkHash)
Set the ID of the circular dependency network.
Definition: ApplicationModule.cc:219
ChimeraTK::ApplicationModule
Definition: ApplicationModule.h:24
ChimeraTK::VariableGroup
Definition: VariableGroup.h:22
ChimeraTK::ApplicationModule::operator=
ApplicationModule & operator=(ApplicationModule &&other) noexcept
Move assignment.
Definition: ApplicationModule.cc:35
ChimeraTK::ApplicationModule::mainLoop
virtual void mainLoop()=0
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
Model.h
ChimeraTK::ApplicationModule::decrementDataFaultCounter
void decrementDataFaultCounter() override
Decrement the fault counter and set the data validity flag to ok if the counter has reached 0.
Definition: ApplicationModule.cc:155
ChimeraTK::ApplicationModule::unregisterModule
void unregisterModule(Module *module) override
Unregister another module as a sub-module.
Definition: ApplicationModule.cc:250
ChimeraTK::ApplicationModule::_model
ChimeraTK::Model::ApplicationModuleProxy _model
Definition: ApplicationModule.h:133
ChimeraTK::ApplicationModule::run
void run() override
Execute the module.
Definition: ApplicationModule.cc:55
ChimeraTK::ApplicationModule::_moduleThread
boost::thread _moduleThread
The thread executing mainLoop()
Definition: ApplicationModule.h:101
ChimeraTK::ApplicationModule::_circularNetworkHash
size_t _circularNetworkHash
Unique ID for the circular dependency network.
Definition: ApplicationModule.h:118
ChimeraTK::ApplicationModule::~ApplicationModule
~ApplicationModule() override
Destructor.
Definition: ApplicationModule.cc:83
ChimeraTK::NodeType::Application
@ Application
ChimeraTK::Logger::StreamProxy
Proxy for output stream, handed out to the log sources by the Logger::Module.
Definition: Logger.h:39
ChimeraTK::ApplicationModule::getDataValidity
DataValidity getDataValidity() const override
Return the data validity flag.
Definition: ApplicationModule.cc:232
ChimeraTK::ApplicationModule::getModuleType
ModuleType getModuleType() const override
Return the module type of this module, or in case of a VirtualModule the module type this VirtualModu...
Definition: ApplicationModule.h:61
ChimeraTK::ApplicationModule::incrementDataFaultCounter
void incrementDataFaultCounter() override
Set the data validity flag to fault and increment the fault counter.
Definition: ApplicationModule.cc:151
ChimeraTK::ApplicationModule::ApplicationModule
ApplicationModule()=default
Default constructor: Allows late initialisation of modules (e.g.
ChimeraTK
InvalidityTracer application module.
Definition: spec_dataValidityPropagation.dox:2
ChimeraTK::ApplicationModule::className
std::string className()
Name of the module class, used for logging and debugging purposes.
Definition: ApplicationModule.h:128
ChimeraTK::ApplicationModule::getDataFaultCounter
size_t getDataFaultCounter() const
Get the Number of inputs which report DataValidity::faulty.
Definition: ApplicationModule.h:71
ChimeraTK::ApplicationModule::getCurrentVersionNumber
VersionNumber getCurrentVersionNumber() const override
Return the current version number which has been received with the last push-type read operation.
Definition: ApplicationModule.h:63
ChimeraTK::Module
Base class for ApplicationModule and DeviceModule, to have a common interface for these module types.
Definition: Module.h:21
ChimeraTK::ApplicationModule::getInputModulesRecursively
std::list< EntityOwner * > getInputModulesRecursively(std::list< EntityOwner * > startList) override
Use pointer to the module as unique identifier.
Definition: ApplicationModule.cc:162
ChimeraTK::ApplicationModule::getCircularNetworkHash
size_t getCircularNetworkHash() const override
Get the ID of the circular dependency network (0 if none).
Definition: ApplicationModule.cc:213
ChimeraTK::ApplicationModule::mainLoopWrapper
void mainLoopWrapper()
Wrapper around mainLoop(), to execute additional tasks in the thread before entering the main loop.
Definition: ApplicationModule.cc:97