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_obj",
56 &Configuration::get_obj_pybind, "Create a configuration object containing the desired entity from the database", py::arg("class_name"), py::arg("id"))
57 .def("get_objs",
58 &Configuration::get_objs_pybind, "Create a list of configuration objects of a given class from the database", py::arg("class_name"), py::arg("query") = "")
59 .def("load",
60 &Configuration::load, "Load database according to the name.", py::arg("db_name"))
61 .def("loaded",
62 &Configuration::loaded, "Check if database is correctly loaded.")
63 .def("remove_include",
64 &Configuration::remove_include, "Remove include file.", py::arg("db_name"), py::arg("include"))
65 .def("relations",
66 &Configuration::relations_pybind, "Get the properties of each relation in a given class", py::arg("class_name"), py::arg("all"))
67 .def("superclasses",
68 &Configuration::superclasses_pybind, "Get the superclasses of a single class", py::arg("class_name"), py::arg("all"))
69 .def("subclasses",
70 &Configuration::subclasses_pybind, "Get the superclasses of a single class", py::arg("class_name"), py::arg("all"))
71 .def("test_object",
72 &Configuration::test_object, "Test the existence of the object", py::arg("class_name"), py::arg("id"), py::arg("rlevel"), py::arg("rclasses"))
73 .def("unload",
74 &Configuration::unload, "Unload previously-loaded database")
75 ;
76}
77
78void
80{
81
82 py::class_<ConfigObject>(m, "_ConfigObject")
83 .def(py::init<>())
84 .def(py::init<const ConfigObject&>())
85 .def("class_name",
86 &ConfigObject::class_name, "Return object's class name")
87 .def("contained_in",
88 &ConfigObject::contained_in, "Return the name of the database file this object belongs to.")
89 .def("full_name",
90 &ConfigObject::full_name, "Return full object name")
91 .def("get_obj",
92 &ConfigObject::get_obj_pybind, "Get a copy of an object", py::arg("attrname"))
93 .def("get_objs",
94 &ConfigObject::get_list_pybind<ConfigObject>, "Getter function for a list", py::arg("attr"))
95 .def("get_string",
96 &ConfigObject::get_value_pybind<std::string>, "Simple getter function", py::arg("attr"))
97 .def("get_bool",
98 &ConfigObject::get_value_pybind<bool>, "Simple getter function", py::arg("attr"))
99 .def("get_s8",
100 &ConfigObject::get_value_pybind<int8_t>, "Simple getter function", py::arg("attr"))
101 .def("get_u8",
102 &ConfigObject::get_value_pybind<uint8_t>, "Simple getter function", py::arg("attr"))
103 .def("get_s16",
104 &ConfigObject::get_value_pybind<int16_t>, "Simple getter function", py::arg("attr"))
105 .def("get_u16",
106 &ConfigObject::get_value_pybind<uint16_t>, "Simple getter function", py::arg("attr"))
107 .def("get_s32",
108 &ConfigObject::get_value_pybind<int32_t>, "Simple getter function", py::arg("attr"))
109 .def("get_u32",
110 &ConfigObject::get_value_pybind<uint32_t>, "Simple getter function", py::arg("attr"))
111 .def("get_s64",
112 &ConfigObject::get_value_pybind<int64_t>, "Simple getter function", py::arg("attr"))
113 .def("get_u64",
114 &ConfigObject::get_value_pybind<uint64_t>, "Simple getter function", py::arg("attr"))
115 .def("get_float",
116 &ConfigObject::get_value_pybind<float>, "Simple getter function", py::arg("attr"))
117 .def("get_double",
118 &ConfigObject::get_value_pybind<double>, "Simple getter function", py::arg("attr"))
119 .def("get_string_vec",
120 &ConfigObject::get_list_pybind<std::string>, "Getter function for a list", py::arg("attr"))
121 .def("get_bool_vec",
122 &ConfigObject::get_list_pybind<bool>, "Getter function for a list", py::arg("attr"))
123 .def("get_s8_vec",
124 &ConfigObject::get_list_pybind<int8_t>, "Getter function for a list", py::arg("attr"))
125 .def("get_u8_vec",
126 &ConfigObject::get_list_pybind<uint8_t>, "Getter function for a list", py::arg("attr"))
127 .def("get_s16_vec",
128 &ConfigObject::get_list_pybind<int16_t>, "Getter function for a list", py::arg("attr"))
129 .def("get_u16_vec",
130 &ConfigObject::get_list_pybind<uint16_t>, "Getter function for a list", py::arg("attr"))
131 .def("get_s32_vec",
132 &ConfigObject::get_list_pybind<int32_t>, "Getter function for a list", py::arg("attr"))
133 .def("get_u32_vec",
134 &ConfigObject::get_list_pybind<uint32_t>, "Getter function for a list", py::arg("attr"))
135 .def("get_s64_vec",
136 &ConfigObject::get_list_pybind<int64_t>, "Getter function for a list", py::arg("attr"))
137 .def("get_u64_vec",
138 &ConfigObject::get_list_pybind<uint64_t>, "Getter function for a list", py::arg("attr"))
139 .def("get_float_vec",
140 &ConfigObject::get_list_pybind<float>, "Getter function for a list", py::arg("attr"))
141 .def("get_double_vec",
142 &ConfigObject::get_list_pybind<double>, "Getter function for a list", py::arg("attr"))
143 .def("rename",
144 &ConfigObject::rename, "Rename object", py::arg("new_id"))
145 .def("set_obj",
146 &ConfigObject::set_obj, "Set relationship single-value", py::arg("name"), py::arg("o"), py::arg("skip_non_null_check") = false)
147 .def("set_objs",
148 &ConfigObject::set_objs, "Set relationship multi-value.", py::arg("name"), py::arg("o"), py::arg("skip_non_null_check") = false)
149 .def("set_class",
150 py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_class), "Set the class name", py::arg("name"), py::arg("value"))
151 .def("set_date",
152 py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_date), "Set the date", py::arg("name"), py::arg("value"))
153 .def("set_enum",
154 py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_enum), "Set the enum", py::arg("name"), py::arg("value"))
155 .def("set_string",
156 &ConfigObject::set_by_val<std::string>, "Simple setter function", py::arg("name"), py::arg("value"))
157 .def("set_time",
158 py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_time), "Set the time", py::arg("name"), py::arg("value"))
159 .def("set_bool",
160 &ConfigObject::set_by_val<bool>, "Simple setter function", py::arg("name"), py::arg("value"))
161 .def("set_s8",
162 &ConfigObject::set_by_val<int8_t>, "Simple setter function", py::arg("name"), py::arg("value"))
163 .def("set_u8",
164 &ConfigObject::set_by_val<uint8_t>, "Simple setter function", py::arg("name"), py::arg("value"))
165 .def("set_s16",
166 &ConfigObject::set_by_val<int16_t>, "Simple setter function", py::arg("name"), py::arg("value"))
167 .def("set_u16",
168 &ConfigObject::set_by_val<uint16_t>, "Simple setter function", py::arg("name"), py::arg("value"))
169 .def("set_s32",
170 &ConfigObject::set_by_val<int32_t>, "Simple setter function", py::arg("name"), py::arg("value"))
171 .def("set_u32",
172 &ConfigObject::set_by_val<uint32_t>, "Simple setter function", py::arg("name"), py::arg("value"))
173 .def("set_s64",
174 &ConfigObject::set_by_val<int64_t>, "Simple setter function", py::arg("name"), py::arg("value"))
175 .def("set_u64",
176 &ConfigObject::set_by_val<uint64_t>, "Simple setter function", py::arg("name"), py::arg("value"))
177 .def("set_float",
178 &ConfigObject::set_by_val<float>, "Simple setter function", py::arg("name"), py::arg("value"))
179 .def("set_double",
180 &ConfigObject::set_by_val<double>, "Simple setter function", py::arg("name"), py::arg("value"))
181 .def("set_bool_vec",
182 &ConfigObject::set_list_pybind<bool>, "Setter function for list", py::arg("attrname"), py::arg("l"))
183 .def("set_s8_vec",
184 &ConfigObject::set_list_pybind<int8_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
185 .def("set_u8_vec",
186 &ConfigObject::set_list_pybind<uint8_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
187 .def("set_s16_vec",
188 &ConfigObject::set_list_pybind<int16_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
189 .def("set_u16_vec",
190 &ConfigObject::set_list_pybind<uint16_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
191 .def("set_s32_vec",
192 &ConfigObject::set_list_pybind<int32_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
193 .def("set_u32_vec",
194 &ConfigObject::set_list_pybind<uint32_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
195 .def("set_s64_vec",
196 &ConfigObject::set_list_pybind<int64_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
197 .def("set_u64_vec",
198 &ConfigObject::set_list_pybind<uint64_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
199 .def("set_float_vec",
200 &ConfigObject::set_list_pybind<float>, "Setter function for list", py::arg("attrname"), py::arg("l"))
201 .def("set_double_vec",
202 &ConfigObject::set_list_pybind<double>, "Setter function for list", py::arg("attrname"), py::arg("l"))
203 .def("set_class_vec",
204 &ConfigObject::set_list_pybind<std::string>, "Set list of classes", py::arg("attrname"), py::arg("l"))
205 .def("set_date_vec",
206 &ConfigObject::set_list_pybind<std::string>, "Set list of dates", py::arg("attrname"), py::arg("l"))
207 .def("set_enum_vec",
208 &ConfigObject::set_list_pybind<std::string>, "Set list of enums", py::arg("attrname"), py::arg("l"))
209 .def("set_string_vec",
210 &ConfigObject::set_list_pybind<std::string>, "Set list of strings", py::arg("attrname"), py::arg("l"))
211 .def("set_time_vec",
212 &ConfigObject::set_list_pybind<std::string>, "Set list of times", py::arg("attrname"), py::arg("l"))
213 .def("UID",
214 &ConfigObject::UID, "Return object identity")
215 ;
216
217}
218
219
220} // 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_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:79