The Gaudi Framework  master (ba5b4fb7)
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 m_owner->declare( *this );
32}
33
34//---------------------------------------------------------------------------
36 // FIXME: operator= should not change our owner, only our 'value'
37 Gaudi::DataHandle::operator=( other );
38 m_EDS = other.m_EDS;
39 m_MS = other.m_MS;
40 m_init = other.m_init;
41 return *this;
43
44//---------------------------------------------------------------------------
49
50//---------------------------------------------------------------------------
51
54
55//---------------------------------------------------------------------------
57
58//---------------------------------------------------------------------------
60 // convenience towards users -- remind them to register
61 // but as m_MS is not yet set, we cannot use a MsgStream...
62 if ( !m_init ) {
63 std::cerr << ( owner() ? owner()->name() : "<UNKNOWN>:" ) << "DataObjectHandle: uninitialized data handle"
64 << std::endl;
65 }
66 DataObject* p = nullptr;
67 m_EDS->retrieveObject( objKey(), p ).ignore();
68 return p;
69}
70
71//---------------------------------------------------------------------------
72
74 if ( m_init ) return true; // initialization already done
75
76 if ( !owner() ) return false;
77
78 Gaudi::Algorithm* algorithm = dynamic_cast<Gaudi::Algorithm*>( owner() );
79 if ( algorithm ) {
80 // Fetch the event Data Service from the algorithm
81 m_EDS = algorithm->evtSvc();
82 m_MS = algorithm->msgSvc();
83 } else {
84 AlgTool* tool = dynamic_cast<AlgTool*>( owner() );
85 if ( tool ) {
86 m_EDS = tool->evtSvc();
87 m_MS = tool->msgSvc();
88 } else {
89 throw GaudiException( "owner is neither AlgTool nor Gaudi::Algorithm", "Invalid Cast", StatusCode::FAILURE );
90 }
91 }
92 m_init = true;
93 return true;
94}
95
96//---------------------------------------------------------------------------
97
99
100//---------------------------------------------------------------------------
101
102std::ostream& operator<<( std::ostream& str, const DataObjectHandleBase& d ) {
103
104 str << d.fullKey() << " m: " << d.mode();
105 if ( d.owner() ) str << " o: " << d.owner()->name();
106 return str;
107}
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 &)
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.