• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Hans Dembinski
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6 
7 // clang-format off
8 
9 //[ getting_started_listing_05
10 
11 //////////////// Begin: put this in header file ////////////////////
12 
13 #include <algorithm>           // std::max_element
14 #include <boost/format.hpp>    // only needed for printing
15 #include <boost/histogram.hpp> // make_histogram, integer, indexed
16 #include <iostream>            // std::cout, std::endl
17 #include <sstream>             // std::ostringstream
18 #include <tuple>
19 #include <vector>
20 
21 // use this when axis configuration is fix to get highest performance
22 struct HolderOfStaticHistogram {
23   // put axis types here
24   using axes_t = std::tuple<
25     boost::histogram::axis::regular<>,
26     boost::histogram::axis::integer<>
27   >;
28   using hist_t = boost::histogram::histogram<axes_t>;
29   hist_t hist_;
30 };
31 
32 // use this when axis configuration should be flexible
33 struct HolderOfDynamicHistogram {
34   // put all axis types here that you are going to use
35   using axis_t = boost::histogram::axis::variant<
36     boost::histogram::axis::regular<>,
37     boost::histogram::axis::variable<>,
38     boost::histogram::axis::integer<>
39   >;
40   using axes_t = std::vector<axis_t>;
41   using hist_t = boost::histogram::histogram<axes_t>;
42   hist_t hist_;
43 };
44 
45 //////////////// End: put this in header file ////////////////////
46 
main()47 int main() {
48   using namespace boost::histogram;
49 
50   HolderOfStaticHistogram hs;
51   hs.hist_ = make_histogram(axis::regular<>(5, 0, 1), axis::integer<>(0, 3));
52   // now assign a different histogram
53   hs.hist_ = make_histogram(axis::regular<>(3, 1, 2), axis::integer<>(4, 6));
54   // hs.hist_ = make_histogram(axis::regular<>(5, 0, 1)); does not work;
55   // the static histogram cannot change the number or order of axis types
56 
57   HolderOfDynamicHistogram hd;
58   hd.hist_ = make_histogram(axis::regular<>(5, 0, 1), axis::integer<>(0, 3));
59   // now assign a different histogram
60   hd.hist_ = make_histogram(axis::regular<>(3, -1, 2));
61   // and assign another
62   hd.hist_ = make_histogram(axis::integer<>(0, 5), axis::integer<>(3, 5));
63 }
64 
65 //]
66