From 91bd456f6737d3703d45deffabd7248c1cfe5927 Mon Sep 17 00:00:00 2001 From: Frank Winklmeier <fwinkl@cern> Date: Tue, 8 Sep 2020 14:53:19 +0200 Subject: [PATCH] AthenaPython: Delete PyJobOptionsSvc Delete unused `PyJobOptionsSvc` and related files to avoid migrating it to the new `IOptionsSvc` interface. --- .../AthenaPython/AthenaPython/PyProperty.h | 128 --------- .../src/PyJobOptionsCatalogue.cxx | 166 ----------- .../AthenaPython/src/PyJobOptionsCatalogue.h | 111 ------- Control/AthenaPython/src/PyJobOptionsSvc.cxx | 256 ----------------- Control/AthenaPython/src/PyJobOptionsSvc.h | 150 ---------- Control/AthenaPython/src/PyProperty.cxx | 270 ------------------ .../src/components/AthenaPython_entries.cxx | 2 - 7 files changed, 1083 deletions(-) delete mode 100644 Control/AthenaPython/AthenaPython/PyProperty.h delete mode 100644 Control/AthenaPython/src/PyJobOptionsCatalogue.cxx delete mode 100644 Control/AthenaPython/src/PyJobOptionsCatalogue.h delete mode 100644 Control/AthenaPython/src/PyJobOptionsSvc.cxx delete mode 100644 Control/AthenaPython/src/PyJobOptionsSvc.h delete mode 100644 Control/AthenaPython/src/PyProperty.cxx diff --git a/Control/AthenaPython/AthenaPython/PyProperty.h b/Control/AthenaPython/AthenaPython/PyProperty.h deleted file mode 100644 index 94aeff7cb6c4..000000000000 --- a/Control/AthenaPython/AthenaPython/PyProperty.h +++ /dev/null @@ -1,128 +0,0 @@ -///////////////////////// -*- C++ -*- ///////////////////////////// - -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -// PyProperty.h -// Header file for class PyProperty -// Author: S.Binet<binet@cern.ch> -/////////////////////////////////////////////////////////////////// -#ifndef ATHENAPYTHON_PYPROPERTY_H -#define ATHENAPYTHON_PYPROPERTY_H 1 - -// python includes -//#include "Python.h" - -// STL includes -#include <typeinfo> - -// Gaudi includes -#include "Gaudi/Property.h" -#include "CxxUtils/checker_macros.h" - -// Forward declaration -struct _object; -typedef _object PyObject; - - -class ATLAS_NOT_THREAD_SAFE PyProperty - : public PropertyWithHandlers<> -{ - - /////////////////////////////////////////////////////////////////// - // Public methods: - /////////////////////////////////////////////////////////////////// - public: - - /// factory helper function - template <typename Klass> - static - PyProperty* create (const std::string& name, Klass* o); - - /// Constructor with parameters: - PyProperty (const std::string& name, - PyObject* obj); - - /// Destructor: - virtual ~PyProperty(); - - /// @c Property implementation - ///@{ - /// export the property value to the destination - virtual bool load (Gaudi::Details::PropertyBase& dest) const override; - - /// import the property value from source - virtual bool assign (const Gaudi::Details::PropertyBase& src) override; - - /// export the property value as a @c std::string - virtual std::string toString() const override; - - /// export the property value into a std::stream - virtual void toStream(std::ostream& out) const override; - - /// import the property value from a @c std::string - virtual StatusCode fromString (const std::string& value) override; - - /// clone: the usual "virtual constructor" pattern - virtual PyProperty* clone() const override; - - /// access underlying wrapped object - virtual void* object() const; - ///@} - - /////////////////////////////////////////////////////////////////// - // Const methods: - /////////////////////////////////////////////////////////////////// - - /// access underlying wrapped object as a python object - /// @return a new reference - PyObject* value() const; - - /////////////////////////////////////////////////////////////////// - // Non-const methods: - /////////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // Protected methods - /////////////////////////////////////////////////////////////////// -private: - - /// Default constructor: not implemented - PyProperty(); - - /// Copy constructor: - PyProperty( const PyProperty& rhs ); - - /// Assignment operator: - PyProperty& operator=( const PyProperty& rhs ); - - /// Constructor with parameters: - PyProperty (const std::string& name, - const std::type_info& type, - void* obj); - - /////////////////////////////////////////////////////////////////// - // Private data: - /////////////////////////////////////////////////////////////////// -private: - - /// the python object we are wrapping - /// (might be a genuine PyObject or a PyRoot one (ObjectProxy)) - PyObject *m_pyobj; -}; - -/////////////////////////////////////////////////////////////////// -// Inline methods: -/////////////////////////////////////////////////////////////////// -//std::ostream& operator<<( std::ostream& out, const PyProperty& o ); - -template <typename Klass> -inline -PyProperty* -PyProperty::create (const std::string& name, Klass* o) -{ - return new PyProperty (name, typeid(o), (void*)o); -} - -#endif //> !ATHENAPYTHON_PYPROPERTY_H diff --git a/Control/AthenaPython/src/PyJobOptionsCatalogue.cxx b/Control/AthenaPython/src/PyJobOptionsCatalogue.cxx deleted file mode 100644 index 1db168f58afa..000000000000 --- a/Control/AthenaPython/src/PyJobOptionsCatalogue.cxx +++ /dev/null @@ -1,166 +0,0 @@ -///////////////////////// -*- C++ -*- ///////////////////////////// - -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -// PyJobOptionsCatalogue.cxx -// Implementation file for class PyJobOptionsCatalogue -// Author: S.Binet<binet@cern.ch> -/////////////////////////////////////////////////////////////////// - -// Python includes -#include "Python.h" - -// AthenaPython includes -#include "PyJobOptionsCatalogue.h" - -// STL includes - - - -/////////////////////////////////////////////////////////////////// -// Public methods: -/////////////////////////////////////////////////////////////////// - -// Constructors -//////////////// -PyJobOptionsCatalogue::PyJobOptionsCatalogue() : - m_catalogue () -{} - -// Destructor -/////////////// -PyJobOptionsCatalogue::~PyJobOptionsCatalogue() -{ - for ( Objects_t::const_iterator - icat = m_catalogue.begin(), - icat_end = m_catalogue.end(); - icat != icat_end; - ++icat ) { - for ( Properties_t::const_iterator - iprop = icat->second.begin(), - iprop_end = icat->second.end(); - iprop != iprop_end; - ++iprop ) { - delete *iprop; - } - } -} - -/////////////////////////////////////////////////////////////////// -// Const methods: -/////////////////////////////////////////////////////////////////// - -const PyJobOptionsCatalogue::Properties_t* -PyJobOptionsCatalogue::properties (const std::string& client) const -{ - return find_properties (client); -} - -std::vector<std::string> -PyJobOptionsCatalogue::clients() const -{ - std::vector<std::string> result; - result.reserve (m_catalogue.size()); - for ( Objects_t::const_iterator - icat = m_catalogue.begin(), - icat_end = m_catalogue.end(); - icat != icat_end; - ++icat ) { - result.push_back (icat->first); - } - return result; -} - -/////////////////////////////////////////////////////////////////// -// Non-const methods: -/////////////////////////////////////////////////////////////////// - -/// add a property to the catalogue -StatusCode -PyJobOptionsCatalogue::add_property (const std::string& client, - const Gaudi::Details::PropertyBase* prop) -{ - if (!prop) { - return StatusCode::FAILURE; - } - - Properties_t* props = find_properties (client); - if (props) { - remove_property (client, prop->name()).ignore(); - props->push_back (prop); - } else { - m_catalogue[client] = Properties_t(1, prop); - } - return StatusCode::SUCCESS; -} - -/// remove a property from the catalogue -StatusCode -PyJobOptionsCatalogue::remove_property (const std::string& client, - const std::string& prop_name) -{ - Properties_t* props = find_properties (client); - if (props) { - Properties_t::iterator itr; - if (find_property (props, prop_name, itr)) { - delete *itr; - props->erase (itr); - } - } - return StatusCode::SUCCESS; -} - -/// find a particular property by name -const PyJobOptionsCatalogue::Property_t* -PyJobOptionsCatalogue::getProperty (const std::string& client, - const std::string& prop_name) const { - - Properties_t* props = find_properties (client); - if (!props) { return nullptr; } - - Properties_t::const_iterator itr; - for (itr = props->begin(); itr!=props->end(); ++itr) { - if (prop_name == (*itr)->name()) { - return *itr; - } - } - return nullptr; -} - -/////////////////////////////////////////////////////////////////// -// Protected methods: -/////////////////////////////////////////////////////////////////// - -/// retrieve the list of properties of a given client -PyJobOptionsCatalogue::Properties_t* -PyJobOptionsCatalogue::find_properties (const std::string& client) const -{ - PyJobOptionsCatalogue *self = const_cast<PyJobOptionsCatalogue*>(this); - Objects_t::iterator result = self->m_catalogue.find (client); - return result==self->m_catalogue.end() - ? NULL - : &result->second; -} - - -/// find a property among a list of properties -bool -PyJobOptionsCatalogue::find_property (Properties_t* props, - const std::string& name, - Properties_t::iterator& result) -{ - if (0==props) { - return false; - } - - for (result = props->begin(); result!=props->end(); ++result) { - // case sensitive... - if (name == (*result)->name()) { - return true; - } - } - return false; -} - diff --git a/Control/AthenaPython/src/PyJobOptionsCatalogue.h b/Control/AthenaPython/src/PyJobOptionsCatalogue.h deleted file mode 100644 index af56d7093607..000000000000 --- a/Control/AthenaPython/src/PyJobOptionsCatalogue.h +++ /dev/null @@ -1,111 +0,0 @@ -///////////////////////// -*- C++ -*- ///////////////////////////// - -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -// PyJobOptionsCatalogue.h -// Header file for class PyJobOptionsCatalogue -// Author: S.Binet<binet@cern.ch> -/////////////////////////////////////////////////////////////////// -#ifndef ATHENAPYTHON_PYJOBOPTIONSCATALOGUE_H -#define ATHENAPYTHON_PYJOBOPTIONSCATALOGUE_H 1 - -// STL includes -#include <vector> -#include <string> -#include <unordered_map> - -// Gaudi includes -#include "GaudiKernel/StatusCode.h" -#include "Gaudi/Property.h" -#include "CxxUtils/checker_macros.h" - -// Forward declaration - - -class ATLAS_NOT_THREAD_SAFE PyJobOptionsCatalogue -{ - /////////////////////////////////////////////////////////////////// - // Public typedefs - /////////////////////////////////////////////////////////////////// -public: - - typedef Gaudi::Details::PropertyBase Property_t; - typedef std::vector<const Property_t*> Properties_t; - typedef std::unordered_map<std::string, Properties_t> Objects_t; - - /////////////////////////////////////////////////////////////////// - // Public methods: - /////////////////////////////////////////////////////////////////// -public: - - /// Default constructor: - PyJobOptionsCatalogue(); - - /// Constructor with parameters: - - /// Destructor: - virtual ~PyJobOptionsCatalogue(); - - /////////////////////////////////////////////////////////////////// - // Const methods: - /////////////////////////////////////////////////////////////////// - - /// retrieve the list of all properties for a given client - const Properties_t* properties (const std::string& client) const; - - /// retrieve the list of names of all clients - /// FIXME: slow and inefficient - std::vector<std::string> clients() const; - - const Property_t* getProperty(const std::string& client, - const std::string& prop_name) const; - - /////////////////////////////////////////////////////////////////// - // Non-const methods: - /////////////////////////////////////////////////////////////////// - - /// add a property to the catalogue - StatusCode - add_property (const std::string& client, const Gaudi::Details::PropertyBase* prop); - - /// remove a property from the catalogue - StatusCode - remove_property (const std::string& client, const std::string& prop_name); - - /////////////////////////////////////////////////////////////////// - // Private methods - /////////////////////////////////////////////////////////////////// - private: - - /// Copy constructor: - PyJobOptionsCatalogue( const PyJobOptionsCatalogue& rhs ); - - /// Assignment operator: - PyJobOptionsCatalogue& operator=( const PyJobOptionsCatalogue& rhs ); - - /// retrieve the list of properties of a given client - Properties_t* find_properties (const std::string& client) const; - - /// find a property among a list of properties - bool find_property (Properties_t* props, - const std::string& name, - Properties_t::iterator& result); - - /////////////////////////////////////////////////////////////////// - // Private data: - /////////////////////////////////////////////////////////////////// -private: - - Objects_t m_catalogue; -}; - -/////////////////////////////////////////////////////////////////// -// Inline methods: -/////////////////////////////////////////////////////////////////// -//std::ostream& operator<<( std::ostream& out, const PyJobOptionsCatalogue& o ); - - - -#endif //> !ATHENAPYTHON_PYJOBOPTIONSCATALOGUE_H diff --git a/Control/AthenaPython/src/PyJobOptionsSvc.cxx b/Control/AthenaPython/src/PyJobOptionsSvc.cxx deleted file mode 100644 index cb30ddd20270..000000000000 --- a/Control/AthenaPython/src/PyJobOptionsSvc.cxx +++ /dev/null @@ -1,256 +0,0 @@ -///////////////////////// -*- C++ -*- ///////////////////////////// - -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -// PyJobOptionsSvc.cxx -// Implementation file for class PyJobOptionsSvc -// Author: S.Binet<binet@cern.ch> -/////////////////////////////////////////////////////////////////// - -#include "Python.h" - -// AthenaPython includes -#include "PyJobOptionsSvc.h" -#include "AthenaPython/PyProperty.h" -#include "AthenaPython/PyAthenaUtils.h" - -// STL includes - -// FrameWork includes -#include "Gaudi/Property.h" -#include "GaudiKernel/System.h" - -// PyRoot -#include "TPython.h" - -typedef PyJobOptionsCatalogue::Property_t Property_t; -typedef PyJobOptionsCatalogue::Properties_t Properties_t; -typedef PyJobOptionsCatalogue::Objects_t Objects_t; - -/////////////////////////////////////////////////////////////////// -// Public methods: -/////////////////////////////////////////////////////////////////// - -// Constructors -//////////////// -PyJobOptionsSvc::PyJobOptionsSvc (const std::string& name, - ISvcLocator* pSvcLocator) - : base_class (name, pSvcLocator), - // m_pmgr (), - // m_source_path(), - // m_source_type(), - // m_dir_search_path(), - m_catalogue() -{ - // - // Property declaration - // - //declareProperty( "Property", m_nProperty ); - - { // bwd-compat with Gaudi joboptionssvc - std::string tmp =System::getEnv ("JOBOPTSEARCHPATH"); - if (!tmp.empty() && ("UNKNOWN" != tmp)) { - m_dir_search_path = tmp; - } - } - - { // bwd-compat with Gaudi joboptionssvc - std::string tmp =System::getEnv ("JOBOPTSDUMPFILE"); - if (!tmp.empty() && ("UNKNOWN" != tmp)) { - m_dump = tmp; - } - } - - // m_pmgr.declareProperty ("TYPE", - // m_source_type = "NONE", - // "type of the joboptions to parse (txt,py,pickle)"); - // m_pmgr.declareProperty ("PATH", - // m_source_path, - // "path to the joboptions to parse"); - // m_pmgr.declareProperty ("SEARCHPATH", - // m_dir_search_path, - // "list of directory-paths to look for joboptions"); - // m_pmgr.declareProperty ("DUMPFILE", - // m_dump, - // "name of a file where to dump the list of options"); - -} - -// Athena Service's Hooks -//////////////////////////// -StatusCode PyJobOptionsSvc::initialize() -{ - StatusCode sc = StatusCode::SUCCESS; - ATH_MSG_INFO ("Initializing " << name() << "..."); - - // read the job options if needed - if (m_source_type != "NONE") { - sc = this->readOptions (m_source_path, m_dir_search_path); - if (!sc.isSuccess()) { - ATH_MSG_WARNING ("problem while reading options !"); - } - } - - return sc; -} - -StatusCode PyJobOptionsSvc::finalize() -{ - ATH_MSG_INFO ("Finalizing " << name() << "..."); - - return StatusCode::SUCCESS; -} - -/** Override default properties of the calling client - * @param client Name of the client algorithm or service - * @param me Address of the interface IProperty of the client - */ -StatusCode -PyJobOptionsSvc::setMyProperties (const std::string& client, - IProperty* component) -{ - const Properties_t* props = m_catalogue.properties (client); - if (!props || !component) { - return StatusCode::SUCCESS; - } - - bool allgood = true; - for (Properties_t::const_iterator - iprop = props->begin(), - iend = props->end(); - iprop != iend; - ++iprop) { - if (!component->setProperty (**iprop).isSuccess()) { - ATH_MSG_ERROR ("Unable to set the property '" - << (*iprop)->name() << "'" - << " of '" << client << "'." - << endmsg - << "Check option and algorithm names, type and bounds."); - allgood = false; - } - } - - return allgood - ? StatusCode::SUCCESS - : StatusCode::FAILURE; -} - -/// Add a property into the JobOptions catalog -StatusCode -PyJobOptionsSvc::addPropertyToCatalogue (const std::string& client, - const Gaudi::Details::PropertyBase& property) -{ - ATH_MSG_VERBOSE ("::addPropToCat (client=[" << client << "], prop=[" - << property.name() << ", " - << System::typeinfoName(*property.type_info()) << "], " - << "prop_val=[" - << property.toString() << "])..."); - - const PyProperty* pyprop = dynamic_cast<const PyProperty*>(&property); - if (pyprop) { - return m_catalogue.add_property (client, pyprop->clone()); - } - - Gaudi::Details::PropertyBase *p = new StringProperty (property.name(), ""); - if (!property.load (*p)) { - delete p; p = 0; - return StatusCode::FAILURE; - } - return m_catalogue.add_property (client, p); -} - -/// Remove a property from the JobOptions catalog -StatusCode -PyJobOptionsSvc::removePropertyFromCatalogue (const std::string& client, - const std::string& name) -{ - return m_catalogue.remove_property (client, name); -} - -/// Get the properties associated to a given client -const Properties_t* -PyJobOptionsSvc::getProperties (const std::string& client) const -{ - return m_catalogue.properties (client); -} - -const Property_t* -PyJobOptionsSvc::getClientProperty( const std::string& client, - const std::string& name ) const - { - return m_catalogue.getProperty( client, name ); - } - - -/// Get the list of clients -std::vector<std::string> -PyJobOptionsSvc::getClients() const -{ - return m_catalogue.clients(); -} - -/** look for file 'File' into search path 'Path' - * and read it to update existing JobOptionsCatalogue - * @param File file name - * @param Path search path - * @return status code - */ -StatusCode -PyJobOptionsSvc::readOptions (const std::string& file, - const std::string& path) -{ - // use the default non-empty path (if any) if no path specified - if (path.empty() && !m_dir_search_path.empty()) { - return readOptions (file, m_dir_search_path); - } - - ATH_MSG_DEBUG ("Job-options read from the file [" << file << "]"); - // do the parsing --> invoke python - TPython::LoadMacro (file.c_str()); - if ( PyErr_Occurred() ) { - PyAthena::throw_py_exception(); - } - - ATH_MSG_INFO ("Job options successfully read in from [" << file <<"]"); - // fillServiceCatalogue(); - - return StatusCode::SUCCESS; -} - -// /// IProperty implementation (needed for initialisation) -// StatusCode -// PyJobOptionsSvc::setProperty(const Gaudi::Details::PropertyBase& p) -// { -// return m_pmgr.setProperty (p); -// } - -// /// IProperty implementation (needed for initialisation) -// StatusCode -// PyJobOptionsSvc::getProperty(Property *p) const -// { -// return m_pmgr.getProperty (p); -// } - -/////////////////////////////////////////////////////////////////// -// Const methods: -/////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -// Non-const methods: -/////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -// Protected methods: -/////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -// Const methods: -/////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -// Non-const methods: -/////////////////////////////////////////////////////////////////// - - diff --git a/Control/AthenaPython/src/PyJobOptionsSvc.h b/Control/AthenaPython/src/PyJobOptionsSvc.h deleted file mode 100644 index 83ddc9ae2fb0..000000000000 --- a/Control/AthenaPython/src/PyJobOptionsSvc.h +++ /dev/null @@ -1,150 +0,0 @@ -///////////////////////// -*- C++ -*- ///////////////////////////// - -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -// PyJobOptionsSvc.h -// Header file for class PyJobOptionsSvc -// Author: S.Binet<binet@cern.ch> -/////////////////////////////////////////////////////////////////// -#ifndef ATHENAPYTHON_PYJOBOPTIONSSVC_H -#define ATHENAPYTHON_PYJOBOPTIONSSVC_H 1 - -// STL includes -#include <string> -#include <vector> -#include <list> - -// FrameWork includes -#include "AthenaBaseComps/AthService.h" - -// GaudiKernel -#include "GaudiKernel/IJobOptionsSvc.h" -#include "GaudiKernel/IProperty.h" -#include "Gaudi/Property.h" -#include "GaudiKernel/PropertyHolder.h" -//#include "GaudiKernel/PropertyMgr.h" - -// AthenaPython includes -#include "PyJobOptionsCatalogue.h" - -#include "CxxUtils/checker_macros.h" - -// Forward declaration -class ISvcLocator; -template <class TYPE> class SvcFactory; -class IProperty; -//class Property; -struct _object; -typedef _object PyObject; - -class ATLAS_NOT_THREAD_SAFE PyJobOptionsSvc - : public extends<::AthService, ::IJobOptionsSvc, ::IProperty> -{ - friend class SvcFactory<PyJobOptionsSvc>; - - /////////////////////////////////////////////////////////////////// - // Public methods: - /////////////////////////////////////////////////////////////////// - public: - - // unhides some of AthService's methods - using AthService::setProperty; - using AthService::getProperty; - using AthService::getProperties; - - // Copy constructor: - - /// Constructor with parameters: - PyJobOptionsSvc( const std::string& name, ISvcLocator* pSvcLocator ); - - /// Destructor: - virtual ~PyJobOptionsSvc() = default; - - // Assignment operator: - //PyJobOptionsSvc &operator=(const PyJobOptionsSvc &alg); - - /// Gaudi Service Implementation - //@{ - virtual StatusCode initialize() override; - virtual StatusCode finalize() override; - //@} - - /// @c IJobOptionsSvc interface - ///@{ - /** Override default properties of the calling client - @param client Name of the client algorithm or service - @param me Address of the interface IProperty of the client - */ - virtual - StatusCode setMyProperties (const std::string& client, IProperty* me) override; - - /// Add a property into the JobOptions catalog - virtual - StatusCode addPropertyToCatalogue (const std::string& client, - const Gaudi::Details::PropertyBase& property ) override; - /// Remove a property from the JobOptions catalog - virtual - StatusCode removePropertyFromCatalogue (const std::string& client, - const std::string& name ) override; - - /// Get the properties associated to a given client - virtual - // const std::vector<const Gaudi::Details::PropertyBase*>* - const std::vector<const Gaudi::Details::PropertyBase*>* - getProperties (const std::string& client) const override; - - /// Get a property for a client - const Gaudi::Details::PropertyBase* - getClientProperty( const std::string& client, - const std::string& name ) const override; - - /// Get the list of clients - virtual - std::vector<std::string> getClients() const override; - - /** look for file 'File' into search path 'Path' - * and read it to update existing JobOptionsCatalogue - * @param File file name - * @param Path search path - * @return status code - */ - virtual - StatusCode readOptions (const std::string& file, - const std::string& path) override; - - ///@} - - /// IProperty implementation (needed for initialisation) - // StatusCode setProperty(const Gaudi::Details::PropertyBase& p); - // StatusCode getProperty(Property *p) const; - - private: - /// Default constructor: - PyJobOptionsSvc() = delete; - - // PropertyMgr m_pmgr; - - // /// path to joboption file - // std::string m_source_path; - // /// source type (old-txt, py, pickle?) - // std::string m_source_type; - // /// list of paths to directories to look for joboptions - // std::string m_dir_search_path; - - // /// optional output file to dump all properties - // std::string m_dump; - - Gaudi::Property<std::string> m_source_type{this, "TYPE"}; - Gaudi::Property<std::string> m_source_path{this, "PATH"}; - Gaudi::Property<std::string> m_dir_search_path{this, "SEARCHPATH"}; - Gaudi::Property<std::string> m_dump{this, "DUMPFILE"}; - - - /// catalogue holding the properties - PyJobOptionsCatalogue m_catalogue; -}; - - -#endif //> !ATHENAPYTHON_PYJOBOPTIONSSVC_H diff --git a/Control/AthenaPython/src/PyProperty.cxx b/Control/AthenaPython/src/PyProperty.cxx deleted file mode 100644 index 21c9f33bc720..000000000000 --- a/Control/AthenaPython/src/PyProperty.cxx +++ /dev/null @@ -1,270 +0,0 @@ -///////////////////////// -*- C++ -*- ///////////////////////////// - -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -// PyProperty.cxx -// Implementation file for class PyProperty -// Author: S.Binet<binet@cern.ch> -/////////////////////////////////////////////////////////////////// - -// Python -#include <Python.h> - -// AthenaPython includes -#include "AthenaPython/PyProperty.h" -#include "AthenaPython/PyAthenaUtils.h" - -// STL includes -#include <iostream> - -// framework -#include "GaudiKernel/System.h" - -// PyRoot -#include <TPython.h> -#include <TPyReturn.h> - -namespace { - - class ATLAS_NOT_THREAD_SAFE DeepCopier - { - PyObject *m_fct; - public: - static DeepCopier* instance ATLAS_NOT_THREAD_SAFE () - { - static DeepCopier self; - static bool first = true; - if (first) { - first = false; - // make sure the python interpreter has been initialized - if (!Py_IsInitialized()) { - Py_Initialize(); - } - - {// first import pyrootfixes - PyObject *module = PyImport_ImportModule - ((char*)"RootUtils.PyROOTFixes"); - if (!module || !PyModule_Check(module)) { - PyAthena::throw_py_exception(); - } - PyObject *pickling = PyDict_GetItemString (PyModule_GetDict (module), - (char*)"enable_pickling"); - Py_XINCREF(pickling); - Py_DECREF (module); - - if (!pickling) { - Py_XDECREF(pickling); - PyAthena::throw_py_exception(); - } - - PyObject *out = PyObject_CallObject (pickling, NULL); - Py_DECREF (pickling); - if (!out) { - PyAthena::throw_py_exception(); - } - Py_DECREF (out); - } - - {// now import 'copy.deepcopy' - PyObject *module = PyImport_ImportModule ((char*)"copy"); - if (!module || !PyModule_Check(module)) { - PyAthena::throw_py_exception(); - } - self.m_fct = PyDict_GetItemString (PyModule_GetDict (module), - (char*)"deepcopy"); - Py_XINCREF(self.m_fct); - Py_DECREF (module); - if (!self.m_fct) { - Py_XDECREF(self.m_fct); - PyAthena::throw_py_exception(); - } - } - } - return &self; - } - private: - DeepCopier() : m_fct (Py_None) {} - public: - ~DeepCopier() { Py_XDECREF (m_fct); } - PyObject *copy (PyObject *in) - { - PyObject *out = PyObject_CallFunction (m_fct, (char*)"O", in); - if (!out) { - PyAthena::throw_py_exception(); - } - return out; - } - }; -} - -/////////////////////////////////////////////////////////////////// -// Public methods: -/////////////////////////////////////////////////////////////////// - -// Constructors -//////////////// - -/// Copy constructor: -PyProperty::PyProperty( const PyProperty& rhs ) : - PropertyWithHandlers (rhs), - m_pyobj (::DeepCopier::instance()->copy (rhs.m_pyobj)) -{} - -/// Assignment operator: -PyProperty& -PyProperty::operator=( const PyProperty& rhs ) -{ - if ( this != &rhs ) { - PropertyWithHandlers::operator= (rhs); - m_pyobj = ::DeepCopier::instance()->copy (rhs.m_pyobj); - } - return *this; -} - -/// Constructor with parameters: -PyProperty::PyProperty(const std::string& name, - const std::type_info& type, - void* obj) : - PropertyWithHandlers (name, type), - m_pyobj (Py_None) -{ - if (type == typeid(PyObject) || - type == typeid(PyObject*)) { - m_pyobj = ::DeepCopier::instance()->copy ((PyObject*)obj); - } else { - m_pyobj = TPython::ObjectProxy_FromVoidPtr - (obj, - System::typeinfoName(type.name()).c_str()); - } -} - -PyProperty::PyProperty (const std::string& name, - PyObject* obj) : - PropertyWithHandlers (name, typeid(obj)), - m_pyobj (::DeepCopier::instance()->copy (obj)) -{} - -// Destructor -/////////////// - -PyProperty::~PyProperty() -{ - Py_XDECREF (m_pyobj); -} - -// Property interface - -/// export the property value to the destination -bool -PyProperty::load (Gaudi::Details::PropertyBase& dest) const -{ - return dest.assign (*this); -} - -/// import the property value from source -bool -PyProperty::assign (const Gaudi::Details::PropertyBase& src) -{ - const PyProperty *p = dynamic_cast<const PyProperty*> (&src); - if (p) { - m_pyobj = ::DeepCopier::instance()->copy (p->m_pyobj); - return true; - } - - const std::string value_type = System::typeinfoName (*src.type_info()); - const std::string prop_type = "PropertyWithValue< "+value_type+" >"; - - PyObject *pyprop= TPython::ObjectProxy_FromVoidPtr - ((void*)&src, (char*)prop_type.c_str()); - if (!pyprop) { - // XXX assume error message installed by PyRoot is explanatory enough. - PyAthena::throw_py_exception(); - } - - PyObject *value = PyObject_CallMethod (pyprop, - (char*)"value", - (char*)""); - Py_DECREF (pyprop); - - if (!value) { - PyAthena::throw_py_exception(); - } - // steal reference - m_pyobj = value; - return true; -} - -/// export the property value as a @c std::string -std::string -PyProperty::toString() const -{ - useReadHandler(); - // XXX this might not do something useful if m_pyobj is an ObjectProxy... - return PyAthena::str(m_pyobj); -} - -/// insert the property into a stream -void -PyProperty::toStream(std::ostream& out) const -{ - useReadHandler(); - // XXX this might not do something useful if m_pyobj is an ObjectProxy... - out << PyAthena::str(m_pyobj); -} - -/// import the property value from a @c std::string -StatusCode -PyProperty::fromString (const std::string& value) -{ - PyObject *o = TPython::ObjectProxy_FromVoidPtr - ((void*)TPython::Eval (value.c_str()), - System::typeinfoName(*this->type_info()).c_str()); - if (!o) { - return StatusCode::FAILURE; - } - if (!TPython::ObjectProxy_Check(o)) { - Py_DECREF(o); - return StatusCode::FAILURE; - } - // steals reference. - m_pyobj = o; - return StatusCode::SUCCESS; -} - -/// clone: the usual "virtual constructor" pattern -PyProperty* -PyProperty::clone() const -{ - return new PyProperty(*this); -} - -/// access underlying wrapped object -void* -PyProperty::object() const -{ - return TPyReturn (m_pyobj); -} - -/// access underlying wrapped object as a python object -PyObject* -PyProperty::value() const -{ - Py_XINCREF (m_pyobj); - return m_pyobj; -} - -/////////////////////////////////////////////////////////////////// -// Const methods: -/////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -// Non-const methods: -/////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -// Protected methods: -/////////////////////////////////////////////////////////////////// - - diff --git a/Control/AthenaPython/src/components/AthenaPython_entries.cxx b/Control/AthenaPython/src/components/AthenaPython_entries.cxx index 58ca4f73115f..0cff5e1a7391 100644 --- a/Control/AthenaPython/src/components/AthenaPython_entries.cxx +++ b/Control/AthenaPython/src/components/AthenaPython_entries.cxx @@ -3,7 +3,6 @@ #include "AthenaPython/PyAthenaTool.h" #include "AthenaPython/PyAthenaAud.h" #include "../PyComponentMgr.h" -#include "../PyJobOptionsSvc.h" DECLARE_COMPONENT( PyAthena::Tool ) @@ -11,5 +10,4 @@ DECLARE_COMPONENT( PyAthena::Alg ) DECLARE_COMPONENT( PyAthena::Aud ) DECLARE_COMPONENT( PyAthena::Svc ) DECLARE_COMPONENT( PyAthena::PyComponentMgr ) -DECLARE_COMPONENT( PyJobOptionsSvc ) -- GitLab