NAIA  1.0.1
 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  m_originalChain->m_event.ForceReadAllBranches();
45  return m_chain->Fill();
46  }
47 
53  int Write() { // NOTE: We copy the whole RTI and FileInfo tree in the output chain
54  NAIA::Version versionHeader;
55  m_outFile->WriteTObject(&versionHeader, "VersionHeader");
56 
57  if (!m_originalChain->IsMC()) {
58  for (int ii = 0; ii < m_originalChain->GetRTITree()->GetEntries(); ii++) {
59  m_originalChain->GetRTITree()->GetEntry(ii);
60  m_chain->FillRTI();
61  }
62  m_chain->m_rti.tree->Write();
63  }
64 
65  for (int ii = 0; ii < m_originalChain->GetFileInfoTree()->GetEntries(); ii++) {
66  m_originalChain->GetFileInfoTree()->GetEntry(ii);
67  m_chain->FillFileInfo();
68  }
69  m_chain->m_file.tree->Write();
70 
71  return m_chain->Write();
72  }
73 
79  TFile *RootFile() { return m_outFile.get(); }
80 
81 private:
82  std::unique_ptr<TFile> m_outFile;
83  std::unique_ptr<T> m_chain;
85 };
86 } // namespace NAIA
87 
88 #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.