X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/5adde094541b74abf79a902dc4b63141d281b818..66dd4bd348bacf6b43b59c2b349a913b722c6504:/configcache.h?ds=inline diff --git a/configcache.h b/configcache.h index 3227233..727d1bd 100644 --- a/configcache.h +++ b/configcache.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -12,6 +13,10 @@ #include #include +#define CACHE_MODE_DISABLED 0 +#define CACHE_MODE_READ 1 +#define CACHE_MODE_FULL 2 + using namespace std; struct parameter{ @@ -19,23 +24,44 @@ struct parameter{ double val; }; +struct infiledesc { + string filename; + int nequi; + int nskip; + bool extended; +}; + class configcache{ public: ~configcache(); - configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize); - bool readConfig(); - void writeConfig(); + configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, + const int& cachemode=CACHE_MODE_FULL, ostream *_log=NULL); + void readConfig(bool *readnewconfig, int *nequileft, vector *excludeFileHashes=NULL); + void writeConfig(int actnequi); void addPara(const string& parid, const double& val=0); void setPara(const string& parid, const double& value); - - private: + void writeHeader(const string& headerid, const char *header, long unsigned int size, int actnequi); + void * getHeader(const string& headerid); + string getOutFileName() { return outFileName.str(); } + string getInFileName() { return DATADIR + "/" + openFileDesc.filename; } + static unsigned long hash(const string& str); + void closeInFile() { inFile.close(); } + int inFilesLeft() { return inFiles.size(); } + char* getConfigMem() { return configMem; } + int getConfigSize() { return configSize; } + bool isOutFileOpen () { return outFile.is_open(); } void finishOutFile(); + + private: + ostream* log; + infiledesc openFileDesc; int getParIndex(const string& parid); int NEQUI; int NSKIP; string DATADIR; string CACHEID; - string getFileId(const bool& shortid=false); + int MODE; + string getFileId(int actnequi, const bool& shortid=false); ofstream outFile; ifstream inFile; @@ -57,11 +83,33 @@ class configcache{ void fetchDataFiles(); - bool isValidInFile(const string& infile); + bool isValidInFile(const string& infile, infiledesc *filedesc); - vector inFiles; + vector inFiles; vector Paras; + + int readDataToMem(char *tmpData, long unsigned int dataSize); + + void openOutFile(int actnequi); + + int readHeader(); + + bool headerWritten; + + int readFullBlock(char *tmpData, long unsigned int dataSize); + + vector< pair > headerStore; + + void deleteHeaderStore(); + + bool readAllHeaders(); + + vector::iterator getNextInfile(vector *excludeFileHashes); + + int nequileft_internal; + + bool doVirtualEquilibration, firstUsedConfig; }; #endif