21#define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
22#define DEBUG_MSG ON_DEBUG debug()
29 auto* queue = algoId_algoQueue.second;
44 info() <<
"TopAlg list empty. Recovering the one of Application Manager" <<
endmsg;
63 if ( !startSc.
isSuccess() )
return startSc;
67 startSc = ialgo->sysStart();
69 error() <<
"Unable to start Algorithm: " << ialgo->name() <<
endmsg;
80 std::hash<std::string_view> hash_function;
81 size_t algo_id = hash_function(
name );
85 error() <<
"Algorithm " <<
name <<
" requested, but not recognised" <<
endmsg;
92 itQueueIAlgPtr->second->pop( algo );
94 if ( !itQueueIAlgPtr->second->try_pop( algo ) ) {
113 DEBUG_MSG <<
"No instance of algorithm " <<
name <<
" could be retrieved in non-blocking mode" <<
endmsg;
125 error() <<
"Failure to allocate resources of algorithm " <<
name <<
endmsg;
128 if ( !algo->
isReEntrant() ) { itQueueIAlgPtr->second->push( algo ); }
133 itQueueIAlgPtr->second->push( algo );
143 std::hash<std::string_view> hash_function;
144 size_t algo_id = hash_function(
name );
177 unsigned int recursionDepth ) {
184 error() <<
"Unable to dcast Algorithm " << algo->name() <<
" to a Sequence, but it has isSequence==true"
189 auto subAlgorithms = seq->subAlgorithms();
194 for (
auto subalgo : *subAlgorithms ) {
197 error() <<
"Algorithm " << subalgo->name() <<
" could not be flattened" <<
endmsg;
202 alglist.emplace_back( algo );
214 error() <<
"Algorithm manager could not be properly fetched." <<
endmsg;
222 IAlgorithm* algo = algMan->algorithm( typeName,
true ).
get();
225 error() <<
"Unable to initialize Algorithm: " << algo->name() <<
endmsg;
247 debug() <<
" o " << algo->type() <<
"/" << algo->name() <<
" @ " << algo <<
endmsg;
253 unsigned int resource_counter( 0 );
254 std::hash<std::string> hash_function;
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 );
264 verbose() <<
"Treating resource management and clones of " << item_name <<
endmsg;
267 queue->push( 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;
275 }
else if ( ialgo->isClonable() ) {
278 if ( ialgo->cardinality() == 1 ) {
282 info() <<
"Algorithm " << ialgo->name() <<
" is un-Clonable but Cardinality was set to "
283 << ialgo->cardinality() <<
". Only creating 1 instance" <<
endmsg;
286 warning() <<
"Overriding UnClonability of Algorithm " << ialgo->name() <<
". Setting Cardinality to "
287 << ialgo->cardinality() <<
endmsg;
296 for (
auto& resource_name : ialgo->neededResources() ) {
299 if ( ret.second ) ++resource_counter;
301 requirements.resize( resource_counter );
303 requirements[ret.first->second] =
true;
311 DEBUG_MSG <<
"type/name to create clone of: " << item_type <<
"/" << item_name <<
endmsg;
315 algMan->createAlgorithm( item_type, item_name, ialgoClone,
true,
false );
318 queue->push( ialgoClone );
345 std::multimap<unsigned int, std::string_view, std::greater<unsigned int>> sortedAlgInstanceMisses;
347 for (
auto& p :
m_algInstanceMisses ) sortedAlgInstanceMisses.insert( { p.second, p.first } );
350 int indnt = std::to_string( sortedAlgInstanceMisses.cbegin()->first ).length();
352 std::ostringstream out;
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";
361 std::hash<std::string_view> hash_function;
363 out << std::right << std::setfill(
' ' );
364 for (
const auto& p : sortedAlgInstanceMisses ) {
365 out << std::setw( indnt + 7 ) << std::to_string( p.first ) +
" "
377 if ( !stopSc.
isSuccess() )
return stopSc;
381 stopSc = ialgo->sysStop();
383 error() <<
"Unable to stop Algorithm: " << ialgo->name() <<
endmsg;
396 return extends::finalize();
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
#define DECLARE_COMPONENT(type)
The AlgResourcePool is a concrete implementation of the IAlgResourcePool interface.
std::list< IAlgorithm * > getFlatAlgList() override
std::map< size_t, size_t > m_n_of_allowed_instances
StatusCode acquireResource(std::string_view name) override
Acquire a certain resource.
Gaudi::Property< bool > m_lazyCreation
boost::dynamic_bitset state_type
std::list< IAlgorithm * > m_algList
The list of all algorithms created within the Pool which are not top.
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
StatusCode initialize() override
std::mutex m_resource_mutex
StatusCode releaseAlgorithm(std::string_view name, IAlgorithm *&algo) override
Release a certain algorithm.
Gaudi::Property< std::vector< std::string > > m_topAlgNames
Gaudi::Property< bool > m_countAlgInstMisses
~AlgResourcePool() override
std::list< IAlgorithm * > m_flatUniqueAlgList
The flat list of algorithms w/o clones.
void dumpInstanceMisses() const
Dump recorded Algorithm instance misses.
std::list< IAlgorithm * > getTopAlgList() override
StatusCode finalize() override
tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
StatusCode releaseResource(std::string_view name) override
Release a certain resource.
std::list< IAlgorithm * > m_topAlgList
The list of top algorithms.
StatusCode stop() override
std::map< size_t, unsigned int > m_n_of_created_instances
state_type m_available_resources
StatusCode acquireAlgorithm(std::string_view name, IAlgorithm *&algo, bool blocking=false) override
Acquire a certain algorithm using its name.
std::unordered_map< std::string_view, unsigned int > m_algInstanceMisses
Counters for Algorithm instance misses.
std::map< size_t, state_type > m_resource_requirements
StatusCode start() override
StatusCode decodeTopAlgs()
Decode the top Algorithm list.
Gaudi::Property< bool > m_overrideUnClonable
StatusCode flattenSequencer(IAlgorithm *sequencer, std::list< IAlgorithm * > &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
std::map< std::string_view, unsigned int > m_resource_indices
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
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)
MSG::Level msgLevel() const
Helper class to parse a string of format "type/name".
The IAlgorithm is the interface implemented by the Algorithm base class.
virtual StatusCode sysInitialize()=0
Initialization method invoked by the framework.
virtual bool isSequence() const =0
Are we a Sequence?
virtual void setIndex(const unsigned int &idx)=0
Set instantiation index of Alg.
virtual bool isReEntrant() const =0
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
const std::string & name() const override
Retrieve name of the service.
StatusCode stop() override
SmartIF< IFace > service(const std::string &name, bool createIf=true) const
StatusCode start() override
StatusCode initialize() override
Small smart pointer class with automatic reference counting for IInterface.
TYPE * get() const
Get interface pointer.
bool isValid() const
Allow for check if smart pointer is valid.
This class is used for returning status codes from appropriate routines.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE