ATLAS Offline Software
Loading...
Searching...
No Matches
RPyEvent.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
3 */
10
14#include "TPython.h"
15
16
17namespace xAOD::Experimental {
18
19
21PyObject* RPyEvent::pyRetrieve(const std::string& key) {
22
23 // Try to find the event format corresponding to this key.
24 const EventFormat* ef = this->inputEventFormat();
25 const EventFormatElement* efe = ((ef != nullptr) ? ef->get(key) : nullptr);
26 if (efe == nullptr) {
27 ef = this->outputEventFormat();
28 efe = ((ef != nullptr) ? ef->get(key) : nullptr);
29 if (efe == nullptr) {
30 // Fail if we can't find the type.
31 Py_INCREF(Py_None);
32 return Py_None;
33 }
34 }
35
36 // Convert the type to a std::type_info.
37 ::TClass* cl = TClass::GetClass(efe->className().c_str());
38 if (cl == nullptr) {
39 Py_INCREF(Py_None);
40 return Py_None;
41 }
42 const std::type_info* ti = cl->GetTypeInfo();
43 if (ti == nullptr) {
44 Py_INCREF(Py_None);
45 return Py_None;
46 }
47
48 // Get the object from the store as a void*.
49 static constexpr bool SILENT = true;
50 static constexpr bool METADATA = false;
51 void* obj ATLAS_THREAD_SAFE =
52 const_cast<void*>(this->getInputObject(key, *ti, SILENT, METADATA));
53 if (obj == nullptr) {
54 obj = this->getOutputObject(key, *ti, METADATA);
55 }
56 if (obj == nullptr) {
57 Py_INCREF(Py_None);
58 return Py_None;
59 }
60
61 // Convert to a PyObject.
62 return TPython::CPPInstance_FromVoidPtr(obj, efe->className().c_str());
63}
64
66bool RPyEvent::pyContains(const std::string& key, const std::string& type) {
67
68 // Try to access the dictionary of this type.
69 ::TClass* cl = ::TClass::GetClass(type.c_str());
70 if (cl == nullptr) {
71 ::Warning("xAOD::TPyEvent::pyContains", "Type name \"%s\" not known",
72 type.c_str());
73 return false;
74 }
75
76 // Check if the dictionary can return a type_info.
77 const std::type_info* ti = cl->GetTypeInfo();
78 if (ti == nullptr) {
79 ::Warning("xAOD::TPyEvent::pyContains",
80 "Type \"%s\" doesn't have a proper dictionary", type.c_str());
81 return false;
82 }
83
84 // Let the base class do the work.
85 static constexpr bool METADATA = false;
86 return REvent::contains(key, *ti, METADATA);
87}
88
90bool RPyEvent::pyTransientContains(const std::string& key,
91 const std::string& type) const {
92
93 // Try to access the dictionary of this type.
94 ::TClass* cl = ::TClass::GetClass(type.c_str());
95 if (cl == nullptr) {
96 ::Warning("xAOD::TPyEvent::pyTransientContains",
97 "Type name \"%s\" not known", type.c_str());
98 return false;
99 }
100
101 // Check if the dictionary can return a type_info:
102 const std::type_info* ti = cl->GetTypeInfo();
103 if (ti == nullptr) {
104 ::Warning("xAOD::TPyEvent::pyTransientContains",
105 "Type \"%s\" doesn't have a proper dictionary", type.c_str());
106 return false;
107 }
108
109 // Let the base class do the work:
110 return REvent::transientContains(key, *ti, kFALSE);
111}
112
113
114} // namespace xAOD::Experimental
_object PyObject
Python interface to xAOD::REvent.
Define macros for attributes used to control the static checker.
Class describing one branch of the ROOT file.
const std::string & className() const
Get the class name of this branch/key.
bool transientContains(const std::string &key) const
Function checking if an object is already in memory.
const EventFormat * outputEventFormat() const
Get information about the output objects.
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 * getOutputObject(SG::sgkey_t key, const std::type_info &ti) override
Function for retrieving an output object in a non-template way.
SG::SGKeyMap< BranchInfo > m_branches ATLAS_THREAD_SAFE
Map from hashed sgkey to BranchInfo.
Definition Event.h:358
bool pyTransientContains(const std::string &key, const std::string &type) const
Function checking if an object is already in memory.
Definition RPyEvent.cxx:90
bool pyContains(const std::string &key, const std::string &type)
Function checking if an object is available from the store.
Definition RPyEvent.cxx:66
PyObject * pyRetrieve(const std::string &key)
Return the object with a given key as a PyObject.
Definition RPyEvent.cxx:21
EventFormat_v1 EventFormat
Definition of the current event format version.
Definition EventFormat.h:16