ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
xAOD::TTreeMgr Class Reference

Class creating (a) transient tree(s) from xAOD files. More...

#include <TTreeMgr.h>

Collaboration diagram for xAOD::TTreeMgr:

Public Member Functions

 TTreeMgr (TEvent::EAuxMode mode=TEvent::kUndefinedAccess)
 Constructor, with an optional access mode selector. More...
 
TEventevent ()
 Get the TEvent object being used by the transient tree(s) More...
 
Function(s) setting up the input(s) for the tree(s)
StatusCode readFrom (::TFile *file, ::Bool_t useTreeCache=kTRUE, const char *treeName="CollectionTree")
 Read from the file given to the function. More...
 
Function(s) used for filtering the contents of the trees
StatusCode enableEventObj (const std::vector< std::string > &names)
 Object/container names that should be used in the event tree. More...
 
StatusCode suppressEventObj (const std::vector< std::string > &names)
 Object/container names that should be vetoed from the event tree. More...
 
StatusCode enableMetaObj (const std::vector< std::string > &names)
 Object/container names that should be used in the metadata tree. More...
 
StatusCode suppressMetaObj (const std::vector< std::string > &names)
 Object/container names that should be suppressed in the metadata tree. More...
 
Transient tree accessors
::TTree * eventTree ()
 Get a pointer to the transient event tree. More...
 
::TTree * metaTree ()
 Get a pointer to the transient metadata tree. More...
 

Private Attributes

std::unique_ptr< xAODTEventTreem_eventTree
 The transient event tree. More...
 
std::unique_ptr< xAODTMetaTreem_metaTree
 The transient metadata tree. More...
 
TEvent m_event
 The internal TEvent object. More...
 
std::string m_eventTreeName
 The name of the event tree to create. More...
 
std::vector< std::string > m_enableEventObj
 Names to select for the event tree. More...
 
std::vector< std::string > m_suppressEventObj
 Names to suppress from the event tree. More...
 
std::vector< std::string > m_enableMetaObj
 Names to select for the metatada tree. More...
 
std::vector< std::string > m_suppressMetaObj
 Names to suppress from the metadata tree. More...
 

Detailed Description

Class creating (a) transient tree(s) from xAOD files.

This class is a replacement for the many MakeTransientTree(...) functions used earlier. It can be used to create a transient tree describing the event tree, and one describing the metadata tree of the input file(s).

Author
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h

Definition at line 34 of file TTreeMgr.h.

Constructor & Destructor Documentation

◆ TTreeMgr()

xAOD::TTreeMgr::TTreeMgr ( TEvent::EAuxMode  mode = TEvent::kUndefinedAccess)

Constructor, with an optional access mode selector.

Definition at line 24 of file TTreeMgr.cxx.

25  : m_eventTree(), m_metaTree(),
26  m_event( mode ), m_eventTreeName( "UNKNOWN" ),
29 
30  }

Member Function Documentation

◆ enableEventObj()

StatusCode xAOD::TTreeMgr::enableEventObj ( const std::vector< std::string > &  names)

Object/container names that should be used in the event tree.

Definition at line 58 of file TTreeMgr.cxx.

58  {
59 
60  // If the event tree already exists, this call will have no effect:
61  if( m_eventTree ) {
62  ::Warning( "xAOD::TTreeMgr::enableEventObj",
63  "Event tree already created, can't filter its contents "
64  "anymore" );
65  return StatusCode::RECOVERABLE;
66  }
67 
68  // Remember the selection:
70 
71  // Return gracefully:
72  return StatusCode::SUCCESS;
73  }

◆ enableMetaObj()

StatusCode xAOD::TTreeMgr::enableMetaObj ( const std::vector< std::string > &  names)

Object/container names that should be used in the metadata tree.

Definition at line 94 of file TTreeMgr.cxx.

94  {
95 
96  // If the metadata tree already exists, this call will have no effect:
97  if( m_metaTree ) {
98  ::Warning( "xAOD::TTreeMgr::enableMetaObj",
99  "Metadata tree already created, can't filter its contents "
100  "anymore" );
101  return StatusCode::RECOVERABLE;
102  }
103 
104  // Remember the selection:
106 
107  // Return gracefully:
108  return StatusCode::SUCCESS;
109  }

◆ event()

TEvent & xAOD::TTreeMgr::event ( )

Get the TEvent object being used by the transient tree(s)

Definition at line 344 of file TTreeMgr.cxx.

344  {
345 
346  // Return a reference to the object:
347  return m_event;
348  }

◆ eventTree()

TTree * xAOD::TTreeMgr::eventTree ( )

Get a pointer to the transient event tree.

Definition at line 129 of file TTreeMgr.cxx.

129  {
130 
131  // If the tree is available, return it right away:
132  if( m_eventTree ) {
133  return m_eventTree.get();
134  }
135 
136  // Get the input file's format:
138  if( ! ef ) {
139  ::Error( "xAOD::TTreeMgr::eventTree",
140  XAOD_MESSAGE( "Couldn't get the input file's format "
141  "metadata. Did you use readFrom(...)?" ) );
142  return 0;
143  }
144 
145  {
146  // Remember which directory we are in now:
147  ::TDirectory* dir = gDirectory;
148 
149  // Create the transient tree:
150  gROOT->cd();
151  m_eventTree.reset( new xAODTEventTree( m_event,
152  m_eventTreeName.c_str() ) );
153 
154  // Go back to the original directory:
155  dir->cd();
156  }
157 
158  // Create a branch for each xAOD interface object:
159  for( auto ef_itr : *ef ) {
160 
161  // Convenience reference:
162  const xAOD::EventFormatElement& efe = ef_itr.second;
163 
164  // Just skip all branches ending in "Aux.":
165  if( efe.branchName().rfind( "Aux." ) ==
166  ( efe.branchName().size() - 4 ) ) {
167  continue;
168  }
169  // Also skip dynamic branches:
170  if( efe.parentName() != "" ) {
171  continue;
172  }
173 
174  // Apply the user specified filtering:
175  if( m_enableEventObj.size() ) {
176  bool accept = false;
177  for( const std::string& name : m_enableEventObj ) {
178  TRegexp re( name.c_str() );
179  Ssiz_t dummy = 0;
180  if( re.Index( efe.branchName().c_str(), &dummy ) >= 0 ) {
181  accept = true;
182  break;
183  }
184  }
185  if( ! accept ) {
186  continue;
187  }
188  }
189  {
190  bool accept = true;
191  for( const std::string& name : m_suppressEventObj ) {
192  TRegexp re( name.c_str() );
193  Ssiz_t dummy = 0;
194  if( re.Index( efe.branchName().c_str(), &dummy ) >= 0 ) {
195  accept = false;
196  break;
197  }
198  }
199  if( ! accept ) {
200  continue;
201  }
202  }
203 
204  // Don't bother if the branch is not available:
205  if( ! m_event.m_inTree->GetBranch( efe.branchName().c_str() ) ) {
206  continue;
207  }
208 
209  // Check if the class in question is known:
210  ::TClass* cl = ::TClass::GetClass( efe.className().c_str(), kTRUE,
211  kTRUE );
212  if( ! cl ) continue;
213 
214  // Don't add auxiliary store objects:
215  if( cl->InheritsFrom( "SG::IConstAuxStore" ) ) {
216  continue;
217  }
218 
219  // Check if we have a type-info for this class:
220  const std::type_info* ti = cl->GetTypeInfo();
221  if( ! ti ) {
222  ::Warning( "xAOD::TTreeMgr::eventTree",
223  "Couldn't find std::type_info object for type %s "
224  "(key=%s)", cl->GetName(), efe.branchName().c_str() );
225  continue;
226  }
227 
228  // Check if the object is actually available on the input:
229  if( ! m_event.contains( efe.branchName(), *ti ) ) {
230  continue;
231  }
232 
233  // If everything is right, let's make the branch:
234  auto br =
235  std::make_unique< xAODTEventBranch >( *m_eventTree, m_event, *ti,
236  efe.branchName().c_str(),
237  efe.className().c_str() );
238  m_eventTree->AddBranch( std::move( br ) );
239  }
240 
241  // Return the newly created object:
242  return m_eventTree.get();
243  }

◆ metaTree()

TTree * xAOD::TTreeMgr::metaTree ( )

Get a pointer to the transient metadata tree.

Definition at line 245 of file TTreeMgr.cxx.

245  {
246 
247  // If the tree is available, return it right away:
248  if( m_metaTree ) {
249  return m_metaTree.get();
250  }
251 
252  // Make sure that the persistent TTree is available:
253  if( ! m_event.m_inMetaTree ) {
254  ::Error( "xAOD::TTreeMgr::metaTree",
255  XAOD_MESSAGE( "Couldn't get the input file's metadata "
256  "tree. Did you use readFrom(...)?" ) );
257  return 0;
258  }
259 
260  {
261  // Remember which directory we are in now:
262  ::TDirectory* dir = gDirectory;
263 
264  // Create the transient tree:
265  gROOT->cd();
266  m_metaTree.reset( new xAODTMetaTree( m_event ) );
267 
268  // Go back to the original directory:
269  dir->cd();
270  }
271 
272  // Loop over the branches of the persistent metadata tree:
273  TObjArray* branches = m_event.m_inMetaTree->GetListOfBranches();
274  for( ::Int_t i = 0; i < branches->GetEntries(); ++i ) {
275 
276  // Access the branch object:
277  ::TBranch* br = dynamic_cast< ::TBranch* >( branches->At( i ) );
278  if( ! br ) {
279  ::Error( "xAOD::TTreeMgr::metaTree",
280  XAOD_MESSAGE( "Couldn't access branch %i as a TBranch" ),
281  i );
282  continue;
283  }
284 
285  // Skip the EventFormat branch. That must not be disturbed by the
286  // generic metadata handling.
287  if( ! strcmp( br->GetName(), "EventFormat" ) ) continue;
288 
289  // Apply the user specified filtering:
290  if( m_enableMetaObj.size() ) {
291  bool accept = false;
292  for( const std::string& name : m_enableMetaObj ) {
293  TRegexp re( name.c_str() );
294  Ssiz_t dummy = 0;
295  if( re.Index( br->GetName(), &dummy ) >= 0 ) {
296  accept = true;
297  break;
298  }
299  }
300  if( ! accept ) {
301  continue;
302  }
303  }
304  {
305  bool accept = true;
306  for( const std::string& name : m_suppressMetaObj ) {
307  TRegexp re( name.c_str() );
308  Ssiz_t dummy = 0;
309  if( re.Index( br->GetName(), &dummy ) >= 0 ) {
310  accept = false;
311  break;
312  }
313  }
314  if( ! accept ) {
315  continue;
316  }
317  }
318 
319  // Check whether we have a dictionary for this type:
320  ::TClass* cl = ::TClass::GetClass( br->GetClassName(), kTRUE, kTRUE );
321  if( ! cl ) continue;
322 
323  // Check if we have a type-info for this class:
324  const std::type_info* ti = cl->GetTypeInfo();
325  if( ! ti ) continue;
326 
327  // Don't add auxiliary store objects:
328  if( cl->InheritsFrom( "SG::IConstAuxStore" ) ) {
329  continue;
330  }
331 
332  // If everything is right, let's make the branch:
333  auto mbr =
334  std::make_unique< xAODTMetaBranch >( *m_metaTree, m_event, *ti,
335  br->GetName(),
336  br->GetClassName() );
337  m_metaTree->AddBranch( std::move( mbr ) );
338  }
339 
340  // Return the now created object:
341  return m_metaTree.get();
342  }

◆ readFrom()

StatusCode xAOD::TTreeMgr::readFrom ( ::TFile *  file,
::Bool_t  useTreeCache = kTRUE,
const char treeName = "CollectionTree" 
)

Read from the file given to the function.

Definition at line 32 of file TTreeMgr.cxx.

33  {
34 
35  // Delete the current transient tree(s):
36  m_eventTree.reset();
37  m_metaTree.reset();
38 
39  // Give the file to the TEvent object:
40  RETURN_CHECK( "xAOD::TTreeMgr::readFrom",
41  m_event.readFrom( file, useTreeCache, treeName ) );
42  // Load the first event from the file.
43  if( m_event.getEntry( 0 ) < 0 ) {
44  ::Error( "xAOD::TTreeMgr::readFrom",
45  "Couldn't load the first event from file \"%s\"",
46  file->GetName() );
47  return StatusCode::FAILURE;
48  }
49 
50  // Remember the event tree name:
52 
53  // Return gracefully:
54  return StatusCode::SUCCESS;
55  }

◆ suppressEventObj()

StatusCode xAOD::TTreeMgr::suppressEventObj ( const std::vector< std::string > &  names)

Object/container names that should be vetoed from the event tree.

Definition at line 76 of file TTreeMgr.cxx.

76  {
77 
78  // If the event tree already exists, this call will have no effect:
79  if( m_eventTree ) {
80  ::Warning( "xAOD::TTreeMgr::suppressEventObj",
81  "Event tree already created, can't filter its contents "
82  "anymore" );
83  return StatusCode::RECOVERABLE;
84  }
85 
86  // Remember the selection:
88 
89  // Return gracefully:
90  return StatusCode::SUCCESS;
91  }

◆ suppressMetaObj()

StatusCode xAOD::TTreeMgr::suppressMetaObj ( const std::vector< std::string > &  names)

Object/container names that should be suppressed in the metadata tree.

Definition at line 112 of file TTreeMgr.cxx.

112  {
113 
114  // If the metadata tree already exists, this call will have no effect:
115  if( m_metaTree ) {
116  ::Warning( "xAOD::TTreeMgr::suppressMetaObj",
117  "Metadata tree already created, can't filter its contents "
118  "anymore" );
119  return StatusCode::RECOVERABLE;
120  }
121 
122  // Remember the selection:
124 
125  // Return gracefully:
126  return StatusCode::SUCCESS;
127  }

Member Data Documentation

◆ m_enableEventObj

std::vector< std::string > xAOD::TTreeMgr::m_enableEventObj
private

Names to select for the event tree.

Definition at line 91 of file TTreeMgr.h.

◆ m_enableMetaObj

std::vector< std::string > xAOD::TTreeMgr::m_enableMetaObj
private

Names to select for the metatada tree.

Definition at line 96 of file TTreeMgr.h.

◆ m_event

TEvent xAOD::TTreeMgr::m_event
private

The internal TEvent object.

Definition at line 85 of file TTreeMgr.h.

◆ m_eventTree

std::unique_ptr< xAODTEventTree > xAOD::TTreeMgr::m_eventTree
private

The transient event tree.

Definition at line 80 of file TTreeMgr.h.

◆ m_eventTreeName

std::string xAOD::TTreeMgr::m_eventTreeName
private

The name of the event tree to create.

Definition at line 88 of file TTreeMgr.h.

◆ m_metaTree

std::unique_ptr< xAODTMetaTree > xAOD::TTreeMgr::m_metaTree
private

The transient metadata tree.

Definition at line 82 of file TTreeMgr.h.

◆ m_suppressEventObj

std::vector< std::string > xAOD::TTreeMgr::m_suppressEventObj
private

Names to suppress from the event tree.

Definition at line 93 of file TTreeMgr.h.

◆ m_suppressMetaObj

std::vector< std::string > xAOD::TTreeMgr::m_suppressMetaObj
private

Names to suppress from the metadata tree.

Definition at line 98 of file TTreeMgr.h.


The documentation for this class was generated from the following files:
xAOD::TTreeMgr::m_eventTree
std::unique_ptr< xAODTEventTree > m_eventTree
The transient event tree.
Definition: TTreeMgr.h:80
xAOD::TTreeMgr::m_enableEventObj
std::vector< std::string > m_enableEventObj
Names to select for the event tree.
Definition: TTreeMgr.h:91
RETURN_CHECK
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition: ReturnCheck.h:26
xAOD::name
name
Definition: TriggerMenuJson_v1.cxx:29
xAODTEventTree
Transient TTree for interactive xAOD event data access.
Definition: xAODTEventTree.h:37
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
xAOD::TTreeMgr::m_suppressMetaObj
std::vector< std::string > m_suppressMetaObj
Names to suppress from the metadata tree.
Definition: TTreeMgr.h:98
xAOD::EventFormatElement::parentName
const std::string & parentName() const
Get the name of the parent auxiliary object.
Definition: EventFormatElement.cxx:42
xAOD::EventFormatElement
Class describing one branch of the ROOT file.
Definition: EventFormatElement.h:39
XAOD_MESSAGE
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Definition: Control/xAODRootAccess/xAODRootAccess/tools/Message.h:19
xAOD::TTreeMgr::m_eventTreeName
std::string m_eventTreeName
The name of the event tree to create.
Definition: TTreeMgr.h:88
xAOD::EventFormatElement::branchName
const std::string & branchName() const
Get the branch/key name.
Definition: EventFormatElement.cxx:30
xAOD::TEvent::m_inMetaTree
::TTree * m_inMetaTree
Pointer to the metadata tree in the input file.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:440
xAODTMetaTree
Transient TTree for interactive xAOD metadata access.
Definition: xAODTMetaTree.h:37
runLayerRecalibration.branches
list branches
Definition: runLayerRecalibration.py:98
xAOD::TTreeMgr::m_event
TEvent m_event
The internal TEvent object.
Definition: TTreeMgr.h:85
xAOD::TEvent::m_inTree
::TTree * m_inTree
The main tree that we are reading from.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:429
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
lumiFormat.i
int i
Definition: lumiFormat.py:92
python.subdetectors.mmg.names
names
Definition: mmg.py:8
xAOD::TEvent::getEntry
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0)
Function loading a given entry of the input TTree.
Definition: Control/xAODRootAccess/Root/TEvent.cxx:1324
xAOD::TTreeMgr::m_metaTree
std::unique_ptr< xAODTMetaTree > m_metaTree
The transient metadata tree.
Definition: TTreeMgr.h:82
file
TFile * file
Definition: tile_monitor.h:29
dumpFileToPlots.treeName
string treeName
Definition: dumpFileToPlots.py:20
xAOD::EventFormatElement::className
const std::string & className() const
Get the class name of this branch/key.
Definition: EventFormatElement.cxx:36
python.xAODType.dummy
dummy
Definition: xAODType.py:4
Preparation.mode
mode
Definition: Preparation.py:96
xAOD::TEvent::contains
::Bool_t contains(const std::string &key)
Function checking if an object is available from the store.
beamspotman.dir
string dir
Definition: beamspotman.py:623
xAOD::TTreeMgr::m_suppressEventObj
std::vector< std::string > m_suppressEventObj
Names to suppress from the event tree.
Definition: TTreeMgr.h:93
xAOD::EventFormat
EventFormat_v1 EventFormat
Definition of the current event format version.
Definition: EventFormat.h:16
re
const boost::regex re(r_e)
xAOD::TEvent::inputEventFormat
const EventFormat * inputEventFormat() const
Get information about the input objects.
Definition: Control/xAODRootAccess/Root/TEvent.cxx:1603
xAOD::TEvent::readFrom
StatusCode readFrom(::TFile *file, Bool_t useTreeCache=kTRUE, const char *treeName=EVENT_TREE_NAME)
Connect the object to a new input file.
Definition: Control/xAODRootAccess/Root/TEvent.cxx:364
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
xAOD::TTreeMgr::m_enableMetaObj
std::vector< std::string > m_enableMetaObj
Names to select for the metatada tree.
Definition: TTreeMgr.h:96
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
LheEventFiller_Common.ef
ef
Definition: SFGen_i/share/common/LheEventFiller_Common.py:7
PlotCalibFromCool.br
br
Definition: PlotCalibFromCool.py:355