dataset.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. virtual void save_all(){
  36. for(auto container : containers)
  37. container.second->save();
  38. }
  39. void register_container(GenContainer *container){
  40. if (containers[container->get_name()] != nullptr){
  41. CRITICAL("Container with name \""+container->get_name()+"\" already exists.", -1);
  42. }
  43. containers[container->get_name()] = container;
  44. }
  45. GenContainer* get_container(std::string container_name){
  46. GenContainer* c = containers[container_name];
  47. if (c == nullptr){
  48. CRITICAL("Request for container \"" << container_name << "\" failed. Doesn't exist.", -1);
  49. }
  50. return c;
  51. }
  52. };
  53. }
  54. #endif // dataset_hpp