Belle II Software development
DBObject.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_DBObject_hh
9#define _Belle2_DBObject_hh
10
11#include <daq/slc/base/AbstractDBObject.h>
12#include <daq/slc/base/StringUtil.h>
13#include <daq/slc/base/Date.h>
14
15namespace Belle2 {
21 class DBObject : public AbstractDBObject {
22
23 public:
24 typedef std::vector<DBObject> DBObjectList;
25 typedef std::map<std::string, void*> FieldValueList;
26 typedef std::map<std::string, std::string> FieldTextList;
27 typedef std::map<std::string, DBObjectList> FieldObjectList;
28
29 public:
30 struct NameValue {
31 std::string name;
32 std::string value;
33 void* buf;
34 DBField::Type type;
35 };
36 typedef std::vector<NameValue> NameValueList;
37
38 public:
39 DBObject();
40 DBObject(const std::string& path);
41 DBObject(const DBObject& obj);
42 virtual ~DBObject();
43 const DBObject& operator=(const DBObject& obj);
44
45 public:
46 int getNObjects(const std::string& name) const;
47 DBObjectList& getObjects(const std::string& name);
48 const DBObjectList& getObjects(const std::string& name) const;
49 DBObject& getObject(const std::string& name, int i = 0);
50 const DBObject& getObject(const std::string& name, int i = 0) const;
51 void addObjects(const std::string& name, const DBObjectList& obj);
52 void addObject(const std::string& name, const DBObject& obj);
53
54 public:
55 DBObject& operator()(const std::string& name, int index = 0)
56 {
57 return getObject(name, index);
58 }
59 const DBObject& operator()(const std::string& name, int index = 0) const
60 {
61 return getObject(name, index);
62 }
63
64 public:
65 StringList getNameList(bool isfull) const;
66 void print(bool isfull = true) const;
67 const std::string sprint(bool isfull) const;
68 void printHTML(bool isfull = true) const;
69 const std::string printSQL(const std::string& table, int id) const;
70 void search(NameValueList& map, const std::string& name = "", bool isfull = true) const;
71 int getDate() const { return m_date; }
72 void setDate(const Date& date) { m_date = date.get(); }
73 void setDate(int date) { m_date = date; }
74
75 public:
76 const void* getValue(const std::string& name) const override;
77 const std::string& getText(const std::string& name) const override;
78 void addText(const std::string& name, const std::string& value) override;
79 void addValue(const std::string& name, const void* value,
80 DBField::Type type, int length) override;
81 void setValue(const std::string& name, const void* value, int length) override;
82
83 public:
84 void readObject(Reader& reader) override;
85 void writeObject(Writer& writer) const override;
86
87 private:
88 FieldValueList m_value_m;
89 FieldTextList m_text_m;
90 FieldObjectList m_obj_v_m;
91 std::string m_empty;
92 int m_date;
93
94 protected:
95 void reset() override;
96
97 private:
98 void copy(const DBObject& obj);
99
100 };
101
102 typedef std::vector<DBObject> DBObjectList;
103
105}
106
107#endif
Abstract base class for different kinds of events.