rasdaman complete source
mddobjix.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 */
23 
24 #ifndef _MDDOBJIX_HH_
25 #define _MDDOBJIX_HH_
26 
27 class PersTile;
28 class BaseType;
29 class Tile;
30 class r_Point;
31 #include "raslib/minterval.hh"
32 #include "raslib/rmdebug.hh"
33 #include "indexmgr/indexds.hh"
35 #include "reladminif/lists.h"
36 #include "relindexif/indexid.hh"
37 #include <vector>
38 
39 
40 /****************************************************************************
41  *
42  *
43  * INCLUDE: mddobjix.hh
44  *
45  * MODULE: indexmgr
46  * CLASS: MDDObjIx
47  *
48  *
49  * COMMENTS:
50  * none
51  *
52  ****************************************************************************/
53 
61 /*@Doc:
62 
63 Each MDD Object is composed of a set of tiles which are accessed through an index.
64 The task of the index is to determine the tiles affected by a spatial operation and to allow fast access to them. It will also take care of memory management of the tiles.
65 
66 {\bfMDD Objects indexes: }
67 
68 MDD Objects indexes are multidimensional since they provide access to multidimensional rectangular tiles existing in multidimensional intervals. An MDDObjIx has to be able to deal with different dimensionalities.
69 
70 The index of an MDD object keeps the information about the current domain of the MDD object. During the lifetime of the object, it is possible that the definition (or current) domain of an object is not completely covered by the tiles already inserted.
71 At each moment, the current domain of an object is the closure of the domains of all tiles. All tiles should be completely contained
72 in the definition domain of an object.
73 The definition domain may have open boundaries, but the current domain is always a closed interval.
74 
75 The lower classes in the indexmgr support storage of any kind of persistent object.
76 This class has to be changed to reflect this aability.
77 
78  In the future, functions have to be implemented which allow the user
79  to give indication about priorities for freeing tiles from main memory.
80 
81 */
82 
83 //function pointer to the static function which inserts objects
84 typedef bool (*IxLogic_insertObject) (IndexDS* theIx, const KeyObject& theObj, const StorageLayout& sl);
85 
86 //function pointer to the static function which removes objects
87 typedef bool (*IxLogic_removeObject) (IndexDS* theIx, const KeyObject& theObj, const StorageLayout& sl);
88 
89 //function pointer to the static function which gets objects from the index
90 typedef void (*IxLogic_intersect) (const IndexDS* theIx, const r_Minterval& searchInterval, KeyObjectVector& objs, const StorageLayout& sl);
91 
92 //function pointer to the static function which gets object at point
93 typedef void (*IxLogic_containPointQuery) (const IndexDS* theIx, const r_Point& searchPoint, KeyObject& result, const StorageLayout& sl);
94 
95 //function pointer to the static function which inserts objects
96 typedef void (*IxLogic_getObjects) (const IndexDS* theIx, KeyObjectVector& objs, const StorageLayout& sl);
97 
98 class MDDObjIx
99 {
100 public:
101 
102  MDDObjIx(const StorageLayout& sl, const r_Minterval& dom, const BaseType* bt = 0);
103  /*@Doc:
104  When bt is NULL this index will behave as if it were a transient index.
105  */
106 
107  MDDObjIx(DBObjectId newDBIx, const StorageLayout& sl, const BaseType* bt);
108  /*@Doc:
109  When bt is NULL this index will behave as if it were a transient index.
110  */
111 
112  void printStatus(unsigned int level = 0, std::ostream& stream = std::cout) const;
113 
114  ~MDDObjIx();
115 
116  DBObjectId getDBMDDObjIxId() const;
117 
119 
120  r_Dimension getDimension() const;
121 
122  void insertTile(const Tile* newTile);
123 
124  bool removeTile(const Tile *);
125 
126  std::vector<Tile *> * intersect(const r_Minterval &) const;
127 
128  char* pointQuery(const r_Point& searchPoint);
129 
130  const char* pointQuery(const r_Point& searchPoint) const;
131 
132  Tile* containPointQuery(const r_Point& searchPoint) const;
133 
134  std::vector< Tile* >* getTiles() const;
135 
136  bool isPersistent() const;
137 
138  void releasePersTiles();
139  /*@Doc:
140  This function has to be called by the destructors of persistent subclasses which use the cache, to make sure that the memory for the tiles in the cache is freed.
141  This will only have effect on persistent indexes.
142  Transient indexes keep their tiles in TransDirIx which deletes its tiles in the destructor.
143  */
144 
145 protected:
146 
147  void setNewLastAccess(const r_Minterval& newLastAccess, const std::vector<Tile*>* newLastTiles);
148 
149  void setNewLastAccess(const Tile* newLastTile, bool te = true);
150  /*@Doc:
151  Add a new tile to the cache and reset the access domain
152  If clear:
153  clear the cache
154  release all tiles
155  */
156 
157  std::vector< Tile* >* lastAccessIntersect(const r_Minterval& searchInter) const;
158 
159  Tile* lastAccessPointQuery(const r_Point& searchPoint) const;
160 
161  bool removeTileFromLastAccesses(const Tile* tileToRemove);
162  /*@Doc:
163  Does NOT free tileToRemove allocated memory. Only removes this pointer from lastAccesses list if it finds it there.
164  Returns true if found.
165  Subclasses which use the cache must call this function before removing a tile from the index, or else the tile may remain in main memory.
166  */
167 
169  /*@Doc:
170  Either empty interval, if not to search in the cache, or an interval
171  corresponding to the search done the last time. The algorithms which
172  search this cache for an intersection take this into account.
173  It works simultaneously as a flag and as the specification for the last
174  access, if valid.
175  Last searched region.
176  */
177 
178  std::vector< Tile* > lastAccessTiles;
179  /*@Doc:
180  Internal cache of {\tt Tile}s accessed the last time.
181  Contents change everytime there is an insert, an intersect, a getTiles
182  or a poin query, in the following way:
183  - insert: cache invalid, last Access is put to empty interval,
184  lastAccessTiles contains the inserted tiles. This is needed
185  if we want the index to automatically manage the memory
186  allocated for persistent tiles or else the just inserted
187  tiles are immediately invalid for the user after insertion
188  in the object. The lastAccess can not be put to the area
189  because it's impossible to determine the area corresponding
190  to inserted tiles (there may be empty areas and so on, it
191  would be rather complex to calculate these things).
192  - intersect/pointquery: cache and lastAccessTiles get the new result.
193  The old access and tiles are thrown away.
194  - getTiles: it would be very inefficient to search here for smaller
195  regions, so lastAccess is made empty and lastAccessTiles
196  contains the tiles accessed (because of PersTiles and
197  automatic management of their memory, they have to be
198  kept by the MDDObjIx).
199  For this reason, tiles passed by PersMDDObj are only valid until the
200  next intersect/pointQuery/insert/getTiles operation.
201  Alternative implementation for getTiles - always put in the cache
202  correctly.
203  Make a check about the search interval and what is in the cache (for
204  example, if cell_count < 90% cache cell count , access index).
205  Such a check should also be done in lastAccessPointQuery(): if the
206  cache has more than 10 elements, it is not worth searching in it for
207  a point.
208  */
209 
211  /*@Doc:
212  This is needed because the PersTile constructor expects a BaseType.
213  It Should be considered to move the creation of PersTiles into the
214  MDDObj class.
215  */
216 
217 
219  /*@Doc:
220  The real index structure
221  */
222 
224  /*@Doc:
225  Function pointer to insert tile logic
226  */
227 
229  /*@Doc:
230  Function pointer to remove tile logic
231  */
232 
234  /*@Doc:
235  Function pointer to find tiles logic
236  */
237 
239  /*@Doc:
240  Function pointer to find tile logic
241  */
242 
244  /*@Doc:
245  Function pointer to get all tiles logic
246  */
247 
248 #ifdef RMANBENCHMARK
249 
251  /*@Doc:
252  This code was commented out because it crashed
253  */
254 
258 #endif
266  /*@Doc:
267  This class is used for both persistent and tranisent objects
268  To be able to distinguish whether it is persistent or transient
269  this attribute is used.
270  */
271 
273  /*@Doc:
274  Nifty object which holds information on how to store data in the database.
275  It tells you which index to use, hos large a index might become and so on.
276  */
277 };
278 
279 #endif
IndexDS * actualIx
Definition: mddobjix.hh:218
IxLogic_containPointQuery do_pointQuery
Definition: mddobjix.hh:238
void(* IxLogic_intersect)(const IndexDS *theIx, const r_Minterval &searchInterval, KeyObjectVector &objs, const StorageLayout &sl)
Definition: mddobjix.hh:90
Definition: mddobjix.hh:98
Definition: point.hh:59
bool(* IxLogic_removeObject)(IndexDS *theIx, const KeyObject &theObj, const StorageLayout &sl)
Definition: mddobjix.hh:87
std::vector< Tile * > lastAccessTiles
Definition: mddobjix.hh:178
std::vector< KeyObject > KeyObjectVector
Definition: lists.h:79
DBObjectId getDBMDDObjIxId() const
IxLogic_intersect do_intersect
Definition: mddobjix.hh:233
RMTimer * getTilesTimer
Definition: mddobjix.hh:257
unsigned int r_Dimension
Definition: mddtypes.hh:118
void setNewLastAccess(const r_Minterval &newLastAccess, const std::vector< Tile * > *newLastTiles)
char * pointQuery(const r_Point &searchPoint)
Definition: indexds.hh:51
Definition: keyobject.hh:43
bool _isPersistent
Definition: mddobjix.hh:265
r_Minterval getCurrentDomain() const
void releasePersTiles()
bool removeTileFromLastAccesses(const Tile *tileToRemove)
IxLogic_getObjects do_getObjs
Definition: mddobjix.hh:243
std::vector< Tile * > * getTiles() const
void(* IxLogic_getObjects)(const IndexDS *theIx, KeyObjectVector &objs, const StorageLayout &sl)
Definition: mddobjix.hh:96
bool isPersistent() const
void initializeLogicStructure()
bool removeTile(const Tile *)
const StorageLayout & myStorageLayout
Definition: mddobjix.hh:272
Tile * lastAccessPointQuery(const r_Point &searchPoint) const
r_Minterval lastAccess
Definition: mddobjix.hh:168
std::vector< Tile * > * intersect(const r_Minterval &) const
IxLogic_insertObject do_insertObj
Definition: mddobjix.hh:223
r_Dimension getDimension() const
Definition: tile.hh:80
RMTimer * pointQueryTimer
Definition: mddobjix.hh:255
Tile * containPointQuery(const r_Point &searchPoint) const
Definition: relcatalogif/basetype.hh:66
bool bool
Definition: rviewSound.hh:65
Module: { raslib}.
Definition: rmdebug.hh:298
void initializeTimerPointers()
void(* IxLogic_containPointQuery)(const IndexDS *theIx, const r_Point &searchPoint, KeyObject &result, const StorageLayout &sl)
Definition: mddobjix.hh:93
std::vector< Tile * > * lastAccessIntersect(const r_Minterval &searchInter) const
const BaseType * cellBaseType
Definition: mddobjix.hh:210
void printStatus(unsigned int level=0, std::ostream &stream=std::cout) const
void insertTile(const Tile *newTile)
MDDObjIx(const StorageLayout &sl, const r_Minterval &dom, const BaseType *bt=0)
Definition: sstoragelayout.hh:65
IxLogic_removeObject do_removeObj
Definition: mddobjix.hh:228
bool(* IxLogic_insertObject)(IndexDS *theIx, const KeyObject &theObj, const StorageLayout &sl)
Definition: mddobjix.hh:84
RMTimer * intersectTimer
Definition: mddobjix.hh:256
Definition: minterval.hh:249