aron_conversions.cpp
Go to the documentation of this file.
1#include "aron_conversions.h"
2
4
5namespace armarx::armem
6{
7 constexpr const char* DATA_WRAPPER_TIME_STORED_FIELD = "__WRITER_METADATA__TIME_STORED";
8 constexpr const char* DATA_WRAPPER_TIME_REFERENCED_FIELD = "__ENTITY_METADATA__TIME_REFERENCED";
9 constexpr const char* DATA_WRAPPER_TIME_SENT_FIELD = "__ENTITY_METADATA__TIME_SENT";
10 constexpr const char* DATA_WRAPPER_TIME_ARRIVED_FIELD = "__ENTITY_METADATA__TIME_ARRIVED";
11 constexpr const char* DATA_WRAPPER_CONFIDENCE_FIELD = "__ENTITY_METADATA__CONFIDENCE";
12 constexpr const char* DATA_WRAPPER_ORIGIN_FIELD = "__ENTITY_METADATA__ORIGIN";
13} // namespace armarx::armem
14
15void
19{
20 ARMARX_CHECK_NOT_NULL(metadata);
21 // Todo: What if data is null?
22
24
25 e.data() = data;
26
27 auto referencedTime = aron::data::Long::DynamicCastAndCheck(
28 metadata->getElement(DATA_WRAPPER_TIME_REFERENCED_FIELD));
29 m.referencedTime = Time(Duration::MicroSeconds(referencedTime->toAronLongDTO()->value));
30
31 auto timeSent =
33 m.sentTime = Time(Duration::MicroSeconds(timeSent->toAronLongDTO()->value));
34
36 metadata->getElement(DATA_WRAPPER_TIME_ARRIVED_FIELD));
37 m.arrivedTime = Time(Duration::MicroSeconds(timeArrived->toAronLongDTO()->value));
38
40 metadata->getElement(DATA_WRAPPER_CONFIDENCE_FIELD));
41 m.confidence = static_cast<float>(confidence->toAronDoubleDTO()->value);
42
43 std::vector<std::string> keys = metadata->getAllKeys();
44
45 if (std::find(keys.begin(), keys.end(), DATA_WRAPPER_ORIGIN_FIELD) != keys.end())
46 {
48 metadata->getElement(DATA_WRAPPER_ORIGIN_FIELD));
49 m.origin = origin->toAronStringDTO()->value;
50 }
51 else
52 {
53 // Might occur for old memory exports
54 ARMARX_WARNING << "DATA_WRAPPER_ORIGIN_FIELD not found";
55 m.origin = "undefined2";
56 }
57}
58
59void
62 const wm::EntityInstance& e)
63{
64 data = e.data();
65 metadata = std::make_shared<aron::data::Dict>();
66
67 auto timeWrapped = std::make_shared<aron::data::Long>(
68 armarx::aron::Path(std::vector<std::string>{DATA_WRAPPER_TIME_STORED_FIELD}));
69 timeWrapped->setValue(Time::Now().toMicroSecondsSinceEpoch());
70 metadata->addElement(DATA_WRAPPER_TIME_STORED_FIELD, timeWrapped);
71
73 auto referencedTime = std::make_shared<aron::data::Long>(
75 referencedTime->setValue(m.referencedTime.toMicroSecondsSinceEpoch());
76 metadata->addElement(DATA_WRAPPER_TIME_REFERENCED_FIELD, referencedTime);
77
78 auto timeSent = std::make_shared<aron::data::Long>(
79 armarx::aron::Path(std::vector<std::string>{DATA_WRAPPER_TIME_SENT_FIELD}));
80 timeSent->setValue(m.sentTime.toMicroSecondsSinceEpoch());
81 metadata->addElement(DATA_WRAPPER_TIME_SENT_FIELD, timeSent);
82
83 auto timeArrived = std::make_shared<aron::data::Long>(
84 armarx::aron::Path(std::vector<std::string>{DATA_WRAPPER_TIME_ARRIVED_FIELD}));
85 timeArrived->setValue(m.arrivedTime.toMicroSecondsSinceEpoch());
86 metadata->addElement(DATA_WRAPPER_TIME_ARRIVED_FIELD, timeArrived);
87
88 auto confidence = std::make_shared<aron::data::Double>(
89 armarx::aron::Path(std::vector<std::string>{DATA_WRAPPER_CONFIDENCE_FIELD}));
90 confidence->setValue(static_cast<double>(m.confidence));
91 metadata->addElement(DATA_WRAPPER_CONFIDENCE_FIELD, confidence);
92
93 auto origin = std::make_shared<aron::data::String>(
94 armarx::aron::Path(std::vector<std::string>{DATA_WRAPPER_ORIGIN_FIELD}));
95 origin->setValue(m.origin);
96 metadata->addElement(DATA_WRAPPER_ORIGIN_FIELD, origin);
97}
The Path class.
Definition Path.h:36
static DateTime Now()
Definition DateTime.cpp:51
std::int64_t toMicroSecondsSinceEpoch() const
Definition DateTime.cpp:87
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition Duration.cpp:24
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
base::EntityInstanceMetadata EntityInstanceMetadata
armem::wm::EntityInstance EntityInstance
constexpr const char * DATA_WRAPPER_TIME_REFERENCED_FIELD
void from_aron(const aron::data::DictPtr &metadata, const aron::data::DictPtr &data, wm::EntityInstance &)
convert from metadata and data aron instance
constexpr const char * DATA_WRAPPER_TIME_SENT_FIELD
armarx::core::time::DateTime Time
void to_aron(aron::data::DictPtr &metadata, aron::data::DictPtr &data, const wm::EntityInstance &)
convert to metadata and aron instance
constexpr const char * DATA_WRAPPER_ORIGIN_FIELD
constexpr const char * DATA_WRAPPER_TIME_ARRIVED_FIELD
constexpr const char * DATA_WRAPPER_CONFIDENCE_FIELD
constexpr const char * DATA_WRAPPER_TIME_STORED_FIELD
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
float confidence
An optional confidence, may be used for things like decay.
Time arrivedTime
Time when this value has arrived at the memory.
Time referencedTime
Time this instance refers to.
std::string origin
Indicates the source of the instance e.g. from a specific LTM.
Time sentTime
Time when this value was sent to the memory.