1 #include "hypercache.h"
 
   3 configcache *hypercache::C = NULL;
 
   4 vector<hypercache::para> hypercache::delayedParaAdd;
 
   5 vector<hypercache::para> hypercache::delayedParaSet;
 
   6 string hypercache::activeCFile = "";
 
   7 vector<unsigned long> hypercache::parentConfigs;
 
   8 ostream* hypercache::log;
 
   9 vector<configcache*> hypercache::Os;
 
  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, ostream* _log) {
 
  17   *cache = new configcache(cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, log);
 
  19   for (vector<para>::iterator parit=delayedParaAdd.begin(); parit != delayedParaAdd.end(); ++parit)
 
  20     (*cache)->addPara(parit->parid, parit->val);
 
  22   for (vector<para>::iterator parit=delayedParaSet.begin(); parit != delayedParaSet.end(); ++parit)
 
  23     (*cache)->setPara(parit->parid, parit->val);
 
  26 void hypercache::addPara(const string& parid, const double& val) {
 
  28   newpara.parid = parid;
 
  30   delayedParaAdd.push_back(newpara);
 
  33     C->addPara(parid, val);
 
  35   for (vector<configcache*>::iterator osit = Os.begin(); osit != Os.end(); ++osit)
 
  36     (*osit)->addPara(parid, val);
 
  39 void hypercache::setPara(const string& parid, const double& val) {
 
  41   newpara.parid = parid;
 
  43   delayedParaSet.push_back(newpara);
 
  46     C->setPara(parid, val);
 
  48   for (vector<configcache*>::iterator osit = Os.begin(); osit != Os.end(); ++osit)
 
  49     (*osit)->setPara(parid, val);
 
  52 void hypercache::finalize() {
 
  53   for (vector<configcache*>::iterator osit = Os.begin(); osit != Os.end(); ++osit)
 
  59 string hypercache::fileOfPath(const string& dressedfile) {
 
  60   return dressedfile.substr(dressedfile.find_last_of("\\/")+1);
 
  63 int hypercache::readC() { 
 
  66   readret = C->readConfig(&parentConfigs);
 
  69     activeCFile = fileOfPath(C->getInFileName());
 
  76 void hypercache::writeC() {
 
  78   activeCFile = fileOfPath( C->getOutFileName().substr( 0, C->getOutFileName().length()-4 ) );
 
  81 void hypercache::writeO(int obsid) {
 
  82   if ( activeCFile != "" ) {
 
  83     unsigned long afilehash = configcache::hash(activeCFile);
 
  84     Os[obsid]->writeHeader("concurrent_cfile", (char*)(&afilehash), sizeof(unsigned long));
 
  86   Os[obsid]->writeConfig(); 
 
  89 int hypercache::readO(int obsid) {
 
  92   readret = Os[obsid]->readConfig();
 
  94   if ( readret == -1 ) {
 
  95     unsigned long *parentconfig = (unsigned long*)Os[obsid]->getHeader("concurrent_cfile");
 
  96     if ( parentconfig != NULL )
 
  97       addParentConfig(parentconfig);
 
 103 void hypercache::addParentConfig(const unsigned long *parentconfig) {
 
 104   for (vector<unsigned long>::iterator parit = parentConfigs.begin(); parit != parentConfigs.end(); ++parit)
 
 105     if ( *parit == *parentconfig )
 
 108   parentConfigs.push_back(*parentconfig);