Belle II Software development
NSMVHandler.cc
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#include "daq/slc/nsm/NSMVHandler.h"
9
10#include "daq/slc/nsm/NSMCallback.h"
11
12using namespace Belle2;
13
14NSMVHandler* NSMVHandler::create(const NSMVar& var)
15{
16 const std::string node = var.getNode();
17 const std::string name = var.getName();
18 if (var.getType() == NSMVar::INT) {
19 if (var.getLength() == 0) {
20 return new NSMVHandlerInt(node, name, false, true);
21 }
22 return new NSMVHandlerIntArray(node, name, false, true);
23 } else if (var.getType() == NSMVar::FLOAT) {
24 if (var.getLength() == 0) {
25 return new NSMVHandlerFloat(node, name, false, true);
26 }
27 return new NSMVHandlerFloatArray(node, name, false, true);
28 } else if (var.getType() == NSMVar::TEXT) {
29 return new NSMVHandlerText(node, name, false, true);
30 }
31 return NULL;
32}
33
34bool NSMVHandlerInt::handleGet(NSMVar& var)
35{
36 int val;
37 if (handleGetInt(val)) {
38 var = val;
39 return true;
40 }
41 return false;
42}
43
44bool NSMVHandlerInt::handleSet(const NSMVar& var)
45{
46 if (var.getType() == NSMVar::INT&& var.getLength() == 0) {
47 if (handleSetInt(var.getInt())) {
48 m_var = var.getInt();
49 return true;
50 }
51 }
52 return false;
53}
54
55bool NSMVHandlerFloat::handleGet(NSMVar& var)
56{
57 float val;
58 if (handleGetFloat(val)) {
59 var = val;
60 return true;
61 }
62 return false;
63}
64
65bool NSMVHandlerFloat::handleSet(const NSMVar& var)
66{
67 if (var.getType() == NSMVar::FLOAT && var.getLength() == 0) {
68 if (handleSetFloat(var.getFloat())) {
69 m_var = var.getFloat();
70 return true;
71 }
72 }
73 return false;
74}
75
76bool NSMVHandlerText::handleGet(NSMVar& var)
77{
78 std::string val;
79 if (handleGetText(val)) {
80 var = val;
81 return true;
82 }
83 return false;
84}
85
86bool NSMVHandlerText::handleSet(const NSMVar& var)
87{
88 if (var.getType() == NSMVar::TEXT && var.getLength() > 0) {
89 if (handleSetText(var.getText())) {
90 m_var = var.getText();
91 return true;
92 }
93 }
94 return false;
95}
96
97bool NSMVHandlerIntArray::handleGetIntArray(std::vector<int>& val)
98{
99 const int* pv = (const int*)m_var.get();
100 val = std::vector<int>();
101 for (int i = 0; i < m_var.getLength(); i++) {
102 val.push_back(pv[i]);
103 }
104 return true;
105}
106
107bool NSMVHandlerIntArray::handleGet(NSMVar& var)
108{
109 std::vector<int> val;
110 if (handleGetIntArray(val)) {
111 var = val;
112 return true;
113 }
114 return false;
115}
116
117bool NSMVHandlerIntArray::handleSet(const NSMVar& var)
118{
119 if (var.getType() == NSMVar::INT&& var.getLength() > 0) {
120 const int* pv = (const int*)var.get();
121 std::vector<int> val;
122 for (int i = 0; i < var.getLength(); i++) {
123 val.push_back(pv[i]);
124 }
125 if (handleSetIntArray(val)) {
126 m_var = val;
127 return true;
128 }
129 }
130 return false;
131}
132
133bool NSMVHandlerFloatArray::handleGetFloatArray(std::vector<float>& val)
134{
135 const float* pv = (const float*)m_var.get();
136 val = std::vector<float>();
137 for (int i = 0; i < m_var.getLength(); i++) {
138 val.push_back(pv[i]);
139 }
140 return true;
141}
142
143bool NSMVHandlerFloatArray::handleGet(NSMVar& var)
144{
145 std::vector<float> val;
146 if (handleGetFloatArray(val)) {
147 var = val;
148 return true;
149 }
150 return false;
151}
152
153bool NSMVHandlerFloatArray::handleSet(const NSMVar& var)
154{
155 if (var.getType() == NSMVar::FLOAT && var.getLength() > 0) {
156 const float* pv = (const float*)var.get();
157 std::vector<float> val;
158 for (int i = 0; i < var.getLength(); i++) {
159 val.push_back(pv[i]);
160 }
161 if (handleSetFloatArray(val)) {
162 m_var = val;
163 return true;
164 }
165 }
166 return false;
167}
168
169bool NSMVHandlerRef::handleGet(NSMVar& var)
170{
171 //var = m_callback.getHandler(m_refname).get();
172 m_callback.get(m_refname, var);
173 return true;
174}
175
176bool NSMVHandlerRef::handleSet(const NSMVar& var)
177{
178 //NSMVar& v(m_callback.getHandler(m_refname).get());
179 //v = var;
180 m_callback.set(m_refname, var);
181 return true;
182}
Abstract base class for different kinds of events.