1 #ifndef MHO_PyContainerStoreInterface_HH__
2 #define MHO_PyContainerStoreInterface_HH__
11 #include "pybind11_json/pybind11_json.hpp"
12 #include <pybind11/embed.h>
13 #include <pybind11/pybind11.h>
14 namespace py = pybind11;
15 namespace nl = nlohmann;
16 using namespace pybind11::literals;
38 if(fContainerStore !=
nullptr)
49 return fContainerStore->GetNObjects();
56 if(fContainerStore !=
nullptr)
62 msg_error(
"python_bindings",
"error could not convert: " << uuid_string <<
" to valid UUID" << eom);
64 return fContainerStore->IsObjectPresent(uuid);
72 if(fContainerStore !=
nullptr)
76 type_uuid = fContainerStore->GetObjectTypeUUID(uuid);
87 msg_error(
"python_bindings",
"error could not convert: " << uuid_string <<
" to valid UUID" << eom);
89 XClassType* obj = fContainerStore->GetObject< XClassType >(uuid);
90 auto ext_ptr = GetExtension(obj);
91 if(ext_ptr !=
nullptr)
97 msg_error(
"python_bindings",
"object with uuid: " << uuid_string <<
" is either not present, or is not a: "<< MHO_ClassIdentity::ClassName<XClassType>() << eom);
106 std::vector< std::tuple< std::string, std::string, std::string > > info = fContainerStore->GetAllObjectInfo();
107 for(std::size_t i = 0; i < info.size(); i++)
110 item_info[
"type_uuid"] = std::get< 0 >(info[i]);
111 item_info[
"object_uuid"] = std::get< 1 >(info[i]);
112 item_info[
"shortname"] = std::get< 2 >(info[i]);
113 info_obj.push_back(item_info);
115 py::list ret_obj = info_obj;
131 return obj->template AsExtension< MHO_PyTableContainer< XClassType > >();
135 return obj->template MakeExtension< MHO_PyTableContainer< XClassType > >();
142 MHO_ContainerStore* fContainerStore;
147 py::class_< MHO_PyContainerStoreInterface >(m, pyclass_name.c_str())
150 "check if the underlying container store object exists and is valid")
152 "get the number of objects present in the container store")
154 "check if an object with the passed UUID is present", py::arg(
"uuid"))
156 "get a list of the object information (list of dict's containing each object's type_uuid, object_uuid, and "
166 MHO_UUID type_id = cStore->GetObjectTypeUUID(uuid);
168 if(type_id == cStore->GetTypeUUID< visibility_type >())
170 return py::cast( *(m.GetObject< visibility_type >(object_uuid) ) );
174 return py::cast( *(m.GetObject< weight_type >(object_uuid) ) );
178 return py::cast( *(m.GetObject< station_coord_type >(object_uuid) ) );
182 return py::cast( *(m.GetObject< visibility_store_type >(object_uuid) ) );
187 return py::cast( *(m.GetObject< weight_store_type >(object_uuid) ) );
192 return py::cast( *(m.GetObject< phasor_type >(object_uuid) ) );
197 return py::cast( *(m.GetObject< multitone_pcal_type >(object_uuid) ) );
203 MHO_ObjectTags* tags = cStore->GetObject< MHO_ObjectTags >(uuid);
206 mho_json meta_data = tags->GetMetaDataAsJSON();
207 std::set< MHO_UUID > tagged_ids = tags->GetTaggedObjectUUIDSet();
208 std::vector< std::string > id_list;
209 for(auto it = tagged_ids.begin(); it != tagged_ids.end(); it++)
211 id_list.push_back(it->as_string());
214 meta_data[
"tagged_object_uuid_list"] = id_list;
216 py::dict dict_obj = meta_data;
221 py::print(
"MHO_ObjectTags object with uuid: ", object_uuid,
" cannot be loaded.");
225 py::print(
"object uuid ", object_uuid,
" is not recognized, returning None.");
226 return py::object(py::cast(
nullptr));
228 py::return_value_policy::reference,
"return the object matching the specified uuid", py::arg(
"uuid"));
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:244
Class MHO_ContainerStore.
Definition: MHO_ContainerStore.hh:32
bool IsObjectPresent(const MHO_UUID &obj_id) const
Checks if an object with a given UUID is present in the container store.
Definition: MHO_ContainerStore.cc:18
MHO_UUID GetTypeUUID()
get the type uuid for a specific type (if it is supported) - if unsupported uuid will be zero
Definition: MHO_ContainerStore.hh:396
python binding to the MHO_ContainerStore
Definition: MHO_PyContainerStoreInterface.hh:30
MHO_ContainerStore * GetContainerStore()
Definition: MHO_PyContainerStoreInterface.hh:121
std::size_t GetNObjects()
Definition: MHO_PyContainerStoreInterface.hh:45
std::string GetObjectTypeUUID(const std::string &uuid_string) const
Definition: MHO_PyContainerStoreInterface.hh:69
bool IsValid()
Definition: MHO_PyContainerStoreInterface.hh:36
bool IsObjectPresent(const std::string &uuid_string) const
Definition: MHO_PyContainerStoreInterface.hh:54
py::list GetObjectList()
Definition: MHO_PyContainerStoreInterface.hh:103
MHO_PyContainerStoreInterface()
Definition: MHO_PyContainerStoreInterface.hh:32
MHO_PyContainerStoreInterface(MHO_ContainerStore *conStore)
Definition: MHO_PyContainerStoreInterface.hh:33
virtual ~MHO_PyContainerStoreInterface()
Definition: MHO_PyContainerStoreInterface.hh:34
MHO_PyTableContainer< XClassType > * GetObject(const std::string &uuid_string)
Definition: MHO_PyContainerStoreInterface.hh:81
python bindings for template MHO_TableContainer objects This extension which allows us to present the...
Definition: MHO_PyTableContainer.hh:40
Class MHO_UUID - a class for a 16 byte UUID (for object and type identification)
Definition: MHO_UUID.hh:27
std::string as_string() const
Definition: MHO_UUID.hh:125
bool from_string(const std::string &uuid_str)
Definition: MHO_UUID.hh:143
Definition: MHO_ChannelLabeler.hh:17
void DeclarePyContainerStoreInterface(py::module &m, std::string pyclass_name)
Definition: MHO_PyContainerStoreInterface.hh:145