diff options
author | Constantin Jucovschi <cj@ubuntu.localdomain> | 2009-04-24 07:20:22 -0400 |
---|---|---|
committer | Constantin Jucovschi <cj@ubuntu.localdomain> | 2009-04-24 07:20:22 -0400 |
commit | 8f27e65bddd7d4b8515ce620fb485fdd78fcdf89 (patch) | |
tree | bd328a4dd4f92d32202241b5e3a7f36177792c5f /tilemgr/test | |
download | rasdaman-upstream-8f27e65bddd7d4b8515ce620fb485fdd78fcdf89.tar.gz rasdaman-upstream-8f27e65bddd7d4b8515ce620fb485fdd78fcdf89.tar.xz rasdaman-upstream-8f27e65bddd7d4b8515ce620fb485fdd78fcdf89.zip |
Initial commitv8.0
Diffstat (limited to 'tilemgr/test')
-rw-r--r-- | tilemgr/test/Makefile | 81 | ||||
-rw-r--r-- | tilemgr/test/test_access.cc | 673 | ||||
-rw-r--r-- | tilemgr/test/test_access.data | 3 | ||||
-rw-r--r-- | tilemgr/test/test_splittile.cc | 142 | ||||
-rw-r--r-- | tilemgr/test/test_tile.cc | 979 | ||||
-rw-r--r-- | tilemgr/test/tilertest.cc | 288 |
6 files changed, 2166 insertions, 0 deletions
diff --git a/tilemgr/test/Makefile b/tilemgr/test/Makefile new file mode 100644 index 0000000..2070f70 --- /dev/null +++ b/tilemgr/test/Makefile @@ -0,0 +1,81 @@ +# -*-Makefile-*- +# +# 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>. # Top Level makefile. This points to the various modules that have to be build +# and/or deployed +# +# MAKEFILE FOR: +# test programs of module tilemgr +# +# COMMENTS: +# +################################################################## +######################### Definitions ############################ + +# all test programs +SRCCXX = test_access.cc test_splittile.cc test_tile.cc tilertest.cc +OBJS = ${SRCCXX:%.cc=%.o} +ALLTESTS = ${SRCCXX:%.cc=%} + + +# Sun Solaris: -lposix4 is needed for test_tile because of clock_gettime +ifeq ($(OSTYPE),$(OSTYPE_SOLARIS)) + LDFLAGS += -lposix4 +endif + +ALLFLAGS = $(BASEDBLDFLAGS) $(LDFLAGS) $(STLLDFLAGS) -L$(SUPPORT_BASE)/lib -lz + +MAINLIBS = $(RASLIB) $(TILEMGR) $(MDDIF) $(CATALOGIF) $(CATALOGMGR) \ + $(INDEXMGR) $(BLOBIF) $(MDDMGR) $(ADMINIF) $(QLPARSER) $(INDEXIF) + +########################### Targets ############################## + +# make all tests +.PHONY: test +test: test_tile test_splittile test_access + + +######################## Dependencies ############################ + +test_splittile: test_splittile.o $(RASLIB) $(TILEMGR) $(MDDMGR) $(CATALOGMGR) \ + $(MDDIF) $(CATALOGIF) $(INDEXIF) $(INDEXMGR) $(BLOBIF) $(ADMINIF) + $(PURIFY) $(CXX) $(BASEDBLDFLAGS) $(STLLDFLAGS) $(LDFLAGS) -o $@ $^ \ + $(STLLDFLAGS) + +tilertest: tilertest.o $(RASLIB) $(TILEMGR) $(MDDMGR) $(CATALOGMGR) \ + $(MDDIF) $(CATALOGIF) $(INDEXIF) $(INDEXMGR) $(BLOBIF) $(ADMINIF) + $(PURIFY) $(CXX) $(BASEDBLDFLAGS) $(STLLDFLAGS) $(LDFLAGS) -o $@ $^ $(BLOBIF) $(ADMINIF) $(CATALOGIF) $(INDEXIF) $(MDDIF) $(CATALOGIF) $(STLLDFLAGS) $(INDEXMGR) $(COMPRESSION) $(RASLIB) + + +# can not be used as a target (module library is not remade!) +test_tile: test_tile.o $(QLPARSER) $(RASLIB) $(ADMINIF) $(CATALOGMGR) \ + $(TILEMGR) $(MDDMGR) $(MDDIF) $(CATALOGIF) $(INDEXMGR) $(BLOBIF) $(INDEXIF) + $(PURIFY) $(CXX) $(LDFLAGS) $(STLLDFLAGS) $(BASEDBLDFLAGS) \ + -L$(SUPPORT_BASE)/lib -o $@ $^ -lmalloc -lospace \ + $(RASLIB) $(QLPARSER) -lz + + +test_access: test_access.o $(SERVERCOMM) $(QLPARSER) $(CONVERSION) $(RASLIB) \ + $(ADMINIF) $(CACHETAMGR) $(COMPRESSION) $(MDDIF) $(CATALOGIF) \ + $(INDEXMGR) $(BLOBIF) $(INDEXIF) $(HTTPSERVER) + $(PURIFY) $(CXX) $(LDFLAGS) $(BASEDBLDFLAGS) -o $@ $^ \ + $(RELCATALOGIF) -lstdc++ -L$(SUPPORT_BASE)/lib $(RASLIB) -ltiff -lz + diff --git a/tilemgr/test/test_access.cc b/tilemgr/test/test_access.cc new file mode 100644 index 0000000..0b9149c --- /dev/null +++ b/tilemgr/test/test_access.cc @@ -0,0 +1,673 @@ +/* +* 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>. +*/ + +/**************************************************************************** + * + * + * PURPOSE: + * accesses data from a RasDaMan database according to the options + * specified in an input file. Optionally outputs timing and size + * information. + * + * DESCRIPTION: + * test_access reads from a text file a database name, and mddcolls + * names and for each one of them, it either reads a PersMDDColl and + * prints the status of all the mddobjs it contains (or part of them) + * or it deletes the MDDObjs. + * The program is able to print the tiles contents, show the accessing + * time and the sizes of each MDDObject. + * The input file has to start with the line: + * 'Database: <database name> ' + * and after it, for every MDDCollection, the line: + * 'MDDColl: <mddcoll name> ' + * which can be followed by the line: + * ' intersect: <domain> ' + * or by the line: + * ' pointQuery: <domain> ' + * in this case, the cell with address equal to the origin of the + * tile is accessed. + * which causes printing only the status of the mddobjs which + * intersect with <domain>. + * Options and arguments are described in the printUsage( ) function. + * + * Example input file : + * Database: SMRasDaBase + * MDDColl: Images2DA + * intersect: [0:29,9:19] + * MDDColl: Toms3DA + * + * + * COMMENTS: + * In this version, the -r option deletes whole collections only. + * To be extended in the future to delete selected objects and/or + * selected parts of objects. + * + ***************************************************************************/ + +#ifdef EARLY_TEMPLATE +#define __EXECUTABLE__ +#ifdef __GNUG__ +#include "server/template_inst.hh" +#endif +#endif + +#include <stdlib.h> +#include <iostream.h> +#include <fstream.h> +#include <string.h> +#include <vector.h> + +#ifdef BASEDB_O2 +#include "o2template_CC.hxx" // declaration of O2 ref and coll classes +#endif + +#include "raslib/rminit.hh" +#include "raslib/rmdebug.hh" +#include "typefactory.hh" +#include "ulongtype.hh" // from the catalogif base DBMS interface module + +#include "mddmgr/persmddcoll.hh" +#include "mddmgr/persmddobj.hh" + +#include "mddmgr/persmddcolliter.hh" + +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" + +#include "compression/tilecompression.hh" + +extern char* myExecArgv0 = ""; + +RMINITGLOBALS('C') + +#define MAX 256 +ifstream testfile; + +void testAccessing( char* persMDDCollName, char* search, + int printTilesContents, int timeAccess, + int printSizes, int printCompression ); +void intersectOption( char* search, + PersMDDColl* accessedColl, + int printTilesContents, + int timeAccess, + int printSizes ); +void pointQueryOption( char* search, + PersMDDColl* accessedColl, + int timeAccess, + int printSizes ); +void testDeleteColls( DatabaseIf* db, char* persMDDCollName, + char* search, int timeAccess, int printSizes ); + +int checkArguments( int argc, char** argv, const char* searchText, + int& optionValueIndex ); +void printUsage( ); + +/********************************************************************** + * 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, test file, ta and session + DatabaseIf database; + TransactionIf ta; + // static char O2BenchSchemaName[] = "SMRasDaSchema"; + static char O2BenchDBName[MAX]; + char mc_name[MAX],search[MAX]; + int printTilesContents = 0; + int timeAccess = 0; + int printSizes = 0; + int printCompression = 0; + int deleteColls = 0; + int i, optionValueIndex; + + // don't forget to initialize before using AdminIf! + myExecArgv0 = argv[0]; + AdminIf* myAdmin = AdminIf::instance(); + + // is help is needed + if (checkArguments (argc, argv, "-h", optionValueIndex)) + { + printUsage( ); + delete myAdmin; + exit( 0 ); + } + + // openning the test file + if (checkArguments (argc, argv, "-f", optionValueIndex)) + { + for (i = 0; argv[optionValueIndex][i+1] != '\0'; i++) + search[i] = argv[optionValueIndex][i+2]; + testfile.open (search); + if (!testfile) + { + cout << "cannot open this file" << endl; + return 1; + } + } + else + printUsage( ); + /* + { + cout << "Please write: test_access -f<testfile-name>" << endl; + cout << "Or maybe: test_access -h for help...." << endl; + return 1; + } + */ + + // updating the flag of printing the tiles + if (checkArguments (argc, argv, "-p", optionValueIndex)) + printTilesContents = 1; + + // updating the flag of timming the access + if (checkArguments (argc, argv, "-t", optionValueIndex)) + timeAccess = 1; + + // updating the flag of printing the sizes of mddobjs + if (checkArguments (argc, argv, "-s", optionValueIndex)) + printSizes = 1; + + // updating the flag of deletion + if (checkArguments (argc, argv, "-r", optionValueIndex)) + deleteColls = 1; + + // updating the flag of compression + if (checkArguments (argc, argv, "-c", optionValueIndex)) + printCompression = 1; + + // reading data-base name + testfile.getline (search, MAX, ':'); + while ((!strstr (search, "Database")) && (!testfile.eof ( ))) + testfile.getline (search, MAX, ':'); + testfile >> O2BenchDBName; + + // connect to the database + cout << "Connecting to database " << O2BenchDBName + << "..." << endl; + database.open (O2BenchDBName); + + // searching for mddcalls + testfile.getline (search, MAX, ':'); + while (!testfile.eof ( )) + { + ta.begin ( &database ); + + // searching for mddcall + while ((!strstr (search, "MDDColl")) && (!testfile.eof ( ))) + testfile.getline (search, MAX, ':'); + if (strstr (search, "MDDColl")) + { + testfile >> mc_name; + testfile.getline (search, MAX, ':'); + if (!deleteColls) + testAccessing (mc_name, search, printTilesContents, timeAccess, + printSizes, printCompression); + else + testDeleteColls(&database, mc_name, search, timeAccess, printSizes); + } + + ta.commit( ); + } + + cout << endl<< "Ending O2 session..." << endl; + database.close( ); + testfile.close( ); + delete myAdmin; +} + +/********************************************************************** + * Function......: + * testAccessing( char* persMDDCollName, char* search, + * int printTilesContents, int timeAccess, + * int printSizes) + * Arguments.....: + * persMDDCollName: the MDDColl name + * search: for searching the words from the file + * printTilesContents: the flag of printing the tiles + * timeAccess: the flag of timming the access + * Return value..: none + * Description...: reads DirTilesIx's and shows contents + **********************************************************************/ + +void testAccessing( char* persMDDCollName, char* search, + int printTilesContents, int timeAccess, + int printSizes, int printCompression) +{ + PersMDDObj* accessedObj; + PersMDDColl* accessedColl; + + cout << endl << endl << "....testAccessing " << persMDDCollName << endl; + try + { + accessedColl = new PersMDDColl(persMDDCollName); + } + catch(...) + { + cout << " Error: exception caught when trying to access collection "; + cout << endl; + return; + } + + // To test PersMDDColl::printStatus( ) + // accessedColl->printStatus( ); + + // To test PersMDDObj::printStatus( ), MDDCollIter::createIterator( ) and + // MDDCollIter methods : + + // cout << " Iterating through the collection with PersMDDCollIter " << endl; + // MDDCollIter* objsIt = accessedColl->createIterator( ); + + + // the regular option of showing the contents + if ((strstr (search, "MDDColl")) || (testfile.eof ( ))) + { + cout << " Iterating through the collection with PersMDDCollIter " << endl; + MDDCollIter* objsIt = accessedColl->createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + accessedObj = (PersMDDObj*) objsIt->getElement(); + cout << endl << endl << " --" << i << ". MDD object in set:" << endl; + + if (printTilesContents && timeAccess) + { + vector<Tile*>* TileVector; + + // start counter + RMInit::dbgOut.rdbuf(cout.rdbuf()); + RMTimer* Counter = new RMTimer("PersMDDObj", "getTiles"); + TileVector = accessedObj->getTiles ( ); + + // stop counter + cout << "The time of accessing by "; + delete Counter; + + vector<Tile*> ::iterator t; + for (t = TileVector->begin ( ); t != TileVector->end ( ); t++) + { + (*t)->printStatus( ); + cout << endl; + } + + TileVector->erase( TileVector->begin(), TileVector->end() ); + delete TileVector; + } + + else if (printTilesContents && !timeAccess) + { + vector<Tile*>* TileVector; + TileVector = accessedObj->getTiles ( ); + + vector<Tile*> ::iterator t; + for (t = TileVector->begin ( ); t != TileVector->end ( ); t++) + { + (*t)->printStatus( ); + cout << endl; + } + + TileVector->erase( TileVector->begin(), TileVector->end() ); + delete TileVector; + } + + else if (!printTilesContents && timeAccess) + { + // start counter + RMInit::dbgOut.rdbuf(cout.rdbuf()); + RMTimer* Counter = new RMTimer("PersMDDObj", "printStatus"); + accessedObj->printStatus ( ); + + // stop counter + cout << endl << "The time of accessing by "; + delete Counter; + } + + else if (!printTilesContents && !timeAccess) + { + accessedObj->printStatus ( ); + } + + if (printSizes) + { + // printing the sizes of the mddobj + cout << endl << "The logical-size of the mddobj: " << accessedObj->getLogicalSize ( ) << endl; + cout << "The physical-size of the mddobj: " << accessedObj->getPhysicalSize ( ) << endl; + cout << "The physical-cells-size of the mddobj: " << accessedObj->getPhysicalCellsSize ( ) << endl; + cout << "The index-size of the mddobj: " << accessedObj->getIxSize ( ) << endl; + } + + if (printCompression) + { + int i = 0; + unsigned long totalSize = 0; + + vector<Tile*>* TileVector; + TileVector = accessedObj->getTiles ( ); + + vector<Tile*> ::iterator t; + for (t = TileVector->begin ( ); t != TileVector->end ( ); t++) + { + cout << ++i << ". "; + if( (*t)->getDataFormat() == r_ZLib ) + { + totalSize += (*t)->getPhysicalSize( ); + cout << "Size of compressed tile: " + << (*t)->getPhysicalSize( ) << endl; + } + else + { + cout << "Tile not compressed! Size: " << (*t)->getSize() << endl; + + } + } + TileVector->erase( TileVector->begin(), TileVector->end() ); + delete TileVector; + + if(totalSize != 0) + cout << "Total size of compressed tiles: " << totalSize << endl; + } + } // for objsIt loop + + delete objsIt; + + } // if MDDColl + + // the intersect option + else if (strstr (search, "intersect")) + { + intersectOption( search, accessedColl, printTilesContents, timeAccess, printSizes); + } + else if (strstr (search, "pointQuery")) + { + pointQueryOption( search, accessedColl, timeAccess, printSizes); + } + else + { + cout << "don't know what is this..." << endl; + testfile.getline (search, MAX, ':'); + } + + + + accessedColl->releaseAll( ); + delete accessedColl; +} + + + +void +intersectOption( char* search, + PersMDDColl* accessedColl, + int printTilesContents, + int timeAccess, + int printSizes ) +{ + PersMDDObj* accessedObj; + + int cont = 1; + for ( ; cont == 1 ; ) // intersect loop + { + testfile.get (search, MAX, '['); + testfile.getline (search, MAX, ']'); + strcat (search, "]"); + + cout << " Iterating through the collection with PersMDDCollIter " << endl; + MDDCollIter* objsIt = accessedColl->createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + accessedObj = (PersMDDObj*) objsIt->getElement(); + cout << endl << endl << " --" << i << ". MDD object in set:" << endl; + + r_Minterval interval (search); + cout << "Intersecting to "<< interval << endl; + vector<Tile*>* TileVector; + vector<Tile*> ::iterator t; + RMTimer* Counter; + + if ( timeAccess ) + { + // start counter + // RMInit::dbgOut = cout.rdbuf(); + RMInit::bmOut << "Intersect Region " << interval << " " << "\t"; + // Counter = new RMTimer(" PersMDDObj", "intersect"); + } + + TileVector = accessedObj->intersect (interval); + + if ( printTilesContents ) + { + int j = 1; + for (t = TileVector->begin ( ); t != TileVector->end ( ); t++, j++) + { + cout << "Tile "<< j <<": "<<endl; + (*t)->printStatus( ); + cout << endl; + } + } + else + { + int j = 1; + for (t = TileVector->begin ( ); t != TileVector->end ( ); t++, j++) + cout << "Tile " << j << ": " << (*t)->getDomain ( ) << endl; + } + + // ?? TileVector->erase( ); + delete TileVector; + + if (printSizes) + { + // printing the sizes of the mddobj + cout << endl << "The logical-size of the mddobj: " << accessedObj->getLogicalSize ( ) << endl; + cout << "The physical-size of the mddobj: " << accessedObj->getPhysicalSize ( ) << endl; + cout << "The physical-cells-size of the mddobj: " << accessedObj->getPhysicalCellsSize ( ) << endl; + cout << "The index-size of the mddobj: " << accessedObj->getIxSize ( ) << endl; + } + } // for objsIt loop + + delete objsIt; + testfile.getline (search, MAX, ':'); + cout << search << endl; + if ( !strstr( search, "intersect") ) + cont = 0; + // cout << " cont "<< cont << endl; + } // for cont loop +} + +void +pointQueryOption( char* search, + PersMDDColl* accessedColl, + int timeAccess, + int printSizes ) +{ + PersMDDObj* accessedObj; + + int cont = 1; + for ( ; cont == 1 ; ) // intersect loop + { + testfile.get (search, MAX, '['); + testfile.getline (search, MAX, ']'); + strcat (search, "]"); + + cout << " Iterating through the collection with PersMDDCollIter " << endl; + MDDCollIter* objsIt = accessedColl->createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + accessedObj = (PersMDDObj*) objsIt->getElement(); + cout << endl << endl << " --" << i << ". MDD object in set:" << endl; + + r_Minterval interval (search); + r_Point pnt = interval.get_origin( ); + cout << "Point query to "<< pnt << endl; + + RMTimer* Counter; + if ( timeAccess ) + { + // start counter + RMInit::bmOut << "Intersect Region " << interval << " " << "\t"; + // Counter = new RMTimer(" PersMDDObj", "intersect"); + } + + char* result = accessedObj->pointQuery(pnt); + if ( result ) + cout << "Result of point query : "<< long(*result) <<endl; + else + cout << "Null pointer returned from pointQuery!!!! "<< endl; + + if (printSizes) + { + // printing the sizes of the mddobj + cout << endl << "The logical-size of the mddobj: " << accessedObj->getLogicalSize ( ) << endl; + cout << "The physical-size of the mddobj: " << accessedObj->getPhysicalSize ( ) << endl; + cout << "The physical-cells-size of the mddobj: " << accessedObj->getPhysicalCellsSize ( ) << endl; + cout << "The index-size of the mddobj: " << accessedObj->getIxSize ( ) << endl; + } + } // for objsIt loop + + delete objsIt; + testfile.getline (search, MAX, ':'); + cout << search << endl; + if ( !strstr( search, "pointQuery") ) + cont = 0; + // cout << " cont "<< cont << endl; + } // for cont loop +} + + + +/********************************************************************** + * Function......: + * testDeleteColls( DatabaseIf* db, char* persMDDCollName, + * char* search, int timeAccess,int printSizes ) + * + * Arguments.....: + * persMDDCollName: the MDDColl name + * search: for searching the words from the file + * printTilesContents: the flag of printing the tiles + * timeAccess: the flag of timming the access + * Return value..: none + * Description...: reads DirTilesIx's and shows contents + **********************************************************************/ + +void testDeleteColls( DatabaseIf* db, char* persMDDCollName, + char* search, int timeAccess, int printSizes) +{ + // PersMDDObj* accessedObj; + PersMDDColl* accessedColl; + + /* + cout << endl << endl << "... Destroying root collection " + << persMDDCollName << endl; + PersMDDColl::destroyRoot( persMDDCollName, db ); + */ + + cout << endl << endl << "....testAccessing " << persMDDCollName << endl; + try + { + accessedColl = new PersMDDColl( persMDDCollName ); + } + catch(...) + { + cout << " Error: exception caught when trying to access collection "; + cout << endl; + return; + } + + accessedColl->removeAll( ); + accessedColl->releaseAll( ); + + cout << endl << endl << "... Destroying root collection " + << persMDDCollName << endl; + PersMDDColl::destroyRoot( persMDDCollName, db ); + +} + +/********************************************************************** + * Function......: checkArguments (int argc, char** argv, + * const char* searchText, + * int& optionValueIndex) + * + * Arguments.....: + * argc: number of arguments given to program + * argv: array of char* with arguments + * searchText: the desire option + * optionValueIndex: the index of the found option + * Return value..: int + * Description...: searching an option in the accexuting line + **********************************************************************/ +int checkArguments (int argc, char** argv, const char* searchText, + int& optionValueIndex) +{ + int found = 0; + int i = 1; + + while (!found && i < argc) + { + found = !strncmp (searchText, argv[i], 2); + if (!found) + i++; + } + if (found) + optionValueIndex = i; + else + optionValueIndex = 0; + + return found; +} + + +void printUsage( ) +{ + cout << endl << "Usage: " << endl; + cout << "test_access -h" << endl; + cout << "test_access -f<file> [-t] [-p] [-s]" << endl; + cout << "test_access -f<file> -r " << endl; + cout << " -h ... this help" << endl; + cout << " -p ... for printing tiles contents" << endl; + cout << " -t ... for timming the access" << endl; + cout << " -s ... for printing the sizes of mddobjs" << endl; + cout << " -f<file> ... for the name of the text file" << endl; + cout << " -r ... for deleting the collections listed in <file>" << endl; + cout << " -c ... for printing info on compressed tiles"; + cout << endl << endl; + +} + + + + + + + + + + + diff --git a/tilemgr/test/test_access.data b/tilemgr/test/test_access.data new file mode 100644 index 0000000..d3b434f --- /dev/null +++ b/tilemgr/test/test_access.data @@ -0,0 +1,3 @@ +Database: RASBASE +MDDColl: rockies_comp + diff --git a/tilemgr/test/test_splittile.cc b/tilemgr/test/test_splittile.cc new file mode 100644 index 0000000..de713e2 --- /dev/null +++ b/tilemgr/test/test_splittile.cc @@ -0,0 +1,142 @@ +/* +* 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>. +*/ + +/************************************************************* + * + * + * COMMENTS: + * + ************************************************************/ + +#include <stdlib.h> +#include <iostream> +#include "typefactory.hh" +#include "basetype.hh" +#include "tilemgr/tile.hh" +#include "tilemgr/transtile.hh" + + +#include "raslib/rminit.hh" +RMINITGLOBALS('C') + +#include "raslib/minterval.hh" +#include "raslib/sinterval.hh" +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" + +// perhaps used later +static char O2BenchDBName[] = "TestSMBase"; +static char O2BenchSchemaName[] = "TestSMSchema"; + +// static void ClearDB( d_Database &DB ); +extern char* myExecArgv0 = ""; + +/************************************************************* + * 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 ); + + + // create indexes and put them in TestMDDObjContainer + cout << " SplitTile..." << endl; + ta.begin(); + + static BaseType* bt = TypeFactory::mapType( "Short" ); + cout << "BaseType " << bt->getTypeName( ) << endl; + + r_Minterval tileDom = + r_Minterval(2) << r_Sinterval(0l,0l) << r_Sinterval(0l,99l); + //r_Minterval(2) << r_Sinterval(0l,9l) << r_Sinterval(0l,9l); + //("[0:9,0:9]"); + cout << "tileDom " << tileDom << endl; + r_Minterval BigTileDom = + r_Minterval(2) << r_Sinterval(0l,39l) << r_Sinterval(0l, 99l); + // ("[0:39,0:39]"); + cout << "BigTileDom " << BigTileDom << endl; + + unsigned long sz = bt->getSize( ) * BigTileDom.cell_count( ); + + char* cells = new char[sz]; + /* + for (int i = 0; i < sz ; i++ ) + { + if (i /2) cells[i] = char (i/10); + else cells[i] = 0; + } + */ + short* typedCells = (short*) cells; + unsigned typedSz = BigTileDom.cell_count( ); + for (int i = 0; i < typedSz; i++ ) + typedCells[i] = i; + + vector< Tile* >* tilesReturned; + TransTile* tile1Obj1 = new TransTile( BigTileDom, + (const BaseType* ) bt, + ( char*) cells, 1); + + cout << "Calling splitTile " << endl; + tilesReturned = tile1Obj1->splitTile( tileDom ); + cout << "Finished splitTile " << endl; + + + vector<Tile*>::iterator entryIt = tilesReturned->begin(); + + i = 0 ; + while (entryIt != tilesReturned->end()) + { + cout << "Tile " << i << endl; + (*entryIt)->printStatus(); + entryIt++; + i++; + } + + ta.commit(); + + delete[] cells; + + cout << endl << "Ending O2 session..." << endl; + database.close( ); + delete myAdmin; +} + diff --git a/tilemgr/test/test_tile.cc b/tilemgr/test/test_tile.cc new file mode 100644 index 0000000..18f5b97 --- /dev/null +++ b/tilemgr/test/test_tile.cc @@ -0,0 +1,979 @@ +#include "mymalloc/mymalloc.h" +/* +* 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>. +*/ + +/************************************************************* + * + * + * PURPOSE: + * creates Tiles and does ops + * + * + * COMMENTS: + * none + * + ************************************************************/ + +static const char rcsid[] = "@(#)cachetamgr,test_tile: $Id: test_tile.cc,v 1.26 2002/08/30 11:51:22 coman Exp $"; + +#include <stdlib.h> +#include <iostream> +#include <time.h> +#include "ulongtype.hh" +#include "booltype.hh" +#include "chartype.hh" +#include "structtype.hh" + +#ifndef bool + #include <bool.h> + #define OS_OMIT_BOOL +#endif + +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" +#include "tilemgr/perstile.hh" +#include "tilemgr/transtile.hh" +#include "typefactory.hh" +#include "raslib/rminit.hh" +#include "raslib/rmdebug.hh" + +// global variable for AdminIf because of O2 d_Session::begin() +extern char* myExecArgv0 = ""; + +RMINITGLOBALS('C') + +// perhaps used later +static char O2BenchDBName[256] = "NorbertBase"; +static char O2BenchSchemaName[256] = "NorbertSchema"; + +void +printTime() +{ + struct timespec cur_time; + clock_gettime(CLOCK_REALTIME, &cur_time); + + cout << asctime(localtime(&(cur_time.tv_sec))); +} + +void +testConstructors() +{ + // for for loops + unsigned long i; + // Tile used for tests + Tile* myTile; + // base types for tiles + BaseType* ulongType = TypeFactory::mapType("ULong"); + // domain of all Tiles + r_Minterval dom = + r_Minterval(3) << r_Sinterval(1L,10L) << r_Sinterval(11L,20L) + << r_Sinterval(5L,7L); + + // testing constructor executing section operation + // first create a tile with the whole domain + // char* containing data for one ULong Tile + char* tileData = (char*)mymalloc(dom.cell_count() * ulongType->getSize()); + for(i = 0; i < dom.cell_count() * ulongType->getSize(); i++) + { + if(i % ulongType->getSize() == 3 ) + tileData[i] = 10; + else + tileData[i] = 0; + } + + // transient with value + cout << "Creating transient ULong Tile containing 10 with domain " + << dom << ":" << endl; + myTile = new TransTile( dom, ulongType, tileData ); + + // now project it + 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(1l, 10l) << r_Sinterval(15l, 15l) + << r_Sinterval(5l, 7l); + + Tile* projectedTile = new TransTile(myTile, projDom, projSet); + + projectedTile->printStatus(); + + delete projSet; + delete projectedTile; +} + +void +testCompression() +{ + // for for loops + unsigned long i; + // Tile used for tests + Tile* myTile; + // Tile used for inititializing tiles with OP_IDENTITY + Tile* myContentTile; + // for contents of tiles + char* tileData; + // base types for tiles + BaseType* ulongType = TypeFactory::mapType("ULong"); + // domain of all Tiles + r_Minterval dom = + r_Minterval(3) << r_Sinterval(1L,10L) << r_Sinterval(11L,20L) + << r_Sinterval(5L,7L); + + cout << "Testing Constructors for Tiles" << endl; + cout << "------------------------------" << endl << endl; + + // ------------------------------------------------------------ + // uncompressed TransTile + // ------------------------------------------------------------ + + // char* containing data for one ULong Tile + tileData = (char*)mymalloc(dom.cell_count() * ulongType->getSize()); + for(i = 0; i < dom.cell_count() * ulongType->getSize(); i++) + { + if(i % ulongType->getSize() == 3 ) + tileData[i] = 10; + else + tileData[i] = 0; + } + + // transient with value + cout << "Creating transient ULong Tile containing 10 with domain " + << dom << ":" << endl; + myTile = new TransTile( dom, ulongType, tileData ); + + cout << " Printing created Tile: " << endl; + myTile->printStatus(); + + cout << " Deleting created Tile" << endl << endl; + delete myTile; + + // ------------------------------------------------------------ + // uncompressed PersTile + // ------------------------------------------------------------ + + // char* containing data for one ULong Tile + tileData = (char*)mymalloc(dom.cell_count() * ulongType->getSize()); + for(i = 0; i < dom.cell_count() * ulongType->getSize(); i++) + { + if(i % ulongType->getSize() == 3 ) + tileData[i] = 10; + else + tileData[i] = 0; + } + + // persistent with value + cout << "Creating persistent ULong Tile containing 10 with domain " + << dom << ":" << endl; + myTile = new PersTile( dom, ulongType, tileData ); + + cout << " Printing created Tile: " << endl; + myTile->printStatus(); + + cout << " Deleting created Tile" << endl << endl; + delete myTile; + + // ------------------------------------------------------------ + // uncompressed TransTile + // ------------------------------------------------------------ + + // char* containing data for one ULong Tile + tileData = (char*)mymalloc(dom.cell_count() * ulongType->getSize()); + for(i = 0; i < dom.cell_count() * ulongType->getSize(); i++) + { + if(i % ulongType->getSize() == 3 ) + tileData[i] = 10; + else + tileData[i] = 0; + } + + // transient with value + cout << "Creating transient ULong Tile containing 10 with domain " + << dom << ":" << endl; + myContentTile = new TransTile( dom, ulongType, tileData ); + myTile = new TransTile( dom, ulongType ); + myTile->execUnaryOp( Ops::OP_IDENTITY, dom, myContentTile, dom ); + + cout << " Printing created Tile: " << endl; + myTile->printStatus(); + + cout << " Deleting created Tile" << endl << endl; + delete myTile; + + // ------------------------------------------------------------ + // uncompressed PersTile + // ------------------------------------------------------------ + + // char* containing data for one ULong Tile + tileData = (char*)mymalloc(dom.cell_count() * ulongType->getSize()); + for(i = 0; i < dom.cell_count() * ulongType->getSize(); i++) + { + if(i % ulongType->getSize() == 3 ) + tileData[i] = 10; + else + tileData[i] = 0; + } + + // persistent with value + cout << "Creating persistent ULong Tile containing 10 with domain " + << dom << ":" << endl; + myContentTile = new PersTile( dom, ulongType, tileData ); + myTile = new PersTile( dom, ulongType, r_ZLib ); + myTile->execUnaryOp( Ops::OP_IDENTITY, dom, myContentTile, dom ); + + cout << " Printing created Tile: " << endl; + myTile->printStatus(); + + cout << " Deleting created Tile" << endl << endl; + delete myTile; + + // ------------------------------------------------------------ + // compressed TransTile + // ------------------------------------------------------------ + + // char* containing data for one ULong Tile + tileData = (char*)mymalloc(dom.cell_count() * ulongType->getSize()); + for(i = 0; i < dom.cell_count() * ulongType->getSize(); i++) + { + if(i % ulongType->getSize() == 3 ) + tileData[i] = 10; + else + tileData[i] = 0; + } + + // transient with value + cout << "Creating compressed transient ULong Tile containing 10 with domain " + << dom << ":" << endl; + myTile = new TransTile( dom, ulongType, r_ZLib ); + myTile->setContents(tileData); + + cout << " Physical Size: " << myTile->getPhysicalSize() << endl; + + cout << " Printing created Tile: " << endl; + myTile->printStatus(); + + cout << " Physical Size: " << myTile->getPhysicalSize() << endl; + + cout << " Deleting created Tile" << endl << endl; + delete myTile; + + // ------------------------------------------------------------ + // compressed PersTile + // ------------------------------------------------------------ + + // char* containing data for one ULong Tile + tileData = (char*)mymalloc(dom.cell_count() * ulongType->getSize()); + for(i = 0; i < dom.cell_count() * ulongType->getSize(); i++) + { + if(i % ulongType->getSize() == 3 ) + tileData[i] = 10; + else + tileData[i] = 0; + } + + // persistent with value + cout << "Creating compressed persistent ULong Tile containing 10 with domain " + << dom << ":" << endl; + myTile = new PersTile( dom, ulongType, r_ZLib ); + myTile->setContents(tileData); + + cout << " Physical Size: " << myTile->getPhysicalSize() << endl; + + cout << " Printing created Tile: " << endl; + myTile->printStatus(); + + cout << " Physical Size: " << myTile->getPhysicalSize() << endl; + + cout << " Deleting created Tile" << endl << endl; + delete myTile; + + // ------------------------------------------------------------ + // compressed TransTile + // ------------------------------------------------------------ + + // char* containing data for one ULong Tile + tileData = (char*)mymalloc(dom.cell_count() * ulongType->getSize()); + for(i = 0; i < dom.cell_count() * ulongType->getSize(); i++) + { + if(i % ulongType->getSize() == 3 ) + tileData[i] = 10; + else + tileData[i] = 0; + } + + // transient with value + cout << "Creating compressed transient ULong Tile containing 10 with domain " + << dom << ":" << endl; + myContentTile = new TransTile( dom, ulongType, tileData ); + myTile = new TransTile( dom, ulongType, r_ZLib ); + myTile->execUnaryOp( Ops::OP_IDENTITY, dom, myContentTile, dom ); + + cout << " Physical Size: " << myTile->getPhysicalSize() << endl; + + cout << " Printing created Tile: " << endl; + myTile->printStatus(); + + cout << " Physical Size: " << myTile->getPhysicalSize() << endl; + + cout << " Deleting created Tile" << endl << endl; + delete myTile; + + // ------------------------------------------------------------ + // compressed PersTile + // ------------------------------------------------------------ + + // char* containing data for one ULong Tile + tileData = (char*)mymalloc(dom.cell_count() * ulongType->getSize()); + for(i = 0; i < dom.cell_count() * ulongType->getSize(); i++) + { + if(i % ulongType->getSize() == 3 ) + tileData[i] = 10; + else + tileData[i] = 0; + } + + // persistent with value + cout << "Creating compressed persistent ULong Tile containing 10 with domain " + << dom << ":" << endl; + myContentTile = new PersTile( dom, ulongType, tileData ); + myTile = new PersTile( dom, ulongType, r_ZLib ); + myTile->execUnaryOp( Ops::OP_IDENTITY, dom, myContentTile, dom ); + + cout << " Physical Size: " << myTile->getPhysicalSize() << endl; + + cout << " Printing created Tile: " << endl; + myTile->printStatus(); + + cout << " Physical Size: " << myTile->getPhysicalSize() << endl; + + cout << " Deleting created Tile" << endl << endl; + delete myTile; +} + +void +testUnaryOps() +{ + // base types for tiles + BaseType* ulongType = TypeFactory::mapType("ULong"); + BaseType* boolType = TypeFactory::mapType("Bool");; + BaseType* charType = TypeFactory::mapType("Char");; + + // default cell for filling ULong Tiles + unsigned long longVal = 4294966295; + char* ulongCell = (char*)&longVal; + + // default cell for filling Bool Tiles + unsigned char boolVal = 1; + char* boolCell = (char*)&boolVal; + + // domain of all Tiles + r_Minterval dom = + r_Minterval(2) << r_Sinterval(1L,10L) << r_Sinterval(11L,20L); + + r_Minterval domOp = + r_Minterval(2) << r_Sinterval(1L,5L) << r_Sinterval(11L,15L); + + // domain of one dimensional result + r_Minterval res1D = + r_Minterval(2) << r_Sinterval(1L,10L); + + unsigned char charVal = 20; + char* charCell = (char*)&charVal; + + // Tiles used for tests + Tile* transULongTile; + Tile* transBoolTile; + Tile* persULongTile; + Tile* persBoolTile; + Tile* transCharTile; + Tile* transCharRes; + + cout << "Testing Unary Operations on Tiles" << endl; + cout << "---------------------------------" << endl << endl; + + // transient with value + cout << "Creating Tiles for Unary Operations with domain " + << dom << ":" << endl; + transULongTile = new TransTile( dom, ulongType, ulongCell ); + transBoolTile = new TransTile( dom, boolType, boolCell ); + persULongTile = new PersTile( dom, ulongType, ulongCell ); + persBoolTile = new PersTile( dom, boolType, boolCell ); + transCharTile = new TransTile( dom, charType, charCell ); + transCharRes = new TransTile( domOp, charType, boolCell ); + + + cout << "Operations with ULong:" << endl << endl; + + cout << "Carrying out NOT on TransTile (should be 1000)" << endl; + transULongTile->execUnaryOp(Ops::OP_NOT, dom, transULongTile, dom); + + cout << "Contents after operation: " << endl; + transULongTile->printStatus(); + + cout << "Carrying out IDENTITY on TransTile (should be 1000)" << endl; + transULongTile->execUnaryOp(Ops::OP_IDENTITY, dom, transULongTile, dom); + + cout << "Contents after operation: " << endl; + transULongTile->printStatus(); + + cout << "Carrying out NOT on PersTile (should be 1000)" << endl; + persULongTile->execUnaryOp(Ops::OP_NOT, dom, persULongTile, dom); + + cout << "Contents after operation: " << endl; + persULongTile->printStatus(); + + cout << "Carrying out IDENTITY on PersTile (should be 1000)" << endl; + persULongTile->execUnaryOp(Ops::OP_IDENTITY, dom, persULongTile, dom); + + cout << "Contents after operation: " << endl; + persULongTile->printStatus(); + + cout << "Operations with Bool:" << endl << endl; + + cout << "Carrying out NOT on TransTile (should be FALSE)" << endl; + transBoolTile->execUnaryOp(Ops::OP_NOT, dom, transBoolTile, dom); + + cout << "Contents after operation: " << endl; + transBoolTile->printStatus(); + + cout << "Carrying out IDENTITY on TransTile (should be FALSE)" << endl; + transBoolTile->execUnaryOp(Ops::OP_IDENTITY, dom, transBoolTile, dom); + + cout << "Contents after operation: " << endl; + transBoolTile->printStatus(); + + cout << "Carrying out NOT on PersTile (should be FALSE)" << endl; + persBoolTile->execUnaryOp(Ops::OP_NOT, dom, persBoolTile, dom); + + cout << "Contents after operation: " << endl; + persBoolTile->printStatus(); + + cout << "Carrying out IDENTITY on PersTile (should be FALSE)" << endl; + persBoolTile->execUnaryOp(Ops::OP_IDENTITY, dom, persBoolTile, dom); + + cout << "Contents after operation: " << endl; + persBoolTile->printStatus(); + + cout << "Carrying out IDENTITY on subset of char tile" << endl; + transCharRes->execUnaryOp(Ops::OP_IDENTITY, domOp, transCharTile, domOp); + + cout << "Contents after operation: " << endl; + transCharRes->printStatus(); + + // Trying to get more interesting values into tile + unsigned char val = 0; + for(int i = 0; i < transCharTile->getSize(); i++) { + transCharTile->setCell(i, (const char*)&val); + val++; + } + + cout << "Tile with more interesting values: " << endl; + transCharTile->printStatus(); + + cout << "Carrying out IDENTITY on subset of char tile" << endl; + transCharRes->execUnaryOp(Ops::OP_IDENTITY, domOp, transCharTile, domOp); + + cout << "Contents after operation: " << endl; + transCharRes->printStatus(); + + // Operation with result of a different dimensionality + + // domain of all Tiles + r_Minterval horSlice = + r_Minterval(2) << r_Sinterval(1L,10L) << r_Sinterval(15L,15L); + r_Minterval verSlice = + r_Minterval(2) << r_Sinterval(5L,5L) << r_Sinterval(11L,20L); + Tile* transRes1D = new TransTile( res1D, charType, charCell ); + + cout << "Carrying out IDENTITY to receive a 1D vertical slice" << endl; + transRes1D->execUnaryOp(Ops::OP_IDENTITY, res1D, transCharTile, horSlice); + + cout << "Contents after operation: " << endl; + transRes1D->printStatus(); + + cout << "Carrying out IDENTITY to receive a 1D horizontal slice" << endl; + transRes1D->execUnaryOp(Ops::OP_IDENTITY, res1D, transCharTile, verSlice); + + cout << "Contents after operation: " << endl; + transRes1D->printStatus(); + + cout << "Deleting created Tiles ..." << endl << endl; + + delete transULongTile; + delete transBoolTile; + delete persULongTile; + delete persBoolTile; + delete transCharRes; + delete transCharTile; + delete transRes1D; +} + +void +testBinaryOps() +{ + // base types for tiles + BaseType* ulongType = TypeFactory::mapType("ULong"); + BaseType* boolType = TypeFactory::mapType("Bool");; + + // default cell for filling ULong Tiles + unsigned long longVal = 1000; + char* ulongCell = (char*)&longVal; + + // default cell for filling Bool Tiles + unsigned char boolVal = 1; + char* boolCell = (char*)&boolVal; + + // domain of all Tiles + r_Minterval dom = + r_Minterval(3) << r_Sinterval(1L,10L) << r_Sinterval(11L,20L) + << r_Sinterval(5L,7L); + + // Tiles used for tests + Tile* transULongTile; + Tile* transBoolTile; + Tile* persULongTile; + Tile* persBoolTile; + Tile* constULongTile; + Tile* constBoolTile; + + cout << "Testing Binary Operations on Tiles" << endl; + cout << "---------------------------------" << endl << endl; + + cout << "Creating Tiles for Binary Operations with domain " + << dom << ":" << endl; + transULongTile = new TransTile( dom, ulongType, ulongCell ); + transBoolTile = new TransTile( dom, boolType, boolCell ); + persULongTile = new PersTile( dom, ulongType, ulongCell ); + persBoolTile = new PersTile( dom, boolType, boolCell ); + + cout << "Creating a TransTile for the two operands..." << endl; + TransTile ttileOp = TransTile(dom, ulongType, ulongCell); + + cout << "Contents: " << endl; + ttileOp.printStatus(); + + cout << "Creating a TransTile for the result..." << endl; + TransTile ttileRes = TransTile(dom, ulongType, ulongCell); + + cout << "Carrying out binary operation..." << endl; + ttileRes.execBinaryOp(Ops::OP_PLUS, dom, &ttileOp, dom, &ttileOp, dom); + + cout << "Contents after operation: " << endl; + ttileRes.printStatus(); + + // testing binary operation with Bool as result + long bval = 10000; + + // default cell for filling all Tiles + char* bvalCell = (char*)&bval; + + cout << "Creating a TransTile for the two operands..." << endl; + TransTile btileOp = TransTile(dom, ulongType, boolCell); + + cout << "Contents: " << endl; + btileOp.printStatus(); + + cout << "Creating a TransTile for the result..." << endl; + TransTile btileRes = TransTile(dom, boolType, boolCell); + + cout << "Carrying out binary operation..." << endl; + btileRes.execBinaryOp(Ops::OP_EQUAL, dom, &btileOp, dom, &btileOp, dom); + + cout << "Contents after operation: " << endl; + btileRes.printStatus(); + + cout << "Carrying out PLUS with TransTile and constant (should be 2000)" + << endl; + + transULongTile->execConstOp(Ops::OP_PLUS, dom, transULongTile, dom, + ulongCell, ulongType); + + cout << "Contents after operation: " << endl; + transULongTile->printStatus(); + + delete transULongTile; + delete transBoolTile; + delete persULongTile; + delete persBoolTile; + delete constULongTile; + delete constBoolTile; +} + +void +testCompTile() +{ +// // size of tiles in one direction +// const long testSize = 10; +// // base types for tiles +// BaseType* ulongType = TypeFactory::mapType("ULong"); + +// // default cell for filling ULong Tiles +// unsigned long longVal = 1000; +// char* ulongCell = (char*)&longVal; + +// // domain of all Tiles +// r_Minterval dom = +// r_Minterval(2) << r_Sinterval(1L,testSize) << r_Sinterval(1L,testSize); + +// // Tiles used for tests +// Tile* compTile1; +// Tile* compTile2; +// TransTile* transTile; + +// cout << "Testing CompTile" << endl; +// cout << "----------------" << endl << endl; + +// cout << "Creating Tiles with domain " +// << dom << ":" << endl; +// compTile1 = new CompTile( dom, ulongType, Tile::COMP_ZLIB, ulongCell ); +// compTile2 = new CompTile( dom, ulongType, Tile::COMP_ZLIB, ulongCell ); +// transTile = new TransTile( dom, ulongType, ulongCell ); + + // initialize with random values +// long val; +// for(int i = 0; i < testSize; i++) { +// for(int j = 0; j < testSize; j++) { +// val = (long)(LONG_MIN + ((double)LONG_MAX-LONG_MIN)*drand48()); +// compTile1->setCell(i*testSize+j, (char*)&val); +// val = (long)(LONG_MIN + ((double)LONG_MAX-LONG_MIN)*drand48()); +// compTile2->setCell(i*testSize+j, (char*)&val); +// } +// } + + // initialize with incrementing values. +// long val; +// for(int i = 0; i < testSize; i++) { +// for(int j = 0; j < testSize; j++) { +// val = i*testSize+j; +// compTile1->setCell(i*testSize+j, (char*)&val); +// compTile2->setCell(i*testSize+j, (char*)&val); +// } +// } + + // initialize with incrementing values, simulate struct +// long val; +// for(int i = 0; i < testSize; i++) { +// for(int j = 0; j < testSize; j += 3) { +// val = i*testSize+j; + +// compTile1->setCell(i*testSize+j, (char*)&val); +// if(j+1 < testSize) +// compTile1->setCell(i*testSize+j+1, (char*)&val+1000000); +// if(j+2 < testSize) +// compTile1->setCell(i*testSize+j+2, (char*)&val+2000000); + +// compTile2->setCell(i*testSize+j, (char*)&val); +// if(j+1 < testSize) +// compTile2->setCell(i*testSize+j+1, (char*)&val+1000000); +// if(j+2 < testSize) +// compTile2->setCell(i*testSize+j+2, (char*)&val+2000000); +// } +// } + +// cout << "Contents transTile: " << endl; +// if(transTile->getSize() <= 1000) +// transTile->printStatus(); + +// cout << "Contents compTile1: " << endl; +// if(transTile->getSize() <= 1000) +// compTile1->printStatus(); + +// cout << "Contents compTile2: " << endl; +// if(transTile->getSize() <= 1000) +// compTile2->printStatus(); + + // does only work if compress() is not protected. +// cout << "Compressing compTiles" << endl; +// ((CompTile*)compTile1)->compress(); +// ((CompTile*)compTile2)->compress(); + +// cout << "Carrying out binary operation..." << endl; +// transTile->execBinaryOp(Ops::OP_PLUS, dom, compTile1, dom, compTile2, dom); + +// cout << "Contents after operation: " << endl; +// if(transTile->getSize() <= 1000) +// transTile->printStatus(); + +// delete compTile1; +// delete compTile2; +// delete transTile; +} + +void +testOpsWithConsts() +{ + // base types for tiles + BaseType* ulongType = TypeFactory::mapType("ULong"); + BaseType* charType = TypeFactory::mapType("Char"); + + StructType* structType = new StructType("TestStruct", 2); + structType->addElement("Band1", "ULong"); + structType->addElement("Band2", "Char"); + + // default cell for filling ULong Tiles + unsigned long uLongVal = 1000; + char* ulongCell = (char*)&uLongVal; + // default cell for filling Char Tiles + unsigned char charVal = 112; + char* charCell = (char*)&charVal; + // default cell for filling Struct Tiles + unsigned char structCell[5]; + structCell[0] = ulongCell[0]; + structCell[1] = ulongCell[1]; + structCell[2] = ulongCell[2]; + structCell[3] = ulongCell[3]; + structCell[4] = charCell[0]; + + // domain of all Tiles + r_Minterval dom = + r_Minterval(2) << r_Sinterval(1L,5L) << r_Sinterval(1L,5L); + + // Tiles used for tests + cout << "Creating Tiles with domain " + << dom << ":" << endl; + Tile* charTile = new TransTile(dom, charType, charCell); + Tile* ulongTile = new TransTile(dom, ulongType, ulongCell); + Tile* structTile = new TransTile(dom, structType, (char*)structCell); + + cout << "Contents of Tiles: " << endl; + charTile->printStatus(); + ulongTile->printStatus(); + structTile->printStatus(); + + cout << "Result Type for Struct and Char: " + << (Ops::getResultType(Ops::OP_PLUS, structType, charType))->getTypeName() << endl; + + cout << "Carrying out binary operation with constant on structTile ..." + << endl; + structTile->execConstOp(Ops::OP_PLUS, dom, structTile, dom, charCell, + charType); + + cout << "Contents after operation: " << endl; + structTile->printStatus(); + + cout << "Carrying out binary operation with charTile on structTile ..." + << endl; + structTile->execBinaryOp(Ops::OP_PLUS, dom, structTile, dom, charTile, dom); + + cout << "Contents after operation: " << endl; + structTile->printStatus(); + + cout << "Carrying out binary operation with two structTiles ..." + << endl; + structTile->execBinaryOp(Ops::OP_PLUS, dom, structTile, dom, structTile, dom); + + cout << "Contents after operation: " << endl; + structTile->printStatus(); + + delete charTile; + delete ulongTile; + delete structTile; +} + +void +testCellAccess() +{ + // base types for tiles + BaseType* ulongType = TypeFactory::mapType("ULong"); + BaseType* charType = TypeFactory::mapType("Char"); + + // default cell for filling ULong Tiles + unsigned long uLongVal = 1000; + char* ulongCell = (char*)&uLongVal; + // default cell for filling Char Tiles + unsigned char charVal = 112; + char* charCell = (char*)&charVal; + + // domain of all Tiles + r_Minterval dom = + r_Minterval(2) << r_Sinterval(1L,10L) << r_Sinterval(1L,10L); + + // Tiles used for tests + cout << "Creating Tiles with domain " + << dom << ":" << endl; + Tile* charTile = new TransTile(dom, charType, charCell); + Tile* ulongTile = new TransTile(dom, ulongType, ulongCell); + + cout << "Accessing cell by point: "; + r_Point a = r_Point(2) << 5 << 5; + cout << (int)*(charTile->getCell(a)) << " " + << *(unsigned long*)ulongTile->getCell(a) << endl; + + delete charTile; + delete ulongTile; +} + +void +testScaleOp(void) +{ + r_Dimension dim = 2; + r_Dimension i; + BaseType* charType = TypeFactory::mapType("Char"); + r_Minterval dom = r_Minterval(dim); + r_Minterval nextDom = r_Minterval(dim); + r_Point origin(dim); + r_Point offset(dim); + unsigned long fullSize; + float scaleBy, incrementBy, eps; + + for (i=0; i<dim; i++) + { + origin[i] = (r_Range)0; + offset[i] = (r_Range)64; + dom << r_Sinterval(origin[i] + offset[i], (r_Range)511 + offset[i]); + nextDom << r_Sinterval((r_Range)512 + offset[i], (r_Range)1023 + offset[i]); + } + + fullSize = dom.cell_count(); + char *tileValues = (char*)mymalloc(fullSize); + Tile *charTile = new TransTile(dom, charType, tileValues, fullSize); + Tile *nextTile = new TransTile(dom, charType); + memset(charTile->getContents(), 0, dom.cell_count()); + + vector<float> scaleFactors(dim); + + incrementBy = 0.05; eps = 1e-2; + for (scaleBy=incrementBy; scaleBy <= 8-eps; scaleBy += incrementBy) + { + vector<float>::iterator iter = scaleFactors.begin(); + + cout << "Scale " << dom << " by " << scaleBy << endl; + + for (i=0; i<dim; i++, iter++) + *iter = scaleBy; + + r_Minterval scaledDom; + if (charTile->scaleGetDomain(dom, origin, scaleFactors, scaledDom)) + { + unsigned long scaledSize = scaledDom.cell_count(); + char *scaledValues = (char*)mymalloc(scaledSize); + Tile *scaledTile = new TransTile(scaledDom, charType, scaledValues, scaledSize); + + r_Minterval nextScaledDom; + if (nextTile->scaleGetDomain(nextDom, origin, scaleFactors, nextScaledDom)) + { + cout << "scaledDom: " << scaledDom << ", nextScaledDom: " << nextScaledDom << endl; + for (i=0; i<dim; i++) + { + if (nextScaledDom[i].low() != scaledDom[i].high() + 1) + { + cout << "NO SEAMLESS MATCH IN DIM " << i << '!' << endl; + } + } + } + + scaledTile->execScaleOp(charTile, dom, origin, scaleFactors); + + delete scaledTile; + } + else + { + cout << "Tile scaled to zero domain" << endl; + } + + incrementBy = 0.05 * (1 << (int)((scaleBy + eps) / 2)); + } + + delete charTile; + delete nextTile; +} + + +/************************************************************* + * 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[] ) +{ + int i; + + i = 1; + while (i < argc) + { + if (argv[i][0] == '-') + { + switch (argv[i][1]) + { + case 'd': + strcpy(O2BenchDBName, argv[++i]); break; + case 's': + strcpy(O2BenchSchemaName, argv[++i]); break; + case 'h': + cout << "Use: " << argv[0] << " [-d dbname -s schemaname -h]" << endl; + exit(0); + default: + break; + } + } + i++; + } + + // 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(); + + cout << "RManDebug: " << RManDebug << endl; + + // connect to the database + cout << "Connecting to database " << O2BenchDBName + << "..." << endl; + database.open( O2BenchDBName ); + + ta.begin(&database); + + cout << "These tests were done with:" << endl + << " " << rcsid << endl; + cout << "This protocol was created on:" << endl << " "; + printTime(); + cout << endl; + + // testConstructors(); + // testCompression(); + // testUnaryOps(); + // testBinaryOps(); + // testCompTile(); + // testOpsWithConsts(); + // testAlgebraOps(); + // testCellAccess(); + // testScaleOp(); + testScaleOp(); + + ta.commit(); + + cout << "Ending O2 session..." << endl; + database.close(); + delete myAdmin; +} diff --git a/tilemgr/test/tilertest.cc b/tilemgr/test/tilertest.cc new file mode 100644 index 0000000..3502ccc --- /dev/null +++ b/tilemgr/test/tilertest.cc @@ -0,0 +1,288 @@ +/* +* 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>. +*/ + +#include "mymalloc/mymalloc.h" +#ifdef EARLY_TEMPLATE +#define __EXECUTABLE__ +#ifdef __GNUG__ +#include "server/template_inst.hh" +#endif +#endif + +#include "raslib/rmdebug.hh" +#include "raslib/minterval.hh" +#include <iostream.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <vector.h> +#include <pair.h> +#include "tilemgr/transtile.hh" +#include "octettype.hh" +#include "tilemgr/tiler.hh" + +RMINITGLOBALS('C') + + +int +main(int argc, char *argv[]) + { + vector<r_Minterval> sourceDomains; + vector<r_Minterval> targetDomains; + vector<r_Minterval> retvalDomains; + vector<r_Minterval>::iterator sourceDIt; + vector<r_Minterval>::iterator targetDIt; + vector<r_Minterval>::iterator retvalDIt; + + + vector<Tile*>::iterator sourceIt; + vector<Tile*>::iterator targetIt; + vector<Tile*>::iterator retvalIt; + + r_Minterval targetDom("[0:50,0:50]"); + r_Minterval targetInt1("[0:10,0:10]"); + r_Minterval targetInt2("[15:25,10:20]"); + r_Minterval targetInt3("[15:25,21:30]"); + r_Minterval targetInt4("[15:25,31:40]"); + r_Minterval targetInt5("[40:50,40:50]"); + r_Minterval targetInt6("[35:41,25:35]"); + r_Minterval targetInt7("[28:32,28:32]"); + r_Minterval targetInt8("[40:40,0:10]"); + r_Minterval targetInt9("[40:50,11:11]"); + r_Minterval targetInt10("[35:35,0:10]"); + r_Minterval targetInt11("[30:34,10:10]"); + OctetType* o = new OctetType(); + + char* cont1 = 0; + char* cont2 = 0; + char* cont3 = 0; + char* cont4 = 0; + char* cont5 = 0; + char* cont6 = 0; + char* cont7 = 0; + char* cont8 = 0; + char* cont9 = 0; + char* cont10 = 0; + char* cont11 = 0; + char* outc = 0; + cont1 = (char*)mymalloc(500); + cont2 = (char*)mymalloc(500); + cont3 = (char*)mymalloc(500); + cont4 = (char*)mymalloc(500); + cont5 = (char*)mymalloc(500); + cont6 = (char*)mymalloc(500); + cont7 = (char*)mymalloc(500); + cont8 = (char*)mymalloc(500); + cont9 = (char*)mymalloc(500); + cont10 = (char*)mymalloc(500); + cont11 = (char*)mymalloc(500); + outc = (char*)mymalloc(101*101); + memset(cont1, 1, 500); + memset(cont2, 2, 500); + memset(cont3, 3, 500); + memset(cont4, 4, 500); + memset(cont5, 5, 500); + memset(cont6, 6, 500); + memset(cont7, 7, 500); + memset(cont8, 8, 500); + memset(cont9, 9, 500); + memset(cont10, 10, 500); + memset(cont11, 11, 500); + memset(outc, 0, 3500); + TransTile output(targetDom, o, outc); + + TransTile* ttile1 = new TransTile(targetInt1, (const BaseType*)o, cont1); + TransTile* ttile2 = new TransTile(targetInt2, (const BaseType*)o, cont2); + TransTile* ttile3 = new TransTile(targetInt3, (const BaseType*)o, cont3); + TransTile* ttile4 = new TransTile(targetInt4, (const BaseType*)o, cont4); + TransTile* ttile5 = new TransTile(targetInt5, (const BaseType*)o, cont5); + TransTile* ttile6 = new TransTile(targetInt6, (const BaseType*)o, cont6); + TransTile* ttile7 = new TransTile(targetInt7, (const BaseType*)o, cont7); + TransTile* ttile8 = new TransTile(targetInt8, (const BaseType*)o, cont8); + TransTile* ttile9 = new TransTile(targetInt9, (const BaseType*)o, cont9); + TransTile* ttile10 = new TransTile(targetInt10, (const BaseType*)o, cont10); + TransTile* ttile11 = new TransTile(targetInt11, (const BaseType*)o, cont11); + + r_Minterval sourceDom("[5:45,5:45]"); + r_Minterval sourceInt1("[5:10,5:10]"); + r_Minterval sourceInt2("[15:25,12:45]"); + r_Minterval sourceInt3("[30:45,30:38]"); + r_Minterval sourceInt4("[40:45,40:45]"); + r_Minterval sourceInt5("[30:45,25:28]"); + r_Minterval sourceInt6("[39:41,9:11]"); + r_Minterval sourceInt7("[34:36,9:11]"); + + char* scont1 = 0; + char* scont2 = 0; + char* scont3 = 0; + char* scont4 = 0; + char* scont5 = 0; + char* scont6 = 0; + char* scont7 = 0; + scont1 = (char*)mymalloc(500); + scont2 = (char*)mymalloc(500); + scont3 = (char*)mymalloc(500); + scont4 = (char*)mymalloc(500); + scont5 = (char*)mymalloc(500); + scont6 = (char*)mymalloc(500); + scont7 = (char*)mymalloc(500); + memset(scont1, 21, 500); + memset(scont2, 22, 500); + memset(scont3, 23, 500); + memset(scont4, 24, 500); + memset(scont5, 25, 500); + memset(scont6, 26, 500); + memset(scont7, 27, 500); + TransTile* stile1 = new TransTile(sourceInt1, (const BaseType*)o, scont1); + TransTile* stile2 = new TransTile(sourceInt2, (const BaseType*)o, scont2); + TransTile* stile3 = new TransTile(sourceInt3, (const BaseType*)o, scont3); + TransTile* stile4 = new TransTile(sourceInt4, (const BaseType*)o, scont4); + TransTile* stile5 = new TransTile(sourceInt5, (const BaseType*)o, scont5); + TransTile* stile6 = new TransTile(sourceInt6, (const BaseType*)o, scont6); + TransTile* stile7 = new TransTile(sourceInt7, (const BaseType*)o, scont7); + + vector<Tile*> sourceTiles; + sourceTiles.push_back(stile1); + sourceTiles.push_back(stile2); + sourceTiles.push_back(stile3); + sourceTiles.push_back(stile4); + sourceTiles.push_back(stile5); + sourceTiles.push_back(stile6); + sourceTiles.push_back(stile7); + + vector<Tile*> targetTiles; + targetTiles.push_back(ttile1); + targetTiles.push_back(ttile2); + targetTiles.push_back(ttile3); + targetTiles.push_back(ttile4); + targetTiles.push_back(ttile5); + targetTiles.push_back(ttile6); + targetTiles.push_back(ttile7); + targetTiles.push_back(ttile8); + targetTiles.push_back(ttile9); + targetTiles.push_back(ttile10); + targetTiles.push_back(ttile11); + + vector<Tile*> retval; + + unsigned long targetTileArea = 0; + unsigned long sourceTileArea = 0; + unsigned long targetTileDomain = 0; + unsigned long updatedArea = 0; + bool intersection = false; + + r_Minterval intersectUpdateDomain; + + bool computed = true; + + cout << "Target Tiles" << endl; + for (targetIt = targetTiles.begin(); targetIt != targetTiles.end(); targetIt++) + cout << (*targetIt)->getDomain() << endl; + cout << endl << "Source Tiles" << endl; + for (sourceIt = sourceTiles.begin(); sourceIt != sourceTiles.end(); sourceIt++) + cout << (*sourceIt)->getDomain() << endl; + cout << endl; + cout << "Checking if only update, insert or update and insert" << endl; + + for (sourceIt = sourceTiles.begin(); sourceIt != sourceTiles.end(); sourceIt++) + { + intersection = false; + sourceTileArea = sourceTileArea + (*sourceIt)->getDomain().cell_count(); + cout << "SourceDomain " << (*sourceIt)->getDomain() << " source area is " << sourceTileArea << endl; + for (targetIt = targetTiles.begin(); targetIt != targetTiles.end(); targetIt++) + { + if (computed) + { + targetTileArea = targetTileArea + (*targetIt)->getDomain().cell_count(); + cout << "Target Tile " << (*targetIt)->getDomain() << " area " << targetTileArea << endl; + } + + if( (*sourceIt)->getDomain().intersects_with( (*targetIt)->getDomain() ) ) + { + cout << "Intersection" << endl; + intersection = true; + intersectUpdateDomain = (*sourceIt)->getDomain().create_intersection( (*targetIt)->getDomain() ); + cout << "Updated " << intersectUpdateDomain << " on source " << (*sourceIt)->getDomain() << " and target " << (*targetIt)->getDomain() << endl; + updatedArea = updatedArea + intersectUpdateDomain.cell_count(); + (*targetIt)->execUnaryOp(Ops::OP_IDENTITY, intersectUpdateDomain, *sourceIt, intersectUpdateDomain ); + } + } + if (!intersection) + { + // Create a new persistent tile, copy the transient data, + // and insert it into the target mdd object. + cout << "No Intersection" << endl; + TransTile* newPersTile = new TransTile((*sourceIt)->getDomain(), o, (*sourceIt)->getDataFormat()); + newPersTile->execUnaryOp(Ops::OP_IDENTITY, (*sourceIt)->getDomain(), *sourceIt, (*sourceIt)->getDomain()); + //targetObj->insertTile( newPersTile ); + updatedArea = updatedArea + (*sourceIt)->getDomain().cell_count(); + } + computed = false; + } + cout << "Source Domain " << sourceDom << " has area " << sourceDom.cell_count() << endl; + cout << "Source Tile Area " << sourceTileArea << endl; + cout << "Target Tile Area " << targetTileArea << endl; + cout << "Updated Area " << updatedArea << endl << endl; + // insert the tile + + if (sourceTileArea <= updatedArea) + { + cout << "and all sources were used" << endl; + } + else { + cout << "and there are still some cells to do" << endl << endl; + + for (retvalIt = sourceTiles.begin(); retvalIt != sourceTiles.end(); retvalIt++) + { + sourceDomains.push_back((*retvalIt)->getDomain()); + } + + for (retvalIt = targetTiles.begin(); retvalIt != targetTiles.end(); retvalIt++) + { + targetDomains.push_back((*retvalIt)->getDomain()); + } + + r_Tiler tiler(sourceDomains, targetDomains); + tiler.split(); + tiler.removeCoveredDomains(); + tiler.removeDoubleDomains(); + retvalDomains = tiler.getTiledDomains(); + cout << "we have now" << endl; + for (retvalDIt = retvalDomains.begin(); retvalDIt != retvalDomains.end(); retvalDIt++) + cout << (*retvalDIt) << endl; + tiler.mergeDomains(); + retvalDomains = tiler.getTiledDomains(); + cout << "we have now" << endl; + for (retvalDIt = retvalDomains.begin(); retvalDIt != retvalDomains.end(); retvalDIt++) + cout << (*retvalDIt) << endl; + vector<Tile*> t = tiler.generateTransTiles(sourceTiles); + for (retvalIt = targetTiles.begin(); retvalIt != targetTiles.end(); retvalIt++) + output.execUnaryOp(Ops::OP_IDENTITY, (*retvalIt)->getDomain(), (*retvalIt), (*retvalIt)->getDomain()); + for (retvalIt = t.begin(); retvalIt != t.end(); retvalIt++) + output.execUnaryOp(Ops::OP_IDENTITY, (*retvalIt)->getDomain(), (*retvalIt), (*retvalIt)->getDomain()); + RManDebug = 30; + output.printStatus(cout); + RManDebug = 1; + } + } + |