Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AlgorithmManager.cpp
Go to the documentation of this file.
1 // $Id: AlgorithmManager.cpp,v 1.11 2008/10/20 20:58:10 marcocle Exp $
2 
3 // Include files
4 #include "AlgorithmManager.h"
8 #include "GaudiKernel/System.h"
11 #include <iostream>
12 #ifndef _WIN32
13 #include <errno.h>
14 #endif
15 
18 
19 using ROOT::Reflex::PluginService;
20 
21 // constructor
23  base_class(application, IAlgorithm::interfaceID())
24 {
25  addRef(); // Initial count set to 1
26 }
27 
28 // destructor
30 }
31 
32 // addAlgorithm
34  m_listalg.push_back(alg);
35  return StatusCode::SUCCESS;
36 }
37 
38 // removeAlgorithm
41  if (it != m_listalg.end()) {
42  m_listalg.erase(it);
43  return StatusCode::SUCCESS;
44  }
45  return StatusCode::FAILURE;
46 }
47 
48 // createService
50  const std::string& algname,
51  IAlgorithm*& algorithm,
52  bool managed)
53 {
54  // Check is the algorithm is already existing
55  if( existsAlgorithm( algname ) ) {
56  // return an error because an algorithm with that name already exists
57  return StatusCode::FAILURE;
58  }
59  algorithm = PluginService::Create<IAlgorithm*>(algtype, algname, serviceLocator().get());
60  if ( !algorithm ) {
61  algorithm = PluginService::CreateWithId<IAlgorithm*>(algtype, algname, serviceLocator().get());
62  }
63  if ( algorithm ) {
64  // Check the compatibility of the version of the interface obtained
65  if( !isValidInterface(algorithm) ) {
66  fatal() << "Incompatible interface IAlgorithm version for " << algtype << endmsg;
67  return StatusCode::FAILURE;
68  }
69  StatusCode rc;
70  m_listalg.push_back(AlgorithmItem(algorithm, managed));
71  // this is needed to keep the reference count correct, since isValidInterface(algorithm)
72  // implies an increment of the counter by 1
73  algorithm->release();
74  if ( managed ) {
75  // Bring the created algorithm to the same state of the ApplicationMgr
77  rc = algorithm->sysInitialize();
79  rc = algorithm->sysStart();
80  }
81  }
82  if ( !rc.isSuccess() ) {
83  this->error() << "Failed to initialize algorithm: [" << algname << "]" << endmsg;
84  }
85  }
86  return rc;
87  }
88  this->error() << "Algorithm of type " << algtype
89  << " is unknown (No factory available)." << endmsg;
90 #ifndef _WIN32
91  errno = 0xAFFEDEAD; // code used by Gaudi for library load errors: forces getLastErrorString do use dlerror (on Linux)
92 #endif
94  if (! err.empty()) {
95  this->error() << err << endmsg;
96  }
97  this->error() << "More information may be available by setting the global jobOpt \"ReflexPluginDebugLevel\" to 1" << endmsg;
98 
99  return StatusCode::FAILURE;
100 }
101 
102 SmartIF<IAlgorithm>& AlgorithmManager::algorithm(const Gaudi::Utils::TypeNameString &typeName, const bool createIf) {
103  ListAlg::iterator it = std::find(m_listalg.begin(), m_listalg.end(), typeName.name());
104  if (it != m_listalg.end()) { // found
105  return it->algorithm;
106  }
107  if (createIf) {
108  IAlgorithm* alg;
109  if (createAlgorithm(typeName.type(), typeName.name(), alg, true).isSuccess()) {
110  return algorithm(typeName, false);
111  }
112  }
113  return no_algorithm;
114 }
115 
116 // existsAlgorithm
119  return it != m_listalg.end();
120 }
121 
122  // Return the list of Algorithms
124 {
126  for (ListAlg::const_iterator it = m_listalg.begin(); it != m_listalg.end(); ++it) {
127  m_listOfPtrs.push_back(const_cast<IAlgorithm*>(it->algorithm.get()));
128  }
129  return m_listOfPtrs;
130 }
131 
133  StatusCode rc;
135  for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
136  if (!it->managed) continue;
137  rc = it->algorithm->sysInitialize();
138  if ( rc.isFailure() ) return rc;
139  }
140  return rc;
141 }
142 
144  StatusCode rc;
146  for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
147  if (!it->managed) continue;
148  rc = it->algorithm->sysStart();
149  if ( rc.isFailure() ) return rc;
150  }
151  return rc;
152 }
153 
155  StatusCode rc;
157  for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
158  if (!it->managed) continue;
159  rc = it->algorithm->sysStop();
160  if ( rc.isFailure() ) return rc;
161  }
162  return rc;
163 }
164 
166  StatusCode rc;
168  while (it != m_listalg.end()){ // finalize and remove from the list the managed algorithms
169  if (it->managed) {
170  rc = it->algorithm->sysFinalize();
171  if( rc.isFailure() ) return rc;
172  it = m_listalg.erase(it);
173  } else {
174  ++it;
175  }
176  }
177  return rc;
178 }
179 
181  StatusCode rc;
183  for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
184  if (!it->managed) continue;
185  rc = it->algorithm->sysReinitialize();
186  if( rc.isFailure() ){
187  this->error() << "Unable to re-initialize algorithm: " << it->algorithm->name() << endmsg;
188  return rc;
189  }
190  }
191  return rc;
192 }
193 
195  StatusCode rc;
197  for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
198  if (!it->managed) continue;
199  rc = it->algorithm->sysRestart();
200  if( rc.isFailure() ){
201  this->error() << "Unable to re-initialize algorithm: " << it->algorithm->name() << endmsg;
202  return rc;
203  }
204  }
205  return rc;
206 }

Generated at Wed Nov 28 2012 12:17:11 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004