The Gaudi Framework  v29r0 (ff2e7097)
DataObjectHandleBase Class Reference

DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h. More...

#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 = typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type>
 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...
 
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 IDataHandleHolderowner () const
 
virtual Mode mode () const
 
virtual void setKey (const DataObjID &key) const
 
virtual void updateKey (const std::string &key) const
 
virtual const std::stringobjKey () const
 
virtual const DataObjIDfullKey () 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
 
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, 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 25 of file DataObjectHandleBase.h.

Constructor & Destructor Documentation

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

Definition at line 47 of file DataObjectHandleBase.cpp.

48  : Gaudi::DataHandle( k, a, owner )
49 {
50  m_owner->declare( *this );
51 }
virtual void declare(Gaudi::DataHandle &)=0
IDataHandleHolder * m_owner
Definition: DataHandle.h:69
DataObjectHandleBase::DataObjectHandleBase ( const std::string k,
Gaudi::DataHandle::Mode  a,
IDataHandleHolder owner 
)

Definition at line 55 of file DataObjectHandleBase.cpp.

56  : DataObjectHandleBase( DataObjID( k ), a, owner )
57 {
58 }
DataObjectHandleBase(const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
DataObjectHandleBase::~DataObjectHandleBase ( )
virtual

Definition at line 61 of file DataObjectHandleBase.cpp.

61 { owner()->renounce( *this ); }
virtual void renounce(Gaudi::DataHandle &)=0
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:42
DataObjectHandleBase::DataObjectHandleBase ( const DataObjectHandleBase )
delete
DataObjectHandleBase::DataObjectHandleBase ( DataObjectHandleBase &&  other)

Definition at line 16 of file DataObjectHandleBase.cpp.

17  : Gaudi::DataHandle( other )
18  , m_EDS( std::move( other.m_EDS ) )
19  , m_MS( std::move( other.m_MS ) )
20  , m_init( other.m_init )
21  , m_optional( other.m_optional )
22  , m_wasRead( other.m_wasRead )
23  , m_wasWritten( other.m_wasWritten )
24  , m_searchDone( other.m_searchDone )
25 {
26  m_owner->declare( *this );
27 }
virtual void declare(Gaudi::DataHandle &)=0
SmartIF< IDataProviderSvc > m_EDS
bool m_searchDone
Whether the search part of the fetch method (so dealing with alt names was already executed or not...
IDataHandleHolder * m_owner
Definition: DataHandle.h:69
T move(T...args)
SmartIF< IMessageSvc > m_MS
template<class OWNER , class K , typename = typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type>
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 40 of file DataObjectHandleBase.h.

40  {},
41  std::string doc = "" )
42  : DataObjectHandleBase( key, m, owner )
43  {
44  auto p = owner->declareProperty( std::move( name ), *this, std::move( doc ) );
45  p->template setOwnerType<OWNER>();
46  }
STL class.
constexpr double m
Definition: SystemOfUnits.h:94
T move(T...args)
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:42
DataObjectHandleBase(const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)

Member Function Documentation

DataObject * DataObjectHandleBase::fetch ( ) const
protected

Definition at line 64 of file DataObjectHandleBase.cpp.

65 {
66  DataObject* p = nullptr;
67  if ( LIKELY( m_searchDone ) ) { // fast path: searchDone, objKey is in its final state
68  m_EDS->retrieveObject( objKey(), p ).ignore();
69  return p;
70  }
71 
72  // slow path -- move into seperate function to improve code generation?
73 
74  // convenience towards users -- remind them to register
75  // but as m_MS is not yet set, we cannot use a MsgStream...
76  if ( !m_init ) {
77  std::cerr << ( owner() ? owner()->name() : "<UNKNOWN>:" ) << "DataObjectHandle: uninitialized data handle"
78  << std::endl;
79  }
80 
81  // as m_searchDone is not true yet, objKey may change... so in this
82  // branch we _first_ grab the mutex, to avoid objKey changing while we use it
83 
84  // take a lock to be sure we only execute this once at a time
86 
87  StatusCode sc = m_EDS->retrieveObject( objKey(), p );
88  if ( m_searchDone ) { // another thread has done the search while we were blocked
89  // on the mutex. As a result, nothing left to do but return...
90  sc.ignore();
91  return p;
92  }
93 
94  if ( !sc.isSuccess() ) {
95  auto tokens = boost::tokenizer<boost::char_separator<char>>{objKey(), boost::char_separator<char>{":"}};
96  // let's try our alternatives (if any)
97  auto alt = std::find_if( tokens.begin(), tokens.end(),
98  [&]( const std::string& n ) { return m_EDS->retrieveObject( n, p ).isSuccess(); } );
99  if ( alt != tokens.end() ) {
100  MsgStream log( m_MS, owner()->name() + ":DataObjectHandle" );
101  log << MSG::DEBUG << ": could not find \"" << objKey() << "\" -- using alternative source: \"" << *alt
102  << "\" instead" << endmsg;
103  // found something -- set it as default; this is not atomic, but
104  // at least in `fetch` there is no use of `objKey` that races with
105  // this assignment... (but there may be others!)
106  setKey( *alt );
107  }
108  }
109  m_searchDone = true;
110  return p;
111 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual const std::string & objKey() const
Definition: DataHandle.h:49
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
T endl(T...args)
SmartIF< IDataProviderSvc > m_EDS
virtual void setKey(const DataObjID &key) const
Definition: DataHandle.h:46
bool m_searchDone
Whether the search part of the fetch method (so dealing with alt names was already executed or not...
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
#define LIKELY(x)
Definition: Kernel.h:127
T find_if(T...args)
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...
void ignore() const
Definition: StatusCode.h:109
SmartIF< IMessageSvc > m_MS
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:29
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
virtual const std::string & name() const =0
Retrieve the name of the instance.
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:42
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 121 of file DataObjectHandleBase.cpp.

121 { Gaudi::Parsers::parse( *this, s ).ignore(); }
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
void ignore() const
Definition: StatusCode.h:109
bool DataObjectHandleBase::init ( )
overrideprotectedvirtual

Reimplemented from Gaudi::DataHandle.

Definition at line 125 of file DataObjectHandleBase.cpp.

126 {
127 
128  assert( !m_init );
129 
130  if ( !owner() ) return false;
131 
132  setRead( false );
133  setWritten( false );
134 
135  Algorithm* algorithm = dynamic_cast<Algorithm*>( owner() );
136  if ( algorithm ) {
137  // Fetch the event Data Service from the algorithm
138  m_EDS = algorithm->evtSvc();
139  m_MS = algorithm->msgSvc();
140  } else {
141  AlgTool* tool = dynamic_cast<AlgTool*>( owner() );
142  if ( tool ) {
143  m_EDS = tool->evtSvc();
144  m_MS = tool->msgSvc();
145  } else {
146  throw GaudiException( "owner is neither AlgTool nor Algorithm", "Invalid Cast", StatusCode::FAILURE );
147  }
148  }
149  m_init = true;
150  return true;
151 }
void setWritten(bool wasWritten=true)
Define general base for Gaudi exception.
SmartIF< IDataProviderSvc > m_EDS
void setRead(bool wasRead=true)
IDataProviderSvc * evtSvc() const
accessor to event service service
Definition: AlgTool.cpp:93
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:78
SmartIF< IDataProviderSvc > & evtSvc() const
shortcut for method eventSvc
Definition: Algorithm.h:280
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:48
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
SmartIF< IMessageSvc > m_MS
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:42
bool DataObjectHandleBase::initialized ( ) const
inline

Definition at line 58 of file DataObjectHandleBase.h.

58 { return m_init; }
bool DataObjectHandleBase::isOptional ( ) const
inline

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

Definition at line 55 of file DataObjectHandleBase.h.

55 { return m_optional; }
bool DataObjectHandleBase::isValid ( ) const

Definition at line 155 of file DataObjectHandleBase.cpp.

155 { return fullKey() != INVALID_DATAOBJID; }
virtual const DataObjID & fullKey() const
Definition: DataHandle.h:50
const DataObjID INVALID_DATAOBJID
DataObjectHandleBase & DataObjectHandleBase::operator= ( const DataObjectHandleBase other)

Definition at line 30 of file DataObjectHandleBase.cpp.

31 {
32  // avoid modification of searchDone in other while we are copying
34  // FIXME: operator= should not change our owner, only our 'value'
36  m_EDS = other.m_EDS;
37  m_MS = other.m_MS;
38  m_init = other.m_init;
39  m_optional = other.m_optional;
40  m_wasRead = other.m_wasRead;
41  m_wasWritten = other.m_wasWritten;
42  m_searchDone = other.m_searchDone;
43  return *this;
44 }
SmartIF< IDataProviderSvc > m_EDS
bool m_searchDone
Whether the search part of the fetch method (so dealing with alt names was already executed or not...
PropertyMgr & operator=(const PropertyMgr &)=delete
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...
SmartIF< IMessageSvc > m_MS
std::string DataObjectHandleBase::pythonRepr ( ) const
overridevirtual

Reimplemented from Gaudi::DataHandle.

Definition at line 118 of file DataObjectHandleBase.cpp.

118 { return "DataObjectHandleBase(\"" + toString() + "\")"; }
std::string toString() const
void DataObjectHandleBase::setOptional ( bool  optional = true)
inline

Definition at line 56 of file DataObjectHandleBase.h.

56 { m_optional = optional; }
void DataObjectHandleBase::setRead ( bool  wasRead = true)
inlineprotected

Definition at line 65 of file DataObjectHandleBase.h.

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

Definition at line 66 of file DataObjectHandleBase.h.

std::string DataObjectHandleBase::toString ( ) const

Definition at line 115 of file DataObjectHandleBase.cpp.

115 { return objKey(); }
virtual const std::string & objKey() const
Definition: DataHandle.h:49
bool DataObjectHandleBase::wasRead ( ) const
inline

Definition at line 59 of file DataObjectHandleBase.h.

59 { return m_wasRead; }
bool DataObjectHandleBase::wasWritten ( ) const
inline

Definition at line 60 of file DataObjectHandleBase.h.

Friends And Related Function Documentation

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

Definition at line 159 of file DataObjectHandleBase.cpp.

160 {
161 
162  str << d.fullKey() << " m: " << d.mode();
163  if ( d.owner() ) str << " o: " << d.owner()->name();
164  str << " opt: " << d.isOptional();
165  return str;
166 }
virtual Mode mode() const
Definition: DataHandle.h:44
virtual const DataObjID & fullKey() const
Definition: DataHandle.h:50
bool isOptional() const
Check if the data object declared is optional for the algorithm.
virtual const std::string & name() const =0
Retrieve the name of the instance.
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:42

Member Data Documentation

SmartIF<IDataProviderSvc> DataObjectHandleBase::m_EDS
protected

Definition at line 73 of file DataObjectHandleBase.h.

bool DataObjectHandleBase::m_init = false
protected

Definition at line 76 of file DataObjectHandleBase.h.

SmartIF<IMessageSvc> DataObjectHandleBase::m_MS
protected

Definition at line 74 of file DataObjectHandleBase.h.

bool DataObjectHandleBase::m_optional = false
protected

Definition at line 77 of file DataObjectHandleBase.h.

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

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

bool DataObjectHandleBase::m_wasRead = false
protected

Definition at line 78 of file DataObjectHandleBase.h.

bool DataObjectHandleBase::m_wasWritten = false
protected

Definition at line 79 of file DataObjectHandleBase.h.


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