ALPS Project: alea library
Header file alea/observable.h
This header contains a class to store a collection of Monte Carlo measurements,
each identified by a name.
Synopsis
namespace alps {
class ObservableSet: public std::map<std::string,Observable*>
{
public:
template static void register_type();
ObservableSet() {};
ObservableSet(const ObservableSet& m);
ObservableSet& operator=(const ObservableSet& m);
~ObservableSet();
void save(osiris::ODump& dump) const;
void load(osiris::IDump& dump);
ObservableSet& operator<<(const ObservableSet& obs);
ObservableSet& operator<<(const Observable& obs);
ObservableSet& operator<<(const boost::shared_ptr<Observable>& ptr);
void addObservable(Observable *obs);
void removeObservable(const std::string& name);
bool has(const std::string& name) const;
Observable& operator[](const std::string& name);
const Observable& operator[](const std::string& name) const;
template <class T> T& get(const std::string& name);
template <class T> const T& get(const std::string& name) const;
template <class F> void do_for_all(F f) const;
template <class F> void do_for_all(F f);
bool can_set_thermalization_all() const;
bool can_set_thermalization_any() const;
void set_thermalization(uint32_t todiscard);
uint32_t get_thermalization() const;
uint32_t number_of_runs() const;
ObservableSet get_run(uint32_t) const;
void reset(bool flag=false);
void compact();
void write_xml(std::ostream& xml, const boost::filesystem::path& =boost::filesystem::path()) const;
void write_xml(oxstream& oxs, const boost::filesystem::path& =boost::filesystem::path()) const;
void read_xml(std::istream& infile, const XMLTag& tag);
};
std::ostream& operator<<(std::ostream& out,const ObservableSet& obs)
ODump& operator<<(ODump& od, const ObservableSet&);
IDump& operator>>(IDump& id, ObservableSet&);
}
The ObservableSet class
is a container for observables, identified by name, implemented as associative
array of pointers to the base class Observable.
Static member functions
template static void register_type();
Since objects derived from Observable are polymorphic, a factor
has to exist to call the right constructor when an observable needs to be
deserialized. The register function creates a factory for the type,
and thus allows deserializing of objects of that type.
Member functions
ObservableSet() {};
ObservableSet(const ObservableSet& m);
ObservableSet& operator=(const ObservableSet& m);
~ObservableSet();
Since ObservableSet is implemented as an associative array of pointers,
a nontrivial copy constructor, destructor and assignment operatir is needed.
void save(osiris::ODump& dump) const;
void load(osiris::IDump& dump);
are the (de)serialization functions using the osiris library.
ObservableSet& operator<<(const ObservableSet& obs);
adds observables from another ObservableSet. If an observable with
a given name does not yet exist, it gets copied into the set. Otherwise it
is added to the observable with the same name in the set. Throws a std::runtime_error
if the adding of two observables fails.
ObservableSet& operator<<(const Observable& obs);
ObservableSet& operator<<(const boost::shared_ptr<Observable>& ptr);
adds an Observable to the ObservableSet. If an observable
with the name does not yet exist, it gets copied into the set. Otherwise
it is added to the observable with the same name in the set. Throws a std::runtime_error
if the adding of the two observables fails.
void addObservable(Observable *obs);
adds an Observable to the ObservableSet. The ObservableSet
assumes ownership of the Observable and deletes it when it itself
is destroyed.
void removeObservable(const std::string& name);
removes the Observable with the given name. Throws std::out_of_range
if no observable with the given name exists.
bool has(const std::string& name) const;
checks if an observable with the given name is contained in the ObservableSet.
Observable& operator[](const std::string& name);
const Observable& operator[](const std::string& name) const;
returns the observable with the given name or throws a std::out_of_range
exception if no observable with the given name exists.
template <class T> T& get(const std::string& name);
template <class T> const T& get(const std::string& name) const;
Same as operator[] but attempts a cast to the given type and throws
a std::runtime_error if the cast fails.
template <class F> void do_for_all(F f) const;
template <class F> void do_for_all(F f);
apply a function object to all observables.
bool can_set_thermalization_all() const;
checks if for the thermalization time can be changed for all Observables
in the ObservableSet.
bool can_set_thermalization_all() const;
checks if for the thermalization time can be changed for any Observables
in the ObservableSet.
void set_thermalization(uint32_t todiscard);
discards at least the number of measurements passed as parameter, in order
to set the thermalization time.
uint32_t get_thermalization() const;
returns the minimum number of thermalization steps for any of the observables.
uint32_t number_of_runs() const;
returns the number of Monte Carlo time series (runs) which contributed to
the ObservableSet.
ObservableSet get_run(uint32_t) const;
returns a new ObservableSet, containing only data from one Monte
Carlo time series (run). Throws std::out_of_range if the number
passed is larger than the number of runs.
void reset(bool flag=false);
calls the reset function with the given argument for all Observables
in the ObservableSet.
void compact();
calls the compact function for all Observables in the
ObservableSet. This the memory allocation, while still enabling
access to the most important results. Usually the ability to modify the
observable and more complex functions (e.g. change thermalization, get crosscorrelations,
...) get lost though.
XML input and output
void write_xml(std::ostream& xml, const boost::filesystem::path& =boost::filesystem::path()) const;
void write_xml(oxstream& oxs, const boost::filesystem::path& =boost::filesystem::path()) const;
output the ObservableSet in XML format, following the schema on
http://xml.comp-phys.org/.
void read_xml(std::istream& infile, const XMLTag& tag);
reads the ObservableSet in XML format, following the schema on
http://xml.comp-phys.org/. The tag
argument contains the parsed opening tag.
I/O operators
std::ostream& operator<<(std::ostream& out,const ObservableSet& obs)
prints all Observables in an ObservableSet by calling
the output operator for each of them.
ODump& operator<<(ODump& od, const ObservableSet&);
IDump& operator>>(IDump& id, ObservableSet&);
serialize and deserialize the ObservableSet
copyright (c) 1994-2003 by Matthias Troyer