From: Alex Schmidt Date: Wed, 20 Mar 2013 11:54:11 +0000 (+0100) Subject: hypercache now working. X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/31dc8788f9711670917daaa5cc544d0d87ec3afc hypercache now working. --- diff --git a/.gitignore b/.gitignore index ec81062..2a0b23c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ Makefile neigh_test cubelooks_test culooks_test +hypercache_test diff --git a/CMakeLists.txt b/CMakeLists.txt index cc76100..45b566d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,3 +25,6 @@ target_link_libraries(neigh_test lat_neigh) add_executable(culooks_test culooks_test.cpp) target_link_libraries(culooks_test lat_culooks) + +add_executable(hypercache_test hypercache_test.cpp) +target_link_libraries(hypercache_test lat_hypercache) \ No newline at end of file diff --git a/configcache.cpp b/configcache.cpp index 62b9fdb..fe7bd78 100644 --- a/configcache.cpp +++ b/configcache.cpp @@ -228,7 +228,8 @@ void configcache::openOutFile() time_t secstamp = time(NULL); outFileName.str(""); - outFileName << DATADIR << "/" << secstamp << "_" << getFileId() << "_.edat.tmp"; + outFileName << DATADIR << "/" << secstamp << "_" << getFileId() << "_.edat.tmp"; + outFile.open( outFileName.str().c_str(), std::ios::binary ); outBuffer = new boost::iostreams::filtering_ostreambuf; diff --git a/hypercache.cpp b/hypercache.cpp index 8fcc609..7e0f0e5 100644 --- a/hypercache.cpp +++ b/hypercache.cpp @@ -1,10 +1,11 @@ #include "hypercache.h" -hypercache::defaults *hypercache::Defaults = NULL; configcache *hypercache::O = NULL; configcache *hypercache::C = NULL; +vector hypercache::delayedParaAdd; +vector hypercache::delayedParaSet; -void hypercache::initCache(configcache *cache, +void hypercache::initCache(configcache **cache, const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, const int& cachemode, writeout *out_a) { @@ -13,15 +14,7 @@ void hypercache::initCache(configcache *cache, if (O == NULL || C == NULL) allInitBefore = false; - cache = new configcache(cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, out_a); - - if (Defaults == NULL) { - Defaults = new defaults; - Defaults->nequi = nequi; - Defaults->nskip = nskip; - Defaults->datadir = datadir; - Defaults->out = out_a; - } + *cache = new configcache(cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, out_a); if (O != NULL && C != NULL && !allInitBefore) { for (vector::iterator parit=delayedParaAdd.begin(); parit != delayedParaAdd.end(); ++parit) { @@ -35,17 +28,6 @@ void hypercache::initCache(configcache *cache, } } -void hypercache::initCache(configcache *cache, const string& subdir, - const string& cacheid, char **configmem, const int& configMemSize, const int& cachemode) { - if (Defaults == NULL) { - cerr << "Defaults were not initialized prior to short initialization!" << endl; - exit(1); - } - - initCache(cache, cacheid, Defaults->nequi, Defaults->nskip, Defaults->datadir + "/" + subdir, - configmem, configMemSize, cachemode, Defaults->out); -} - void hypercache::addPara(const string& parid, const double& val) { if (O == NULL || C == NULL) { para newpara; @@ -71,3 +53,8 @@ void hypercache::setPara(const string& parid, const double& val) { C->setPara(parid, val); } } + +void hypercache::finalize() { + delete C; + delete O; +} diff --git a/hypercache.h b/hypercache.h index 53e0f67..6997d82 100644 --- a/hypercache.h +++ b/hypercache.h @@ -11,18 +11,11 @@ class hypercache { public: static void initO(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL, writeout *out_a=NULL) { - initCache(O, cacheid, nequi, nskip, datadir+"/o", configmem, configMemSize, cachemode, out_a); + initCache(&O, cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, out_a); } static void initC(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL, writeout *out_a=NULL) { - initCache(C, cacheid, nequi, nskip, datadir+"/c", configmem, configMemSize, cachemode, out_a); - } - - static void initO(const string& cacheid, char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL) { - initCache(O, "o", cacheid, configmem, configMemSize, cachemode); - } - static void initC(const string& cacheid, char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL) { - initCache(C, "c", cacheid, configmem, configMemSize, cachemode); + initCache(&C, cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, out_a); } static void addPara(const string& parid, const double& val=0); @@ -35,29 +28,24 @@ class hypercache { static void *getHeaderO(const string& headerid) { O->getHeader(headerid); } static void writeHeaderC(const string& headerid, char *header, long unsigned int size) { C->writeHeader(headerid, header, size); } static void *getHeaderC(const string& headerid) { C->getHeader(headerid); } + + static void finalize(); private: - struct defaults{ - int nequi; - int nskip; - string datadir; - writeout *out; - }; struct para{ string parid; double val; }; - static void initCache(configcache *cache, + static void initCache(configcache **cache, const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL, writeout *out_a=NULL); - static void initCache( configcache *cache, const string& subdir, + static void initCache( configcache **cache, const string& cacheid, char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL); - + static configcache *O; static configcache *C; - static defaults *Defaults; static vector delayedParaAdd; static vector delayedParaSet; }; diff --git a/hypercache_test.cpp b/hypercache_test.cpp new file mode 100644 index 0000000..388ab0a --- /dev/null +++ b/hypercache_test.cpp @@ -0,0 +1,16 @@ +#include "hypercache.h" + +#include + +using namespace std; + +int main() { + char *test; + char *test2; + + hypercache::initO("hallo", 100, 10, "", &test, sizeof(int), CACHE_MODE_READ); + + hypercache::addPara("kappa", 1); + + hypercache::readO(); +}