]> git.treefish.org Git - phys/latlib.git/commitdiff
...
authorAlex Schmidt <alex@treefish.org>
Thu, 23 May 2013 13:18:01 +0000 (15:18 +0200)
committerAlex Schmidt <alex@treefish.org>
Thu, 23 May 2013 13:18:01 +0000 (15:18 +0200)
o815/o815.h
o815/obs.cpp
obs.hpp [deleted file]
obstat.hpp [new file with mode: 0644]
paraq.cpp
paraq.h

index 8b004374ac0e779c046f1b56d181eb913bf7189f..91fc747685204a379f8a2b0951dec367b7726754 100644 (file)
@@ -36,7 +36,6 @@ class o815 {
     char *obsMem;
     string simid, datadesc;
     ostream *out, *log;
-    void printParas();
     paraq* paraQ;
   };
 
index c10a5f4e89c18ab9c3ab24f0fda4e68a1ceddf58..807d4ee2195863f8860beae7fe48cc776e5394a3 100644 (file)
@@ -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<string>::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 (file)
index 4d20bd6..0000000
--- a/obs.hpp
+++ /dev/null
@@ -1,128 +0,0 @@
-#ifndef OBS_HPP
-#define OBS_HPP
-
-#include <vector>
-#include <string>
-#include <map>
-#include <math.h>
-
-using namespace std;
-
-template <typename obstype>
-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 <obstype> > *vals, void *para)=NULL, void *para=NULL);
-  void computeJack(double (*func)(vector< vector <obstype> > *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<obstype> > measurements;
-  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);
-};
-
-
-template <typename obstype> 
-void obs<obstype>::reset()
-{
-  computations.clear();
-  measurements.clear();
-}
-
-template <typename obstype> 
-void obs<obstype>::addMeas(const obstype& val)
-{
-  measurements.push_back( vector<obstype>(1,val) );
-}
-
-template <typename obstype>
-void obs<obstype>::addMeas(obstype val[], int valsize)
-{
-  vector<obstype> tmpvec;
-  for(int i=0; i<valsize; i++) tmpvec.push_back(val[i]);
-  measurements.push_back(tmpvec);
-}
-
-template <typename obstype>
-void obs<obstype>::mean(const string& compid, vector< vector<double> > *meas, const int& ival)
-{
-  computations[compid].val = 0;
-  computations[compid].err = 0;
-  
-  int nmeas = meas->size();
-
-  for(vector< vector<double> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
-    computations[compid].val += (*measIt)[ival];
-  computations[compid].val /= nmeas;
-  
-  for(vector< vector<double> >::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 <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 = sqrt( computations[compid].err ) / nmeas;
-}                               
-    
-template <typename obstype>
-void obs<obstype>::computeJack(const string& compid, double (*func)(vector< vector<obstype> > *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<obstype> >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++)
-    {
-      vector<obstype> 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<nmeas; imean++)
-    computations[compid].err += pow( manymeans[imean] - computations[compid].val, 2 );
-  computations[compid].err *= (double)(nmeas-1)/nmeas;
-  computations[compid].err = sqrt(computations[compid].err);
-}
-
-#endif
diff --git a/obstat.hpp b/obstat.hpp
new file mode 100644 (file)
index 0000000..d66467b
--- /dev/null
@@ -0,0 +1,128 @@
+#ifndef OBSTAT_HPP
+#define OBSTAT_HPP
+
+#include <vector>
+#include <string>
+#include <map>
+#include <math.h>
+
+using namespace std;
+
+template <typename obstype>
+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 <obstype> > *vals, void *para)=NULL, void *para=NULL);
+  void computeJack(double (*func)(vector< vector <obstype> > *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<obstype> > measurements;
+  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);
+};
+
+
+template <typename obstype> 
+void obstat<obstype>::reset()
+{
+  computations.clear();
+  measurements.clear();
+}
+
+template <typename obstype> 
+void obstat<obstype>::addMeas(const obstype& val)
+{
+  measurements.push_back( vector<obstype>(1,val) );
+}
+
+template <typename obstype>
+void obstat<obstype>::addMeas(obstype val[], int valsize)
+{
+  vector<obstype> tmpvec;
+  for(int i=0; i<valsize; i++) tmpvec.push_back(val[i]);
+  measurements.push_back(tmpvec);
+}
+
+template <typename obstype>
+void obstat<obstype>::mean(const string& compid, vector< vector<double> > *meas, const int& ival)
+{
+  computations[compid].val = 0;
+  computations[compid].err = 0;
+  
+  int nmeas = meas->size();
+
+  for(vector< vector<double> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
+    computations[compid].val += (*measIt)[ival];
+  computations[compid].val /= nmeas;
+  
+  for(vector< vector<double> >::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 <typename obstype>
+void obstat<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 = sqrt( computations[compid].err ) / nmeas;
+}                               
+    
+template <typename obstype>
+void obstat<obstype>::computeJack(const string& compid, double (*func)(vector< vector<obstype> > *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<obstype> >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++)
+    {
+      vector<obstype> 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<nmeas; imean++)
+    computations[compid].err += pow( manymeans[imean] - computations[compid].val, 2 );
+  computations[compid].err *= (double)(nmeas-1)/nmeas;
+  computations[compid].err = sqrt(computations[compid].err);
+}
+
+#endif
index 381941f7812dec35e5da058716a98dd62faaffce..ac8fc14ff77ac4897ba082e1b847ce1712f5120a 100644 (file)
--- a/paraq.cpp
+++ b/paraq.cpp
@@ -129,3 +129,24 @@ void paraq::uniqueAllParaIdsAdd(const string& paraid) {
 
   allParaIds.push_back(paraid);
 }
+
+string paraq::getParaNames() {
+  stringstream paranames;
+  
+  for (vector<string>::iterator parait = allParaIds.begin(); parait != allParaIds.end(); ++parait)
+    paranames << *parait << ":";
+  
+  return paranames.str();
+}
+
+string paraq::getParaVals() {
+  stringstream paravals;
+
+  for (vector<string>::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 6aba45b9da3c524d2b186d429b03029296e7e141..6dc582d6b575ca2a30cc99b9eddc852e8b9800df 100644 (file)
--- a/paraq.h
+++ b/paraq.h
@@ -19,6 +19,8 @@ class paraq {
   int getTotalJobs();
   string rangeString();
   vector<string> allParaIds;
+  string getParaNames();
+  string getParaVals();
 
  private:
   int nprocs, rank;