Commit 60fd5194 authored by stefanwessel's avatar stefanwessel
Browse files

added support for custom resize of observables (cf. resizefactor and...

added support for custom resize of observables (cf. resizefactor and resizeoffset), old code not broken. Default values are resizefactor=2, resizeoffset=0

git-svn-id: https://svn.rwth-aachen.de/repos/sw440870_load_leveller/trunk@46 36cca2a8-63f0-4188-8a56-663e3b0d1cf3
parent 56c957e6
......@@ -24,6 +24,15 @@ void measurements :: add_observable(std::string name, luint bin_length, luint in
tag[name]=1;
}
void measurements :: add_observable(std::string name, luint bin_length, luint initial_length, luint resizefactor, luint resizeoffset)
{
observable *o = new observable(name, 1, bin_length, initial_length, resizefactor, resizeoffset);
obs_v.push_back(o);
eo[name]=obs_v.size()-1;
tag[name]=1;
}
void measurements :: add_vectorobservable(std::string name)
{
observable *o = new observable(name);
......@@ -56,6 +65,14 @@ void measurements :: add_vectorobservable(std::string name, luint vector_length,
tag[name]=1;
}
void measurements :: add_vectorobservable(std::string name, luint vector_length, luint bin_length, luint initial_length, luint resizefactor, luint resizeoffset)
{
observable *o = new observable(name, vector_length, bin_length, initial_length, resizefactor, resizeoffset);
obs_v.push_back(o);
eo[name]=obs_v.size()-1;
tag[name]=1;
}
void measurements :: add_evalable(std::string name, std::vector<std::string>& n,
void (*f) (double&, std::vector <std::valarray<double>* >&))
{
......
......@@ -48,6 +48,8 @@ class measurements
//! Adds scalar observable
/*! Adds a new observable with specified name, specific bin length and a specified initial number of bins*/
void add_observable(std::string,luint,luint);
/*! Adds a new observable with specified name, specific bin length and a specified initial number of bins and resizing data*/
void add_observable(std::string,luint,luint,luint,luint);
//! Adds vector observable
/*! Adds a new vector observable with specified name and default vector length and default bin length*/
......@@ -61,6 +63,8 @@ class measurements
//! Adds vector observable
/*! Adds a new vector observable with specified name and specified vector length and specified bin length and specified initial number of bins*/
void add_vectorobservable(std::string,luint,luint,luint);
/*! Adds a new vector observable with specified name and specified vector length and specified bin length and specified initial number of bins and resizing data*/
void add_vectorobservable(std::string,luint,luint,luint,luint,luint);
//! (Re)Set bin length for all observables
void set_bin_length(luint bl) {for (uint i=0;i<obs_v.size();++i) obs_v[i]->set_bin_length(bl);}
......
......@@ -3,30 +3,35 @@
observable :: observable()
{
init("",1,1,1000);
init("",1,1,1000,2,0);
}
observable :: observable(std::string _name)
{
init(_name,1,1,1000);
init(_name,1,1,1000,2,0);
}
observable :: observable(std::string _name, luint _vector_length)
{
init(_name,_vector_length,1,1000);
init(_name,_vector_length,1,1000,2,0);
}
observable :: observable(std::string _name, luint _vector_length, luint _bin_length)
{
init(_name,_vector_length,_bin_length,1000);
init(_name,_vector_length,_bin_length,1000,2,0);
}
observable :: observable(std::string _name, luint _vector_length, luint _bin_length, luint _initial_length)
{
init(_name,_vector_length,_bin_length,_initial_length);
init(_name,_vector_length,_bin_length,_initial_length,2,0);
}
void observable :: init(std::string _name, luint _vector_length, luint _bin_length, luint _initial_length)
observable :: observable(std::string _name, luint _vector_length, luint _bin_length, luint _initial_length, luint _resizefactor, luint _resizeoffset)
{
init(_name,_vector_length,_bin_length,_initial_length,_resizefactor,_resizeoffset);
}
void observable :: init(std::string _name, luint _vector_length, luint _bin_length, luint _initial_length, luint _resizefactor, luint _resizeoffset)
{
name_=_name;
vector_length_ = _vector_length;
......@@ -34,6 +39,8 @@ void observable :: init(std::string _name, luint _vector_length, luint _bin_leng
initial_length = _initial_length;
length = initial_length;
samples.resize(length*vector_length_,0.);
resizefactor=resizefactor;
resizeoffset=resizeoffset;
current_bin= 0;
current_bin_filling=0;
analysis_done=0;
......@@ -71,9 +78,9 @@ void observable :: add(const valarray<double>& val)
if( current_bin == (length - 1)) //need to allocate more memory for a new chunk of bins
{
valarray<double> old=samples;
samples.resize(2*old.size(),0.);
samples.resize(resizefactor*old.size()+resizeoffset,0.);
samples[slice(0,old.size(),1)]=old;
length += length;
length =resizefactor*length+resizeoffset;
}
++current_bin;
current_bin_filling=0;
......@@ -322,6 +329,8 @@ void observable :: write(odump& d)
d.write(initial_length);
d.write(current_bin);
d.write(current_bin_filling);
d.write(resizefactor);
d.write(resizeoffset);
d.write(&samples[0],(current_bin+1)*vector_length_);
}
......@@ -337,6 +346,8 @@ bool observable :: read(idump& d, int skipbins)
d.read(initial_length);
d.read(current_bin);
d.read(current_bin_filling);
d.read(resizefactor);
d.read(resizeoffset);
if (skipbins) {
if (skipbins>current_bin) skipbins=current_bin;
d.ignore<double>(skipbins*vector_length_);
......
......@@ -25,6 +25,7 @@ class observable
observable(string,luint);
observable(string,luint,luint);
observable(string,luint,luint,luint);
observable(string,luint,luint,luint,luint,luint);
~observable() {}
......@@ -35,7 +36,7 @@ class observable
void set_bin_length(luint bl) {bin_length_=bl;}
luint vector_length() {return vector_length_;}
void set_vector_length(luint vl) {init(name_, vl, bin_length_, initial_length);}
void set_vector_length(luint vl) {init(name_, vl, bin_length_, initial_length, resizefactor, resizeoffset);}
luint bins() {return current_bin;}
......@@ -95,7 +96,10 @@ class observable
luint current_bin_filling;
luint chunks;
void init(string,luint,luint,luint);
luint resizefactor;
luint resizeoffset;
void init(string,luint,luint,luint,luint,luint);
void binning();
void simple();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment