TTTT Analysis  0.1
dataset.hpp
Go to the documentation of this file.
1 
31 #ifndef dataset_hpp
32 #define dataset_hpp
33 #include <iostream>
34 #include "value.hpp"
35 #include "container.hpp"
36 #include "log.hpp"
37 
38 namespace fv{
39 
40 typedef std::map<std::string, GenContainer*> ContainerSet;
41 
42 /*
43  * A DataSet is a generic source of data that is used to populate
44  * ObservedValues. For each ObservedValue, it is recommened that the DataSet
45  * have a field whose value is updated when the load_next() method is called. A
46  * pointer to this value is then passed during the creation of the
47  * ObservedValue. It is important, therefore, that the location in memory of
48  * the data not change from event to event.
49  */
50 class DataSet{
51  private:
52  void summary(){
53  INFO(GenValue::summary());
54  INFO(GenFunction::summary());
55  }
56 
57  protected:
58  ContainerSet containers;
59  virtual bool load_next() = 0;
60  virtual int get_events() = 0;
61  virtual int get_current_event() = 0;
62 
63  public:
64  void process(bool silent=false){
65  int events, current_event;
66  summary();
67  events = get_events();
68  if (!silent) std::cout << std::endl;
69  while( load_next() ){
70  current_event = get_current_event();
71  if (!silent) std::cout << "\rprocessing event: " << current_event+1 << "/" << events << std::flush;
72  GenValue::reset();
73  for(auto con : containers){
74  con.second->fill();
75  }
76  }
77  if (!silent) std::cout << " Finished!" << std::endl;
78  }
79 
80  virtual void save_all(){
81  for(auto container : containers)
82  container.second->save();
83  }
84 
85  GenContainer* register_container(GenContainer *container){
86  if (containers[container->get_name()] != nullptr){
87  CRITICAL("Container with name \""+container->get_name()+"\" already exists.", -1);
88  }
89  containers[container->get_name()] = container;
90  return container;
91  }
92 
93  GenContainer* get_container(std::string container_name){
94  GenContainer* c = containers[container_name];
95  if (c == nullptr){
96  CRITICAL("Request for container \"" << container_name << "\" failed. Doesn't exist.", -1);
97  }
98  return c;
99  }
100 };
101 }
102 #endif // dataset_hpp
The namespace containing all filval classes and functions.
Definition: api.hpp:6