The Gaudi Framework  master (37c0b60a)
HiveTestAlgorithm.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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>
14 
15 #include <atomic>
16 
17 DECLARE_COMPONENT( HiveTestAlgorithm )
18 
19 using namespace std;
20 
21 class MyObject : public DataObject {
22  int m_data;
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() { return m_data; }
31  static void dump() { cout << "MyObject (C/D): " << c_instances << "/" << d_instances << endl; }
32 };
33 
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 
57  return StatusCode::SUCCESS;
58 }
59 
61  ++m_total;
63 
64  info() << ":HiveTestAlgorithm::getting inputs... " << evt << endmsg;
65 
66  for ( auto& handle : m_inputHandles ) {
67  auto obj = dynamic_cast<MyObject*>( 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 
83  info() << name() << ":HiveTestAlgorithm::finalize - total events: " << m_total << endmsg;
85  return StatusCode::SUCCESS;
86 }
87 
89 
IOTest.evt
evt
Definition: IOTest.py:107
HiveTestAlgorithm::get_outputs
virtual const std::vector< std::string > get_outputs()
Definition: HiveTestAlgorithm.cpp:90
MyObject::d_instances
static atomic< int > d_instances
Definition: HiveTestAlgorithm.cpp:24
Gaudi::Hive::currentContext
GAUDI_API const EventContext & currentContext()
Definition: ThreadLocalContext.cpp:30
HiveTestAlgorithm::initialize
StatusCode initialize() override
Definition: HiveTestAlgorithm.cpp:37
std::vector< std::string >
MyObject::m_data
int m_data
Definition: HiveTestAlgorithm.cpp:22
HiveTestAlgorithm.h
DataObjectHandle< DataObject >
Gaudi::DataHandle::Writer
@ Writer
Definition: DataHandle.h:40
MyObject::c_instances
static atomic< int > c_instances
Definition: HiveTestAlgorithm.cpp:23
StatusCode
Definition: StatusCode.h:65
HiveTestAlgorithm::get_inputs
virtual const std::vector< std::string > get_inputs()
Definition: HiveTestAlgorithm.cpp:88
MyObject::getData
int getData()
Definition: HiveTestAlgorithm.cpp:30
std::cout
std::to_string
T to_string(T... args)
MyObject::MyObject
MyObject(int d)
Definition: HiveTestAlgorithm.cpp:27
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
std::atomic< int >
MyObject::dump
static void dump()
Definition: HiveTestAlgorithm.cpp:31
HiveTestAlgorithm::finalize
StatusCode finalize() override
Definition: HiveTestAlgorithm.cpp:82
ThreadLocalContext.h
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
std::endl
T endl(T... args)
MyObject
Definition: HiveTestAlgorithm.cpp:21
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
HiveTestAlgorithm::execute
StatusCode execute() override
Definition: HiveTestAlgorithm.cpp:60
DataObject
Definition: DataObject.h:36
MyObject::~MyObject
~MyObject()
Definition: HiveTestAlgorithm.cpp:29
Gaudi::DataHandle::Reader
@ Reader
Definition: DataHandle.h:40
MyObject::MyObject
MyObject(const MyObject &o)
Definition: HiveTestAlgorithm.cpp:28
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
EventContext::evt
ContextEvt_t evt() const
Definition: EventContext.h:50
MsgStream.h