The Gaudi Framework  master (37c0b60a)
MIReadAlg.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 // Framework include files
13 #include <GaudiKernel/MsgStream.h>
15 
16 // Example related include files
17 #include "MIHelpers.h"
18 #include "MIReadAlg.h"
19 
20 // Event Model related classes
21 #include <GaudiTestSuite/Event.h>
22 #include <GaudiTestSuite/MyTrack.h>
23 
24 #include <GaudiKernel/System.h>
25 
26 #include <fstream>
27 
28 using namespace Gaudi::TestSuite::MultiInput;
29 
31 
32 //--------------------------------------------------------------------
33 // Initialize
34 //--------------------------------------------------------------------
35 StatusCode ReadAlg::initialize() {
37  if ( sc.isFailure() ) return sc;
38 
39  if ( msgLevel( MSG::DEBUG ) ) debug() << "Reading " << m_addressfile.value() << endmsg;
40  m_addresses.clear();
41  std::ifstream input{ m_addressfile };
42  while ( input.good() ) {
43  RootAddressArgs addr;
44  input >> addr;
45  if ( input.eof() ) break;
46  m_addresses.push_back( addr );
47  }
48  if ( msgLevel( MSG::DEBUG ) ) debug() << "Read " << m_addresses.size() << " addresses" << endmsg;
49 
50  m_count = 0;
51 
52  return StatusCode::SUCCESS;
53 }
54 
55 //--------------------------------------------------------------------
56 // Execute
57 //--------------------------------------------------------------------
59 
60  if ( m_count < m_addresses.size() ) {
61  // register the entry "Extra/Tracks" in the TES so that it is loaded
62  // from the other file
63  StatusCode sc = eventSvc()->registerObject( "Extra", new DataObject );
64  if ( sc.isFailure() ) {
65  error() << "Cannot add entry 'Extra' to the TES" << endmsg;
66  return sc;
67  }
68  sc =
69  SmartIF<IDataManagerSvc>( eventSvc() )->registerAddress( "Extra/Tracks", make_address( m_addresses[m_count] ) );
70  if ( sc.isFailure() ) {
71  error() << "Failed to register the address to the extra data" << endmsg;
72  return sc;
73  }
74  ++m_count;
75  }
76 
77  SmartDataPtr<MyTrackVector> trks1( eventSvc(), "Tracks" );
78  SmartDataPtr<MyTrackVector> trks2( eventSvc(), "Extra/Tracks" );
79 
80  if ( trks1 )
81  info() << "Base event tracks: " << trks1->size() << endmsg;
82  else
83  warning() << "No tracks container in base event" << endmsg;
84  if ( trks2 )
85  info() << "Extra event tracks: " << trks2->size() << endmsg;
86  else
87  warning() << "No tracks container in extra event" << endmsg;
88 
89  return StatusCode::SUCCESS;
90 }
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
Event.h
MIHelpers.h
MIReadAlg.h
MyTrack.h
Gaudi::Algorithm::eventSvc
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
Definition: Algorithm.cpp:559
System.h
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:178
std::tuple
Gaudi::TestSuite::MultiInput::ReadAlg::m_count
size_t m_count
Definition: MIReadAlg.h:38
StatusCode
Definition: StatusCode.h:65
SmartDataPtr.h
Gaudi::TestSuite::MultiInput::ReadAlg::execute
StatusCode execute() override
Event callback.
Definition: MIReadAlg.cpp:58
Gaudi::TestSuite::MultiInput
Definition: DumpAddress.cpp:26
SmartIF< IDataManagerSvc >
MsgStream::clear
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:181
Gaudi::TestSuite::MultiInput::ReadAlg::m_addresses
std::vector< RootAddressArgs > m_addresses
Address details for the data to be added to the main event.
Definition: MIReadAlg.h:37
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
Gaudi::TestSuite::MultiInput::make_address
Gaudi::RootAddress * make_address(RootAddressArgs args)
Definition: MIHelpers.h:37
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
SmartDataPtr
A small class used to access easily (and efficiently) data items residing in data stores.
Definition: SmartDataPtr.h:57
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
DataObject
Definition: DataObject.h:36
IDataManagerSvc.h
MsgStream.h
Gaudi::TestSuite::MultiInput::ReadAlg
Simple algorithm used to read data from two files.
Definition: MIReadAlg.h:25
std::ifstream
STL class.