Writer.cpp
Go to the documentation of this file.
1 #include "Writer.h"
2 
3 #include <iterator>
4 
6 #include <armarx/navigation/algorithms/aron/Costmap.aron.generated.h>
8 #include <armarx/navigation/human/aron/Human.aron.generated.h>
11 
12 
14 {
15  Writer::~Writer() = default;
16 
17  bool
19  // const std::string& name,
20  const std::string& providerName,
21  const armem::Time& timestamp)
22  {
23  std::lock_guard g{writeMutex};
24 
25  const auto result =
27 
28  if (not result.success)
29  {
30  ARMARX_ERROR << result.errorMessage;
31 
32  // TODO(fabian.reister): message
33  return false;
34  }
35 
36  const auto providerId = armem::MemoryID(result.segmentID);
37  const auto entityID = providerId.withEntityName("humans").withTimestamp(timestamp);
38 
40  update.entityID = entityID;
41 
42  std::transform(humans.begin(),
43  humans.end(),
44  std::back_inserter(update.instancesData),
46  navigation::human::arondto::Human dto;
47  toAron(dto, human);
48 
49  return dto.toAron();
50  });
51 
52 
53  update.referencedTime = timestamp;
54 
55  ARMARX_DEBUG << "Committing " << update << " at time " << timestamp;
57 
58  ARMARX_DEBUG << updateResult;
59 
60  if (not updateResult.success)
61  {
62  ARMARX_ERROR << updateResult.errorMessage;
63  }
64 
65  return updateResult.success;
66  }
67 
68  bool
70  // const std::string& name,
71  const std::string& providerName,
72  const armem::Time& timestamp)
73  {
74  std::lock_guard g{writeMutex};
75 
76  const auto result =
78 
79  if (not result.success)
80  {
81  ARMARX_ERROR << result.errorMessage;
82 
83  // TODO(fabian.reister): message
84  return false;
85  }
86 
87  const auto providerId = armem::MemoryID(result.segmentID);
88  const auto entityID = providerId.withEntityName("groups").withTimestamp(timestamp);
89 
91  update.entityID = entityID;
92 
93  std::transform(groups.begin(),
94  groups.end(),
95  std::back_inserter(update.instancesData),
97  navigation::human::arondto::HumanGroup dto;
98  toAron(dto, group);
99 
100  return dto.toAron();
101  });
102 
103 
104  update.referencedTime = timestamp;
105 
106  ARMARX_DEBUG << "Committing " << update << " at time " << timestamp;
108 
109  ARMARX_DEBUG << updateResult;
110 
111  if (not updateResult.success)
112  {
113  ARMARX_ERROR << updateResult.errorMessage;
114  }
115 
116  return updateResult.success;
117  }
118 
119  std::string
121  {
122  return "mem.nav.human.";
123  }
124 
125  armarx::armem::client::util::SimpleWriterBase::SimpleWriterBase::Properties
127  {
128  return SimpleWriterBase::Properties{.memoryName = memory::constants::NavigationMemoryName,
129  .coreSegmentName =
131  }
132 
133 } // namespace armarx::navigation::memory::client::human
armarx::navigation::human::HumanGroup
Definition: types.h:48
armarx::navigation::human::Human
Definition: types.h:33
armarx::armem::client::Writer::addSegment
data::AddSegmentResult addSegment(const std::string &coreSegmentName, const std::string &providerSegmentName, bool clearWhenExists=false) const
Definition: Writer.cpp:16
aron_conversions.h
armarx::armem::EntityUpdateResult
Result of an EntityUpdate.
Definition: Commit.h:72
armarx::navigation::memory::client::human
Definition: Reader.cpp:24
types.h
armarx::navigation::memory::constants::NavigationMemoryName
const std::string NavigationMemoryName
Definition: constants.h:27
armarx::navigation::human::Humans
std::vector< Human > Humans
Definition: types.h:45
armarx::navigation::memory::client::human::Writer::~Writer
~Writer() override
armarx::navigation::memory::client::human::Writer::store
bool store(const armarx::navigation::human::Humans &humans, const std::string &providerName, const armem::Time &timestamp)
Definition: Writer.cpp:18
armarx::armem::client::util::SimpleWriterBase::memoryWriter
armem::client::Writer & memoryWriter()
Definition: SimpleWriterBase.cpp:51
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::armem::client::util::SimpleWriterBase::Properties::memoryName
std::string memoryName
Definition: SimpleWriterBase.h:51
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:27
armarx::navigation::memory::client::human::Writer::defaultProperties
Properties defaultProperties() const override
Definition: Writer.cpp:126
aron_conversions.h
armarx::armem::client::Writer::commit
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition: Writer.cpp:59
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::navigation::memory::constants::HumanCoreSegmentName
const std::string HumanCoreSegmentName
Definition: constants.h:35
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
Writer.h
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::transform
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT > >
Convenience function (with less typing) to transform a container of type InputT into the same contain...
Definition: algorithm.h:315
constants.h
armarx::navigation::human::HumanGroups
std::vector< HumanGroup > HumanGroups
Definition: types.h:58
armarx::navigation::memory::client::human::Writer::propertyPrefix
std::string propertyPrefix() const override
Definition: Writer.cpp:120
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:29