The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
HiveTestAlgorithm.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#include "
HiveTestAlgorithm.h
"
12
#include <
GaudiKernel/MsgStream.h
>
13
#include <
GaudiKernel/ThreadLocalContext.h
>
14
15
#include <atomic>
16
17
DECLARE_COMPONENT
(
HiveTestAlgorithm
)
18
19
using namespace
std
;
20
21
class
MyObject
:
public
DataObject
{
22
int
m_data
;
23
static
atomic<int>
c_instances
;
24
static
atomic<int>
d_instances
;
25
26
public
:
27
MyObject
(
int
d ) :
m_data
( d ) {
c_instances
++; }
28
MyObject
(
const
MyObject
& o ) :
DataObject
(),
m_data
( o.
m_data
) {
c_instances
++; }
29
~MyObject
() {
d_instances
++; }
30
int
getData
()
const
{
return
m_data
; }
31
static
void
dump
() { cout <<
"MyObject (C/D): "
<<
c_instances
<<
"/"
<<
d_instances
<< endl; }
32
};
33
34
atomic<int>
MyObject::c_instances
;
35
atomic<int>
MyObject::d_instances
;
36
37
StatusCode
HiveTestAlgorithm::initialize
() {
38
info
() <<
":HiveTestAlgorithm::initialize "
<<
endmsg
;
39
40
int
i = 0;
41
for
(
auto
k :
m_inputs
) {
42
debug
() <<
"adding input key "
<< k <<
endmsg
;
43
m_inputHandles
.emplace_back( std::make_unique<
DataObjectHandle<DataObject>
>( k,
Gaudi::DataHandle::Reader
,
this
) );
44
declareProperty
(
"dummy_in_"
+ std::to_string( i ), *(
m_inputHandles
.back() ) );
45
i++;
46
}
47
48
i = 0;
49
for
(
auto
k :
m_outputs
) {
50
debug
() <<
"adding output key "
<< k <<
endmsg
;
51
m_outputHandles
.emplace_back(
52
std::make_unique<
DataObjectHandle<DataObject>
>( k,
Gaudi::DataHandle::Writer
,
this
) );
53
declareProperty
(
"dummy_out_"
+ std::to_string( i ), *(
m_outputHandles
.back() ) );
54
i++;
55
}
56
57
return
StatusCode::SUCCESS
;
58
}
59
60
StatusCode
HiveTestAlgorithm::execute
() {
61
++
m_total
;
62
int
evt =
Gaudi::Hive::currentContext
().
evt
();
63
64
info
() <<
":HiveTestAlgorithm::getting inputs... "
<< evt <<
endmsg
;
65
66
for
(
auto
& handle :
m_inputHandles
) {
67
auto
obj =
dynamic_cast<
MyObject
const*
>
( handle->get() );
68
if
( !obj ) {
69
fatal
() <<
"Unable to dcast inputHandles object"
<<
endmsg
;
70
return
StatusCode::FAILURE
;
71
}
72
info
() <<
"Got data with value "
<< obj->getData() <<
endmsg
;
73
}
74
75
info
() <<
":HiveTestAlgorithm::registering outputs... "
<< evt <<
endmsg
;
76
77
for
(
auto
& outputHandle :
m_outputHandles
) { outputHandle->put( std::make_unique<MyObject>( 1000 + evt ) ); }
78
79
return
StatusCode::SUCCESS
;
80
}
81
82
StatusCode
HiveTestAlgorithm::finalize
() {
83
info
() <<
name
() <<
":HiveTestAlgorithm::finalize - total events: "
<<
m_total
<<
endmsg
;
84
MyObject::dump
();
85
return
StatusCode::SUCCESS
;
86
}
87
88
const
std::vector<std::string>
HiveTestAlgorithm::get_inputs
() {
return
m_inputs
; }
89
90
const
std::vector<std::string>
HiveTestAlgorithm::get_outputs
() {
return
m_outputs
; }
HiveTestAlgorithm.h
MsgStream.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
ThreadLocalContext.h
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition
CommonMessaging.h:103
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition
CommonMessaging.h:118
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition
CommonMessaging.h:115
DataObjectHandle
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
Definition
DataObjectHandle.h:110
DataObject::DataObject
DataObject()
Standard Constructor.
Definition
DataObject.cpp:23
EventContext::evt
ContextEvt_t evt() const
Definition
EventContext.h:51
Gaudi::Algorithm::declareProperty
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
Definition
Algorithm.h:286
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition
Algorithm.cpp:518
Gaudi::DataHandle::Reader
@ Reader
Definition
DataHandle.h:45
Gaudi::DataHandle::Writer
@ Writer
Definition
DataHandle.h:45
HiveTestAlgorithm
Definition
HiveTestAlgorithm.h:17
HiveTestAlgorithm::m_outputHandles
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_outputHandles
Definition
HiveTestAlgorithm.h:50
HiveTestAlgorithm::get_outputs
virtual const std::vector< std::string > get_outputs()
Definition
HiveTestAlgorithm.cpp:90
HiveTestAlgorithm::get_inputs
virtual const std::vector< std::string > get_inputs()
Definition
HiveTestAlgorithm.cpp:88
HiveTestAlgorithm::m_inputs
Gaudi::Property< std::vector< std::string > > m_inputs
Definition
HiveTestAlgorithm.h:46
HiveTestAlgorithm::m_inputHandles
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_inputHandles
Definition
HiveTestAlgorithm.h:49
HiveTestAlgorithm::m_total
int m_total
The total events seen.
Definition
HiveTestAlgorithm.h:44
HiveTestAlgorithm::initialize
StatusCode initialize() override
Definition
HiveTestAlgorithm.cpp:37
HiveTestAlgorithm::finalize
StatusCode finalize() override
Definition
HiveTestAlgorithm.cpp:82
HiveTestAlgorithm::m_outputs
Gaudi::Property< std::vector< std::string > > m_outputs
Definition
HiveTestAlgorithm.h:47
HiveTestAlgorithm::execute
StatusCode execute() override
Definition
HiveTestAlgorithm.cpp:60
MyObject
Definition
HiveTestAlgorithm.cpp:21
MyObject::~MyObject
~MyObject()
Definition
HiveTestAlgorithm.cpp:29
MyObject::MyObject
MyObject(int d)
Definition
HiveTestAlgorithm.cpp:27
MyObject::m_data
int m_data
Definition
HiveTestAlgorithm.cpp:22
MyObject::getData
int getData() const
Definition
HiveTestAlgorithm.cpp:30
MyObject::dump
static void dump()
Definition
HiveTestAlgorithm.cpp:31
MyObject::MyObject
MyObject(const MyObject &o)
Definition
HiveTestAlgorithm.cpp:28
MyObject::c_instances
static atomic< int > c_instances
Definition
HiveTestAlgorithm.cpp:23
MyObject::d_instances
static atomic< int > d_instances
Definition
HiveTestAlgorithm.cpp:24
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
Gaudi::Hive::currentContext
GAUDI_API const EventContext & currentContext()
Definition
ThreadLocalContext.cpp:30
std
STL namespace.
GaudiHive
src
HiveTestAlgorithm.cpp
Generated on
for The Gaudi Framework by
1.17.0