TTTT Analysis  0.1
container.hpp
1 #ifndef container_hpp
2 #define container_hpp
3 #include "value.hpp"
4 #include "filter.hpp"
5 #include <vector>
6 
7 namespace fv{
8 
9 enum SaveOption{
10  PNG = 0,
11  PDF = 1,
12  ROOT = 2
13 };
14 
16  private:
17  std::string name;
18  std::string desc;
19  std::vector<Filter*> filters;
20  protected:
21  virtual void _fill() = 0;
22  public:
23  GenContainer(const std::string name, const std::string& desc)
24  :name(name),desc(desc) { }
25 
26  GenContainer(const std::string name)
27  :GenContainer(name,"N/A"){ }
28 
29  void add_filter(GenValue* filter){
30  filters.push_back(dynamic_cast<Filter*>(filter));
31  }
32 
33  void fill(){
34  for (auto filter : filters){
35  if (!filter->get_value()) return;
36  }
37  _fill();
38  }
39 
40  void set_description(const std::string& description){
41  desc = description;
42  }
43  const std::string& get_name(){
44  return name;
45  }
46  virtual void save_as(const std::string& fname, const SaveOption& option) = 0;
47  virtual void save(const SaveOption& option=SaveOption::PNG) {
48  save_as(get_name(), option);
49  }
50 };
51 typedef std::map<std::string, GenContainer*> ContainerSet;
52 
53 template <typename H>
54 class Container : public GenContainer{
55  protected:
56  H* container;
57  public:
58  Container(const std::string& name, H* container)
59  :GenContainer(name),
60  container(container){ }
61  virtual H* get_container(){
62  return container;
63  }
64 
65 };
66 
67 template <typename T>
68 class ContainerVector : public Container<std::vector<T> >{
69  private:
70  Value<T>* value;
71 
72  void _fill(){
73  this->container->push_back(value->get_value());
74  }
75  public:
76  ContainerVector(const std::string& name, std::vector<T> *container, Value<T>* value)
77  :Container<std::vector<T> >(name, container),
78  value(value){ }
79  ContainerVector(const std::string& name, Value<T>* value)
80  :Container<std::vector<T> >(name, nullptr),
81  value(value){
82  this->container = new std::vector<T>();
83  }
84  void save_as(const std::string& fname) { }
85  virtual void save() { }
86 };
87 
88 template <typename T>
89 class ContainerMean : public Container<T>{
90  private:
91  Value<T>* value;
92  int count;
93  T sum;
94 
95  void _fill(){
96  count++;
97  sum += value->get_value();
98  }
99  public:
100  ContainerMean(const std::string& name, Value<T>* value)
101  :Container<std::vector<T> >(name, nullptr),
102  value(value){
103  this->container = new T();
104  }
105 
106  T* get_container(){
107  *(this->container) = sum/count;
108  return (this->container);
109  }
110  void save_as(const std::string& fname) { }
111  virtual void save() { }
112 };
113 
114 }
115 #endif // container_hpp
Definition: value.hpp:184
Definition: container.hpp:68
Definition: container.hpp:89
The namespace containing all filval classes and functions.
A generic value.
Definition: value.hpp:299
Definition: container.hpp:15
virtual T & get_value()=0
Calculate, if necessary, and return the value held by this object.
Definition: container.hpp:54