5 #include "GaudiKernel/ISvcLocator.h"
6 #include "GaudiKernel/SvcFactory.h"
7 #include "GaudiKernel/ThreadGaudi.h"
20 base_class(name,svc), m_available_resources(0), m_EFGraph(0)
22 declareProperty(
"CreateLazily", m_lazyCreation =
false );
23 declareProperty(
"TopAlg", m_topAlgNames );
32 auto* queue = algoId_algoQueue.second;
46 warning () <<
"Base class could not be started" <<
endmsg;
50 info() <<
"TopAlg list empty. Recovering the one of Application Manager" <<
endmsg;
57 const std::string&
name =
"ExecutionFlowGraph";
63 warning() <<
"Algorithms could not be properly decoded." <<
endmsg;
75 if ( ! startSc.
isSuccess() )
return startSc;
79 startSc = ialgo->sysStart();
81 error() <<
"Unable to start Algorithm: " << ialgo->name() <<
endmsg;
92 std::hash<std::string> hash_function;
93 size_t algo_id = hash_function(name);
97 error() <<
"Algorithm " << name <<
" requested, but not recognised"
105 itQueueIAlgPtr->second->pop(algo);
108 sc = itQueueIAlgPtr->second->try_pop(algo);
113 debug() <<
"No instance of algorithm " << name <<
" could be retrieved in non-blocking mode" <<
endmsg;
126 error() <<
"Failure to allocate resources of algorithm " << name <<
endmsg;
127 itQueueIAlgPtr->second->push(algo);
138 std::hash<std::string> hash_function;
139 size_t algo_id = hash_function(name);
175 std::vector<Algorithm*>* subAlgorithms = algo->
subAlgorithms();
178 (subAlgorithms->empty() and not (algo->
type() ==
"GaudiSequencer"))
180 or (algo->
type() ==
"GaudiAtomicSequencer" and not subAlgorithms->empty())){
182 debug() << std::string(recursionDepth,
' ') << algo->
name() <<
" is " <<
183 (algo->
type() !=
"GaudiAtomicSequencer" ?
"not a sequencer" :
"an atomic sequencer")
184 <<
". Appending it" <<
endmsg;
186 alglist.emplace_back(algo);
193 debug() << std::string(recursionDepth,
' ') << algo->
name() <<
" is a sequencer. Flattening it." <<
endmsg;
195 bool allPass =
false;
197 if (
"GaudiSequencer" == algo->
type()) {
198 modeOR = (algo->
getProperty(
"ModeOR").toString() ==
"True")?
true :
false;
199 allPass = (algo->
getProperty(
"IgnoreFilterPassed").toString() ==
"True")?
true :
false;
200 isLazy = (algo->
getProperty(
"ShortCircuit").toString() ==
"True")?
true :
false;
201 if (allPass) isLazy =
false;
205 error() <<
"Failed to add DecisionHub " << algo->
name() <<
" to execution flow graph" <<
endmsg;
209 for (
Algorithm* subalgo : *subAlgorithms ) {
212 error() <<
"Algorithm " << subalgo->name() <<
" could not be flattened" <<
endmsg;
225 error() <<
"Algorithm manager could not be properly fetched." <<
endmsg;
230 auto createAlg = [&algMan,
this] (
const std::string& item_type,
231 const std::string& item_name,
239 this->warning() <<
"Algorithm " << item_type <<
"/" << item_name
240 <<
" could not be created." <<
endmsg;
248 for (
auto&
name : topAlgNames) {
252 const std::string& item_name = item.
name();
253 const std::string& item_type = item.
type();
256 if (!algoSmartIF.isValid()){
257 createAlg(item_type,item_name,algo);
272 if (!algorithm) fatal() <<
"Conversion from IAlgorithm to Algorithm failed" <<
endmsg;
276 debug() <<
"List of algorithms is: " <<
endmsg;
278 debug() <<
" o " << algo->type() <<
"/" << algo->name() <<
" @ " << algo <<
endmsg;
284 unsigned int resource_counter(0);
285 std::hash<std::string> hash_function;
288 const std::string& item_name = ialgoSmartIF->name();
290 verbose() <<
"Treating resource management and clones of " << item_name <<
endmsg;
293 if (!algo) fatal() <<
"Conversion from IAlgorithm to Algorithm failed" <<
endmsg;
294 const std::string& item_type = algo->
type();
296 size_t algo_id = hash_function(item_name);
310 for (
auto& resource_name : ialgo->neededResources()){
311 auto ret =
m_resource_indices.insert(std::pair<std::string, unsigned int>(resource_name,resource_counter));
313 if (ret.second==
true) {
317 requirements.resize(resource_counter);
319 requirements[ret.first->second] =
true;
327 for (
unsigned int i =1,
end =ialgo->cardinality();
i<
end; ++
i){
328 debug() <<
"type/name to create clone of: " << item_type <<
"/" << item_name <<
endmsg;
330 createAlg(item_type,item_name,ialgoClone);
332 queue->push(ialgoClone);
343 kv.second.resize(resource_counter);
377 warning() <<
"beginRun() of algorithm " << algoSmartIF->name() <<
" failed" <<
endmsg;
384 if (algBeginRun(algoSmartIF).isFailure())
398 warning() <<
"endRun() of algorithm " << algoSmartIF->name() <<
" failed" <<
endmsg;
405 if (algEndRun(algoSmartIF).isFailure())
409 if (algEndRun(algoSmartIF).isFailure())
420 if ( ! stopSc.
isSuccess() )
return stopSc;
424 stopSc = ialgo->sysStop();
426 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.
virtual StatusCode releaseResource(const std::string &name)
Release a certrain resource.
StringArrayProperty m_topAlgNames
The names of the algorithms to be passed to the algorithm manager.
StatusCode initialize() override
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
virtual std::list< IAlgorithm * > getTopAlgList()
virtual StatusCode getProperty(Property *p) const =0
Get the property by property.
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
StatusCode addDecisionHubNode(Algorithm *daughterAlgo, const std::string &parentName, bool modeOR, bool allPass, bool isLazy)
Add a node, which aggregates decisions of direct daughter nodes.
StatusCode start() override
bool isSuccess() const
Test for a status code of SUCCESS.
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...
std::list< SmartIF< IAlgorithm > > ListAlg
virtual StatusCode initialize()
const std::string & type() const override
The type of the algorithm object.
virtual void resetExecuted()=0
Reset the Algorithm executed state for the current event.
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.
const std::string & name() const override
The identifying name of the algorithm object.
boost::dynamic_bitset state_type
Helper class to parse a string of format "type/name".
std::map< size_t, size_t > m_n_of_allowed_instances
StatusCode getProperty(Property *p) const override
Implementation of IProperty::getProperty.
tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
std::list< IAlgorithm * > m_flatUniqueAlgPtrList
The flat list of algorithms w/o clones which is returned.
auto end(reverse_wrapper< T > &w)
virtual StatusCode acquireResource(const std::string &name)
Acquire a certain resource.
This class is used for returning status codes from appropriate routines.
concurrency::ExecutionFlowGraph * m_EFGraph
OMG yet another hack.
std::list< IAlgorithm * > m_topAlgPtrList
The top list of algorithms.
#define DECLARE_SERVICE_FACTORY(x)
StatusCode stop() override
The IAlgorithm is the interface implemented by the Algorithm base class.
virtual StatusCode start()
const TYPE & value() const
explicit conversion
virtual StatusCode endRun()
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.
bool assign(const Property &source) override
get the value from another property
StatusCode addAlgorithmNode(Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
Add algorithm node.
StatusCode decodeTopAlgs()
Decode the top alg list.
bool isValid() const
Allow for check if smart pointer is valid.
Base class used to extend a class implementing other interfaces.
virtual std::list< IAlgorithm * > getFlatAlgList()
const std::string & type() const
StatusCode flattenSequencer(Algorithm *sequencer, ListAlg &alglist, const std::string &parentName, unsigned int recursionDepth=0)
Recursively flatten an algList.
std::map< size_t, state_type > m_resource_requirements
void addHeadNode(const std::string &headName, bool modeOR, bool allPass, bool isLazy)
Add a node, which has no parents.
virtual StatusCode releaseAlgorithm(const std::string &name, IAlgorithm *&algo)
Release a certain algorithm.
const std::string & name() const
ListAlg m_topAlgList
The list of top algorithms.
virtual StatusCode stop()
std::map< std::string, unsigned int > m_resource_indices
void attachAlgorithmsToNodes(const std::string &algo_name, const T &container)
Attach pointers to real Algorithms (and their clones) to Algorithm nodes of the graph.
virtual StatusCode beginRun()
std::map< size_t, unsigned int > m_n_of_created_instances
ListAlg m_algList
The list of all algorithms created withing the Pool which are not top.
virtual StatusCode acquireAlgorithm(const std::string &name, IAlgorithm *&algo, bool blocking=false)
Acquire a certain algorithm using its name.