DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
config.cpp
Go to the documentation of this file.
1
11#include "conffwk/Schema.hpp"
12#include "conffwk/set.hpp"
13
14#include <pybind11/pybind11.h>
15#include <pybind11/stl.h>
16#include <pybind11/stl_bind.h>
17
18#include <list>
19#include <string>
20#include <vector>
21
22namespace py = pybind11;
23
25
26void
27register_conffwk(py::module& m)
28{
29
30 py::class_<Configuration>(m, "_Configuration")
31 .def(py::init<>())
32 .def(py::init<std::string>())
33 .def("add_include",
34 &Configuration::add_include, "Add include file to existing database.", py::arg("db_name"), py::arg("include"))
35 .def("attributes",
36 &Configuration::attributes_pybind, "Get the properties of each attribute in a given class", py::arg("class_name"), py::arg("all"))
37 .def("classes",
38 &Configuration::get_class_list, "Get the names of the superclasses for each class")
39 .def("commit",
40 &Configuration::commit, "Commit database changes.", py::arg("log_message") = "")
41 .def("create_db",
42 static_cast<void (Configuration::*)(const std::string&, const std::list<std::string>&)>(&Configuration::create), "Create a database from a list of files", py::arg("db_name"), py::arg("includes"))
43 .def("create_obj",
44 py::overload_cast<const std::string&, const std::string&, const std::string&>(&Configuration::create_and_return_obj_pybind), "Create new object by class name and object id.", py::arg("at"), py::arg("class_name"), py::arg("id"))
45 .def("create_obj",
46 py::overload_cast<const ConfigObject&, const std::string&, const std::string&>(&Configuration::create_and_return_obj_pybind), "Create new object by class name and object id.", py::arg("at"), py::arg("class_name"), py::arg("id"))
47 .def("destroy_obj",
48 &Configuration::destroy_obj, "The method tries to destroy given object.", py::arg("object"))
49 .def("get_impl_param",
50 &Configuration::get_impl_param, "Get implementation plug-in parameter used to build conffwk object")
51 .def("get_impl_spec",
52 &Configuration::get_impl_spec, "Get implementation plug-in and its parameter used to build conffwk object")
53 .def("get_includes",
54 &Configuration::return_includes_pybind, "Returns list of files included by given database.", py::arg("db_name"))
55 .def("get_schema_path",
56 &Configuration::get_schema_path_pybind, "Get path to schema file with definition of the given class", py::arg("class_name"))
57 .def("get_obj",
58 &Configuration::get_obj_pybind, "Create a configuration object containing the desired entity from the database", py::arg("class_name"), py::arg("id"))
59 .def("get_objs",
60 &Configuration::get_objs_pybind, "Create a list of configuration objects of a given class from the database", py::arg("class_name"), py::arg("query") = "")
61 .def("load",
62 &Configuration::load, "Load database according to the name.", py::arg("db_name"))
63 .def("loaded",
64 &Configuration::loaded, "Check if database is correctly loaded.")
65 .def("remove_include",
66 &Configuration::remove_include, "Remove include file.", py::arg("db_name"), py::arg("include"))
67 .def("relations",
68 &Configuration::relations_pybind, "Get the properties of each relation in a given class", py::arg("class_name"), py::arg("all"))
69 .def("superclasses",
70 &Configuration::superclasses_pybind, "Get the superclasses of a single class", py::arg("class_name"), py::arg("all"))
71 .def("subclasses",
72 &Configuration::subclasses_pybind, "Get the subclasses of a single class", py::arg("class_name"), py::arg("all"))
73 .def("test_object",
74 &Configuration::test_object, "Test the existence of the object", py::arg("class_name"), py::arg("id"), py::arg("rlevel"), py::arg("rclasses"))
75 .def("unload",
76 &Configuration::unload, "Unload previously-loaded database")
77 ;
78}
79
80
81void
83{
84
85 py::class_<ConfigObject>(m, "_ConfigObject")
86 .def(py::init<>())
87 .def(py::init<const ConfigObject&>())
88 .def("class_name",
89 &ConfigObject::class_name, "Return object's class name")
90 .def("contained_in",
91 &ConfigObject::contained_in, "Return the name of the database file this object belongs to.")
92 .def("full_name",
93 &ConfigObject::full_name, "Return full object name")
94 .def("get_obj",
95 &ConfigObject::get_obj_pybind, "Get a copy of an object", py::arg("attrname"))
96 .def("get_objs",
97 &ConfigObject::get_list_pybind<ConfigObject>, "Getter function for a list", py::arg("attr"))
98 .def("get_string",
99 &ConfigObject::get_value_pybind<std::string>, "Simple getter function", py::arg("attr"))
100 .def("get_bool",
101 &ConfigObject::get_value_pybind<bool>, "Simple getter function", py::arg("attr"))
102 .def("get_s8",
103 &ConfigObject::get_value_pybind<int8_t>, "Simple getter function", py::arg("attr"))
104 .def("get_u8",
105 &ConfigObject::get_value_pybind<uint8_t>, "Simple getter function", py::arg("attr"))
106 .def("get_s16",
107 &ConfigObject::get_value_pybind<int16_t>, "Simple getter function", py::arg("attr"))
108 .def("get_u16",
109 &ConfigObject::get_value_pybind<uint16_t>, "Simple getter function", py::arg("attr"))
110 .def("get_s32",
111 &ConfigObject::get_value_pybind<int32_t>, "Simple getter function", py::arg("attr"))
112 .def("get_u32",
113 &ConfigObject::get_value_pybind<uint32_t>, "Simple getter function", py::arg("attr"))
114 .def("get_s64",
115 &ConfigObject::get_value_pybind<int64_t>, "Simple getter function", py::arg("attr"))
116 .def("get_u64",
117 &ConfigObject::get_value_pybind<uint64_t>, "Simple getter function", py::arg("attr"))
118 .def("get_float",
119 &ConfigObject::get_value_pybind<float>, "Simple getter function", py::arg("attr"))
120 .def("get_double",
121 &ConfigObject::get_value_pybind<double>, "Simple getter function", py::arg("attr"))
122 .def("get_string_vec",
123 &ConfigObject::get_list_pybind<std::string>, "Getter function for a list", py::arg("attr"))
124 .def("get_bool_vec",
125 &ConfigObject::get_list_pybind<bool>, "Getter function for a list", py::arg("attr"))
126 .def("get_s8_vec",
127 &ConfigObject::get_list_pybind<int8_t>, "Getter function for a list", py::arg("attr"))
128 .def("get_u8_vec",
129 &ConfigObject::get_list_pybind<uint8_t>, "Getter function for a list", py::arg("attr"))
130 .def("get_s16_vec",
131 &ConfigObject::get_list_pybind<int16_t>, "Getter function for a list", py::arg("attr"))
132 .def("get_u16_vec",
133 &ConfigObject::get_list_pybind<uint16_t>, "Getter function for a list", py::arg("attr"))
134 .def("get_s32_vec",
135 &ConfigObject::get_list_pybind<int32_t>, "Getter function for a list", py::arg("attr"))
136 .def("get_u32_vec",
137 &ConfigObject::get_list_pybind<uint32_t>, "Getter function for a list", py::arg("attr"))
138 .def("get_s64_vec",
139 &ConfigObject::get_list_pybind<int64_t>, "Getter function for a list", py::arg("attr"))
140 .def("get_u64_vec",
141 &ConfigObject::get_list_pybind<uint64_t>, "Getter function for a list", py::arg("attr"))
142 .def("get_float_vec",
143 &ConfigObject::get_list_pybind<float>, "Getter function for a list", py::arg("attr"))
144 .def("get_double_vec",
145 &ConfigObject::get_list_pybind<double>, "Getter function for a list", py::arg("attr"))
146 .def("rename",
147 &ConfigObject::rename, "Rename object", py::arg("new_id"))
148 .def("set_obj",
149 &ConfigObject::set_obj, "Set relationship single-value", py::arg("name"), py::arg("o"), py::arg("skip_non_null_check") = false)
150 .def("set_objs",
151 &ConfigObject::set_objs, "Set relationship multi-value.", py::arg("name"), py::arg("o"), py::arg("skip_non_null_check") = false)
152 .def("set_class",
153 py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_class), "Set the class name", py::arg("name"), py::arg("value"))
154 .def("set_date",
155 py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_date), "Set the date", py::arg("name"), py::arg("value"))
156 .def("set_enum",
157 py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_enum), "Set the enum", py::arg("name"), py::arg("value"))
158 .def("set_string",
159 &ConfigObject::set_by_val<std::string>, "Simple setter function", py::arg("name"), py::arg("value"))
160 .def("set_time",
161 py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_time), "Set the time", py::arg("name"), py::arg("value"))
162 .def("set_bool",
163 &ConfigObject::set_by_val<bool>, "Simple setter function", py::arg("name"), py::arg("value"))
164 .def("set_s8",
165 &ConfigObject::set_by_val<int8_t>, "Simple setter function", py::arg("name"), py::arg("value"))
166 .def("set_u8",
167 &ConfigObject::set_by_val<uint8_t>, "Simple setter function", py::arg("name"), py::arg("value"))
168 .def("set_s16",
169 &ConfigObject::set_by_val<int16_t>, "Simple setter function", py::arg("name"), py::arg("value"))
170 .def("set_u16",
171 &ConfigObject::set_by_val<uint16_t>, "Simple setter function", py::arg("name"), py::arg("value"))
172 .def("set_s32",
173 &ConfigObject::set_by_val<int32_t>, "Simple setter function", py::arg("name"), py::arg("value"))
174 .def("set_u32",
175 &ConfigObject::set_by_val<uint32_t>, "Simple setter function", py::arg("name"), py::arg("value"))
176 .def("set_s64",
177 &ConfigObject::set_by_val<int64_t>, "Simple setter function", py::arg("name"), py::arg("value"))
178 .def("set_u64",
179 &ConfigObject::set_by_val<uint64_t>, "Simple setter function", py::arg("name"), py::arg("value"))
180 .def("set_float",
181 &ConfigObject::set_by_val<float>, "Simple setter function", py::arg("name"), py::arg("value"))
182 .def("set_double",
183 &ConfigObject::set_by_val<double>, "Simple setter function", py::arg("name"), py::arg("value"))
184 .def("set_bool_vec",
185 &ConfigObject::set_list_pybind<bool>, "Setter function for list", py::arg("attrname"), py::arg("l"))
186 .def("set_s8_vec",
187 &ConfigObject::set_list_pybind<int8_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
188 .def("set_u8_vec",
189 &ConfigObject::set_list_pybind<uint8_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
190 .def("set_s16_vec",
191 &ConfigObject::set_list_pybind<int16_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
192 .def("set_u16_vec",
193 &ConfigObject::set_list_pybind<uint16_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
194 .def("set_s32_vec",
195 &ConfigObject::set_list_pybind<int32_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
196 .def("set_u32_vec",
197 &ConfigObject::set_list_pybind<uint32_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
198 .def("set_s64_vec",
199 &ConfigObject::set_list_pybind<int64_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
200 .def("set_u64_vec",
201 &ConfigObject::set_list_pybind<uint64_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
202 .def("set_float_vec",
203 &ConfigObject::set_list_pybind<float>, "Setter function for list", py::arg("attrname"), py::arg("l"))
204 .def("set_double_vec",
205 &ConfigObject::set_list_pybind<double>, "Setter function for list", py::arg("attrname"), py::arg("l"))
206 .def("set_class_vec",
207 &ConfigObject::set_list_pybind<std::string>, "Set list of classes", py::arg("attrname"), py::arg("l"))
208 .def("set_date_vec",
209 &ConfigObject::set_list_pybind<std::string>, "Set list of dates", py::arg("attrname"), py::arg("l"))
210 .def("set_enum_vec",
211 &ConfigObject::set_list_pybind<std::string>, "Set list of enums", py::arg("attrname"), py::arg("l"))
212 .def("set_string_vec",
213 &ConfigObject::set_list_pybind<std::string>, "Set list of strings", py::arg("attrname"), py::arg("l"))
214 .def("set_time_vec",
215 &ConfigObject::set_list_pybind<std::string>, "Set list of times", py::arg("attrname"), py::arg("l"))
216 .def("UID",
217 &ConfigObject::UID, "Return object identity")
218 ;
219
220}
221
222
223} // namespace dunedaq::conffwk::python
void set_time(const std::string &name, const std::string &value)
Set attribute time value.
void set_by_val(const std::string &name, T value)
Set attribute value.
ConfigObject * get_obj_pybind(const std::string &attrname)
T get_value_pybind(const std::string &attrname)
void set_date(const std::string &name, const std::string &value)
Set attribute date value.
void set_objs(const std::string &name, const std::vector< const ConfigObject * > &o, bool skip_non_null_check=false)
Set relationship multi-value.
const std::string & UID() const noexcept
Return object identity.
void set_class(const std::string &name, const std::string &value)
Set attribute class value.
void set_list_pybind(const std::string &attrname, std::vector< T > l)
void set_enum(const std::string &name, const std::string &value)
Set attribute enumeration value.
const std::string full_name() const noexcept
Return full object name.
void set_obj(const std::string &name, const ConfigObject *o, bool skip_non_null_check=false)
Set relationship single-value.
void rename(const std::string &new_id)
Rename object.
std::vector< T > get_list_pybind(const std::string &attrname)
const std::string & class_name() const noexcept
Return object's class name.
const std::string contained_in() const
Return the name of the database file this object belongs to.
Defines base class for cache of template objects.
std::vector< ConfigObject > * get_objs_pybind(const std::string &class_name, const std::string &query="")
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > attributes_pybind(const std::string &class_name, bool all)
void destroy_obj(ConfigObject &object)
Destroy object.
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > relations_pybind(const std::string &class_name, bool all)
void remove_include(const std::string &db_name, const std::string &include)
Remove include file.
void load(const std::string &db_name)
Load database according to the name. If name is empty, take it from TDAQ_DB_NAME and TDAQ_DB_DATA env...
const std::string & get_impl_param() const noexcept
std::vector< std::string > superclasses_pybind(const std::string &class_name, bool all)
void create(const std::string &at, const std::string &class_name, const std::string &id, ConfigObject &object)
Create new object by class name and object id.
std::vector< std::string > subclasses_pybind(const std::string &class_name, bool all)
std::list< std::string > * return_includes_pybind(const std::string &db_name)
bool loaded() const noexcept
Check if database is correctly loaded.
std::vector< std::string > get_class_list() const
const std::string & get_schema_path_pybind(const std::string &class_name)
const std::string & get_impl_spec() const noexcept
void commit(const std::string &log_message="")
Commit database changes.
ConfigObject * get_obj_pybind(const std::string &class_name, const std::string &id)
void unload()
Unload database.
bool test_object(const std::string &class_name, const std::string &id, unsigned long rlevel=0, const std::vector< std::string > *rclasses=0)
Test the object existence.
void add_include(const std::string &db_name, const std::string &include)
Add include file to existing database.
ConfigObject * create_and_return_obj_pybind(const std::string &at, const std::string &class_name, const std::string &id)
conffwk entry point
void register_conffwk(py::module &m)
Definition config.cpp:27
void register_conffwkobject(py::module &m)
Definition config.cpp:82