dataset.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef dataset_hpp
  2. #define dataset_hpp
  3. #include <iostream>
  4. #include "value.hpp"
  5. #include "container.hpp"
  6. #include "log.hpp"
  7. namespace fv{
  8. class DataSet{
  9. private:
  10. void summary(){
  11. INFO(GenValue::summary());
  12. INFO(GenFunction::summary());
  13. }
  14. protected:
  15. ContainerSet containers;
  16. virtual bool load_next() = 0;
  17. virtual int get_events() = 0;
  18. virtual int get_current_event() = 0;
  19. public:
  20. void process(){
  21. int events, current_event;
  22. summary();
  23. events = get_events();
  24. std::cout << std::endl;
  25. while( load_next() ){
  26. current_event = get_current_event();
  27. std::cout << "\rprocessing event: " << current_event+1 << "/" << events << std::flush;
  28. GenValue::reset();
  29. for(auto con : containers){
  30. con.second->fill();
  31. }
  32. }
  33. std::cout << " Finished!" << std::endl;
  34. }
  35. void add_container(GenContainer *container){
  36. containers[container->get_name()] = container;
  37. }
  38. GenContainer* get_container(std::string container_name){
  39. GenContainer* c = containers[container_name];
  40. if (c == nullptr){
  41. std::cout << "Request for container \"" << container_name << "\" failed. Doesn't exist." << std::endl;
  42. exit(-1);
  43. }
  44. return c;
  45. }
  46. };
  47. }
  48. #endif // dataset_hpp