| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
DataObjectHandleBase Class Reference

DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h. More...

`#include <GaudiKernel/DataObjectHandleBase.h>`

Inheritance diagram for DataObjectHandleBase:
[legend]
Collaboration diagram for DataObjectHandleBase:
[legend]

## 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 &&)
DataObjectHandleBase & | operator= (const DataObjectHandleBase &)
std::string | toString () const
std::string | pythonRepr () const override
void | fromString (const std::string &s)
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 IDataHandleHolder * | owner () const
virtual Mode | mode () const
virtual void | setKey (const DataObjID &key) const
virtual void | updateKey (const std::string &key) const
virtual const std::string & | objKey () const
virtual const DataObjID & | fullKey () const
virtual void | reset (bool)
virtual StatusCode | commit ()
virtual bool | isCondition () const

## Protected Member Functions
void | setRead (bool wasRead=true)
void | setWritten (bool wasWritten=true)
bool | init () override
DataObject * | fetch () const

## Protected Attributes
SmartIF< IDataProviderSvc > | m_EDS
SmartIF< IMessageSvc > | m_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...
IDataHandleHolder * | m_owner = nullptr

## Friends
std::ostream & | operator<< (std::ostream &str, const DataObjectHandleBase &d)

## Additional Inherited Members
Public Types inherited from Gaudi::DataHandle
enum | Mode { Reader = 1<<2, Writer = 1<<4, Updater = Reader | Writer }

## 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 24 of file DataObjectHandleBase.h.

## Constructor & Destructor Documentation

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

Definition at line 45 of file DataObjectHandleBase.cpp.

47 :
48 Gaudi::DataHandle(k,a,owner) {
49 m_owner->declare(*this);
50 }
IDataHandleHolder::declare
virtual void declare(Gaudi::DataHandle &)=0
Gaudi::DataHandle::m_owner
IDataHandleHolder * m_owner
Definition: DataHandle.h:77
Gaudi::DataHandle
Definition: DataHandle.h:27

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

Definition at line 54 of file DataObjectHandleBase.cpp.

56 :
57 DataObjectHandleBase(DataObjID(k), a, owner)
58 {}
DataObjID
Definition: DataObjID.h:38
DataObjectHandleBase::DataObjectHandleBase
DataObjectHandleBase(const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
Definition: DataObjectHandleBase.cpp:45

DataObjectHandleBase::~DataObjectHandleBase | ( |  | ) |
| virtual

Definition at line 61 of file DataObjectHandleBase.cpp.

61 {
62 owner()->renounce(*this);
63 }
IDataHandleHolder::renounce
virtual void renounce(Gaudi::DataHandle &)=0
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:49

DataObjectHandleBase::DataObjectHandleBase | ( | const DataObjectHandleBase & |  | ) |
| delete

DataObjectHandleBase::DataObjectHandleBase | ( | DataObjectHandleBase && | other | ) |

Definition at line 18 of file DataObjectHandleBase.cpp.

18 :
19 Gaudi::DataHandle(other), m_EDS(std::move(other.m_EDS)),
20 m_MS(std::move(other.m_MS)), m_init(other.m_init),
21 m_optional(other.m_optional),
22 m_wasRead(other.m_wasRead), m_wasWritten(other.m_wasWritten),
23 m_searchDone(other.m_searchDone) {
24 m_owner->declare(*this);
25 }
IDataHandleHolder::declare
virtual void declare(Gaudi::DataHandle &)=0
DataObjectHandleBase::m_wasRead
bool m_wasRead
Definition: DataObjectHandleBase.h:70
DataObjectHandleBase::m_EDS
SmartIF< IDataProviderSvc > m_EDS
Definition: DataObjectHandleBase.h:65
DataObjectHandleBase::m_init
bool m_init
Definition: DataObjectHandleBase.h:68
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:78
DataObjectHandleBase::m_optional
bool m_optional
Definition: DataObjectHandleBase.h:69
Gaudi::DataHandle::m_owner
IDataHandleHolder * m_owner
Definition: DataHandle.h:77
Gaudi::DataHandle
Definition: DataHandle.h:27
std::move
T move(T...args)
DataObjectHandleBase::m_MS
SmartIF< IMessageSvc > m_MS
Definition: DataObjectHandleBase.h:66
DataObjectHandleBase::m_wasWritten
bool m_wasWritten
Definition: DataObjectHandleBase.h:71

## Member Function Documentation

DataObject * DataObjectHandleBase::fetch | ( |  | ) | const
| protected

Definition at line 66 of file DataObjectHandleBase.cpp.

66 {
67 DataObject* p = nullptr;
68 if (LIKELY(m_searchDone)) { // fast path: searchDone, objKey is in its final state
69 m_EDS->retrieveObject(objKey(), p).ignore();
70 return p;
71 }
72
73 // slow path -- move into seperate function to improve code generation?
74
75 // convenience towards users -- remind them to register
76 // but as m_MS is not yet set, we cannot use a MsgStream...
77 if (!m_init) {
78 std::cerr << ( owner() ? owner()->name() : "<UNKNOWN>:")
79 << "DataObjectHandle: uninitialized data handle" << std::endl;
80 }
81
82 // as m_searchDone is not true yet, objKey may change... so in this
83 // branch we _first_ grab the mutex, to avoid objKey changing while we use it
84
85 // take a lock to be sure we only execute this once at a time
86 std::lock_guard<std::mutex> guard(m_searchMutex);
87
88 StatusCode sc = m_EDS->retrieveObject(objKey(), p);
89 if (m_searchDone) { // another thread has done the search while we were blocked
90 // on the mutex. As a result, nothing left to do but return...
91 sc.ignore();
92 return p;
93 }
94
95 if (!sc.isSuccess()) {
96 auto tokens = boost::tokenizer<boost::char_separator<char>>{objKey(),boost::char_separator<char>{":"}};
97 // let's try our alternatives (if any)
98 auto alt = std::find_if( tokens.begin(), tokens.end(),
99 [&](const std::string& n) {
100 return m_EDS->retrieveObject(n,p).isSuccess();
101 } );
102 if (alt!=tokens.end()) {
103 MsgStream log(m_MS,owner()->name() + ":DataObjectHandle");
104 log << MSG::DEBUG << ": could not find \"" << objKey()
105 << "\" -- using alternative source: \"" << *alt << "\" instead"
106 << 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 }
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
Gaudi::DataHandle::objKey
virtual const std::string & objKey() const
Definition: DataHandle.h:56
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
MSG::DEBUG
Definition: IMessageSvc.h:18
std::endl
T endl(T...args)
DataObjectHandleBase::m_EDS
SmartIF< IDataProviderSvc > m_EDS
Definition: DataObjectHandleBase.h:65
DataObjectHandleBase::m_init
bool m_init
Definition: DataObjectHandleBase.h:68
Gaudi::DataHandle::setKey
virtual void setKey(const DataObjID &key) const
Definition: DataHandle.h:53
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:78
std::string
STL class.
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:217
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::find_if
T find_if(T...args)
LIKELY
#define LIKELY(x)
Definition: Kernel.h:125
std::lock_guard
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:84
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:106
DataObjectHandleBase::m_MS
SmartIF< IMessageSvc > m_MS
Definition: DataObjectHandleBase.h:66
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
std::cerr
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:49
Gaudi.Configuration.log
log
Definition: Configuration.py:13
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.

void DataObjectHandleBase::fromString | ( | const std::string & | s | ) |

Definition at line 132 of file DataObjectHandleBase.cpp.

132 {
133 Gaudi::Parsers::parse(*this,s).ignore();
134 }
Gaudi::Parsers::parse
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
Definition: DODBasicMapper.cpp:11
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:106

bool DataObjectHandleBase::init | ( |  | ) |
| override protected virtual

Reimplemented from Gaudi::DataHandle.

Definition at line 139 of file DataObjectHandleBase.cpp.

139 {
140
141 assert(!m_init);
142
143 if (!owner()) return false;
144
145 setRead(false);
146 setWritten(false);
147
148 Algorithm* algorithm = dynamic_cast<Algorithm*>( owner() );
149 if (algorithm) {
150 // Fetch the event Data Service from the algorithm
151 m_EDS = algorithm->evtSvc();
152 m_MS = algorithm->msgSvc();
153 } else {
154 AlgTool* tool = dynamic_cast<AlgTool*>( owner() );
155 if (tool) {
156 m_EDS = tool->evtSvc();
157 m_MS = tool->msgSvc();
158 } else {
159 throw GaudiException( "owner is neither AlgTool nor Algorithm" ,
160 "Invalid Cast", StatusCode::FAILURE) ;
161 }
162 }
163 m_init = true;
164 return true;
165 }
DataObjectHandleBase::setWritten
void setWritten(bool wasWritten=true)
Definition: DataObjectHandleBase.h:57
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
StatusCode::FAILURE
Definition: StatusCode.h:29
DataObjectHandleBase::m_EDS
SmartIF< IDataProviderSvc > m_EDS
Definition: DataObjectHandleBase.h:65
DataObjectHandleBase::m_init
bool m_init
Definition: DataObjectHandleBase.h:68
DataObjectHandleBase::setRead
void setRead(bool wasRead=true)
Definition: DataObjectHandleBase.h:56
AlgTool::evtSvc
IDataProviderSvc * evtSvc() const
accessor to event service service
Definition: AlgTool.cpp:93
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:78
Algorithm::evtSvc
SmartIF< IDataProviderSvc > & evtSvc() const
shortcut for method eventSvc
Definition: Algorithm.h:276
AlgTool
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:48
CommonMessagingBase::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:70
DataObjectHandleBase::m_MS
SmartIF< IMessageSvc > m_MS
Definition: DataObjectHandleBase.h:66
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:49

bool DataObjectHandleBase::initialized | ( |  | ) | const
| inline

Definition at line 49 of file DataObjectHandleBase.h.

49 { return m_init; }
DataObjectHandleBase::m_init
bool m_init
Definition: DataObjectHandleBase.h:68

bool DataObjectHandleBase::isOptional | ( |  | ) | const
| inline

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

Definition at line 46 of file DataObjectHandleBase.h.

46 {return m_optional;}
DataObjectHandleBase::m_optional
bool m_optional
Definition: DataObjectHandleBase.h:69

bool DataObjectHandleBase::isValid | ( |  | ) | const

Definition at line 170 of file DataObjectHandleBase.cpp.

170 {
171
172 return fullKey() != INVALID_DATAOBJID;
173
174 }
Gaudi::DataHandle::fullKey
virtual const DataObjID & fullKey() const
Definition: DataHandle.h:57
INVALID_DATAOBJID
const DataObjID INVALID_DATAOBJID
Definition: DataObjectHandleBase.cpp:15

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

Definition at line 29 of file DataObjectHandleBase.cpp.

29 {
30 // avoid modification of searchDone in other while we are copying
31 std::lock_guard<std::mutex> guard(other.m_searchMutex);
32 //FIXME: operator= should not change our owner, only our 'value'
33 Gaudi::DataHandle::operator=(other);
34 m_EDS = other.m_EDS;
35 m_MS = other.m_MS;
36 m_init = other.m_init;
37 m_optional = other.m_optional;
38 m_wasRead = other.m_wasRead;
39 m_wasWritten = other.m_wasWritten;
40 m_searchDone = other.m_searchDone;
41 return *this;
42 }
DataObjectHandleBase::m_wasRead
bool m_wasRead
Definition: DataObjectHandleBase.h:70
DataObjectHandleBase::m_EDS
SmartIF< IDataProviderSvc > m_EDS
Definition: DataObjectHandleBase.h:65
DataObjectHandleBase::m_init
bool m_init
Definition: DataObjectHandleBase.h:68
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:78
DataObjectHandleBase::m_optional
bool m_optional
Definition: DataObjectHandleBase.h:69
operator=
PropertyMgr & operator=(const PropertyMgr &)=delete
std::lock_guard
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:84
DataObjectHandleBase::m_MS
SmartIF< IMessageSvc > m_MS
Definition: DataObjectHandleBase.h:66
DataObjectHandleBase::m_wasWritten
bool m_wasWritten
Definition: DataObjectHandleBase.h:71

std::string DataObjectHandleBase::pythonRepr | ( |  | ) | const
| override virtual

Reimplemented from Gaudi::DataHandle.

Definition at line 126 of file DataObjectHandleBase.cpp.

126 {
127 return "DataObjectHandleBase(\"" + toString() + "\")";
128 }
DataObjectHandleBase::toString
std::string toString() const
Definition: DataObjectHandleBase.cpp:120

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

Definition at line 47 of file DataObjectHandleBase.h.

47 { m_optional = optional; }
DataObjectHandleBase::m_optional
bool m_optional
Definition: DataObjectHandleBase.h:69

void DataObjectHandleBase::setRead | ( | bool | wasRead = `true` | ) |
| inline protected

Definition at line 56 of file DataObjectHandleBase.h.

56 {m_wasRead = wasRead;}
DataObjectHandleBase::m_wasRead
bool m_wasRead
Definition: DataObjectHandleBase.h:70
DataObjectHandleBase::wasRead
bool wasRead() const
Definition: DataObjectHandleBase.h:50

void DataObjectHandleBase::setWritten | ( | bool | wasWritten = `true` | ) |
| inline protected

Definition at line 57 of file DataObjectHandleBase.h.

57 {m_wasWritten = wasWritten;}
DataObjectHandleBase::wasWritten
bool wasWritten() const
Definition: DataObjectHandleBase.h:51
DataObjectHandleBase::m_wasWritten
bool m_wasWritten
Definition: DataObjectHandleBase.h:71

std::string DataObjectHandleBase::toString | ( |  | ) | const

Definition at line 120 of file DataObjectHandleBase.cpp.

120 {
121 return objKey();
122 }
Gaudi::DataHandle::objKey
virtual const std::string & objKey() const
Definition: DataHandle.h:56

bool DataObjectHandleBase::wasRead | ( |  | ) | const
| inline

Definition at line 50 of file DataObjectHandleBase.h.

50 { return m_wasRead; }
DataObjectHandleBase::m_wasRead
bool m_wasRead
Definition: DataObjectHandleBase.h:70

bool DataObjectHandleBase::wasWritten | ( |  | ) | const
| inline

Definition at line 51 of file DataObjectHandleBase.h.

51 { return m_wasWritten; }
DataObjectHandleBase::m_wasWritten
bool m_wasWritten
Definition: DataObjectHandleBase.h:71

## Friends And Related Function Documentation

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

Definition at line 179 of file DataObjectHandleBase.cpp.

179 {
180
181 str << d.fullKey() << " m: " << d.mode();
182 if (d.owner()) str << " o: " << d.owner()->name();
183 str << " opt: " << d.isOptional();
184 return str;
185 }
Gaudi::DataHandle::mode
virtual Mode mode() const
Definition: DataHandle.h:51
Gaudi::DataHandle::fullKey
virtual const DataObjID & fullKey() const
Definition: DataHandle.h:57
DataObjectHandleBase::isOptional
bool isOptional() const
Check if the data object declared is optional for the algorithm.
Definition: DataObjectHandleBase.h:46
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:49

## Member Data Documentation

SmartIF<IDataProviderSvc> DataObjectHandleBase::m_EDS
| protected

Definition at line 65 of file DataObjectHandleBase.h.

bool DataObjectHandleBase::m_init = false
| protected

Definition at line 68 of file DataObjectHandleBase.h.

SmartIF<IMessageSvc> DataObjectHandleBase::m_MS
| protected

Definition at line 66 of file DataObjectHandleBase.h.

bool DataObjectHandleBase::m_optional = false
| protected

Definition at line 69 of file DataObjectHandleBase.h.

bool DataObjectHandleBase::m_searchDone = false
| mutable protected

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 78 of file DataObjectHandleBase.h.

std::mutex DataObjectHandleBase::m_searchMutex
| mutable protected

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 84 of file DataObjectHandleBase.h.

bool DataObjectHandleBase::m_wasRead = false
| protected

Definition at line 70 of file DataObjectHandleBase.h.

bool DataObjectHandleBase::m_wasWritten = false
| protected

Definition at line 71 of file DataObjectHandleBase.h.

The documentation for this class was generated from the following files:

- GaudiKernel/GaudiKernel/DataObjectHandleBase.h
- GaudiKernel/src/Lib/DataObjectHandleBase.cpp