| The Gaudi Framework v32r1 (f65d50dc)

AlgResourcePool.h
Go to the documentation of this file.
1 #ifndef GAUDIHIVE_ALGRESOURCEPOOL_H
2 #define GAUDIHIVE_ALGRESOURCEPOOL_H
3
4 #include "GaudiKernel/IAlgManager.h"
5 #include "GaudiKernel/IAlgResourcePool.h"
6 #include "GaudiKernel/IAlgorithm.h"
7 #include "GaudiKernel/Service.h"
8 #include <Gaudi/Algorithm.h>
9
10 #include <atomic>
11 #include <bitset>
12 #include <list>
13 #include <mutex>
14 #include <string>
15 #include <vector>
16
17 // External libs
18 #include "boost/dynamic_bitset.hpp"
19 #include "tbb/concurrent_queue.h"
20
29 class AlgResourcePool : public extends<Service, IAlgResourcePool> {
30 public:
31 // Standard constructor
32 using extends::extends;
33 // Standard destructor
34 ~AlgResourcePool() override;
35
36 StatusCode start() override;
37 StatusCode initialize() override;
39 StatusCode acquireAlgorithm( const std::string& name, IAlgorithm*& algo, bool blocking = false ) override;
41 StatusCode releaseAlgorithm( const std::string& name, IAlgorithm*& algo ) override;
43 StatusCode acquireResource( const std::string& name ) override;
45 StatusCode releaseResource( const std::string& name ) override;
46
47 std::list<IAlgorithm*> getFlatAlgList() override;
48 std::list<IAlgorithm*> getTopAlgList() override;
49
50 StatusCode stop() override;
51
52 private:
53 typedef tbb::concurrent_bounded_queue<IAlgorithm*> concurrentQueueIAlgPtr;
54 typedef std::list<SmartIF<IAlgorithm>> ListAlg;
55 typedef boost::dynamic_bitset<> state_type;
56
57 std::mutex m_resource_mutex;
58
59 state_type m_available_resources{0};
60 std::map<size_t, concurrentQueueIAlgPtr*> m_algqueue_map;
61 std::map<size_t, state_type> m_resource_requirements;
62 std::map<size_t, size_t> m_n_of_allowed_instances;
63 std::map<size_t, unsigned int> m_n_of_created_instances;
64 std::map<std::string, unsigned int> m_resource_indices;
65
67 StatusCode decodeTopAlgs();
68
70 StatusCode flattenSequencer( Gaudi::Algorithm* sequencer, ListAlg& alglist, unsigned int recursionDepth = 0 );
71
72 Gaudi::Property<bool> m_lazyCreation{this, "CreateLazily", false, ""};
73 Gaudi::Property<std::vector<std::string>> m_topAlgNames{
74 this, "TopAlg", {}, "names of the algorithms to be passed to the algorithm manager"};
75 Gaudi::Property<bool> m_overrideUnClonable{this, "OverrideUnClonable", false,
76 "override the Un-Clonability of Algorithms. Use with caution!"};
77
79 ListAlg m_algList;
80
82 ListAlg m_topAlgList;
83
85 ListAlg m_flatUniqueAlgList;
86
88 std::list<IAlgorithm*> m_flatUniqueAlgPtrList;
89
91 std::list<IAlgorithm*> m_topAlgPtrList;
92 };
93
94 #endif // GAUDIHIVE_ALGRESOURCEPOOL_H
AlgResourcePool::m_flatUniqueAlgList
ListAlg m_flatUniqueAlgList
The flat list of algorithms w/o clones.
Definition: AlgResourcePool.h:85
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
IAlgorithm.h
AlgResourcePool::m_resource_indices
std::map< std::string, unsigned int > m_resource_indices
Definition: AlgResourcePool.h:64
IAlgResourcePool.h
AlgResourcePool::m_resource_mutex
std::mutex m_resource_mutex
Definition: AlgResourcePool.h:57
AlgResourcePool::ListAlg
std::list< SmartIF< IAlgorithm > > ListAlg
Definition: AlgResourcePool.h:54
AlgResourcePool::stop
StatusCode stop() override
Definition: AlgResourcePool.cpp:371
AlgResourcePool
The AlgResourcePool is a concrete implementation of the IAlgResourcePool interface.
Definition: AlgResourcePool.h:29
std::map< size_t, concurrentQueueIAlgPtr * >
AlgResourcePool::m_available_resources
state_type m_available_resources
Definition: AlgResourcePool.h:59
std::mutex
AlgResourcePool::m_overrideUnClonable
Gaudi::Property< bool > m_overrideUnClonable
Definition: AlgResourcePool.h:75
std::string
STL class.
Service.h
AlgResourcePool::state_type
boost::dynamic_bitset state_type
Definition: AlgResourcePool.h:55
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
AlgResourcePool::concurrentQueueIAlgPtr
tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
Definition: AlgResourcePool.h:53
AlgResourcePool::m_flatUniqueAlgPtrList
std::list< IAlgorithm * > m_flatUniqueAlgPtrList
The flat list of algorithms w/o clones which is returned.
Definition: AlgResourcePool.h:88
Algorithm.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
AlgResourcePool::m_resource_requirements
std::map< size_t, state_type > m_resource_requirements
Definition: AlgResourcePool.h:61
AlgResourcePool::start
StatusCode start() override
Definition: AlgResourcePool.cpp:53
AlgResourcePool::~AlgResourcePool
~AlgResourcePool() override
Definition: AlgResourcePool.cpp:20
AlgResourcePool::m_topAlgPtrList
std::list< IAlgorithm * > m_topAlgPtrList
The top list of algorithms.
Definition: AlgResourcePool.h:91
AlgResourcePool::getFlatAlgList
std::list< IAlgorithm * > getFlatAlgList() override
Definition: AlgResourcePool.cpp:355
AlgResourcePool::releaseResource
StatusCode releaseResource(const std::string &name) override
Release a certrain resource.
Definition: AlgResourcePool.cpp:151
AlgResourcePool::m_topAlgNames
Gaudi::Property< std::vector< std::string > > m_topAlgNames
Definition: AlgResourcePool.h:73
AlgResourcePool::getTopAlgList
std::list< IAlgorithm * > getTopAlgList() override
Definition: AlgResourcePool.cpp:363
std::list< IAlgorithm * >
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
AlgResourcePool::acquireResource
StatusCode acquireResource(const std::string &name) override
Acquire a certain resource.
Definition: AlgResourcePool.cpp:142
AlgResourcePool::m_algqueue_map
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
Definition: AlgResourcePool.h:60
AlgResourcePool::decodeTopAlgs
StatusCode decodeTopAlgs()
Decode the top alg list.
Definition: AlgResourcePool.cpp:193
AlgResourcePool::flattenSequencer
StatusCode flattenSequencer(Gaudi::Algorithm *sequencer, ListAlg &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
Definition: AlgResourcePool.cpp:160
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
AlgResourcePool::acquireAlgorithm
StatusCode acquireAlgorithm(const std::string &name, IAlgorithm *&algo, bool blocking=false) override
Acquire a certain algorithm using its name.
Definition: AlgResourcePool.cpp:71
IAlgManager.h
AlgResourcePool::m_n_of_created_instances
std::map< size_t, unsigned int > m_n_of_created_instances
Definition: AlgResourcePool.h:63
AlgResourcePool::initialize
StatusCode initialize() override
Definition: AlgResourcePool.cpp:30
AtlasMCRecoFullPrecedenceDump.sequencer
sequencer
Definition: AtlasMCRecoFullPrecedenceDump.py:40
AlgResourcePool::m_topAlgList
ListAlg m_topAlgList
The list of top algorithms.
Definition: AlgResourcePool.h:82
AlgResourcePool::m_n_of_allowed_instances
std::map< size_t, size_t > m_n_of_allowed_instances
Definition: AlgResourcePool.h:62
AlgResourcePool::m_algList
ListAlg m_algList
The list of all algorithms created withing the Pool which are not top.
Definition: AlgResourcePool.h:79
AlgResourcePool::releaseAlgorithm
StatusCode releaseAlgorithm(const std::string &name, IAlgorithm *&algo) override
Release a certain algorithm.
Definition: AlgResourcePool.cpp:125
AlgResourcePool::m_lazyCreation
Gaudi::Property< bool > m_lazyCreation
Definition: AlgResourcePool.h:72