The Gaudi Framework  v30r3 (a5ef0a68)
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 (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, "[[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()"}
 
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 29 of file AlgResourcePool.h.

Member Typedef Documentation

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

Definition at line 54 of file AlgResourcePool.h.

Definition at line 55 of file AlgResourcePool.h.

typedef boost::dynamic_bitset AlgResourcePool::state_type
private

Definition at line 56 of file AlgResourcePool.h.

Constructor & Destructor Documentation

AlgResourcePool::~AlgResourcePool ( )
override

Definition at line 20 of file AlgResourcePool.cpp.

21 {
22 
23  for ( auto& algoId_algoQueue : m_algqueue_map ) {
24  auto* queue = algoId_algoQueue.second;
25  delete queue;
26  }
27 }
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map

Member Function Documentation

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

Acquire a certain algorithm using its name.

Definition at line 75 of file AlgResourcePool.cpp.

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

Acquire a certain resource.

Definition at line 154 of file AlgResourcePool.cpp.

155 {
159  return StatusCode::SUCCESS;
160 }
T unlock(T...args)
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
std::map< std::string, unsigned int > m_resource_indices
std::mutex m_resource_mutex
state_type m_available_resources
T lock(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
StatusCode AlgResourcePool::decodeTopAlgs ( )
private

Decode the top alg list.

Definition at line 213 of file AlgResourcePool.cpp.

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

Recursively flatten an algList.

Definition at line 174 of file AlgResourcePool.cpp.

175 {
176 
178 
179  bool isGaudiSequencer( false );
180  bool isAthSequencer( false );
181 
182  if ( algo->isSequence() ) {
183  if ( algo->hasProperty( "ShortCircuit" ) )
184  isGaudiSequencer = true;
185  else if ( algo->hasProperty( "StopOverride" ) )
186  isAthSequencer = true;
187  }
188 
189  std::vector<Algorithm*>* subAlgorithms = algo->subAlgorithms();
190  if ( // we only want to add basic algorithms -> have no subAlgs
191  // and exclude the case of empty sequencers
192  ( subAlgorithms->empty() && !( isGaudiSequencer || isAthSequencer ) ) ) {
193 
194  alglist.emplace_back( algo );
195  return sc;
196  }
197 
198  // Recursively unroll
199  ++recursionDepth;
200 
201  for ( Algorithm* subalgo : *subAlgorithms ) {
202  sc = flattenSequencer( subalgo, alglist, recursionDepth );
203  if ( sc.isFailure() ) {
204  error() << "Algorithm " << subalgo->name() << " could not be flattened" << endmsg;
205  return sc;
206  }
207  }
208  return sc;
209 }
T empty(T...args)
StatusCode flattenSequencer(Algorithm *sequencer, ListAlg &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
bool isFailure() const
Definition: StatusCode.h:139
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:78
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
T emplace_back(T...args)
std::list< IAlgorithm * > AlgResourcePool::getFlatAlgList ( )
override

Definition at line 364 of file AlgResourcePool.cpp.

365 {
367  for ( auto algoSmartIF : m_flatUniqueAlgList )
368  m_flatUniqueAlgPtrList.push_back( const_cast<IAlgorithm*>( algoSmartIF.get() ) );
369  return m_flatUniqueAlgPtrList;
370 }
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)
std::list< IAlgorithm * > AlgResourcePool::getTopAlgList ( )
override

Definition at line 374 of file AlgResourcePool.cpp.

375 {
377  for ( auto algoSmartIF : m_topAlgList ) m_topAlgPtrList.push_back( const_cast<IAlgorithm*>( algoSmartIF.get() ) );
378  return m_topAlgPtrList;
379 }
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.
StatusCode AlgResourcePool::initialize ( )
override

Definition at line 32 of file AlgResourcePool.cpp.

33 {
34 
36  if ( !sc.isSuccess() ) warning() << "Base class could not be started" << endmsg;
37 
38  // Try to recover the topAlgList from the ApplicationManager for backward-compatibility
39  if ( m_topAlgNames.value().empty() ) {
40  info() << "TopAlg list empty. Recovering the one of Application Manager" << endmsg;
41  const Gaudi::Utils::TypeNameString appMgrName( "ApplicationMgr/ApplicationMgr" );
42  SmartIF<IProperty> appMgrProps( serviceLocator()->service( appMgrName ) );
43  m_topAlgNames.assign( appMgrProps->getProperty( "TopAlg" ) );
44  }
45 
46  sc = decodeTopAlgs();
47  if ( sc.isFailure() ) warning() << "Algorithms could not be properly decoded." << endmsg;
48 
49  // let's assume all resources are there
51  return StatusCode::SUCCESS;
52 }
StatusCode initialize() override
Definition: Service.cpp:63
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".
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
Gaudi::Property< std::vector< std::string > > m_topAlgNames
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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&#39;t already exist.
Definition: Service.h:84
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:291
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode AlgResourcePool::releaseAlgorithm ( const std::string name,
IAlgorithm *&  algo 
)
override

Release a certain algorithm.

Definition at line 134 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() ) {
147  m_algqueue_map[algo_id]->push( algo );
148  }
149  return StatusCode::SUCCESS;
150 }
T unlock(T...args)
std::mutex m_resource_mutex
state_type m_available_resources
std::map< size_t, state_type > m_resource_requirements
T lock(T...args)
virtual unsigned int cardinality() const =0
Cardinality (Maximum number of clones that can exist) special value 0 means that algorithm is reentra...
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
StatusCode AlgResourcePool::releaseResource ( const std::string name)
override

Release a certrain resource.

Definition at line 164 of file AlgResourcePool.cpp.

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

Definition at line 56 of file AlgResourcePool.cpp.

57 {
58 
59  StatusCode startSc = Service::start();
60  if ( !startSc.isSuccess() ) return startSc;
61 
62  // sys-Start the algos
63  for ( auto& ialgo : m_algList ) {
64  startSc = ialgo->sysStart();
65  if ( startSc.isFailure() ) {
66  error() << "Unable to start Algorithm: " << ialgo->name() << endmsg;
67  return startSc;
68  }
69  }
70  return StatusCode::SUCCESS;
71 }
StatusCode start() override
Definition: Service.cpp:136
bool isSuccess() const
Definition: StatusCode.h:287
bool isFailure() const
Definition: StatusCode.h:139
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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:209
StatusCode AlgResourcePool::stop ( )
override

Definition at line 383 of file AlgResourcePool.cpp.

384 {
385 
386  StatusCode stopSc = Service::stop();
387  if ( !stopSc.isSuccess() ) return stopSc;
388 
389  // sys-Stop the algos
390  for ( auto& ialgo : m_algList ) {
391  stopSc = ialgo->sysStop();
392  if ( stopSc.isFailure() ) {
393  error() << "Unable to stop Algorithm: " << ialgo->name() << endmsg;
394  return stopSc;
395  }
396  }
397  return StatusCode::SUCCESS;
398 }
bool isSuccess() const
Definition: StatusCode.h:287
bool isFailure() const
Definition: StatusCode.h:139
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
StatusCode stop() override
Definition: Service.cpp:129
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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:209

Member Data Documentation

ListAlg AlgResourcePool::m_algList
private

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

Definition at line 80 of file AlgResourcePool.h.

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

Definition at line 61 of file AlgResourcePool.h.

state_type AlgResourcePool::m_available_resources {0}
private

Definition at line 60 of file AlgResourcePool.h.

ListAlg AlgResourcePool::m_flatUniqueAlgList
private

The flat list of algorithms w/o clones.

Definition at line 86 of file AlgResourcePool.h.

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

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

Definition at line 89 of file AlgResourcePool.h.

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

Definition at line 73 of file AlgResourcePool.h.

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

Definition at line 63 of file AlgResourcePool.h.

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

Definition at line 64 of file AlgResourcePool.h.

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

Definition at line 76 of file AlgResourcePool.h.

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

Definition at line 65 of file AlgResourcePool.h.

std::mutex AlgResourcePool::m_resource_mutex
private

Definition at line 58 of file AlgResourcePool.h.

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

Definition at line 62 of file AlgResourcePool.h.

ListAlg AlgResourcePool::m_topAlgList
private

The list of top algorithms.

Definition at line 83 of file AlgResourcePool.h.

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 74 of file AlgResourcePool.h.

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

The top list of algorithms.

Definition at line 92 of file AlgResourcePool.h.


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