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 int hypercache::read1CForEqui() {
77 int readret = C->readConfig(NULL);
82 void hypercache::writeC() {
84 activeCFile = fileOfPath( C->getOutFileName().substr( 0, C->getOutFileName().length()-4 ) );
87 void hypercache::writeO(int obsid) {
88 if ( activeCFile != "" ) {
89 unsigned long afilehash = configcache::hash(activeCFile);
90 Os[obsid]->writeHeader("concurrent_cfile", (char*)(&afilehash), sizeof(unsigned long));
92 Os[obsid]->writeConfig();
95 int hypercache::readO(int obsid) {
98 readret = Os[obsid]->readConfig();
100 if ( readret == -1 ) {
101 unsigned long *parentconfig = (unsigned long*)Os[obsid]->getHeader("concurrent_cfile");
102 if ( parentconfig != NULL )
103 addParentConfig(parentconfig);
109 void hypercache::addParentConfig(const unsigned long *parentconfig) {
110 for (vector<unsigned long>::iterator parit = parentConfigs.begin(); parit != parentConfigs.end(); ++parit)
111 if ( *parit == *parentconfig )
114 parentConfigs.push_back(*parentconfig);