MiniTreeDataSet.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef minitreedataset_h
  2. #define minitreedataset_h
  3. #include <string>
  4. #include <tuple>
  5. #include "filval/filval.hpp"
  6. #include "filval_root/filval_root.hpp"
  7. #include "MiniTree.hpp"
  8. using namespace std;
  9. using namespace filval;
  10. using namespace filval::root;
  11. class MiniTreeDataSet : public DataSet,
  12. public MiniTree{
  13. private:
  14. long next_entry;
  15. long nentries;
  16. bool load_next(){
  17. if (next_entry >= nentries) return false;
  18. fChain->GetEntry(next_entry);
  19. ++next_entry;
  20. return true;
  21. }
  22. int get_events(){
  23. return nentries;
  24. }
  25. int get_current_event(){
  26. return next_entry-1;
  27. }
  28. public:
  29. MiniTreeDataSet(TTree *tree)
  30. :MiniTree(tree){
  31. next_entry = 0;
  32. nentries = fChain->GetEntriesFast();
  33. }
  34. template <typename T>
  35. Value<T>* track_branch(const std::string& bname){
  36. T* bref = (T*) fChain->GetBranch(bname.c_str())->GetAddress();
  37. fChain->SetBranchStatus(bname.c_str(), true);
  38. cout << "Registering branch \"" << bname
  39. << "\" with address " << bref
  40. << " and type " << typeid(bref).name() << endl;
  41. return new ObservedValue<T>(bname, bref);
  42. }
  43. template <typename T>
  44. Value<T*>* track_branch_ptr(const std::string& bname){
  45. T* bref = (T*) fChain->GetBranch(bname.c_str())->GetAddress();
  46. fChain->SetBranchStatus(bname.c_str(), true);
  47. cout << "Registering pointer branch \"" << bname
  48. << "\" with address " << bref
  49. << " and type " << typeid(bref).name() << endl;
  50. return new PointerValue<T>(bname, bref);
  51. }
  52. void register_container(GenContainer* container){
  53. containers[container->get_name()] = container;
  54. }
  55. };
  56. #endif // minitreedataset_h