The Gaudi Framework  v36r1 (3e2fb5a8)
AlgResourcePool Class Reference

#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 (std::string_view name, IAlgorithm *&algo, bool blocking=false) override
 Acquire a certain algorithm using its name. More...
 
StatusCode releaseAlgorithm (std::string_view name, IAlgorithm *&algo) override
 Release a certain algorithm. More...
 
StatusCode acquireResource (std::string_view name) override
 Acquire a certain resource. More...
 
StatusCode releaseResource (std::string_view name) override
 Release a certain resource. More...
 
std::list< IAlgorithm * > getFlatAlgList () override
 
std::list< IAlgorithm * > getTopAlgList () override
 
StatusCode stop () override
 
StatusCode finalize () 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 ()
 
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 >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, std::string toolTypeAndName, bool createIf=true)
 Declare used tool. More...
 
template<class T >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
template<class T >
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
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 std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property. More...
 
virtual StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p)=0
 Set the property from a property with a different name. More...
 
virtual StatusCode setProperty (const std::string &s)=0
 Set the property by string. More...
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals. More...
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string. More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name More...
 
StatusCode getProperty (std::string_view 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 (std::string_view name) const override
 Return true if we have a property with the given name. More...
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected More...
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 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...
 

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 Algorithm list. More...
 
StatusCode flattenSequencer (Gaudi::Algorithm *sequencer, ListAlg &alglist, unsigned int recursionDepth=0)
 Recursively flatten an algList. More...
 
void dumpInstanceMisses () const
 Dump recorded Algorithm instance misses. 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_view, unsigned int > m_resource_indices
 
std::unordered_map< std::string_view, unsigned int > m_algInstanceMisses
 Counters for Algorithm instance misses. More...
 
Gaudi::Property< bool > m_lazyCreation {this, "CreateLazily", false, ""}
 
Gaudi::Property< std::vector< std::string > > m_topAlgNames
 
Gaudi::Property< bool > m_overrideUnClonable
 
Gaudi::Property< bool > m_countAlgInstMisses
 
ListAlg m_algList
 The list of all algorithms created within 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
std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 Standard Destructor
More...
 
int outputLevel () const
 get the Service's output level More...
 
- 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"}
 flag indicating whether ToolHandle tools have been added to m_tools More...
 
Gaudi::Property< bool > m_auditInit {this, "AuditServices", false, "[[deprecated]] 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()"}
 
Gaudi::Property< bool > m_autoRetrieveTools {this, "AutoRetrieveTools", true, "retrieve all AlgTools during initialize"}
 
Gaudi::Property< bool > m_checkToolDeps
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service
More...
 

Detailed Description

The AlgResourcePool is a concrete implementation of the IAlgResourcePool interface. It either creates all instances up front or lazily. Internal bookkeeping is done via hashes of the algorithm names.

Author
Benedikt Hegner

Definition at line 42 of file AlgResourcePool.h.

Member Typedef Documentation

◆ concurrentQueueIAlgPtr

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

Definition at line 67 of file AlgResourcePool.h.

◆ ListAlg

Definition at line 68 of file AlgResourcePool.h.

◆ state_type

typedef boost::dynamic_bitset AlgResourcePool::state_type
private

Definition at line 69 of file AlgResourcePool.h.

Constructor & Destructor Documentation

◆ ~AlgResourcePool()

AlgResourcePool::~AlgResourcePool ( )
override

Definition at line 31 of file AlgResourcePool.cpp.

31  {
32  for ( auto& algoId_algoQueue : m_algqueue_map ) {
33  auto* queue = algoId_algoQueue.second;
34  delete queue;
35  }
36 }

Member Function Documentation

◆ acquireAlgorithm()

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

Acquire a certain algorithm using its name.

Definition at line 82 of file AlgResourcePool.cpp.

82  {
83 
84  std::hash<std::string_view> hash_function;
85  size_t algo_id = hash_function( name );
86  auto itQueueIAlgPtr = m_algqueue_map.find( algo_id );
87 
88  if ( itQueueIAlgPtr == m_algqueue_map.end() ) {
89  error() << "Algorithm " << name << " requested, but not recognised" << endmsg;
90  algo = nullptr;
91  return StatusCode::FAILURE;
92  }
93 
94  StatusCode sc;
95  if ( blocking ) {
96  itQueueIAlgPtr->second->pop( algo );
97  } else {
98  if ( !itQueueIAlgPtr->second->try_pop( algo ) ) {
99  if ( m_countAlgInstMisses ) {
100  auto result = m_algInstanceMisses.find( name );
101  if ( result != m_algInstanceMisses.end() )
102  ++( result->second );
103  else
105  }
106  sc = StatusCode::FAILURE;
107  }
108  }
109 
110  // Note that reentrant algorithms are not consumed so we put them
111  // back immediately in the queue at the end of this function.
112  // Now we may still be called again in between and get this
113  // error. In such a case, the Scheduler will retry later.
114  // This is of course not optimal, but should only happen very
115  // seldom and thud won't affect the global efficiency
116  if ( sc.isFailure() )
117  DEBUG_MSG << "No instance of algorithm " << name << " could be retrieved in non-blocking mode" << endmsg;
118 
119  // if (m_lazyCreation ) {
120  // TODO: fill the lazyCreation part
121  // }
122  if ( sc.isSuccess() ) {
123  state_type requirements = m_resource_requirements[algo_id];
125  if ( requirements.is_subset_of( m_available_resources ) ) {
126  m_available_resources ^= requirements;
127  } else {
128  sc = StatusCode::FAILURE;
129  error() << "Failure to allocate resources of algorithm " << name << endmsg;
130  // in case of not reentrant, push it back. Reentrant ones are pushed back
131  // in all cases further down
132  if ( 0 != algo->cardinality() ) { itQueueIAlgPtr->second->push( algo ); }
133  }
135  if ( 0 == algo->cardinality() ) {
136  // push back reentrant algorithms immediately as it can be reused
137  itQueueIAlgPtr->second->push( algo );
138  }
139  }
140  return sc;
141 }

◆ acquireResource()

StatusCode AlgResourcePool::acquireResource ( std::string_view  name)
override

Acquire a certain resource.

Definition at line 162 of file AlgResourcePool.cpp.

162  {
166  return StatusCode::SUCCESS;
167 }

◆ decodeTopAlgs()

StatusCode AlgResourcePool::decodeTopAlgs ( )
private

Decode the top Algorithm list.

Definition at line 213 of file AlgResourcePool.cpp.

213  {
214 
216  if ( !algMan.isValid() ) {
217  error() << "Algorithm manager could not be properly fetched." << endmsg;
218  return StatusCode::FAILURE;
219  }
220 
221  // Useful lambda not to repeat ourselves --------------------------
222  auto createAlg = [&algMan, this]( const std::string& item_type, const std::string& item_name, IAlgorithm*& algo ) {
223  StatusCode createAlgSc = algMan->createAlgorithm( item_type, item_name, algo, true, false );
224  if ( createAlgSc.isFailure() )
225  this->warning() << "Algorithm " << item_type << "/" << item_name << " could not be created." << endmsg;
226  };
227  // End of lambda --------------------------------------------------
228 
230 
231  // Fill the top algorithm list ----
232  const std::vector<std::string>& topAlgNames = m_topAlgNames.value();
233  for ( auto& name : topAlgNames ) {
234  IAlgorithm* algo( nullptr );
235 
237  const std::string& item_name = item.name();
238  const std::string& item_type = item.type();
239  SmartIF<IAlgorithm> algoSmartIF( algMan->algorithm( item_name, false ) );
240 
241  if ( !algoSmartIF.isValid() ) {
242  createAlg( item_type, item_name, algo );
243  algoSmartIF = algo;
244  }
245 
246  algoSmartIF->sysInitialize().ignore();
247  m_topAlgList.push_back( algoSmartIF );
248  }
249  // Top algorithm list filled ----
250 
251  // Now we unroll it ----
252  for ( auto& algoSmartIF : m_topAlgList ) {
253  Gaudi::Algorithm* algorithm = dynamic_cast<Gaudi::Algorithm*>( algoSmartIF.get() );
254  if ( !algorithm ) {
255  fatal() << "Conversion from IAlgorithm to Gaudi::Algorithm failed" << endmsg;
256  return StatusCode::FAILURE;
257  }
258  sc = flattenSequencer( algorithm, m_flatUniqueAlgList );
259  }
260  // stupid O(N^2) unique-ification..
261  for ( auto i = begin( m_flatUniqueAlgList ); i != end( m_flatUniqueAlgList ); ++i ) {
262  auto n = next( i );
263  while ( n != end( m_flatUniqueAlgList ) ) {
264  if ( *n == *i )
266  else
267  ++n;
268  }
269  }
270  if ( msgLevel( MSG::DEBUG ) ) {
271  debug() << "List of algorithms is: " << endmsg;
272  for ( auto& algo : m_flatUniqueAlgList )
273  debug() << " o " << algo->type() << "/" << algo->name() << " @ " << algo << endmsg;
274  }
275 
276  // Unrolled ---
277 
278  // Now let's manage the clones
279  unsigned int resource_counter( 0 );
280  std::hash<std::string> hash_function;
281  for ( auto& ialgoSmartIF : m_flatUniqueAlgList ) {
282 
283  const std::string& item_name = ialgoSmartIF->name();
284 
285  verbose() << "Treating resource management and clones of " << item_name << endmsg;
286 
287  Gaudi::Algorithm* algo = dynamic_cast<Gaudi::Algorithm*>( ialgoSmartIF.get() );
288  if ( !algo ) {
289  fatal() << "Conversion from IAlgorithm to Gaudi::Algorithm failed" << endmsg;
290  return StatusCode::FAILURE;
291  }
292  const std::string& item_type = algo->type();
293 
294  size_t algo_id = hash_function( item_name );
296  m_algqueue_map[algo_id] = queue;
297 
298  // DP TODO Do it properly with SmartIFs, also in the queues
299  IAlgorithm* ialgo( ialgoSmartIF.get() );
300 
301  queue->push( ialgo );
302  m_algList.push_back( ialgo );
303  if ( ialgo->isReEntrant() ) {
304  if ( ialgo->cardinality() != 0 ) {
305  info() << "Algorithm " << ialgo->name() << " is ReEntrant, but Cardinality was set to " << ialgo->cardinality()
306  << endmsg;
307  m_n_of_allowed_instances[algo_id] = ialgo->cardinality();
308  } else {
309  m_n_of_allowed_instances[algo_id] = 1;
310  }
311  } else if ( ialgo->isClonable() ) {
312  m_n_of_allowed_instances[algo_id] = ialgo->cardinality();
313  } else {
314  if ( ialgo->cardinality() == 1 ) {
315  m_n_of_allowed_instances[algo_id] = 1;
316  } else {
317  if ( !m_overrideUnClonable ) {
318  info() << "Algorithm " << ialgo->name() << " is un-Clonable but Cardinality was set to "
319  << ialgo->cardinality() << ". Only creating 1 instance" << endmsg;
320  m_n_of_allowed_instances[algo_id] = 1;
321  } else {
322  warning() << "Overriding UnClonability of Algorithm " << ialgo->name() << ". Setting Cardinality to "
323  << ialgo->cardinality() << endmsg;
324  m_n_of_allowed_instances[algo_id] = ialgo->cardinality();
325  }
326  }
327  }
328  m_n_of_created_instances[algo_id] = 1;
329 
330  state_type requirements( 0 );
331 
332  for ( auto& resource_name : ialgo->neededResources() ) {
333  auto ret = m_resource_indices.emplace( resource_name, resource_counter );
334  // insert successful means == wasn't known before. So increment counter
335  if ( ret.second ) ++resource_counter;
336  // Resize for every algorithm according to the found resources
337  requirements.resize( resource_counter );
338  // in any case the return value holds the proper product index
339  requirements[ret.first->second] = true;
340  }
341 
342  m_resource_requirements[algo_id] = requirements;
343 
344  // potentially create clones; if not lazy creation we have to do it now
345  if ( !m_lazyCreation ) {
346  for ( unsigned int i = 1, end = m_n_of_allowed_instances[algo_id]; i < end; ++i ) {
347  debug() << "type/name to create clone of: " << item_type << "/" << item_name << endmsg;
348  IAlgorithm* ialgoClone( nullptr );
349  createAlg( item_type, item_name, ialgoClone );
350  ialgoClone->setIndex( i );
351  if ( ialgoClone->sysInitialize().isFailure() ) {
352  error() << "unable to initialize Algorithm clone " << ialgoClone->name() << endmsg;
353  sc = StatusCode::FAILURE;
354  // FIXME: should we delete this failed clone?
355  } else {
356  queue->push( ialgoClone );
357  m_n_of_created_instances[algo_id] += 1;
358  }
359  }
360  }
361  }
362 
363  // Now resize all the requirement bitsets to the same size
364  for ( auto& kv : m_resource_requirements ) { kv.second.resize( resource_counter ); }
365 
366  // Set all resources to be available
367  m_available_resources.resize( resource_counter );
368  m_available_resources.set();
369 
370  return sc;
371 }

◆ dumpInstanceMisses()

void AlgResourcePool::dumpInstanceMisses ( ) const
private

Dump recorded Algorithm instance misses.

Definition at line 390 of file AlgResourcePool.cpp.

390  {
391 
393 
394  for ( auto& p : m_algInstanceMisses ) sortedAlgInstanceMisses.insert( {p.second, p.first} );
395 
396  // determine optimal indentation
397  int indnt = std::to_string( sortedAlgInstanceMisses.cbegin()->first ).length();
398 
400 
401  out << "Hit parade of algorithm instance misses:\n"
402  << std::right << std::setfill( ' ' )
403  << " ===============================================================================\n"
404  << std::setw( indnt + 7 ) << "Misses "
405  << "| Algorithm (# of clones) \n"
406  << " ===============================================================================\n";
407 
408  std::hash<std::string_view> hash_function;
409 
410  out << std::right << std::setfill( ' ' );
411  for ( const auto& p : sortedAlgInstanceMisses ) {
412  out << std::setw( indnt + 7 ) << std::to_string( p.first ) + " "
413  << " " << p.second << " (" << m_n_of_allowed_instances.at( hash_function( p.second ) ) << ")\n";
414  }
415 
416  info() << out.str() << endmsg;
417 }

◆ finalize()

StatusCode AlgResourcePool::finalize ( )
override

Definition at line 439 of file AlgResourcePool.cpp.

439  {
440  // we do not need to hold the ref counts of the algorithms anymore
441  // (this triggers algorithms destructors)
443  m_algList.clear();
445  return extends::finalize();
446 }

◆ flattenSequencer()

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

Recursively flatten an algList.

Definition at line 180 of file AlgResourcePool.cpp.

180  {
181 
183 
184  if ( algo->isSequence() ) {
185  auto seq = dynamic_cast<Gaudi::Sequence*>( algo );
186  if ( seq == 0 ) {
187  error() << "Unable to dcast Algorithm " << algo->name() << " to a Sequence, but it has isSequence==true"
188  << endmsg;
189  return StatusCode::FAILURE;
190  }
191 
192  auto subAlgorithms = seq->subAlgorithms();
193 
194  // Recursively unroll
195  ++recursionDepth;
196 
197  for ( auto subalgo : *subAlgorithms ) {
198  sc = flattenSequencer( subalgo, alglist, recursionDepth );
199  if ( sc.isFailure() ) {
200  error() << "Algorithm " << subalgo->name() << " could not be flattened" << endmsg;
201  return sc;
202  }
203  }
204  } else {
205  alglist.emplace_back( algo );
206  return sc;
207  }
208  return sc;
209 }

◆ getFlatAlgList()

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

Definition at line 375 of file AlgResourcePool.cpp.

375  {
377  for ( auto algoSmartIF : m_flatUniqueAlgList ) m_flatUniqueAlgPtrList.push_back( algoSmartIF.get() );
378  return m_flatUniqueAlgPtrList;
379 }

◆ getTopAlgList()

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

Definition at line 383 of file AlgResourcePool.cpp.

383  {
385  for ( auto algoSmartIF : m_topAlgList ) m_topAlgPtrList.push_back( algoSmartIF.get() );
386  return m_topAlgPtrList;
387 }

◆ initialize()

StatusCode AlgResourcePool::initialize ( )
override

Definition at line 41 of file AlgResourcePool.cpp.

41  {
42 
44  if ( !sc.isSuccess() ) warning() << "Base class could not be started" << endmsg;
45 
46  // Try to recover the topAlgList from the ApplicationManager for backward-compatibility
47  if ( m_topAlgNames.value().empty() ) {
48  info() << "TopAlg list empty. Recovering the one of Application Manager" << endmsg;
49  const Gaudi::Utils::TypeNameString appMgrName( "ApplicationMgr/ApplicationMgr" );
50  SmartIF<IProperty> appMgrProps( serviceLocator()->service( appMgrName ) );
51  m_topAlgNames.assign( appMgrProps->getProperty( "TopAlg" ) );
52  }
53 
54  sc = decodeTopAlgs();
55  if ( sc.isFailure() ) warning() << "Algorithms could not be properly decoded." << endmsg;
56 
57  // let's assume all resources are there
59  return StatusCode::SUCCESS;
60 }

◆ releaseAlgorithm()

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

Release a certain algorithm.

Definition at line 145 of file AlgResourcePool.cpp.

145  {
146 
147  std::hash<std::string_view> hash_function;
148  size_t algo_id = hash_function( name );
149 
150  // release resources used by the algorithm
154 
155  // release algorithm itself if not reentrant
156  if ( 0 != algo->cardinality() ) { m_algqueue_map[algo_id]->push( algo ); }
157  return StatusCode::SUCCESS;
158 }

◆ releaseResource()

StatusCode AlgResourcePool::releaseResource ( std::string_view  name)
override

Release a certain resource.

Definition at line 171 of file AlgResourcePool.cpp.

171  {
175  return StatusCode::SUCCESS;
176 }

◆ start()

StatusCode AlgResourcePool::start ( )
override

Definition at line 64 of file AlgResourcePool.cpp.

64  {
65 
66  StatusCode startSc = Service::start();
67  if ( !startSc.isSuccess() ) return startSc;
68 
69  // sys-Start the algorithms
70  for ( auto& ialgo : m_algList ) {
71  startSc = ialgo->sysStart();
72  if ( startSc.isFailure() ) {
73  error() << "Unable to start Algorithm: " << ialgo->name() << endmsg;
74  return startSc;
75  }
76  }
77  return StatusCode::SUCCESS;
78 }

◆ stop()

StatusCode AlgResourcePool::stop ( )
override

Definition at line 421 of file AlgResourcePool.cpp.

421  {
422 
423  StatusCode stopSc = Service::stop();
424  if ( !stopSc.isSuccess() ) return stopSc;
425 
426  // sys-Stop the algorithm
427  for ( auto& ialgo : m_algList ) {
428  stopSc = ialgo->sysStop();
429  if ( stopSc.isFailure() ) {
430  error() << "Unable to stop Algorithm: " << ialgo->name() << endmsg;
431  return stopSc;
432  }
433  }
435 
436  return StatusCode::SUCCESS;
437 }

Member Data Documentation

◆ m_algInstanceMisses

std::unordered_map<std::string_view, unsigned int> AlgResourcePool::m_algInstanceMisses
private

Counters for Algorithm instance misses.

Definition at line 89 of file AlgResourcePool.h.

◆ m_algList

ListAlg AlgResourcePool::m_algList
private

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

Definition at line 101 of file AlgResourcePool.h.

◆ m_algqueue_map

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

Definition at line 74 of file AlgResourcePool.h.

◆ m_available_resources

state_type AlgResourcePool::m_available_resources {0}
private

Definition at line 73 of file AlgResourcePool.h.

◆ m_countAlgInstMisses

Gaudi::Property<bool> AlgResourcePool::m_countAlgInstMisses
private
Initial value:
{
this, "CountAlgorithmInstanceMisses", false,
"Count and print out algorithm instance misses. Useful for finding ways to improve throughput scalability."}

Definition at line 96 of file AlgResourcePool.h.

◆ m_flatUniqueAlgList

ListAlg AlgResourcePool::m_flatUniqueAlgList
private

The flat list of algorithms w/o clones.

Definition at line 107 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 110 of file AlgResourcePool.h.

◆ m_lazyCreation

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

Definition at line 91 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 76 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 77 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 94 of file AlgResourcePool.h.

◆ m_resource_indices

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

Definition at line 78 of file AlgResourcePool.h.

◆ m_resource_mutex

std::mutex AlgResourcePool::m_resource_mutex
private

Definition at line 71 of file AlgResourcePool.h.

◆ m_resource_requirements

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

Definition at line 75 of file AlgResourcePool.h.

◆ m_topAlgList

ListAlg AlgResourcePool::m_topAlgList
private

The list of top algorithms.

Definition at line 104 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 92 of file AlgResourcePool.h.

◆ m_topAlgPtrList

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

The top list of algorithms.

Definition at line 113 of file AlgResourcePool.h.


The documentation for this class was generated from the following files:
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
std::mutex::lock
T lock(T... args)
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:118
std::string
STL class.
AlgResourcePool::m_countAlgInstMisses
Gaudi::Property< bool > m_countAlgInstMisses
Definition: AlgResourcePool.h:96
AlgResourcePool::m_available_resources
state_type m_available_resources
Definition: AlgResourcePool.h:73
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:542
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:355
Service::start
StatusCode start() override
Definition: Service.cpp:187
Gaudi::Algorithm::type
const std::string & type() const override
The type of the algorithm object.
Definition: Algorithm.h:165
AlgResourcePool::m_algList
ListAlg m_algList
The list of all algorithms created within the Pool which are not top.
Definition: AlgResourcePool.h:101
std::vector< std::string >
std::map::find
T find(T... args)
AlgResourcePool::m_flatUniqueAlgList
ListAlg m_flatUniqueAlgList
The flat list of algorithms w/o clones.
Definition: AlgResourcePool.h:107
std::map::emplace
T emplace(T... args)
IAlgorithm::cardinality
virtual unsigned int cardinality() const =0
Cardinality (Maximum number of clones that can exist) special value 0 means that algorithm is reentra...
AlgResourcePool::state_type
boost::dynamic_bitset state_type
Definition: AlgResourcePool.h:69
std::setfill
T setfill(T... args)
Gaudi::Property::assign
bool assign(const Details::PropertyBase &source) override
get the value from another property
Definition: Property.h:373
AlgResourcePool::m_flatUniqueAlgPtrList
std::list< IAlgorithm * > m_flatUniqueAlgPtrList
The flat list of algorithms w/o clones which is returned.
Definition: AlgResourcePool.h:110
CommonMessaging< implements< IService, IProperty, IStateful > >::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:148
std::list::clear
T clear(T... args)
std::mutex::unlock
T unlock(T... args)
AlgResourcePool::m_n_of_created_instances
std::map< size_t, unsigned int > m_n_of_created_instances
Definition: AlgResourcePool.h:77
std::list::push_back
T push_back(T... args)
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:20
AlgResourcePool::m_resource_requirements
std::map< size_t, state_type > m_resource_requirements
Definition: AlgResourcePool.h:75
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:332
StatusCode
Definition: StatusCode.h:65
std::map::at
T at(T... args)
IAlgorithm
Definition: IAlgorithm.h:38
CLHEP::begin
double * begin(CLHEP::HepVector &v)
Definition: TupleAlg.cpp:45
AlgResourcePool::m_resource_indices
std::map< std::string_view, unsigned int > m_resource_indices
Definition: AlgResourcePool.h:78
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:90
Gaudi::Property::value
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:240
std::to_string
T to_string(T... args)
std::list::erase
T erase(T... args)
AlgResourcePool::dumpInstanceMisses
void dumpInstanceMisses() const
Dump recorded Algorithm instance misses.
Definition: AlgResourcePool.cpp:390
HistogramsTiming.seq
seq
Definition: HistogramsTiming.py:24
SmartIF< IAlgManager >
AlgResourcePool::decodeTopAlgs
StatusCode decodeTopAlgs()
Decode the top Algorithm list.
Definition: AlgResourcePool.cpp:213
genconfuser.verbose
verbose
Definition: genconfuser.py:29
AlgResourcePool::concurrentQueueIAlgPtr
tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
Definition: AlgResourcePool.h:67
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
AlgResourcePool::m_overrideUnClonable
Gaudi::Property< bool > m_overrideUnClonable
Definition: AlgResourcePool.h:94
AlgResourcePool::m_n_of_allowed_instances
std::map< size_t, size_t > m_n_of_allowed_instances
Definition: AlgResourcePool.h:76
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:221
std::ostringstream
STL class.
AlgResourcePool::m_algInstanceMisses
std::unordered_map< std::string_view, unsigned int > m_algInstanceMisses
Counters for Algorithm instance misses.
Definition: AlgResourcePool.h:89
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:142
AlgResourcePool::m_lazyCreation
Gaudi::Property< bool > m_lazyCreation
Definition: AlgResourcePool.h:91
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
Service::stop
StatusCode stop() override
Definition: Service.cpp:181
std::right
T right(T... args)
AlgResourcePool::m_topAlgNames
Gaudi::Property< std::vector< std::string > > m_topAlgNames
Definition: AlgResourcePool.h:92
std::multimap::cbegin
T cbegin(T... args)
AlgResourcePool::flattenSequencer
StatusCode flattenSequencer(Gaudi::Algorithm *sequencer, ListAlg &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
Definition: AlgResourcePool.cpp:180
std::multimap::insert
T insert(T... args)
AlgResourcePool::m_algqueue_map
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
Definition: AlgResourcePool.h:74
DEBUG_MSG
#define DEBUG_MSG
Definition: AlgResourcePool.cpp:26
std::multimap
STL class.
AlgResourcePool::m_resource_mutex
std::mutex m_resource_mutex
Definition: AlgResourcePool.h:71
std::map::end
T end(T... args)
IOTest.end
end
Definition: IOTest.py:123
std::setw
T setw(T... args)
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::Sequence
Definition: Sequence.h:18
AlgResourcePool::m_topAlgPtrList
std::list< IAlgorithm * > m_topAlgPtrList
The top list of algorithms.
Definition: AlgResourcePool.h:113
Service::service
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:94
AlgResourcePool::m_topAlgList
ListAlg m_topAlgList
The list of top algorithms.
Definition: AlgResourcePool.h:104
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator
Definition: Service.cpp:335
std::hash
PrepareBase.out
out
Definition: PrepareBase.py:20
std::next
T next(T... args)