The Gaudi Framework  master (53dee381)
Loading...
Searching...
No Matches
DataObjectHandleBase.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 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 if ( !m_owner ) {
32 throw GaudiException( "DataObjectHandleBase requires a non-null owner", "Invalid Owner", StatusCode::FAILURE );
33 }
34 m_owner->declare( *this );
35}
36
37//---------------------------------------------------------------------------
39 // FIXME: operator= should not change our owner, only our 'value'
40 Gaudi::DataHandle::operator=( other );
41 m_EDS = other.m_EDS;
42 m_MS = other.m_MS;
43 m_init = other.m_init;
44 return *this;
45}
46
47//---------------------------------------------------------------------------
49 : Gaudi::DataHandle( std::move( k ), a, owner ) {
50 if ( !m_owner ) {
51 throw GaudiException( "DataObjectHandleBase requires a non-null owner", "Invalid Owner", StatusCode::FAILURE );
52 }
53 m_owner->declare( *this );
54}
55
56//---------------------------------------------------------------------------
57
60
61//---------------------------------------------------------------------------
63 // Regular DataObjectHandles are declared to an owner during construction,
64 // but destruction must remain harmless for exceptional or moved-from states.
65 if ( owner() ) owner()->renounce( *this );
66}
67
68//---------------------------------------------------------------------------
70 // convenience towards users -- remind them to register
71 // but as m_MS is not yet set, we cannot use a MsgStream...
72 if ( !m_init ) {
73 std::cerr << ( owner() ? owner()->name() : "<UNKNOWN>:" ) << "DataObjectHandle: uninitialized data handle"
74 << std::endl;
75 }
76 DataObject* p = nullptr;
77 m_EDS->retrieveObject( objKey(), p ).ignore();
78 return p;
79}
80
81//---------------------------------------------------------------------------
82
84 if ( m_init ) return true; // initialization already done
85
86 if ( !owner() ) return false;
87
88 Gaudi::Algorithm* algorithm = dynamic_cast<Gaudi::Algorithm*>( owner() );
89 if ( algorithm ) {
90 // Fetch the event Data Service from the algorithm
91 m_EDS = algorithm->evtSvc();
92 m_MS = algorithm->msgSvc();
93 } else {
94 AlgTool* tool = dynamic_cast<AlgTool*>( owner() );
95 if ( tool ) {
96 m_EDS = tool->evtSvc();
97 m_MS = tool->msgSvc();
98 } else {
99 throw GaudiException( "owner is neither AlgTool nor Gaudi::Algorithm", "Invalid Cast", StatusCode::FAILURE );
100 }
101 }
102 m_init = true;
103 return true;
104}
105
106//---------------------------------------------------------------------------
107
109
110//---------------------------------------------------------------------------
111
112std::ostream& operator<<( std::ostream& str, const DataObjectHandleBase& d ) {
113
114 str << d.fullKey() << " m: " << d.mode();
115 if ( d.owner() ) str << " o: " << d.owner()->name();
116 return str;
117}
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
DataObjectHandleBase(DataObjID k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
DataObject * fetch() const
DataObjectHandleBase & operator=(const DataObjectHandleBase &)
DataObjectHandleBase(DataObjID k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
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:86
virtual IDataHandleHolder * owner() const
Definition DataHandle.h:58
virtual const std::string & objKey() const
Definition DataHandle.h:65
virtual Mode mode() const
Definition DataHandle.h:60
virtual const DataObjID & fullKey() const
Definition DataHandle.h:66
DataHandle(DataObjID k, Mode a=Reader, IDataHandleHolder *owner=nullptr)
Definition DataHandle.h:47
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.