The Gaudi Framework  v29r0 (ff2e7097)
HiveTestAlgorithm.cpp
Go to the documentation of this file.
5 
6 #include <atomic>
7 
8 DECLARE_ALGORITHM_FACTORY( HiveTestAlgorithm )
9 
10 using namespace std;
11 
13 {
14  int m_data;
17 
18 public:
19  MyObject( int d ) : m_data( d ) { c_instances++; }
20  MyObject( const MyObject& o ) : DataObject(), m_data( o.m_data ) { c_instances++; }
21  ~MyObject() { d_instances++; }
22  int getData() { return m_data; }
23  static void dump() { cout << "MyObject (C/D): " << c_instances << "/" << d_instances << endl; }
24 };
25 
28 
30 {
31  info() << ":HiveTestAlgorithm::initialize " << endmsg;
32 
33  int i = 0;
34  for ( auto k : m_inputs ) {
35  debug() << "adding input key " << k << endmsg;
36  m_inputHandles.push_back( new DataObjectHandle<DataObject>( k, Gaudi::DataHandle::Reader, this ) );
37  declareProperty( "dummy_in_" + std::to_string( i ), *( m_inputHandles.back() ) );
38  i++;
39  }
40 
41  i = 0;
42  for ( auto k : m_outputs ) {
43  debug() << "adding output key " << k << endmsg;
44  m_outputHandles.push_back( new DataObjectHandle<DataObject>( k, Gaudi::DataHandle::Writer, this ) );
45  declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
46  i++;
47  }
48 
49  return StatusCode::SUCCESS;
50 }
51 
53 {
54  ++m_total;
56 
57  info() << ":HiveTestAlgorithm::getting inputs... " << evt << endmsg;
58 
59  for ( auto& handle : m_inputHandles ) {
60  auto obj = dynamic_cast<MyObject*>( handle->get() );
61  if ( !obj ) {
62  fatal() << "Unable to dcast inputHandles object" << endmsg;
63  return StatusCode::FAILURE;
64  }
65  info() << "Got data with value " << obj->getData() << endmsg;
66  }
67 
68  info() << ":HiveTestAlgorithm::registering outputs... " << evt << endmsg;
69 
70  for ( auto& outputHandle : m_outputHandles ) {
71  outputHandle->put( new MyObject( 1000 + evt ) );
72  }
73 
74  return StatusCode::SUCCESS;
75 }
76 
78 {
79  info() << name() << ":HiveTestAlgorithm::finalize - total events: " << m_total << endmsg;
81  return StatusCode::SUCCESS;
82 }
83 
85 
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()
STL namespace.
static void dump()
#define class
static atomic< int > d_instances
ContextEvt_t evt() const
Definition: EventContext.h:39
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, TYPE &value, const std::string &doc="none")
Declare a property (templated)
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:629
GAUDI_API const EventContext & currentContext()
StatusCode initialize() override
std::vector< InputHandle_t< In > > m_inputs
virtual const std::vector< std::string > get_inputs()
StatusCode execute() override
StatusCode finalize() override
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:29
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
evt
Definition: IOTest.py:96