| The Gaudi Framework v30r0 (c919700c)

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

- File List
- File Members

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