NAIA  1.0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
NAIAChain.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 
31 class NAIAChain {
32  friend class NtpSelector;
33  friend class SkimTreeHandle<NAIAChain>;
34 
35 public:
40  enum class AccessMode { Read, Write };
41 
47  explicit NAIAChain(AccessMode mode = AccessMode::Read);
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 create_MC_branches = false);
119 
132  SkimTreeHandle<NAIAChain> 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() const { return m_isMC; };
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, NAIAChain *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  static bool CheckVersion(const std::string &filePath);
266 
267  bool m_isMC = false;
268  unsigned long int m_iEv = 0;
270 
275 
279 
280  // in c++17 we would use a std::variant
281  union TC {
282  TTree *tree;
283  TChain *chain;
284  };
285 
286  TC m_data{};
287  TC m_rti{};
288  TC m_file{};
289 };
290 
291 inline bool operator==(const NAIAChain::EventItr &lhs, const NAIAChain::EventItr &rhs) {
292  return (lhs.m_entry == rhs.m_entry && lhs.m_chain == rhs.m_chain);
293 }
294 
295 inline bool operator!=(const NAIAChain::EventItr &lhs, const NAIAChain::EventItr &rhs) { return !(lhs == rhs); }
296 
297 inline NAIAChain::EventItr begin(NAIAChain &chain) { return {0, &chain}; }
298 inline NAIAChain::EventItr end(NAIAChain &chain) { return {chain.GetEntries() - 1, &chain}; }
299 
300 } // namespace NAIA
301 
302 #endif
SkimTreeHandle class description.
EventItr end()
Definition: NAIAChain.h:262
void SetupBranches(bool create_MC_branches=false)
Set all branch addresses for reading operations, or create all branches for writing operation...
Definition: NAIAChain.cpp:227
Helper class to ease skimming operations.
const RTIInfo & GetEventRTIInfo()
Get the RTIInfo object associated with this event.
Definition: NAIAChain.cpp:48
AccessMode
Simple enum to express whether we are in read or write mode.
Definition: NAIAChain.h:40
EventItr begin()
Definition: NAIAChain.h:261
FileInfo * m_fileInfoPtr
Definition: NAIAChain.h:276
void SetEntryList(TEntryList *entryList, Option_t *option)
Set an entry list for this tree.
Definition: NAIAChain.cpp:303
unsigned long int GetEntries()
Get the total number of events.
Definition: NAIAChain.cpp:178
Event & GetEventWithIndex(unsigned int run, unsigned int eventno)
Get the Event object using the underlying index.
Definition: NAIAChain.cpp:44
NAIAChain(AccessMode mode=AccessMode::Read)
Construct a new Single Tree Chain object.
Definition: NAIAChain.cpp:11
void SetDirectory(TDirectory *directory)
Set the TDirectory for the trees.
Definition: NAIAChain.cpp:121
NAIAChain::EventItr begin(NAIAChain &chain)
Definition: NAIAChain.h:297
EventItr & operator++()
Definition: NAIAChain.h:232
RTIInfo m_rtiInfo
Definition: NAIAChain.h:273
AccessMode m_accessMode
Definition: NAIAChain.h:269
MCFileInfo * m_fileInfoMCPtr
needed for SetBranchAddress
Definition: NAIAChain.h:277
TChain * GetRTITree()
Get the RTIInfo TTree object.
Definition: NAIAChain.cpp:91
friend bool operator==(const EventItr &lhs, const EventItr &rhs)
Definition: NAIAChain.h:291
void Clear()
Clear all containers.
Definition: Event.cpp:179
bool operator==(const NAIAChain::EventItr &lhs, const NAIAChain::EventItr &rhs)
Definition: NAIAChain.h:291
needed for SetBranchAddress
Definition: NAIAChain.h:281
int FillFileInfo()
Fill the FileInfo data.
Definition: NAIAChain.cpp:167
Event object.
Definition: Event.h:20
TChain * GetFileInfoTree()
Get the FileInfo TTree object.
Definition: NAIAChain.cpp:106
const MCFileInfo & GetEventMCFileInfo()
Get the MCFileInfo object associated with this event.
Definition: NAIAChain.cpp:77
RTIInfo * m_rtiInfoPtr
needed for SetBranchAddress
Definition: NAIAChain.h:278
SkimTreeHandle< NAIAChain > CreateSkimTree(const std::string &filename, const std::string &exclBranches)
Create a new SkimTree handle object and setup all internal branches.
Definition: NAIAChain.cpp:278
EventItr operator--(int)
Definition: NAIAChain.h:248
EventItr & operator--()
Definition: NAIAChain.h:243
bool operator!=(const NAIAChain::EventItr &lhs, const NAIAChain::EventItr &rhs)
Definition: NAIAChain.h:295
void Print()
Print all the chains.
Definition: NAIAChain.cpp:189
void Clear()
Clear all the event information.
Definition: NAIAChain.h:148
int Add(const std::string &filePath)
Add a file to the chain.
Definition: NAIAChain.cpp:127
unsigned long int m_iEv
Definition: NAIAChain.h:268
int Fill()
Fill the event data.
Definition: NAIAChain.cpp:145
FileInfo container class description.
Container class for processed File information.
Definition: FileInfo.h:23
int FillRTI()
Fill the RTI data.
Definition: NAIAChain.cpp:156
Event class description.
Container class for additional MC File information.
Definition: FileInfo.h:54
const FileInfo & GetEventFileInfo()
Get the FileInfo object associated with this event.
Definition: NAIAChain.cpp:66
EventItr(unsigned long long entry, NAIAChain *chain)
Definition: NAIAChain.h:229
Event & GetEvent(unsigned long long iEv)
Get the Event object.
Definition: NAIAChain.cpp:28
FileInfo m_fileInfo
Definition: NAIAChain.h:271
MCFileInfo m_fileInfoMC
Definition: NAIAChain.h:272
static bool CheckVersion(const std::string &filePath)
Definition: NAIAChain.cpp:319
bool IsMC() const
Check if this file is a MC file.
Definition: NAIAChain.h:190
EventItr operator++(int)
Definition: NAIAChain.h:237
NAIAChain::EventItr end(NAIAChain &chain)
Definition: NAIAChain.h:298
int Write()
Write the trees to disk.
Definition: NAIAChain.cpp:204
unsigned long long m_entry
Definition: NAIAChain.h:257
RTIInfo container class description.
Container class for RTI info.
Definition: RTIInfo.h:33