PriorKnowledge.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::PriorKnowledge
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 #include "PriorKnowledge.h"
24 
25 #include <IceUtil/UUID.h>
26 
27 #include <SimoxUtility/algorithm/string/string_tools.h>
28 
29 #include <ArmarXCore/interface/core/Log.h>
30 
38 
39 
40 #define PRIOR_SEGMENT_NAME_CLASSES "classes"
41 #define PRIOR_SEGMENT_NAME_RELATIONS "relations"
42 #define PRIOR_SEGMENT_NAME_GRAPH "graphs"
43 
44 namespace memoryx
45 {
46  void
48  {
49  usingProxy("CommonStorage");
50 
51  const std::string clsCollNamesStr = getProperty<std::string>("ClassCollections").getValue();
52  classCollNames = simox::alg::split(clsCollNamesStr, ",");
53 
54  const std::string relCollNamesStr =
55  getProperty<std::string>("RelationCollections").getValue();
56  relationCollNames = simox::alg::split(relCollNamesStr, ",");
57 
58  const std::string graphCollNamesStr =
59  getProperty<std::string>("GraphCollections").getValue();
60  graphCollNames = simox::alg::split(graphCollNamesStr, ",");
61  }
62 
63  void
65  {
66  ARMARX_INFO << "Starting MemoryX::PriorKnowledge";
67 
68  const Ice::CommunicatorPtr ic = getIceManager()->getCommunicator();
69 
70  dataBasePrx = getProxy<CommonStorageInterfacePrx>("CommonStorage");
71 
72  CollectionInterfacePrx writeClassColl = dataBasePrx->requestCollection(classCollNames[0]);
73  PersistentObjectClassSegmentPtr classesSegment =
74  new PersistentObjectClassSegment(writeClassColl, ic);
76  addSegment(PRIOR_SEGMENT_NAME_CLASSES, classesSegment);
77 
78  if (relationCollNames.size() > 0 && !relationCollNames[0].empty())
79  {
80  CollectionInterfacePrx writeRelationColl =
81  dataBasePrx->requestCollection(relationCollNames[0]);
82  PersistentRelationSegmentPtr relationsSegment =
83  new PersistentRelationSegment(writeRelationColl, ic);
85  addSegment(PRIOR_SEGMENT_NAME_RELATIONS, relationsSegment);
86  }
87 
88  if (graphCollNames.size() > 0 && !graphCollNames[0].empty())
89  {
90  ARMARX_INFO << "Adding segments: " << graphCollNames;
91  CollectionInterfacePrx graphClassColl =
92  dataBasePrx->requestCollection(graphCollNames[0]);
93  GraphMemorySegmentPtr graphSegment{new GraphMemorySegment{graphClassColl, ic}};
95  addSegment(PRIOR_SEGMENT_NAME_GRAPH, graphSegment);
96  }
97  }
98 
99  PersistentObjectClassSegmentBasePrx
100  PriorKnowledge::getObjectClassesSegment(const ::Ice::Current& c) const
101  {
102  return PersistentObjectClassSegmentBasePrx::uncheckedCast(
104  }
105 
106  PersistentRelationSegmentBasePrx
107  PriorKnowledge::getRelationsSegment(const ::Ice::Current& c) const
108  {
109  return PersistentRelationSegmentBasePrx::uncheckedCast(
111  }
112 
113  GraphMemorySegmentBasePrx
114  PriorKnowledge::getGraphSegment(const ::Ice::Current& c) const
115  {
116  return GraphMemorySegmentBasePrx::uncheckedCast(getSegment(PRIOR_SEGMENT_NAME_GRAPH, c));
117  }
118 
119  bool
120  PriorKnowledge::hasGraphSegment(const Ice::Current& c) const
121  {
123  }
124 
125  CommonStorageInterfacePrx
126  PriorKnowledge::getCommonStorage(const ::Ice::Current&) const
127  {
128  return dataBasePrx;
129  }
130 
131  bool
132  PriorKnowledge::isPriorCollection(const ::std::string& collNS, const ::Ice::Current&)
133  {
134  const size_t found = collNS.find_first_of('.');
135  if (found == std::string::npos)
136  {
137  return false;
138  }
139  std::string postfix = collNS.substr(found + 1, std::string::npos);
140  return simox::alg::starts_with(postfix, PRIOR_COLLECTION_PREFIX);
141  }
142 
143  void
144  PriorKnowledge::clear(const ::Ice::Current&)
145  {
146  throw armarx::NotImplementedYetException();
147  }
148 
149  void
150  PriorKnowledge::setSegmentReadCollections(const PersistentEntitySegmentBasePtr& segmentPrx,
151  const NameList& collNameList)
152  {
153  ARMARX_INFO << "Setting read collections";
154  segmentPrx->clearReadCollections();
155 
156  for (memoryx::NameList::const_iterator it = collNameList.begin(); it != collNameList.end();
157  ++it)
158  {
159  ARMARX_INFO << "Adding collection " << *it;
160  CollectionInterfacePrx readColl = dataBasePrx->requestCollection(*it);
161 
162  if (!readColl)
163  {
164  ARMARX_ERROR << " Could not find collection with name " << *it << std::endl;
165  }
166  else
167  {
168  segmentPrx->addReadCollection(readColl);
169  }
170  }
171  }
172 
173  std::string
174  PriorKnowledge::getMemoryName(const Ice::Current&) const
175  {
176  return getName();
177  }
178 
179  AbstractMemorySegmentPrx
180  PriorKnowledge::addGenericSegment(const std::string& segmentName, const Ice::Current&)
181  {
183  dataBasePrx->requestCollection(segmentName), getIceManager()->getCommunicator());
184  return addSegment(segmentName, segment);
185  }
186 } // namespace memoryx
armarx::ManagedIceObject::getIceManager
IceManagerPtr getIceManager() const
Returns the IceManager.
Definition: ManagedIceObject.cpp:366
memoryx::PriorKnowledge::hasGraphSegment
bool hasGraphSegment(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: PriorKnowledge.cpp:120
cyberglove_with_calib_22dof.ic
ic
Definition: cyberglove_with_calib_22dof.py:22
memoryx::PriorKnowledge::addGenericSegment
AbstractMemorySegmentPrx addGenericSegment(const std::string &segmentName, const Ice::Current &) override
Definition: PriorKnowledge.cpp:180
memoryx::PriorKnowledge::relationCollNames
NameList relationCollNames
Definition: PriorKnowledge.h:120
memoryx::SegmentedMemory::addSegment
AbstractMemorySegmentPrx addSegment(const std::string &segmentName, const AbstractMemorySegmentPtr &segment, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: SegmentedMemory.cpp:41
memoryx::PriorKnowledge::getRelationsSegment
PersistentRelationSegmentBasePrx getRelationsSegment(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PriorKnowledge.cpp:107
memoryx::PersistentRelationSegment
Definition: PersistentRelationSegment.h:38
PRIOR_SEGMENT_NAME_GRAPH
#define PRIOR_SEGMENT_NAME_GRAPH
Definition: PriorKnowledge.cpp:42
memoryx::PriorKnowledge::getGraphSegment
GraphMemorySegmentBasePrx getGraphSegment(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: PriorKnowledge.cpp:114
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::PriorKnowledge::getCommonStorage
CommonStorageInterfacePrx getCommonStorage(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PriorKnowledge.cpp:126
memoryx::PriorKnowledge::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: PriorKnowledge.cpp:64
ObjectClass.h
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:47
memoryx::PriorKnowledge::isPriorCollection
bool isPriorCollection(const ::std::string &collNS, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: PriorKnowledge.cpp:132
memoryx::SegmentedMemory::hasSegment
bool hasSegment(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: SegmentedMemory.cpp:74
memoryx::PriorKnowledge::getObjectClassesSegment
PersistentObjectClassSegmentBasePrx getObjectClassesSegment(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PriorKnowledge.cpp:100
IceInternal::Handle<::Ice::Communicator >
memoryx::PriorKnowledge::dataBasePrx
CommonStorageInterfacePrx dataBasePrx
Definition: PriorKnowledge.h:117
memoryx::PriorKnowledge::clear
void clear(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: PriorKnowledge.cpp:144
PriorKnowledge.h
PersistentObjectClassSegment.h
PRIOR_SEGMENT_NAME_RELATIONS
#define PRIOR_SEGMENT_NAME_RELATIONS
Definition: PriorKnowledge.cpp:41
memoryx::PriorKnowledge::setSegmentReadCollections
void setSegmentReadCollections(const PersistentEntitySegmentBasePtr &segmentPrx, const NameList &collNameList)
Definition: PriorKnowledge.cpp:150
memoryx::GraphMemorySegment
The Graph Memory Segment contains directed graphs. The graph consists of nodes with poses and edges b...
Definition: GraphMemorySegment.h:43
MemoryXCoreObjectFactories.h
PRIOR_SEGMENT_NAME_CLASSES
#define PRIOR_SEGMENT_NAME_CLASSES
Definition: PriorKnowledge.cpp:40
memoryx::PriorKnowledge::classCollNames
NameList classCollNames
Definition: PriorKnowledge.h:119
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
ObjectInstance.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
memoryx::PriorKnowledge::graphCollNames
NameList graphCollNames
Definition: PriorKnowledge.h:121
IceUtil::Handle
Definition: forward_declarations.h:30
memoryx::PersistentEntitySegment
The PersistentEntitySegment class is the base class for all memory segments containing memoryx::Entit...
Definition: PersistentEntitySegment.h:105
MemoryXTypesObjectFactories.h
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:108
memoryx::PriorKnowledge::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: PriorKnowledge.cpp:47
memoryx::SegmentedMemory::getSegment
AbstractMemorySegmentPrx getSegment(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: SegmentedMemory.cpp:81
GraphMemorySegment.h
armarx::ManagedIceObject::getCommunicator
Ice::CommunicatorPtr getCommunicator() const
Definition: ManagedIceObject.cpp:451
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::PriorKnowledge::getMemoryName
std::string getMemoryName(const Ice::Current &) const override
Definition: PriorKnowledge.cpp:174
PersistentRelationSegment.h
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:38