]> git.treefish.org Git - phys/latlib.git/blob - configcache.h
Changed hashed parastring cachfilename postfix to sdat and made configcache backward...
[phys/latlib.git] / configcache.h
1 #ifndef CONFIGCACHE_H
2 #define CONFIGCACHE_H
3
4 #include <vector>
5 #include <string>
6 #include <fstream>
7 #include <sstream>
8 #include <ostream>
9
10 #define CACHE_MODE_OO 0
11 #define CACHE_MODE_RO 1
12 #define CACHE_MODE_WO 2
13 #define CACHE_MODE_RW 3
14
15 using namespace std;
16
17 struct parameter{
18   string id;
19   double val;
20 };
21
22 struct infiledesc {
23   string filename;
24   int nequi;
25   int nskip;
26   bool extended;
27   bool superextended;
28 };
29
30 class configcache{
31  public:
32   ~configcache();
33   configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, 
34               const int& cachemode=CACHE_MODE_RW, ostream *_log=NULL);
35   void readConfig(bool *readnewconfig, int *nequileft, vector<unsigned long> *excludeFileHashes=NULL);
36   void writeConfig(int actnequi);
37   void addPara(const string& parid, const double& val=0);
38   void setPara(const string& parid, const double& value);
39   void writeHeader(const string& headerid, const char *header, long unsigned int size, int actnequi);
40   void * getHeader(const string& headerid);
41   string getOutFileName() { return outFileName.str(); }
42   string getInFileName() { return DATADIR + "/" + openFileDesc.filename; }
43   static unsigned long hash(const string& str);
44   void closeInFile() { inFile.close(); }
45   int inFilesLeft() { return inFiles.size(); }
46   char* getConfigMem() { return configMem; }
47   int getConfigSize() { return configSize; }
48   bool isOutFileOpen () { return outFile.is_open(); }
49   void finishOutFile();
50
51  private:
52   struct iobuffers;
53   iobuffers *ioBuffers;
54
55   ostream* log;
56   infiledesc openFileDesc;
57   int getParIndex(const string& parid);
58   int NEQUI;
59   int NSKIP;
60   string DATADIR;
61   string CACHEID;
62   int MODE;
63   string getFileId(int actnequi, const bool& superextended=true, const bool& shortid=false);
64
65   ofstream outFile;
66   ifstream inFile;
67
68   stringstream outFileName;
69
70   int readnum;
71
72   int inSize;
73
74   int configSize;
75   char *configMem;
76   char *tmpConfig;
77
78   bool refetchDataFiles;
79
80   void fetchDataFiles();
81   
82   bool isValidInFile(const string& infile, infiledesc *filedesc);
83
84   vector<infiledesc> inFiles;
85
86   vector<parameter> Paras;
87
88   int readDataToMem(char *tmpData, long unsigned int dataSize);
89
90   void openOutFile(int actnequi);
91
92   int readHeader();
93
94   bool headerWritten;
95
96   int readFullBlock(char *tmpData, long unsigned int dataSize);
97
98   vector< pair<unsigned long, void *> > headerStore;
99
100   void deleteHeaderStore();
101
102   bool readAllHeaders();
103
104   vector<infiledesc>::iterator getNextInfile(vector<unsigned long> *excludeFileHashes);
105
106   int nequileft_internal;
107
108   bool doVirtualEquilibration, firstUsedConfig;
109
110   string paraString();
111 };
112
113 #endif