Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HiveTestAlgorithm.cpp
Go to the documentation of this file.
4 
5 #include <atomic>
6 
7 DECLARE_COMPONENT( HiveTestAlgorithm )
8 
9 using namespace std;
10 
12  int m_data;
15 
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 
26 
28  info() << ":HiveTestAlgorithm::initialize " << endmsg;
29 
30  int i = 0;
31  for ( auto k : m_inputs ) {
32  debug() << "adding input key " << k << endmsg;
33  m_inputHandles.push_back( new DataObjectHandle<DataObject>( k, Gaudi::DataHandle::Reader, this ) );
34  declareProperty( "dummy_in_" + std::to_string( i ), *( m_inputHandles.back() ) );
35  i++;
36  }
37 
38  i = 0;
39  for ( auto k : m_outputs ) {
40  debug() << "adding output key " << k << endmsg;
41  m_outputHandles.push_back( new DataObjectHandle<DataObject>( k, Gaudi::DataHandle::Writer, this ) );
42  declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
43  i++;
44  }
45 
46  return StatusCode::SUCCESS;
47 }
48 
50  ++m_total;
52 
53  info() << ":HiveTestAlgorithm::getting inputs... " << evt << endmsg;
54 
55  for ( auto& handle : m_inputHandles ) {
56  auto obj = dynamic_cast<MyObject*>( handle->get() );
57  if ( !obj ) {
58  fatal() << "Unable to dcast inputHandles object" << endmsg;
59  return StatusCode::FAILURE;
60  }
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 
72  info() << name() << ":HiveTestAlgorithm::finalize - total events: " << m_total << endmsg;
74  return StatusCode::SUCCESS;
75 }
76 
78 
static atomic< int > c_instances
MyObject(const MyObject &o)
T to_string(T...args)
T endl(T...args)
virtual const std::vector< std::string > get_outputs()
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
STL namespace.
static void dump()
#define class
static atomic< int > d_instances
ContextEvt_t evt() const
Definition: EventContext.h:47
#define DECLARE_COMPONENT(type)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, TYPE &value, const std::string &doc="none")
Declare a property (templated)
GAUDI_API const EventContext & currentContext()
StatusCode initialize() override
std::vector< InputHandle_t< In > > m_inputs
virtual const std::vector< std::string > get_inputs()
constexpr static const auto FAILURE
Definition: StatusCode.h:86
StatusCode execute() override
standard execution method
StatusCode finalize() override
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
evt
Definition: IOTest.py:94