ATLAS Offline Software
RDataSourceEvent.cxx
Go to the documentation of this file.
1 //
2 // Copyright (C) 2002-2019 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 
22 namespace xAOD {
23 
25  : TEvent( TEvent::kClassAccess ) {
26 
27  }
28 
29  std::vector< std::pair< std::string, std::string > >
31 
32  // This makes sure that the input is connected to.
33  if( ( ! m_inTree ) && ( getEntry( 0 ) < 0 ) ) {
34  ::Error( "xAOD::RDataSourceEvent::columnAndTypeNames",
35  XAOD_MESSAGE( "No input file opened yet" ) );
36  throw std::runtime_error( "No input file opened yet" );
37  }
38 
39  // A sanity check.
40  if( ! inputEventFormat() ) {
41  ::Error( "xAOD::RDataSourceEvent::columnAndTypeNames",
42  XAOD_MESSAGE( "No xAOD::EventFormat object available" ) );
43  throw std::runtime_error( "No xAOD::EventFormat object available" );
44  }
45 
46  // The result object.
47  std::vector< std::pair< std::string, std::string > > result;
48 
49  // Loop over the known objects.
52  for( ; ef_itr != ef_end; ++ef_itr ) {
53 
54  // A convenient reference.
55  const xAOD::EventFormatElement& efe = ef_itr->second;
56 
57  // Skip auxiliary containers.
58  if( efe.branchName().rfind( "Aux." ) ==
59  ( efe.branchName().size() - 4 ) ) {
60  continue;
61  }
62  // Skip dynamic branches.
63  if( efe.parentName() != "" ) {
64  continue;
65  }
66  // Skip unavailable branches.
67  if( ! m_inTree->GetBranch( efe.branchName().c_str() ) ) {
68  continue;
69  }
70  // Skip unknown types.
71  ::TClass* cl = ::TClass::GetClass( efe.className().c_str() );
72  if( ! cl ) {
73  continue;
74  }
75  // Skip auxiliary containers that are mislabeled.
76  if( cl->InheritsFrom( "SG::IConstAuxStore" ) ) {
77  continue;
78  }
79 
80  // Make sure that we have a functional dictionary for the type.
81  const std::type_info* ti = cl->GetTypeInfo();
82  if( ! ti ) {
83  ::Warning( "xAOD::RDataSourceEvent::columnAndTypeNames",
84  "No std::type_info available for type %s (key=%s)",
85  cl->GetName(), efe.branchName().c_str() );
86  continue;
87  }
88 
89  // And do one final check that we can really read this type.
90  if( ! contains( efe.branchName(), *ti ) ) {
91  continue;
92  }
93 
94  // Remember this objects.
95  result.emplace_back( efe.branchName(), efe.className() );
96  }
97 
98  // Return the collected results.
99  return result;
100  }
101 
102  void* RDataSourceEvent::columnReader( std::string_view columnName,
103  const std::type_info& typeInfo ) {
104 
105  // Make sure that this is the active event in the current thread.
106  setActive();
107 
108  // Create/access the pointer for this object.
109  return &( m_objects[ std::make_pair( std::string( columnName ),
110  &typeInfo ) ] );
111  }
112 
114 
115  // Make sure that this is the active event in the current thread.
116  setActive();
117 
118  // Switch to the new entry.
119  if( getEntry( entry ) < 0 ) {
120  ::Error( "xAOD::RDataSourceEvent::updateObjectsForEntry",
121  XAOD_MESSAGE( "Failed to get entry %lld" ), entry );
122  throw std::runtime_error( "Failed to get entry" );
123  }
124 
125  // Loop over all "registered" objects.
126  for( auto& obj : m_objects ) {
127  // (Re-)Access this object.
128  obj.second = getInputObject( obj.first.first, *( obj.first.second ) );
129  }
130 
131  // Return gracefully.
132  return;
133  }
134 
135  std::size_t
137 
138  return std::hash< std::string >()( key.first + key.second->name() );
139  }
140 
141 } // namespace xAOD
xAOD::EventFormat_v1::end
const_iterator end() const
STL-like function for getting the end of the container.
Definition: EventFormat_v1.cxx:163
get_generator_info.result
result
Definition: get_generator_info.py:21
xAOD::TEvent::getInputObject
const void * getInputObject(SG::sgkey_t key, const std::type_info &ti, bool silent=false) override
Function for retrieving an input object in a non-template way.
Definition: Control/xAODRootAccess/Root/TEvent.cxx:1938
xAOD::RDataSourceEvent::Key_t
std::pair< std::string, const std::type_info * > Key_t
Type of the key used in the internal map of object pointers.
Definition: RDataSourceEvent.h:47
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
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
Utils.h
xAOD::EventFormatElement::branchName
const std::string & branchName() const
Get the branch/key name.
Definition: EventFormatElement.cxx:30
xAOD::RDataSourceEvent::updateObjectsForEntry
void updateObjectsForEntry(Long64_t entry)
Update all objects in memory for a new event.
Definition: RDataSourceEvent.cxx:113
xAOD::RDataSourceEvent::m_objects
std::unordered_map< Key_t, const void *, key_hash > m_objects
Objects served to RDataFrame.
Definition: RDataSourceEvent.h:57
xAOD::EventFormat_v1::begin
const_iterator begin() const
STL-like function for getting the beginning of the container.
Definition: EventFormat_v1.cxx:158
xAOD::TEvent::m_inTree
::TTree * m_inTree
The main tree that we are reading from.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:429
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
Message.h
xAOD::RDataSourceEvent::key_hash::operator()
std::size_t operator()(const Key_t &key) const
Function calculating the hash for this type.
Definition: RDataSourceEvent.cxx:136
xAOD::RDataSourceEvent::RDataSourceEvent
RDataSourceEvent()
Default constructor.
Definition: RDataSourceEvent.cxx:24
xAOD::EventFormatElement::className
const std::string & className() const
Get the class name of this branch/key.
Definition: EventFormatElement.cxx:36
xAOD::TEvent::contains
::Bool_t contains(const std::string &key)
Function checking if an object is available from the store.
TObjectManager.h
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
xAOD::RDataSourceEvent::columnReader
void * columnReader(std::string_view columnName, const std::type_info &typeInfo)
Get a "column reader", a pointer to a pointer to the object.
Definition: RDataSourceEvent.cxx:102
xAOD::RDataSourceEvent::columnAndTypeNames
std::vector< std::pair< std::string, std::string > > columnAndTypeNames()
Get the available columm and type names from the input.
Definition: RDataSourceEvent.cxx:30
THolder.h
xAOD::TEvent::inputEventFormat
const EventFormat * inputEventFormat() const
Get information about the input objects.
Definition: Control/xAODRootAccess/Root/TEvent.cxx:1603
RDataSourceEvent.h
xAOD::EventFormat_v1::const_iterator
KeyedData_t::const_iterator const_iterator
Iterator for looping over the elements of the object.
Definition: EventFormat_v1.h:67
python.PyAthena.obj
obj
Definition: PyAthena.py:132
xAOD::TEvent::setActive
void setActive() const
Set this event object as the currently active one.
Definition: Control/xAODRootAccess/Root/TEvent.cxx:860
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37