14 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 15 #define DEBUG_MSG ON_DEBUG debug() 24 auto* queue = algoId_algoQueue.second;
40 info() <<
"TopAlg list empty. Recovering the one of Application Manager" <<
endmsg;
60 if ( !startSc.
isSuccess() )
return startSc;
64 startSc = ialgo->sysStart();
66 error() <<
"Unable to start Algorithm: " << ialgo->name() <<
endmsg;
79 size_t algo_id = hash_function( name );
83 error() <<
"Algorithm " << name <<
" requested, but not recognised" <<
endmsg;
90 itQueueIAlgPtr->second->pop( algo );
92 if ( !itQueueIAlgPtr->second->try_pop( algo ) ) {
104 DEBUG_MSG <<
"No instance of algorithm " << name <<
" could be retrieved in non-blocking mode" <<
endmsg;
116 error() <<
"Failure to allocate resources of algorithm " << name <<
endmsg;
120 itQueueIAlgPtr->second->push( algo );
126 itQueueIAlgPtr->second->push( algo );
138 size_t algo_id = hash_function( name );
179 bool isGaudiSequencer(
false );
180 bool isAthSequencer(
false );
184 isGaudiSequencer =
true;
186 isAthSequencer =
true;
192 ( subAlgorithms->
empty() && !( isGaudiSequencer || isAthSequencer ) ) ) {
201 for (
Algorithm* subalgo : *subAlgorithms ) {
204 error() <<
"Algorithm " << subalgo->name() <<
" could not be flattened" <<
endmsg;
218 error() <<
"Algorithm manager could not be properly fetched." <<
endmsg;
226 this->
warning() <<
"Algorithm " << item_type <<
"/" << item_name <<
" could not be created." <<
endmsg;
234 for (
auto&
name : topAlgNames ) {
242 if ( !algoSmartIF.isValid() ) {
243 createAlg( item_type, item_name, algo );
255 if ( !algorithm )
fatal() <<
"Conversion from IAlgorithm to Algorithm failed" <<
endmsg;
271 debug() <<
" o " << algo->type() <<
"/" << algo->name() <<
" @ " << algo <<
endmsg;
277 unsigned int resource_counter( 0 );
281 const std::string& item_name = ialgoSmartIF->name();
283 verbose() <<
"Treating resource management and clones of " << item_name <<
endmsg;
286 if ( !algo )
fatal() <<
"Conversion from IAlgorithm to Algorithm failed" <<
endmsg;
289 size_t algo_id = hash_function( item_name );
296 queue->push( ialgo );
298 if ( ialgo->isClonable() ) {
301 if ( ialgo->cardinality() == 1 ) {
305 info() <<
"Algorithm " << ialgo->name() <<
" is un-Clonable but Cardinality was set to " 306 << ialgo->cardinality() <<
". Only creating 1 instance" <<
endmsg;
309 warning() <<
"Overriding UnClonability of Algorithm " << ialgo->name() <<
". Setting Cardinality to " 310 << ialgo->cardinality() <<
endmsg;
319 for (
auto& resource_name : ialgo->neededResources() ) {
322 if ( ret.second ) ++resource_counter;
324 requirements.resize( resource_counter );
326 requirements[ret.first->second] =
true;
334 debug() <<
"type/name to create clone of: " << item_type <<
"/" << item_name <<
endmsg;
336 createAlg( item_type, item_name, ialgoClone );
339 error() <<
"unable to initialize Algorithm clone " << ialgoClone->name() <<
endmsg;
343 queue->push( ialgoClone );
352 kv.second.resize( resource_counter );
387 if ( !stopSc.
isSuccess() )
return stopSc;
391 stopSc = ialgo->sysStop();
393 error() <<
"Unable to stop Algorithm: " << ialgo->name() <<
endmsg;
ListAlg m_flatUniqueAlgList
The flat list of algorithms w/o clones.
virtual SmartIF< IAlgorithm > & algorithm(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
constexpr static const auto FAILURE
StatusCode initialize() override
const std::string & name() const override
Retrieve name of the service.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
StatusCode start() override
std::map< std::string, unsigned int > m_resource_indices
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
StatusCode flattenSequencer(Algorithm *sequencer, ListAlg &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
std::mutex m_resource_mutex
virtual StatusCode createAlgorithm(const std::string &algtype, const std::string &algname, IAlgorithm *&alg, bool managed=false, bool checkIfExists=true)=0
Create an instance of a algorithm type that has been declared beforehand and assigns to it a name...
StatusCode stop() override
virtual StatusCode getProperty(Gaudi::Details::PropertyBase *p) const =0
Get the property by property.
The AlgResourcePool is a concrete implementation of the IAlgResourcePool interface.
state_type m_available_resources
Gaudi::Property< bool > m_overrideUnClonable
virtual StatusCode sysInitialize()=0
Initialization method invoked by the framework.
#define DECLARE_COMPONENT(type)
boost::dynamic_bitset state_type
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
std::list< IAlgorithm * > m_flatUniqueAlgPtrList
The flat list of algorithms w/o clones which is returned.
This class is used for returning status codes from appropriate routines.
std::map< size_t, state_type > m_resource_requirements
StatusCode start() override
~AlgResourcePool() override
std::list< IAlgorithm * > m_topAlgPtrList
The top list of algorithms.
virtual unsigned int cardinality() const =0
Cardinality (Maximum number of clones that can exist) special value 0 means that algorithm is reentra...
virtual void setIndex(const unsigned int &idx)=0
Set instantiation index of Alg.
std::list< IAlgorithm * > getFlatAlgList() override
StatusCode releaseResource(const std::string &name) override
Release a certrain resource.
Gaudi::Property< std::vector< std::string > > m_topAlgNames
std::list< IAlgorithm * > getTopAlgList() override
StatusCode stop() override
The IAlgorithm is the interface implemented by the Algorithm base class.
constexpr static const auto SUCCESS
StatusCode acquireResource(const std::string &name) override
Acquire a certain resource.
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
const std::vector< Algorithm * > * subAlgorithms() const
List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms.
Base class from which all concrete algorithm classes should be derived.
StatusCode decodeTopAlgs()
Decode the top alg list.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
bool isValid() const
Allow for check if smart pointer is valid.
bool isSequence() const override
Are we a Sequence?
const std::string & type() const
const StatusCode & ignore() const
Ignore/check StatusCode.
StatusCode acquireAlgorithm(const std::string &name, IAlgorithm *&algo, bool blocking=false) override
Acquire a certain algorithm using its name.
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.
std::map< size_t, unsigned int > m_n_of_created_instances
AttribStringParser::Iterator begin(const AttribStringParser &parser)
const std::string & name() const
StatusCode initialize() override
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.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
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.
StatusCode releaseAlgorithm(const std::string &name, IAlgorithm *&algo) override
Release a certain algorithm.
Gaudi::Property< bool > m_lazyCreation
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)