JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
MQwPublishable.cc
Go to the documentation of this file.
1/*!
2 * \file MQwPublishable.cc
3 * \brief Mix-in class implementation for publishable data elements
4 */
5
6#include "MQwPublishable.h"
7
8#include "QwSubsystemArray.h"
9#include "VQwSubsystem.h"
10
11#include "QwDataHandlerArray.h"
12#include "VQwDataHandler.h"
13
14/* Retrieve the variable name from other subsystem arrays. See header for docs. */
15template<class U, class T>
16Bool_t MQwPublishable<U,T>::RequestExternalValue(const TString& name, VQwHardwareChannel* value) const
17{
18 // If this has a parent, we should escalate the call to that object,
19 // but so far we don't have that capability.
20 return ReturnInternalValue(name, value);
21}
22
23template<class U, class T>
25{
26 // If this has a parent, we should escalate the call to that object,
27 // but so far we don't have that capability.
28 return ReturnInternalValue(name);
29}
30
31
32/* Retrieve the variable name from subsystems in this subsystem array. */
33template<class U, class T>
35{
36 // First try to find the value in the list of published values.
37 std::map<TString, const VQwHardwareChannel*>::const_iterator iter1 =
39 if (iter1 != fPublishedValuesDataElement.end()) {
40 return iter1->second;
41 }
42 /*
43 // Second, ask the subsystem that has claimed the value
44 typename std::map<TString, const T*>::const_iterator iter2 =
45 fPublishedValuesSubsystem.find(name);
46 if (iter2 != fPublishedValuesSubsystem.end()) {
47 return (iter2->second)->ReturnInternalValue(name);
48 }
49 */
50 // If the value is not yet published, try requesting it.
51 if (const_cast<MQwPublishable*>(this)->PublishByRequest(name)){
52 iter1 = fPublishedValuesDataElement.find(name);
53 if (iter1 != fPublishedValuesDataElement.end()) {
54 return iter1->second;
55 }
56 QwError << "PublishByRequest succeeded, but can't find the record for "
57 << name << QwLog::endl;
58
59 } else {
60 QwDebug << "PublishByRequest failed for " << name << QwLog::endl;
61 }
62 // Not found
63 return 0;
64}
65
66/* Retrieve the variable into provided value pointer. */
67template<class U, class T>
68Bool_t MQwPublishable<U,T>::ReturnInternalValue(const TString& name, VQwHardwareChannel* value) const
69{
70 Bool_t foundit = kFALSE;
71
72 // Check for null pointer
73 if (! value)
74 QwWarning << "MQwPublishable::ReturnInternalValue requires that "
75 << "'value' be a non-null pointer to a VQwHardwareChannel."
76 << QwLog::endl;
77
78 // Get a const pointer to the internal value
79 const VQwHardwareChannel* internal_value = ReturnInternalValue(name);
80 if (value && internal_value) {
81 value->AssignValueFrom(internal_value);
82 foundit = kTRUE;
83 } else
84 QwWarning << "MQwPublishable::ReturnInternalValue: name \""
85 << name << "\" not found in array." << QwLog::endl;
86
87 return foundit;
88}
89
90/* Publish the value name with description from a subsystem in this array. */
91template<class U, class T>
93 const TString name,
94 const TString desc,
95 const T* subsys,
96 const VQwHardwareChannel* element)
97{
98 if (fPublishedValuesSubsystem.count(name) > 0) {
99 QwError << "Attempting to publish existing variable key!" << QwLog::endl;
101 return kFALSE;
102 }
103 fPublishedValuesSubsystem[name] = subsys;
104 fPublishedValuesDescription[name] = desc;
105 fPublishedValuesDataElement[name] = element;
106 return kTRUE;
107}
108
109/* Try to publish an internal variable matching the submitted name. */
110template<class U, class T>
111Bool_t MQwPublishable<U,T>::PublishByRequest(TString device_name)
112{
113 Bool_t status = kFALSE;
114 if (fPublishedValuesSubsystem.count(device_name) > 0) {
115 QwDebug << "MQwPublishable::PublishByRequest: Channel "
116 << device_name << " has already been published."
117 << QwLog::endl;
119 status = kTRUE;
120 } else {
121 U* u = dynamic_cast<U*>(this);
122 if (not u->empty()) {
123 for (auto subsys = u->begin(); subsys != u->end(); ++subsys)
124 {
125 status = (*subsys)->PublishByRequest(device_name);
126 if (status) break;
127 }
128 // Report failure to publish
129 if (! status) {
130 QwDebug << "MQwPublishable::PublishByRequest: Failed to publish channel name: "
131 << device_name << QwLog::endl;
132 }
133 }
134 }
135 return status;
136}
137
138
139/* List the published values and description in this subsystem array. */
140template<class U, class T>
142{
143 QwOut << "List of published values:" << QwLog::endl;
144 std::map<TString,TString>::const_iterator iter;
145 for (iter = fPublishedValuesDescription.begin();
146 iter != fPublishedValuesDescription.end(); iter++) {
147 QwOut << iter->first << ": " << iter->second << QwLog::endl;
148 }
149}
150
152
153/* Get the value corresponding to a variable name from a different data array. */
154template<class U, class T>
156 if (fParent != 0) {
157 return fParent->RequestExternalValue(name,value);
158 }
159 return kFALSE;
161/// \brief Retrieve the variable name from other subsystem arrays
162template<class U, class T>
164 if (fParent != 0) {
165 return fParent->RequestExternalPointer(name);
166 }
167 return NULL;
168}
170// Publish a variable name to the subsystem array. See header for parameters.
171template<class U, class T>
173 const TString name,
174 const TString desc,
175 const VQwHardwareChannel* element) const{
176 // Get the parent and check for existence
177 if (fParent != 0) {
178 // Publish the variable with name in the parent
179 if (fParent->PublishInternalValue(name, desc, fSelf, element) == kFALSE) {
180 QwError << "Could not publish variable " << name
181 << " in from object " << fSelf->GetName() << "!" << QwLog::endl;
182 return kFALSE; // Error: variable could not be puslished
183 }
184 } else {
185 QwError << "Unable to publish; I am an orphan :-(" << QwLog::endl;
186 return kFALSE; // Error: no parent defined
187 }
188 return kTRUE; // Success
189}
190
191
192// Force instantiation of template classes we will need
#define QwOut
Predefined log drain for explicit output.
Definition QwLog.h:34
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
#define QwWarning
Predefined log drain for warnings.
Definition QwLog.h:44
#define QwDebug
Predefined log drain for debugging output.
Definition QwLog.h:59
Definition of the pure virtual base class of all subsystems.
Array container for managing multiple subsystems.
Array container for managing multiple data handlers.
Virtual base class for data handlers accessing multiple subsystems.
Mix-in for objects that can publish/request variables via a parent container.
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.
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...
Mix-in for container classes that manage variable publishing.
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 ...
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
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...
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
Abstract base for concrete hardware channels implementing dual-operator pattern.
void AssignValueFrom(const VQwDataElement *valueptr) override=0