The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
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;
43 return *this;
44}
45
46//---------------------------------------------------------------------------
51
52//---------------------------------------------------------------------------
53
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
104std::ostream& operator<<( std::ostream& str, const DataObjectHandleBase& d ) {
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}
const DataObjID INVALID_DATAOBJID
std::ostream & operator<<(std::ostream &str, const DataObjectHandleBase &d)
Provide serialization function (output only) for some common STL classes (vectors,...
Base class from which all the concrete tool classes should be derived.
Definition AlgTool.h:55
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
SmartIF< IDataProviderSvc > m_EDS
SmartIF< IMessageSvc > m_MS
bool isOptional() const
Check if the data object declared is optional for the algorithm.
DataObjectHandleBase(DataObjID k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
DataObject * fetch() const
DataObjectHandleBase & operator=(const DataObjectHandleBase &)
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:87
SmartIF< IDataProviderSvc > & evtSvc() const
shortcut for method eventSvc
Definition Algorithm.h:233
IDataHandleHolder * m_owner
Definition DataHandle.h:80
virtual IDataHandleHolder * owner() const
Definition DataHandle.h:52
virtual const std::string & objKey() const
Definition DataHandle.h:59
virtual Mode mode() const
Definition DataHandle.h:54
virtual const DataObjID & fullKey() const
Definition DataHandle.h:60
DataHandle(DataObjID k, Mode a=Reader, IDataHandleHolder *owner=nullptr)
Definition DataHandle.h:41
Define general base for Gaudi exception.
virtual void renounce(Gaudi::DataHandle &)=0
virtual const std::string & name() const =0
Retrieve the name of the instance.
constexpr static const auto FAILURE
Definition StatusCode.h:100
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
STL namespace.