| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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/AlgFactory.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 int m_data;
14 static atomic<int> c_instances;
15 static atomic<int> d_instances;
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
28 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
52 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 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
72 HiveTestAlgorithm::finalize()
73 {
74 info() << name() << ":HiveTestAlgorithm::finalize - total events: " << m_total << endmsg;
75 MyObject::dump();
76 return StatusCode::SUCCESS;
77 }
78
79 const std::vector<std::string> HiveTestAlgorithm::get_inputs()
80 {
81 return m_inputs;
82 }
83
84 const std::vector<std::string> HiveTestAlgorithm::get_outputs()
85 {
86 return m_outputs;
87 }
MyObject::c_instances
static atomic< int > c_instances
Definition: HiveTestAlgorithm.cpp:14
StatusCode::SUCCESS
Definition: StatusCode.h:30
MyObject::~MyObject
~MyObject()
Definition: HiveTestAlgorithm.cpp:19
std::atomic< int >
MyObject::MyObject
MyObject(const MyObject &o)
Definition: HiveTestAlgorithm.cpp:18
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
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:84
std
STL namespace.
MyObject::dump
static void dump()
Definition: HiveTestAlgorithm.cpp:21
class
#define class
Definition: HistogramPersistencySvc.cpp:45
MyObject
Definition: HiveTestAlgorithm.cpp:12
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:40
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:620
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:39
std::vector< std::string >
HiveTestAlgorithm::get_inputs
virtual const std::vector< std::string > get_inputs()
Definition: HiveTestAlgorithm.cpp:79
Gaudi::DataHandle::Writer
Definition: DataHandle.h:32
HiveTestAlgorithm::execute
StatusCode execute() override
Definition: HiveTestAlgorithm.cpp:52
HiveTestAlgorithm::finalize
StatusCode finalize() override
Definition: HiveTestAlgorithm.cpp:72
MyObject::MyObject
MyObject(int d)
Definition: HiveTestAlgorithm.cpp:17
AlgFactory.h
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:244
IOTest.evt
evt
Definition: IOTest.py:85