#include <time.h>
#include <dirent.h>
-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;
outBuffer = NULL;
inBuffer = NULL;
+ MODE = cachemode;
+
refetchDataFiles = false;
}
bool configcache::readConfig()
{
- if(DATADIR == "") return false;
+ if(DATADIR == "" || MODE == CACHE_MODE_DISABLED) return false;
if(refetchDataFiles){
refetchDataFiles = false;
void configcache::writeConfig()
{
- if( DATADIR == "") return;
+ if( DATADIR == "" || MODE < 2 ) return;
if(!outFile.is_open()){
time_t secstamp = time(NULL);
#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/copy.hpp>
+#define CACHE_MODE_DISABLED 0
+#define CACHE_MODE_READ 1
+#define CACHE_MODE_FULL 2
+
using namespace std;
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);
int NSKIP;
string DATADIR;
string CACHEID;
+ int MODE;
string getFileId(const bool& shortid=false);
ofstream outFile;
map<string,result> computations;
void mean(const string& compid, vector< vector <double> > *meas, const int& ival);
+ void mean(const string& compid, vector< vector <int> > *meas, const int& ival);
};
computations[compid].err += pow( (*measIt)[ival] - computations[compid].val, 2 );
computations[compid].err /= nmeas*(nmeas-1);
computations[compid].err = sqrt( computations[compid].err );
+}
+
+template <typename obstype>
+void obs<obstype>::mean(const string& compid, vector< vector<int> > *meas, const int& ival)
+{
+ computations[compid].val = 0;
+ computations[compid].err = 0;
+
+ int nmeas = meas->size();
+
+ for(vector< vector<int> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
+ computations[compid].val += (*measIt)[ival];
+ computations[compid].val /= nmeas;
+
+ for(vector< vector<int> >::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 <typename obstype>