PandaTree
IOUtils.h
1 #ifndef PandaTree_Interface_IOUtils_h
2 #define PandaTree_Interface_IOUtils_h
3 
4 #include "TString.h"
5 #include "TTree.h"
6 
7 #include <vector>
8 #include <iostream>
9 
10 namespace panda {
11  class ReaderObject;
12 
13  namespace utils {
14 
15  class BranchList;
16 
18 
24  class BranchName : public std::vector<TString> {
25  public:
26  BranchName() {}
27  BranchName(BranchName const&);
28  BranchName(char const*);
29  BranchName(std::string const& s) : BranchName(s.c_str()) {}
30  BranchName(TString const& s) : BranchName(s.Data()) {}
31  template<class InputIterator> BranchName(InputIterator begin, InputIterator end, bool isVeto) : std::vector<TString>(begin, end), isVeto_(isVeto) {}
33  operator TString() const;
35  TString fullName(TString const& objName = "") const;
37  bool isVeto() const { return isVeto_; }
39 
42  bool match(BranchName const&) const;
44 
48  bool in(BranchList const&) const;
50 
54  bool vetoed(BranchList const&) const;
55 
56  private:
57  bool isVeto_{false};
58  };
59 
61 
64  class BranchList : public std::vector<BranchName> {
65  public:
66  BranchList() {}
67  BranchList(std::initializer_list<value_type> il, const allocator_type& alloc = allocator_type()) : std::vector<BranchName>(il, alloc) {}
69  BranchList subList(TString const& objName) const;
71  bool matchesAny(BranchList const&) const;
73  BranchList& operator+=(BranchList const&);
75  void collapse();
77  BranchList fullNames(TString const& objName = "") const;
79  static BranchList makeList(TTree&);
81 
87  void setVerbosity(int i) { verbosity = i; }
89  int getVerbosity() const { return verbosity; }
90  private:
91  int verbosity{0};
92  };
93 
95 
101  Int_t checkStatus(TTree&, TString const& fullName, Bool_t status);
103 
110  Int_t setStatus(TTree&, TString const& objName, BranchName const& bName, BranchList const&);
112 
115  BranchName getStatus(TTree&, TString const& objName, BranchName const& bName);
117 
124  Int_t setAddress(TTree&, TString const& objName, BranchName const& bName, void* bPtr, BranchList const&, Bool_t setStatus);
126 
132  Int_t book(TTree&, TString const& objName, BranchName const& bName, TString const& size, char lType, void* bPtr, BranchList const&);
133  Int_t resetAddress(TTree&, TString const& objName, BranchName const& bName);
134 
135  template<class O>
136  Int_t
137  book(TTree& _tree, TString const& _objName, BranchName const& _bName, TString const& _objType, O** _bPtr, BranchList const& _bList)
138  {
139  // objName: electrons
140  // bName: tags
141  // objType: std::vector<int>
142 
143  if (!_bName.in(_bList))
144  return -1;
145 
146  _tree.Branch(_bName.fullName(_objName), _objType, _bPtr);
147 
148  return 0;
149  }
150 
152 
155  TTree*
156  makeDocTree(TString const& treeName, TString names[], UInt_t size);
157 
159 
165  class TNotify : public TObjArray {
166  public:
167  TNotify();
168  ~TNotify() {}
169  Bool_t Notify() override;
170  };
171 
173 
181  class BranchArrayUpdator : public TObject {
182  public:
185 
186  char const* GetName() const override;
187  Bool_t Notify() override;
188 
189  ReaderObject const& getObject() const { return obj_; }
190 
191  private:
192  ReaderObject& obj_;
193  TTree& tree_;
194  };
195 
197 
202  Bool_t removeBranchArrayUpdator(ReaderObject& obj, TTree& tree);
203 
204  }
205 }
206 
208 std::ostream& operator<<(std::ostream&, panda::utils::BranchName const&);
209 std::ostream& operator<<(std::ostream&, panda::utils::BranchList const&);
210 
211 #endif
TString fullName(TString const &objName="") const
Prepend the branch name with <objName.>.
Definition: IOUtils.cc:50
bool in(BranchList const &) const
Is the name included and not vetoed?
Definition: IOUtils.cc:96
List of branch names.
Definition: IOUtils.h:64
void setVerbosity(int i)
Set the verbosity level.
Definition: IOUtils.h:87
bool match(BranchName const &) const
Does the name match with the given name?
Definition: IOUtils.cc:72
bool vetoed(BranchList const &) const
Is the name included and vetoed?
Definition: IOUtils.cc:108
Automated branch list update for ReaderObjects.
Definition: IOUtils.h:181
bool isVeto() const
Did the name start with a &#39;!&#39;?
Definition: IOUtils.h:37
int getVerbosity() const
Get the verbosity level.
Definition: IOUtils.h:89
Tokenized branch name.
Definition: IOUtils.h:24
Definition: Array.h:11
Base class for objects that can be linked to an input tree directly.
Definition: ReaderObject.h:10
One big Notify() manager for all objects.
Definition: IOUtils.h:165