ATLAS Offline Software
Loading...
Searching...
No Matches
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::kClassAccess)
 Constructor, with an optional access mode selector.
TEventevent ()
 Get the TEvent object being used by the transient tree(s)
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.
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.
StatusCode suppressEventObj (const std::vector< std::string > &names)
 Object/container names that should be vetoed from the event tree.
StatusCode enableMetaObj (const std::vector< std::string > &names)
 Object/container names that should be used in the metadata tree.
StatusCode suppressMetaObj (const std::vector< std::string > &names)
 Object/container names that should be suppressed in the metadata tree.
Transient tree accessors
::TTree * eventTree ()
 Get a pointer to the transient event tree.
::TTree * metaTree ()
 Get a pointer to the transient metadata tree.

Private Attributes

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

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::kClassAccess)

Constructor, with an optional access mode selector.

Definition at line 24 of file TTreeMgr.cxx.

26 m_event( mode ), m_eventTreeName( "UNKNOWN" ),
29
30 }
std::unique_ptr< xAODTMetaTree > m_metaTree
The transient metadata tree.
Definition TTreeMgr.h:82
std::vector< std::string > m_enableEventObj
Names to select for the event tree.
Definition TTreeMgr.h:91
TEvent m_event
The internal TEvent object.
Definition TTreeMgr.h:85
std::vector< std::string > m_enableMetaObj
Names to select for the metatada tree.
Definition TTreeMgr.h:96
std::vector< std::string > m_suppressMetaObj
Names to suppress from the metadata tree.
Definition TTreeMgr.h:98
std::string m_eventTreeName
The name of the event tree to create.
Definition TTreeMgr.h:88
std::unique_ptr< xAODTEventTree > m_eventTree
The transient event tree.
Definition TTreeMgr.h:80
std::vector< std::string > m_suppressEventObj
Names to suppress from the event tree.
Definition TTreeMgr.h:93

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 }
static const SG::AuxElement::Accessor< std::vector< std::string > > names("thrNames")
Accessor for the names of the passed thresholds.

◆ 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 345 of file TTreeMgr.cxx.

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

◆ 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:
137 const EventFormat* ef = m_event.inputEventFormat();
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( const 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 static constexpr bool METADATA = false;
230 if( ! m_event.contains( efe.branchName(), *ti, METADATA ) ) {
231 continue;
232 }
233
234 // If everything is right, let's make the branch:
235 auto br =
236 std::make_unique< xAODTEventBranch >( *m_eventTree, m_event, *ti,
237 efe.branchName().c_str(),
238 efe.className().c_str() );
239 m_eventTree->AddBranch( std::move( br ) );
240 }
241
242 // Return the newly created object:
243 return m_eventTree.get();
244 }
const boost::regex re(r_e)
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
const std::string & branchName() const
Get the branch/key name.
const std::string & parentName() const
Get the name of the parent auxiliary object.
const std::string & className() const
Get the class name of this branch/key.
StatusCode accept(const xAOD::Muon *mu)
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
EventFormat_v1 EventFormat
Definition of the current event format version.
Definition EventFormat.h:16

◆ metaTree()

TTree * xAOD::TTreeMgr::metaTree ( )

Get a pointer to the transient metadata tree.

Definition at line 246 of file TTreeMgr.cxx.

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

◆ 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 }
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition ReturnCheck.h:26
TFile * file

◆ 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: