DAS  3.0
Das Analysis System
FriendUtils.h
Go to the documentation of this file.
1 
4 #pragma once
5 
10 #include <TChain.h>
11 #include <TFile.h>
12 #include <TFriendElement.h>
13 #include <TNotifyLink.h>
14 #include <TObjString.h>
15 
16 namespace Darwin::Tools {
17 
34 class ChainSlice : public TChain
35 {
36  Long64_t fBegin;
37  Long64_t fEnd;
38 
42  auto GetLast () const
43  {
44  return fEnd >= 0 ? std::min(fEnd, TChain::GetEntries())
45  : TChain::GetEntries();
46  }
47 
48 public:
49  // Disable copies.
50  ChainSlice (const ChainSlice&) = delete;
51 
57  ChainSlice (Long64_t begin = 0, Long64_t end = -1)
58  : fBegin(begin)
59  , fEnd(end)
60  {
61  // Force creation of the friends list. This controls friend handling in
62  // TChain::LoadTree, *also for the friends of the loaded TTree*. I
63  // consider this a bug in ROOT.
64  fFriends = new TList();
65  }
66 
73  ChainSlice (const char * name,
74  Long64_t begin = 0,
75  Long64_t end = -1,
76  const char * title = "")
77  : TChain(name, title)
78  , fBegin(begin)
79  , fEnd(end)
80  {
81  // Force creation of the friends list. This controls friend handling in
82  // TChain::LoadTree, *also for the friends of the loaded TTree*. I
83  // consider this a bug in ROOT.
84  fFriends = new TList();
85  }
86 
87  // Only to have something in the source file for linking purpose.
88  virtual ~ChainSlice ();
89 
93  Long64_t GetBegin () const { return fBegin; }
94 
98  Long64_t GetEnd () const { return fEnd; }
99 
105  void SetBegin (Long64_t begin) { fBegin = begin; }
106 
112  void SetEnd (Long64_t end) { fEnd = end; }
113 
118  Long64_t GetEntries () const override { return GetLast() - GetBegin(); }
119 
126  Long64_t GetEntriesFast () const override { return GetEntries(); }
127 
135  Int_t GetEntry (Long64_t entry, Int_t getall = 0) override
136  { return TChain::GetEntry(entry + GetBegin(), getall); }
137 
143  Long64_t GetReadEntry () const override { return TChain::GetReadEntry() - GetBegin(); }
144 
150  Long64_t GetReadEvent () const override { return GetReadEntry(); }
151 
157  Long64_t LoadTreeFriend (Long64_t entry, TTree * parent) override
158  { return TChain::LoadTreeFriend(entry + GetBegin(), parent); }
159 
163  void Print (Option_t *) const override;
164 
165  ClassDefOverride(ChainSlice, 1)
166 };
167 
172 class SlicedFriendElement : public TFriendElement
173 {
174  Long64_t fBegin = 0;
175  Long64_t fEnd = -1;
176 
182  TList * fTrees = nullptr;
183 
184  ChainSlice * fChain = nullptr;
185  bool fOwnsChain = false;
186  TNotifyLink<SlicedFriendElement> fNotify;
187 
188 public:
190  SlicedFriendElement (TTree * parent,
191  ChainSlice * friendChain,
192  const char * alias);
194 
195  static SlicedFriendElement * AddTo (TTree * tree,
196  ChainSlice * chain,
197  const char * alias);
198 
199  TTree * GetTree () override;
200  TFile * GetFile () override;
201 
208  TList * GetListOfTrees () const { return fTrees; }
209 
211  Long64_t GetBegin () const { return fBegin; }
212 
214  Long64_t GetEnd () const { return fEnd; }
215 
216  bool Notify () override;
217  void Print (Option_t * opt = 0) const override;
218 
219  ClassDefOverride(SlicedFriendElement, 1)
220 };
221 
222 } // namespace Darwin::Tools
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.name
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
Darwin::Tools::ChainSlice::LoadTreeFriend
Long64_t LoadTreeFriend(Long64_t entry, TTree *parent) override
Loads the requested entry, called from a friend tree.
Definition: FriendUtils.h:157
Darwin::Tools::ChainSlice::GetEntries
Long64_t GetEntries() const override
Return the total number of entries in the chain, taking the restrictions set by GetBegin and GetEnd i...
Definition: FriendUtils.h:118
Darwin::Tools::ChainSlice::~ChainSlice
virtual ~ChainSlice()
Darwin::Tools::SlicedFriendElement::Print
void Print(Option_t *opt=0) const override
Darwin::Tools::SlicedFriendElement::Notify
bool Notify() override
Darwin::Tools::SlicedFriendElement::fTrees
TList * fTrees
The list of trees in the chain.
Definition: FriendUtils.h:182
Darwin::Tools::SlicedFriendElement::AddTo
static SlicedFriendElement * AddTo(TTree *tree, ChainSlice *chain, const char *alias)
Darwin::Tools::SlicedFriendElement::SlicedFriendElement
SlicedFriendElement()
Definition: FriendUtils.h:189
Darwin::Tools::ChainSlice::GetReadEvent
Long64_t GetReadEvent() const override
Number of the currently-loaded entry.
Definition: FriendUtils.h:150
Darwin::Tools::ChainSlice::GetLast
auto GetLast() const
Definition: FriendUtils.h:42
Darwin::Tools::SlicedFriendElement::GetFile
TFile * GetFile() override
Darwin::Tools::SlicedFriendElement::GetBegin
Long64_t GetBegin() const
Index of the first entry to use in the chain.
Definition: FriendUtils.h:211
Darwin::Tools::SlicedFriendElement::fEnd
Long64_t fEnd
End parameter of the ChainSlice.
Definition: FriendUtils.h:175
Darwin::Tools::SlicedFriendElement::fBegin
Long64_t fBegin
Begin parameter of the ChainSlice.
Definition: FriendUtils.h:174
Darwin::Tools::SlicedFriendElement::SlicedFriendElement
SlicedFriendElement(TTree *parent, ChainSlice *friendChain, const char *alias)
Darwin::Tools::ChainSlice::GetBegin
Long64_t GetBegin() const
Returns the index of the first entry that will be used.
Definition: FriendUtils.h:93
Darwin::Tools::SlicedFriendElement::fNotify
TNotifyLink< SlicedFriendElement > fNotify
! See comment in GetTree().
Definition: FriendUtils.h:186
Darwin::Tools::ChainSlice::ChainSlice
ChainSlice(const char *name, Long64_t begin=0, Long64_t end=-1, const char *title="")
Creates a ChainSlice.
Definition: FriendUtils.h:73
Darwin::Tools::ChainSlice::fBegin
Long64_t fBegin
The first entry to use.
Definition: FriendUtils.h:36
Darwin::Tools::ChainSlice::GetEnd
Long64_t GetEnd() const
Returns the index past the last entry that will be used.
Definition: FriendUtils.h:98
Darwin::Tools::ChainSlice::fEnd
Long64_t fEnd
Past the last entry to use, or -1 to go till the end.
Definition: FriendUtils.h:37
Darwin::Tools::ChainSlice::SetEnd
void SetEnd(Long64_t end)
Changes the last entry to be loaded.
Definition: FriendUtils.h:112
Darwin::Tools
Classes and functions related to the framework.
Definition: Dict_rdict.cxx:990
Darwin::Tools::SlicedFriendElement::GetTree
TTree * GetTree() override
Darwin::Tools::ChainSlice
Wrapper around TChain that restricts available entries to a subset.
Definition: FriendUtils.h:35
Darwin::Tools::ChainSlice::GetEntry
Int_t GetEntry(Long64_t entry, Int_t getall=0) override
Get entry from the chain to memory.
Definition: FriendUtils.h:135
Darwin::Tools::SlicedFriendElement::GetListOfTrees
TList * GetListOfTrees() const
Returns the list of trees in the associated chain.
Definition: FriendUtils.h:208
Darwin::Tools::ChainSlice::SetBegin
void SetBegin(Long64_t begin)
Changes the first entry to be loaded.
Definition: FriendUtils.h:105
Darwin::Tools::ChainSlice::GetReadEntry
Long64_t GetReadEntry() const override
Number of the currently-loaded entry.
Definition: FriendUtils.h:143
Darwin::Tools::ChainSlice::ChainSlice
ChainSlice(Long64_t begin=0, Long64_t end=-1)
Creates a ChainSlice.
Definition: FriendUtils.h:57
Darwin::Tools::SlicedFriendElement::GetEnd
Long64_t GetEnd() const
Index of a past-the-end entry to use in the chain.
Definition: FriendUtils.h:214
Darwin::Tools::SlicedFriendElement::fChain
ChainSlice * fChain
! The loaded chain.
Definition: FriendUtils.h:184
Darwin::Tools::SlicedFriendElement
A TFriendElement that remembers the list of files and slicing of a ChainSlice.
Definition: FriendUtils.h:173
Darwin::Tools::SlicedFriendElement::fOwnsChain
bool fOwnsChain
! Whether we own the tree.
Definition: FriendUtils.h:185
Darwin::Tools::ChainSlice::Print
void Print(Option_t *) const override
Prints information about the current tree in the chain.
Darwin::Tools::ChainSlice::GetEntriesFast
Long64_t GetEntriesFast() const override
Return the total number of entries in the chain, taking the restrictions set by begin and end into ac...
Definition: FriendUtils.h:126
Darwin::Tools::ChainSlice::ChainSlice
ChainSlice(const ChainSlice &)=delete
Darwin::Tools::SlicedFriendElement::~SlicedFriendElement
virtual ~SlicedFriendElement()