The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
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
15
16// Example related include files
17#include "MIHelpers.h"
18#include "MIReadAlg.h"
19
20// Event Model related classes
23
24#include <GaudiKernel/System.h>
25
26#include <fstream>
27
28using namespace Gaudi::TestSuite::MultiInput;
29
31
32//--------------------------------------------------------------------
33// Initialize
34//--------------------------------------------------------------------
36 StatusCode sc = Algorithm::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
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
90}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition Algorithm.h:175
Gaudi::Property< std::string > m_addressfile
Definition MIReadAlg.h:33
std::vector< RootAddressArgs > m_addresses
Address details for the data to be added to the main event.
Definition MIReadAlg.h:36
StatusCode registerObject(std::string_view fullPath, DataObject *pObject)
Register object with the data store.
ReadAlg class for the RootIOExample.
Definition ReadAlg.h:27
StatusCode execute() override
Event callback.
Definition ReadAlg.cpp:113
StatusCode initialize() override
Initialize.
Definition ReadAlg.cpp:48
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto SUCCESS
Definition StatusCode.h:99
Gaudi::RootAddress * make_address(RootAddressArgs args)
Definition MIHelpers.h:36
std::tuple< long, CLID, std::string, std::string, unsigned long, unsigned long > RootAddressArgs
Definition MIHelpers.h:26
@ DEBUG
Definition IMessageSvc.h:22