All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaudiHandle.cpp
Go to the documentation of this file.
2 #include <iostream>
3 #include <string>
4 
5 //
6 // GaudiHandleBase implementation
7 //
8 
9 void GaudiHandleBase::setTypeAndName( const std::string& myTypeAndName ) {
10  m_typeAndName = myTypeAndName;
11 }
12 
13 std::string GaudiHandleBase::type() const {
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 
24 std::string GaudiHandleBase::name() const {
25  std::string::size_type 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 
44 const std::string GaudiHandleBase::pythonPropertyClassName() const {
45  return componentType() + "Handle";
46 }
47 
48 const std::string GaudiHandleBase::messageName() const {
49  std::string propName = propertyName();
50  if ( propName.empty() ) {
51  propName = pythonPropertyClassName() + "('" + m_typeAndName + "')";
52  }
53  return parentName() + "." + propName;
54 }
55 
56 const std::string GaudiHandleBase::pythonRepr() const {
57  return pythonPropertyClassName() + "('" + m_typeAndName + "')";
58 }
59 
60 //
61 // GaudiHandleArrayBase implementation
62 //
63 bool GaudiHandleArrayBase::setTypesAndNames( const std::vector< std::string >& myTypesAndNamesList ) {
64  clear();
65  std::vector< std::string >::const_iterator it = myTypesAndNamesList.begin(),
66  itEnd = myTypesAndNamesList.end();
67  for ( ; it != itEnd; ++it ) {
68  if ( !push_back( *it ) ) return false;
69  }
70  return true;
71 }
72 
73 const std::vector< std::string >
74 GaudiHandleArrayBase::getBaseInfos( std::string (GaudiHandleBase::*pMemFunc)() const ) const {
75  std::vector< std::string > theList;
77  GaudiHandleArrayBase::ConstBaseHandleArray::const_iterator it = baseArray.begin(),
78  itEnd = baseArray.end();
79  for ( ; it != itEnd; ++it ) theList.push_back( ((*it)->*pMemFunc)() );
80  return theList;
81 }
82 
83 const std::vector< std::string > GaudiHandleArrayBase::typesAndNames() const {
85 }
86 
87 const std::vector< std::string > GaudiHandleArrayBase::types() const {
89 }
90 
91 const std::vector< std::string > GaudiHandleArrayBase::names() const {
93 }
94 
96  return componentType() + "HandleArray";
97 }
98 
99 const std::string GaudiHandleArrayBase::pythonRepr() const {
100  std::string repr = pythonPropertyClassName() + "([";
101  const std::vector< std::string >& theList = typesAndNames();
102  std::vector< std::string >::const_iterator it = theList.begin(),
103  itEnd = theList.end(), itLast = itEnd - 1;
104  for ( ; it != itEnd; ++it ) {
105  repr += "'" + *it + "'";
106  if ( it != itLast ) repr += ",";
107  }
108  repr += "])";
109  return repr;
110 }
111 
112 
113 //
114 // Public functions
115 //
116 std::ostream& operator<<( std::ostream& os, const GaudiHandleInfo& handle ) {
117  std::string msg;
118  const std::string& propName = handle.propertyName();
119  if ( !propName.empty() ) msg += propName + " = ";
120  msg += handle.pythonRepr();
121  os << msg;
122  return os;
123 }
124 
std::ostream & operator<<(std::ostream &os, const GaudiHandleInfo &handle)
std::vector< const GaudiHandleBase * > ConstBaseHandleArray
Definition: GaudiHandle.h:300
const std::string messageName() const
name used for printing messages
Definition: GaudiHandle.cpp:48
virtual ConstBaseHandleArray getBaseArray() const =0
Get a read-only vector of const GaudiHandleBase* pointing to the real handles.
virtual const std::string pythonPropertyClassName() const
Name of the componentType with "HandleArray" appended.
Definition: GaudiHandle.cpp:95
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:48
const std::vector< std::string > names() const
Return a vector with "type/name" strings of all handles in the array.
Definition: GaudiHandle.cpp:91
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:74
const std::vector< std::string > types() const
Return a vector with "type" strings of all handles in the array.
Definition: GaudiHandle.cpp:87
const std::string & propertyName() const
name as used in declareProperty(name,gaudiHandle)
Definition: GaudiHandle.h:38
bool setTypesAndNames(const std::vector< std::string > &myTypesAndNamesList)
Set the array of handles from list of "type/name" strings in .
Definition: GaudiHandle.cpp:63
virtual void clear()=0
Clear the list of handles.
virtual const std::string pythonRepr() const
Python representation of handle, i.e.
Definition: GaudiHandle.cpp:56
std::string m_typeAndName
Definition: GaudiHandle.h:145
virtual bool push_back(const std::string &myHandleTypeAndName)=0
Add a handle to the array with "type/name" given in .
void setTypeAndName(const std::string &myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:9
std::string type() const
The concrete component class name: the part before the '/'.
Definition: GaudiHandle.cpp:13
const std::vector< std::string > typesAndNames() const
Return a vector with "type/name" strings of all handles in the array.
Definition: GaudiHandle.cpp:83
std::string name() const
The instance name: the part after the '/'.
Definition: GaudiHandle.cpp:24
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
Definition: GaudiHandle.h:80
std::string typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:107
virtual const std::string pythonRepr() const =0
Python representation of handle, i.e.
const std::string pythonPropertyClassName() const
Name of the componentType with "Handle" appended.
Definition: GaudiHandle.cpp:44
void setName(const std::string &myName)
Set the instance name (part after the '/') without changing the class type.
Definition: GaudiHandle.cpp:40
const std::string & componentType() const
Definition: GaudiHandle.h:33
virtual const std::string pythonRepr() const
Python representation of array of handles, i.e.
Definition: GaudiHandle.cpp:99