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;
57 for (
const auto& [res_name, res_required] : algo->neededResources() ) {
60 if ( res_required > res_available ) {
61 error() <<
"Cannot satisfy resource requirement '" << res_name <<
"' for algorithm '" << algo->name()
62 <<
" (required: " << res_required <<
", available: " << res_available <<
")" <<
endmsg;
76 if ( !startSc.
isSuccess() )
return startSc;
80 startSc = ialgo->sysStart();
82 error() <<
"Unable to start Algorithm: " << ialgo->name() <<
endmsg;
93 std::hash<std::string_view> hash_function;
94 size_t algo_id = hash_function(
name );
98 error() <<
"Algorithm " <<
name <<
" requested, but not recognised" <<
endmsg;
105 itQueueIAlgPtr->second->pop( algo );
107 if ( !itQueueIAlgPtr->second->try_pop( algo ) ) {
111 ++( result->second );
126 DEBUG_MSG <<
"No instance of algorithm " <<
name <<
" could be retrieved in non-blocking mode" <<
endmsg;
137 res->second -= res_value;
142 msgStream( lvl ) <<
"Failure to allocate resource '" << res_name <<
"' for algorithm " <<
name
143 <<
" (required: " << res_value <<
", available: " << res->second <<
")" <<
endmsg;
156 if ( !algo->
isReEntrant() ) { itQueueIAlgPtr->second->push( algo ); }
162 itQueueIAlgPtr->second->push( algo );
172 std::hash<std::string_view> hash_function;
173 size_t algo_id = hash_function(
name );
195 res->second -= value;
209 res->second += value;
216 unsigned int recursionDepth ) {
223 error() <<
"Unable to dcast Algorithm " << algo->name() <<
" to a Sequence, but it has isSequence==true"
228 auto subAlgorithms = seq->subAlgorithms();
233 for (
auto subalgo : *subAlgorithms ) {
236 error() <<
"Algorithm " << subalgo->name() <<
" could not be flattened" <<
endmsg;
241 alglist.emplace_back( algo );
253 error() <<
"Algorithm manager could not be properly fetched." <<
endmsg;
261 IAlgorithm* algo = algMan->algorithm( typeName,
true ).
get();
264 error() <<
"Unable to initialize Algorithm: " << algo->name() <<
endmsg;
286 debug() <<
" o " << algo->type() <<
"/" << algo->name() <<
" @ " << algo <<
endmsg;
292 std::hash<std::string> hash_function;
295 const std::string& item_name = ialgo->name();
296 const std::string& item_type = ialgo->type();
297 size_t algo_id = hash_function( item_name );
302 verbose() <<
"Treating resource management and clones of " << item_name <<
endmsg;
305 queue->push( ialgo );
307 if ( ialgo->isReEntrant() ) {
308 if ( ialgo->cardinality() != 0 ) {
309 info() <<
"Algorithm " << ialgo->name() <<
" is ReEntrant, but Cardinality was set to " << ialgo->cardinality()
310 <<
". Only creating 1 instance" <<
endmsg;
313 }
else if ( ialgo->isClonable() ) {
316 if ( ialgo->cardinality() == 1 ) {
320 info() <<
"Algorithm " << ialgo->name() <<
" is un-Clonable but Cardinality was set to "
321 << ialgo->cardinality() <<
". Only creating 1 instance" <<
endmsg;
324 warning() <<
"Overriding UnClonability of Algorithm " << ialgo->name() <<
". Setting Cardinality to "
325 << ialgo->cardinality() <<
endmsg;
335 DEBUG_MSG <<
"type/name to create clone of: " << item_type <<
"/" << item_name <<
endmsg;
338 if (
StatusCode createAlgSc = algMan->createAlgorithm( item_type, item_name, ialgoClone,
true,
340 createAlgSc.isFailure() ) {
344 queue->push( ialgoClone );
364 std::multimap<unsigned int, std::string_view, std::greater<unsigned int>> sortedAlgInstanceMisses;
366 for (
auto& p :
m_algInstanceMisses ) sortedAlgInstanceMisses.insert( { p.second, p.first } );
369 int indnt = std::to_string( sortedAlgInstanceMisses.cbegin()->first ).length();
371 std::ostringstream out;
373 out <<
"Hit parade of algorithm instance misses:\n"
374 << std::right << std::setfill(
' ' )
375 <<
" ===============================================================================\n"
376 << std::setw( indnt + 7 ) <<
"Misses "
377 <<
"| Algorithm (# of clones) \n"
378 <<
" ===============================================================================\n";
380 std::hash<std::string_view> hash_function;
382 out << std::right << std::setfill(
' ' );
383 for (
const auto& p : sortedAlgInstanceMisses ) {
384 out << std::setw( indnt + 7 ) << std::to_string( p.first ) +
" "
396 if ( !stopSc.
isSuccess() )
return stopSc;
400 stopSc = ialgo->sysStop();
402 error() <<
"Unable to stop Algorithm: " << ialgo->name() <<
endmsg;
415 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
Gaudi::Property< bool > m_lazyCreation
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
StatusCode acquireResource(std::string_view name, unsigned int value) override
Acquire units of a certain resource.
std::list< IAlgorithm * > m_flatUniqueAlgList
The flat list of algorithms w/o clones.
void dumpInstanceMisses() const
Dump recorded Algorithm instance misses.
Gaudi::Property< int > m_missingResourceMsgLevel
StatusCode releaseResource(std::string_view name, unsigned int value) override
Release a certain resource.
std::list< IAlgorithm * > getTopAlgList() override
StatusCode finalize() override
tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
Gaudi::Property< IAlgorithm::AlgResources_t > m_availableResources
std::list< IAlgorithm * > m_topAlgList
The list of top algorithms.
StatusCode stop() override
std::map< size_t, unsigned int > m_n_of_created_instances
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.
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.
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 & msgStream() const
Return an uninitialized MsgStream.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Helper class for efficient "key" access for strings.
Helper class to parse a string of format "type/name".
The IAlgorithm is the interface implemented by the Algorithm base class.
virtual const AlgResources_t & neededResources() const =0
Named, non thread-safe resources used during event processing.
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