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