The Gaudi Framework  master (37c0b60a)
DataObjectHandleBase.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 <Gaudi/Algorithm.h>
12 #include <GaudiKernel/AlgTool.h>
17 
18 #include <boost/tokenizer.hpp>
19 #include <ostream>
20 #include <sstream>
21 #include <string>
22 
24 
25 //---------------------------------------------------------------------------
27  : Gaudi::DataHandle( other )
28  , m_EDS( std::move( other.m_EDS ) )
29  , m_MS( std::move( other.m_MS ) )
30  , m_init( other.m_init )
31  , m_optional( other.m_optional ) {
32  m_owner->declare( *this );
33 }
34 
35 //---------------------------------------------------------------------------
37  // FIXME: operator= should not change our owner, only our 'value'
38  Gaudi::DataHandle::operator=( other );
39  m_EDS = other.m_EDS;
40  m_MS = other.m_MS;
41  m_init = other.m_init;
42  m_optional = other.m_optional;
43  return *this;
44 }
45 
46 //---------------------------------------------------------------------------
48  : Gaudi::DataHandle( std::move( k ), a, owner ) {
49  m_owner->declare( *this );
50 }
51 
52 //---------------------------------------------------------------------------
53 
55  : DataObjectHandleBase( DataObjID{ std::move( k ) }, a, owner ) {}
56 
57 //---------------------------------------------------------------------------
59 
60 //---------------------------------------------------------------------------
62  // convenience towards users -- remind them to register
63  // but as m_MS is not yet set, we cannot use a MsgStream...
64  if ( !m_init ) {
65  std::cerr << ( owner() ? owner()->name() : "<UNKNOWN>:" ) << "DataObjectHandle: uninitialized data handle"
66  << std::endl;
67  }
68  DataObject* p = nullptr;
69  m_EDS->retrieveObject( objKey(), p ).ignore();
70  return p;
71 }
72 
73 //---------------------------------------------------------------------------
74 
76  if ( m_init ) return true; // initialization already done
77 
78  if ( !owner() ) return false;
79 
80  Gaudi::Algorithm* algorithm = dynamic_cast<Gaudi::Algorithm*>( owner() );
81  if ( algorithm ) {
82  // Fetch the event Data Service from the algorithm
83  m_EDS = algorithm->evtSvc();
84  m_MS = algorithm->msgSvc();
85  } else {
86  AlgTool* tool = dynamic_cast<AlgTool*>( owner() );
87  if ( tool ) {
88  m_EDS = tool->evtSvc();
89  m_MS = tool->msgSvc();
90  } else {
91  throw GaudiException( "owner is neither AlgTool nor Gaudi::Algorithm", "Invalid Cast", StatusCode::FAILURE );
92  }
93  }
94  m_init = true;
95  return true;
96 }
97 
98 //---------------------------------------------------------------------------
99 
101 
102 //---------------------------------------------------------------------------
103 
105 
106  str << d.fullKey() << " m: " << d.mode();
107  if ( d.owner() ) str << " o: " << d.owner()->name();
108  str << " opt: " << d.isOptional();
109  return str;
110 }
IDataHandleHolder
Definition: IDataHandleHolder.h:24
std::string
STL class.
std::move
T move(T... args)
DataObjectHandleBase::m_EDS
SmartIF< IDataProviderSvc > m_EDS
Definition: DataObjectHandleBase.h:70
DataObjectHandleBase::m_MS
SmartIF< IMessageSvc > m_MS
Definition: DataObjectHandleBase.h:71
operator<<
std::ostream & operator<<(std::ostream &str, const DataObjectHandleBase &d)
Definition: DataObjectHandleBase.cpp:104
GaudiException
Definition: GaudiException.h:31
DataObjectHandleBase::m_optional
bool m_optional
Definition: DataObjectHandleBase.h:74
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
DataObjectHandleBase::operator=
DataObjectHandleBase & operator=(const DataObjectHandleBase &)
Definition: DataObjectHandleBase.cpp:36
IDataProviderSvc.h
DataObjectHandleBase::isOptional
bool isOptional() const
Check if the data object declared is optional for the algorithm.
Definition: DataObjectHandleBase.h:59
IDataHandleHolder::declare
virtual void declare(Gaudi::DataHandle &)=0
bug_34121.tool
tool
Definition: bug_34121.py:18
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:53
DataObjectHandleBase::m_init
bool m_init
Definition: DataObjectHandleBase.h:73
std::cerr
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:90
DataObjectHandleBase
DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.
Definition: DataObjectHandleBase.h:35
IDataHandleHolder::renounce
virtual void renounce(Gaudi::DataHandle &)=0
Algorithm.h
Gaudi::DataHandle::objKey
virtual const std::string & objKey() const
Definition: DataHandle.h:60
Gaudi::DataHandle::m_owner
IDataHandleHolder * m_owner
Definition: DataHandle.h:81
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
DataObjID
Definition: DataObjID.h:47
DataObjectHandleBase::fetch
DataObject * fetch() const
Definition: DataObjectHandleBase.cpp:61
Gaudi::DataHandle::Mode
Mode
Definition: DataHandle.h:40
std::endl
T endl(T... args)
Gaudi::Algorithm::evtSvc
SmartIF< IDataProviderSvc > & evtSvc() const
shortcut for method eventSvc
Definition: Algorithm.h:250
AlgTool
Definition: AlgTool.h:62
ServiceLocatorHelper.h
Gaudi::DataHandle::mode
virtual Mode mode() const
Definition: DataHandle.h:55
std
STL namespace.
DataObjectHandleBase.h
DataObject
Definition: DataObject.h:36
DataObjectHandleBase::~DataObjectHandleBase
~DataObjectHandleBase() override
Definition: DataObjectHandleBase.cpp:58
AlgTool.h
DataObjectHandleBase::DataObjectHandleBase
DataObjectHandleBase(DataObjID k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
Definition: DataObjectHandleBase.cpp:47
SerializeSTL.h
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
INVALID_DATAOBJID
const DataObjID INVALID_DATAOBJID
Definition: DataObjectHandleBase.cpp:23
DataObjectHandleBase::isValid
bool isValid() const
Definition: DataObjectHandleBase.cpp:100
Gaudi::DataHandle::fullKey
virtual const DataObjID & fullKey() const
Definition: DataHandle.h:61
DataObjectHandleBase::init
bool init() override
Definition: DataObjectHandleBase.cpp:75