From 027b93b16fe0d77104e0e711377c5728b0934035 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Fri, 25 May 2012 15:13:03 +0200 Subject: [PATCH] ... --- configcache.cpp | 8 +++++--- configcache.h | 7 ++++++- obs.hpp | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/configcache.cpp b/configcache.cpp index 48c31f4..f3c02de 100644 --- a/configcache.cpp +++ b/configcache.cpp @@ -5,7 +5,7 @@ #include #include -configcache::configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize){ +configcache::configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, const int& cachemode){ NEQUI = nequi; NSKIP = nskip; DATADIR = datadir; @@ -20,6 +20,8 @@ configcache::configcache(const string& cacheid, const int& nequi, const int& nsk outBuffer = NULL; inBuffer = NULL; + MODE = cachemode; + refetchDataFiles = false; } @@ -87,7 +89,7 @@ bool configcache::isValidInFile(const string& infile) bool configcache::readConfig() { - if(DATADIR == "") return false; + if(DATADIR == "" || MODE == CACHE_MODE_DISABLED) return false; if(refetchDataFiles){ refetchDataFiles = false; @@ -124,7 +126,7 @@ bool configcache::readConfig() void configcache::writeConfig() { - if( DATADIR == "") return; + if( DATADIR == "" || MODE < 2 ) return; if(!outFile.is_open()){ time_t secstamp = time(NULL); diff --git a/configcache.h b/configcache.h index 3227233..4372946 100644 --- a/configcache.h +++ b/configcache.h @@ -12,6 +12,10 @@ #include #include +#define CACHE_MODE_DISABLED 0 +#define CACHE_MODE_READ 1 +#define CACHE_MODE_FULL 2 + using namespace std; struct parameter{ @@ -22,7 +26,7 @@ struct parameter{ class configcache{ public: ~configcache(); - configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize); + configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL); bool readConfig(); void writeConfig(); void addPara(const string& parid, const double& val=0); @@ -35,6 +39,7 @@ class configcache{ int NSKIP; string DATADIR; string CACHEID; + int MODE; string getFileId(const bool& shortid=false); ofstream outFile; diff --git a/obs.hpp b/obs.hpp index 2501f14..99d97fa 100644 --- a/obs.hpp +++ b/obs.hpp @@ -35,6 +35,7 @@ private: map computations; void mean(const string& compid, vector< vector > *meas, const int& ival); + void mean(const string& compid, vector< vector > *meas, const int& ival); }; @@ -75,6 +76,24 @@ void obs::mean(const string& compid, vector< vector > *meas, co computations[compid].err += pow( (*measIt)[ival] - computations[compid].val, 2 ); computations[compid].err /= nmeas*(nmeas-1); computations[compid].err = sqrt( computations[compid].err ); +} + +template +void obs::mean(const string& compid, vector< vector > *meas, const int& ival) +{ + computations[compid].val = 0; + computations[compid].err = 0; + + int nmeas = meas->size(); + + for(vector< vector >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt) + computations[compid].val += (*measIt)[ival]; + computations[compid].val /= nmeas; + + for(vector< vector >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt) + computations[compid].err += pow( (*measIt)[ival] - computations[compid].val, 2 ); + computations[compid].err /= nmeas*(nmeas-1); + computations[compid].err = sqrt( computations[compid].err ); } template -- 2.39.5