| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

GaudiParallelizer.h
Go to the documentation of this file.
1 #ifndef LIB_GAUDIPARALLELIZER_H
2 #define LIB_GAUDIPARALLELIZER_H 1
3 // Include files
4 // from Gaudi
5 #include "GaudiAlg/GaudiAlgorithm.h"
6 #include "GaudiKernel/ThreadLocalContext.h"
7
8 #include <boost/bind.hpp>
9 #include <tbb/task_group.h>
10 #include <tbb/task_scheduler_init.h>
11
12 // Forward declarations
13 class ISequencerTimerTool;
14
21 class GaudiParallelizer : public GaudiAlgorithm
22 {
23 public:
25 GaudiParallelizer( const std::string& name, ISvcLocator* pSvcLocator );
27 ~GaudiParallelizer() noexcept( true ) override {}
28 StatusCode initialize() override;
29 StatusCode execute() override;
30 StatusCode finalize() override;
31
33 void membershipHandler( Gaudi::Details::PropertyBase& theProp );
34
35 protected:
36 class AlgorithmEntry
37 {
38 public:
40 AlgorithmEntry( Algorithm* alg )
41 {
42 m_algorithm = alg;
43 m_reverse = false;
44 m_timer = 0;
45 }
46
47 virtual ~AlgorithmEntry(){};
48 void setReverse( bool flag ) { m_reverse = flag; }
49
50 Algorithm* algorithm() const { return m_algorithm; }
51 bool reverse() const { return m_reverse; }
52 void setTimer( int nb ) { m_timer = nb; }
53 int timer() const { return m_timer; }
54
56 void run( GaudiParallelizer& prlzr )
57 {
58 if ( prlzr.m_measureTime ) prlzr.m_timerTool->start( timer() );
59 m_returncode = m_algorithm->sysExecute(Gaudi::Hive::currentContext());
60 if ( prlzr.m_measureTime ) prlzr.m_timerTool->stop( timer() );
61 algorithm()->setExecuted( true );
62 }
63
64 StatusCode m_returncode;
65
66 private:
67 Algorithm* m_algorithm;
68 bool m_reverse;
69 int m_timer;
70 };
71
73 StatusCode decodeNames();
74
75 private:
76 Gaudi::Property<std::vector<std::string>> m_names{this, "Members", {}, "list of algorithms"};
77 Gaudi::Property<bool> m_modeOR{this, "ModeOR", false, "use OR loginc instead of AND"};
78 Gaudi::Property<bool> m_measureTime{this, "MeasureTime", false, "measure time"};
79 Gaudi::Property<bool> m_returnOK{this, "ReturnOK", false, "forces the sequencer to return a good status"};
80 Gaudi::Property<unsigned short> m_nthreads{this, "NumberOfThreads", 0, "number of threads in the thread pool"};
81
82 std::vector<AlgorithmEntry> m_entries;
83
84 ISequencerTimerTool* m_timerTool = nullptr;
85 int m_timer;
86
87 tbb::task_group m_task_group;
88 };
89
90 #endif // LIB_GAUDIPARALLELIZER_H
GaudiParallelizer::initialize
StatusCode initialize() override
Algorithm initialization.
Definition: GaudiParallelizer.cpp:30
GaudiParallelizer::m_measureTime
Gaudi::Property< bool > m_measureTime
Definition: GaudiParallelizer.h:78
GaudiParallelizer::execute
StatusCode execute() override
Algorithm execution.
Definition: GaudiParallelizer.cpp:81
GaudiParallelizer::AlgorithmEntry::m_reverse
bool m_reverse
Indicates that the flag has to be inverted.
Definition: GaudiParallelizer.h:68
GaudiParallelizer::AlgorithmEntry::AlgorithmEntry
AlgorithmEntry(Algorithm *alg)
Standard constructor.
Definition: GaudiParallelizer.h:40
GaudiParallelizer::m_modeOR
Gaudi::Property< bool > m_modeOR
Definition: GaudiParallelizer.h:77
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
GaudiParallelizer::GaudiParallelizer
GaudiParallelizer(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.
Definition: GaudiParallelizer.cpp:21
GaudiParallelizer::AlgorithmEntry::algorithm
Algorithm * algorithm() const
Definition: GaudiParallelizer.h:50
Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:715
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:314
ThreadLocalContext.h
GaudiAlgorithm.h
Header file for class GaudiAlgorithm.
GaudiParallelizer
Definition: GaudiParallelizer.h:21
GaudiParallelizer::decodeNames
StatusCode decodeNames()
Decode a vector of string.
Definition: GaudiParallelizer.cpp:125
std::string
STL class.
GaudiParallelizer::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: GaudiParallelizer.cpp:116
Algorithm::setExecuted
void setExecuted(bool state) override
Set the executed flag to the specified state.
Definition: Algorithm.cpp:730
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiAlgorithm
The useful base class for data processing algorithms.
Definition: GaudiAlgorithm.h:94
Gaudi::Hive::currentContext
GAUDI_API const EventContext & currentContext()
Definition: ThreadLocalContext.cpp:24
GaudiParallelizer::m_returnOK
Gaudi::Property< bool > m_returnOK
Definition: GaudiParallelizer.h:79
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
GaudiParallelizer::~GaudiParallelizer
~GaudiParallelizer() noexcept(true) override
Destructor. An explicit noexcept(true) is necessary for Gaudi to build (see GAUDI-1187) ...
Definition: GaudiParallelizer.h:27
GaudiParallelizer::m_nthreads
Gaudi::Property< unsigned short > m_nthreads
Definition: GaudiParallelizer.h:80
GaudiParallelizer::m_task_group
tbb::task_group m_task_group
TBB task group.
Definition: GaudiParallelizer.h:87
ISequencerTimerTool::start
virtual void start(int index)=0
start the counter, i.e.
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:78
std::vector
STL class.
GaudiParallelizer::AlgorithmEntry::m_algorithm
Algorithm * m_algorithm
Algorithm pointer.
Definition: GaudiParallelizer.h:67
GaudiParallelizer::AlgorithmEntry::~AlgorithmEntry
virtual ~AlgorithmEntry()
Definition: GaudiParallelizer.h:47
GaudiParallelizer::AlgorithmEntry::setReverse
void setReverse(bool flag)
Destructor.
Definition: GaudiParallelizer.h:48
GaudiParallelizer::m_entries
std::vector< AlgorithmEntry > m_entries
List of algorithms to process.
Definition: GaudiParallelizer.h:82
GaudiParallelizer::AlgorithmEntry::timer
int timer() const
Definition: GaudiParallelizer.h:53
ISequencerTimerTool
Implements the time measurement inside a sequencer.
Definition: ISequencerTimerTool.h:14
GaudiParallelizer::AlgorithmEntry::setTimer
void setTimer(int nb)
Definition: GaudiParallelizer.h:52
GaudiParallelizer::AlgorithmEntry::m_returncode
StatusCode m_returncode
StatusCode of an algorithm execution received from a thread.
Definition: GaudiParallelizer.h:64
GaudiParallelizer::membershipHandler
void membershipHandler(Gaudi::Details::PropertyBase &theProp)
for asynchronous changes in the list of algorithms
Definition: GaudiParallelizer.cpp:259
GaudiParallelizer::m_names
Gaudi::Property< std::vector< std::string > > m_names
Definition: GaudiParallelizer.h:76
GaudiParallelizer::AlgorithmEntry::m_timer
int m_timer
Timer number for this algorithm.
Definition: GaudiParallelizer.h:69
GaudiParallelizer::m_timerTool
ISequencerTimerTool * m_timerTool
Pointer to the timer tool.
Definition: GaudiParallelizer.h:84
GaudiParallelizer::m_timer
int m_timer
Timer number for the sequencer.
Definition: GaudiParallelizer.h:85
GaudiParallelizer::AlgorithmEntry::reverse
bool reverse() const
Definition: GaudiParallelizer.h:51
GaudiParallelizer::AlgorithmEntry
Definition: GaudiParallelizer.h:36
ISequencerTimerTool::stop
virtual double stop(int index)=0
stop the counter, return the elapsed time
GaudiParallelizer::AlgorithmEntry::run
void run(GaudiParallelizer &prlzr)
Thread task executor method to wrap an algorithm execution in.
Definition: GaudiParallelizer.h:56
Algorithm::sysExecute
StatusCode sysExecute(const EventContext &ctx) override
The actions to be performed by the algorithm on an event.
Definition: Algorithm.cpp:484