| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
AlgResourcePool Class Reference

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

`#include <GaudiHive/AlgResourcePool.h>`

Inheritance diagram for AlgResourcePool:
[legend]
Collaboration diagram for AlgResourcePool:
[legend]

## 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::string > | getInterfaceNames () const override
| Implementation of IInterface::getInterfaceNames. More...
Public Member Functions inherited from Service
const std::string & | name () 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::PropertyBase & | declareProperty (Gaudi::Details::PropertyBase &prop)
| Declare a property. More...
Gaudi::Details::PropertyBase * | declareProperty (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::PropertyBase * | declareProperty (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::PropertyBase * | declareRemoteProperty (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::PropertyBase & | getProperty (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
PropertyHolder & | operator= (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...
MsgStream & | msgStream () const
| Return an uninitialized MsgStream. More...
MsgStream & | msgStream (const MSG::Level level) const
| Predefined configurable message stream for the efficient printouts. More...
MsgStream & | always () const
| shortcut for the method msgStream(MSG::ALWAYS) More...
MsgStream & | fatal () const
| shortcut for the method msgStream(MSG::FATAL) More...
MsgStream & | err () const
| shortcut for the method msgStream(MSG::ERROR) More...
MsgStream & | error () const
| shortcut for the method msgStream(MSG::ERROR) More...
MsgStream & | warning () const
| shortcut for the method msgStream(MSG::WARNING) More...
MsgStream & | info () const
| shortcut for the method msgStream(MSG::INFO) More...
MsgStream & | debug () const
| shortcut for the method msgStream(MSG::DEBUG) More...
MsgStream & | verbose () const
| shortcut for the method msgStream(MSG::VERBOSE) More...
MsgStream & | msg () 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_type > | m_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::PropertyBase * | property (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< IAuditorSvc > | m_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

## ◆ concurrentQueueIAlgPtr

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

Definition at line 53 of file AlgResourcePool.h.

## ◆ ListAlg

typedef std::list<SmartIF<IAlgorithm> > AlgResourcePool::ListAlg
| private

Definition at line 54 of file AlgResourcePool.h.

## ◆ state_type

typedef boost::dynamic_bitset AlgResourcePool::state_type
| private

Definition at line 55 of file AlgResourcePool.h.

## Constructor & Destructor Documentation

## ◆ ~AlgResourcePool()

AlgResourcePool::~AlgResourcePool | ( |  | ) |
| override

Definition at line 20 of file AlgResourcePool.cpp.

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

## 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 71 of file AlgResourcePool.cpp.

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

## ◆ acquireResource()

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

Acquire a certain resource.

Definition at line 142 of file AlgResourcePool.cpp.

142 {
143 m_resource_mutex.lock();
144 m_available_resources[m_resource_indices[name]] = false;
145 m_resource_mutex.unlock();
146 return StatusCode::SUCCESS;
147 }
std::mutex::unlock
T unlock(T... args)
AlgResourcePool::m_resource_indices
std::map< std::string, unsigned int > m_resource_indices
Definition: AlgResourcePool.h:64
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
AlgResourcePool::m_resource_mutex
std::mutex m_resource_mutex
Definition: AlgResourcePool.h:57
AlgResourcePool::m_available_resources
state_type m_available_resources
Definition: AlgResourcePool.h:59
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
std::mutex::lock
T lock(T... args)

## ◆ decodeTopAlgs()

StatusCode AlgResourcePool::decodeTopAlgs | ( |  | ) |
| private

Decode the top alg list.

Definition at line 193 of file AlgResourcePool.cpp.

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

## ◆ flattenSequencer()

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

Recursively flatten an algList.

Definition at line 160 of file AlgResourcePool.cpp.

160 {
161
162 StatusCode sc = StatusCode::SUCCESS;
163
164 if ( algo->isSequence() ) {
165 auto seq = dynamic_cast<Gaudi::Sequence*>( algo );
166 if ( seq == 0 ) {
167 error() << "Unable to dcast Algorithm " << algo->name() << " to a Sequence, but it has isSequence==true"
168 << endmsg;
169 return StatusCode::FAILURE;
170 }
171
172 auto subAlgorithms = seq->subAlgorithms();
173
174 // Recursively unroll
175 ++recursionDepth;
176
177 for ( auto subalgo : *subAlgorithms ) {
178 sc = flattenSequencer( subalgo, alglist, recursionDepth );
179 if ( sc.isFailure() ) {
180 error() << "Algorithm " << subalgo->name() << " could not be flattened" << endmsg;
181 return sc;
182 }
183 }
184 } else {
185 alglist.emplace_back( algo );
186 return sc;
187 }
188 return sc;
189 }
ManySmallAlgs.seq
seq
Definition: ManySmallAlgs.py:89
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
AlgResourcePool::flattenSequencer
StatusCode flattenSequencer(Gaudi::Algorithm *sequencer, ListAlg &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
Definition: AlgResourcePool.cpp:160
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ getFlatAlgList()

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

Definition at line 355 of file AlgResourcePool.cpp.

355 {
356 m_flatUniqueAlgPtrList.clear();
357 for ( auto algoSmartIF : m_flatUniqueAlgList ) m_flatUniqueAlgPtrList.push_back( algoSmartIF.get() );
358 return m_flatUniqueAlgPtrList;
359 }
AlgResourcePool::m_flatUniqueAlgList
ListAlg m_flatUniqueAlgList
The flat list of algorithms w/o clones.
Definition: AlgResourcePool.h:85
std::list::push_back
T push_back(T... args)
AlgResourcePool::m_flatUniqueAlgPtrList
std::list< IAlgorithm * > m_flatUniqueAlgPtrList
The flat list of algorithms w/o clones which is returned.
Definition: AlgResourcePool.h:88
std::list::clear
T clear(T... args)

## ◆ getTopAlgList()

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

Definition at line 363 of file AlgResourcePool.cpp.

363 {
364 m_topAlgPtrList.clear();
365 for ( auto algoSmartIF : m_topAlgList ) m_topAlgPtrList.push_back( algoSmartIF.get() );
366 return m_topAlgPtrList;
367 }
std::list::push_back
T push_back(T... args)
AlgResourcePool::m_topAlgPtrList
std::list< IAlgorithm * > m_topAlgPtrList
The top list of algorithms.
Definition: AlgResourcePool.h:91
std::list::clear
T clear(T... args)
AlgResourcePool::m_topAlgList
ListAlg m_topAlgList
The list of top algorithms.
Definition: AlgResourcePool.h:82

## ◆ initialize()

StatusCode AlgResourcePool::initialize | ( |  | ) |
| override

Definition at line 30 of file AlgResourcePool.cpp.

30 {
31
32 StatusCode sc( Service::initialize() );
33 if ( !sc.isSuccess() ) warning() << "Base class could not be started" << endmsg;
34
35 // Try to recover the topAlgList from the ApplicationManager for backward-compatibility
36 if ( m_topAlgNames.value().empty() ) {
37 info() << "TopAlg list empty. Recovering the one of Application Manager" << endmsg;
38 const Gaudi::Utils::TypeNameString appMgrName( "ApplicationMgr/ApplicationMgr" );
39 SmartIF<IProperty> appMgrProps( serviceLocator()->service( appMgrName ) );
40 m_topAlgNames.assign( appMgrProps->getProperty( "TopAlg" ) );
41 }
42
43 sc = decodeTopAlgs();
44 if ( sc.isFailure() ) warning() << "Algorithms could not be properly decoded." << endmsg;
45
46 // let's assume all resources are there
47 m_available_resources.set();
48 return StatusCode::SUCCESS;
49 }
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:60
SmartIF< IProperty >
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:277
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:101
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:104
AlgResourcePool::m_available_resources
state_type m_available_resources
Definition: AlgResourcePool.h:59
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:10
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
AlgResourcePool::m_topAlgNames
Gaudi::Property< std::vector< std::string > > m_topAlgNames
Definition: AlgResourcePool.h:73
AlgResourcePool::decodeTopAlgs
StatusCode decodeTopAlgs()
Decode the top alg list.
Definition: AlgResourcePool.cpp:193
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:83
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ releaseAlgorithm()

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

Release a certain algorithm.

Definition at line 125 of file AlgResourcePool.cpp.

125 {
126
127 std::hash<std::string> hash_function;
128 size_t algo_id = hash_function( name );
129
130 // release resources used by the algorithm
131 m_resource_mutex.lock();
132 m_available_resources |= m_resource_requirements[algo_id];
133 m_resource_mutex.unlock();
134
135 // release algorithm itself if not reentrant
136 if ( 0 != algo->cardinality() ) { m_algqueue_map[algo_id]->push( algo ); }
137 return StatusCode::SUCCESS;
138 }
std::mutex::unlock
T unlock(T... args)
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
AlgResourcePool::m_resource_mutex
std::mutex m_resource_mutex
Definition: AlgResourcePool.h:57
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::m_available_resources
state_type m_available_resources
Definition: AlgResourcePool.h:59
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
std::hash
AlgResourcePool::m_resource_requirements
std::map< size_t, state_type > m_resource_requirements
Definition: AlgResourcePool.h:61
std::mutex::lock
T lock(T... args)
AlgResourcePool::m_algqueue_map
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
Definition: AlgResourcePool.h:60

## ◆ releaseResource()

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

Release a certrain resource.

Definition at line 151 of file AlgResourcePool.cpp.

151 {
152 m_resource_mutex.lock();
153 m_available_resources[m_resource_indices[name]] = true;
154 m_resource_mutex.unlock();
155 return StatusCode::SUCCESS;
156 }
std::mutex::unlock
T unlock(T... args)
AlgResourcePool::m_resource_indices
std::map< std::string, unsigned int > m_resource_indices
Definition: AlgResourcePool.h:64
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
AlgResourcePool::m_resource_mutex
std::mutex m_resource_mutex
Definition: AlgResourcePool.h:57
AlgResourcePool::m_available_resources
state_type m_available_resources
Definition: AlgResourcePool.h:59
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
std::mutex::lock
T lock(T... args)

## ◆ start()

StatusCode AlgResourcePool::start | ( |  | ) |
| override

Definition at line 53 of file AlgResourcePool.cpp.

53 {
54
55 StatusCode startSc = Service::start();
56 if ( !startSc.isSuccess() ) return startSc;
57
58 // sys-Start the algos
59 for ( auto& ialgo : m_algList ) {
60 startSc = ialgo->sysStart();
61 if ( startSc.isFailure() ) {
62 error() << "Unable to start Algorithm: " << ialgo->name() << endmsg;
63 return startSc;
64 }
65 }
66 return StatusCode::SUCCESS;
67 }
Service::start
StatusCode start() override
Definition: Service.cpp:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
AlgResourcePool::m_algList
ListAlg m_algList
The list of all algorithms created withing the Pool which are not top.
Definition: AlgResourcePool.h:79
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ stop()

StatusCode AlgResourcePool::stop | ( |  | ) |
| override

Definition at line 371 of file AlgResourcePool.cpp.

371 {
372
373 StatusCode stopSc = Service::stop();
374 if ( !stopSc.isSuccess() ) return stopSc;
375
376 // sys-Stop the algos
377 for ( auto& ialgo : m_algList ) {
378 stopSc = ialgo->sysStop();
379 if ( stopSc.isFailure() ) {
380 error() << "Unable to stop Algorithm: " << ialgo->name() << endmsg;
381 return stopSc;
382 }
383 }
384 return StatusCode::SUCCESS;
385 }
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Service::stop
StatusCode stop() override
Definition: Service.cpp:123
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
AlgResourcePool::m_algList
ListAlg m_algList
The list of all algorithms created withing the Pool which are not top.
Definition: AlgResourcePool.h:79
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

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

## ◆ m_algqueue_map

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

Definition at line 60 of file AlgResourcePool.h.

## ◆ m_available_resources

state_type AlgResourcePool::m_available_resources {0}
| private

Definition at line 59 of file AlgResourcePool.h.

## ◆ m_flatUniqueAlgList

ListAlg AlgResourcePool::m_flatUniqueAlgList
| private

The flat list of algorithms w/o clones.

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

## ◆ m_lazyCreation

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

Definition at line 72 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 62 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 63 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 75 of file AlgResourcePool.h.

## ◆ m_resource_indices

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

Definition at line 64 of file AlgResourcePool.h.

## ◆ m_resource_mutex

std::mutex AlgResourcePool::m_resource_mutex
| private

Definition at line 57 of file AlgResourcePool.h.

## ◆ m_resource_requirements

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

Definition at line 61 of file AlgResourcePool.h.

## ◆ m_topAlgList

ListAlg AlgResourcePool::m_topAlgList
| private

The list of top algorithms.

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

## ◆ m_topAlgPtrList

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

The top list of algorithms.

Definition at line 91 of file AlgResourcePool.h.

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

- GaudiHive/src/AlgResourcePool.h
- GaudiHive/src/AlgResourcePool.cpp