| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# AlgorithmManager Class Reference

`#include <AlgorithmManager.h>`

Inheritance diagram for AlgorithmManager:

[legend]
Collaboration diagram for AlgorithmManager:

[legend]

List of all members.

## Detailed Description

The AlgorithmManager class is in charge of the creation of concrete instances of Algorithms.

The ApplicationMgr delegates the creation and bookkeeping of algorithms to the algorithm factory. In order to be able to create algorithms from which it does not know the concrete type it requires that the algorithm has been declared in one of 3 possible ways: an abstract static creator function, a dynamic link library or an abstract factory reference.

Author:
  Pere Mato

Definition at line 31 of file AlgorithmManager.h.

## Public Types
typedef std::list< IAlgorithm * > | ListAlg
| typedefs and classes
## Public Member Functions
| AlgorithmManager (IInterface *iface)
| default creator
virtual | ~AlgorithmManager ()
| virtual destructor
virtual unsigned long | addRef ()
| implmentation of IInterface::addRef
virtual unsigned long | release ()
| implmentation of IInterface::release
virtual StatusCode | queryInterface (const InterfaceID &iid, void **pinterface)
| implementation of IInterface::queryInterface
virtual StatusCode | addAlgorithm (IAlgorithm *alg)
| implementation of IAlgManager::addAlgorithm
virtual StatusCode | removeAlgorithm (IAlgorithm *alg)
| implementation of IAlgManager::removeAlgorithm
virtual StatusCode | createAlgorithm (const std::string &algtype, const std::string &algname, IAlgorithm *&algorithm, bool managed=false)
| implementation of IAlgManager::createAlgorithm
virtual StatusCode | getAlgorithm (const std::string &name, IAlgorithm *&alg) const
| implementation of IAlgManager::getAlgorithm
virtual bool | existsAlgorithm (const std::string &name) const
| implementation of IAlgManager::existsAlgorithm
virtual std::list< IAlgorithm * > & | getAlgorithms () const
| implementation of IAlgManager::getAlgorithms
virtual StatusCode | initializeAlgorithms ()
| implementation of IAlgManager::initializeAlgorithms
virtual StatusCode | startAlgorithms ()
| implementation of IAlgManager::startAlgorithms
virtual StatusCode | stopAlgorithms ()
| implementation of IAlgManager::stopAlgorithms
virtual StatusCode | finalizeAlgorithms ()
| implementation of IAlgManager::finalizeAlgorithms
virtual StatusCode | reinitializeAlgorithms ()
| implementation of IAlgManager::initializeAlgorithms
virtual StatusCode | restartAlgorithms ()
| implementation of IAlgManager::startAlgorithms
## Private Member Functions
IMessageSvc * | msgSvc ()
## Private Attributes
IInterface * | m_pOuter
| Interface hub reference (ApplicationMgr).
unsigned long | m_refcount
| Reference counter.
ListAlg * | m_listalg
| List of algorithms maintained by AlgorithmManager.
ListAlg * | m_listmgralg
| List of managed algorithms maintained by AlgorithmManager.
ISvcLocator * | m_svclocator
| Service locator reference.
IMessageSvc * | m_msgsvc
| Pointer to the message service if it exists.
SmartIF< IStateful > | m_statemgr
| Pointer to the state machine.

## Member Typedef Documentation

typedef std::list<IAlgorithm*> AlgorithmManager::ListAlg

typedefs and classes

Definition at line 34 of file AlgorithmManager.h.

## Constructor & Destructor Documentation

AlgorithmManager::AlgorithmManager | ( | IInterface * | iface | ) |

default creator

Definition at line 18 of file AlgorithmManager.cpp.

    00018                                                    :
    00019   m_statemgr(iface)
    00020 {
    00021   m_pOuter = iface;
    00022   m_pOuter->queryInterface(IID_ISvcLocator, pp_cast<void>(&m_svclocator)).ignore();
    00023   m_msgsvc     = 0;
    00024   m_refcount   = 1;
    00025   m_listalg    = new ListAlg();
    00026   m_listmgralg = new ListAlg();
    00027 }

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

virtual destructor

Definition at line 30 of file AlgorithmManager.cpp.

    00030                                     {
    00031   delete m_listalg;
    00032   delete m_listmgralg;
    00033   if( m_msgsvc ) m_msgsvc->release();
    00034   if( m_svclocator ) m_svclocator->release();
    00035 }

## Member Function Documentation

unsigned long AlgorithmManager::addRef | ( |  | ) | `[virtual]`

implmentation of IInterface::addRef

Implements IInterface.

Definition at line 38 of file AlgorithmManager.cpp.

    00038                                        {
    00039   m_refcount++;
    00040   return m_refcount;
    00041 }

unsigned long AlgorithmManager::release | ( |  | ) | `[virtual]`

implmentation of IInterface::release

Implements IInterface.

Definition at line 44 of file AlgorithmManager.cpp.

    00044                                         {
    00045   unsigned long count = --m_refcount;
    00046   if( count <= 0) {
    00047     delete this;
    00048   }
    00049   return count;
    00050 }

StatusCode AlgorithmManager::queryInterface | ( | const InterfaceID & | iid,
|  | void ** | pinterface |
| ) |  |  | `[virtual]`

implementation of IInterface::queryInterface

Implements IInterface.

Definition at line 53 of file AlgorithmManager.cpp.

    00053                                                                                      {
    00054   if( iid == IID_IInterface ) {
    00055     *pinterface = (IInterface*)this;
    00056     addRef();
    00057     return StatusCode::SUCCESS;
    00058   }
    00059   else if ( iid == IID_IAlgManager ) {
    00060     *pinterface = (IAlgManager*)this;
    00061     addRef();
    00062     return StatusCode::SUCCESS;
    00063   }
    00064   else {
    00065     return m_pOuter->queryInterface(iid, pinterface);
    00066   }
    00067   return StatusCode::SUCCESS;
    00068 }

StatusCode AlgorithmManager::addAlgorithm | ( | IAlgorithm * | alg | ) | `[virtual]`

implementation of IAlgManager::addAlgorithm

Implements IAlgManager.

Definition at line 71 of file AlgorithmManager.cpp.

    00071                                                            {
    00072   m_listalg->push_back( alg );
    00073   return StatusCode::SUCCESS;
    00074 }

StatusCode AlgorithmManager::removeAlgorithm | ( | IAlgorithm * | alg | ) | `[virtual]`

implementation of IAlgManager::removeAlgorithm

Implements IAlgManager.

Definition at line 77 of file AlgorithmManager.cpp.

    00077                                                               {
    00078   ListAlg::iterator it;
    00079   for (it = m_listalg->begin(); it != m_listalg->end(); it++ ) {
    00080     if( *it == alg ) {
    00081       m_listalg->erase(it);
    00082       break;
    00083     }
    00084   }
    00085   return StatusCode::SUCCESS;
    00086 }

StatusCode AlgorithmManager::createAlgorithm | ( | const std::string & | algtype,
|  | const std::string & | algname,
|  | IAlgorithm *& | algorithm,
|  | bool | managed = `false` |
| ) |  |  | `[virtual]`

implementation of IAlgManager::createAlgorithm

Implements IAlgManager.

Definition at line 89 of file AlgorithmManager.cpp.

    00093 {
    00094   MsgStream log(msgSvc(), "AlgorithmManager");
    00095   // Check is the algorithm is already existing
    00096   if( existsAlgorithm( algname ) ) {
    00097     // return an error because an algorithm with that name already exists
    00098     return StatusCode::FAILURE;
    00099   }
    00100   algorithm = PluginService::Create<IAlgorithm*>(algtype, algname, m_svclocator);
    00101   if ( !algorithm ) {
    00102     algorithm = PluginService::CreateWithId<IAlgorithm*>(algtype, algname, m_svclocator);
    00103   }
    00104   if ( algorithm ) {
    00105     // Check the compatibility of the version of the interface obtained
    00106     if( !isValidInterface(algorithm) ) {
    00107       log << MSG::FATAL << "Incompatible interface IAlgorithm version for " << algtype << endreq;
    00108       return StatusCode::FAILURE;
    00109     }
    00110     StatusCode rc;
    00111     m_listalg->push_back( algorithm );
    00112     if ( managed ) {
    00113       algorithm->addRef();
    00114       m_listmgralg->push_back( algorithm );
    00115
    00116       // Bring the created service to the same state of the ApplicationMgr
    00117       if (m_statemgr->FSMState() >= Gaudi::StateMachine::INITIALIZED) {
    00118         rc = algorithm->sysInitialize();
    00119         if (rc.isSuccess() && m_statemgr->FSMState() >= Gaudi::StateMachine::RUNNING) {
    00120           rc = algorithm->sysStart();
    00121         }
    00122       }
    00123       if ( !rc.isSuccess() )  {
    00124         log << MSG::ERROR << "Failed to initialize algorithm: "
    00125             << "[" << algname << "]" << endmsg;
    00126       }
    00127     }
    00128     return rc;
    00129   }
    00130   log << MSG::ERROR << "Algorithm of type " << algtype
    00131       << " is unknown (No factory available)." << endmsg;
    00132 #ifndef _WIN32
    00133   errno = 0xAFFEDEAD; // code used by Gaudi for library load errors: forces getLastErrorString do use dlerror (on Linux)
    00134 #endif
    00135   std::string err = System::getLastErrorString();
    00136   if (! err.empty()) {
    00137     log << MSG::ERROR << err << endmsg;
    00138   }
    00139   log << MSG::ERROR << "More information may be available by setting the global jobOpt \"ReflexPluginDebugLevel\" to 1" << endmsg;
    00140
    00141   return StatusCode::FAILURE;
    00142 }

StatusCode AlgorithmManager::getAlgorithm | ( | const std::string & | name,
|  | IAlgorithm *& | alg |
| ) |  |  | const`[virtual]`

implementation of IAlgManager::getAlgorithm

Implements IAlgManager.

Definition at line 145 of file AlgorithmManager.cpp.

    00145                                                                                         {
    00146   ListAlg::const_iterator it;
    00147   for (it = m_listalg->begin(); it != m_listalg->end(); it++ ) {
    00148     if( (*it)->name() == name ) {
    00149       alg = *it;
    00150       return StatusCode::SUCCESS;
    00151     }
    00152   }
    00153   return StatusCode::FAILURE;
    00154 }

bool AlgorithmManager::existsAlgorithm | ( | const std::string & | name | ) | const`[virtual]`

implementation of IAlgManager::existsAlgorithm

Implements IAlgManager.

Definition at line 157 of file AlgorithmManager.cpp.

    00157                                                                     {
    00158   ListAlg::const_iterator it;
    00159   for (it = m_listalg->begin(); it != m_listalg->end(); it++ ) {
    00160     if( (*it)->name() == name ) {
    00161       return true;
    00162     }
    00163   }
    00164   return false;
    00165 }

std::list< IAlgorithm * > & AlgorithmManager::getAlgorithms | ( |  | ) | const`[virtual]`

implementation of IAlgManager::getAlgorithms

Implements IAlgManager.

Definition at line 168 of file AlgorithmManager.cpp.

    00169 {
    00170   return *m_listalg;
    00171 }

StatusCode AlgorithmManager::initializeAlgorithms | ( |  | ) | `[virtual]`

implementation of IAlgManager::initializeAlgorithms

Implements IAlgManager.

Definition at line 173 of file AlgorithmManager.cpp.

    00173                                                   {
    00174   StatusCode rc;
    00175   ListAlg::const_iterator it;
    00176   for (it = m_listmgralg->begin(); it != m_listmgralg->end(); it++ ) {
    00177     rc = (*it)->sysInitialize();
    00178     if ( rc.isFailure() ) return rc;
    00179   }
    00180   return rc;
    00181 }

StatusCode AlgorithmManager::startAlgorithms | ( |  | ) | `[virtual]`

implementation of IAlgManager::startAlgorithms

Implements IAlgManager.

Definition at line 183 of file AlgorithmManager.cpp.

    00183                                              {
    00184   StatusCode rc;
    00185   ListAlg::const_iterator it;
    00186   for (it = m_listmgralg->begin(); it != m_listmgralg->end(); it++ ) {
    00187     rc = (*it)->sysStart();
    00188     if ( rc.isFailure() ) return rc;
    00189   }
    00190   return rc;
    00191 }

StatusCode AlgorithmManager::stopAlgorithms | ( |  | ) | `[virtual]`

implementation of IAlgManager::stopAlgorithms

Implements IAlgManager.

Definition at line 193 of file AlgorithmManager.cpp.

    00193                                             {
    00194   StatusCode rc;
    00195   ListAlg::const_iterator it;
    00196   for (it = m_listmgralg->begin(); it != m_listmgralg->end(); it++ ) {
    00197     rc = (*it)->sysStop();
    00198     if ( rc.isFailure() ) return rc;
    00199   }
    00200   return rc;
    00201 }

StatusCode AlgorithmManager::finalizeAlgorithms | ( |  | ) | `[virtual]`

implementation of IAlgManager::finalizeAlgorithms

Implements IAlgManager.

Definition at line 203 of file AlgorithmManager.cpp.

    00203                                                 {
    00204   StatusCode rc;
    00205   ListAlg::const_iterator it;
    00206   for (it = m_listmgralg->begin(); it != m_listmgralg->end(); it++ ) {
    00207     rc = (*it)->sysFinalize();
    00208     if( rc.isFailure() ) return rc;
    00209     (*it)->release();
    00210   }
    00211   m_listmgralg->clear();
    00212   return rc;
    00213 }

StatusCode AlgorithmManager::reinitializeAlgorithms | ( |  | ) | `[virtual]`

implementation of IAlgManager::initializeAlgorithms

Implements IAlgManager.

Definition at line 215 of file AlgorithmManager.cpp.

    00215                                                     {
    00216   StatusCode rc;
    00217   ListAlg::const_iterator it;
    00218   for (it = m_listmgralg->begin(); it != m_listmgralg->end(); it++ ) {
    00219     rc = (*it)->sysReinitialize();
    00220     if( rc.isFailure() ){
    00221       MsgStream log(msgSvc(), "AlgorithmManager");
    00222       log << MSG::ERROR << "Unable to re-initialize Service: " << (*it)->name() << endreq;
    00223       return rc;
    00224     }
    00225   }
    00226   return rc;
    00227 }

StatusCode AlgorithmManager::restartAlgorithms | ( |  | ) | `[virtual]`

implementation of IAlgManager::startAlgorithms

Implements IAlgManager.

Definition at line 229 of file AlgorithmManager.cpp.

    00229                                                {
    00230   StatusCode rc;
    00231   ListAlg::const_iterator it;
    00232   for (it = m_listmgralg->begin(); it != m_listmgralg->end(); it++ ) {
    00233     rc = (*it)->sysRestart();
    00234     if( rc.isFailure() ){
    00235       MsgStream log(msgSvc(), "AlgorithmManager");
    00236       log << MSG::ERROR << "Unable to re-initialize Service: " << (*it)->name() << endreq;
    00237       return rc;
    00238     }
    00239   }
    00240   return rc;
    00241 }

IMessageSvc * AlgorithmManager::msgSvc | ( |  | ) | `[private]`

Definition at line 243 of file AlgorithmManager.cpp.

    00243                                      {
    00244   // Access the message service if not yet done already
    00245   if( m_msgsvc == 0 ) {
    00246     m_svclocator->getService( "MessageSvc", IID_IMessageSvc,
    00247                               *pp_cast<IInterface>(&m_msgsvc) ).ignore();
    00248   }
    00249   return m_msgsvc;
    00250 }

## Member Data Documentation

IInterface* AlgorithmManager::m_pOuter`[private]`

Interface hub reference (ApplicationMgr).

Definition at line 78 of file AlgorithmManager.h.

unsigned long AlgorithmManager::m_refcount`[private]`

Reference counter.

Definition at line 79 of file AlgorithmManager.h.

ListAlg* AlgorithmManager::m_listalg`[private]`

List of algorithms maintained by AlgorithmManager.

Definition at line 80 of file AlgorithmManager.h.

ListAlg* AlgorithmManager::m_listmgralg`[private]`

List of managed algorithms maintained by AlgorithmManager.

Definition at line 81 of file AlgorithmManager.h.

ISvcLocator* AlgorithmManager::m_svclocator`[private]`

Service locator reference.

Definition at line 82 of file AlgorithmManager.h.

IMessageSvc* AlgorithmManager::m_msgsvc`[private]`

Pointer to the message service if it exists.

Definition at line 83 of file AlgorithmManager.h.

SmartIF<IStateful> AlgorithmManager::m_statemgr`[private]`

Pointer to the state machine.

Definition at line 84 of file AlgorithmManager.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r4/GaudiSvc/src/ApplicationMgr/AlgorithmManager.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r4/GaudiSvc/src/ApplicationMgr/AlgorithmManager.cpp