Belle II Software development
NSMVHandler.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#ifndef _Belle2_NSMVHandler_h
9#define _Belle2_NSMVHandler_h
10
11#include <daq/slc/nsm/NSMVar.h>
12
13#include <vector>
14#include <map>
15
16namespace Belle2 {
23
24 friend class Callback;
25 friend class AbstractNSMCallback;
26 friend class NSMCallback;
27
28 public:
29 static NSMVHandler* create(const NSMVar& var);
30
31 public:
32 NSMVHandler(const std::string& node, const std::string& name,
33 bool useget, bool useset)
34 : m_id(0), m_timestamp(0), m_node(node), m_name(name),
35 m_useget(useget), m_useset(useset), m_var(name) {}
36 virtual ~NSMVHandler() {}
37
38 public:
39 virtual bool handleGet(NSMVar& var)
40 {
41 var = m_var;
42 return true;
43 }
44 virtual bool handleSet(const NSMVar& var)
45 {
46 m_var = var;
47 return true;
48 }
49
50 public:
51 const std::string& getNode() const { return m_node; }
52 const std::string& getName() const { return m_name; }
53 bool useGet() const { return m_useget; }
54 bool useSet() const { return m_useset; }
55 void setUseGet(bool use) { m_useget = use; }
56 void setUseSet(bool use) { m_useset = use; }
57 int getTimeStamp() const { return m_timestamp; }
58 int getId() const { return m_id; }
59 void setNode(const std::string& node) { m_node = node; }
60 void setId(int id) { m_id = id; }
61 void set(const NSMVar& var) { m_var = var; }
62 void set(int val) { m_var = val; }
63 void set(float val) { m_var = val; }
64 void set(const std::string& val) { m_var = val; }
65 void set(const std::vector<int>& val) { m_var = val; }
66 void set(const std::vector<float>& val) { m_var = val; }
67 const NSMVar& get() const { return m_var; }
68 NSMVar& get() { return m_var; }
69 NSMVar::Type getType() const { return m_var.getType(); }
70 const char* getTypeLabel() const { return m_var.getTypeLabel(); }
71 bool isDumped() const { return m_isdump; }
72 void setDumped(bool isdump) { m_isdump = isdump; }
73
74 protected:
75 int m_id;
76 int m_timestamp;
77 std::string m_node;
78 std::string m_name;
79 bool m_useget;
80 bool m_useset;
81 NSMVar m_var;
82 bool m_isdump;
83
84 };
85
86 typedef std::map<std::string, NSMVHandler*> NSMVHandlerList;
87
88 class NSMVHandlerInt : public NSMVHandler {
89
90 public:
91 NSMVHandlerInt(const std::string& name,
92 bool useget, bool useset, int val = 0)
93 : NSMVHandler("", name, useget, useset)
94 {
95 m_var = val;
96 }
97 NSMVHandlerInt(const std::string& node, const std::string& name,
98 bool useget, bool useset, int val = 0)
99 : NSMVHandler(node, name, useget, useset)
100 {
101 m_var = val;
102 }
103 virtual ~NSMVHandlerInt() {}
104
105 public:
106 bool handleGet(NSMVar& var) override;
107 bool handleSet(const NSMVar& var) override;
108
109 public:
110 virtual bool handleGetInt(int& val)
111 {
112 val = m_var.getInt();
113 return true;
114 }
115 virtual bool handleSetInt(int val)
116 {
117 m_var = val;
118 return true;
119 }
120
121 };
122
124
125 public:
126 NSMVHandlerFloat(const std::string& name,
127 bool useget, bool useset, float val = 0)
128 : NSMVHandler("", name, useget, useset)
129 {
130 m_var = val;
131 }
132 NSMVHandlerFloat(const std::string& node, const std::string& name,
133 bool useget, bool useset, float val = 0)
134 : NSMVHandler(node, name, useget, useset)
135 {
136 m_var = val;
137 }
138 virtual ~NSMVHandlerFloat() {}
139
140 private:
141 bool handleGet(NSMVar& var) override;
142 bool handleSet(const NSMVar& var) override;
143
144 public:
145 virtual bool handleGetFloat(float& val)
146 {
147 val = m_var.getFloat();
148 return true;
149 }
150 virtual bool handleSetFloat(float val)
151 {
152 m_var = val;
153 return true;
154 }
155
156 };
157
159
160 public:
161 NSMVHandlerText(const std::string& name,
162 bool useget, bool useset, const std::string& val = "")
163 : NSMVHandler("", name, useget, useset)
164 {
165 m_var = val;
166 }
167 NSMVHandlerText(const std::string& node, const std::string& name,
168 bool useget, bool useset, const std::string& val = "")
169 : NSMVHandler(node, name, useget, useset)
170 {
171 m_var = val;
172 }
173 virtual ~NSMVHandlerText() {}
174
175 private:
176 bool handleGet(NSMVar& var) override;
177 bool handleSet(const NSMVar& var) override;
178
179 public:
180 virtual bool handleGetText(std::string& val)
181 {
182 val = m_var.getText();
183 return true;
184 }
185 virtual bool handleSetText(const std::string& val)
186 {
187 m_var = val;
188 return true;
189 }
190
191 };
192
194
195 public:
196 NSMVHandlerIntArray(const std::string& name,
197 bool useget, bool useset,
198 const std::vector<int>& val = std::vector<int>())
199 : NSMVHandler("", name, useget, useset)
200 {
201 m_var = val;
202 }
203 NSMVHandlerIntArray(const std::string& node, const std::string& name,
204 bool useget, bool useset,
205 const std::vector<int>& val = std::vector<int>())
206 : NSMVHandler(node, name, useget, useset)
207 {
208 m_var = val;
209 }
210 virtual ~NSMVHandlerIntArray() {}
211
212 public:
213 bool handleGet(NSMVar& var) override;
214 bool handleSet(const NSMVar& var) override;
215
216 public:
217 virtual bool handleGetIntArray(std::vector<int>& val);
218 virtual bool handleSetIntArray(const std::vector<int>& val)
219 {
220 m_var = val;
221 return true;
222 }
223
224 };
225
227
228 public:
229 NSMVHandlerFloatArray(const std::string& name,
230 bool useget, bool useset,
231 const std::vector<float>& val = std::vector<float>())
232 : NSMVHandler("", name, useset, useget)
233 {
234 m_var = val;
235 }
236 NSMVHandlerFloatArray(const std::string& node, const std::string& name,
237 bool useget, bool useset,
238 const std::vector<float>& val = std::vector<float>())
239 : NSMVHandler(node, name, useset, useget)
240 {
241 m_var = val;
242 }
243 virtual ~NSMVHandlerFloatArray() {}
244
245 public:
246 bool handleGet(NSMVar& var) override;
247 bool handleSet(const NSMVar& var) override;
248
249 public:
250 virtual bool handleGetFloatArray(std::vector<float>& val);
251 virtual bool handleSetFloatArray(const std::vector<float>& val)
252 {
253 m_var = val;
254 return true;
255 }
256
257 };
258
259 class NSMCallback;
260
262
263 public:
264 NSMVHandlerRef(NSMCallback& callback,
265 const std::string& name,
266 const std::string& refname)
267 : NSMVHandler("", name, true, true),
268 m_callback(callback), m_refname(refname) {}
269 virtual ~NSMVHandlerRef() {}
270
271 public:
272 bool handleGet(NSMVar& var) override;
273 bool handleSet(const NSMVar& var) override;
274
275 private:
276 NSMCallback& m_callback;
277 std::string m_refname;
278
279 };
280
282};
283
284#endif
Abstract base class for different kinds of events.