DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
config.cpp
Go to the documentation of this file.
1
8
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",
35 "Add include file to existing database.",
36 py::arg("db_name"),
37 py::arg("include"))
38 .def("attributes",
40 "Get the properties of each attribute in a given class",
41 py::arg("class_name"),
42 py::arg("all"))
43 .def("classes", &Configuration::get_class_list, "Get the names of the superclasses for each class")
44 .def("commit", &Configuration::commit, "Commit database changes.", py::arg("log_message") = "")
45 .def(
46 "create_db",
47 static_cast<void (Configuration::*)(const std::string&, const std::list<std::string>&)>(&Configuration::create),
48 "Create a database from a list of files",
49 py::arg("db_name"),
50 py::arg("includes"))
51 .def("create_obj",
52 py::overload_cast<const std::string&, const std::string&, const std::string&>(
54 "Create new object by class name and object id.",
55 py::arg("at"),
56 py::arg("class_name"),
57 py::arg("id"))
58 .def("create_obj",
59 py::overload_cast<const ConfigObject&, const std::string&, const std::string&>(
61 "Create new object by class name and object id.",
62 py::arg("at"),
63 py::arg("class_name"),
64 py::arg("id"))
65 .def("destroy_obj", &Configuration::destroy_obj, "The method tries to destroy given object.", py::arg("object"))
66 .def("get_impl_param",
68 "Get implementation plug-in parameter used to build conffwk object")
69 .def("get_impl_spec",
71 "Get implementation plug-in and its parameter used to build conffwk object")
72 .def("get_includes",
74 "Returns list of files included by given database.",
75 py::arg("db_name"))
76 .def("get_schema_path",
78 "Get path to schema file with definition of the given class",
79 py::arg("class_name"))
80 .def("get_obj",
82 "Create a configuration object containing the desired entity from the database",
83 py::arg("class_name"),
84 py::arg("id"))
85 .def("get_objs",
87 "Create a list of configuration objects of a given class from the database",
88 py::arg("class_name"),
89 py::arg("query") = "")
90 .def("load", &Configuration::load, "Load database according to the name.", py::arg("db_name"))
91 .def("loaded", &Configuration::loaded, "Check if database is correctly loaded.")
92 .def(
93 "remove_include", &Configuration::remove_include, "Remove include file.", py::arg("db_name"), py::arg("include"))
94 .def("relations",
96 "Get the properties of each relation in a given class",
97 py::arg("class_name"),
98 py::arg("all"))
99 .def("superclasses",
101 "Get the superclasses of a single class",
102 py::arg("class_name"),
103 py::arg("all"))
104 .def("subclasses",
106 "Get the subclasses of a single class",
107 py::arg("class_name"),
108 py::arg("all"))
109 .def("test_object",
111 "Test the existence of the object",
112 py::arg("class_name"),
113 py::arg("id"),
114 py::arg("rlevel"),
115 py::arg("rclasses"))
116 .def("unload", &Configuration::unload, "Unload previously-loaded database");
117}
118
119void
121{
122
123 py::class_<ConfigObject>(m, "_ConfigObject")
124 .def(py::init<>())
125 .def(py::init<const ConfigObject&>())
126 .def("class_name", &ConfigObject::class_name, "Return object's class name")
127 .def("contained_in", &ConfigObject::contained_in, "Return the name of the database file this object belongs to.")
128 .def("full_name", &ConfigObject::full_name, "Return full object name")
129 .def("get_obj", &ConfigObject::get_obj_pybind, "Get a copy of an object", py::arg("attrname"))
130 .def("get_objs", &ConfigObject::get_list_pybind<ConfigObject>, "Getter function for a list", py::arg("attr"))
131 .def("get_string", &ConfigObject::get_value_pybind<std::string>, "Simple getter function", py::arg("attr"))
132 .def("get_bool", &ConfigObject::get_value_pybind<bool>, "Simple getter function", py::arg("attr"))
133 .def("get_s8", &ConfigObject::get_value_pybind<int8_t>, "Simple getter function", py::arg("attr"))
134 .def("get_u8", &ConfigObject::get_value_pybind<uint8_t>, "Simple getter function", py::arg("attr"))
135 .def("get_s16", &ConfigObject::get_value_pybind<int16_t>, "Simple getter function", py::arg("attr"))
136 .def("get_u16", &ConfigObject::get_value_pybind<uint16_t>, "Simple getter function", py::arg("attr"))
137 .def("get_s32", &ConfigObject::get_value_pybind<int32_t>, "Simple getter function", py::arg("attr"))
138 .def("get_u32", &ConfigObject::get_value_pybind<uint32_t>, "Simple getter function", py::arg("attr"))
139 .def("get_s64", &ConfigObject::get_value_pybind<int64_t>, "Simple getter function", py::arg("attr"))
140 .def("get_u64", &ConfigObject::get_value_pybind<uint64_t>, "Simple getter function", py::arg("attr"))
141 .def("get_float", &ConfigObject::get_value_pybind<float>, "Simple getter function", py::arg("attr"))
142 .def("get_double", &ConfigObject::get_value_pybind<double>, "Simple getter function", py::arg("attr"))
143 .def("get_string_vec", &ConfigObject::get_list_pybind<std::string>, "Getter function for a list", py::arg("attr"))
144 .def("get_bool_vec", &ConfigObject::get_list_pybind<bool>, "Getter function for a list", py::arg("attr"))
145 .def("get_s8_vec", &ConfigObject::get_list_pybind<int8_t>, "Getter function for a list", py::arg("attr"))
146 .def("get_u8_vec", &ConfigObject::get_list_pybind<uint8_t>, "Getter function for a list", py::arg("attr"))
147 .def("get_s16_vec", &ConfigObject::get_list_pybind<int16_t>, "Getter function for a list", py::arg("attr"))
148 .def("get_u16_vec", &ConfigObject::get_list_pybind<uint16_t>, "Getter function for a list", py::arg("attr"))
149 .def("get_s32_vec", &ConfigObject::get_list_pybind<int32_t>, "Getter function for a list", py::arg("attr"))
150 .def("get_u32_vec", &ConfigObject::get_list_pybind<uint32_t>, "Getter function for a list", py::arg("attr"))
151 .def("get_s64_vec", &ConfigObject::get_list_pybind<int64_t>, "Getter function for a list", py::arg("attr"))
152 .def("get_u64_vec", &ConfigObject::get_list_pybind<uint64_t>, "Getter function for a list", py::arg("attr"))
153 .def("get_float_vec", &ConfigObject::get_list_pybind<float>, "Getter function for a list", py::arg("attr"))
154 .def("get_double_vec", &ConfigObject::get_list_pybind<double>, "Getter function for a list", py::arg("attr"))
155 .def("rename", &ConfigObject::rename, "Rename object", py::arg("new_id"))
156 .def("set_obj",
158 "Set relationship single-value",
159 py::arg("name"),
160 py::arg("o"),
161 py::arg("skip_non_null_check") = false)
162 .def("set_objs",
164 "Set relationship multi-value.",
165 py::arg("name"),
166 py::arg("o"),
167 py::arg("skip_non_null_check") = false)
168 .def("set_class",
169 py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_class),
170 "Set the class name",
171 py::arg("name"),
172 py::arg("value"))
173 .def("set_date",
174 py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_date),
175 "Set the date",
176 py::arg("name"),
177 py::arg("value"))
178 .def("set_enum",
179 py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_enum),
180 "Set the enum",
181 py::arg("name"),
182 py::arg("value"))
183 .def(
184 "set_string", &ConfigObject::set_by_val<std::string>, "Simple setter function", py::arg("name"), py::arg("value"))
185 .def("set_time",
186 py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_time),
187 "Set the time",
188 py::arg("name"),
189 py::arg("value"))
190 .def("set_bool", &ConfigObject::set_by_val<bool>, "Simple setter function", py::arg("name"), py::arg("value"))
191 .def("set_s8", &ConfigObject::set_by_val<int8_t>, "Simple setter function", py::arg("name"), py::arg("value"))
192 .def("set_u8", &ConfigObject::set_by_val<uint8_t>, "Simple setter function", py::arg("name"), py::arg("value"))
193 .def("set_s16", &ConfigObject::set_by_val<int16_t>, "Simple setter function", py::arg("name"), py::arg("value"))
194 .def("set_u16", &ConfigObject::set_by_val<uint16_t>, "Simple setter function", py::arg("name"), py::arg("value"))
195 .def("set_s32", &ConfigObject::set_by_val<int32_t>, "Simple setter function", py::arg("name"), py::arg("value"))
196 .def("set_u32", &ConfigObject::set_by_val<uint32_t>, "Simple setter function", py::arg("name"), py::arg("value"))
197 .def("set_s64", &ConfigObject::set_by_val<int64_t>, "Simple setter function", py::arg("name"), py::arg("value"))
198 .def("set_u64", &ConfigObject::set_by_val<uint64_t>, "Simple setter function", py::arg("name"), py::arg("value"))
199 .def("set_float", &ConfigObject::set_by_val<float>, "Simple setter function", py::arg("name"), py::arg("value"))
200 .def("set_double", &ConfigObject::set_by_val<double>, "Simple setter function", py::arg("name"), py::arg("value"))
201 .def("set_bool_vec",
203 "Setter function for list",
204 py::arg("attrname"),
205 py::arg("l"))
206 .def("set_s8_vec",
208 "Setter function for list",
209 py::arg("attrname"),
210 py::arg("l"))
211 .def("set_u8_vec",
213 "Setter function for list",
214 py::arg("attrname"),
215 py::arg("l"))
216 .def("set_s16_vec",
218 "Setter function for list",
219 py::arg("attrname"),
220 py::arg("l"))
221 .def("set_u16_vec",
223 "Setter function for list",
224 py::arg("attrname"),
225 py::arg("l"))
226 .def("set_s32_vec",
228 "Setter function for list",
229 py::arg("attrname"),
230 py::arg("l"))
231 .def("set_u32_vec",
233 "Setter function for list",
234 py::arg("attrname"),
235 py::arg("l"))
236 .def("set_s64_vec",
238 "Setter function for list",
239 py::arg("attrname"),
240 py::arg("l"))
241 .def("set_u64_vec",
243 "Setter function for list",
244 py::arg("attrname"),
245 py::arg("l"))
246 .def("set_float_vec",
248 "Setter function for list",
249 py::arg("attrname"),
250 py::arg("l"))
251 .def("set_double_vec",
253 "Setter function for list",
254 py::arg("attrname"),
255 py::arg("l"))
256 .def("set_class_vec",
258 "Set list of classes",
259 py::arg("attrname"),
260 py::arg("l"))
261 .def("set_date_vec",
263 "Set list of dates",
264 py::arg("attrname"),
265 py::arg("l"))
266 .def("set_enum_vec",
268 "Set list of enums",
269 py::arg("attrname"),
270 py::arg("l"))
271 .def("set_string_vec",
273 "Set list of strings",
274 py::arg("attrname"),
275 py::arg("l"))
276 .def("set_time_vec",
278 "Set list of times",
279 py::arg("attrname"),
280 py::arg("l"))
281 .def("UID", &ConfigObject::UID, "Return object identity");
282}
283
284} // 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:120