120{
122
123 const std::string pyModuleName = "AthenaPython.Configurables";
124
125
126 RootUtils::PyGILStateEnsure ensure;
127 ATH_MSG_DEBUG(
"Importing module [" << pyModuleName <<
"]...");
128 PyObject*
module = PyImport_ImportModule(
const_cast<char*
>(pyModuleName.c_str()) );
129 if ( !module || !PyModule_Check( module ) ) {
130 ATH_MSG_ERROR(
"Could not import [" << pyModuleName <<
"] !!");
131 Py_XDECREF (module);
132#ifdef ATLAS_HAVE_CPYCPPYY
133 throw CPyCppyy::PyException();
134#else
135 throw std::runtime_error ("Python exception");
136#endif
137 }
138
139 const std::string pyClassName = "PyComponents";
141 pyClass = PyDict_GetItemString( PyModule_GetDict( module ),
142 const_cast<char*>( pyClassName.c_str() ) );
143
144
145 Py_XINCREF( pyClass );
146
147 if ( !pyClass ) {
149 << "] from module [" << pyModuleName << "] !!");
150 Py_XDECREF(pyClass);
151 Py_DECREF (module);
152 return StatusCode::FAILURE;
153 }
154
155 m_dict = PyObject_GetAttrString( pyClass,
156 const_cast<char*>( "instances" ) );
158 ATH_MSG_ERROR(
"Could not retrieve attribute [instances] from class ["
159 << pyClassName << "] !!");
160 Py_DECREF (pyClass);
161 Py_DECREF (module);
162 return StatusCode::FAILURE;
163 }
164 Py_DECREF(pyClass);
165
166
167
168
169 {
171 fancy_attr = PyDict_GetItemString(PyModule_GetDict(module),
172 (char*)"_install_fancy_attrs");
173
174 Py_XINCREF(fancy_attr);
175 if (!fancy_attr) {
176 PyErr_Clear();
178 ("could not retrieve function [_install_fancy_attrs] from module ["
179 << pyModuleName << "]");
180 } else {
181 PyObject* ret = PyObject_CallFunction(fancy_attr, NULL);
182 Py_XDECREF(ret);
183 }
184 Py_XDECREF(fancy_attr);
185 }
186 Py_DECREF (module);
187
188
189 const std::string pyRootFixes = "RootUtils.PyROOTFixes";
190 ATH_MSG_DEBUG(
"Importing module [" << pyRootFixes <<
"]...");
192 rootFixes = PyImport_ImportModule(const_cast<char*>(pyRootFixes.c_str()));
193 if ( !rootFixes || !PyModule_Check( rootFixes ) ) {
194 PyErr_Print();
195 PyErr_Clear();
198 << "Some problem may appear with some C++->python binded classes (YMMV)");
199 }
200 Py_XDECREF(rootFixes);
201 return StatusCode::SUCCESS;
202}
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)