ATLAS Offline Software
Loading...
Searching...
No Matches
RDataSourceEvent.cxx
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3//
4
5// Local include(s).
6#include "RDataSourceEvent.h"
7
8// xAOD include(s).
13
14// ROOT include(s).
15#include <TClass.h>
16#include <TTree.h>
17#include <TError.h>
18
19// System include(s).
20#include <functional>
21
22namespace xAOD {
23
24 std::vector< std::pair< std::string, std::string > >
26
27 // This makes sure that the input is connected to.
28 if( ( ! m_inTree ) && ( getEntry( 0 ) < 0 ) ) {
29 ::Error( "xAOD::RDataSourceEvent::columnAndTypeNames",
30 XAOD_MESSAGE( "No input file opened yet" ) );
31 throw std::runtime_error( "No input file opened yet" );
32 }
33
34 // A sanity check.
35 if( ! inputEventFormat() ) {
36 ::Error( "xAOD::RDataSourceEvent::columnAndTypeNames",
37 XAOD_MESSAGE( "No xAOD::EventFormat object available" ) );
38 throw std::runtime_error( "No xAOD::EventFormat object available" );
39 }
40
41 // The result object.
42 std::vector< std::pair< std::string, std::string > > result;
43
44 // Loop over the known objects.
47 for( ; ef_itr != ef_end; ++ef_itr ) {
48
49 // A convenient reference.
50 const xAOD::EventFormatElement& efe = ef_itr->second;
51
52 // Skip auxiliary containers.
53 if( efe.branchName().rfind( "Aux." ) ==
54 ( efe.branchName().size() - 4 ) ) {
55 continue;
56 }
57 // Skip dynamic branches.
58 if( efe.parentName() != "" ) {
59 continue;
60 }
61 // Skip unavailable branches.
62 if( ! m_inTree->GetBranch( efe.branchName().c_str() ) ) {
63 continue;
64 }
65 // Skip unknown types.
66 ::TClass* cl = ::TClass::GetClass( efe.className().c_str() );
67 if( ! cl ) {
68 continue;
69 }
70 // Skip auxiliary containers that are mislabeled.
71 if( cl->InheritsFrom( "SG::IConstAuxStore" ) ) {
72 continue;
73 }
74
75 // Make sure that we have a functional dictionary for the type.
76 const std::type_info* ti = cl->GetTypeInfo();
77 if( ! ti ) {
78 ::Warning( "xAOD::RDataSourceEvent::columnAndTypeNames",
79 "No std::type_info available for type %s (key=%s)",
80 cl->GetName(), efe.branchName().c_str() );
81 continue;
82 }
83
84 // And do one final check that we can really read this type.
85 static constexpr bool METADATA = false;
86 if( ! contains( efe.branchName(), *ti, METADATA ) ) {
87 continue;
88 }
89
90 // Remember this objects.
91 result.emplace_back( efe.branchName(), efe.className() );
92 }
93
94 // Return the collected results.
95 return result;
96 }
97
98 void* RDataSourceEvent::columnReader( std::string_view columnName,
99 const std::type_info& typeInfo ) {
100
101 // Make sure that this is the active event in the current thread.
102 setActive();
103
104 // Create/access the pointer for this object.
105 return &( m_objects[ std::make_pair( std::string( columnName ),
106 &typeInfo ) ] );
107 }
108
110
111 // Make sure that this is the active event in the current thread.
112 setActive();
113
114 // Switch to the new entry.
115 if( getEntry( entry ) < 0 ) {
116 ::Error( "xAOD::RDataSourceEvent::updateObjectsForEntry",
117 XAOD_MESSAGE( "Failed to get entry %lld" ), entry );
118 throw std::runtime_error( "Failed to get entry" );
119 }
120
121 // Loop over all "registered" objects.
122 for( auto& obj : m_objects ) {
123 // (Re-)Access this object.
124 static constexpr bool SILENT = false;
125 static constexpr bool METADATA = false;
126 obj.second = getInputObject( obj.first.first, *( obj.first.second ),
127 SILENT, METADATA );
128 }
129
130 // Return gracefully.
131 return;
132 }
133
134 std::size_t
136
137 return std::hash< std::string >()( key.first + key.second->name() );
138 }
139
140} // namespace xAOD
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Class describing one branch of the ROOT file.
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.
KeyedData_t::const_iterator const_iterator
Iterator for looping over the elements of the object.
const_iterator end() const
STL-like function for getting the end of the container.
const_iterator begin() const
STL-like function for getting the beginning of the container.
const EventFormat * inputEventFormat() const
Get information about the input objects.
bool contains(const std::string &key)
Function checking if an object is available from the store.
const void * getInputObject(SG::sgkey_t key, const std::type_info &ti, bool silent) override
Function for retrieving an input object in a non-template way.
void setActive() const
Set this event object as the currently active one.
Definition EventCore.cxx:54
std::size_t operator()(const Key_t &key) const
Function calculating the hash for this type.
void updateObjectsForEntry(Long64_t entry)
Update all objects in memory for a new event.
std::pair< std::string, const std::type_info * > Key_t
Type of the key used in the internal map of object pointers.
void * columnReader(std::string_view columnName, const std::type_info &typeInfo)
Get a "column reader", a pointer to a pointer to the object.
std::vector< std::pair< std::string, std::string > > columnAndTypeNames()
Get the available columm and type names from the input.
std::unordered_map< Key_t, const void *, key_hash > m_objects
Objects served to RDataFrame.
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0)
Function loading a given entry of the input TTree.
::TTree * m_inTree
The main tree that we are reading from.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.