7 #include <boost/preprocessor/tuple/to_seq.hpp> 8 #include <boost/preprocessor/seq/for_each.hpp> 10 #include <alps/config.hpp> 17 #define ALPS_ACCUMULATOR_VALUE_TYPES_SEQ BOOST_PP_TUPLE_TO_SEQ(ALPS_ACCUMULATOR_VALUE_TYPES_SIZE, (ALPS_ACCUMULATOR_VALUE_TYPES)) 20 namespace accumulators {
23 template<
typename T>
struct serializable_type {
24 virtual ~serializable_type() {}
25 virtual std::size_t rank()
const = 0;
26 virtual bool can_load(hdf5::archive & ar)
const = 0;
27 virtual T * create(hdf5::archive & ar)
const = 0;
30 template<
typename T,
typename A>
struct serializable_type_impl :
public serializable_type<T> {
31 std::size_t rank()
const {
34 bool can_load(hdf5::archive & ar)
const {
35 return A::can_load(ar);
37 T * create(hdf5::archive & )
const {
42 void register_predefined_serializable_types();
48 m_types.push_back(std::shared_ptr<detail::serializable_type<T> >(
new detail::serializable_type_impl<T, A>));
49 for (std::size_t i = m_types.size(); i > 1 && m_types[i - 1]->rank() > m_types[i - 2]->rank(); --i)
50 m_types[i - 1].
swap(m_types[i - 2]);
55 std::lock_guard<std::mutex> guard(m_types_mutex);
56 if (m_types.empty()) detail::register_predefined_serializable_types();
57 register_serializable_type_nolock<A>();
62 void register_predefined_serializable_types() {
63 #define ALPS_ACCUMULATOR_REGISTER_ACCUMULATOR(A) \ 64 accumulator_set::register_serializable_type_nolock<A::accumulator_type>(); \ 65 result_set::register_serializable_type_nolock<A::result_type>(); 67 #define ALPS_ACCUMULATOR_REGISTER_TYPE(r, data, T) \ 68 ALPS_ACCUMULATOR_REGISTER_ACCUMULATOR(MeanAccumulator<T>) \ 69 ALPS_ACCUMULATOR_REGISTER_ACCUMULATOR(NoBinningAccumulator<T>) \ 70 ALPS_ACCUMULATOR_REGISTER_ACCUMULATOR(LogBinningAccumulator<T>) \ 71 ALPS_ACCUMULATOR_REGISTER_ACCUMULATOR(FullBinningAccumulator<T>) 75 #undef ALPS_ACCUMULATOR_REGISTER_TYPE 76 #undef ALPS_ACCUMULATOR_REGISTER_ACCUMULATOR 86 if (it->second->count()!=0) {
87 ar[it->first] = *(it->second);
94 std::lock_guard<std::mutex> guard(m_types_mutex);
96 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it) {
98 for (
typename std::vector<std::shared_ptr<detail::serializable_type<T> > >::
const_iterator jt = m_types.begin()
102 if ((*jt)->can_load(ar)) {
103 operator[](*it) = std::shared_ptr<T>((*jt)->create(ar));
107 throw std::logic_error(
"The Accumulator/Result " + *it +
" cannot be unserilized" +
ALPS_STACKTRACE);
108 operator[](*it).load(ar);
#define ALPS_ACCUMULATOR_VALUE_TYPES_SEQ
void load(archive &ar, std::string const &path, T &value, std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t >=std::vector< std::size_t >())
void swap(params &p1, params &p2)
void set_context(std::string const &context)
void create_group(std::string path) const
#define ALPS_ACCUMULATOR_REGISTER_TYPE(r, data, T)
std::vector< std::string > list_children(std::string path) const
std::map< std::string, std::shared_ptr< T > >::const_iterator const_iterator
void save(archive &ar, std::string const &path, T const &value, std::vector< std::size_t >=std::vector< std::size_t >(), std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t >=std::vector< std::size_t >())