summaryrefslogtreecommitdiffstats
path: root/mddmgr/test/test_mddjoin.cc
blob: c7ae617d6aad2a59a138d02fde71589c42960d1a (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
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
/
/**
 * SOURCE: test_mddjoin.cc
 *
 * MODULE: example for making one tile out of a vector of
 *         Tiles
 *
 * COMMENTS:
 *   later has to be moved to the executor
 *
*/

static const char rcsid[] = "@(#)blobif,test_mddops: $Id: test_mddjoin.cc,v 1.9 2002/09/03 14:46:50 coman Exp $";

#include <stdlib.h>
#include <iostream>
#include "ulongtype.hh"
#include "booltype.hh"
#include "mddmgr/persmddobj.hh"
#include "mddmgr/perstile.hh"
#include "mddmgr/transtile.hh"
#include "adminif.hh"
#include "databaseif.hh"
#include "transactionif.hh"
#include "raslib/rminit.hh"
#include "typefactory.hh"

// global variable for AdminIf because of O2 d_Session::begin()
extern char* myExecArgv0 = "";

RMINITGLOBALS('C')

static char O2BenchDBName[] = "NorbertBase";
static char O2BenchSchemaName[] = "NorbertSchema";

static void testOperations( DatabaseIf myDB );

static BaseType* myType;
static BaseType* boolType;

/*************************************************************
 * Function name.: int main( int argc, char** argv)
 *
 * Arguments.....: 
 *   argc: number of arguments given to program
 *   argv: array of char* with arguments
 * Return value..: exit status
 * Description...: none
 ************************************************************/

int
main( int /* argc */, char** argv)
{
  // variables representing O2 database, ta and session
  DatabaseIf database;
  TransactionIf ta;

  // don't forget to initialize before using AdminIf!
  myExecArgv0 = argv[0];
  AdminIf* myAdmin = AdminIf::instance();

  // connect to the database
  cout << "Connecting to database " << O2BenchDBName 
       << "..." << endl;
  database.open( O2BenchDBName );
  ta.begin(&database);

  // only possible after AdminIf::instance on Sun!
  myType = TypeFactory::mapType("ULong");
  boolType = TypeFactory::mapType("Bool");

  testOperations( database );

  ta.commit();
  cout << "Ending O2 session..." << endl;
  database.close();
  delete myAdmin;
}

void
printAllTiles(const MDDObj* mdd)
{
  // contains all tiles of MDD
  vector<Tile*>* allTiles;
  // iterator
  vector<Tile*>::iterator tileIt;
  // domains of a  tile
  r_Minterval tileDom;

  // domain of MDD object
  r_Minterval dom;
  dom = mdd->getCurrentDomain();

  // get all tiles of result MDD
  allTiles = mdd->intersect(dom);

  // and iterate over them
  tileIt = allTiles->begin();
  while (tileIt !=  allTiles->end())
  {
    tileDom = (*tileIt)->getDomain();
    cout << "Domain of Tile: ";
    tileDom.print_status();
    cout << endl;

    cout << "Tile: " << endl;
    (*tileIt)->printStatus();
    cout << endl;    

    tileIt++;
  }
}

/*************************************************************
 * Function......: testConstructors( DatabaseIf myDB )
 *
 * Arguments.....: 
 *   myDB: database to use (should be opened)
 * Return value..: none
 * Description...: constructs BLOBTiles and inserts them
 *                 in root collection.
 ************************************************************/

static void testOperations( DatabaseIf /* myDB */)
{
  unsigned long cell = 1000;

  ULongType ulongtype;
  BaseType* type = &ulongtype;
  Tile* res;
  Tile* boolTile;

  vector<Tile*>* result = new vector<Tile*>;
  vector<Tile*>::iterator tileIt;
  Tile* bigTile;

  cout << "Creating Tile: ";
  r_Minterval bigDom = 
    r_Minterval(3) << r_Sinterval(1l,10l) << r_Sinterval(1l,10l) 
		   << r_Sinterval(1l,10l);
  bigDom.print_status();
  cout << endl;
  
  bigTile = new PersTile(bigDom, type, (char*)&cell);

  r_Minterval smallDom 
    = r_Minterval(3) << r_Sinterval(1l,6l) << r_Sinterval(1l,6l)
		     << r_Sinterval(1l,6l);

  cout << "Splitting it into ";
  smallDom.print_status();
  cout << " tiles." << endl;

  result = bigTile->splitTile(smallDom);

  cout << "Result tiles: " << endl;
  // and iterate over them
  tileIt = result->begin();
  while (tileIt !=  result->end())
  {
    cout << "  Domain of Tile " << (tileIt - result->begin()) << ": ";
    ((*tileIt)->getDomain()).print_status();
    cout << endl;

    tileIt++;
  }

  cout << "Joining the Tiles again:" << endl;

  r_Minterval proj = 
    r_Minterval(3) << r_Sinterval(2l,9l) << r_Sinterval(2l,9l)
		   << r_Sinterval(2l,9l);

  res = new TransTile(result, proj );

  cout << "  Result MDD equals original MDD: ";
  boolTile = new TransTile(res->getDomain(), boolType);
  cout << "Domain of result Tile: ";
  (res->getDomain()).print_status();
  cout << endl;
  res->printStatus();
  boolTile->execBinaryOp(Ops::OP_EQUAL, proj, 
			 res, proj,
			 bigTile, proj);

  char init = 1;

  cout << "Checking if Tile are equal: ";
  cout << (int)(*(boolTile->execCondenseOp(Ops::OP_ALL, 
					   res->getDomain(), 
					   &init ))) << endl;

  cout << "Creating a trimmed, projected 2-D Tile out of the Tile:" << endl;
  set<r_Dimension, less<r_Dimension> >* projSet = 
    new set<r_Dimension, less<r_Dimension> >;
  projSet->insert(1);

  r_Minterval projDom = 
    r_Minterval(3) << r_Sinterval(2l, 9l) << r_Sinterval(5l, 5l) 
		   << r_Sinterval(2l, 9l);

  Tile* projectedTile = new TransTile(res, projDom, projSet);

  projectedTile->printStatus();
  
  cout << endl;
}