| The Gaudi Framework v27r1

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

- File List
- File Members

DataObjectHandleBase.cpp
Go to the documentation of this file.
1 #include "GaudiKernel/DataObjectHandleBase.h"
2 #include "GaudiKernel/Algorithm.h"
3 #include "GaudiKernel/AlgTool.h"
4 #include "GaudiKernel/IDataProviderSvc.h"
5 #include "GaudiKernel/ServiceLocatorHelper.h"
6
7 #include <sstream>
8 #include <string>
9 #include <ostream>
10
11 const DataObjID INVALID_DATAOBJID = DataObjID();
12
13 //---------------------------------------------------------------------------
14
15 DataObjectHandleBase::DataObjectHandleBase():
16 Gaudi::DataHandle(), m_init(false),
17 m_goodType(false), m_optional(false), m_wasRead(false), m_wasWritten(false) {}
18
19 //---------------------------------------------------------------------------
20 DataObjectHandleBase::DataObjectHandleBase(const DataObjID & k,
21 Gaudi::DataHandle::Mode a,
22 IDataHandleHolder* owner):
23 Gaudi::DataHandle(k,a,owner), m_init(false), m_goodType(false),
24 m_optional(false), m_wasRead(false), m_wasWritten(false) {}
25
26 //---------------------------------------------------------------------------
27
28 DataObjectHandleBase::DataObjectHandleBase(const std::string & k,
29 Gaudi::DataHandle::Mode a,
30 IDataHandleHolder* owner):
31 DataObjectHandleBase(DataObjID(k), a, owner){}
32
33 //---------------------------------------------------------------------------
34
35 const std::string
36 DataObjectHandleBase::toString() const {
37 std::ostringstream ost;
38 ost << m_key << "|" << mode() << "|" << isOptional() << "|";
39 for (auto &a : m_altNames) {
40 ost << a << "&";
41 }
42 // ost << ")";
43 return ost.str();
44 }
45
46 //---------------------------------------------------------------------------
47 const std::string
48 DataObjectHandleBase::pythonRepr() const {
49 return "DataObjectHandleBase(\"" + toString() + "\")";
50 }
51
52 //---------------------------------------------------------------------------
53 void
54 DataObjectHandleBase::fromString(const std::string& s) {
55 Gaudi::Parsers::parse(*this,s).ignore();
56 }
57
58 //---------------------------------------------------------------------------
59
60 void
61 DataObjectHandleBase::init() {
62
63 if (m_init) return;
64
65 if (m_owner == 0) return;
66
67 setRead(false);
68 setWritten(false);
69
70 Algorithm* algorithm = dynamic_cast<Algorithm*>( m_owner );
71 if (algorithm != 0) {
72 // Fetch the event Data Service from the algorithm
73 m_EDS = algorithm->evtSvc();
74 m_MS = algorithm->msgSvc();
75 } else {
76 AlgTool* tool = dynamic_cast<AlgTool*>( owner() );
77 if (tool != 0) {
78 m_EDS = tool->evtSvc();
79 m_MS = tool->msgSvc();
80 } else {
81 throw GaudiException( "owner is not an AlgTool or Algorithm" ,
82 "Invalid Cast", StatusCode::FAILURE) ;
83 }
84 }
85
86 m_init = true;
87
88 }
89
90 //---------------------------------------------------------------------------
91
92 bool
93 DataObjectHandleBase::isValid() const {
94
95 return ( fullKey() != INVALID_DATAOBJID );
96
97 }
98
99 //---------------------------------------------------------------------------
100
101 std::ostream&
102 operator<< (std::ostream& str, const DataObjectHandleBase& d) {
103
104 str << d.fullKey() << " m: " << d.mode();
105 if (d.owner() != 0) {
106 str << " o: " << d.owner()->name();
107 }
108
109 str << " opt: " << d.isOptional();
110
111 if (d.alternativeDataProductNames().size() != 0) {
112 str << " alt: [";
113 for ( auto &n : d.alternativeDataProductNames()) {
114 str << n << ",";
115 }
116 str << "]";
117 }
118
119 return str;
120 }
DataObjectHandleBase::setWritten
void setWritten(bool wasWritten=true)
Definition: DataObjectHandleBase.h:60
Algorithm.h
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
DataObjectHandleBase::pythonRepr
const std::string pythonRepr() const
Definition: DataObjectHandleBase.cpp:48
DataObjID
Definition: DataObjID.h:38
AlgTool.h
Gaudi::DataHandle::mode
virtual Mode mode() const
Definition: DataHandle.h:47
DataObjectHandleBase::m_EDS
SmartIF< IDataProviderSvc > m_EDS
Definition: DataObjectHandleBase.h:66
DataObjectHandleBase::m_init
bool m_init
Definition: DataObjectHandleBase.h:69
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
DataObjectHandleBase::setRead
void setRead(bool wasRead=true)
Definition: DataObjectHandleBase.h:59
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
std::string
STL class.
Gaudi::DataHandle::fullKey
virtual const DataObjID & fullKey() const
Definition: DataHandle.h:53
IDataHandleHolder
Definition: IDataHandleHolder.h:17
IDataProviderSvc.h
Gaudi::DataHandle::m_key
DataObjID m_key
Definition: DataHandle.h:63
StatusCode::FAILURE
Definition: StatusCode.h:29
std::ostringstream
STL class.
operator<<
std::ostream & operator<<(std::ostream &str, const DataObjectHandleBase &d)
Definition: DataObjectHandleBase.cpp:102
Gaudi::DataHandle::m_owner
IDataHandleHolder * m_owner
Definition: DataHandle.h:64
INVALID_DATAOBJID
const DataObjID INVALID_DATAOBJID
Definition: DataObjectHandleBase.cpp:11
std::ostringstream::str
T str(T...args)
DataObjectHandleBase::fromString
void fromString(const std::string &s)
Definition: DataObjectHandleBase.cpp:54
AlgTool::evtSvc
IDataProviderSvc * evtSvc() const
accessor to event service service
Definition: AlgTool.cpp:95
DataObjectHandleBase.h
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
DataObjectHandleBase::isValid
bool isValid() const
Definition: DataObjectHandleBase.cpp:93
std::vector::size
T size(T...args)
Algorithm::evtSvc
SmartIF< IDataProviderSvc > & evtSvc() const
shortcut for method eventSvc
Definition: Algorithm.h:284
DataObjectHandleBase
DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.
Definition: DataObjectHandleBase.h:24
DataObjectHandleBase::m_altNames
std::vector< std::string > m_altNames
Definition: DataObjectHandleBase.h:74
DataObjectHandleBase::toString
const std::string toString() const
Definition: DataObjectHandleBase.cpp:36
AlgTool
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:45
gaudirun.s
string s
Definition: gaudirun.py:245
CommonMessagingBase::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:73
ServiceLocatorHelper.h
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:108
DataObjectHandleBase::m_MS
SmartIF< IMessageSvc > m_MS
Definition: DataObjectHandleBase.h:67
Gaudi::DataHandle::Mode
Mode
Definition: DataHandle.h:30
DataObjectHandleBase::isOptional
bool isOptional() const
Check if the data object declared is optional for the algorithm.
Definition: DataObjectHandleBase.h:45
std::ostream
STL class.
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
DataObjectHandleBase::alternativeDataProductNames
const std::vector< std::string > & alternativeDataProductNames() const
Definition: DataObjectHandleBase.h:48
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:45
DataObjectHandleBase::DataObjectHandleBase
DataObjectHandleBase()
Definition: DataObjectHandleBase.cpp:15
DataObjectHandleBase::init
void init()
Definition: DataObjectHandleBase.cpp:61