DAS  3.0
Das Analysis System
SlicedFriendElement

Description

A TFriendElement that remembers the list of files and slicing of a ChainSlice.

#include <FriendUtils.h>

+ Inheritance diagram for SlicedFriendElement:
+ Collaboration diagram for SlicedFriendElement:

Public Member Functions

 SlicedFriendElement ()
 
 SlicedFriendElement (TTree *parent, ChainSlice *friendChain, const char *alias)
 
virtual ~SlicedFriendElement ()
 
TTree * GetTree () override
 
TFile * GetFile () override
 
TList * GetListOfTrees () const
 
Long64_t GetBegin () const
 
Long64_t GetEnd () const
 
bool Notify () override
 
void Print (Option_t *opt=0) const override
 
 SlicedFriendElement ()
 
 SlicedFriendElement (TTree *parent, ChainSlice *friendChain, const char *alias)
 
virtual ~SlicedFriendElement ()
 
TTree * GetTree () override
 
TFile * GetFile () override
 
TList * GetListOfTrees () const
 
Long64_t GetBegin () const
 
Long64_t GetEnd () const
 
bool Notify () override
 
void Print (Option_t *opt=0) const override
 

Static Public Member Functions

static SlicedFriendElementAddTo (TTree *tree, ChainSlice *chain, const char *alias)
 
static SlicedFriendElementAddTo (TTree *tree, ChainSlice *chain, const char *alias)
 

Private Attributes

Long64_t fBegin = 0
 
Long64_t fEnd = -1
 
TList * fTrees = nullptr
 
ChainSlicefChain = nullptr
 
bool fOwnsChain = false
 
TNotifyLink< SlicedFriendElementfNotify
 

Constructor & Destructor Documentation

◆ SlicedFriendElement() [1/4]

SlicedFriendElement ( )
inline
189 : fNotify(this) {}

◆ SlicedFriendElement() [2/4]

SlicedFriendElement ( TTree *  parent,
ChainSlice friendChain,
const char *  alias 
)

Constructs an SlicedFriendElement without attaching it to the parent.

See the corresponding TFriendElement constructor.

41  : TFriendElement(parent, friendChain, alias)
42  , fBegin(friendChain->GetBegin())
43  , fEnd(friendChain->GetEnd())
44  , fTrees(new TList)
45  , fChain(friendChain)
46  , fOwnsChain(false)
47  , fNotify(this)
48 {
49  for (const TObject * el : *friendChain->GetListOfFiles()) {
50  // These are actually TChainElements, but we don't need to know
51  auto named = dynamic_cast<const TNamed *>(el);
52  if (!named)
53  // If this throws, ROOT changed how chains work
54  BOOST_THROW_EXCEPTION(
55  std::logic_error("unexpected chain structure"));
56 
57  auto name = TString(el->GetTitle()) + "?#" + el->GetName();
58  fTrees->Add(new TObjString(name));
59  }
60 }

◆ ~SlicedFriendElement() [1/2]

~SlicedFriendElement ( )
virtual

Destructor.

66 {
67  if (fOwnsChain)
68  delete fChain;
69  delete fTrees;
70 }

◆ SlicedFriendElement() [3/4]

SlicedFriendElement ( )
inline
189 : fNotify(this) {}

◆ SlicedFriendElement() [4/4]

SlicedFriendElement ( TTree *  parent,
ChainSlice friendChain,
const char *  alias 
)

◆ ~SlicedFriendElement() [2/2]

virtual ~SlicedFriendElement ( )
virtual

Member Function Documentation

◆ AddTo() [1/2]

SlicedFriendElement * AddTo ( TTree *  tree,
ChainSlice chain,
const char *  alias 
)
static

Adds a ChainSlice as a friend to a TTree.

The chain is added to the list of friends of the tree. Entry 0 in the tree is matched to entry 0 in the chain, taking the offset into account. The chain offset must be set before using this function or it will not be stored correctly.

Todo:
ROOT does a few extra checks when adding a friend. Easier to do if upstreaming.
83 {
84  // Make sure the tree has a list of friends. This requires some gymnastics
85  // when it's not there yet.
86  auto friends = tree->GetListOfFriends();
87  if (!friends) {
88  // Force the TTree to create its list of friends by adding one.
89  TTree t;
90  tree->AddFriend(&t);
91  tree->RemoveFriend(&t);
92  friends = tree->GetListOfFriends();
93  if (!friends)
94  // Normally the above will always work, but ROOT might change it at
95  // some point
96  BOOST_THROW_EXCEPTION(
97  std::logic_error("could not create TTree list of friends"));
98  }
99 
100  auto element = new SlicedFriendElement(tree, chain, alias);
101  friends->Add(element);
104 
105  return element;
106 }

◆ AddTo() [2/2]

static SlicedFriendElement* AddTo ( TTree *  tree,
ChainSlice chain,
const char *  alias 
)
static

◆ GetBegin() [1/2]

Long64_t GetBegin ( ) const
inline

Index of the first entry to use in the chain.

211 { return fBegin; }

◆ GetBegin() [2/2]

Long64_t GetBegin ( ) const
inline

Index of the first entry to use in the chain.

211 { return fBegin; }

◆ GetEnd() [1/2]

Long64_t GetEnd ( ) const
inline

Index of a past-the-end entry to use in the chain.

214 { return fEnd; }

◆ GetEnd() [2/2]

Long64_t GetEnd ( ) const
inline

Index of a past-the-end entry to use in the chain.

214 { return fEnd; }

◆ GetFile() [1/2]

TFile* GetFile ( )
override

◆ GetFile() [2/2]

TFile * GetFile ( )
override

Always returns nullptr, as ChainSlice cover multiple files.

168 {
169  return nullptr;
170 }

◆ GetListOfTrees() [1/2]

TList* GetListOfTrees ( ) const
inline

Returns the list of trees in the associated chain.

The list contains strings in a format suitable for TChain::AddFileInfoList.

208 { return fTrees; }

◆ GetListOfTrees() [2/2]

TList* GetListOfTrees ( ) const
inline

Returns the list of trees in the associated chain.

The list contains strings in a format suitable for TChain::AddFileInfoList.

208 { return fTrees; }

◆ GetTree() [1/2]

TTree * GetTree ( )
override

See TFriendElement::GetTree.

This returns a ChainSlice.

114 {
115  if (!fChain) {
116  fChain = new ChainSlice(GetName(), GetBegin(), GetEnd(), GetTitle());
117  fChain->RegisterExternalFriend(this);
118  fOwnsChain = true;
119  if (fTrees)
120  fChain->AddFileInfoList(fTrees);
121  } else {
122  // See the HACK section below.
123  ResetUpdated();
124  }
125 
126  // HACK: Ask the parent tree to notify us when a new tree is loaded.
127  //
128  // This is necessary when our parent is in a TChain. It allows us to work
129  // around a ROOT bug and force trigger internal TChain code to update
130  // branch addresses.
131  //
132  // If the parent is a simple TTree and we are the only friend, fNotify
133  // fires in two cases:
134  //
135  // * Upon loading of the parent TTree. This only ever happens once.
136  // * When *our* chain switches to another tree. This is what we need to
137  // catch.
138  //
139  // The sequence of events for the second case is as follows:
140  //
141  // 1. Our chain loads a new tree and calls MarkUpdated().
142  // 2. The parent tree checks IsUpdated() then ResetUpdated().
143  // 3. If IsUpdated() returned true, call our Notify().
144  // 4. Our Notify() calls MarkUpdated() again.
145  // 5. The parent's chain checks IsUpdated() then calls ResetUpdated(). If
146  // we hadn't marked ourselves as updated, IsUpdated() would return false
147  // here and nothing else would happen.
148  // 6. The parent's chain, seeing IsUpdated() == true, updates its branch
149  // addresses. This is the logic we need to trigger.
150  //
151  // If our parent tree isn't in a TChain, IsUpdated() will never get reset
152  // externally. We do it above to avoid Notify being called at every event
153  // (this function gets called for every event).
154  //
155  // We do not do this when the parent is a TChain because direct friends of
156  // a TChain update branches in step 2 above.
157  if (!fNotify.IsLinked() && !dynamic_cast<TChain *>(GetParentTree())) {
158  fNotify.PrependLink(*GetParentTree());
159  }
160 
161  return fChain;
162 }

◆ GetTree() [2/2]

TTree* GetTree ( )
override

◆ Notify() [1/2]

bool Notify ( )
override

Gets notification about modified TTrees.

176 {
177  // If the parent tree is part of a TChain, the chain may look at us next if
178  // configured properly. Even then it doesn't always do it, so we may stay
179  // in updated state for too long, triggering extraneous branch updates.
180  // Fixing the behaviour in ROOT would allow removing this hack.
181  //
182  // See the explanation in GetTree() for why we do this.
183  MarkUpdated();
184 
185  return true;
186 }

◆ Notify() [2/2]

bool Notify ( )
override

◆ Print() [1/2]

void Print ( Option_t *  opt = 0) const
override

◆ Print() [2/2]

void Print ( Option_t *  opt = 0) const
override

Prints information about the trees in this friend element.

192 {
193  TNamed::Print(opt);
194  if (fTrees) {
195  Printf("Contains %d trees, slice [%lld:%lld):", fTrees->GetSize(), fBegin, fEnd);
196  for (const TObject * tree : *fTrees)
197  Printf("- %s", tree->GetName());
198  } else
199  Printf("Contains no trees, slice [%lld:%lld)", fBegin, fEnd);
200 }

Member Data Documentation

◆ fBegin

Long64_t fBegin = 0
private

Begin parameter of the ChainSlice.

◆ fChain

ChainSlice * fChain = nullptr
private

! The loaded chain.

◆ fEnd

Long64_t fEnd = -1
private

End parameter of the ChainSlice.

◆ fNotify

TNotifyLink< SlicedFriendElement > fNotify
private

! See comment in GetTree().

◆ fOwnsChain

bool fOwnsChain = false
private

! Whether we own the tree.

◆ fTrees

TList * fTrees = nullptr
private

The list of trees in the chain.

The list contains strings in a format suitable for TChain::AddFileInfoList. We keep track of this separately from the chain because fChain isn't saved. This list does get saved.


The documentation for this class was generated from the following files:
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::SlicedFriendElement::fTrees
TList * fTrees
The list of trees in the chain.
Definition: FriendUtils.h:182
Darwin::Tools::SlicedFriendElement::SlicedFriendElement
SlicedFriendElement()
Definition: FriendUtils.h:189
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::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::GetEnd
Long64_t GetEnd() const
Returns the index past the last entry that will be used.
Definition: FriendUtils.h:98
Darwin::Tools::ChainSlice
Wrapper around TChain that restricts available entries to a subset.
Definition: FriendUtils.h:35
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::fOwnsChain
bool fOwnsChain
! Whether we own the tree.
Definition: FriendUtils.h:185