The Gaudi Framework master (934d2c3c)
Loading...
Searching...
No Matches
HiveTestAlgorithm.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 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
12// Framework includes
13#include <Gaudi/Property.h>
18
19// STL includes
20#include <atomic>
21#include <memory>
22#include <string>
23#include <vector>
24
26public:
31
32 /*****************************
33 ** Public Function Members **
34 *****************************/
35
36 StatusCode initialize() override;
37 StatusCode execute() override;
38 StatusCode finalize() override;
39
40 // BH: concurrency additions
43
44private:
45 /**************************
46 ** Private Data Members **
47 **************************/
48
52 int m_total = 0;
53
54 Gaudi::Property<std::vector<std::string>> m_inputs{ this, "Input", {}, "List of required inputs" };
55 Gaudi::Property<std::vector<std::string>> m_outputs{ this, "Output", {}, "List of provided outputs" };
56
59};
60
62
63using namespace std;
64
65class MyObject : public DataObject {
66 int m_data;
69
70public:
71 MyObject( int d ) : m_data( d ) { c_instances++; }
72 MyObject( const MyObject& o ) : DataObject(), m_data( o.m_data ) { c_instances++; }
74 int getData() const { return m_data; }
75 static void dump() { cout << "MyObject (C/D): " << c_instances << "/" << d_instances << endl; }
76};
77
80
82 info() << ":HiveTestAlgorithm::initialize " << endmsg;
83
84 int i = 0;
85 for ( auto k : m_inputs ) {
86 debug() << "adding input key " << k << endmsg;
87 m_inputHandles.emplace_back( std::make_unique<DataObjectHandle<DataObject>>( k, Gaudi::DataHandle::Reader, this ) );
88 declareProperty( "dummy_in_" + std::to_string( i ), *( m_inputHandles.back() ) );
89 i++;
90 }
91
92 i = 0;
93 for ( auto k : m_outputs ) {
94 debug() << "adding output key " << k << endmsg;
95 m_outputHandles.emplace_back(
96 std::make_unique<DataObjectHandle<DataObject>>( k, Gaudi::DataHandle::Writer, this ) );
97 declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
98 i++;
99 }
100
101 return StatusCode::SUCCESS;
102}
103
105 ++m_total;
106 int evt = Gaudi::Hive::currentContext().evt();
107
108 info() << ":HiveTestAlgorithm::getting inputs... " << evt << endmsg;
109
110 for ( auto& handle : m_inputHandles ) {
111 auto obj = dynamic_cast<MyObject const*>( handle->get() );
112 if ( !obj ) {
113 fatal() << "Unable to dcast inputHandles object" << endmsg;
114 return StatusCode::FAILURE;
115 }
116 info() << "Got data with value " << obj->getData() << endmsg;
117 }
118
119 info() << ":HiveTestAlgorithm::registering outputs... " << evt << endmsg;
120
121 for ( auto& outputHandle : m_outputHandles ) { outputHandle->put( std::make_unique<MyObject>( 1000 + evt ) ); }
122
123 return StatusCode::SUCCESS;
124}
125
127 info() << name() << ":HiveTestAlgorithm::finalize - total events: " << m_total << endmsg;
129 return StatusCode::SUCCESS;
130}
131
133
#define GAUDI_API
Definition Kernel.h:49
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
ostream cout
constexpr const_reference back() const noexcept
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
DataObject()
Standard Constructor.
ContextEvt_t evt() const
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition Algorithm.h:98
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
Definition Algorithm.h:286
const std::string & name() const override
The identifying name of the algorithm object.
Implementation of property with value of concrete type.
Definition Property.h:35
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_outputHandles
virtual const std::vector< std::string > get_outputs()
virtual const std::vector< std::string > get_inputs()
Gaudi::Property< std::vector< std::string > > m_inputs
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_inputHandles
int m_total
The total events seen.
StatusCode initialize() override
StatusCode finalize() override
Gaudi::Property< std::vector< std::string > > m_outputs
StatusCode execute() override
int getData() const
static void dump()
MyObject(const MyObject &o)
static atomic< int > c_instances
static atomic< int > d_instances
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
GAUDI_API const EventContext & currentContext()
STL namespace.