From: Alex Schmidt Date: Thu, 23 May 2013 13:18:01 +0000 (+0200) Subject: ... X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/a5f05e337d18c193ac57b4da0013d1cdc69f8faa ... --- diff --git a/o815/o815.h b/o815/o815.h index 8b00437..91fc747 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -36,7 +36,6 @@ class o815 { char *obsMem; string simid, datadesc; ostream *out, *log; - void printParas(); paraq* paraQ; }; diff --git a/o815/obs.cpp b/o815/obs.cpp index c10a5f4..807d4ee 100644 --- a/o815/obs.cpp +++ b/o815/obs.cpp @@ -35,8 +35,3 @@ o815::obs::obs(const string& _obsid, const string& _datadesc, o815 *_O815, const ocid = hypercache::initO(O815->programid + "-" + obsid, O815->comargs.nequi, O815->comargs.nskip, O815->comargs.obscache.first, &obsMem, obsmemSize, O815->comargs.obscache.second, log); } - -void o815::obs::printParas() { - for (vector::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait) - *O815->out->out[obsid] << (*paraQ)[*parait] << "\t"; -} diff --git a/obs.hpp b/obs.hpp deleted file mode 100644 index 4d20bd6..0000000 --- a/obs.hpp +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef OBS_HPP -#define OBS_HPP - -#include -#include -#include -#include - -using namespace std; - -template -class obs -{ -public: - void addMeas(const obstype& val); - void addMeas(obstype val[], int valsize); - - void computeEasy(const string& compid="one", const int& ival=0) { mean(compid, &measurements, ival); } - - void computeJack(const string& compid, double (*func)(vector< vector > *vals, void *para)=NULL, void *para=NULL); - void computeJack(double (*func)(vector< vector > *vals, void *para)=NULL, void *para=NULL) { computeJack("one",func,para); } - - double getMean(const string& compid="one") { return computations[compid].val; } - double getErr(const string& compid="one") { return computations[compid].err; } - - void reset(); - -private: - struct result{ - double val; - double err; - }; - - vector< vector > measurements; - map computations; - - void mean(const string& compid, vector< vector > *meas, const int& ival); - void mean(const string& compid, vector< vector > *meas, const int& ival); -}; - - -template -void obs::reset() -{ - computations.clear(); - measurements.clear(); -} - -template -void obs::addMeas(const obstype& val) -{ - measurements.push_back( vector(1,val) ); -} - -template -void obs::addMeas(obstype val[], int valsize) -{ - vector tmpvec; - for(int i=0; i -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 = sqrt( computations[compid].err ) / nmeas; -} - -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 = sqrt( computations[compid].err ) / nmeas; -} - -template -void obs::computeJack(const string& compid, double (*func)(vector< vector > *vals, void *para), void *para) -{ - int nmeas=measurements.size(); - double manymeans[nmeas]; - - computations[compid].val = 0; - computations[compid].err = 0; - - int imeas=0; - for(typename vector< vector >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++) - { - vector removed = *removedIt; - - *removedIt = measurements.back(); - measurements.pop_back(); - - manymeans[imeas] = func(&measurements, para); - computations[compid].val += manymeans[imeas]; - - measurements.push_back( *removedIt ); - *removedIt = removed; - } - computations[compid].val /= nmeas; - - for(int imean=0; imean +#include +#include +#include + +using namespace std; + +template +class obstat +{ +public: + void addMeas(const obstype& val); + void addMeas(obstype val[], int valsize); + + void computeEasy(const string& compid="one", const int& ival=0) { mean(compid, &measurements, ival); } + + void computeJack(const string& compid, double (*func)(vector< vector > *vals, void *para)=NULL, void *para=NULL); + void computeJack(double (*func)(vector< vector > *vals, void *para)=NULL, void *para=NULL) { computeJack("one",func,para); } + + double getMean(const string& compid="one") { return computations[compid].val; } + double getErr(const string& compid="one") { return computations[compid].err; } + + void reset(); + +private: + struct result{ + double val; + double err; + }; + + vector< vector > measurements; + map computations; + + void mean(const string& compid, vector< vector > *meas, const int& ival); + void mean(const string& compid, vector< vector > *meas, const int& ival); +}; + + +template +void obstat::reset() +{ + computations.clear(); + measurements.clear(); +} + +template +void obstat::addMeas(const obstype& val) +{ + measurements.push_back( vector(1,val) ); +} + +template +void obstat::addMeas(obstype val[], int valsize) +{ + vector tmpvec; + for(int i=0; i +void obstat::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 = sqrt( computations[compid].err ) / nmeas; +} + +template +void obstat::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 = sqrt( computations[compid].err ) / nmeas; +} + +template +void obstat::computeJack(const string& compid, double (*func)(vector< vector > *vals, void *para), void *para) +{ + int nmeas=measurements.size(); + double manymeans[nmeas]; + + computations[compid].val = 0; + computations[compid].err = 0; + + int imeas=0; + for(typename vector< vector >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++) + { + vector removed = *removedIt; + + *removedIt = measurements.back(); + measurements.pop_back(); + + manymeans[imeas] = func(&measurements, para); + computations[compid].val += manymeans[imeas]; + + measurements.push_back( *removedIt ); + *removedIt = removed; + } + computations[compid].val /= nmeas; + + for(int imean=0; imean::iterator parait = allParaIds.begin(); parait != allParaIds.end(); ++parait) + paranames << *parait << ":"; + + return paranames.str(); +} + +string paraq::getParaVals() { + stringstream paravals; + + for (vector::iterator parait = allParaIds.begin(); parait != allParaIds.end(); ++parait) { + if ( parait != allParaIds.begin() ) + paravals << "\t"; + paravals << (*this)[*parait]; + } + + return paravals.str(); +} diff --git a/paraq.h b/paraq.h index 6aba45b..6dc582d 100644 --- a/paraq.h +++ b/paraq.h @@ -19,6 +19,8 @@ class paraq { int getTotalJobs(); string rangeString(); vector allParaIds; + string getParaNames(); + string getParaVals(); private: int nprocs, rank;