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 #include "NAIAVersion.h"
17 
18 namespace NAIA {
19 
27 template <class T> class SkimTreeHandle {
28 public:
37  SkimTreeHandle(std::unique_ptr<TFile> outFile, std::unique_ptr<T> chain, T *originalChain)
38  : m_outFile{std::move(outFile)}, m_chain{std::move(chain)}, m_originalChain{originalChain} {};
39 
45  int Fill() {
46 
47  if (!m_originalChain->IsMC()) {
48  static unsigned int lastSec = 0;
49  if (m_originalChain->GetEventRTIInfo().UTCTime != lastSec) {
50  lastSec = m_originalChain->GetEventRTIInfo().UTCTime;
51  m_chain->FillRTI();
52  }
53  }
54 
55  static unsigned int lastRun = 0;
56  if (m_originalChain->GetEventFileInfo().Run != lastRun) {
57  lastRun = m_originalChain->GetEventFileInfo().Run;
58  m_chain->FillFileInfo();
59  }
60 
61  m_originalChain->m_event.ForceReadAllBranches();
62  return m_chain->Fill();
63  }
64 
70  int Write() {
71  NAIA::Version versionHeader;
72  m_outFile->WriteTObject(&versionHeader, "VersionHeader");
73  return m_chain->Write();
74  }
75 
81  TFile *RootFile() { return m_outFile.get(); }
82 
83 private:
84  std::unique_ptr<TFile> m_outFile;
85  std::unique_ptr<T> m_chain;
87 };
88 } // namespace NAIA
89 
90 #endif // NAIA_SKIMTREEHANDLE_H
Helper class to ease skimming operations.
std::unique_ptr< T > m_chain
Container class for versioning info.
Definition: NAIAVersion.h:21
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.
NAIAVersion container class description.