| The Gaudi Framework v30r0 (c919700c)

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

- File List
- File Members

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_ALGORITHM_FACTORY( HiveTestAlgorithm )
8
9 using namespace std;
10
11 class MyObject : public DataObject
12 {
13 int m_data;
14 static atomic<int> c_instances;
15 static atomic<int> d_instances;
16
17 public:
18 MyObject( int d ) : m_data( d ) { c_instances++; }
19 MyObject( const MyObject& o ) : DataObject(), m_data( o.m_data ) { c_instances++; }
20 ~MyObject() { d_instances++; }
21 int getData() { return m_data; }
22 static void dump() { cout << "MyObject (C/D): " << c_instances << "/" << d_instances << endl; }
23 };
24
25 atomic<int> MyObject::c_instances;
26 atomic<int> MyObject::d_instances;
27
28 StatusCode HiveTestAlgorithm::initialize()
29 {
30 info() << ":HiveTestAlgorithm::initialize " << endmsg;
31
32 int i = 0;
33 for ( auto k : m_inputs ) {
34 debug() << "adding input key " << k << endmsg;
35 m_inputHandles.push_back( new DataObjectHandle<DataObject>( k, Gaudi::DataHandle::Reader, this ) );
36 declareProperty( "dummy_in_" + std::to_string( i ), *( m_inputHandles.back() ) );
37 i++;
38 }
39
40 i = 0;
41 for ( auto k : m_outputs ) {
42 debug() << "adding output key " << k << endmsg;
43 m_outputHandles.push_back( new DataObjectHandle<DataObject>( k, Gaudi::DataHandle::Writer, this ) );
44 declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
45 i++;
46 }
47
48 return StatusCode::SUCCESS;
49 }
50
51 StatusCode HiveTestAlgorithm::execute()
52 {
53 ++m_total;
54 int evt = Gaudi::Hive::currentContext().evt();
55
56 info() << ":HiveTestAlgorithm::getting inputs... " << evt << endmsg;
57
58 for ( auto& handle : m_inputHandles ) {
59 auto obj = dynamic_cast<MyObject*>( handle->get() );
60 if ( !obj ) {
61 fatal() << "Unable to dcast inputHandles object" << endmsg;
62 return StatusCode::FAILURE;
63 }
64 info() << "Got data with value " << obj->getData() << endmsg;
65 }
66
67 info() << ":HiveTestAlgorithm::registering outputs... " << evt << endmsg;
68
69 for ( auto& outputHandle : m_outputHandles ) {
70 outputHandle->put( new MyObject( 1000 + evt ) );
71 }
72
73 return StatusCode::SUCCESS;
74 }
75
76 StatusCode HiveTestAlgorithm::finalize()
77 {
78 info() << name() << ":HiveTestAlgorithm::finalize - total events: " << m_total << endmsg;
79 MyObject::dump();
80 return StatusCode::SUCCESS;
81 }
82
83 const std::vector<std::string> HiveTestAlgorithm::get_inputs() { return m_inputs; }
84
85 const std::vector<std::string> HiveTestAlgorithm::get_outputs() { return m_outputs; }
MyObject::c_instances
static atomic< int > c_instances
Definition: HiveTestAlgorithm.cpp:14
StatusCode::SUCCESS
Definition: StatusCode.h:29
MyObject::~MyObject
~MyObject()
Definition: HiveTestAlgorithm.cpp:20
std::atomic< int >
MyObject::MyObject
MyObject(const MyObject &o)
Definition: HiveTestAlgorithm.cpp:19
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
MsgStream.h
HiveTestAlgorithm.h
ThreadLocalContext.h
MyObject::getData
int getData()
Definition: HiveTestAlgorithm.cpp:21
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:85
std
STL namespace.
MyObject::dump
static void dump()
Definition: HiveTestAlgorithm.cpp:22
class
#define class
Definition: HistogramPersistencySvc.cpp:45
MyObject
Definition: HiveTestAlgorithm.cpp:11
MyObject::d_instances
static atomic< int > d_instances
Definition: HiveTestAlgorithm.cpp:15
Gaudi::DataHandle::Reader
Definition: DataHandle.h:31
EventContext::evt
ContextEvt_t evt() const
Definition: EventContext.h:39
DataObjectHandle< DataObject >
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
declareProperty
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, TYPE &value, const std::string &doc="none")
Declare a property (templated)
DECLARE_ALGORITHM_FACTORY
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:631
MyObject::m_data
int m_data
Definition: HiveTestAlgorithm.cpp:13
Gaudi::Hive::currentContext
GAUDI_API const EventContext & currentContext()
Definition: ThreadLocalContext.cpp:24
HiveTestAlgorithm::initialize
StatusCode initialize() override
Definition: HiveTestAlgorithm.cpp:28
Gaudi::Functional::m_inputs
std::vector< InputHandle_t< In > > m_inputs
Definition: MergingTransformer.h:45
std::vector< std::string >
HiveTestAlgorithm::get_inputs
virtual const std::vector< std::string > get_inputs()
Definition: HiveTestAlgorithm.cpp:83
Gaudi::DataHandle::Writer
Definition: DataHandle.h:31
HiveTestAlgorithm::execute
StatusCode execute() override
Definition: HiveTestAlgorithm.cpp:51
HiveTestAlgorithm::finalize
StatusCode finalize() override
Definition: HiveTestAlgorithm.cpp:76
MyObject::MyObject
MyObject(int d)
Definition: HiveTestAlgorithm.cpp:18
StatusCode::FAILURE
Definition: StatusCode.h:29
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:209
IOTest.evt
evt
Definition: IOTest.py:96