The Gaudi Framework  master (ff829712)
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"
14
15#include <atomic>
16
18
19using namespace std;
20
21class MyObject : public DataObject {
22 int m_data;
23 static atomic<int> c_instances;
24 static atomic<int> d_instances;
25
26public:
27 MyObject( int d ) : m_data( d ) { c_instances++; }
28 MyObject( const MyObject& o ) : DataObject(), m_data( o.m_data ) { c_instances++; }
30 int getData() const { return m_data; }
31 static void dump() { cout << "MyObject (C/D): " << c_instances << "/" << d_instances << endl; }
32};
33
34atomic<int> MyObject::c_instances;
35atomic<int> MyObject::d_instances;
36
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
58}
59
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;
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
80}
81
83 info() << name() << ":HiveTestAlgorithm::finalize - total events: " << m_total << endmsg;
86}
87
88const std::vector<std::string> HiveTestAlgorithm::get_inputs() { return m_inputs; }
89
90const std::vector<std::string> HiveTestAlgorithm::get_outputs() { return m_outputs; }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
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
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.
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.