Belle II Software development
NSMData.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_NSMData_hh
9#define _Belle2_NSMData_hh
10
11#include <daq/slc/base/AbstractDBObject.h>
12
13extern "C" {
14#include <nsm2/nsm2.h>
15#if NSM_PACKAGE_VERSION >= 1914
16#include <nsm2/nsmparse.h>
17#endif
18}
19
20#include <map>
21#include <vector>
22
23namespace Belle2 {
29 class NSMCommunicator;
30
31 class NSMData : public AbstractDBObject {
32
33 typedef std::vector<NSMData> NSMDataList;
34 typedef std::map<std::string, NSMDataList> NSMDataListMap;
35
36 public:
37 struct NameValue {
38 std::string name;
39 std::string value;
40 void* buf;
41 DBField::Type type;
42 };
43 typedef std::vector<NameValue> NameValueList;
44
45 public:
46 NSMData(const std::string& dataname,
47 const std::string& format, int revision);
48 NSMData();
49 NSMData(const NSMData& data);
50 virtual ~NSMData();
51
55 const NSMData& operator=(const NSMData& data);
56
57 private:
58 NSMData(void* pdata, const NSMData& data);
59 NSMData(void* pdata, const std::string& dataname,
60 const std::string& format, int revision);
61
62 public:
63 int getRevision() const { return m_revision; }
64 const std::string& getFormat() const { return m_format; }
65 int getSize() const { return m_size; }
66 void setRevision(int revision) { m_revision = revision; }
67 void setFormat(const std::string& format) { m_format = format; }
68 void setSize(int size) { m_size = size; }
69 bool isAvailable() { return (m_pdata != NULL); }
70 void* open(NSMCommunicator& comm);
71 void* allocate(NSMCommunicator& comm, int interval = 2);
72 void flush();
73 void* get() { return m_pdata; }
74 const void* get() const { return m_pdata; }
75 void* parse(const char* inc_dir = NULL, bool allocated = false);
76
77 int getNObjects(const std::string& name) const;
78 const NSMDataList& getObjects(const std::string& name) const;
79 NSMDataList& getObjects(const std::string& name);
80 const NSMData& getObject(const std::string& name, int index = 0) const;
81 NSMData& getObject(const std::string& name, int index = 0);
82
83 void print(const std::string& name_in = "") const;
84 void printPV(const std::string& name_in = "") const;
85 const void* find(const std::string& name_in, DBField::Type& type, int& length) const;
86 void search(NameValueList& map, const std::string& name = "") const;
87
88 public:
89 void* getValue(const std::string& name);
90 const void* getValue(const std::string& name) const override;
91 void setValue(const std::string& name, const void* value, int size) override;
92 void addValue(const std::string& name, const void* value,
93 DBField::Type type, int length = 0) override;
94 const std::string& getText(const std::string&) const override { return m_empty; }
95 void addText(const std::string&, const std::string&) override {}
96
97 public:
98 void readObject(Reader& reader) override;
99 void writeObject(Writer& writer) const override;
100
101 protected:
102 void reset() override;
103
104 private:
105 void set(void* pdata) { m_pdata = pdata; }
106 int initProperties();
107#if NSM_PACKAGE_VERSION >= 1914
108 NSMparse* parse(NSMparse* ptr, int& length,
109 std::string& name_in);
110#endif
111
112 private:
113 bool m_allocated;
114 void* m_pdata;
115 int m_size;
116 int m_offset;
117 std::string m_format;
118 int m_revision;
119 NSMDataListMap m_data_v_m;
120 std::string m_empty;
121 NSMCommunicator* m_com;
122 int m_tstamp;
123
124 };
125
126 typedef std::vector<NSMData> NSMDataList;
127 typedef std::map<std::string, NSMDataList> NSMDataListMap;
128
130}
131
132#endif
const NSMData & operator=(const NSMData &data)
Operator =.
Definition: NSMData.cc:93
Abstract base class for different kinds of events.