NAIA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
SkimTreeHandle.h
Go to the documentation of this file.
1 
9 #ifndef NAIA_SKIMTREEHANDLE_H
10 #define NAIA_SKIMTREEHANDLE_H
11 
12 #include <memory>
13 
14 #include "TFile.h"
15 
16 namespace NAIA {
17 
25 template <class T> class SkimTreeHandle {
26 public:
35  SkimTreeHandle(std::unique_ptr<TFile> outFile, std::unique_ptr<T> chain, T *originalChain)
36  : m_outFile{std::move(outFile)}, m_chain{std::move(chain)}, m_originalChain{originalChain} {};
37 
43  int Fill() {
44  static unsigned int lastSec = 0;
45  if (m_originalChain->GetEventRTIInfo().UTCTime != lastSec) {
46  lastSec = m_originalChain->GetEventRTIInfo().UTCTime;
47  m_chain->FillRTI();
48  }
49 
50  static unsigned int lastRun = 0;
51  if (m_originalChain->GetEventFileInfo().Run != lastRun) {
52  lastRun = m_originalChain->GetEventFileInfo().Run;
53  m_chain->FillFileInfo();
54  }
55 
56  m_originalChain->m_event.ForceReadAllBranches();
57  return m_chain->Fill();
58  }
59 
65  int Write() { return m_chain->Write(); }
66 
72  TFile *RootFile() { return m_outFile.get(); }
73 
74 private:
75  std::unique_ptr<TFile> m_outFile;
76  std::unique_ptr<T> m_chain;
78 };
79 } // namespace NAIA
80 
81 #endif // NAIA_SKIMTREEHANDLE_H
Helper class to ease skimming operations.
std::unique_ptr< T > m_chain
std::unique_ptr< TFile > m_outFile
TFile * RootFile()
Get a non-owning pointer to the underlying rootfile.
SkimTreeHandle(std::unique_ptr< TFile > outFile, std::unique_ptr< T > chain, T *originalChain)
Construct a new SkimTreeHandle.
int Write()
Writes the skimmed tree on the output rootfile.
int Fill()
Fills the underlying event in the output tree.