| The Gaudi Framework v29r1 (5cd95fa2)

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