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 
160  ClassDefOverride(ChainSlice, 1)
161 };
162 
167 class SlicedFriendElement : public TFriendElement
168 {
169  Long64_t fBegin = 0;
170  Long64_t fEnd = -1;
171 
177  TList * fTrees = nullptr;
178 
179  ChainSlice * fChain = nullptr;
180  bool fOwnsChain = false;
181  TNotifyLink<SlicedFriendElement> fNotify;
182 
183 public:
185  SlicedFriendElement (TTree * parent,
186  ChainSlice * friendChain,
187  const char * alias);
188  virtual ~SlicedFriendElement();
189 
190  static SlicedFriendElement * AddTo (TTree * tree,
191  ChainSlice * chain,
192  const char * alias);
193 
194  TTree * GetTree () override;
195  TFile * GetFile () override;
196 
203  TList * GetListOfTrees () const { return fTrees; }
204 
206  Long64_t GetBegin () const { return fBegin; }
207 
209  Long64_t GetEnd () const { return fEnd; }
210 
211  bool Notify () override;
212  void Print (Option_t * opt = 0) const override;
213 
214  ClassDefOverride(SlicedFriendElement, 1)
215 };
216 
217 } // 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::SlicedFriendElement::~SlicedFriendElement
virtual ~SlicedFriendElement()
Destructor.
Definition: FriendUtils.cc:54
Darwin::Tools::ChainSlice::~ChainSlice
virtual ~ChainSlice()
Destructor.
Definition: FriendUtils.cc:20
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::SlicedFriendElement::Print
void Print(Option_t *opt=0) const override
Prints information about the trees in this friend element.
Definition: FriendUtils.cc:180
Darwin::Tools::SlicedFriendElement::Notify
bool Notify() override
Gets notification about modified TTrees.
Definition: FriendUtils.cc:164
Darwin::Tools::SlicedFriendElement::fTrees
TList * fTrees
The list of trees in the chain.
Definition: FriendUtils.h:177
Darwin::Tools::SlicedFriendElement::SlicedFriendElement
SlicedFriendElement()
Definition: FriendUtils.h:184
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::GetBegin
Long64_t GetBegin() const
Index of the first entry to use in the chain.
Definition: FriendUtils.h:206
Darwin::Tools::SlicedFriendElement::fEnd
Long64_t fEnd
End parameter of the ChainSlice.
Definition: FriendUtils.h:170
Darwin::Tools::SlicedFriendElement::fBegin
Long64_t fBegin
Begin parameter of the ChainSlice.
Definition: FriendUtils.h:169
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:181
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::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:203
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:209
Darwin::Tools::SlicedFriendElement::fChain
ChainSlice * fChain
! The loaded chain.
Definition: FriendUtils.h:179
Darwin::Tools::SlicedFriendElement
A TFriendElement that remembers the list of files and slicing of a ChainSlice.
Definition: FriendUtils.h:168
Darwin::Tools::SlicedFriendElement::fOwnsChain
bool fOwnsChain
! Whether we own the tree.
Definition: FriendUtils.h:180
Darwin::Tools::SlicedFriendElement::AddTo
static SlicedFriendElement * AddTo(TTree *tree, ChainSlice *chain, const char *alias)
Adds a ChainSlice as a friend to a TTree.
Definition: FriendUtils.cc:69
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::GetTree
TTree * GetTree() override
See TFriendElement::GetTree.
Definition: FriendUtils.cc:102
Darwin::Tools::SlicedFriendElement::GetFile
TFile * GetFile() override
Always returns nullptr, as ChainSlice cover multiple files.
Definition: FriendUtils.cc:156