The Gaudi Framework  v33r0 (d5ea422b)
AlgResourcePool Class Reference

The AlgResourcePool is a concrete implementation of the IAlgResourcePool interface. More...

#include <GaudiHive/AlgResourcePool.h>

Inheritance diagram for AlgResourcePool:
Collaboration diagram for AlgResourcePool:

Public Member Functions

 ~AlgResourcePool () override
 
StatusCode start () override
 
StatusCode initialize () override
 
StatusCode acquireAlgorithm (const std::string &name, IAlgorithm *&algo, bool blocking=false) override
 Acquire a certain algorithm using its name. More...
 
StatusCode releaseAlgorithm (const std::string &name, IAlgorithm *&algo) override
 Release a certain algorithm. More...
 
StatusCode acquireResource (const std::string &name) override
 Acquire a certain resource. More...
 
StatusCode releaseResource (const std::string &name) override
 Release a certrain resource. More...
 
std::list< IAlgorithm * > getFlatAlgList () override
 
std::list< IAlgorithm * > getTopAlgList () override
 
StatusCode stop () override
 
- Public Member Functions inherited from extends< Service, IAlgResourcePool >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service. More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service. More...
 
StatusCode sysStart () override
 Initialize Service. More...
 
StatusCode sysStop () override
 Initialize Service. More...
 
StatusCode sysFinalize () override
 Finalize Service. More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, std::string toolTypeAndName, bool createIf=true)
 Declare used tool. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p) override
 set the property form another property More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 set the property from name and the value More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (const std::string &name) const override
 get the property by name More...
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (const std::string &name) const override
 Return true if we have a property with the given name. More...
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const
 Backward compatibility function for getting the output level. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 

Private Types

typedef tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
 
typedef std::list< SmartIF< IAlgorithm > > ListAlg
 
typedef boost::dynamic_bitset state_type
 

Private Member Functions

StatusCode decodeTopAlgs ()
 Decode the top alg list. More...
 
StatusCode flattenSequencer (Gaudi::Algorithm *sequencer, ListAlg &alglist, unsigned int recursionDepth=0)
 Recursively flatten an algList. More...
 

Private Attributes

std::mutex m_resource_mutex
 
state_type m_available_resources {0}
 
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
 
std::map< size_t, state_typem_resource_requirements
 
std::map< size_t, size_t > m_n_of_allowed_instances
 
std::map< size_t, unsigned int > m_n_of_created_instances
 
std::map< std::string, unsigned int > m_resource_indices
 
Gaudi::Property< bool > m_lazyCreation {this, "CreateLazily", false, ""}
 
Gaudi::Property< std::vector< std::string > > m_topAlgNames
 
Gaudi::Property< bool > m_overrideUnClonable
 
ListAlg m_algList
 The list of all algorithms created withing the Pool which are not top. More...
 
ListAlg m_topAlgList
 The list of top algorithms. More...
 
ListAlg m_flatUniqueAlgList
 The flat list of algorithms w/o clones. More...
 
std::list< IAlgorithm * > m_flatUniqueAlgPtrList
 The flat list of algorithms w/o clones which is returned. More...
 
std::list< IAlgorithm * > m_topAlgPtrList
 The top list of algorithms. More...
 

Additional Inherited Members

- Public Types inherited from extends< Service, IAlgResourcePool >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
- Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory< IService *(const std::string &, ISvcLocator *)>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl = PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Member Functions inherited from Service
 ~Service () override
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
Gaudi::Details::PropertyBaseproperty (const std::string &name) const
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches. More...
 
MSG::Level resetMessaging ()
 Reinitialize internal states. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::Property< int > m_outputLevel {this, "OutputLevel", MSG::NIL, "output level"}
 
Gaudi::Property< bool > m_auditInit {this, "AuditServices", false, " unused"}
 
Gaudi::Property< bool > m_auditorInitialize {this, "AuditInitialize", false, "trigger auditor on initialize()"}
 
Gaudi::Property< bool > m_auditorStart {this, "AuditStart", false, "trigger auditor on start()"}
 
Gaudi::Property< bool > m_auditorStop {this, "AuditStop", false, "trigger auditor on stop()"}
 
Gaudi::Property< bool > m_auditorFinalize {this, "AuditFinalize", false, "trigger auditor on finalize()"}
 
Gaudi::Property< bool > m_auditorReinitialize {this, "AuditReinitialize", false, "trigger auditor on reinitialize()"}
 
Gaudi::Property< bool > m_auditorRestart {this, "AuditRestart", false, "trigger auditor on restart()"}
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service. More...
 

Detailed Description

The AlgResourcePool is a concrete implementation of the IAlgResourcePool interface.

It either creates all instances upfront or lazily. Internal bookkeeping is done via hashes of the algo names.

Author
Benedikt Hegner

Definition at line 39 of file AlgResourcePool.h.

Member Typedef Documentation

◆ concurrentQueueIAlgPtr

typedef tbb::concurrent_bounded_queue<IAlgorithm*> AlgResourcePool::concurrentQueueIAlgPtr
private

Definition at line 63 of file AlgResourcePool.h.

◆ ListAlg

Definition at line 64 of file AlgResourcePool.h.

◆ state_type

typedef boost::dynamic_bitset AlgResourcePool::state_type
private

Definition at line 65 of file AlgResourcePool.h.

Constructor & Destructor Documentation

◆ ~AlgResourcePool()

AlgResourcePool::~AlgResourcePool ( )
override

Definition at line 30 of file AlgResourcePool.cpp.

30  {
31  for ( auto& algoId_algoQueue : m_algqueue_map ) {
32  auto* queue = algoId_algoQueue.second;
33  delete queue;
34  }
35 }
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map

Member Function Documentation

◆ acquireAlgorithm()

StatusCode AlgResourcePool::acquireAlgorithm ( const std::string name,
IAlgorithm *&  algo,
bool  blocking = false 
)
override

Acquire a certain algorithm using its name.

Definition at line 81 of file AlgResourcePool.cpp.

81  {
82 
83  std::hash<std::string> hash_function;
84  size_t algo_id = hash_function( name );
85  auto itQueueIAlgPtr = m_algqueue_map.find( algo_id );
86 
87  if ( itQueueIAlgPtr == m_algqueue_map.end() ) {
88  error() << "Algorithm " << name << " requested, but not recognised" << endmsg;
89  algo = nullptr;
90  return StatusCode::FAILURE;
91  }
92 
93  StatusCode sc;
94  if ( blocking ) {
95  itQueueIAlgPtr->second->pop( algo );
96  } else {
97  if ( !itQueueIAlgPtr->second->try_pop( algo ) ) { sc = StatusCode::FAILURE; }
98  }
99 
100  // Note that reentrant algos are not consumed so we put them
101  // back immediately in the queue at the end of this function.
102  // Now we may still be called again in between and get this
103  // error. In such a case, the Scheduler will retry later.
104  // This is of course not optimal, but should only happen very
105  // seldom and thud won't affect the global efficiency
106  if ( sc.isFailure() )
107  DEBUG_MSG << "No instance of algorithm " << name << " could be retrieved in non-blocking mode" << endmsg;
108 
109  // if (m_lazyCreation ) {
110  // TODO: fill the lazyCreation part
111  // }
112  if ( sc.isSuccess() ) {
113  state_type requirements = m_resource_requirements[algo_id];
115  if ( requirements.is_subset_of( m_available_resources ) ) {
116  m_available_resources ^= requirements;
117  } else {
118  sc = StatusCode::FAILURE;
119  error() << "Failure to allocate resources of algorithm " << name << endmsg;
120  // in case of not reentrant, push it back. Reentrant ones are pushed back
121  // in all cases further down
122  if ( 0 != algo->cardinality() ) { itQueueIAlgPtr->second->push( algo ); }
123  }
125  if ( 0 == algo->cardinality() ) {
126  // push back reentrant algos immediately as it can be reused
127  itQueueIAlgPtr->second->push( algo );
128  }
129  }
130  return sc;
131 }
T unlock(T... args)
std::mutex m_resource_mutex
T end(T... args)
virtual unsigned int cardinality() const =0
Cardinality (Maximum number of clones that can exist) special value 0 means that algorithm is reentra...
state_type m_available_resources
boost::dynamic_bitset state_type
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
std::map< size_t, state_type > m_resource_requirements
T lock(T... args)
bool isSuccess() const
Definition: StatusCode.h:361
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
T find(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97
bool isFailure() const
Definition: StatusCode.h:141
#define DEBUG_MSG
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ acquireResource()

StatusCode AlgResourcePool::acquireResource ( const std::string name)
override

Acquire a certain resource.

Definition at line 152 of file AlgResourcePool.cpp.

152  {
156  return StatusCode::SUCCESS;
157 }
T unlock(T... args)
std::map< std::string, unsigned int > m_resource_indices
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
std::mutex m_resource_mutex
state_type m_available_resources
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
T lock(T... args)

◆ decodeTopAlgs()

StatusCode AlgResourcePool::decodeTopAlgs ( )
private

Decode the top alg list.

Definition at line 203 of file AlgResourcePool.cpp.

203  {
204 
206  if ( !algMan.isValid() ) {
207  error() << "Algorithm manager could not be properly fetched." << endmsg;
208  return StatusCode::FAILURE;
209  }
210 
211  // Useful lambda not to repeat ourselves --------------------------
212  auto createAlg = [&algMan, this]( const std::string& item_type, const std::string& item_name, IAlgorithm*& algo ) {
213  StatusCode createAlgSc = algMan->createAlgorithm( item_type, item_name, algo, true, false );
214  if ( createAlgSc.isFailure() )
215  this->warning() << "Algorithm " << item_type << "/" << item_name << " could not be created." << endmsg;
216  };
217  // End of lambda --------------------------------------------------
218 
220 
221  // Fill the top alg list ----
222  const std::vector<std::string>& topAlgNames = m_topAlgNames.value();
223  for ( auto& name : topAlgNames ) {
224  IAlgorithm* algo( nullptr );
225 
227  const std::string& item_name = item.name();
228  const std::string& item_type = item.type();
229  SmartIF<IAlgorithm> algoSmartIF( algMan->algorithm( item_name, false ) );
230 
231  if ( !algoSmartIF.isValid() ) {
232  createAlg( item_type, item_name, algo );
233  algoSmartIF = algo;
234  }
235  // Init and start
236  algoSmartIF->sysInitialize().ignore();
237  m_topAlgList.push_back( algoSmartIF );
238  }
239  // Top Alg list filled ----
240 
241  // Now we unroll it ----
242  for ( auto& algoSmartIF : m_topAlgList ) {
243  Gaudi::Algorithm* algorithm = dynamic_cast<Gaudi::Algorithm*>( algoSmartIF.get() );
244  if ( !algorithm ) {
245  fatal() << "Conversion from IAlgorithm to Gaudi::Algorithm failed" << endmsg;
246  return StatusCode::FAILURE;
247  }
248  sc = flattenSequencer( algorithm, m_flatUniqueAlgList );
249  }
250  // stupid O(N^2) unique-ification..
251  for ( auto i = begin( m_flatUniqueAlgList ); i != end( m_flatUniqueAlgList ); ++i ) {
252  auto n = next( i );
253  while ( n != end( m_flatUniqueAlgList ) ) {
254  if ( *n == *i )
256  else
257  ++n;
258  }
259  }
260  if ( msgLevel( MSG::DEBUG ) ) {
261  debug() << "List of algorithms is: " << endmsg;
262  for ( auto& algo : m_flatUniqueAlgList )
263  debug() << " o " << algo->type() << "/" << algo->name() << " @ " << algo << endmsg;
264  }
265 
266  // Unrolled ---
267 
268  // Now let's manage the clones
269  unsigned int resource_counter( 0 );
270  std::hash<std::string> hash_function;
271  for ( auto& ialgoSmartIF : m_flatUniqueAlgList ) {
272 
273  const std::string& item_name = ialgoSmartIF->name();
274 
275  verbose() << "Treating resource management and clones of " << item_name << endmsg;
276 
277  Gaudi::Algorithm* algo = dynamic_cast<Gaudi::Algorithm*>( ialgoSmartIF.get() );
278  if ( !algo ) {
279  fatal() << "Conversion from IAlgorithm to Gaudi::Algorithm failed" << endmsg;
280  return StatusCode::FAILURE;
281  }
282  const std::string& item_type = algo->type();
283 
284  size_t algo_id = hash_function( item_name );
286  m_algqueue_map[algo_id] = queue;
287 
288  // DP TODO Do it properly with SmartIFs, also in the queues
289  IAlgorithm* ialgo( ialgoSmartIF.get() );
290 
291  queue->push( ialgo );
292  m_algList.push_back( ialgo );
293  if ( ialgo->isReEntrant() ) {
294  if ( ialgo->cardinality() != 0 ) {
295  info() << "Algorithm " << ialgo->name() << " is ReEntrant, but Cardinality was set to " << ialgo->cardinality()
296  << endmsg;
297  m_n_of_allowed_instances[algo_id] = ialgo->cardinality();
298  } else {
299  m_n_of_allowed_instances[algo_id] = 1;
300  }
301  } else if ( ialgo->isClonable() ) {
302  m_n_of_allowed_instances[algo_id] = ialgo->cardinality();
303  } else {
304  if ( ialgo->cardinality() == 1 ) {
305  m_n_of_allowed_instances[algo_id] = 1;
306  } else {
307  if ( !m_overrideUnClonable ) {
308  info() << "Algorithm " << ialgo->name() << " is un-Clonable but Cardinality was set to "
309  << ialgo->cardinality() << ". Only creating 1 instance" << endmsg;
310  m_n_of_allowed_instances[algo_id] = 1;
311  } else {
312  warning() << "Overriding UnClonability of Algorithm " << ialgo->name() << ". Setting Cardinality to "
313  << ialgo->cardinality() << endmsg;
314  m_n_of_allowed_instances[algo_id] = ialgo->cardinality();
315  }
316  }
317  }
318  m_n_of_created_instances[algo_id] = 1;
319 
320  state_type requirements( 0 );
321 
322  for ( auto& resource_name : ialgo->neededResources() ) {
323  auto ret = m_resource_indices.emplace( resource_name, resource_counter );
324  // insert successful means == wasn't known before. So increment counter
325  if ( ret.second ) ++resource_counter;
326  // Resize for every algo according to the found resources
327  requirements.resize( resource_counter );
328  // in any case the return value holds the proper product index
329  requirements[ret.first->second] = true;
330  }
331 
332  m_resource_requirements[algo_id] = requirements;
333 
334  // potentially create clones; if not lazy creation we have to do it now
335  if ( !m_lazyCreation ) {
336  for ( unsigned int i = 1, end = m_n_of_allowed_instances[algo_id]; i < end; ++i ) {
337  debug() << "type/name to create clone of: " << item_type << "/" << item_name << endmsg;
338  IAlgorithm* ialgoClone( nullptr );
339  createAlg( item_type, item_name, ialgoClone );
340  ialgoClone->setIndex( i );
341  if ( ialgoClone->sysInitialize().isFailure() ) {
342  error() << "unable to initialize Algorithm clone " << ialgoClone->name() << endmsg;
343  sc = StatusCode::FAILURE;
344  // FIXME: should we delete this failed clone?
345  } else {
346  queue->push( ialgoClone );
347  m_n_of_created_instances[algo_id] += 1;
348  }
349  }
350  }
351  }
352 
353  // Now resize all the requirement bitsets to the same size
354  for ( auto& kv : m_resource_requirements ) { kv.second.resize( resource_counter ); }
355 
356  // Set all resources to be available
357  m_available_resources.resize( resource_counter );
358  m_available_resources.set();
359 
360  return sc;
361 }
ListAlg m_flatUniqueAlgList
The flat list of algorithms w/o clones.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:287
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
std::map< std::string, unsigned int > m_resource_indices
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
state_type m_available_resources
Gaudi::Property< bool > m_overrideUnClonable
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
boost::dynamic_bitset state_type
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
T push_back(T... args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Helper class to parse a string of format "type/name".
tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
T next(T... args)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
const std::string & type() const override
The type of the algorithm object.
Definition: Algorithm.h:163
std::map< size_t, state_type > m_resource_requirements
T erase(T... args)
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
def end
Definition: IOTest.py:123
Gaudi::Property< std::vector< std::string > > m_topAlgNames
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:38
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
StatusCode flattenSequencer(Gaudi::Algorithm *sequencer, ListAlg &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:89
T emplace(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97
std::map< size_t, unsigned int > m_n_of_created_instances
bool isFailure() const
Definition: StatusCode.h:141
AttribStringParser::Iterator begin(const AttribStringParser &parser)
ListAlg m_topAlgList
The list of top algorithms.
std::map< size_t, size_t > m_n_of_allowed_instances
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
ListAlg m_algList
The list of all algorithms created withing the Pool which are not top.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
Gaudi::Property< bool > m_lazyCreation

◆ flattenSequencer()

StatusCode AlgResourcePool::flattenSequencer ( Gaudi::Algorithm sequencer,
ListAlg alglist,
unsigned int  recursionDepth = 0 
)
private

Recursively flatten an algList.

Definition at line 170 of file AlgResourcePool.cpp.

170  {
171 
173 
174  if ( algo->isSequence() ) {
175  auto seq = dynamic_cast<Gaudi::Sequence*>( algo );
176  if ( seq == 0 ) {
177  error() << "Unable to dcast Algorithm " << algo->name() << " to a Sequence, but it has isSequence==true"
178  << endmsg;
179  return StatusCode::FAILURE;
180  }
181 
182  auto subAlgorithms = seq->subAlgorithms();
183 
184  // Recursively unroll
185  ++recursionDepth;
186 
187  for ( auto subalgo : *subAlgorithms ) {
188  sc = flattenSequencer( subalgo, alglist, recursionDepth );
189  if ( sc.isFailure() ) {
190  error() << "Algorithm " << subalgo->name() << " could not be flattened" << endmsg;
191  return sc;
192  }
193  }
194  } else {
195  alglist.emplace_back( algo );
196  return sc;
197  }
198  return sc;
199 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
StatusCode flattenSequencer(Gaudi::Algorithm *sequencer, ListAlg &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
constexpr static const auto FAILURE
Definition: StatusCode.h:97
bool isFailure() const
Definition: StatusCode.h:141
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getFlatAlgList()

std::list< IAlgorithm * > AlgResourcePool::getFlatAlgList ( )
override

Definition at line 365 of file AlgResourcePool.cpp.

365  {
367  for ( auto algoSmartIF : m_flatUniqueAlgList ) m_flatUniqueAlgPtrList.push_back( algoSmartIF.get() );
368  return m_flatUniqueAlgPtrList;
369 }
ListAlg m_flatUniqueAlgList
The flat list of algorithms w/o clones.
T push_back(T... args)
std::list< IAlgorithm * > m_flatUniqueAlgPtrList
The flat list of algorithms w/o clones which is returned.
T clear(T... args)

◆ getTopAlgList()

std::list< IAlgorithm * > AlgResourcePool::getTopAlgList ( )
override

Definition at line 373 of file AlgResourcePool.cpp.

373  {
375  for ( auto algoSmartIF : m_topAlgList ) m_topAlgPtrList.push_back( algoSmartIF.get() );
376  return m_topAlgPtrList;
377 }
T push_back(T... args)
std::list< IAlgorithm * > m_topAlgPtrList
The top list of algorithms.
T clear(T... args)
ListAlg m_topAlgList
The list of top algorithms.

◆ initialize()

StatusCode AlgResourcePool::initialize ( )
override

Definition at line 40 of file AlgResourcePool.cpp.

40  {
41 
43  if ( !sc.isSuccess() ) warning() << "Base class could not be started" << endmsg;
44 
45  // Try to recover the topAlgList from the ApplicationManager for backward-compatibility
46  if ( m_topAlgNames.value().empty() ) {
47  info() << "TopAlg list empty. Recovering the one of Application Manager" << endmsg;
48  const Gaudi::Utils::TypeNameString appMgrName( "ApplicationMgr/ApplicationMgr" );
49  SmartIF<IProperty> appMgrProps( serviceLocator()->service( appMgrName ) );
50  m_topAlgNames.assign( appMgrProps->getProperty( "TopAlg" ) );
51  }
52 
53  sc = decodeTopAlgs();
54  if ( sc.isFailure() ) warning() << "Algorithms could not be properly decoded." << endmsg;
55 
56  // let's assume all resources are there
58  return StatusCode::SUCCESS;
59 }
StatusCode initialize() override
Definition: Service.cpp:70
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:287
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
state_type m_available_resources
Helper class to parse a string of format "type/name".
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
Gaudi::Property< std::vector< std::string > > m_topAlgNames
StatusCode decodeTopAlgs()
Decode the top alg list.
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:93
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ releaseAlgorithm()

StatusCode AlgResourcePool::releaseAlgorithm ( const std::string name,
IAlgorithm *&  algo 
)
override

Release a certain algorithm.

Definition at line 135 of file AlgResourcePool.cpp.

135  {
136 
137  std::hash<std::string> hash_function;
138  size_t algo_id = hash_function( name );
139 
140  // release resources used by the algorithm
144 
145  // release algorithm itself if not reentrant
146  if ( 0 != algo->cardinality() ) { m_algqueue_map[algo_id]->push( algo ); }
147  return StatusCode::SUCCESS;
148 }
T unlock(T... args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
std::mutex m_resource_mutex
virtual unsigned int cardinality() const =0
Cardinality (Maximum number of clones that can exist) special value 0 means that algorithm is reentra...
state_type m_available_resources
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
std::map< size_t, state_type > m_resource_requirements
T lock(T... args)
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map

◆ releaseResource()

StatusCode AlgResourcePool::releaseResource ( const std::string name)
override

Release a certrain resource.

Definition at line 161 of file AlgResourcePool.cpp.

161  {
165  return StatusCode::SUCCESS;
166 }
T unlock(T... args)
std::map< std::string, unsigned int > m_resource_indices
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
std::mutex m_resource_mutex
state_type m_available_resources
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
T lock(T... args)

◆ start()

StatusCode AlgResourcePool::start ( )
override

Definition at line 63 of file AlgResourcePool.cpp.

63  {
64 
65  StatusCode startSc = Service::start();
66  if ( !startSc.isSuccess() ) return startSc;
67 
68  // sys-Start the algos
69  for ( auto& ialgo : m_algList ) {
70  startSc = ialgo->sysStart();
71  if ( startSc.isFailure() ) {
72  error() << "Unable to start Algorithm: " << ialgo->name() << endmsg;
73  return startSc;
74  }
75  }
76  return StatusCode::SUCCESS;
77 }
StatusCode start() override
Definition: Service.cpp:139
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
bool isSuccess() const
Definition: StatusCode.h:361
bool isFailure() const
Definition: StatusCode.h:141
ListAlg m_algList
The list of all algorithms created withing the Pool which are not top.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ stop()

StatusCode AlgResourcePool::stop ( )
override

Definition at line 381 of file AlgResourcePool.cpp.

381  {
382 
383  StatusCode stopSc = Service::stop();
384  if ( !stopSc.isSuccess() ) return stopSc;
385 
386  // sys-Stop the algos
387  for ( auto& ialgo : m_algList ) {
388  stopSc = ialgo->sysStop();
389  if ( stopSc.isFailure() ) {
390  error() << "Unable to stop Algorithm: " << ialgo->name() << endmsg;
391  return stopSc;
392  }
393  }
394  return StatusCode::SUCCESS;
395 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
StatusCode stop() override
Definition: Service.cpp:133
bool isSuccess() const
Definition: StatusCode.h:361
bool isFailure() const
Definition: StatusCode.h:141
ListAlg m_algList
The list of all algorithms created withing the Pool which are not top.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

Member Data Documentation

◆ m_algList

ListAlg AlgResourcePool::m_algList
private

The list of all algorithms created withing the Pool which are not top.

Definition at line 89 of file AlgResourcePool.h.

◆ m_algqueue_map

std::map<size_t, concurrentQueueIAlgPtr*> AlgResourcePool::m_algqueue_map
private

Definition at line 70 of file AlgResourcePool.h.

◆ m_available_resources

state_type AlgResourcePool::m_available_resources {0}
private

Definition at line 69 of file AlgResourcePool.h.

◆ m_flatUniqueAlgList

ListAlg AlgResourcePool::m_flatUniqueAlgList
private

The flat list of algorithms w/o clones.

Definition at line 95 of file AlgResourcePool.h.

◆ m_flatUniqueAlgPtrList

std::list<IAlgorithm*> AlgResourcePool::m_flatUniqueAlgPtrList
private

The flat list of algorithms w/o clones which is returned.

Definition at line 98 of file AlgResourcePool.h.

◆ m_lazyCreation

Gaudi::Property<bool> AlgResourcePool::m_lazyCreation {this, "CreateLazily", false, ""}
private

Definition at line 82 of file AlgResourcePool.h.

◆ m_n_of_allowed_instances

std::map<size_t, size_t> AlgResourcePool::m_n_of_allowed_instances
private

Definition at line 72 of file AlgResourcePool.h.

◆ m_n_of_created_instances

std::map<size_t, unsigned int> AlgResourcePool::m_n_of_created_instances
private

Definition at line 73 of file AlgResourcePool.h.

◆ m_overrideUnClonable

Gaudi::Property<bool> AlgResourcePool::m_overrideUnClonable
private
Initial value:
{this, "OverrideUnClonable", false,
"override the Un-Clonability of Algorithms. Use with caution!"}

Definition at line 85 of file AlgResourcePool.h.

◆ m_resource_indices

std::map<std::string, unsigned int> AlgResourcePool::m_resource_indices
private

Definition at line 74 of file AlgResourcePool.h.

◆ m_resource_mutex

std::mutex AlgResourcePool::m_resource_mutex
private

Definition at line 67 of file AlgResourcePool.h.

◆ m_resource_requirements

std::map<size_t, state_type> AlgResourcePool::m_resource_requirements
private

Definition at line 71 of file AlgResourcePool.h.

◆ m_topAlgList

ListAlg AlgResourcePool::m_topAlgList
private

The list of top algorithms.

Definition at line 92 of file AlgResourcePool.h.

◆ m_topAlgNames

Gaudi::Property<std::vector<std::string> > AlgResourcePool::m_topAlgNames
private
Initial value:
{
this, "TopAlg", {}, "names of the algorithms to be passed to the algorithm manager"}

Definition at line 83 of file AlgResourcePool.h.

◆ m_topAlgPtrList

std::list<IAlgorithm*> AlgResourcePool::m_topAlgPtrList
private

The top list of algorithms.

Definition at line 101 of file AlgResourcePool.h.


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