Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 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  std::string actualalgtype(algtype);
60  // a '\' in front of the type name prevents alias replacement
61  if ((actualalgtype.size() > 8) && (actualalgtype.substr(0, 8) == "unalias:")) {
62  actualalgtype = actualalgtype.substr(8);
63  } else {
65  if (typeAlias != m_algTypeAliases.end()) {
66  actualalgtype = typeAlias->second;
67  }
68  }
69  algorithm = PluginService::Create<IAlgorithm*>(actualalgtype, algname, serviceLocator().get());
70  if ( !algorithm ) {
71  algorithm = PluginService::CreateWithId<IAlgorithm*>(actualalgtype, algname, serviceLocator().get());
72  }
73  if ( algorithm ) {
74  // Check the compatibility of the version of the interface obtained
75  if( !isValidInterface(algorithm) ) {
76  fatal() << "Incompatible interface IAlgorithm version for " << actualalgtype << endmsg;
77  return StatusCode::FAILURE;
78  }
79  StatusCode rc;
80  m_listalg.push_back(AlgorithmItem(algorithm, managed));
81  // this is needed to keep the reference count correct, since isValidInterface(algorithm)
82  // implies an increment of the counter by 1
83  algorithm->release();
84  if ( managed ) {
85  // Bring the created algorithm to the same state of the ApplicationMgr
87  rc = algorithm->sysInitialize();
89  rc = algorithm->sysStart();
90  }
91  }
92  if ( !rc.isSuccess() ) {
93  this->error() << "Failed to initialize algorithm: [" << algname << "]" << endmsg;
94  }
95  }
96  return rc;
97  }
98  this->error() << "Algorithm of type " << actualalgtype
99  << " is unknown (No factory available)." << endmsg;
100 #ifndef _WIN32
101  errno = 0xAFFEDEAD; // code used by Gaudi for library load errors: forces getLastErrorString do use dlerror (on Linux)
102 #endif
104  if (! err.empty()) {
105  this->error() << err << endmsg;
106  }
107  this->error() << "More information may be available by setting the global jobOpt \"ReflexPluginDebugLevel\" to 1" << endmsg;
108 
109  return StatusCode::FAILURE;
110 }
111 
112 SmartIF<IAlgorithm>& AlgorithmManager::algorithm(const Gaudi::Utils::TypeNameString &typeName, const bool createIf) {
113  ListAlg::iterator it = std::find(m_listalg.begin(), m_listalg.end(), typeName.name());
114  if (it != m_listalg.end()) { // found
115  return it->algorithm;
116  }
117  if (createIf) {
118  IAlgorithm* alg;
119  if (createAlgorithm(typeName.type(), typeName.name(), alg, true).isSuccess()) {
120  return algorithm(typeName, false);
121  }
122  }
123  return no_algorithm;
124 }
125 
126 // existsAlgorithm
129  return it != m_listalg.end();
130 }
131 
132  // Return the list of Algorithms
134 {
136  for (ListAlg::const_iterator it = m_listalg.begin(); it != m_listalg.end(); ++it) {
137  m_listOfPtrs.push_back(const_cast<IAlgorithm*>(it->algorithm.get()));
138  }
139  return m_listOfPtrs;
140 }
141 
143  StatusCode rc;
145  for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
146  if (!it->managed) continue;
147  rc = it->algorithm->sysInitialize();
148  if ( rc.isFailure() ) return rc;
149  }
150  return rc;
151 }
152 
154  StatusCode rc;
156  for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
157  if (!it->managed) continue;
158  rc = it->algorithm->sysStart();
159  if ( rc.isFailure() ) return rc;
160  }
161  return rc;
162 }
163 
165  StatusCode rc;
167  for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
168  if (!it->managed) continue;
169  rc = it->algorithm->sysStop();
170  if ( rc.isFailure() ) return rc;
171  }
172  return rc;
173 }
174 
176  StatusCode rc;
178  while (it != m_listalg.end()){ // finalize and remove from the list the managed algorithms
179  if (it->managed) {
180  rc = it->algorithm->sysFinalize();
181  if( rc.isFailure() ) return rc;
182  it = m_listalg.erase(it);
183  } else {
184  ++it;
185  }
186  }
187  return rc;
188 }
189 
191  StatusCode rc;
193  for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
194  if (!it->managed) continue;
195  rc = it->algorithm->sysReinitialize();
196  if( rc.isFailure() ){
197  this->error() << "Unable to re-initialize algorithm: " << it->algorithm->name() << endmsg;
198  return rc;
199  }
200  }
201  return rc;
202 }
203 
205  StatusCode rc;
207  for (it = m_listalg.begin(); it != m_listalg.end(); ++it) {
208  if (!it->managed) continue;
209  rc = it->algorithm->sysRestart();
210  if( rc.isFailure() ){
211  this->error() << "Unable to re-initialize algorithm: " << it->algorithm->name() << endmsg;
212  return rc;
213  }
214  }
215  return rc;
216 }

Generated at Wed Dec 4 2013 14:33:07 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004