NAIA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
SingleTreeChain.h
Go to the documentation of this file.
1 
9 #ifndef NAIA_SINGLETREECHAIN_H
10 #define NAIA_SINGLETREECHAIN_H
11 
12 // ROOT headers
13 #include "TChain.h"
14 #include "TTree.h"
15 
16 // NAIA headers
17 #include "Chain/Event.h"
18 #include "Chain/SkimTreeHandle.h"
19 #include "Containers/FileInfo.h"
20 #include "Containers/RTIInfo.h"
21 
22 namespace NAIA {
23 
32  friend class NtpSelector;
34 
35 public:
40  enum class AccessMode { Read, Write };
41 
48 
56  const FileInfo &GetEventFileInfo();
57 
65  const RTIInfo &GetEventRTIInfo();
66 
73  Event &GetEvent(unsigned long long iEv);
74 
82  Event &GetEventWithIndex(unsigned int run, unsigned int eventno);
83 
91  TChain *GetFileInfoTree();
92 
100  TChain *GetRTITree();
101 
109  void SetupBranches(bool isMC = false);
110 
123  SkimTreeHandle<SingleTreeChain> CreateSkimTree(const std::string &filename, const std::string &exclBranches);
124 
131  int Add(const std::string &filePath);
132 
139  void Clear() { m_event.Clear(); }
140 
148  int Fill();
149 
157  int FillRTI();
158 
166  int FillFileInfo();
167 
173  unsigned long int GetEntries();
174 
181  bool IsMC() { return m_data.chain->GetBranch(MCTruthBase::BranchName.c_str()); };
182 
187  void Print();
188 
197  int Write();
198 
204  void SetDirectory(TDirectory *directory);
205 
214  void SetEntryList(TEntryList *entryList, Option_t *option);
215 
216  class EventItr {
217  friend bool operator==(const EventItr &lhs, const EventItr &rhs);
218 
219  public:
220  EventItr(unsigned long long entry, SingleTreeChain *chain) : m_entry{entry}, m_chain{chain} {};
221 
222  // prefix increment operator
224  m_entry++;
225  return *this;
226  }
227  // postfix increment operator
229  EventItr old = *this;
230  operator++();
231  return old;
232  }
233  // prefix decrement operator
235  m_entry--;
236  return *this;
237  }
238  // postfix decrement operator
240  EventItr old = *this;
241  operator--();
242  return old;
243  }
244 
246 
247  private:
248  unsigned long long m_entry = 0;
250  };
251 
252  EventItr begin() { return {0, this}; }
253  EventItr end() { return {GetEntries() - 1, this}; }
254 
255 private:
256  unsigned long int m_iEv = 0;
258 
263 
267 
268  // in c++17 we would use a std::variant
269  union TC {
270  TTree *tree;
271  TChain *chain;
272  };
273 
274  TC m_data{};
275  TC m_rti{};
276  TC m_file{};
277 };
278 
280  return (lhs.m_entry == rhs.m_entry && lhs.m_chain == rhs.m_chain);
281 };
282 
284  return !(lhs == rhs);
285 };
286 
287 inline SingleTreeChain::EventItr begin(SingleTreeChain &chain) { return {0, &chain}; }
288 inline SingleTreeChain::EventItr end(SingleTreeChain &chain) { return {chain.GetEntries() - 1, &chain}; }
289 
290 } // namespace NAIA
291 
292 #endif
SkimTreeHandle< SingleTreeChain > CreateSkimTree(const std::string &filename, const std::string &exclBranches)
Create a new SkimTree handle object and setup all internal branches.
SkimTreeHandle class description.
Event & GetEvent(unsigned long long iEv)
Get the Event object.
Helper class to ease skimming operations.
TChain * GetRTITree()
Get the RTIInfo TTree object.
void SetDirectory(TDirectory *directory)
Set the TDirectory for the trees.
MCFileInfo * m_fileInfoMCPtr
needed for SetBranchAddress
bool operator==(const SingleTreeChain::EventItr &lhs, const SingleTreeChain::EventItr &rhs)
needed for SetBranchAddress
int FillRTI()
Fill the RTI data.
const FileInfo & GetEventFileInfo()
Get the FileInfo object associated with this event.
Event & GetEventWithIndex(unsigned int run, unsigned int eventno)
Get the Event object using the underlying index.
void Clear()
Clear all containers.
Definition: Event.cpp:164
TChain * GetFileInfoTree()
Get the FileInfo TTree object.
void Clear()
Clear all the event information.
Event object.
Definition: Event.h:20
void SetEntryList(TEntryList *entryList, Option_t *option)
Set an entry list for this tree.
SingleTreeChain(AccessMode mode=AccessMode::Read)
Construct a new Single Tree Chain object.
int Write()
Write the trees to disk.
EventItr(unsigned long long entry, SingleTreeChain *chain)
int Add(const std::string &filePath)
Add a file to the chain.
FileInfo container class description.
Container class for processed File information.
Definition: FileInfo.h:23
const RTIInfo & GetEventRTIInfo()
Get the RTIInfo object associated with this event.
bool IsMC()
Check if this file is a MC file.
SingleTreeChain::EventItr end(SingleTreeChain &chain)
Event class description.
friend bool operator==(const EventItr &lhs, const EventItr &rhs)
Container class for additional MC File information.
Definition: FileInfo.h:54
unsigned long int m_iEv
AccessMode
Simple enum to express whether we are in read or write mode.
RTIInfo * m_rtiInfoPtr
needed for SetBranchAddress
SingleTreeChain::EventItr begin(SingleTreeChain &chain)
int FillFileInfo()
Fill the FileInfo data.
unsigned long int GetEntries()
Get the total number of events.
static const std::string BranchName
Definition: MCTruth.h:142
int Fill()
Fill the event data.
RTIInfo container class description.
void SetupBranches(bool isMC=false)
Set all branch addresses for reading operations, or create all branches for writing operation...
bool operator!=(const SingleTreeChain::EventItr &lhs, const SingleTreeChain::EventItr &rhs)
Container class for RTI info.
Definition: RTIInfo.h:33
void Print()
Print all the chains.