JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
MQwPublishable.h
Go to the documentation of this file.
1#pragma once
2
3// System headers
4#include <map>
5
6// ROOT headers
7#include "Rtypes.h"
8
9// Qweak headers
10#include "VQwHardwareChannel.h"
11
12/**
13 * \class MQwPublishable_child
14 * \ingroup QwAnalysis
15 * \brief Mix-in for objects that can publish/request variables via a parent container
16 *
17 * Enables subsystems or data handlers to request external variables from
18 * sibling objects via a parent container, and to publish their own internal
19 * variables for external access. Part of the variable publishing framework.
20 */
21template<class U, class T>
23
24 public:
25
26 /**
27 * \brief Default constructor
28 * Initializes the child object and sets up self-reference for publishing.
29 */
30 MQwPublishable_child() {fSelf = dynamic_cast<T*>(this); };
31
32 /**
33 * \brief Copy constructor
34 * @param source Source object to copy from
35 */
36 MQwPublishable_child(const MQwPublishable_child& source) {fSelf = dynamic_cast<T*>(this);};
37
38 /** \brief Virtual destructor */
39 virtual ~MQwPublishable_child() { };
40
41 /**
42 * \brief Set the parent container for this child object
43 * @param parent Pointer to the parent container that manages variable publishing
44 */
45 void SetParent(U* parent){fParent = parent;};
46
47 /**
48 * \brief Get the parent container for this child object
49 * @return Pointer to the parent container, or nullptr if no parent is set
50 */
51 U* GetParent() const {return fParent;};
52
53
54 protected:
55 /**
56 * \brief Retrieve the variable name from other subsystem arrays
57 * Get the value corresponding to some variable name from a different
58 * data array.
59 * @param name Name of the desired variable
60 * @param value Pointer to the value to be filled by the call
61 * @return True if the variable was found, false if not found
62 */
63 Bool_t RequestExternalValue(const TString& name, VQwHardwareChannel* value) const;
64 /**
65 * \brief Retrieve a pointer to an external variable by name
66 * Requests a direct pointer to a variable from sibling subsystems via the parent container.
67 * @param name Name of the desired variable
68 * @return Pointer to the variable's data element, or nullptr if not found
69 */
70 const VQwHardwareChannel* RequestExternalPointer(const TString& name) const;
71 /**
72 * \brief Publish a variable from this child into the parent container.
73 * @param name Variable key to publish under.
74 * @param desc Human-readable description of the variable.
75 * @param element Pointer to the data element representing this variable.
76 * @return kTRUE if the variable was published; kFALSE on duplicate key or no parent.
77 */
78 Bool_t PublishInternalValue(const TString name, const TString desc, const VQwHardwareChannel* element) const;
79
80
81 /// The functions below should be specified in the fully derived classes.
82 public:
83 /**
84 * \brief Publish all variables of the subsystem
85 * Called to register all internal variables that this subsystem wants to make
86 * available to other subsystems via the publishing framework.
87 * @return kTRUE if all variables were successfully published, kFALSE otherwise
88 */
89 virtual Bool_t PublishInternalValues() const = 0;
90
91 /**
92 * \brief Try to publish an internal variable matching the submitted name
93 * Called when another subsystem requests a variable that hasn't been published yet.
94 * Allows for lazy/on-demand publishing of variables.
95 * @param device_name Name of the variable being requested
96 * @return kTRUE if the variable was found and published, kFALSE otherwise
97 */
98 virtual Bool_t PublishByRequest(TString device_name) = 0;
99
100 private:
103};
104
105
106/**
107 * \class MQwPublishable
108 * \ingroup QwAnalysis
109 * \brief Mix-in for container classes that manage variable publishing
110 *
111 * Provides the container-side logic for the variable publishing system,
112 * including registering published variables, handling external requests,
113 * and maintaining mappings between variable names and data elements.
114 */
115template<class U, class T>
117
118 public:
119
120 /**
121 * \brief Default constructor
122 * Initializes empty variable publishing maps.
123 */
125
126 /**
127 * \brief Copy constructor
128 * Creates a new container with cleared publishing maps (variables are not copied).
129 * @param source Source object to copy from (maps are cleared, not copied)
130 */
136
137 /** \brief Virtual destructor */
138 virtual ~MQwPublishable() { };
139
140 public:
141 std::vector<std::vector<TString> > fPublishList;
142
143 /**
144 * \brief Retrieve a variable value from external sources by copying
145 * Searches for the named variable in external subsystem arrays and copies
146 * its value into the provided data element.
147 * @param name Name of the variable to retrieve
148 * @param value Pointer to data element that will receive the variable's value
149 * @return kTRUE if variable was found and copied, kFALSE otherwise
150 */
151 Bool_t RequestExternalValue(const TString& name, VQwHardwareChannel* value) const;
152
153 /**
154 * \brief Retrieve a direct pointer to an external variable
155 * Searches for the named variable in external subsystem arrays and returns
156 * a direct pointer to the data element.
157 * @param name Name of the variable to retrieve
158 * @return Pointer to the variable's data element, or nullptr if not found
159 */
160 const VQwHardwareChannel* RequestExternalPointer(const TString& name) const;
161
162 /**
163 * \brief Retrieve an internal variable by name (pointer version)
164 * Searches for the named variable among published internal variables and
165 * returns a direct pointer to the data element.
166 * @param name Name of the variable to retrieve
167 * @return Pointer to the variable's data element, or nullptr if not found
168 */
169 virtual const VQwHardwareChannel* ReturnInternalValue(const TString& name) const;
170
171 /**
172 * \brief Retrieve an internal variable by name (copy version)
173 * Searches for the named variable among published internal variables and
174 * copies its value into the provided data element.
175 * @param name Name of the variable to retrieve
176 * @param value Pointer to data element that will receive the variable's value
177 * @return kTRUE if variable was found and copied, kFALSE otherwise
178 */
179 Bool_t ReturnInternalValue(const TString& name, VQwHardwareChannel* value) const;
180
181 /**
182 * \brief List all published variables with descriptions
183 * Prints a summary of all currently published variables and their descriptions
184 * to the logging output for debugging and inspection purposes.
185 */
186 void ListPublishedValues() const;
187
188 /**
189 * \brief Publish an internal variable from a subsystem
190 * Registers a variable from one of the contained subsystems in the publishing
191 * framework, making it available for external access by name.
192 * @param name Unique name/key for the variable
193 * @param desc Human-readable description of the variable
194 * @param subsys Pointer to the subsystem that owns this variable
195 * @param element Pointer to the data element representing this variable
196 * @return kTRUE if variable was successfully published, kFALSE if name already exists
197 */
199 const TString name,
200 const TString desc,
201 const T* subsys,
202 const VQwHardwareChannel* element);
203
204 private:
205 /**
206 * \brief Try to publish an internal variable on demand
207 * Called internally when a variable is requested but not yet published.
208 * Iterates through contained subsystems to find and publish the requested variable.
209 * @param device_name Name of the variable being requested
210 * @return kTRUE if the variable was found and published, kFALSE otherwise
211 */
212 virtual Bool_t PublishByRequest(TString device_name);
213
214 /// Published values
215 std::map<TString, const VQwHardwareChannel*> fPublishedValuesDataElement;
216 std::map<TString, const T*> fPublishedValuesSubsystem;
217 std::map<TString, TString> fPublishedValuesDescription;
218
219};
virtual Bool_t PublishInternalValues() const =0
The functions below should be specified in the fully derived classes.
MQwPublishable_child(const MQwPublishable_child &source)
Copy constructor.
Bool_t RequestExternalValue(const TString &name, VQwHardwareChannel *value) const
Retrieve the variable name from other subsystem arrays Get the value corresponding to some variable n...
Bool_t PublishInternalValue(const TString name, const TString desc, const VQwHardwareChannel *element) const
Publish a variable from this child into the parent container.
virtual ~MQwPublishable_child()
Virtual destructor.
U * GetParent() const
Get the parent container for this child object.
const VQwHardwareChannel * RequestExternalPointer(const TString &name) const
Retrieve a pointer to an external variable by name Requests a direct pointer to a variable from sibli...
virtual Bool_t PublishByRequest(TString device_name)=0
Try to publish an internal variable matching the submitted name Called when another subsystem request...
MQwPublishable_child()
Default constructor Initializes the child object and sets up self-reference for publishing.
void SetParent(U *parent)
Set the parent container for this child object.
MQwPublishable(const MQwPublishable &source)
Copy constructor Creates a new container with cleared publishing maps (variables are not copied).
Bool_t PublishInternalValue(const TString name, const TString desc, const T *subsys, const VQwHardwareChannel *element)
Publish an internal variable from a subsystem Registers a variable from one of the contained subsyste...
virtual Bool_t PublishByRequest(TString device_name)
Try to publish an internal variable on demand Called internally when a variable is requested but not ...
void ListPublishedValues() const
List all published variables with descriptions Prints a summary of all currently published variables ...
virtual ~MQwPublishable()
Virtual destructor.
std::map< TString, const T * > fPublishedValuesSubsystem
MQwPublishable()
Default constructor Initializes empty variable publishing maps.
std::map< TString, const VQwHardwareChannel * > fPublishedValuesDataElement
Published values.
Bool_t RequestExternalValue(const TString &name, VQwHardwareChannel *value) const
Retrieve a variable value from external sources by copying Searches for the named variable in externa...
std::map< TString, TString > fPublishedValuesDescription
std::vector< std::vector< TString > > fPublishList
const VQwHardwareChannel * RequestExternalPointer(const TString &name) const
Retrieve a direct pointer to an external variable Searches for the named variable in external subsyst...
virtual const VQwHardwareChannel * ReturnInternalValue(const TString &name) const
Retrieve an internal variable by name (pointer version) Searches for the named variable among publish...
Abstract base for concrete hardware channels implementing dual-operator pattern.