The Gaudi Framework  master (37c0b60a)
GaudiHandle.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
12 #include <iostream>
13 #include <string>
14 
15 //
16 // GaudiHandleBase implementation
17 //
18 
19 void GaudiHandleBase::setTypeAndName( std::string myTypeAndName ) { m_typeAndName = std::move( myTypeAndName ); }
20 
22  std::string::size_type slash = m_typeAndName.find( '/' );
23  if ( slash != std::string::npos ) {
24  // return only part before /
25  return m_typeAndName.substr( 0, slash );
26  } else {
27  // return full string
28  return m_typeAndName;
29  }
30 }
31 
33  auto slash = m_typeAndName.find( '/' );
34  if ( slash == std::string::npos ) {
35  // only type is given, or string is empty.
36  // return default name (=type or empty, in this case full string)
37  return m_typeAndName;
38  } else if ( slash != m_typeAndName.length() - 1 ) {
39  // an explicit name is given, so return it
40  return m_typeAndName.substr( slash + 1 );
41  } else {
42  // ends with /, i.e. explicit empty name.
43  // Should probably never happen.
44  return "";
45  }
46 }
47 
48 void GaudiHandleBase::setName( std::string_view myName ) { m_typeAndName = type().append( "/" ).append( myName ); }
49 
51 
53  std::string propName = propertyName();
54  if ( propName.empty() ) { propName = pythonPropertyClassName() + "('" + m_typeAndName + "')"; }
55  return parentName() + "." + propName;
56 }
57 
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 
73  for ( const auto& it : getBaseArray() ) theList.push_back( ( it->*pMemFunc )() );
74  return theList;
75 }
76 
79 }
80 
82 
84 
86 
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 //
106  const auto& propName = handle.propertyName();
107  if ( !propName.empty() ) msg += propName + " = ";
108  msg += handle.pythonRepr();
109  os << msg;
110  return os;
111 }
GaudiHandleArrayBase::pythonRepr
std::string pythonRepr() const override
Python representation of array of handles, i.e.
Definition: GaudiHandle.cpp:87
GaudiHandleInfo::parentName
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:65
GaudiHandle.h
std::string
STL class.
GaudiHandleBase::messageName
std::string messageName() const
name used for printing messages
Definition: GaudiHandle.cpp:52
std::move
T move(T... args)
std::vector< std::string >
std::string::find
T find(T... args)
std::string::length
T length(T... args)
operator<<
std::ostream & operator<<(std::ostream &os, const GaudiHandleInfo &handle)
Definition: GaudiHandle.cpp:104
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
GaudiHandleArrayBase::getBaseInfos
const std::vector< std::string > getBaseInfos(auto(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:71
GaudiHandleBase::name
std::string name() const
The instance name: the part after the '/'.
Definition: GaudiHandle.cpp:32
GaudiHandleInfo::componentType
const std::string & componentType() const
Definition: GaudiHandle.h:56
GaudiHandleBase::setName
void setName(std::string_view myName)
Set the instance name (part after the '/') without changing the class type.
Definition: GaudiHandle.cpp:48
GaudiHandleBase
Definition: GaudiHandle.h:105
std::vector::push_back
T push_back(T... args)
std::ostream
STL class.
GaudiHandleBase::m_typeAndName
std::string m_typeAndName
Definition: GaudiHandle.h:167
GaudiHandleInfo::propertyName
const std::string & propertyName() const
name as used in declareProperty(name,gaudiHandle)
Definition: GaudiHandle.h:59
GaudiHandleBase::pythonRepr
std::string pythonRepr() const override
Python representation of handle, i.e.
Definition: GaudiHandle.cpp:58
GaudiHandleArrayBase::clear
virtual void clear()=0
Clear the list of handles.
GaudiHandleArrayBase::getBaseArray
virtual ConstBaseHandleArray getBaseArray() const =0
Get a read-only vector of const GaudiHandleBase* pointing to the real handles.
std::string::append
T append(T... args)
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:63
std::string::substr
T substr(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:83
GaudiHandleBase::type
std::string type() const
The concrete component class name: the part before the '/'.
Definition: GaudiHandle.cpp:21
GaudiHandleBase::pythonPropertyClassName
std::string pythonPropertyClassName() const override
Name of the componentType with "Handle" appended.
Definition: GaudiHandle.cpp:50
GaudiHandleArrayBase::push_back
virtual bool push_back(const std::string &myHandleTypeAndName)=0
Add a handle to the array with "type/name" given in <myHandleTypeAndName>.
std::string::empty
T empty(T... args)
GaudiHandleInfo
Definition: GaudiHandle.h:34
GaudiHandleBase::typeAndName
const std::string & typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:131
GaudiHandleArrayBase::pythonPropertyClassName
std::string pythonPropertyClassName() const override
Name of the componentType with "HandleArray" appended.
Definition: GaudiHandle.cpp:85
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:77
GaudiHandleInfo::pythonRepr
virtual std::string pythonRepr() const =0
Python representation of handle, i.e.
GaudiHandleArrayBase::types
const std::vector< std::string > types() const
Return a vector with "type" strings of all handles in the array.
Definition: GaudiHandle.cpp:81
GaudiHandleBase::setTypeAndName
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:19