ALPSCore reference
accumulators.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
7 #include <alps/accumulators_.hpp>
10 
11 
12 namespace alps {
13  namespace accumulators {
14  namespace wrapped {
15 
16 
17  // default constructor
19  : m_cnt(new std::ptrdiff_t(1))
20  , m_ptr(new result_wrapper())
21  {}
22 
23  // constructor from raw accumulator
25  : m_cnt(new std::ptrdiff_t(1))
26  , m_ptr(arg)
27  {}
28 
29  // copy constructor
31  : m_cnt(rhs.m_cnt)
32  , m_ptr(rhs.m_ptr)
33  {
34  ++(*m_cnt);
35  }
36 
37  // constructor from hdf5
39  : m_cnt(new std::ptrdiff_t(1))
40  , m_ptr(new result_wrapper(ar))
41  {}
42 
43  // destructor
45  if (!--(*m_cnt)) {
46  delete m_cnt;
47  delete m_ptr;
48  }
49  }
50 
51  // count
53  return m_ptr->count();
54  }
55 
56  // mean
57  #define ALPS_ACCUMULATOR_MEAN_IMPL(r, data, T) \
58  template<> T virtual_result_wrapper<virtual_accumulator_wrapper>::mean_impl(T) const { \
59  return m_ptr->mean<T>(); \
60  }
62  #undef ALPS_ACCUMULATOR_MEAN_IMPL
63 
64  // error
65  #define ALPS_ACCUMULATOR_ERROR_IMPL(r, data, T) \
66  template<> T virtual_result_wrapper<virtual_accumulator_wrapper>::error_impl(T) const { \
67  return m_ptr->error<T>(); \
68  }
70  #undef ALPS_ACCUMULATOR_ERROR_IMPL
71 
72  // save
74  m_ptr->save(ar);
75  }
76 
77  // load
79  m_ptr->load(ar);
80  }
81 
82  // print
83  template<> void virtual_result_wrapper<virtual_accumulator_wrapper>::print(std::ostream & os) const {
84  m_ptr->print(os);
85  }
86 
87  // default constructor
89  : m_cnt(new std::ptrdiff_t(1))
90  , m_ptr(new accumulator_wrapper())
91  {}
92 
93  // constructor from raw accumulator
95  : m_cnt(new std::ptrdiff_t(1))
96  , m_ptr(arg)
97  {}
98 
99  // copy constructor
101  : m_cnt(rhs.m_cnt)
102  , m_ptr(rhs.m_ptr)
103  {
104  ++(*m_cnt);
105  }
106 
107  // constructor from hdf5
109  : m_cnt(new std::ptrdiff_t(1))
110  , m_ptr(new accumulator_wrapper(ar))
111  {}
112 
113  // destructor
115  if (!--(*m_cnt)) {
116  delete m_cnt;
117  delete m_ptr;
118  }
119  }
120 
121  // operator()
122  #define ALPS_ACCUMULATOR_OPERATOR_CALL(r, data, T) \
123  virtual_accumulator_wrapper & virtual_accumulator_wrapper::operator()(T const & value) { \
124  (*m_ptr)(value); \
125  return (*this); \
126  }
128  #undef ALPS_ACCUMULATOR_OPERATOR_CALL
129 
132  m_ptr->merge(*(rhs.m_ptr));
133  }
134 
135  virtual_accumulator_wrapper & virtual_accumulator_wrapper::operator=(std::shared_ptr<virtual_accumulator_wrapper> const & rhs){
136  (*m_ptr) = *(rhs->m_ptr);
137  return *this;
138  }
139 
140  // count
141  boost::uint64_t virtual_accumulator_wrapper::count() const{
142  return m_ptr->count();
143  }
144 
145  // mean
146  #define ALPS_ACCUMULATOR_MEAN_IMPL(r, data, T) \
147  T virtual_accumulator_wrapper::mean_impl(T) const { \
148  return m_ptr->mean<T>(); \
149  }
151  #undef ALPS_ACCUMULATOR_MEAN_IMPL
152 
153  // error
154  #define ALPS_ACCUMULATOR_ERROR_IMPL(r, data, T) \
155  T virtual_accumulator_wrapper::error_impl(T) const { \
156  return m_ptr->error<T>(); \
157  }
159  #undef ALPS_ACCUMULATOR_ERROR_IMPL
160 
161  // save
163  m_ptr->save(ar);
164  }
165 
166  // load
168  m_ptr->load(ar);
169  }
170 
171  // reset
173  m_ptr->reset();
174  }
175 
176  // result
177  std::shared_ptr<virtual_result_wrapper<virtual_accumulator_wrapper> > virtual_accumulator_wrapper::result() const {
178  return std::shared_ptr<virtual_result_wrapper<virtual_accumulator_wrapper> >(
180  );
181  }
182 
183  // print
184  void virtual_accumulator_wrapper::print(std::ostream & os) const {
185  m_ptr->print(os);
186  }
187 
188 #ifdef ALPS_HAVE_MPI
189  // collective_merge
190  void virtual_accumulator_wrapper::collective_merge(alps::mpi::communicator const & comm, int root) {
191  m_ptr->collective_merge(comm, root);
192  }
193  void virtual_accumulator_wrapper::collective_merge(alps::mpi::communicator const & comm, int root) const {
194  m_ptr->collective_merge(comm, root);
195  }
196 #endif
197  }
198  }
199 
200  #define ALPS_ACCUMULATOR_ADD_ACCUMULATOR(r, type, T) \
201  accumulator_set & operator<<(accumulator_set & set, const MeanAccumulator< T > & arg) { \
202  set.insert(arg.name(), std::shared_ptr<accumulators::wrapped::virtual_accumulator_wrapper>( \
203  new accumulators::wrapped::virtual_accumulator_wrapper(new accumulators::accumulator_wrapper( \
204  accumulators::impl::Accumulator< \
205  T , accumulators::mean_tag, accumulators::impl::Accumulator< \
206  T , accumulators::count_tag, accumulators::impl::AccumulatorBase< T > \
207  > \
208  >() \
209  ) \
210  ))); \
211  return set; \
212  } \
213  accumulator_set & operator<<(accumulator_set & set, const NoBinningAccumulator< T > & arg) { \
214  set.insert(arg.name(), std::shared_ptr<accumulators::wrapped::virtual_accumulator_wrapper>( \
215  new accumulators::wrapped::virtual_accumulator_wrapper(new accumulators::accumulator_wrapper( \
216  accumulators::impl::Accumulator< \
217  T , accumulators::error_tag, accumulators::impl::Accumulator< \
218  T , accumulators::mean_tag, accumulators::impl::Accumulator< \
219  T , accumulators::count_tag, accumulators::impl::AccumulatorBase< T > \
220  > \
221  > \
222  >() \
223  ) \
224  ))); \
225  return set; \
226  } \
227  accumulator_set & operator<<(accumulator_set & set, const LogBinningAccumulator< T > & arg) { \
228  set.insert(arg.name(), std::shared_ptr<accumulators::wrapped::virtual_accumulator_wrapper>( \
229  new accumulators::wrapped::virtual_accumulator_wrapper(new accumulators::accumulator_wrapper( \
230  accumulators::impl::Accumulator< \
231  T , accumulators::binning_analysis_tag, accumulators::impl::Accumulator< \
232  T , accumulators::error_tag, accumulators::impl::Accumulator< \
233  T , accumulators::mean_tag, accumulators::impl::Accumulator< \
234  T , accumulators::count_tag, accumulators::impl::AccumulatorBase< T > \
235  > \
236  > \
237  > \
238  >() \
239  ) \
240  ))); \
241  return set; \
242  } \
243  accumulator_set & operator<<(accumulator_set & set, const FullBinningAccumulator< T > & arg) { \
244  set.insert(arg.name(), std::shared_ptr<accumulators::wrapped::virtual_accumulator_wrapper>( \
245  new accumulators::wrapped::virtual_accumulator_wrapper(new accumulators::accumulator_wrapper( \
246  accumulators::impl::Accumulator< \
247  T , accumulators::max_num_binning_tag, accumulators::impl::Accumulator< \
248  T , accumulators::binning_analysis_tag, accumulators::impl::Accumulator< \
249  T , accumulators::error_tag, accumulators::impl::Accumulator< \
250  T , accumulators::mean_tag, accumulators::impl::Accumulator< \
251  T , accumulators::count_tag, accumulators::impl::AccumulatorBase< T > \
252  > \
253  > \
254  > \
255  > \
256  >() \
257  ) \
258  ))); \
259  return set; \
260  }
262  #undef ALPS_ACCUMULATOR_ADD_ACCUMULATOR
263 }
#define ALPS_ACCUMULATOR_ERROR_IMPL(r, data, T)
virtual_accumulator_wrapper & operator=(std::shared_ptr< virtual_accumulator_wrapper > const &rhs)
STL namespace.
void merge(const virtual_accumulator_wrapper &rhs)
Merge another accumulator into this one.
std::shared_ptr< virtual_result_wrapper< virtual_accumulator_wrapper > > result() const
Encapsulation of an MPI communicator and some communicator-related operations.
Definition: mpi.hpp:111
#define ALPS_ACCUMULATOR_OPERATOR_CALL(r, data, T)
#define ALPS_ACCUMULATOR_ADD_ACCUMULATOR(r, type, T)
#define ALPS_ACCUMULATOR_MEAN_IMPL(r, data, T)
void merge(const accumulator_wrapper &rhs_acc)
Merge another accumulator into this one.
void print(std::ostream &os, bool terse=false) const
std::shared_ptr< result_wrapper > result() const
boost::uint64_t count() const
#define ALPS_ACCUMULATOR_VALUE_TYPES_SEQ
void save(hdf5::archive &ar) const
void print(std::ostream &os, bool terse=false) const