The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
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 (std::string_view name, IAlgorithm *&algo, bool blocking=false) override
 Acquire a certain algorithm using its name.
 
StatusCode releaseAlgorithm (std::string_view name, IAlgorithm *&algo) override
 Release a certain algorithm.
 
StatusCode acquireResource (std::string_view name) override
 Acquire a certain resource.
 
StatusCode releaseResource (std::string_view name) override
 Release a certain resource.
 
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 const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
 
- Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
 
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.
 
StatusCode sysStart () override
 Initialize Service.
 
StatusCode sysStop () override
 Initialize Service.
 
StatusCode sysFinalize () override
 Finalize Service.
 
StatusCode sysReinitialize () override
 Re-initialize the Service.
 
StatusCode sysRestart () override
 Re-initialize the Service.
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
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, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
 
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.
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
 
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.
 
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.
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
 
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)
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 

Private Types

typedef tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
 
typedef boost::dynamic_bitset state_type
 

Private Member Functions

StatusCode decodeTopAlgs ()
 Decode the top Algorithm list.
 
StatusCode flattenSequencer (IAlgorithm *sequencer, std::list< IAlgorithm * > &alglist, unsigned int recursionDepth=0)
 Recursively flatten an algList.
 
void dumpInstanceMisses () const
 Dump recorded Algorithm instance misses.
 

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.
 
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
 
std::list< IAlgorithm * > m_algList
 The list of all algorithms created within the Pool which are not top.
 
std::list< IAlgorithm * > m_topAlgList
 The list of top algorithms.
 
std::list< IAlgorithm * > m_flatUniqueAlgList
 The flat list of algorithms w/o clones.
 

Additional Inherited Members

- Public Types inherited from extends< Service, IAlgResourcePool >
using base_class
 Typedef to this class.
 
using extend_interfaces_base
 Typedef to the base of this class.
 
- 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
 Typedef used to refer to this class from derived classes, as in.
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
 
- Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 
int outputLevel () const
 get the Service's output level
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches.
 
MSG::Level resetMessaging ()
 Reinitialize internal states.
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
 
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
 
Gaudi::Property< bool > m_checkToolDeps
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service.
 

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

Member Typedef Documentation

◆ concurrentQueueIAlgPtr

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

Definition at line 62 of file AlgResourcePool.h.

◆ state_type

typedef boost::dynamic_bitset AlgResourcePool::state_type
private

Definition at line 63 of file AlgResourcePool.h.

Constructor & Destructor Documentation

◆ ~AlgResourcePool()

AlgResourcePool::~AlgResourcePool ( )
override

Definition at line 27 of file AlgResourcePool.cpp.

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

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

78 {
79
80 std::hash<std::string_view> hash_function;
81 size_t algo_id = hash_function( name );
82 auto itQueueIAlgPtr = m_algqueue_map.find( algo_id );
83
84 if ( itQueueIAlgPtr == m_algqueue_map.end() ) {
85 error() << "Algorithm " << name << " requested, but not recognised" << endmsg;
86 algo = nullptr;
88 }
89
90 StatusCode sc;
91 if ( blocking ) {
92 itQueueIAlgPtr->second->pop( algo );
93 } else {
94 if ( !itQueueIAlgPtr->second->try_pop( algo ) ) {
96 auto result = m_algInstanceMisses.find( name );
97 if ( result != m_algInstanceMisses.end() )
98 ++( result->second );
99 else
101 }
103 }
104 }
105
106 // Note that reentrant algorithms are not consumed so we put them
107 // back immediately in the queue at the end of this function.
108 // Now we may still be called again in between and get this
109 // error. In such a case, the Scheduler will retry later.
110 // This is of course not optimal, but should only happen very
111 // seldom and thud won't affect the global efficiency
112 if ( sc.isFailure() )
113 DEBUG_MSG << "No instance of algorithm " << name << " could be retrieved in non-blocking mode" << endmsg;
114
115 // if (m_lazyCreation ) {
116 // TODO: fill the lazyCreation part
117 // }
118 if ( sc.isSuccess() ) {
119 state_type requirements = m_resource_requirements[algo_id];
120 m_resource_mutex.lock();
121 if ( requirements.is_subset_of( m_available_resources ) ) {
122 m_available_resources ^= requirements;
123 } else {
125 error() << "Failure to allocate resources of algorithm " << name << endmsg;
126 // in case of not reentrant, push it back. Reentrant ones are pushed back
127 // in all cases further down
128 if ( !algo->isReEntrant() ) { itQueueIAlgPtr->second->push( algo ); }
129 }
130 m_resource_mutex.unlock();
131 if ( algo->isReEntrant() ) {
132 // push back reentrant algorithms immediately as it can be reused
133 itQueueIAlgPtr->second->push( algo );
134 }
135 }
136 return sc;
137}
#define DEBUG_MSG
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
boost::dynamic_bitset state_type
std::mutex m_resource_mutex
Gaudi::Property< bool > m_countAlgInstMisses
state_type m_available_resources
std::unordered_map< std::string_view, unsigned int > m_algInstanceMisses
Counters for Algorithm instance misses.
std::map< size_t, state_type > m_resource_requirements
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
virtual bool isReEntrant() const =0
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
bool isFailure() const
Definition StatusCode.h:129
bool isSuccess() const
Definition StatusCode.h:314
constexpr static const auto FAILURE
Definition StatusCode.h:100

◆ acquireResource()

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

Acquire a certain resource.

Definition at line 158 of file AlgResourcePool.cpp.

158 {
159 m_resource_mutex.lock();
161 m_resource_mutex.unlock();
162 return StatusCode::SUCCESS;
163}
std::map< std::string_view, unsigned int > m_resource_indices
constexpr static const auto SUCCESS
Definition StatusCode.h:99

◆ decodeTopAlgs()

StatusCode AlgResourcePool::decodeTopAlgs ( )
private

Decode the top Algorithm list.

Definition at line 210 of file AlgResourcePool.cpp.

210 {
211
212 SmartIF<IAlgManager> algMan( serviceLocator() );
213 if ( !algMan.isValid() ) {
214 error() << "Algorithm manager could not be properly fetched." << endmsg;
215 return StatusCode::FAILURE;
216 }
217
218 StatusCode sc = StatusCode::SUCCESS;
219
220 // Fill the top algorithm list ----
221 for ( const std::string& typeName : m_topAlgNames ) {
222 IAlgorithm* algo = algMan->algorithm( typeName, /*createIf*/ true ).get();
223 sc = algo->sysInitialize();
224 if ( sc.isFailure() ) {
225 error() << "Unable to initialize Algorithm: " << algo->name() << endmsg;
226 return sc;
227 }
228 m_topAlgList.push_back( algo );
229 }
230 // Top algorithm list filled ----
231
232 // Now we unroll it ----
233 for ( IAlgorithm* ialgo : m_topAlgList ) { sc = flattenSequencer( ialgo, m_flatUniqueAlgList ); }
234 // stupid O(N^2) unique-ification..
235 for ( auto i = begin( m_flatUniqueAlgList ); i != end( m_flatUniqueAlgList ); ++i ) {
236 auto n = next( i );
237 while ( n != end( m_flatUniqueAlgList ) ) {
238 if ( *n == *i )
239 n = m_flatUniqueAlgList.erase( n );
240 else
241 ++n;
242 }
243 }
244 ON_DEBUG {
245 debug() << "List of algorithms is: " << endmsg;
246 for ( IAlgorithm* algo : m_flatUniqueAlgList )
247 debug() << " o " << algo->type() << "/" << algo->name() << " @ " << algo << endmsg;
248 }
249
250 // Unrolled ---
251
252 // Now let's manage the clones
253 unsigned int resource_counter( 0 );
254 std::hash<std::string> hash_function;
255 for ( IAlgorithm* ialgo : m_flatUniqueAlgList ) {
256
257 const std::string& item_name = ialgo->name();
258 const std::string& item_type = ialgo->type();
259 size_t algo_id = hash_function( item_name );
261 m_algqueue_map[algo_id] = queue;
262
263 if ( msgLevel( MSG::VERBOSE ) ) {
264 verbose() << "Treating resource management and clones of " << item_name << endmsg;
265 }
266
267 queue->push( ialgo );
268 m_algList.push_back( ialgo );
269 if ( ialgo->isReEntrant() ) {
270 if ( ialgo->cardinality() != 0 ) {
271 info() << "Algorithm " << ialgo->name() << " is ReEntrant, but Cardinality was set to " << ialgo->cardinality()
272 << ". Only creating 1 instance" << endmsg;
273 }
274 m_n_of_allowed_instances[algo_id] = 1;
275 } else if ( ialgo->isClonable() ) {
276 m_n_of_allowed_instances[algo_id] = ialgo->cardinality();
277 } else {
278 if ( ialgo->cardinality() == 1 ) {
279 m_n_of_allowed_instances[algo_id] = 1;
280 } else {
281 if ( !m_overrideUnClonable ) {
282 info() << "Algorithm " << ialgo->name() << " is un-Clonable but Cardinality was set to "
283 << ialgo->cardinality() << ". Only creating 1 instance" << endmsg;
284 m_n_of_allowed_instances[algo_id] = 1;
285 } else {
286 warning() << "Overriding UnClonability of Algorithm " << ialgo->name() << ". Setting Cardinality to "
287 << ialgo->cardinality() << endmsg;
288 m_n_of_allowed_instances[algo_id] = ialgo->cardinality();
289 }
290 }
291 }
292 m_n_of_created_instances[algo_id] = 1;
293
294 state_type requirements( 0 );
295
296 for ( auto& resource_name : ialgo->neededResources() ) {
297 auto ret = m_resource_indices.emplace( resource_name, resource_counter );
298 // insert successful means == wasn't known before. So increment counter
299 if ( ret.second ) ++resource_counter;
300 // Resize for every algorithm according to the found resources
301 requirements.resize( resource_counter );
302 // in any case the return value holds the proper product index
303 requirements[ret.first->second] = true;
304 }
305
306 m_resource_requirements[algo_id] = requirements;
307
308 // potentially create clones; if not lazy creation we have to do it now
309 if ( !m_lazyCreation ) {
310 for ( unsigned int i = 1, end = m_n_of_allowed_instances[algo_id]; i < end; ++i ) {
311 DEBUG_MSG << "type/name to create clone of: " << item_type << "/" << item_name << endmsg;
312 IAlgorithm* ialgoClone( nullptr );
313
314 StatusCode createAlgSc =
315 algMan->createAlgorithm( item_type, item_name, ialgoClone, /*managed*/ true, /*checkIfExists*/ false );
316
317 ialgoClone->setIndex( i );
318 queue->push( ialgoClone );
319 m_n_of_created_instances[algo_id] += 1;
320 }
321 }
322 }
323
324 // Now resize all the requirement bitsets to the same size
325 for ( auto& kv : m_resource_requirements ) { kv.second.resize( resource_counter ); }
326
327 // Set all resources to be available
328 m_available_resources.resize( resource_counter );
330
331 return sc;
332}
#define ON_DEBUG
std::map< size_t, size_t > m_n_of_allowed_instances
Gaudi::Property< bool > m_lazyCreation
std::list< IAlgorithm * > m_algList
The list of all algorithms created within the Pool which are not top.
Gaudi::Property< std::vector< std::string > > m_topAlgNames
std::list< IAlgorithm * > m_flatUniqueAlgList
The flat list of algorithms w/o clones.
tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
std::list< IAlgorithm * > m_topAlgList
The list of top algorithms.
std::map< size_t, unsigned int > m_n_of_created_instances
Gaudi::Property< bool > m_overrideUnClonable
StatusCode flattenSequencer(IAlgorithm *sequencer, std::list< IAlgorithm * > &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
virtual const std::string & type() const =0
The type of the algorithm.
virtual StatusCode sysInitialize()=0
Initialization method invoked by the framework.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition Service.cpp:336
AttribStringParser::Iterator begin(const AttribStringParser &parser)
@ VERBOSE
Definition IMessageSvc.h:22

◆ dumpInstanceMisses()

void AlgResourcePool::dumpInstanceMisses ( ) const
private

Dump recorded Algorithm instance misses.

Definition at line 343 of file AlgResourcePool.cpp.

343 {
344
345 std::multimap<unsigned int, std::string_view, std::greater<unsigned int>> sortedAlgInstanceMisses;
346
347 for ( auto& p : m_algInstanceMisses ) sortedAlgInstanceMisses.insert( { p.second, p.first } );
348
349 // determine optimal indentation
350 int indnt = std::to_string( sortedAlgInstanceMisses.cbegin()->first ).length();
351
352 std::ostringstream out;
353
354 out << "Hit parade of algorithm instance misses:\n"
355 << std::right << std::setfill( ' ' )
356 << " ===============================================================================\n"
357 << std::setw( indnt + 7 ) << "Misses "
358 << "| Algorithm (# of clones) \n"
359 << " ===============================================================================\n";
360
361 std::hash<std::string_view> hash_function;
362
363 out << std::right << std::setfill( ' ' );
364 for ( const auto& p : sortedAlgInstanceMisses ) {
365 out << std::setw( indnt + 7 ) << std::to_string( p.first ) + " "
366 << " " << p.second << " (" << m_n_of_allowed_instances.at( hash_function( p.second ) ) << ")\n";
367 }
368
369 info() << out.str() << endmsg;
370}

◆ finalize()

StatusCode AlgResourcePool::finalize ( )
override

Definition at line 392 of file AlgResourcePool.cpp.

392 {
393 m_topAlgList.clear();
394 m_algList.clear();
395 m_flatUniqueAlgList.clear();
396 return extends::finalize();
397}

◆ flattenSequencer()

StatusCode AlgResourcePool::flattenSequencer ( IAlgorithm * sequencer,
std::list< IAlgorithm * > & alglist,
unsigned int recursionDepth = 0 )
private

Recursively flatten an algList.

Definition at line 176 of file AlgResourcePool.cpp.

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

◆ getFlatAlgList()

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

Definition at line 336 of file AlgResourcePool.cpp.

336{ return m_flatUniqueAlgList; }

◆ getTopAlgList()

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

Definition at line 340 of file AlgResourcePool.cpp.

340{ return m_topAlgList; }

◆ initialize()

StatusCode AlgResourcePool::initialize ( )
override

Definition at line 37 of file AlgResourcePool.cpp.

37 {
38
39 StatusCode sc( Service::initialize() );
40 if ( !sc.isSuccess() ) warning() << "Base class could not be started" << endmsg;
41
42 // Try to recover the topAlgList from the ApplicationManager for backward-compatibility
43 if ( m_topAlgNames.value().empty() ) {
44 info() << "TopAlg list empty. Recovering the one of Application Manager" << endmsg;
45 const Gaudi::Utils::TypeNameString appMgrName( "ApplicationMgr/ApplicationMgr" );
46 SmartIF<IProperty> appMgrProps( serviceLocator()->service( appMgrName ) );
47 m_topAlgNames.assign( appMgrProps->getProperty( "TopAlg" ) );
48 }
49
50 sc = decodeTopAlgs();
51 if ( sc.isFailure() ) warning() << "Algorithms could not be properly decoded." << endmsg;
52
53 // let's assume all resources are there
56}
StatusCode decodeTopAlgs()
Decode the top Algorithm list.
SmartIF< IFace > service(const std::string &name, bool createIf=true) const
Definition Service.h:79
StatusCode initialize() override
Definition Service.cpp:118

◆ releaseAlgorithm()

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

Release a certain algorithm.

Definition at line 141 of file AlgResourcePool.cpp.

141 {
142
143 std::hash<std::string_view> hash_function;
144 size_t algo_id = hash_function( name );
145
146 // release resources used by the algorithm
147 m_resource_mutex.lock();
149 m_resource_mutex.unlock();
150
151 // release algorithm itself if not reentrant
152 if ( !algo->isReEntrant() ) { m_algqueue_map[algo_id]->push( algo ); }
153 return StatusCode::SUCCESS;
154}

◆ releaseResource()

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

Release a certain resource.

Definition at line 167 of file AlgResourcePool.cpp.

167 {
168 m_resource_mutex.lock();
170 m_resource_mutex.unlock();
171 return StatusCode::SUCCESS;
172}

◆ start()

StatusCode AlgResourcePool::start ( )
override

Definition at line 60 of file AlgResourcePool.cpp.

60 {
61
62 StatusCode startSc = Service::start();
63 if ( !startSc.isSuccess() ) return startSc;
64
65 // sys-Start the algorithms
66 for ( IAlgorithm* ialgo : m_algList ) {
67 startSc = ialgo->sysStart();
68 if ( startSc.isFailure() ) {
69 error() << "Unable to start Algorithm: " << ialgo->name() << endmsg;
70 return startSc;
71 }
72 }
74}
StatusCode start() override
Definition Service.cpp:187

◆ stop()

StatusCode AlgResourcePool::stop ( )
override

Definition at line 374 of file AlgResourcePool.cpp.

374 {
375
376 StatusCode stopSc = Service::stop();
377 if ( !stopSc.isSuccess() ) return stopSc;
378
379 // sys-Stop the algorithm
380 for ( IAlgorithm* ialgo : m_algList ) {
381 stopSc = ialgo->sysStop();
382 if ( stopSc.isFailure() ) {
383 error() << "Unable to stop Algorithm: " << ialgo->name() << endmsg;
384 return stopSc;
385 }
386 }
388
389 return StatusCode::SUCCESS;
390}
void dumpInstanceMisses() const
Dump recorded Algorithm instance misses.
StatusCode stop() override
Definition Service.cpp:181

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

◆ m_algList

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

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

Definition at line 96 of file AlgResourcePool.h.

◆ m_algqueue_map

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

Definition at line 68 of file AlgResourcePool.h.

◆ m_available_resources

state_type AlgResourcePool::m_available_resources { 0 }
private

Definition at line 67 of file AlgResourcePool.h.

67{ 0 };

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

91 {
92 this, "CountAlgorithmInstanceMisses", false,
93 "Count and print out algorithm instance misses. Useful for finding ways to improve throughput scalability." };

◆ m_flatUniqueAlgList

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

The flat list of algorithms w/o clones.

Definition at line 102 of file AlgResourcePool.h.

◆ m_lazyCreation

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

Definition at line 86 of file AlgResourcePool.h.

86{ this, "CreateLazily", false, "" };

◆ m_n_of_allowed_instances

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

Definition at line 70 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 71 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 89 of file AlgResourcePool.h.

89 { this, "OverrideUnClonable", false,
90 "Override the un-clonability of algorithms. Use with caution!" };

◆ m_resource_indices

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

Definition at line 72 of file AlgResourcePool.h.

◆ m_resource_mutex

std::mutex AlgResourcePool::m_resource_mutex
private

Definition at line 65 of file AlgResourcePool.h.

◆ m_resource_requirements

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

Definition at line 69 of file AlgResourcePool.h.

◆ m_topAlgList

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

The list of top algorithms.

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

87 {
88 this, "TopAlg", {}, "Names of the algorithms to be passed to the algorithm manager" };

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