ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
EntityOwner.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
5#include "Flags.h"
6#include "Utilities.h"
8
9#include <iostream>
10#include <list>
11#include <string>
12#include <unordered_set>
13
14namespace ChimeraTK {
15
16 /********************************************************************************************************************/
17
18 class AccessorBase;
19 class Module;
20
21 /********************************************************************************************************************/
22
27 using TAGS = const std::unordered_set<std::string>;
28
30 std::string negateTag(const std::string& tag);
31
32 /********************************************************************************************************************/
33
39 public:
42 EntityOwner(std::string name, std::string description, std::unordered_set<std::string> tags = {});
43
46
48 virtual ~EntityOwner() = default;
49
51 EntityOwner(EntityOwner&& other) noexcept { operator=(std::move(other)); }
52 EntityOwner(const EntityOwner& other) = delete;
53
55 EntityOwner& operator=(EntityOwner&& other) noexcept;
56 EntityOwner& operator=(const EntityOwner& other) = delete;
57
59 const std::string& getName() const { return _name; }
60
63 virtual std::string getQualifiedName() const = 0;
64
66 std::string getQualifiedNameWithType() const;
67
69 const std::string& getDescription() const { return _description; }
70
73 virtual std::string getFullDescription() const = 0;
74
77 std::list<VariableNetworkNode> getAccessorList() const { return _accessorList; }
78
80 std::list<Module*> getSubmoduleList() const { return _moduleList; }
81
84 std::list<VariableNetworkNode> getAccessorListRecursive() const;
85
88 std::list<Module*> getSubmoduleListRecursive() const;
89
93
96 void unregisterAccessor(const VariableNetworkNode& accessor) { _accessorList.remove(accessor); }
97
103 void registerModule(Module* module, bool addTags = true);
104
107 virtual void unregisterModule(Module* module);
108
112 void addTag(const std::string& tag);
113
115 void dump(const std::string& prefix = "", std::ostream& stream = std::cout) const;
116
118
121 virtual ModuleType getModuleType() const = 0;
122
125 virtual VersionNumber getCurrentVersionNumber() const = 0;
126
129 virtual void setCurrentVersionNumber(VersionNumber versionNumber) = 0;
130
133 virtual DataValidity getDataValidity() const = 0;
134
138 virtual void incrementDataFaultCounter() = 0;
139
144 virtual void decrementDataFaultCounter() = 0;
145
147 virtual std::list<EntityOwner*> getInputModulesRecursively(std::list<EntityOwner*> startList) = 0;
148
152 virtual size_t getCircularNetworkHash() const = 0;
153
156
161 template<typename T>
162 std::string constant(T value);
163
167 static constexpr std::string_view namePrefixConstant{"/@CONST@"};
168
169 protected:
171 std::string _name;
172
174 std::string _description;
175
177 std::list<VariableNetworkNode> _accessorList;
178
180 std::list<Module*> _moduleList;
181
184 std::unordered_set<std::string> _tags;
185
190 std::atomic<bool> _testableModeReached{false};
191 };
192
193 /********************************************************************************************************************/
194
195 template<typename T>
196 std::string EntityOwner::constant(T value) {
197 // Make sure every constant has its unique name to avoid differently typed inputs to be connected to the same
198 // constant. Note that the template type argument T may not match the expected type by the application, since the
199 // type of the constant is determined by the input accessor, not by the type of the value argument of this function.
200 // We hence need to use both the type name and a unique counter as part of the name. The unique counter lives inside
201 // this template function and hence counts for each type T separately!
202 static std::atomic<uint64_t> uid(0);
203 return std::string(namePrefixConstant) + "/" + DataType(typeid(T)).getAsString() + "/" + std::to_string(uid++) +
204 "/" + Utilities::escapeName(userTypeToUserType<std::string>(value), false);
205 }
206
207 /********************************************************************************************************************/
208
209} /* namespace ChimeraTK */
Base class for owners of other EntityOwners (e.g.
Definition EntityOwner.h:38
std::list< Module * > getSubmoduleListRecursive() const
Obtain the list of submodules associated with this instance and any submodules.
const std::string & getName() const
Get the name of the module instance.
Definition EntityOwner.h:59
std::list< VariableNetworkNode > getAccessorList() const
Obtain the list of accessors/variables directly associated with this instance.
Definition EntityOwner.h:77
static constexpr std::string_view namePrefixConstant
Prefix for constants created by constant().
EntityOwner & operator=(const EntityOwner &other)=delete
std::list< Module * > getSubmoduleList() const
Obtain the list of submodules associated with this instance.
Definition EntityOwner.h:80
void registerAccessor(VariableNetworkNode accessor)
Called inside the constructor of Accessor: adds the accessor to the list.
const std::string & getDescription() const
Get the description of the module instance.
Definition EntityOwner.h:69
virtual size_t getCircularNetworkHash() const =0
Get the ID of the circular dependency network (0 if none).
virtual void decrementDataFaultCounter()=0
Decrement the fault counter and set the data validity flag to ok if the counter has reached 0.
EntityOwner()
Default constructor just for late initialisation.
std::string constant(T value)
Create a variable name which will be automatically connected with a constant value.
std::string _name
The name of this instance.
virtual ModuleType getModuleType() const =0
Return the module type of this module, or in case of a VirtualModule the module type this VirtualModu...
virtual void unregisterModule(Module *module)
Unregister another module as a sub-module.
EntityOwner(EntityOwner &&other) noexcept
Move constructor.
Definition EntityOwner.h:51
virtual void incrementDataFaultCounter()=0
Set the data validity flag to fault and increment the fault counter.
virtual void setCurrentVersionNumber(VersionNumber versionNumber)=0
Set the current version number.
void dump(const std::string &prefix="", std::ostream &stream=std::cout) const
Print the full hierarchy to given stream.
std::string _description
The description of this instance.
EntityOwner(const EntityOwner &other)=delete
std::list< Module * > _moduleList
List of modules owned by this instance.
bool hasReachedTestableMode()
Check whether this module has declared that it reached the testable mode.
virtual VersionNumber getCurrentVersionNumber() const =0
Return the current version number which has been received with the last push-type read operation.
std::atomic< bool > _testableModeReached
Flag used by the testable mode to identify whether a thread within the EntityOwner has reached the po...
void registerModule(Module *module, bool addTags=true)
Register another module as a sub-module.
virtual DataValidity getDataValidity() const =0
Return the data validity flag.
virtual std::string getQualifiedName() const =0
Get the fully qualified name of the module instance, i.e.
std::string getQualifiedNameWithType() const
Get the fully qualified name of the module instance, followed by the C++ data type (in pointy bracket...
void addTag(const std::string &tag)
Add a tag to all Application-type nodes inside this group.
EntityOwner & operator=(EntityOwner &&other) noexcept
Move assignment operator.
virtual std::string getFullDescription() const =0
Obtain the full description including the full description of the owner.
std::unordered_set< std::string > _tags
List of tags to be added to all accessors and modules inside this module.
std::list< VariableNetworkNode > _accessorList
List of accessors owned by this instance.
virtual ~EntityOwner()=default
Virtual destructor to make the type polymorphic.
virtual std::list< EntityOwner * > getInputModulesRecursively(std::list< EntityOwner * > startList)=0
Use pointer to the module as unique identifier.
std::list< VariableNetworkNode > getAccessorListRecursive() const
Obtain the list of accessors/variables associated with this instance and any submodules.
void unregisterAccessor(const VariableNetworkNode &accessor)
Called inside the destructor of Accessor: removes the accessor from the list.
Definition EntityOwner.h:96
Base class for ApplicationModule and DeviceModule, to have a common interface for these module types.
Definition Module.h:21
Class describing a node of a variable network.
std::string escapeName(const std::string &name, bool allowDotsAndSlashes)
Convert all characters which are not allowed in variable or module names into underscores followed by...
Definition Utilities.cc:45
InvalidityTracer application module.
const std::unordered_set< std::string > TAGS
Convenience type definition which can optionally be used as a shortcut for the type which defines a l...
Definition EntityOwner.h:27
std::string negateTag(const std::string &tag)
negate tag using prefix '!'