Belle II Software  release-06-02-00
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 
13 extern "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 
23 namespace 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 
52  private:
53  NSMData(void* pdata, const NSMData& data);
54  NSMData(void* pdata, const std::string& dataname,
55  const std::string& format, int revision);
56 
57  public:
58  int getRevision() const { return m_revision; }
59  const std::string& getFormat() const { return m_format; }
60  int getSize() const { return m_size; }
61  void setRevision(int revision) { m_revision = revision; }
62  void setFormat(const std::string& format) { m_format = format; }
63  void setSize(int size) { m_size = size; }
64  bool isAvailable() { return (m_pdata != NULL); }
65  void* open(NSMCommunicator& comm);
66  void* allocate(NSMCommunicator& comm, int interval = 2);
67  void flush();
68  void* get() { return m_pdata; }
69  const void* get() const { return m_pdata; }
70  void* parse(const char* inc_dir = NULL, bool allocated = false);
71 
72  int getNObjects(const std::string& name) const;
73  const NSMDataList& getObjects(const std::string& name) const;
74  NSMDataList& getObjects(const std::string& name);
75  const NSMData& getObject(const std::string& name, int index = 0) const;
76  NSMData& getObject(const std::string& name, int index = 0);
77 
78  void print(const std::string& name_in = "") const;
79  void printPV(const std::string& name_in = "") const;
80  const void* find(const std::string& name_in, DBField::Type& type, int& length) const;
81  void search(NameValueList& map, const std::string& name = "") const;
82 
83  public:
84  virtual void* getValue(const std::string& name);
85  virtual const void* getValue(const std::string& name) const;
86  virtual void setValue(const std::string& name, const void* value, int size);
87  virtual void addValue(const std::string& name, const void* value,
88  DBField::Type type, int length = 0);
89  virtual const std::string& getText(const std::string&) const { return m_empty; }
90  virtual void addText(const std::string&, const std::string&) {}
91 
92  public:
93  virtual void readObject(Reader& reader);
94  virtual void writeObject(Writer& writer) const;
95 
96  protected:
97  virtual void reset();
98 
99  private:
100  void set(void* pdata) { m_pdata = pdata; }
101  int initProperties();
102 #if NSM_PACKAGE_VERSION >= 1914
103  NSMparse* parse(NSMparse* ptr, int& length,
104  std::string& name_in);
105 #endif
106 
107  private:
108  bool m_allocated;
109  void* m_pdata;
110  int m_size;
111  int m_offset;
112  std::string m_format;
113  int m_revision;
114  NSMDataListMap m_data_v_m;
115  std::string m_empty;
116  NSMCommunicator* m_com;
117  int m_tstamp;
118 
119  };
120 
121  typedef std::vector<NSMData> NSMDataList;
122  typedef std::map<std::string, NSMDataList> NSMDataListMap;
123 
125 }
126 
127 #endif
Abstract base class for different kinds of events.