| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends

# IoComponentMgr Class Reference

`#include <IoComponentMgr.h>`

Inheritance diagram for IoComponentMgr:
[legend]
Collaboration diagram for IoComponentMgr:
[legend]

List of all members.

## Public Member Functions
| IoComponentMgr (const std::string &name, ISvcLocator *pSvcLocator)
| Constructor with parameters:
virtual | ~IoComponentMgr ()
| Destructor:
virtual bool | io_hasitem (IIoComponent *iocomponent) const
| : check if the registry contains a given `IIoComponent`
virtual bool | io_contains (IIoComponent *iocomponent, const std::string &fname) const
| : check if the registry contains a given `IIoComponent` and that component had
virtual StatusCode | io_register (IIoComponent *iocomponent)
| : allow a `IIoComponent` to register itself with this manager so appropriate actions can be taken when e.g.
virtual StatusCode | io_register (IIoComponent *iocomponent, IIoComponentMgr::IoMode::Type iomode, const std::string &fname)
| : allow a `IIoComponent` to register itself with this manager so appropriate actions can be taken when e.g.
virtual StatusCode | io_retrieve (IIoComponent *iocomponent, std::string &fname)
| : retrieve the new filename for a given `IIoComponent` and
virtual StatusCode | io_reinitialize ()
| : reinitialize the I/O subsystem.
virtual StatusCode | io_finalize ()
| : finalize the I/O subsystem.
virtual StatusCode | initialize ()
| Gaudi Service Implementation.
virtual StatusCode | finalize ()
## Private Types
typedef std::map< std::string, IIoComponent * > | IoRegistry_t
typedef std::list< IIoComponent * > | IoStack_t
## Private Member Functions
| IoComponentMgr ()
| Default constructor:
## Private Attributes
MsgStream | m_log
IoRegistry_t | m_ioregistry
| Registry of `IIoComponents`.
IoStack_t | m_iostack
| Stack of `IIoComponents` to properly handle order of registration.
PyObject * | m_dict
| pointer to a python dictionary holding the associations: { 'iocomp-name' : { 'oldfname' : [ 'iomode', 'newfname' ] } }
std::string | m_dict_location
| location of the python dictionary
## Friends
class | SvcFactory< IoComponentMgr >

## Detailed Description

Definition at line 29 of file IoComponentMgr.h.

## Member Typedef Documentation

typedef std::map<std::string, IIoComponent*> IoComponentMgr::IoRegistry_t`[private]`

Definition at line 127 of file IoComponentMgr.h.

typedef std::list<IIoComponent*> IoComponentMgr::IoStack_t`[private]`

Definition at line 131 of file IoComponentMgr.h.

## Constructor & Destructor Documentation

IoComponentMgr::IoComponentMgr | ( | const std::string & | name,
|  | ISvcLocator * | pSvcLocator
| ) |  |

Constructor with parameters:

Definition at line 29 of file IoComponentMgr.cpp.

    : base_class(name,svc), m_log(msgSvc(), name ),
        m_dict   ( 0 )
    {
      //
      // Property declaration
      //
      //declareProperty( "Property", m_nProperty );

    //   declareProperty ("Registry",
    //                 m_dict_location = "GaudiMP.IoRegistry.registry",
    //                 "Location of the python dictionary holding the "
    //                 "associations: \n"
    //                 " {component-name:{ 'old-fname' : ['io','new-fname'] }}\n"
    //                 "\nSyntax: <python-module>.<python-module>.<fct-name> \n"
    //                 " where fct-name is a function returning the wanted "
    //                 " dictionary.");
    }

IoComponentMgr::~IoComponentMgr | ( | ) | `[virtual]`

Destructor:

Definition at line 51 of file IoComponentMgr.cpp.

    {
      Py_XDECREF (m_dict);
    }

IoComponentMgr::IoComponentMgr | ( | ) | `[private]`

Default constructor:

## Member Function Documentation

StatusCode IoComponentMgr::finalize | ( | void | ) | `[virtual]`

Reimplemented from Service.

Definition at line 134 of file IoComponentMgr.cpp.

    {
      m_log << MSG::INFO << "Finalizing " << name() << "..." << endmsg;

      if (m_log.level() <= MSG::DEBUG) {
        m_log << MSG::DEBUG << "Listing all monitored entries: " << std::endl;

        std::string repr = "";
        // PyObject_Repr returns a new ref.
        PyObject* py_repr = PyObject_Repr (m_dict);
        if ( py_repr && PyString_Check(py_repr) ) {
          repr = PyString_AsString(py_repr);
        }
        Py_XDECREF( py_repr );
        m_log << MSG::DEBUG << "content: " << repr << endmsg;
      }

      return StatusCode::SUCCESS;
    }

StatusCode IoComponentMgr::initialize | ( | void | ) | `[virtual]`

Gaudi Service Implementation.

Reimplemented from Service.

Definition at line 58 of file IoComponentMgr.cpp.

    {
      m_log << MSG::INFO << "Initializing " << name() << "..." << endmsg;

      if ( Service::initialize().isFailure() ) {
        m_log << MSG::ERROR << "Unable to initialize Service base class" << endmsg;
        return StatusCode::FAILURE;
      }
      m_log.setLevel( m_outputLevel.value() );

      if ( ! Py_IsInitialized() ) {
        if (m_log.level() <= MSG::DEBUG) {
          m_log << MSG::DEBUG << "Initializing Python" << endmsg;
        }
        PyEval_InitThreads();
        Py_Initialize();

        if ( ! Py_IsInitialized() ) {
          m_log << MSG::ERROR << "Unable to initialize Python" << endmsg;
          return StatusCode::FAILURE;
        }
      }

      // retrieve the python dictionary holding the I/O registry
      const std::string py_module_name = "GaudiMP.IoRegistry";
      m_log << MSG::DEBUG << "importing module [" << py_module_name << "]..."
            << endmsg;
      PyObject *module = PyImport_ImportModule ((char*)py_module_name.c_str());
      if ( !module || !PyModule_Check (module) ) {
        m_log << MSG::ERROR << "Could not import [" << py_module_name << "] !"
              << endmsg;
        Py_XDECREF (module);
        return StatusCode::FAILURE;
      }

      const std::string py_class_name = "IoRegistry";
      PyObject *pyclass = PyDict_GetItemString (PyModule_GetDict(module),
                                                (char*)py_class_name.c_str());
      // borrowed ref.
      Py_XINCREF (pyclass);
      if ( !pyclass ) {
        m_log << MSG::ERROR << "Could not import ["
              << py_class_name << "] from module ["
              << py_module_name << "] !"
              << endmsg ;
        Py_XDECREF (pyclass);
        Py_DECREF  (module);
        return StatusCode::FAILURE;
      }

      m_dict = PyObject_GetAttrString (pyclass, (char*)"instances");
      if ( !m_dict || !PyDict_Check (m_dict) ) {
        m_log << MSG::ERROR
              << "could not retrieve attribute [instances] from class ["
              << py_module_name << "." << py_class_name << "] !" << endmsg;
        Py_DECREF (pyclass);
        Py_DECREF (module);
        return StatusCode::FAILURE;
      }

      m_log << MSG::INFO <<  "python I/O registry retrieved [ok]" << endmsg;
      if ( m_log.level() <=  MSG::DEBUG ) {
        std::string repr = "";
        // PyObject_Repr returns a new ref.
        PyObject* py_repr = PyObject_Repr (m_dict);
        if ( py_repr && PyString_Check(py_repr) ) {
          repr = PyString_AsString(py_repr);
        }
        Py_XDECREF( py_repr );
        m_log << MSG::DEBUG << "content: " << repr << endmsg;
      }

      return StatusCode::SUCCESS;
    }

bool IoComponentMgr::io_contains | ( | IIoComponent * | iocomponent,
|  | const std::string & | fname
| ) |  | const`[virtual]`

: check if the registry contains a given `IIoComponent` and that component had

Parameters:

  `fname` | as a filename

Implements IIoComponentMgr.

Definition at line 176 of file IoComponentMgr.cpp.

    {
      if ( 0 == iocomponent ) {
        return false;
      }
      const std::string& ioname = iocomponent->name();

      // m_dict is a python dictionary like so:
      //  { 'iocomp-name' : { 'oldfname' : [ 'iomode', 'newfname' ] } }

      // -> check there is an 'iocomp-name' entry
      // -> retrieve that entry
      PyObject *o = PyDict_GetItemString (m_dict, (char*)ioname.c_str());
      Py_XINCREF (o);

      // -> check it is a dictionary
      if ( NULL==o || !PyDict_Check (o) ) {
        Py_XDECREF (o);

        return false;
      }

      // -> check 'oldfname' exists
      PyObject *item = PyDict_GetItemString (o, (char*)fname.c_str());

      const bool contains = (item != 0);
      if ( contains == false ) {
        std::string repr = "";
        // PyObject_Repr returns a new ref.
        PyObject* py_repr = PyObject_Repr (o);
        if ( py_repr && PyString_Check(py_repr) ) {
          repr = PyString_AsString(py_repr);
        }
        Py_XDECREF( py_repr );
        m_log << MSG::ERROR << "content: " << repr << endmsg;
      }
      Py_DECREF (o);
      Py_XDECREF(item);
      return contains;
    }

StatusCode IoComponentMgr::io_finalize | ( | ) | `[virtual]`

: finalize the I/O subsystem.

Hook to allow to e.g. give a chance to I/O subsystems to merge output files. Not sure how to do this correctly though...

Implements IIoComponentMgr.

Definition at line 452 of file IoComponentMgr.cpp.

    {
      return StatusCode::SUCCESS;
    }

bool IoComponentMgr::io_hasitem | ( | IIoComponent * | iocomponent ) | const`[virtual]`

: check if the registry contains a given `IIoComponent`

Implements IIoComponentMgr.

Definition at line 162 of file IoComponentMgr.cpp.

    {
      if ( 0 == iocomponent ) {
        return false;
      }
      const std::string& ioname = iocomponent->name();
      IoRegistry_t::const_iterator io = m_ioregistry.find (ioname);
      return io != m_ioregistry.end();
    }

StatusCode IoComponentMgr::io_register | ( | IIoComponent * | iocomponent ) | `[virtual]`

: allow a `IIoComponent` to register itself with this manager so appropriate actions can be taken when e.g.

a `fork(2)` has been issued (this is usually handled by calling `IIoComponent::io_reinit` on every registered component)

Implements IIoComponentMgr.

Definition at line 229 of file IoComponentMgr.cpp.

    {
      if ( 0 == iocomponent ) {
        m_log << MSG::ERROR
              << "io_register (component) received a NULL pointer !" << endmsg;
        return StatusCode::FAILURE;
      }
      const std::string& ioname = iocomponent->name();
      IoRegistry_t::iterator itr = m_ioregistry.find (ioname);
      if ( itr == m_ioregistry.end() ) {
        iocomponent->addRef(); // ownership...
        m_ioregistry[ioname] = iocomponent;
        m_iostack.push_back (iocomponent);
      } else {
        m_log << MSG::INFO << "IoComponent[" << iocomponent->name()
              <<"] already registered @" << (void*)itr->second << endmsg;
      }
      return StatusCode::SUCCESS;
    }

StatusCode IoComponentMgr::io_register | ( | IIoComponent * | iocomponent,
|  | IIoComponentMgr::IoMode::Type | iomode,
|  | const std::string & | fname
| ) |  | `[virtual]`

: allow a `IIoComponent` to register itself with this manager so appropriate actions can be taken when e.g.

a `fork(2)` has been issued (this is usually handled by calling `IIoComponent::io_reinit` on every registered component)

Implements IIoComponentMgr.

Definition at line 256 of file IoComponentMgr.cpp.

    {
      if ( 0 == iocomponent ) {
        return StatusCode::FAILURE;
      }
      const std::string& ioname = iocomponent->name();

      if ( !io_hasitem (iocomponent) ) {
        if ( !io_register (iocomponent).isSuccess() ) {
          m_log << MSG::ERROR
                << "could not register component [" << iocomponent->name() << "] "
                << "with the I/O component manager !"
                << endmsg;
          return StatusCode::FAILURE;
        }
      }

      // m_dict is a python dictionary like so:
      //  { 'iocomp-name' : { 'oldfname' : [ 'iomode', 'newfname' ] } }

      // -> check there is an 'iocomp-name' entry
      // -> retrieve that entry
      PyObject *o = PyDict_GetItemString (m_dict, (char*)ioname.c_str());

      // -> check it is a dictionary
      if ( NULL==o ) {
        o = PyDict_New();
        if (NULL == o) {
          m_log << MSG::ERROR << "could not create an I/O entry for ["
                << ioname << "] "
                << "in the I/O registry !" << endmsg;
          return StatusCode::FAILURE;
        }
        if ( 0 != PyDict_SetItemString (m_dict, (char*)ioname.c_str(), o) ) {
          Py_DECREF (o);
          m_log << MSG::ERROR << "could not create an I/O entry for ["
                << ioname << "] " << "in the I/O registry !" << endmsg;
          return StatusCode::FAILURE;
        }
      } else if ( !PyDict_Check (o) ) {
        m_log << MSG::ERROR
              << "internal consistency error (expected a dictionary !)"
              << endmsg;
        return StatusCode::FAILURE;
      } else {
        // borrowed ref.
        Py_INCREF (o);
      }

      // -> check if 'fname' has already been registered
      std::string mode;
      switch (iomode) {
      case IIoComponentMgr::IoMode::Input: mode ="<input>"; break;
      case IIoComponentMgr::IoMode::Output:mode ="<output>";break;
      default:
        m_log << MSG::ERROR << "unknown value for iomode: [" << iomode << "] !"
              << endmsg;
        Py_DECREF (o);
        return StatusCode::FAILURE;
      }

      PyObject *val = PyDict_GetItemString (o, (char*)fname.c_str());
      if ( 0 != val ) {
        Py_DECREF (o);
        return StatusCode::SUCCESS;
      }

      val = PyList_New(2);
      if ( 0 == val ) {
        m_log << MSG::ERROR << "could not allocate a python-list !" << endmsg;
        Py_DECREF (o);
        return StatusCode::FAILURE;
      }

      int err = PyList_SetItem (val,
                                0, PyString_FromString ((char*)mode.c_str()));
      if (err) {
        Py_DECREF (val);
        Py_DECREF (o);
        m_log << MSG::ERROR << "could not set py-iomode !" << endmsg;
        return StatusCode::FAILURE;
      }
      Py_INCREF (Py_None);
      // PyList_SetItem steals the ref...
      err = PyList_SetItem (val, 1, Py_None);
      if (err) {
        Py_DECREF (val);
        Py_DECREF (o);
        m_log << MSG::ERROR << "could not properly fill python-list !" << endmsg;
        return StatusCode::FAILURE;
      }
      err = PyDict_SetItemString (o, (char*)fname.c_str(), val);
      if (err) {
        m_log << MSG::ERROR << "could not properly fill registry w/ python-list !"
              << endmsg;
        Py_DECREF (val);
        Py_DECREF (o);
        return StatusCode::FAILURE;
      }
      Py_DECREF (o);
      return StatusCode::SUCCESS;
    }

StatusCode IoComponentMgr::io_reinitialize | ( | ) | `[virtual]`

: reinitialize the I/O subsystem.

This effectively calls `IIoComponent::io_reinit` on all the registered `IIoComponent`.

Implements IIoComponentMgr.

Definition at line 419 of file IoComponentMgr.cpp.

    {
      m_log << MSG::DEBUG << "reinitializing I/O subsystem..." << endmsg;
      bool allgood = true;
      for ( IoStack_t::iterator io = m_iostack.begin(), ioEnd = m_iostack.end();
            io != ioEnd;
            ++io ) {
        m_log << MSG::DEBUG << " [" << (*io)->name() << "]->io_reinit()..."
              << endmsg;
        if ( !(*io)->io_reinit().isSuccess() ) {
          allgood = false;
          m_log << MSG::ERROR << "problem in [" << (*io)->name()
                << "]->io_reinit() !" << endmsg;
        }
        // we are done with this guy... release it
        (*io)->release();
      }

      // we are done.
      // FIXME: shall we allow for multiple io_reinitialize ?
      m_iostack.clear();
      m_ioregistry.clear();

      return allgood
        ? StatusCode::SUCCESS
        : StatusCode::FAILURE;
    }

StatusCode IoComponentMgr::io_retrieve | ( | IIoComponent * | iocomponent,
|  | std::string & | fname
| ) |  | `[virtual]`

: retrieve the new filename for a given `IIoComponent` and

Parameters:

  `fname` | filename
  `oldfname` | filename

Implements IIoComponentMgr.

Definition at line 365 of file IoComponentMgr.cpp.

    {
      if ( 0 == iocomponent ) {
        return StatusCode::FAILURE;
      }

      const std::string& ioname = iocomponent->name();

      // m_dict is a python dictionary like so:
      //  { 'iocomp-name' : { 'oldfname' : [ 'iomode', 'newfname' ] } }

      // -> check there is an 'iocomp-name' entry
      // -> retrieve that entry
      PyObject *o = PyDict_GetItemString (m_dict, (char*)ioname.c_str());
      Py_XINCREF (o);

      // -> check it is a dictionary
      if ( NULL==o || !PyDict_Check (o) ) {
        Py_XDECREF (o);
        return StatusCode::FAILURE;
      }

      // -> check 'oldfname' exists
      PyObject *pylist = PyDict_GetItemString (o, (char*)fname.c_str());
      Py_XINCREF (pylist);

      if ( NULL==pylist || !PyList_Check (pylist) ) {
        Py_XDECREF(pylist);
        Py_DECREF (o);
        return StatusCode::FAILURE;
      }

      const std::size_t sz = PyList_Size (pylist);
      if ( 2 != sz ) {
        m_log << MSG::ERROR << "[" << ioname << "][" << fname << "] list has size ["
              << sz << " ! (expected sz==2)"
              << endmsg;
        Py_DECREF (o);
        Py_DECREF (pylist);
        return StatusCode::FAILURE;
      }

      fname = PyString_AsString ( PyList_GetItem (pylist, 1) );
      Py_DECREF (o);
      Py_DECREF (pylist);
      return StatusCode::SUCCESS;
    }

## Friends And Related Function Documentation

friend class SvcFactory< IoComponentMgr >`[friend]`

Definition at line 31 of file IoComponentMgr.h.

## Member Data Documentation

PyObject* IoComponentMgr::m_dict`[private]`

pointer to a python dictionary holding the associations: { 'iocomp-name' : { 'oldfname' : [ 'iomode', 'newfname' ] } }

Definition at line 138 of file IoComponentMgr.h.

std::string IoComponentMgr::m_dict_location`[private]`

location of the python dictionary

Definition at line 141 of file IoComponentMgr.h.

IoRegistry_t IoComponentMgr::m_ioregistry`[private]`

Registry of `IIoComponents`.

Definition at line 129 of file IoComponentMgr.h.

IoStack_t IoComponentMgr::m_iostack`[private]`

Stack of `IIoComponents` to properly handle order of registration.

Definition at line 133 of file IoComponentMgr.h.

MsgStream IoComponentMgr::m_log`[mutable, private]`

Definition at line 125 of file IoComponentMgr.h.

The documentation for this class was generated from the following files:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r4/GaudiMP/src/component/IoComponentMgr.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r4/GaudiMP/src/component/IoComponentMgr.cpp

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines