LongtermMemory.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package MemoryX::LongtermMemory
17 * @author Alexey Kozlov ( kozlov at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 // core
24 #include "LongtermMemory.h"
25 
27 
28 #include "../../libraries/longtermmemory/WorkingMemorySnapshotListSegment.h"
29 #include "../../libraries/memorytypes/segment/KBMSegment.h"
30 #include "../../libraries/memorytypes/segment/OacMemorySegment.h"
31 #include "../../libraries/memorytypes/segment/PersistentDMPDataSegment.h"
32 #include "../../libraries/memorytypes/segment/PersistentObjectClassSegment.h"
33 #include "../../libraries/memorytypes/segment/PersistentObjectInstanceSegment.h"
34 #include "../../libraries/memorytypes/segment/PersistentPredictionDataSegment.h"
35 #include "../../libraries/memorytypes/segment/PersistentProfilerDataSegment.h"
36 #include "../../libraries/memorytypes/segment/PersistentResourceProfileSegment.h"
37 #include <MemoryX/interface/core/EntityBase.h>
38 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
39 
40 namespace memoryx
41 {
42  std::string
44  {
45  return "LongtermMemory";
46  }
47 
48  void
50  {
51  usingProxy("PriorKnowledge");
52 
53  const std::string clsCollNamesStr = getProperty<std::string>("ClassCollections").getValue();
54  classCollNames = armarx::Split(clsCollNamesStr, ",");
55  }
56 
57  void
59  {
60  ARMARX_INFO << "connecting long term memory";
61  priorKnowledgePrx = getProxy<PriorKnowledgeInterfacePrx>("PriorKnowledge");
62  const std::string snaplistCollectionName =
63  getProperty<std::string>("SnapshotListCollection").getValue();
64  const std::string oacCollectionName = getProperty<std::string>("OacCollection").getValue();
65  const std::string kbmCollectionName = getProperty<std::string>("KbmCollection").getValue();
66  const std::string dmpCollectionName = getProperty<std::string>("DmpCollection").getValue();
67  const std::string profilerCollectionName =
68  getProperty<std::string>("ProfilerDataCollection").getValue();
69  const std::string resourceProfileCollectionName =
70  getProperty<std::string>("ResourceProfileCollection").getValue();
71  const std::string predictionDataCollectionName =
72  getProperty<std::string>("PredictionDataCollection").getValue();
73  const std::string selfLocalisationCollectionName =
74  getProperty<std::string>("SelfLocalisationCollection").getValue();
75 
76  databaseInterfacePrx = storagePrx->requestDatabase(dbName);
77 
78  CollectionInterfacePrx snapshotListCollection =
79  databaseInterfacePrx->requestCollection(snaplistCollectionName);
80  CollectionInterfacePrx oacCollection =
81  databaseInterfacePrx->requestCollection(oacCollectionName);
82  CollectionInterfacePrx kbmCollection =
83  databaseInterfacePrx->requestCollection(kbmCollectionName);
84  CollectionInterfacePrx dmpCollection =
85  databaseInterfacePrx->requestCollection(dmpCollectionName);
86 
87  WorkingMemorySnapshotListSegmentPtr snapshotListSegment =
88  new WorkingMemorySnapshotListSegment(databaseInterfacePrx, snapshotListCollection, ic);
89  addSegment(LTM::SegmentNames::SNAPSHOTS, snapshotListSegment);
90 
91  OacMemorySegmentPtr oacSegment =
92  new OacMemorySegment(priorKnowledgePrx->getObjectClassesSegment(), oacCollection, ic);
93  addSegment(LTM::SegmentNames::OACS, oacSegment);
94 
95  PersistentEntitySegmentBasePtr kbmSegment = new KBMSegment(kbmCollection, ic);
96  addSegment(LTM::SegmentNames::KBM, kbmSegment);
97 
98  CollectionInterfacePrx profilerCollection =
99  databaseInterfacePrx->requestCollection(profilerCollectionName);
100  addSegment(LTM::SegmentNames::PROFILER,
101  new PersistentProfilerDataSegment(profilerCollection, ic));
102 
103  CollectionInterfacePrx resourceProfileCollection =
104  databaseInterfacePrx->requestCollection(resourceProfileCollectionName);
105  addSegment(LTM::SegmentNames::RESOURCE_PROFILES,
106  new PersistentResourceProfileSegment(resourceProfileCollection, ic));
107 
108  CollectionInterfacePrx predictionDataCollection =
109  databaseInterfacePrx->requestCollection(predictionDataCollectionName);
110  addSegment(LTM::SegmentNames::PREDICTION_DATA,
111  new PersistentPredictionDataSegment(predictionDataCollection, ic));
112 
113  CollectionInterfacePrx classColl = storagePrx->requestCollection(classCollNames[0]);
114  PersistentObjectClassSegmentPtr classesSegment =
115  new PersistentObjectClassSegment(classColl, ic);
116  addSegment(LTM::SegmentNames::OBJECTCLASSES, classesSegment);
117 
118  PersistentDMPDataSegmentPtr dmpSegment = new PersistentDMPDataSegment(dmpCollection, ic);
119  addSegment(LTM::SegmentNames::DMP, dmpSegment);
120 
121  CollectionInterfacePrx selfLocalisationCollection =
122  databaseInterfacePrx->requestCollection(selfLocalisationCollectionName);
123  PersistentEntitySegmentPtr selfLocalisationSegment =
124  new PersistentEntitySegment(selfLocalisationCollection, ic);
125  addSegment(LTM::SegmentNames::SELF_LOCALISATION, selfLocalisationSegment);
126 
127  ARMARX_INFO << "successfully connected long term memory";
128  }
129 
130  WorkingMemorySnapshotListSegmentBasePrx
132  {
133  return WorkingMemorySnapshotListSegmentBasePrx::uncheckedCast(
134  getSegment(LTM::SegmentNames::SNAPSHOTS, c));
135  }
136 
137  PersistentObjectInstanceSegmentBasePrx
138  LongtermMemory::getCustomInstancesSegment(const std::string& segmentName,
139  bool createIfMissing,
140  const ::Ice::Current& c)
141  {
142  if (hasSegment(segmentName))
143  {
144  return PersistentObjectInstanceSegmentBasePrx::uncheckedCast(
145  getSegment(segmentName, c));
146  }
147  else if (createIfMissing)
148  {
150  databaseInterfacePrx->requestCollection(segmentName), ic);
151  return PersistentObjectInstanceSegmentBasePrx::uncheckedCast(
152  addSegment(segmentName, customSegment, c));
153  }
154  else
155  {
156  return PersistentObjectInstanceSegmentBasePrx();
157  }
158  }
159 
160  void
162  const std::string& snapshotName,
163  const AbstractWorkingMemoryInterfacePrx& workingMemory,
164  const ::Ice::Current&)
165  {
166  WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
168 
169  if (snapshotListSegment)
170  {
171  snapshotListSegment->loadSnapshot(snapshotName, workingMemory);
172  }
173  }
174 
175  bool
177  const std::string& snapshotName,
178  const AbstractWorkingMemoryInterfacePrx& workingMemory,
179  const ::Ice::Current&)
180  {
181  WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
183 
184  if (snapshotListSegment)
185  {
186  return snapshotListSegment->createSnapshot(snapshotName, workingMemory);
187  }
188  else
189  {
190  return false;
191  }
192  }
193 
194  WorkingMemorySnapshotInterfacePrx
195  LongtermMemory::openWorkingMemorySnapshot(const std::string& snapshotName,
196  const ::Ice::Current&)
197  {
198  WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
200 
201  if (snapshotListSegment)
202  {
203  return snapshotListSegment->openSnapshot(snapshotName);
204  }
205  else
206  {
207  return WorkingMemorySnapshotInterfacePrx();
208  }
209  }
210 
211  bool
212  LongtermMemory::removeWorkingMemorySnapshot(const std::string& snapshotName,
213  const ::Ice::Current&)
214  {
215  WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
217 
218  if (snapshotListSegment)
219  {
220  return snapshotListSegment->removeSnapshot(snapshotName);
221  }
222  else
223  {
224  return false;
225  }
226  }
227 
228  NameList
229  LongtermMemory::getSnapshotNames(const ::Ice::Current& c)
230  {
231  WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
233 
234  if (snapshotListSegment)
235  {
236  return snapshotListSegment->getSnapshotNames();
237  }
238  else
239  {
240  throw SnapshotNotFoundException("Snapshot segment not found!", "");
241  }
242  }
243 
244  std::string
245  LongtermMemory::getMemoryName(const Ice::Current&) const
246  {
247  return getName();
248  }
249 
250  PersistentProfilerDataSegmentBasePrx
252  {
253  return PersistentProfilerDataSegmentBasePrx::uncheckedCast(
254  getSegment(LTM::SegmentNames::PROFILER, c));
255  }
256 
257  PersistentPredictionDataSegmentBasePrx
259  {
260  return PersistentPredictionDataSegmentBasePrx::uncheckedCast(
261  getSegment(LTM::SegmentNames::PREDICTION_DATA, c));
262  }
263 
264  PersistentResourceProfileSegmentBasePrx
266  {
267  return PersistentResourceProfileSegmentBasePrx::uncheckedCast(
268  getSegment(LTM::SegmentNames::RESOURCE_PROFILES, c));
269  }
270 
271  OacMemorySegmentBasePrx
272  LongtermMemory::getOacSegment(const ::Ice::Current& c)
273  {
274  return OacMemorySegmentBasePrx::uncheckedCast(getSegment(LTM::SegmentNames::OACS, c));
275  }
276 
277  KBMSegmentBasePrx
278  LongtermMemory::getKBMSegment(const Ice::Current& c)
279  {
280  return KBMSegmentBasePrx::uncheckedCast(getSegment(LTM::SegmentNames::KBM, c));
281  }
282 
283  CommonStorageInterfacePrx
284  LongtermMemory::getCommonStorage(const ::Ice::Current&) const
285  {
286  return storagePrx;
287  }
288 
289  PersistentObjectClassSegmentBasePrx
290  LongtermMemory::getObjectClassesSegment(const ::Ice::Current& c) const
291  {
292  return PersistentObjectClassSegmentBasePrx::uncheckedCast(
293  getSegment(LTM::SegmentNames::OBJECTCLASSES, c));
294  }
295 
296  PersistentDMPDataSegmentBasePrx
297  LongtermMemory::getDMPSegment(const Ice::Current& c)
298  {
299  return PersistentDMPDataSegmentBasePrx::uncheckedCast(
300  getSegment(LTM::SegmentNames::DMP, c));
301  }
302 
303  PersistentEntitySegmentBasePrx
305  {
306  return PersistentEntitySegmentBasePrx::uncheckedCast(
307  getSegment(LTM::SegmentNames::SELF_LOCALISATION, c));
308  }
309 
310  AbstractMemorySegmentPrx
311  memoryx::LongtermMemory::addGenericSegment(const std::string& segmentName, const Ice::Current&)
312  {
314  new PersistentEntitySegment(databaseInterfacePrx->requestCollection(segmentName),
315  getIceManager()->getCommunicator());
316  return addSegment(segmentName, segment);
317  }
318 } // namespace memoryx
memoryx::KBMSegment
Definition: KBMSegment.h:33
memoryx::PersistentProfilerDataSegment
Definition: PersistentProfilerDataSegment.h:35
memoryx::SegmentedMemory::addSegment
AbstractMemorySegmentPrx addSegment(const std::string &segmentName, const AbstractMemorySegmentPtr &segment, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: SegmentedMemory.cpp:41
memoryx::OacMemorySegment
Definition: OacMemorySegment.h:38
armarx::Split
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelperTemplates.h:36
memoryx::AbstractLongtermMemory::storagePrx
CommonStorageInterfacePrx storagePrx
Definition: AbstractLongtermMemory.h:81
memoryx::AbstractLongtermMemory::dbName
std::string dbName
Definition: AbstractLongtermMemory.h:85
memoryx::LongtermMemory::getSnapshotNames
NameList getSnapshotNames(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:229
memoryx::LongtermMemory::removeWorkingMemorySnapshot
bool removeWorkingMemorySnapshot(const std::string &snapshotName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:212
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
memoryx::PersistentObjectClassSegment
The persistent object class segment is a specialized segment of the SegmentedMemory.
Definition: PersistentObjectClassSegment.h:42
memoryx::LongtermMemory::getKBMSegment
KBMSegmentBasePrx getKBMSegment(const Ice::Current &) override
Definition: LongtermMemory.cpp:278
LongtermMemory.h
memoryx::LongtermMemory::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: LongtermMemory.cpp:43
memoryx::LongtermMemory::onConnectLongtermMemory
void onConnectLongtermMemory() override
Definition: LongtermMemory.cpp:58
memoryx::LongtermMemory::getOacSegment
OacMemorySegmentBasePrx getOacSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:272
StringHelpers.h
memoryx::SegmentedMemory::hasSegment
bool hasSegment(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: SegmentedMemory.cpp:74
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::WorkingMemorySnapshotListSegment
Definition: WorkingMemorySnapshotListSegment.h:37
memoryx::LongtermMemory::getProfilerDataSegment
PersistentProfilerDataSegmentBasePrx getProfilerDataSegment(const Ice::Current &c=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:251
memoryx::PersistentPredictionDataSegment
Definition: PersistentPredictionDataSegment.h:34
memoryx::LongtermMemory::getObjectClassesSegment
PersistentObjectClassSegmentBasePrx getObjectClassesSegment(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: LongtermMemory.cpp:290
memoryx::LongtermMemory::getCommonStorage
CommonStorageInterfacePrx getCommonStorage(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: LongtermMemory.cpp:284
memoryx::LongtermMemory::getResourceProfileSegment
PersistentResourceProfileSegmentBasePrx getResourceProfileSegment(const Ice::Current &c=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:265
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
memoryx::LongtermMemory::getPredictionDataSegment
PersistentPredictionDataSegmentBasePrx getPredictionDataSegment(const Ice::Current &c=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:258
IceUtil::Handle
Definition: forward_declarations.h:30
memoryx::LongtermMemory::getDMPSegment
PersistentDMPDataSegmentBasePrx getDMPSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:297
memoryx::PersistentEntitySegment
The PersistentEntitySegment class is the base class for all memory segments containing memoryx::Entit...
Definition: PersistentEntitySegment.h:105
memoryx::LongtermMemory::getCustomInstancesSegment
PersistentObjectInstanceSegmentBasePrx getCustomInstancesSegment(const std::string &segmentName, bool createIfMissing, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:138
memoryx::AbstractLongtermMemory::ic
Ice::CommunicatorPtr ic
Definition: AbstractLongtermMemory.h:82
memoryx::LongtermMemory::openWorkingMemorySnapshot
WorkingMemorySnapshotInterfacePrx openWorkingMemorySnapshot(const std::string &snapshotName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:195
memoryx::PersistentObjectInstanceSegment
Definition: PersistentObjectInstanceSegment.h:38
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:108
memoryx::SegmentedMemory::getSegment
AbstractMemorySegmentPrx getSegment(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: SegmentedMemory.cpp:81
memoryx::LongtermMemory::getSelfLocalisationSegment
PersistentEntitySegmentBasePrx getSelfLocalisationSegment(const Ice::Current &c=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:304
memoryx::LongtermMemory::getWorkingMemorySnapshotListSegment
WorkingMemorySnapshotListSegmentBasePrx getWorkingMemorySnapshotListSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:131
memoryx::LongtermMemory::getMemoryName
std::string getMemoryName(const Ice::Current &=Ice::emptyCurrent) const override
Definition: LongtermMemory.cpp:245
memoryx::LongtermMemory::saveWorkingMemorySnapshot
bool saveWorkingMemorySnapshot(const std::string &snapshotName, const AbstractWorkingMemoryInterfacePrx &workingMemory, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:176
memoryx::LongtermMemory::loadWorkingMemorySnapshot
void loadWorkingMemorySnapshot(const std::string &snapshotName, const AbstractWorkingMemoryInterfacePrx &workingMemory, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: LongtermMemory.cpp:161
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:154
memoryx::LongtermMemory::onInitLongtermMemory
void onInitLongtermMemory() override
Definition: LongtermMemory.cpp:49
memoryx::LongtermMemory::addGenericSegment
AbstractMemorySegmentPrx addGenericSegment(const std::string &segmentName, const Ice::Current &) override
Definition: LongtermMemory.cpp:311
memoryx::PersistentResourceProfileSegment
Definition: PersistentResourceProfileSegment.h:35
memoryx::PersistentDMPDataSegment
Definition: PersistentDMPDataSegment.h:35