namespace alps {
class ObservableSet: public std::map<std::string,Observable*>
{
public:
templatestatic void register_type(); ObservableSet& operator<<(const boost::shared_ptr<Observable>& ptr);
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);
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&);
}
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.templatestatic void register_type();
Since ObservableSet is implemented as an associative array of pointers, a nontrivial copy constructor, destructor and assignment operatir is needed.ObservableSet() {};
ObservableSet(const ObservableSet& m);
ObservableSet& operator=(const ObservableSet& m);
~ObservableSet();
are the (de)serialization functions using the osiris library.void save(osiris::ODump& dump) const;
void load(osiris::IDump& dump);
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 ObservableSet& obs);
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.ObservableSet& operator<<(const Observable& obs);
ObservableSet& operator<<(const boost::shared_ptr<Observable>& ptr);
adds an Observable to the ObservableSet. The ObservableSet assumes ownership of the Observable and deletes it when it itself is destroyed.void addObservable(Observable *obs);
removes the Observable with the given name. Throws std::out_of_range if no observable with the given name exists.void removeObservable(const std::string& name);
checks if an observable with the given name is contained in the ObservableSet.bool has(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.Observable& operator[](const std::string& name);
const Observable& operator[](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 T> T& get(const std::string& name);
template <class T> const T& get(const std::string& name) const;
apply a function object to all observables.template <class F> void do_for_all(F f) const;
template <class F> void do_for_all(F f);
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.bool can_set_thermalization_all() const;
discards at least the number of measurements passed as parameter, in order to set the thermalization time.void set_thermalization(uint32_t todiscard);
returns the minimum number of thermalization steps for any of the observables.uint32_t get_thermalization() const;
returns the number of Monte Carlo time series (runs) which contributed to the ObservableSet.uint32_t number_of_runs() 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.ObservableSet get_run(uint32_t) const;
calls the reset function with the given argument for all Observables in the ObservableSet.void reset(bool flag=false);
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.void compact();
output the ObservableSet in XML format, following the schema on http://xml.comp-phys.org/.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;
reads the ObservableSet in XML format, following the schema on http://xml.comp-phys.org/. The tag argument contains the parsed opening tag.void read_xml(std::istream& infile, const XMLTag& tag);
prints all Observables in an ObservableSet by calling the output operator for each of them.std::ostream& operator<<(std::ostream& out,const ObservableSet& obs)
serialize and deserialize the ObservableSetODump& operator<<(ODump& od, const ObservableSet&);
IDump& operator>>(IDump& id, ObservableSet&);
copyright (c) 1994-2010 by Matthias Troyer
Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt)