19 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 20 #define DEBUG_MSG ON_DEBUG debug() 28 auto* queue = algoId_algoQueue.second;
46 info() <<
"TopAlg list empty. Recovering the one of Application Manager" <<
endmsg;
59 warning() <<
"Algorithms could not be properly decoded." <<
endmsg;
71 if ( ! startSc.
isSuccess() )
return startSc;
75 startSc = ialgo->sysStart();
77 error() <<
"Unable to start Algorithm: " << ialgo->name() <<
endmsg;
89 size_t algo_id = hash_function(name);
93 error() <<
"Algorithm " << name <<
" requested, but not recognised" 101 itQueueIAlgPtr->second->pop(algo);
104 sc = itQueueIAlgPtr->second->try_pop(algo);
114 DEBUG_MSG <<
"No instance of algorithm " << name <<
" could be retrieved in non-blocking mode" <<
endmsg;
126 error() <<
"Failure to allocate resources of algorithm " << name <<
endmsg;
130 itQueueIAlgPtr->second->push(algo);
136 itQueueIAlgPtr->second->push(algo);
147 size_t algo_id = hash_function(name);
185 bool isGaudiSequencer(
false);
186 bool isAthSequencer(
false);
190 isGaudiSequencer =
true;
192 isAthSequencer =
true;
198 (subAlgorithms->
empty() && !(isGaudiSequencer || isAthSequencer)) ) {
201 <<
" is not a sequencer. Appending it" <<
endmsg;
212 bool allPass =
false;
214 bool isSequential =
false;
216 if ( isGaudiSequencer ) {
217 modeOR = (algo->
getProperty(
"ModeOR").toString() ==
"True")?
true :
false;
218 allPass = (algo->
getProperty(
"IgnoreFilterPassed").toString() ==
"True")?
true :
false;
219 isLazy = (algo->
getProperty(
"ShortCircuit").toString() ==
"True")?
true :
false;
220 if (allPass) isLazy =
false;
222 (algo->
getProperty(
"Sequential").toString() ==
"True") );
223 }
else if (isAthSequencer ) {
224 modeOR = (algo->
getProperty(
"ModeOR").toString() ==
"True")?
true :
false;
225 allPass = (algo->
getProperty(
"IgnoreFilterPassed").toString() ==
"True")?
true :
false;
226 isLazy = (algo->
getProperty(
"StopOverride").toString() ==
"True")?
false :
true;
228 (algo->
getProperty(
"Sequential").toString() ==
"True") );
232 error() <<
"Failed to add DecisionHub " << algo->
name() <<
" to graph of precedence rules" <<
endmsg;
236 for (
Algorithm* subalgo : *subAlgorithms ) {
239 error() <<
"Algorithm " << subalgo->name() <<
" could not be flattened" <<
endmsg;
252 error() <<
"Algorithm manager could not be properly fetched." <<
endmsg;
257 auto createAlg = [&algMan,
this] (
const std::string& item_type,
266 this->
warning() <<
"Algorithm " << item_type <<
"/" << item_name
267 <<
" could not be created." <<
endmsg;
275 for (
auto&
name : topAlgNames) {
283 if (!algoSmartIF.isValid()){
284 createAlg(item_type,item_name,algo);
299 if (!algorithm)
fatal() <<
"Conversion from IAlgorithm to Algorithm failed" <<
endmsg;
313 debug() <<
" o " << algo->type() <<
"/" << algo->name() <<
" @ " << algo <<
endmsg;
319 unsigned int resource_counter(0);
323 const std::string& item_name = ialgoSmartIF->name();
325 verbose() <<
"Treating resource management and clones of " << item_name <<
endmsg;
328 if (!algo)
fatal() <<
"Conversion from IAlgorithm to Algorithm failed" <<
endmsg;
331 size_t algo_id = hash_function(item_name);
345 for (
auto& resource_name : ialgo->neededResources()){
348 if (ret.second) ++resource_counter;
350 requirements.resize(resource_counter);
352 requirements[ret.first->second] =
true;
360 for (
unsigned int i =1,
end =ialgo->cardinality();i<
end; ++i){
361 debug() <<
"type/name to create clone of: " << item_type <<
"/" 364 createAlg(item_type,item_name,ialgoClone);
367 error() <<
"unable to initialize Algorithm clone " 368 << ialgoClone->name() <<
endmsg;
372 queue->push(ialgoClone);
384 kv.second.resize(resource_counter);
418 warning() <<
"beginRun() of algorithm " << algoSmartIF->name() <<
" failed" <<
endmsg;
425 if (algBeginRun(algoSmartIF).isFailure())
439 warning() <<
"endRun() of algorithm " << algoSmartIF->name() <<
" failed" <<
endmsg;
446 if (algEndRun(algoSmartIF).isFailure())
450 if (algEndRun(algoSmartIF).isFailure())
461 if ( ! stopSc.
isSuccess() )
return stopSc;
465 stopSc = ialgo->sysStop();
467 error() <<
"Unable to stop Algorithm: " << ialgo->name() <<
endmsg;
ListAlg m_flatUniqueAlgList
The flat list of algorithms w/o clones.
StatusCode getProperty(Gaudi::Details::PropertyBase *p) const override
get the property
virtual SmartIF< IAlgorithm > & algorithm(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
StatusCode initialize() override
StatusCode addAlgorithmNode(Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
Add algorithm node.
const std::string & name() const override
The identifying name of the algorithm object.
const std::string & name() const override
Retrieve name of the service.
void attachAlgorithmsToNodes(const std::string &algo_name, const T &container)
Attach pointers to real Algorithms (and their clones) to Algorithm nodes of the graph.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
StatusCode start() override
std::map< std::string, unsigned int > m_resource_indices
bool isSuccess() const
Test for a status code of SUCCESS.
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
StatusCode addDecisionHubNode(Algorithm *daughterAlgo, const std::string &parentName, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
Add a node, which aggregates decisions of direct daughter nodes.
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 beginRun() override
void addHeadNode(const std::string &headName, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
Add a node, which has no parents.
StatusCode stop() override
virtual StatusCode getProperty(Gaudi::Details::PropertyBase *p) const =0
Get the property by property.
StatusCode endRun() override
The AlgResourcePool is a concrete implementation of the IAlgResourcePool interface.
bool isFailure() const
Test for a status code of FAILURE.
state_type m_available_resources
virtual StatusCode sysInitialize()=0
Initialization method invoked by the framework.
auto begin(reverse_wrapper< T > &w)
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...
auto end(reverse_wrapper< T > &w)
virtual void setIndex(const unsigned int &idx)=0
Set instantiation index of Alg.
std::list< IAlgorithm * > getFlatAlgList() override
#define DECLARE_SERVICE_FACTORY(x)
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.
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.
const std::string & type() const
StatusCode flattenSequencer(Algorithm *sequencer, ListAlg &alglist, const std::string &parentName, unsigned int recursionDepth=0)
Recursively flatten an algList.
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
const std::string & name() const
StatusCode initialize() override
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
concurrency::PrecedenceRulesGraph * m_PRGraph
OMG yet another hack.
ListAlg m_topAlgList
The list of top algorithms.
const std::string & type() const override
The type of the algorithm object.
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
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