Gaudi Framework, version v21r4

Home   Generated: 7 Sep 2009

AlgorithmManager Class Reference

#include <AlgorithmManager.h>

Inheritance diagram for AlgorithmManager:

Inheritance graph
[legend]
Collaboration diagram for AlgorithmManager:

Collaboration graph
[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 32 of file AlgorithmManager.h.


Public Types

typedef std::list< AlgorithmItemListAlg
 typedefs and classes

Public Member Functions

 AlgorithmManager (IInterface *iface)
 default creator
virtual ~AlgorithmManager ()
 virtual destructor
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 bool existsAlgorithm (const std::string &name) const
 implementation of IAlgManager::existsAlgorithm
virtual const std::list
< IAlgorithm * > & 
getAlgorithms () const
 implementation of IAlgManager::getAlgorithms
virtual StatusCode initialize ()
 Initialization (from CONFIGURED to INITIALIZED).
virtual StatusCode start ()
 Start (from INITIALIZED to RUNNING).
virtual StatusCode stop ()
 Stop (from RUNNING to INITIALIZED).
virtual StatusCode finalize ()
 Finalize (from INITIALIZED to CONFIGURED).
virtual StatusCode reinitialize ()
 Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
virtual StatusCode restart ()
 Initialization (from RUNNING to RUNNING, via INITIALIZED).
const std::stringname () const
 Return the name of the manager (implementation of INamedInterface).
virtual SmartIF< IAlgorithm > & algorithm (const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
 Returns a smart pointer to a service.

Private Attributes

ListAlg m_listalg
 List of algorithms maintained by AlgorithmManager.
std::list< IAlgorithm * > m_listOfPtrs
 List of pointers to the know services used to implement getAlgorithms().

Classes

struct  AlgorithmItem

Member Typedef Documentation

typedefs and classes

Definition at line 49 of file AlgorithmManager.h.


Constructor & Destructor Documentation

AlgorithmManager::AlgorithmManager ( IInterface iface  ) 

default creator

Definition at line 22 of file AlgorithmManager.cpp.

00022                                                          :
00023   base_class(application, IAlgorithm::interfaceID())
00024 {
00025   addRef(); // Initial count set to 1
00026 }

AlgorithmManager::~AlgorithmManager (  )  [virtual]

virtual destructor

Definition at line 29 of file AlgorithmManager.cpp.

00029                                     {
00030 }


Member Function Documentation

StatusCode AlgorithmManager::addAlgorithm ( IAlgorithm alg  )  [virtual]

implementation of IAlgManager::addAlgorithm

Implements IAlgManager.

Definition at line 33 of file AlgorithmManager.cpp.

00033                                                          {
00034   m_listalg.push_back(alg);
00035   return StatusCode::SUCCESS;
00036 }

StatusCode AlgorithmManager::removeAlgorithm ( IAlgorithm alg  )  [virtual]

implementation of IAlgManager::removeAlgorithm

Implements IAlgManager.

Definition at line 39 of file AlgorithmManager.cpp.

00039                                                             {
00040   ListAlg::iterator it = std::find(m_listalg.begin(), m_listalg.end(), alg);
00041   if (it != m_listalg.end()) {
00042     m_listalg.erase(it);
00043     return StatusCode::SUCCESS;
00044   }
00045   return StatusCode::FAILURE;
00046 }

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 49 of file AlgorithmManager.cpp.

00053 {
00054   // Check is the algorithm is already existing
00055   if( existsAlgorithm( algname ) ) {
00056     // return an error because an algorithm with that name already exists
00057     return StatusCode::FAILURE;
00058   }
00059   algorithm = PluginService::Create<IAlgorithm*>(algtype, algname, serviceLocator().get());
00060   if ( !algorithm ) {
00061     algorithm = PluginService::CreateWithId<IAlgorithm*>(algtype, algname, serviceLocator().get());
00062   }
00063   if ( algorithm ) {
00064     // Check the compatibility of the version of the interface obtained
00065     if( !isValidInterface(algorithm) ) {
00066       fatal() << "Incompatible interface IAlgorithm version for " << algtype << endmsg;
00067       return StatusCode::FAILURE;
00068     }
00069     StatusCode rc;
00070     m_listalg.push_back(AlgorithmItem(algorithm, managed));
00071     if ( managed ) {
00072       // Bring the created algorithm to the same state of the ApplicationMgr
00073       if (FSMState() >= Gaudi::StateMachine::INITIALIZED) {
00074         rc = algorithm->sysInitialize();
00075         if (rc.isSuccess() && FSMState() >= Gaudi::StateMachine::RUNNING) {
00076           rc = algorithm->sysStart();
00077         }
00078       }
00079       if ( !rc.isSuccess() )  {
00080         this->error() << "Failed to initialize algorithm: [" << algname << "]" << endmsg;
00081       }
00082     }
00083     return rc;
00084   }
00085   this->error() << "Algorithm of type " << algtype
00086                 << " is unknown (No factory available)." << endmsg;
00087 #ifndef _WIN32
00088   errno = 0xAFFEDEAD; // code used by Gaudi for library load errors: forces getLastErrorString do use dlerror (on Linux)
00089 #endif
00090   std::string err = System::getLastErrorString();
00091   if (! err.empty()) {
00092     this->error() << err << endmsg;
00093   }
00094   this->error() << "More information may be available by setting the global jobOpt \"ReflexPluginDebugLevel\" to 1" << endmsg;
00095 
00096   return StatusCode::FAILURE;
00097 }

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

implementation of IAlgManager::existsAlgorithm

Implements IAlgManager.

Definition at line 114 of file AlgorithmManager.cpp.

00114                                                                   {
00115   ListAlg::const_iterator it = std::find(m_listalg.begin(), m_listalg.end(), name);
00116   return it != m_listalg.end();
00117 }

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

implementation of IAlgManager::getAlgorithms

Implements IAlgManager.

Definition at line 120 of file AlgorithmManager.cpp.

00121 {
00122   m_listOfPtrs.clear();
00123   for (ListAlg::const_iterator it = m_listalg.begin(); it != m_listalg.end(); ++it) {
00124     m_listOfPtrs.push_back(const_cast<IAlgorithm*>(it->algorithm.get()));
00125   }
00126   return m_listOfPtrs;
00127 }

StatusCode AlgorithmManager::initialize (  )  [virtual]

Initialization (from CONFIGURED to INITIALIZED).

Reimplemented from ComponentManager.

Definition at line 129 of file AlgorithmManager.cpp.

00129                                         {
00130   StatusCode rc;
00131   ListAlg::iterator it;
00132   for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
00133     if (!it->managed) continue;
00134     rc = it->algorithm->sysInitialize();
00135     if ( rc.isFailure() ) return rc;
00136   }
00137   return rc;
00138 }

StatusCode AlgorithmManager::start (  )  [virtual]

Start (from INITIALIZED to RUNNING).

Reimplemented from ComponentManager.

Definition at line 140 of file AlgorithmManager.cpp.

00140                                    {
00141   StatusCode rc;
00142   ListAlg::iterator it;
00143   for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
00144     if (!it->managed) continue;
00145     rc = it->algorithm->sysStart();
00146     if ( rc.isFailure() ) return rc;
00147   }
00148   return rc;
00149 }

StatusCode AlgorithmManager::stop (  )  [virtual]

Stop (from RUNNING to INITIALIZED).

Reimplemented from ComponentManager.

Definition at line 151 of file AlgorithmManager.cpp.

00151                                   {
00152   StatusCode rc;
00153   ListAlg::iterator it;
00154   for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
00155     if (!it->managed) continue;
00156     rc = it->algorithm->sysStop();
00157     if ( rc.isFailure() ) return rc;
00158   }
00159   return rc;
00160 }

StatusCode AlgorithmManager::finalize ( void   )  [virtual]

Finalize (from INITIALIZED to CONFIGURED).

Reimplemented from ComponentManager.

Definition at line 162 of file AlgorithmManager.cpp.

00162                                       {
00163   StatusCode rc;
00164   ListAlg::iterator it = m_listalg.begin();
00165   while (it != m_listalg.end()){ // finalize and remove from the list the managed algorithms
00166     if (it->managed) {
00167       rc = it->algorithm->sysFinalize();
00168       if( rc.isFailure() ) return rc;
00169       it = m_listalg.erase(it);
00170     } else {
00171       ++it;
00172     }
00173   }
00174   return rc;
00175 }

StatusCode AlgorithmManager::reinitialize (  )  [virtual]

Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).

Reimplemented from ComponentManager.

Definition at line 177 of file AlgorithmManager.cpp.

00177                                           {
00178   StatusCode rc;
00179   ListAlg::iterator it;
00180   for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
00181     if (!it->managed) continue;
00182     rc = it->algorithm->sysReinitialize();
00183     if( rc.isFailure() ){
00184       this->error() << "Unable to re-initialize algorithm: " << it->algorithm->name() << endmsg;
00185       return rc;
00186     }
00187   }
00188   return rc;
00189 }

StatusCode AlgorithmManager::restart (  )  [virtual]

Initialization (from RUNNING to RUNNING, via INITIALIZED).

Reimplemented from ComponentManager.

Definition at line 191 of file AlgorithmManager.cpp.

00191                                      {
00192   StatusCode rc;
00193   ListAlg::iterator it;
00194   for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
00195     if (!it->managed) continue;
00196     rc = it->algorithm->sysRestart();
00197     if( rc.isFailure() ){
00198       this->error() << "Unable to re-initialize algorithm: " << it->algorithm->name() << endmsg;
00199       return rc;
00200     }
00201   }
00202   return rc;
00203 }

const std::string& AlgorithmManager::name (  )  const [inline, virtual]

Return the name of the manager (implementation of INamedInterface).

Implements CommonMessaging< implements1< IComponentManager > >.

Definition at line 84 of file AlgorithmManager.h.

00084                                 {
00085     static std::string _name = "AlgorithmManager";
00086     return _name;
00087   }

SmartIF< IAlgorithm > & AlgorithmManager::algorithm ( const Gaudi::Utils::TypeNameString &  typeName,
const bool  createIf = true 
) [virtual]

Returns a smart pointer to a service.

Implements IAlgManager.

Definition at line 99 of file AlgorithmManager.cpp.

00099                                                                                                               {
00100   ListAlg::iterator it = std::find(m_listalg.begin(), m_listalg.end(), typeName.name());
00101   if (it != m_listalg.end()) { // found
00102     return it->algorithm;
00103   }
00104   if (createIf) {
00105     IAlgorithm* alg;
00106     if (createAlgorithm(typeName.type(), typeName.name(), alg, true).isSuccess()) {
00107       return algorithm(typeName, false);
00108     }
00109   }
00110   return no_algorithm;
00111 }


Member Data Documentation

List of algorithms maintained by AlgorithmManager.

Definition at line 92 of file AlgorithmManager.h.

List of pointers to the know services used to implement getAlgorithms().

Definition at line 95 of file AlgorithmManager.h.


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

Generated at Mon Sep 7 18:16:46 2009 for Gaudi Framework, version v21r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004