All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GaudiHandle.cpp
Go to the documentation of this file.
2 #include <iostream>
3 #include <string>
4 
5 //
6 // GaudiHandleBase implementation
7 //
8 
10  m_typeAndName = std::move(myTypeAndName);
11 }
12 
14  std::string::size_type slash = m_typeAndName.find('/');
15  if ( slash != std::string::npos ) {
16  // return only part before /
17  return m_typeAndName.substr(0,slash);
18  } else {
19  // return full string
20  return m_typeAndName;
21  }
22 }
23 
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 ) {
41  m_typeAndName = type() + '/' + myName;
42 }
43 
45  return componentType() + "Handle";
46 }
47 
49  std::string propName = propertyName();
50  if ( propName.empty() ) {
51  propName = pythonPropertyClassName() + "('" + m_typeAndName + "')";
52  }
53  return parentName() + "." + propName;
54 }
55 
57  return pythonPropertyClassName() + "('" + m_typeAndName + "')";
58 }
59 
60 //
61 // GaudiHandleArrayBase implementation
62 //
64  clear();
65  for ( const auto& it : myTypesAndNamesList ) {
66  if ( !push_back( it ) ) return false;
67  }
68  return true;
69 }
70 
74  for ( const auto& it : getBaseArray() ) theList.push_back( (it->*pMemFunc)() );
75  return theList;
76 }
77 
79  return getBaseInfos( &GaudiHandleBase::typeAndName );
80 }
81 
83  return getBaseInfos( &GaudiHandleBase::type );
84 }
85 
87  return getBaseInfos( &GaudiHandleBase::name );
88 }
89 
91  return componentType() + "HandleArray";
92 }
93 
95  std::string repr = pythonPropertyClassName() + "([";
96  auto theList = typesAndNames();
97  auto first = theList.begin();
98  auto last = theList.end();
99  if ( first != last ) { repr += "'" + *first + "'"; ++first; }
100  for (;first!=last;++first) repr += ",'" + *first + "'";
101  repr += "])";
102  return repr;
103 }
104 
105 //
106 // Public functions
107 //
110  const auto& propName = handle.propertyName();
111  if ( !propName.empty() ) msg += propName + " = ";
112  msg += handle.pythonRepr();
113  os << msg;
114  return os;
115 }
std::string messageName() const
name used for printing messages
Definition: GaudiHandle.cpp:48
T empty(T...args)
std::ostream & operator<<(std::ostream &os, const GaudiHandleInfo &handle)
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:9
std::string pythonPropertyClassName() const override
Name of the componentType with "Handle" appended.
Definition: GaudiHandle.cpp:44
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:50
const std::vector< std::string > names() const
Return a vector with "type/name" strings of all handles in the array.
Definition: GaudiHandle.cpp:86
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:72
STL class.
T push_back(T...args)
const std::vector< std::string > types() const
Return a vector with "type" strings of all handles in the array.
Definition: GaudiHandle.cpp:82
const std::string & propertyName() const
name as used in declareProperty(name,gaudiHandle)
Definition: GaudiHandle.h:40
bool setTypesAndNames(const std::vector< std::string > &myTypesAndNamesList)
Set the array of handles from list of "type/name" strings in <myTypesAndNamesList>.
Definition: GaudiHandle.cpp:63
std::string m_typeAndName
Definition: GaudiHandle.h:159
std::string pythonRepr() const override
Python representation of array of handles, i.e.
Definition: GaudiHandle.cpp:94
T move(T...args)
T find(T...args)
T length(T...args)
std::string pythonRepr() const override
Python representation of handle, i.e.
Definition: GaudiHandle.cpp:56
std::string type() const
The concrete component class name: the part before the &#39;/&#39;.
Definition: GaudiHandle.cpp:13
T substr(T...args)
const std::vector< std::string > typesAndNames() const
Return a vector with "type/name" strings of all handles in the array.
Definition: GaudiHandle.cpp:78
std::string name() const
The instance name: the part after the &#39;/&#39;.
Definition: GaudiHandle.cpp:24
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
Definition: GaudiHandle.h:94
std::string typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:121
virtual std::string pythonRepr() const =0
Python representation of handle, i.e.
void setName(const std::string &myName)
Set the instance name (part after the &#39;/&#39;) without changing the class type.
Definition: GaudiHandle.cpp:40
STL class.
std::string pythonPropertyClassName() const override
Name of the componentType with "HandleArray" appended.
Definition: GaudiHandle.cpp:90
const std::string & componentType() const
Definition: GaudiHandle.h:35