MiniTreeDataSet.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 fv;
  10. using namespace fv::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. INFO("Registering branch \"" << bname
  39. << "\" with address " << bref
  40. << " and type " << typeid(bref).name());
  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. INFO("Registering pointer branch \"" << bname
  48. << "\" with address " << bref
  49. << " and type " << typeid(bref).name());
  50. return new PointerValue<T>(bname, bref);
  51. }
  52. void save_all(){
  53. for(auto container : containers){
  54. container.second->save_as("outfile", SaveOption::ROOT);
  55. }
  56. }
  57. };
  58. #endif // minitreedataset_h