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