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 
66 
74  const RTIInfo &GetEventRTIInfo();
75 
82  Event &GetEvent(unsigned long long iEv);
83 
91  Event &GetEventWithIndex(unsigned int run, unsigned int eventno);
92 
100  TChain *GetFileInfoTree();
101 
109  TChain *GetRTITree();
110 
118  void SetupBranches(bool isMC = false);
119 
132  SkimTreeHandle<SingleTreeChain> CreateSkimTree(const std::string &filename, const std::string &exclBranches);
133 
140  int Add(const std::string &filePath);
141 
148  void Clear() { m_event.Clear(); }
149 
157  int Fill();
158 
166  int FillRTI();
167 
175  int FillFileInfo();
176 
182  unsigned long int GetEntries();
183 
190  bool IsMC() { return m_data.chain->GetBranch(MCTruthBase::BranchName.c_str()); };
191 
196  void Print();
197 
206  int Write();
207 
213  void SetDirectory(TDirectory *directory);
214 
223  void SetEntryList(TEntryList *entryList, Option_t *option);
224 
225  class EventItr {
226  friend bool operator==(const EventItr &lhs, const EventItr &rhs);
227 
228  public:
229  EventItr(unsigned long long entry, SingleTreeChain *chain) : m_entry{entry}, m_chain{chain} {};
230 
231  // prefix increment operator
233  m_entry++;
234  return *this;
235  }
236  // postfix increment operator
238  EventItr old = *this;
239  operator++();
240  return old;
241  }
242  // prefix decrement operator
244  m_entry--;
245  return *this;
246  }
247  // postfix decrement operator
249  EventItr old = *this;
250  operator--();
251  return old;
252  }
253 
255 
256  private:
257  unsigned long long m_entry = 0;
259  };
260 
261  EventItr begin() { return {0, this}; }
262  EventItr end() { return {GetEntries() - 1, this}; }
263 
264 private:
265  unsigned long int m_iEv = 0;
267 
272 
276 
277  // in c++17 we would use a std::variant
278  union TC {
279  TTree *tree;
280  TChain *chain;
281  };
282 
283  TC m_data{};
284  TC m_rti{};
285  TC m_file{};
286 };
287 
289  return (lhs.m_entry == rhs.m_entry && lhs.m_chain == rhs.m_chain);
290 };
291 
293  return !(lhs == rhs);
294 };
295 
296 inline SingleTreeChain::EventItr begin(SingleTreeChain &chain) { return {0, &chain}; }
297 inline SingleTreeChain::EventItr end(SingleTreeChain &chain) { return {chain.GetEntries() - 1, &chain}; }
298 
299 } // namespace NAIA
300 
301 #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.
const MCFileInfo & GetEventMCFileInfo()
Get the MCFileInfo object associated with this event.
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.