1 #include "hypercache.h"
 
   3 configcache *hypercache::O = NULL;
 
   4 configcache *hypercache::C = NULL;
 
   5 vector<hypercache::para> hypercache::delayedParaAdd;
 
   6 vector<hypercache::para> hypercache::delayedParaSet;
 
   7 string hypercache::activeCFile = "";
 
   8 vector<string> hypercache::parentConfigs;
 
   9 writeout *hypercache::out = NULL;
 
  11 void hypercache::initCache(configcache **cache,
 
  12                            const string& cacheid, const int& nequi, const int& nskip, const string& datadir, 
 
  13                            char **configmem, const int& configMemSize, const int& cachemode, writeout *out_a) {
 
  15   bool allInitBefore = true;
 
  17   if (O == NULL || C == NULL)
 
  18     allInitBefore = false;
 
  23   *cache = new configcache(cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, out_a);
 
  25   if (O != NULL && C != NULL && !allInitBefore) {
 
  26     for (vector<para>::iterator parit=delayedParaAdd.begin(); parit != delayedParaAdd.end(); ++parit) {
 
  27       O->addPara(parit->parid, parit->val);
 
  28       C->addPara(parit->parid, parit->val);
 
  30     for (vector<para>::iterator parit=delayedParaSet.begin(); parit != delayedParaSet.end(); ++parit) {
 
  31       O->setPara(parit->parid, parit->val);
 
  32       C->setPara(parit->parid, parit->val);
 
  37 void hypercache::addPara(const string& parid, const double& val) {
 
  38   if (O == NULL || C == NULL) {
 
  40     newpara.parid = parid;
 
  42     delayedParaAdd.push_back(newpara);
 
  45     O->addPara(parid, val);
 
  46     C->addPara(parid, val);
 
  50 void hypercache::setPara(const string& parid, const double& val) {
 
  51   if (O == NULL || C == NULL) {
 
  53     newpara.parid = parid;
 
  55     delayedParaSet.push_back(newpara);
 
  58     O->setPara(parid, val);
 
  59     C->setPara(parid, val);
 
  61     parentConfigs.clear();
 
  65 void hypercache::finalize() {
 
  70 string hypercache::fileOfPath(const string& dressedfile) {
 
  71   return dressedfile.substr(dressedfile.find_last_of("\\/")+1);
 
  74 bool hypercache::readC() { 
 
  77   if ( readret = C->readConfig(&parentConfigs) )
 
  78     activeCFile = fileOfPath(C->getInFileName());
 
  85 void hypercache::writeC() {
 
  87   activeCFile = fileOfPath( C->getOutFileName().substr( 0, C->getOutFileName().length()-4 ) );
 
  90 void hypercache::writeO() {
 
  91   if ( activeCFile != "" )
 
  92     O->writeHeader("concurrent_cfile", activeCFile.c_str(), (activeCFile.length()+1)*sizeof(char));
 
  97 bool hypercache::readO() {
 
 100   if ( readret = O->readConfig() ) {
 
 101     char *parentconfig = (char*)O->getHeader("concurrent_cfile");
 
 102     if ( parentconfig != NULL )
 
 103       addParentConfig(parentconfig);
 
 109 void hypercache::addParentConfig(const char* parentconfig) {
 
 110   for (vector<string>::iterator parit = parentConfigs.begin(); parit != parentConfigs.end(); ++parit)
 
 111     if ( *parit == parentconfig )
 
 114   parentConfigs.push_back(parentconfig);