Belle II Software development
NSMVar.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_NSMVar_h
9#define _Belle2_NSMVar_h
10
11#include <daq/slc/base/Serializable.h>
12#include <daq/slc/base/Date.h>
13
14#include <vector>
15#include <string>
16
17namespace Belle2 {
23 class NSMVar : public Serializable {
24
25 public:
26 enum Type {
27 NONE = 0,
28 INT,
29 FLOAT,
30 TEXT,
31 };
32
33 public:
34 static const NSMVar NOVALUE;
35
36 public:
37 NSMVar() : m_value(NULL), m_name(), m_type(NONE), m_len(0)
38 {
39 setDate(Date());
40 }
41 NSMVar(const std::string& name, Type type, int len, const void* value)
42 : m_value(NULL)
43 {
44 copy(name, type, len, value);
45 }
46 NSMVar(const std::string& name, const std::string& value)
47 : m_value(NULL)
48 {
49 copy(name, TEXT, value.size(), value.c_str());
50 }
51 NSMVar(const std::string& name, int value)
52 : m_value(NULL)
53 {
54 copy(name, INT, 0, &value);
55 }
56 NSMVar(const std::string& name, float value)
57 : m_value(NULL)
58 {
59 copy(name, FLOAT, 0, &value);
60 }
61 NSMVar(const std::string& name, int len, int* value)
62 : m_value(NULL)
63 {
64 copy(name, INT, len, value);
65 }
66 NSMVar(const std::string& name, int len, float* value)
67 : m_value(NULL)
68 {
69 copy(name, FLOAT, len, value);
70 }
71 NSMVar(const std::string& name, const std::vector<int>& value);
72 NSMVar(const std::string& name, const std::vector<float>& value);
73 NSMVar(const std::string& name) : m_value(NULL), m_name(name), m_type(NONE), m_len(0) {}
74 NSMVar(const NSMVar& var) : m_value(NULL) { *this = var; }
75 ~NSMVar();
76
77 public:
78 const NSMVar& operator=(const NSMVar& var)
79 {
80 copy(var.m_name, var.m_type, var.m_len, var.m_value, var.m_id, var.m_date);
81 m_node = var.m_node;
82 m_date = var.m_date;
83 return *this;
84 }
85 const NSMVar& operator=(int val)
86 {
87 copy(m_name, INT, 0, &val, m_id);
88 return *this;
89 }
90 const NSMVar& operator=(float val)
91 {
92 copy(m_name, FLOAT, 0, &val, m_id);
93 return *this;
94 }
95 const NSMVar& operator=(const std::string& val)
96 {
97 if (val.size() > 0) {
98 copy(m_name, TEXT, val.size(), val.c_str(), m_id);
99 } else {
100 copy(m_name, TEXT, 1, "", m_id);
101 }
102 return *this;
103 }
104 const NSMVar& operator=(const std::vector<int>& val);
105 const NSMVar& operator=(const std::vector<float>& val);
106 const NSMVar& operator>>(int& val) const { val = getInt(); return *this; }
107 const NSMVar& operator>>(float& val) const { val = getFloat(); return *this; }
108 const NSMVar& operator>>(std::string& val) const { val = getText(); return *this; }
109 const NSMVar& operator>>(std::vector<int>& val) const;
110 const NSMVar& operator>>(std::vector<float>& val) const;
111
112 public:
113 void setNode(const std::string& node) { m_node = node; }
114 void setName(const std::string& name) { m_name = name; }
115 const void* get() const { return m_value; }
116 void* get() { return m_value; }
117 int size() const;
118 const std::string& getNode() const { return m_node; }
119 const std::string& getName() const { return m_name; }
120 Type getType() const { return m_type; }
121 const char* getTypeLabel() const;
122 int getLength() const { return m_len; }
123 int getInt() const;
124 float getFloat() const;
125 const char* getText() const;
126 int getInt(int i) const;
127 float getFloat(int i) const;
128 int getId() const { return m_id; }
129 void setId(int id) { m_id = id; }
130 void setDate(int date) { m_date = date; }
131 void setDate(const Date& date) { m_date = date.get(); }
132 int getDate() const { return m_date; }
133
134 public:
135 void readObject(Reader&) override;
136 void writeObject(Writer&) const override;
137
138 public:
139 void copy(const std::string& name, Type type, int len,
140 const void* value, int id = 0, int date = 0);
141
142 private:
143 void* m_value;
144 std::string m_node;
145 std::string m_name;
146 Type m_type;
147 int m_len;
148 int m_id;
149 int m_date;
150
151 };
152
153 typedef std::vector<NSMVar> NSMVarList;
154
156}
157
158#endif
std::istream & operator>>(std::istream &input, IntervalOfValidity &iov)
Abstract base class for different kinds of events.