Gaudi Framework, version v21r11

Home   Generated: 30 Sep 2010

AlgorithmManager Class Reference

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

#include <AlgorithmManager.h>

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

List of all members.

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


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.


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     // this is needed to keep the reference count correct, since isValidInterface(algorithm)
00072     // implies an increment of the counter by 1
00073     algorithm->release();
00074     if ( managed ) {
00075       // Bring the created algorithm to the same state of the ApplicationMgr
00076       if (FSMState() >= Gaudi::StateMachine::INITIALIZED) {
00077         rc = algorithm->sysInitialize();
00078         if (rc.isSuccess() && FSMState() >= Gaudi::StateMachine::RUNNING) {
00079           rc = algorithm->sysStart();
00080         }
00081       }
00082       if ( !rc.isSuccess() )  {
00083         this->error() << "Failed to initialize algorithm: [" << algname << "]" << endmsg;
00084       }
00085     }
00086     return rc;
00087   }
00088   this->error() << "Algorithm of type " << algtype
00089                 << " is unknown (No factory available)." << endmsg;
00090 #ifndef _WIN32
00091   errno = 0xAFFEDEAD; // code used by Gaudi for library load errors: forces getLastErrorString do use dlerror (on Linux)
00092 #endif
00093   std::string err = System::getLastErrorString();
00094   if (! err.empty()) {
00095     this->error() << err << endmsg;
00096   }
00097   this->error() << "More information may be available by setting the global jobOpt \"ReflexPluginDebugLevel\" to 1" << endmsg;
00098 
00099   return StatusCode::FAILURE;
00100 }

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

implementation of IAlgManager::existsAlgorithm

Implements IAlgManager.

Definition at line 117 of file AlgorithmManager.cpp.

00117                                                                   {
00118   ListAlg::const_iterator it = std::find(m_listalg.begin(), m_listalg.end(), name);
00119   return it != m_listalg.end();
00120 }

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

implementation of IAlgManager::getAlgorithms

Implements IAlgManager.

Definition at line 123 of file AlgorithmManager.cpp.

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

StatusCode AlgorithmManager::initialize (  )  [virtual]

Initialization (from CONFIGURED to INITIALIZED).

Reimplemented from ComponentManager.

Definition at line 132 of file AlgorithmManager.cpp.

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

StatusCode AlgorithmManager::start (  )  [virtual]

Start (from INITIALIZED to RUNNING).

Reimplemented from ComponentManager.

Definition at line 143 of file AlgorithmManager.cpp.

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

StatusCode AlgorithmManager::stop (  )  [virtual]

Stop (from RUNNING to INITIALIZED).

Reimplemented from ComponentManager.

Definition at line 154 of file AlgorithmManager.cpp.

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

StatusCode AlgorithmManager::finalize (  )  [virtual]

Finalize (from INITIALIZED to CONFIGURED).

Reimplemented from ComponentManager.

Definition at line 165 of file AlgorithmManager.cpp.

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

StatusCode AlgorithmManager::reinitialize (  )  [virtual]

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

Reimplemented from ComponentManager.

Definition at line 180 of file AlgorithmManager.cpp.

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

StatusCode AlgorithmManager::restart (  )  [virtual]

Initialization (from RUNNING to RUNNING, via INITIALIZED).

Reimplemented from ComponentManager.

Definition at line 194 of file AlgorithmManager.cpp.

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

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

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


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 Thu Sep 30 09:58:21 2010 for Gaudi Framework, version v21r11 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004