Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

DBCacheTester.hpp

Go to the documentation of this file.
00001 #ifndef DBCacheTester_HPP
00002 #define DBCacheTester_HPP
00003 
00008 #include "common.hpp"
00009 #include "common/log.h"
00010 #include "io/FDRepr.hpp"
00011 #include "io/codec/decoder/normal/CacheNormalDecoder.hpp"
00012 #include "io/codec/coder/Coder.hpp"
00013 #include <vector>
00014 
00015 
00016 
00017 
00018 class DBCacheTester
00019 {
00020    public:
00021       void usageDBCacheTester();
00022       void doTest(int argc, char *argv[] );
00023    private:
00024       typedef CacheNormalDecoder<> D;
00025 
00026       template <class CACHER> void selectMode(
00027          char* codemode, char* file_name, int nr_of_traversals,
00028          item_t largest_item, D* decoder,
00029          std::vector< std::pair<counter_t, item_t> >* freq_items_with_counters);
00030 
00031       template <class CACHER, CodeMode MODE> void cacheDatabase(
00032          char* file_name, int nr_of_traversals, item_t largest_item, D* decoder,
00033          std::vector< std::pair<counter_t, item_t> >* freq_items_with_counters);
00034 
00035 };
00036 
00037 
00038 template <class CACHER> void DBCacheTester::selectMode(
00039    char* codemode, char* file_name, int nr_of_traversals,
00040    item_t largest_item, D* decoder,
00041    std::vector< std::pair<counter_t, item_t> >* freq_items_with_counters)
00042 {
00043    if( strcmp(codemode, "ASC") ==0 )
00044    {
00045       log_info(0,"Ascending order is chosen.");
00046       cacheDatabase<CACHER, ASC>( file_name, nr_of_traversals, 
00047                                   largest_item, decoder,
00048                                   freq_items_with_counters);
00049    }
00050    else if( strcmp(codemode, "DESC") ==0 )
00051    {
00052       log_info(0,"Descending order is chosen.");
00053       cacheDatabase<CACHER, DESC>( file_name, nr_of_traversals, 
00054                                    largest_item, decoder,
00055                                    freq_items_with_counters);
00056    }
00057    else if( strcmp(codemode, "NOCARE") ==0 )
00058    {
00059       log_info(0,"Order is not going to be modified.");
00060       cacheDatabase<CACHER, NOCARE>( file_name, nr_of_traversals, 
00061                                      largest_item, decoder,
00062                                      freq_items_with_counters);
00063    }
00064    else
00065       usageDBCacheTester();
00066 }
00067 
00068 
00069 template <class CACHER, CodeMode MODE> void DBCacheTester::cacheDatabase(
00070    char* file_name, int nr_of_traversals, 
00071    item_t largest_item, D* decoder,
00072    std::vector< std::pair<counter_t, item_t> >* freq_items_with_counters)
00073 {
00074    typename CACHER::params_t par;
00075    par.file_name = file_name;
00076    par.mode=FileReprBase::READ;
00077    par.largest_item = largest_item;
00078    par.decoder = decoder;
00079    par.freq_items_with_counters = freq_items_with_counters;
00080    par.codemode = MODE;
00081 
00082    log_info(0,"Doing database cacher.");
00083    CACHER t_r(&par);
00084    std::cout<<"\t\t\t\t\tDone!"<<std::endl;
00085 
00086    std::cout<<"Traversing through the cached transactions "
00087             << nr_of_traversals<<" times."<<std::endl;
00088    std::vector<item_t> transaction;
00089    counter_t multiplicity;
00090    for(int trav_index = 1; trav_index <= nr_of_traversals; ++trav_index)
00091    {
00092       std::cout<<trav_index<<". travel"<<std::flush;
00093       t_r.rewind();
00094       while( (multiplicity = t_r.nextTransactionBIS(
00095                  transaction)) !=0 )
00096       {
00097          // uncomment the following lines if you want to see the output
00098          decoder->writeItemsetAndCounter( 
00099             transaction.begin(), transaction.end(), multiplicity );
00100       }
00101       std::cout<<"\t\t\t\t\t\tDone!"<<std::endl;
00102    }
00103 }
00104 
00105 #endif

Generated on Sun Sep 17 17:50:38 2006 for FIM environment by  doxygen 1.4.4