return NULL;
}
-bool configcache::readConfig()
-{
+bool configcache::readConfig(vector<string> *excludefiles)
+{
if(DATADIR == "" || MODE == CACHE_MODE_DISABLED) return false;
if(refetchDataFiles){
if( (!inFile.is_open()) && inFiles.size() == 0 ) return false;
while( (!inFile.is_open()) && inFiles.size() > 0 ) {
- if(out) *out->log << "CCACHE: Opening dat-file: " << inFiles.back().filename << endl << flush;
+ bool excludethisfile=false;
openFileDesc = inFiles.back();
- inFile.open( (DATADIR + "/" + inFiles.back().filename).c_str(), std::ios::binary );
- inFiles.pop_back();
+ if (excludefiles != NULL)
+ for (vector<string>::iterator exit = excludefiles->begin(); exit != excludefiles->end(); ++exit)
+ if ( *exit == inFiles.back().filename ) {
+ excludethisfile = true;
+ break;
+ }
+
+ if ( ! excludethisfile ) {
+ if(out) *out->log << "CCACHE: Opening dat-file: " << inFiles.back().filename << endl << flush;
+ inFile.open( (DATADIR + "/" + inFiles.back().filename).c_str(), std::ios::binary );
+ }
+ else
+ if(out) *out->log << "CCACHE: Excluded dat-file: " << inFiles.back().filename << endl << flush;
+
+ inFiles.pop_back();
+
if( !inFile.is_open() ) continue;
inBuffer = new boost::iostreams::filtering_istreambuf;
outBuffer->push(outFile);
}
-void configcache::writeHeader(const string& headerid, char *header, long unsigned int size) {
+void configcache::writeHeader(const string& headerid, const char *header, long unsigned int size) {
unsigned long headeridhash;
if( DATADIR == "" || MODE < 2 ) return;
~configcache();
configcache(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);
- bool readConfig();
+ bool readConfig(vector<string> *excludefiles=NULL);
void writeConfig();
void addPara(const string& parid, const double& val=0);
void setPara(const string& parid, const double& value);
- void writeHeader(const string& headerid, char *header, long unsigned int size);
+ void writeHeader(const string& headerid, const char *header, long unsigned int size);
void * getHeader(const string& headerid);
-
+ string getOutFileName() { return outFileName.str(); }
+ string getInFileName() { return DATADIR + "/" + openFileDesc.filename; }
+ static unsigned long hash(const string& str);
+
private:
infiledesc openFileDesc;
void finishOutFile();
int readFullBlock(char *tmpData, long unsigned int dataSize);
- static unsigned long hash(const string& str);
-
vector< pair<unsigned long, void *> > headerStore;
void deleteHeaderStore();
configcache *hypercache::C = NULL;
vector<hypercache::para> hypercache::delayedParaAdd;
vector<hypercache::para> hypercache::delayedParaSet;
+string hypercache::activeCFile = "";
+vector<string> hypercache::parentConfigs;
+writeout *hypercache::out = NULL;
void hypercache::initCache(configcache **cache,
const string& cacheid, const int& nequi, const int& nskip, const string& datadir,
if (O == NULL || C == NULL)
allInitBefore = false;
+ if ( out_a != NULL )
+ out = out_a;
+
*cache = new configcache(cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, out_a);
if (O != NULL && C != NULL && !allInitBefore) {
else {
O->setPara(parid, val);
C->setPara(parid, val);
+ activeCFile = "";
+ parentConfigs.clear();
}
}
delete C;
delete O;
}
+
+string hypercache::fileOfPath(const string& dressedfile) {
+ return dressedfile.substr(dressedfile.find_last_of("\\/")+1);
+}
+
+bool hypercache::readC() {
+ bool readret;
+
+ if ( readret = C->readConfig(&parentConfigs) )
+ activeCFile = fileOfPath(C->getInFileName());
+ else
+ activeCFile = "";
+
+ return readret;
+}
+
+void hypercache::writeC() {
+ C->writeConfig();
+ activeCFile = fileOfPath( C->getOutFileName().substr( 0, C->getOutFileName().length()-4 ) );
+}
+
+void hypercache::writeO() {
+ if ( activeCFile != "" )
+ O->writeHeader("concurrent_cfile", activeCFile.c_str(), (activeCFile.length()+1)*sizeof(char));
+
+ O->writeConfig();
+}
+
+bool hypercache::readO() {
+ bool readret;
+
+ if ( readret = O->readConfig() ) {
+ char *parentconfig = (char*)O->getHeader("concurrent_cfile");
+ if ( parentconfig != NULL )
+ addParentConfig(parentconfig);
+ }
+
+ return readret;
+}
+
+void hypercache::addParentConfig(const char* parentconfig) {
+ for (vector<string>::iterator parit = parentConfigs.begin(); parit != parentConfigs.end(); ++parit)
+ if ( *parit == parentconfig )
+ return;
+
+ parentConfigs.push_back(parentconfig);
+}
static void addPara(const string& parid, const double& val=0);
static void setPara(const string& parid, const double& value);
- static bool readO() { return O->readConfig(); }
- static bool readC() { return C->readConfig(); }
- static void writeO() { O->writeConfig(); }
- static void writeC() { C->writeConfig(); }
+ static bool readO();
+ static bool readC();
+ static void writeO();
+ static void writeC();
static void writeHeaderO(const string& headerid, char *header, long unsigned int size) { O->writeHeader(headerid, header, size); }
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 configcache *C;
static vector<para> delayedParaAdd;
static vector<para> delayedParaSet;
+ static writeout *out;
+
+ static string fileOfPath(const string& dressedfile);
+ static string activeCFile;
+ static vector<string> parentConfigs;
+ static void addParentConfig(const char* parentconfig);
};
#endif