summaryrefslogtreecommitdiffstats
path: root/storagemgr/sstoragelayout.cc
blob: 856294add1b28a9aedabc7fe7ba40dc35fc1ddbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/****************************************************************************
 *
 *
 * SOURCE: sstoragelayout.cc
 *
 * MODULE: indexmgr
 * CLASS:	StorageLayout
 *
 * CHANGE HISTORY (append further entries):
 * when				 who				what
 * -----------------------------------------------------------------------
 * 10-Sep-97		furtado		creation of preliminary version.
 * 09-Oct-97		sivan			set, get functions
 * 13-Oct-97		furtado		extended functionality, class hierarchy
 * 4-Nov-98		furtado		added RegDirIx< >.
 * 13-Nov-00		hoefner		startet to do something with this class
 * 07-Jan-09            Shams           add tiling set to the getLayout method 
 * 07-Jan-09            Shams           add some methods for supporting tiling
 * COMMENTS:
 *	 none
 *
 ****************************************************************************/

#include "sstoragelayout.hh"
#include <stdlib.h>
#include "raslib/rmdebug.hh"
#include "rasodmg/alignedtiling.hh"
#include "rasodmg/dirtiling.hh"
#include "rasodmg/stattiling.hh"

const r_Bytes	StorageLayout::DBSPageSize = 4096; 

r_Bytes		StorageLayout::DefaultMinimalTileSize = DBSPageSize;

r_Bytes		StorageLayout::DefaultPCTMax = 2 * DBSPageSize;

r_Bytes		StorageLayout::DefaultTileSize = 32 * DBSPageSize;

unsigned int		StorageLayout::DefaultIndexSize = 0;

r_Index_Type		StorageLayout::DefaultIndexType = r_RPlus_Tree_Index; // DirTilesIx; // AutoIx; 

r_Tiling_Scheme		StorageLayout::DefaultTilingScheme = r_DirectionalTiling;

r_Minterval		StorageLayout::DefaultTileConfiguration("[0:511,0:511]");

r_Data_Format		StorageLayout::DefaultDataFormat = r_Array;

StorageLayout::StorageLayout(r_Index_Type ixType)
	:	myLayout(new DBStorageLayout())
	{
	setIndexType(ixType);
	extraFeatures = new StgMddConfig();
	RMDBGONCE(4, RMDebug::module_storagemgr, "StorageLayout", "StorageLayout(" << ixType << ")")
	}

StorageLayout::StorageLayout()
	:	myLayout(new DBStorageLayout())
	{
	extraFeatures = new StgMddConfig();
	RMDBGONCE(4, RMDebug::module_storagemgr, "StorageLayout", "StorageLayout()")
	}

StorageLayout::StorageLayout(const DBStorageLayoutId& id) 
	:	myLayout(id)	
	{
	extraFeatures = new StgMddConfig();
	RMDBGONCE(4, RMDebug::module_storagemgr, "StorageLayout", "StorageLayout(" << id.getOId() << ")")
	}

/*
const char* 
StorageLayout::getName() const
	{
	return stName;
	} 
*/

DBStorageLayoutId
StorageLayout::getDBStorageLayout() const
	{
	return myLayout;
	}


r_Index_Type
StorageLayout::getIndexType() const
	{
	return myLayout->getIndexType();
	} 


r_Tiling_Scheme
StorageLayout::getTilingScheme() const
	{
	return myLayout->getTilingScheme();
	} 

r_Bytes
StorageLayout::getTileSize() const
	{
	return myLayout->getTileSize(); 
	}

r_Bytes
StorageLayout::getMinimalTileSize() const
	{
	return StorageLayout::DBSPageSize;
	}

r_Minterval
StorageLayout::getTileConfiguration() const
	{
	return myLayout->getTileConfiguration();
	}


void 
StorageLayout::setIndexType(r_Index_Type it)
	{
	myLayout->setIndexType(it);
	}

void 
StorageLayout::setDataFormat(r_Data_Format cs)
	{
	myLayout->setDataFormat(cs);
	}

void 
StorageLayout::setTilingScheme(r_Tiling_Scheme ts)
	{ 
	myLayout->setTilingScheme(ts);
	}

void 
StorageLayout::setTileSize(r_Bytes newSize) 
	{
	myLayout->setTileSize(newSize);
	}

void 
StorageLayout::setTileConfiguration(const r_Minterval& tc)	
	{
	myLayout->setTileConfiguration(tc);
	}

r_Data_Format
StorageLayout::getDataFormat(const r_Point& where) const
	{
	return myLayout->getDataFormat();
	}

void
StorageLayout::setBBoxes(const vector<r_Minterval>& input) {
    extraFeatures->setBBoxes(input);
}

void
StorageLayout::setSubTiling()
{extraFeatures->setSubTiling();}

void
StorageLayout::resetSubTiling()
{extraFeatures->resetSubTiling();}

void
StorageLayout::setInterestThreshold(double i){
    extraFeatures->setInterestThreshold(i);
}

void
StorageLayout::setBorderThreshold(unsigned int b){
    extraFeatures->setBorderThreshold(b);
}

void
StorageLayout::setCellSize(int i){
    extraFeatures->setCellSize(i);
}


void
StorageLayout::setDirDecomp(vector<r_Dir_Decompose>* dir){
    vector<r_Dir_Decompose> dec;
    for(int i = 0 ; i < dir->size() ; ++i){
        dec.push_back(dir->at(i));
    }
    extraFeatures->setDirDecompose(dec);
}


std::vector< r_Minterval > 
StorageLayout::getLayout(const r_Minterval& tileDomain)
	{
	RMDBGENTER(5, RMDebug::module_storagemgr, "StorageLayout", "getLayout(" << tileDomain << ")");
	std::vector< r_Minterval > retval;
	if (myLayout->supportsTilingScheme())
		switch (myLayout->getTilingScheme())
			{
			case r_RegularTiling:
				if (myLayout->getTileConfiguration().dimension() == tileDomain.dimension())
					retval = calcRegLayout(tileDomain);
				else	{
					RMInit::logOut << "Regular Tiling chosen without Tiling Domain!\nPlease specify a Tiling Domain.\nNow using no tiling." << endl;
					RMDBGMIDDLE(0, RMDebug::module_storagemgr, "StorageLayout", "getLayout(" << tileDomain << ") Regular Tiling without Tiling Domain");
					retval.push_back(tileDomain);
					}
				break;
            case r_InterestTiling:
                    retval = calcInterestLayout(tileDomain);
                    RMInit::logOut << "Interest Tiling chosen Everything is OK" << endl;
                    RMDBGMIDDLE(0, RMDebug::module_storagemgr, "StorageLayout", "getLayout(" << tileDomain << ") Interest Tiling");
                break;
            case r_StatisticalTiling:
                    retval = calcStatisticLayout(tileDomain);
                    RMInit::logOut << "Statistical Tiling chosen" << endl;
                break;
            case r_AlignedTiling:
                if (myLayout->getTileConfiguration().dimension() == tileDomain.dimension())
                    retval = calcAlignedLayout(tileDomain);
                else {
                    RMInit::logOut << "Aligned Tiling chosen without Tiling Domain!\nPlease specify a Tiling Domain.\nNow using no tiling." << endl;
                    RMDBGMIDDLE(0, RMDebug::module_storagemgr, "StorageLayout", "getLayout(" << tileDomain << ") Aligned Tiling without Tiling Domain");
                    retval.push_back(tileDomain);
                }
                break;

            case r_DirectionalTiling:
//                if (myLayout->getTileConfiguration().dimension() == tileDomain.dimension())
                    retval = calcDirectionalLayout(tileDomain);
//                else {
                    RMInit::logOut << "Directional Tiling chosen. Everything is OK." << endl;
//                    RMDBGMIDDLE(0, RMDebug::module_storagemgr, "StorageLayout", "getLayout(" << tileDomain << ") Directional Tiling without Tiling Domain");
//                    retval.push_back(tileDomain);
  //              }
                break;

                    case r_SizeTiling:
				RMInit::logOut << "Tiling Scheme " << myLayout->getTilingScheme() << " " << (int)myLayout->getTilingScheme() << " not supported" << endl;
				RMDBGMIDDLE(0, RMDebug::module_storagemgr, "StorageLayout", "getLayout(" << tileDomain << ") of " << myLayout->getOId() << " Tiling Scheme " << myLayout->getTilingScheme() << " " << (int)myLayout->getTilingScheme() << " not supported");
				retval.push_back(tileDomain);
				break;
			default:
				RMInit::logOut << "Unknown Tiling Scheme " << myLayout->getTilingScheme() << " " << (int)myLayout->getTilingScheme() << endl;
				RMDBGMIDDLE(0, RMDebug::module_storagemgr, "StorageLayout", "getLayout(" << tileDomain << ") of " << myLayout->getOId() << " unknown Tiling Scheme " << myLayout->getTilingScheme() << " " << (int)myLayout->getTilingScheme());
			case r_NoTiling:
				retval.push_back(tileDomain);
				break;
			}
	else
		retval.push_back(tileDomain);
	RMDBGEXIT(5, RMDebug::module_storagemgr, "StorageLayout", "getLayout(" << tileDomain << ")");
	return retval;
	}

StorageLayout::~StorageLayout()
	{	
	}

std::vector< r_Minterval >
StorageLayout::calcRegLayout(const r_Minterval& tileDomain) const
	{
	RMDBGENTER(4, RMDebug::module_storagemgr, "StorageLayout", "calcRegLayout(" << tileDomain << ") " << myLayout->getOId());
	std::vector< r_Minterval > retval;
	r_Minterval base = myLayout->getTileConfiguration();
	RMDBGMIDDLE(5, RMDebug::module_storagemgr, "StorageLayout", "base: " << base)
	r_Point borigin = base.get_origin();
	r_Point bhigh = base.get_high();
	r_Point bextent = base.get_extent();
	r_Point torigin = tileDomain.get_origin();
	r_Point thigh = tileDomain.get_high();
	r_Point textent = tileDomain.get_extent();
	r_Dimension dim = base.dimension();
	r_Point transex(dim);
	r_Point transexmax(dim);
	r_Point transco(dim);
	r_Point transcotemp(dim);
	r_Minterval nextDomain(dim);
	r_Dimension counter2 = 0;
	r_Range extent = 0;
	r_Range extent2 = 0;
	r_Range origindiff = 0;
	r_Range highdiff = 0;
	for (counter2 = 0; counter2 < dim; counter2++)
		{
		origindiff = torigin[counter2] - borigin[counter2];
		highdiff = thigh[counter2] - bhigh[counter2];
		if (highdiff%bextent[counter2] > 0)
			transexmax[counter2] = highdiff/bextent[counter2] + 1;
		else
			transexmax[counter2] = highdiff/bextent[counter2];
		if (origindiff%bextent[counter2] < 0)
			transex[counter2] = origindiff/bextent[counter2] - 1;
		else
			transex[counter2] = origindiff/bextent[counter2];
		transco[counter2] = (transex[counter2]) * bextent[counter2];
		}
	for (extent = transex[dim - 1]; extent <= transexmax[dim - 1]; extent++)
		{
		transcotemp = transco;
		transcotemp[dim - 1] = bextent[dim - 1] * extent;
		nextDomain = base.create_translation(transcotemp);
		retval.push_back(nextDomain);
		
		for (counter2 = 0; counter2 < dim - 1; counter2++)
			{
			for (extent2 = transex[counter2] + 1; extent2 <= transexmax[counter2]; extent2++)
				{
				transcotemp[counter2] = bextent[counter2] * extent2;
				nextDomain = base.create_translation(transcotemp);
				retval.push_back(nextDomain);
				}
			}
		}
RMDBGIF(5, RMDebug::module_storagemgr, "StorageLayout", \
	for (std::vector< r_Minterval >::iterator i = retval.begin(); i != retval.end(); i++) \
		RMDBGMIDDLE(1, RMDebug::module_storagemgr, "StorageLayout", *i); \
);
	RMDBGEXIT(4, RMDebug::module_storagemgr, "StorageLayout", "calcRegLayout(" << tileDomain << ") " << myLayout->getOId());
        RMInit::logOut << "CalcReg Tiling: tile number: " << retval.size() << endl;
	return retval;
	}

std::vector< r_Minterval >
StorageLayout::calcInterestLayout(const r_Minterval& tileDomain) {
    RMInit::logOut << "Entering CalcInterest Tiling" << endl;
    r_Interest_Tiling* tiling = new r_Interest_Tiling
            (tileDomain.dimension(), extraFeatures->getBBoxes(), myLayout->getTileSize(), r_Interest_Tiling::SUB_TILING);
    std::vector<r_Minterval> ret;
    std::vector<r_Minterval>* ret1 = tiling->compute_tiles
            (tileDomain, extraFeatures->getCellSize());
    RMInit::logOut << "CalcInterest Tiling: tile number: " << ret1->size() << endl;
    for (int i = 0; i < ret1->size(); i++) {
        ret.push_back(ret1->at(i));
    }
    RMInit::logOut << "CalcInterest Tiling: tile number2: " << ret.size() << endl;
    return ret;
}

std::vector< r_Minterval >
StorageLayout::calcAlignedLayout(const r_Minterval& tileDomain) {
    RMInit::logOut << "Entering CalcAligned Tiling" << endl;
    r_Aligned_Tiling* tiling = new r_Aligned_Tiling
            (myLayout->getTileConfiguration(),myLayout->getTileSize());
    std::vector<r_Minterval> ret;
    std::vector<r_Minterval>* ret1 = tiling->compute_tiles
    (tileDomain, extraFeatures->getCellSize());
    RMInit::logOut << "CalcAligned Tiling: tile number: " << ret1->size() << endl;
    for (int i = 0; i < ret1->size(); i++) {
        ret.push_back(ret1->at(i));
    }
    RMInit::logOut << "CalcAligned Tiling: tile number2: " << ret.size() << endl;
    return ret;
}

std::vector< r_Minterval >
StorageLayout::calcDirectionalLayout(const r_Minterval& tileDomain){
    RMInit::logOut << "Entering CalcDir Tiling" << endl;
    r_Dir_Tiling* dirTile ;
    if(!extraFeatures->getSubTiling())
        dirTile = new r_Dir_Tiling(tileDomain.dimension(),
                extraFeatures->getDirDecompose(),myLayout->getTileSize(),
                r_Dir_Tiling::WITHOUT_SUBTILING);
    else
        dirTile = new r_Dir_Tiling(tileDomain.dimension(),
            extraFeatures->getDirDecompose(),myLayout->getTileSize(),
            r_Dir_Tiling::WITH_SUBTILING);

    std::vector<r_Minterval> ret;
    std::vector<r_Minterval>* ret1 = dirTile->compute_tiles
    (tileDomain, extraFeatures->getCellSize());
    RMInit::logOut << "CalcDir Tiling: tile number: " << ret1->size() << endl;
    for (int i = 0; i < ret1->size(); i++) {
        ret.push_back(ret1->at(i));
    }
    RMInit::logOut << "End of dirTiling Method Tile numbers = "<< ret.size();
    return ret;
}

std::vector< r_Minterval >
StorageLayout::calcStatisticLayout(const r_Minterval& tileDomain){
    RMInit::logOut << "Entering CalcStatistic Tiling" << endl;
    std::vector<r_Minterval> ret;
    RMInit::logOut << "ret is created" << endl;
    RMInit::logOut << "bboxes are " << extraFeatures->getBBoxes().size() << endl;
    vector<r_Minterval> temp = extraFeatures->getBBoxes();
    RMInit::logOut << "bboxes are ok " << temp.size() << endl;
    RMInit::logOut << "Statistic areas are "<< endl;
    std::vector<r_Access> accesses;
    RMInit::logOut << "Beginning of For"<< endl;
    for(int i = 0 ; i < temp.size() ; ++i){
        r_Minterval area = temp.at(i);
        r_Access ac(area);
        RMInit::logOut << ac;
        accesses.push_back(ac);
    }
    RMInit::logOut << "\nStatistic End of for"<<endl;
    unsigned int borderT;
    double interestT;
    if(extraFeatures->getBorderThreshold() < 0)
        borderT = r_Stat_Tiling::DEF_BORDER_THR;
    else
        borderT = extraFeatures->getBorderThreshold();
    if(extraFeatures->getInterestThreshold() < 0)
        interestT = r_Stat_Tiling::DEF_INTERESTING_THR;
    else
        interestT = extraFeatures->getInterestThreshold();
    RMInit::logOut << "Object is : " <<tileDomain.dimension() <<" "<< accesses.size() << " "<<myLayout->getTileSize()<<" "<< borderT<< " "<< interestT <<endl;
    r_Stat_Tiling* stat = new r_Stat_Tiling(tileDomain.dimension(),accesses,
            myLayout->getTileSize(), borderT,
            interestT);
    RMInit::logOut << "Object created" << endl;
    std::vector<r_Minterval>* ret1 = stat->compute_tiles(tileDomain,extraFeatures->getCellSize());
    RMInit::logOut << "End of CalcStatistic Tiling tile numbers = "<< ret.size() << endl;
    for (int i = 0; i < ret1->size(); i++) {
        ret.push_back(ret1->at(i));
    }

    return ret;
}