The Gaudi Framework  v36r1 (3e2fb5a8)
DataObjectHandleBase Class Reference

DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/DataObjectHandleBase.h>

Inheritance diagram for DataObjectHandleBase:
Collaboration diagram for DataObjectHandleBase:

Public Member Functions

 DataObjectHandleBase (const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
 
 DataObjectHandleBase (const std::string &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
 
virtual ~DataObjectHandleBase ()
 
 DataObjectHandleBase (const DataObjectHandleBase &)=delete
 
 DataObjectHandleBase (DataObjectHandleBase &&)
 
DataObjectHandleBaseoperator= (const DataObjectHandleBase &)
 
template<class OWNER , class K , typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
 DataObjectHandleBase (OWNER *owner, Gaudi::DataHandle::Mode m, std::string name, const K &key={}, std::string doc="")
 Autodeclaring constructor with property name, mode, key and documentation. More...
 
bool isOptional () const
 Check if the data object declared is optional for the algorithm. More...
 
void setOptional (bool optional=true)
 
bool initialized () const
 
bool wasRead () const
 
bool wasWritten () const
 
bool isValid () const
 
- Public Member Functions inherited from Gaudi::DataHandle
 DataHandle (const DataObjID &k, Mode a=Reader, IDataHandleHolder *owner=nullptr)
 
 DataHandle (const DataObjID &k, const bool &isCond, Mode a=Reader, IDataHandleHolder *owner=nullptr)
 
virtual ~DataHandle ()=default
 
virtual void setOwner (IDataHandleHolder *o)
 
virtual IDataHandleHolderowner () const
 
virtual Mode mode () const
 
virtual void setKey (DataObjID key) const
 
virtual void updateKey (std::string key) const
 
virtual const std::stringobjKey () const
 
virtual const DataObjIDfullKey () const
 
virtual void reset (bool)
 
virtual std::string pythonRepr () const
 
virtual bool isCondition () const
 

Protected Member Functions

void setRead (bool wasRead=true)
 
void setWritten (bool wasWritten=true)
 
bool init () override
 
DataObjectfetch () const
 

Protected Attributes

SmartIF< IDataProviderSvcm_EDS
 
SmartIF< IMessageSvcm_MS
 
bool m_init = false
 
bool m_optional = false
 
bool m_wasRead = false
 
bool m_wasWritten = false
 
bool m_searchDone = false
 Whether the search part of the fetch method (so dealing with alt names was already executed or not. More...
 
std::mutex m_searchMutex
 A Mutex protecting the calls to the search part of the fetch method, so that we are sure that we only call it once. More...
 
- Protected Attributes inherited from Gaudi::DataHandle
DataObjID m_key = {"NONE"}
 The key of the object behind this DataHandle Although it may look strange to have it mutable, this can actually change in case the object had alternative names, and it should not be visible to the end user, for which the Handle is still the same. More...
 
IDataHandleHolderm_owner = nullptr
 

Friends

std::ostreamoperator<< (std::ostream &str, const DataObjectHandleBase &d)
 

Additional Inherited Members

- Public Types inherited from Gaudi::DataHandle
enum  Mode { Reader = 1 << 2, Writer = 1 << 4 }
 
using PropertyType = DataHandleProperty
 
- Static Protected Attributes inherited from Gaudi::DataHandle
static const std::string default_type = "unknown_t"
 

Detailed Description

DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.

Base class for handles to Data Objects in the Event Store, to simplify access via Properties.

Author
Charles Leggett
Date
2015-09-01

Definition at line 35 of file DataObjectHandleBase.h.

Constructor & Destructor Documentation

◆ DataObjectHandleBase() [1/5]

DataObjectHandleBase::DataObjectHandleBase ( const DataObjID k,
Gaudi::DataHandle::Mode  a,
IDataHandleHolder owner 
)

Definition at line 55 of file DataObjectHandleBase.cpp.

56  : Gaudi::DataHandle( k, a, owner ) {
57  m_owner->declare( *this );
58 }

◆ DataObjectHandleBase() [2/5]

DataObjectHandleBase::DataObjectHandleBase ( const std::string k,
Gaudi::DataHandle::Mode  a,
IDataHandleHolder owner 
)

Definition at line 62 of file DataObjectHandleBase.cpp.

63  : DataObjectHandleBase( DataObjID( k ), a, owner ) {}

◆ ~DataObjectHandleBase()

DataObjectHandleBase::~DataObjectHandleBase ( )
virtual

Definition at line 66 of file DataObjectHandleBase.cpp.

66 { owner()->renounce( *this ); }

◆ DataObjectHandleBase() [3/5]

DataObjectHandleBase::DataObjectHandleBase ( const DataObjectHandleBase )
delete

◆ DataObjectHandleBase() [4/5]

DataObjectHandleBase::DataObjectHandleBase ( DataObjectHandleBase &&  other)

Definition at line 26 of file DataObjectHandleBase.cpp.

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_wasRead( other.m_wasRead )
33  , m_wasWritten( other.m_wasWritten )
34  , m_searchDone( other.m_searchDone ) {
35  m_owner->declare( *this );
36 }

◆ DataObjectHandleBase() [5/5]

template<class OWNER , class K , typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
DataObjectHandleBase::DataObjectHandleBase ( OWNER *  owner,
Gaudi::DataHandle::Mode  m,
std::string  name,
const K &  key = {},
std::string  doc = "" 
)
inline

Autodeclaring constructor with property name, mode, key and documentation.

Note
the use std::enable_if is required to avoid ambiguities

Definition at line 49 of file DataObjectHandleBase.h.

49  {},
50  std::string doc = "" )
52  auto p = owner->declareProperty( std::move( name ), *this, std::move( doc ) );
53  p->template setOwnerType<OWNER>();
54  }

Member Function Documentation

◆ fetch()

DataObject * DataObjectHandleBase::fetch ( ) const
protected

Definition at line 69 of file DataObjectHandleBase.cpp.

69  {
70  DataObject* p = nullptr;
71  if ( LIKELY( m_searchDone ) ) { // fast path: searchDone, objKey is in its final state
72  m_EDS->retrieveObject( objKey(), p ).ignore();
73  return p;
74  }
75 
76  // slow path -- move into seperate function to improve code generation?
77 
78  // convenience towards users -- remind them to register
79  // but as m_MS is not yet set, we cannot use a MsgStream...
80  if ( !m_init ) {
81  std::cerr << ( owner() ? owner()->name() : "<UNKNOWN>:" ) << "DataObjectHandle: uninitialized data handle"
82  << std::endl;
83  }
84 
85  // as m_searchDone is not true yet, objKey may change... so in this
86  // branch we _first_ grab the mutex, to avoid objKey changing while we use it
87 
88  // take a lock to be sure we only execute this once at a time
89  auto guard = std::scoped_lock{m_searchMutex};
90 
91  StatusCode sc = m_EDS->retrieveObject( objKey(), p );
92  if ( m_searchDone ) { // another thread has done the search while we were blocked
93  // on the mutex. As a result, nothing left to do but return...
94  sc.ignore();
95  return p;
96  }
97 
98  if ( !sc.isSuccess() ) {
99  auto tokens = boost::tokenizer<boost::char_separator<char>>{objKey(), boost::char_separator<char>{":"}};
100  // let's try our alternatives (if any)
101  auto alt = std::find_if( tokens.begin(), tokens.end(),
102  [&]( const std::string& n ) { return m_EDS->retrieveObject( n, p ).isSuccess(); } );
103  if ( alt != tokens.end() ) {
104  MsgStream log( m_MS, owner()->name() + ":DataObjectHandle" );
105  log << MSG::DEBUG << ": could not find \"" << objKey() << "\" -- using alternative source: \"" << *alt
106  << "\" instead" << endmsg;
107  // found something -- set it as default; this is not atomic, but
108  // at least in `fetch` there is no use of `objKey` that races with
109  // this assignment... (but there may be others!)
110  setKey( *alt );
111  }
112  }
113  m_searchDone = true;
114  return p;
115 }

◆ init()

bool DataObjectHandleBase::init ( )
overrideprotectedvirtual

Reimplemented from Gaudi::DataHandle.

Definition at line 119 of file DataObjectHandleBase.cpp.

119  {
120 
121  assert( !m_init );
122 
123  if ( !owner() ) return false;
124 
125  setRead( false );
126  setWritten( false );
127 
128  Gaudi::Algorithm* algorithm = dynamic_cast<Gaudi::Algorithm*>( owner() );
129  if ( algorithm ) {
130  // Fetch the event Data Service from the algorithm
131  m_EDS = algorithm->evtSvc();
132  m_MS = algorithm->msgSvc();
133  } else {
134  AlgTool* tool = dynamic_cast<AlgTool*>( owner() );
135  if ( tool ) {
136  m_EDS = tool->evtSvc();
137  m_MS = tool->msgSvc();
138  } else {
139  throw GaudiException( "owner is neither AlgTool nor Gaudi::Algorithm", "Invalid Cast", StatusCode::FAILURE );
140  }
141  }
142  m_init = true;
143  return true;
144 }

◆ initialized()

bool DataObjectHandleBase::initialized ( ) const
inline

Definition at line 62 of file DataObjectHandleBase.h.

62 { return m_init; }

◆ isOptional()

bool DataObjectHandleBase::isOptional ( ) const
inline

Check if the data object declared is optional for the algorithm.

Definition at line 59 of file DataObjectHandleBase.h.

59 { return m_optional; }

◆ isValid()

bool DataObjectHandleBase::isValid ( ) const

Definition at line 148 of file DataObjectHandleBase.cpp.

148 { return fullKey() != INVALID_DATAOBJID; }

◆ operator=()

DataObjectHandleBase & DataObjectHandleBase::operator= ( const DataObjectHandleBase other)

Definition at line 39 of file DataObjectHandleBase.cpp.

39  {
40  // avoid modification of searchDone in other while we are copying
41  auto guard = std::scoped_lock{other.m_searchMutex};
42  // FIXME: operator= should not change our owner, only our 'value'
43  Gaudi::DataHandle::operator=( other );
44  m_EDS = other.m_EDS;
45  m_MS = other.m_MS;
46  m_init = other.m_init;
47  m_optional = other.m_optional;
48  m_wasRead = other.m_wasRead;
49  m_wasWritten = other.m_wasWritten;
50  m_searchDone = other.m_searchDone;
51  return *this;
52 }

◆ setOptional()

void DataObjectHandleBase::setOptional ( bool  optional = true)
inline

Definition at line 60 of file DataObjectHandleBase.h.

60 { m_optional = optional; }

◆ setRead()

void DataObjectHandleBase::setRead ( bool  wasRead = true)
inlineprotected

Definition at line 69 of file DataObjectHandleBase.h.

69 { m_wasRead = wasRead; }

◆ setWritten()

void DataObjectHandleBase::setWritten ( bool  wasWritten = true)
inlineprotected

Definition at line 70 of file DataObjectHandleBase.h.

◆ wasRead()

bool DataObjectHandleBase::wasRead ( ) const
inline

Definition at line 63 of file DataObjectHandleBase.h.

63 { return m_wasRead; }

◆ wasWritten()

bool DataObjectHandleBase::wasWritten ( ) const
inline

Definition at line 64 of file DataObjectHandleBase.h.

64 { return m_wasWritten; }

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream str,
const DataObjectHandleBase d 
)
friend

Definition at line 152 of file DataObjectHandleBase.cpp.

152  {
153 
154  str << d.fullKey() << " m: " << d.mode();
155  if ( d.owner() ) str << " o: " << d.owner()->name();
156  str << " opt: " << d.isOptional();
157  return str;
158 }

Member Data Documentation

◆ m_EDS

SmartIF<IDataProviderSvc> DataObjectHandleBase::m_EDS
protected

Definition at line 77 of file DataObjectHandleBase.h.

◆ m_init

bool DataObjectHandleBase::m_init = false
protected

Definition at line 80 of file DataObjectHandleBase.h.

◆ m_MS

SmartIF<IMessageSvc> DataObjectHandleBase::m_MS
protected

Definition at line 78 of file DataObjectHandleBase.h.

◆ m_optional

bool DataObjectHandleBase::m_optional = false
protected

Definition at line 81 of file DataObjectHandleBase.h.

◆ m_searchDone

bool DataObjectHandleBase::m_searchDone = false
mutableprotected

Whether the search part of the fetch method (so dealing with alt names was already executed or not.

On subsequent calls (when this is true), it will be skipped.

Definition at line 90 of file DataObjectHandleBase.h.

◆ m_searchMutex

std::mutex DataObjectHandleBase::m_searchMutex
mutableprotected

A Mutex protecting the calls to the search part of the fetch method, so that we are sure that we only call it once.

Definition at line 96 of file DataObjectHandleBase.h.

◆ m_wasRead

bool DataObjectHandleBase::m_wasRead = false
protected

Definition at line 82 of file DataObjectHandleBase.h.

◆ m_wasWritten

bool DataObjectHandleBase::m_wasWritten = false
protected

Definition at line 83 of file DataObjectHandleBase.h.


The documentation for this class was generated from the following files:
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
std::string
STL class.
Gaudi.Configuration.log
log
Definition: Configuration.py:24
std::move
T move(T... args)
DataObjectHandleBase::m_wasWritten
bool m_wasWritten
Definition: DataObjectHandleBase.h:83
DataObjectHandleBase::m_EDS
SmartIF< IDataProviderSvc > m_EDS
Definition: DataObjectHandleBase.h:77
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:355
DataObjectHandleBase::m_MS
SmartIF< IMessageSvc > m_MS
Definition: DataObjectHandleBase.h:78
std::find_if
T find_if(T... args)
DataObjectHandleBase::m_searchDone
bool m_searchDone
Whether the search part of the fetch method (so dealing with alt names was already executed or not.
Definition: DataObjectHandleBase.h:90
GaudiException
Definition: GaudiException.h:31
DataObjectHandleBase::DataObjectHandleBase
DataObjectHandleBase(const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
Definition: DataObjectHandleBase.cpp:55
DataObjectHandleBase::m_optional
bool m_optional
Definition: DataObjectHandleBase.h:81
Gaudi::DataHandle::setKey
virtual void setKey(DataObjID key) const
Definition: DataHandle.h:57
Gaudi::DataHandle
Definition: DataHandle.h:38
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
DataObjectHandleBase::wasRead
bool wasRead() const
Definition: DataObjectHandleBase.h:63
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
DataObjectHandleBase::setRead
void setRead(bool wasRead=true)
Definition: DataObjectHandleBase.h:69
bug_34121.tool
tool
Definition: bug_34121.py:17
TimingHistograms.name
name
Definition: TimingHistograms.py:23
StatusCode
Definition: StatusCode.h:65
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:53
DataObjectHandleBase::m_init
bool m_init
Definition: DataObjectHandleBase.h:80
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
std::cerr
LIKELY
#define LIKELY(x)
Definition: Kernel.h:105
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:90
IDataHandleHolder::renounce
virtual void renounce(Gaudi::DataHandle &)=0
Gaudi::DataHandle::objKey
virtual const std::string & objKey() const
Definition: DataHandle.h:60
Gaudi::DataHandle::m_owner
IDataHandleHolder * m_owner
Definition: DataHandle.h:81
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
MsgStream
Definition: MsgStream.h:34
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:221
DataObjID
Definition: DataObjID.h:47
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:156
std::endl
T endl(T... args)
Gaudi::Algorithm::evtSvc
SmartIF< IDataProviderSvc > & evtSvc() const
shortcut for method eventSvc
Definition: Algorithm.h:248
AlgTool
Definition: AlgTool.h:62
Gaudi::DataHandle::mode
virtual Mode mode() const
Definition: DataHandle.h:55
DataObject
Definition: DataObject.h:40
DataObjectHandleBase::setWritten
void setWritten(bool wasWritten=true)
Definition: DataObjectHandleBase.h:70
DataObjectHandleBase::wasWritten
bool wasWritten() const
Definition: DataObjectHandleBase.h:64
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
INVALID_DATAOBJID
const DataObjID INVALID_DATAOBJID
Definition: DataObjectHandleBase.cpp:23
DataObjectHandleBase::m_searchMutex
std::mutex m_searchMutex
A Mutex protecting the calls to the search part of the fetch method, so that we are sure that we only...
Definition: DataObjectHandleBase.h:96
Gaudi::DataHandle::fullKey
virtual const DataObjID & fullKey() const
Definition: DataHandle.h:61
ProduceConsume.key
key
Definition: ProduceConsume.py:52
DataObjectHandleBase::m_wasRead
bool m_wasRead
Definition: DataObjectHandleBase.h:82