| The Gaudi Framework v32r1 (f65d50dc)

HiveTestAlgorithm.cpp
Go to the documentation of this file.
1 #include "GaudiHive/HiveTestAlgorithm.h"
2 #include "GaudiKernel/MsgStream.h"
3 #include "GaudiKernel/ThreadLocalContext.h"
4
5 #include <atomic>
6
7 DECLARE_COMPONENT( HiveTestAlgorithm )
8
9 using namespace std;
10
11 class MyObject : public DataObject {
12 int m_data;
13 static atomic<int> c_instances;
14 static atomic<int> d_instances;
15
16 public:
17 MyObject( int d ) : m_data( d ) { c_instances++; }
18 MyObject( const MyObject& o ) : DataObject(), m_data( o.m_data ) { c_instances++; }
19 ~MyObject() { d_instances++; }
20 int getData() { return m_data; }
21 static void dump() { cout << "MyObject (C/D): " << c_instances << "/" << d_instances << endl; }
22 };
23
24 atomic<int> MyObject::c_instances;
25 atomic<int> MyObject::d_instances;
26
27 StatusCode HiveTestAlgorithm::initialize() {
28 info() << ":HiveTestAlgorithm::initialize " << endmsg;
29
30 int i = 0;
31 for ( auto k : m_inputs ) {
32 debug() << "adding input key " << k << endmsg;
33 m_inputHandles.push_back( new DataObjectHandle<DataObject>( k, Gaudi::DataHandle::Reader, this ) );
34 declareProperty( "dummy_in_" + std::to_string( i ), *( m_inputHandles.back() ) );
35 i++;
36 }
37
38 i = 0;
39 for ( auto k : m_outputs ) {
40 debug() << "adding output key " << k << endmsg;
41 m_outputHandles.push_back( new DataObjectHandle<DataObject>( k, Gaudi::DataHandle::Writer, this ) );
42 declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
43 i++;
44 }
45
46 return StatusCode::SUCCESS;
47 }
48
49 StatusCode HiveTestAlgorithm::execute() {
50 ++m_total;
51 int evt = Gaudi::Hive::currentContext().evt();
52
53 info() << ":HiveTestAlgorithm::getting inputs... " << evt << endmsg;
54
55 for ( auto& handle : m_inputHandles ) {
56 auto obj = dynamic_cast<MyObject*>( handle->get() );
57 if ( !obj ) {
58 fatal() << "Unable to dcast inputHandles object" << endmsg;
59 return StatusCode::FAILURE;
60 }
61 info() << "Got data with value " << obj->getData() << endmsg;
62 }
63
64 info() << ":HiveTestAlgorithm::registering outputs... " << evt << endmsg;
65
66 for ( auto& outputHandle : m_outputHandles ) { outputHandle->put( new MyObject( 1000 + evt ) ); }
67
68 return StatusCode::SUCCESS;
69 }
70
71 StatusCode HiveTestAlgorithm::finalize() {
72 info() << name() << ":HiveTestAlgorithm::finalize - total events: " << m_total << endmsg;
73 MyObject::dump();
74 return StatusCode::SUCCESS;
75 }
76
77 const std::vector<std::string> HiveTestAlgorithm::get_inputs() { return m_inputs; }
78
79 const std::vector<std::string> HiveTestAlgorithm::get_outputs() { return m_outputs; }
MyObject::c_instances
static atomic< int > c_instances
Definition: HiveTestAlgorithm.cpp:13
MyObject::~MyObject
~MyObject()
Definition: HiveTestAlgorithm.cpp:19
std::atomic< int >
MyObject::MyObject
MyObject(const MyObject &o)
Definition: HiveTestAlgorithm.cpp:18
EventContext::evt
ContextEvt_t evt() const
Definition: EventContext.h:40
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
MsgStream.h
HiveTestAlgorithm.h
ThreadLocalContext.h
MyObject::getData
int getData()
Definition: HiveTestAlgorithm.cpp:20
std::to_string
T to_string(T... args)
std::endl
T endl(T... args)
HiveTestAlgorithm::get_outputs
virtual const std::vector< std::string > get_outputs()
Definition: HiveTestAlgorithm.cpp:79
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std
STL namespace.
MyObject::dump
static void dump()
Definition: HiveTestAlgorithm.cpp:21
MyObject
Definition: HiveTestAlgorithm.cpp:11
MyObject::d_instances
static atomic< int > d_instances
Definition: HiveTestAlgorithm.cpp:14
Gaudi::DataHandle::Reader
Definition: DataHandle.h:29
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
DataObjectHandle< DataObject >
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
MyObject::m_data
int m_data
Definition: HiveTestAlgorithm.cpp:12
Gaudi::Hive::currentContext
GAUDI_API const EventContext & currentContext()
Definition: ThreadLocalContext.cpp:20
HiveTestAlgorithm::initialize
StatusCode initialize() override
Definition: HiveTestAlgorithm.cpp:27
std::vector< std::string >
HiveTestAlgorithm::get_inputs
virtual const std::vector< std::string > get_inputs()
Definition: HiveTestAlgorithm.cpp:77
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
Gaudi::DataHandle::Writer
Definition: DataHandle.h:29
HiveTestAlgorithm::execute
StatusCode execute() override
Definition: HiveTestAlgorithm.cpp:49
HiveTestAlgorithm::finalize
StatusCode finalize() override
Definition: HiveTestAlgorithm.cpp:71
MyObject::MyObject
MyObject(int d)
Definition: HiveTestAlgorithm.cpp:17
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
std::cout
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
IOTest.evt
evt
Definition: IOTest.py:94