| The Gaudi Framework v32r1 (f65d50dc)

GaudiHandle.cpp
Go to the documentation of this file.
1 #include "GaudiKernel/GaudiHandle.h"
2 #include <iostream>
3 #include <string>
4
5 //
6 // GaudiHandleBase implementation
7 //
8
9 void GaudiHandleBase::setTypeAndName( std::string myTypeAndName ) { m_typeAndName = std::move( myTypeAndName ); }
10
11 std::string GaudiHandleBase::type() const {
12 std::string::size_type slash = m_typeAndName.find( '/' );
13 if ( slash != std::string::npos ) {
14 // return only part before /
15 return m_typeAndName.substr( 0, slash );
16 } else {
17 // return full string
18 return m_typeAndName;
19 }
20 }
21
22 std::string GaudiHandleBase::name() const {
23 auto slash = m_typeAndName.find( '/' );
24 if ( slash == std::string::npos ) {
25 // only type is given, or string is empty.
26 // return default name (=type or empty, in this case full string)
27 return m_typeAndName;
28 } else if ( slash != m_typeAndName.length() - 1 ) {
29 // an explicit name is given, so return it
30 return m_typeAndName.substr( slash + 1 );
31 } else {
32 // ends with /, i.e. explicit empty name.
33 // Should probably never happen.
34 return "";
35 }
36 }
37
38 void GaudiHandleBase::setName( const std::string& myName ) { m_typeAndName = type() + '/' + myName; }
39
40 std::string GaudiHandleBase::pythonPropertyClassName() const { return componentType() + "Handle"; }
41
42 std::string GaudiHandleBase::messageName() const {
43 std::string propName = propertyName();
44 if ( propName.empty() ) { propName = pythonPropertyClassName() + "('" + m_typeAndName + "')"; }
45 return parentName() + "." + propName;
46 }
47
48 std::string GaudiHandleBase::pythonRepr() const { return pythonPropertyClassName() + "('" + m_typeAndName + "')"; }
49
50 //
51 // GaudiHandleArrayBase implementation
52 //
53 bool GaudiHandleArrayBase::setTypesAndNames( const std::vector<std::string>& myTypesAndNamesList ) {
54 clear();
55 for ( const auto& it : myTypesAndNamesList ) {
56 if ( !push_back( it ) ) return false;
57 }
58 return true;
59 }
60
61 const std::vector<std::string> GaudiHandleArrayBase::getBaseInfos( std::string ( GaudiHandleBase::*pMemFunc )()
62 const ) const {
63 std::vector<std::string> theList;
64 for ( const auto& it : getBaseArray() ) theList.push_back( ( it->*pMemFunc )() );
65 return theList;
66 }
67
68 const std::vector<std::string> GaudiHandleArrayBase::typesAndNames() const {
69 return getBaseInfos( &GaudiHandleBase::typeAndName );
70 }
71
72 const std::vector<std::string> GaudiHandleArrayBase::types() const { return getBaseInfos( &GaudiHandleBase::type ); }
73
74 const std::vector<std::string> GaudiHandleArrayBase::names() const { return getBaseInfos( &GaudiHandleBase::name ); }
75
76 std::string GaudiHandleArrayBase::pythonPropertyClassName() const { return componentType() + "HandleArray"; }
77
78 std::string GaudiHandleArrayBase::pythonRepr() const {
79 std::string repr = pythonPropertyClassName() + "([";
80 auto theList = typesAndNames();
81 auto first = theList.begin();
82 auto last = theList.end();
83 if ( first != last ) {
84 repr += "'" + *first + "'";
85 ++first;
86 }
87 for ( ; first != last; ++first ) repr += ",'" + *first + "'";
88 repr += "])";
89 return repr;
90 }
91
92 //
93 // Public functions
94 //
95 std::ostream& operator<<( std::ostream& os, const GaudiHandleInfo& handle ) {
96 std::string msg;
97 const auto& propName = handle.propertyName();
98 if ( !propName.empty() ) msg += propName + " = ";
99 msg += handle.pythonRepr();
100 os << msg;
101 return os;
102 }
GaudiHandleArrayBase::types
const std::vector< std::string > types() const
Return a vector with "type" strings of all handles in the array.
Definition: GaudiHandle.cpp:72
std::string::empty
T empty(T... args)
operator<<
std::ostream & operator<<(std::ostream &os, const GaudiHandleInfo &handle)
Definition: GaudiHandle.cpp:95
GaudiHandleBase::setTypeAndName
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:9
GaudiHandleInfo::propertyName
const std::string & propertyName() const
name as used in declareProperty(name,gaudiHandle)
Definition: GaudiHandle.h:47
GaudiHandleBase::typeAndName
std::string typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:115
GaudiHandleArrayBase::typesAndNames
const std::vector< std::string > typesAndNames() const
Return a vector with "type/name" strings of all handles in the array.
Definition: GaudiHandle.cpp:68
GaudiHandleArrayBase::getBaseArray
virtual ConstBaseHandleArray getBaseArray() const =0
Get a read-only vector of const GaudiHandleBase* pointing to the real handles.
GaudiHandleBase::pythonPropertyClassName
std::string pythonPropertyClassName() const override
Name of the componentType with "Handle" appended.
Definition: GaudiHandle.cpp:40
GaudiHandleBase::pythonRepr
std::string pythonRepr() const override
Python representation of handle, i.e.
Definition: GaudiHandle.cpp:48
std::string
STL class.
GaudiHandleBase::name
std::string name() const
The instance name: the part after the '/'.
Definition: GaudiHandle.cpp:22
std::vector::push_back
T push_back(T... args)
GaudiHandleInfo::pythonRepr
virtual std::string pythonRepr() const =0
Python representation of handle, i.e.
GaudiHandleArrayBase::setTypesAndNames
bool setTypesAndNames(const std::vector< std::string > &myTypesAndNamesList)
Set the array of handles from list of "type/name" strings in <myTypesAndNamesList>.
Definition: GaudiHandle.cpp:53
GaudiHandleInfo::parentName
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:53
GaudiHandleArrayBase::clear
virtual void clear()=0
Clear the list of handles.
GaudiHandleBase::m_typeAndName
std::string m_typeAndName
Definition: GaudiHandle.h:151
std::move
T move(T... args)
GaudiHandleArrayBase::getBaseInfos
const std::vector< std::string > getBaseInfos(std::string(GaudiHandleBase::*pMemFunc)() const) const
Helper function to get a vector of strings filled with the return value of each tool of a member func...
Definition: GaudiHandle.cpp:61
GaudiHandleBase::messageName
std::string messageName() const
name used for printing messages
Definition: GaudiHandle.cpp:42
GaudiHandleInfo::componentType
const std::string & componentType() const
Definition: GaudiHandle.h:44
std::string::find
T find(T... args)
std::string::length
T length(T... args)
GaudiHandleArrayBase::names
const std::vector< std::string > names() const
Return a vector with "type/name" strings of all handles in the array.
Definition: GaudiHandle.cpp:74
std::vector< std::string >
GaudiHandleBase::type
std::string type() const
The concrete component class name: the part before the '/'.
Definition: GaudiHandle.cpp:11
GaudiHandleArrayBase::push_back
virtual bool push_back(const std::string &myHandleTypeAndName)=0
Add a handle to the array with "type/name" given in <myHandleTypeAndName>.
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
std::string::substr
T substr(T... args)
GaudiHandleBase
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
Definition: GaudiHandle.h:89
GaudiHandleArrayBase::pythonPropertyClassName
std::string pythonPropertyClassName() const override
Name of the componentType with "HandleArray" appended.
Definition: GaudiHandle.cpp:76
GaudiHandleBase::setName
void setName(const std::string &myName)
Set the instance name (part after the '/') without changing the class type.
Definition: GaudiHandle.cpp:38
std::ostream
STL class.
GaudiHandle.h
GaudiHandleInfo
Definition: GaudiHandle.h:25
GaudiHandleArrayBase::pythonRepr
std::string pythonRepr() const override
Python representation of array of handles, i.e.
Definition: GaudiHandle.cpp:78