| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

# GaudiHandle.cpp

Go to the documentation of this file.

    00001 #include "GaudiKernel/GaudiHandle.h"
    00002 #include <iostream>
    00003 #include <string>
    00004
    00005 //
    00006 // GaudiHandleBase implementation
    00007 //
    00008
    00009 void GaudiHandleBase::setTypeAndName( const std::string& myTypeAndName ) {
    00010   m_typeAndName = myTypeAndName;
    00011 }
    00012
    00013 std::string GaudiHandleBase::type() const {
    00014   std::string::size_type slash = m_typeAndName.find('/');
    00015   if ( slash != std::string::npos ) {
    00016     // return only part before /
    00017     return m_typeAndName.substr(0,slash);
    00018   } else {
    00019     // return full string
    00020     return m_typeAndName;
    00021   }
    00022 }
    00023
    00024 std::string GaudiHandleBase::name() const {
    00025   std::string::size_type slash = m_typeAndName.find('/');
    00026   if ( slash == std::string::npos ) {
    00027     // only type is given, or string is empty.
    00028     // return default name (=type or empty, in this case full string)
    00029     return m_typeAndName;
    00030   } else if ( slash != m_typeAndName.length() -1 ) {
    00031     // an explicit name is given, so return it
    00032     return m_typeAndName.substr(slash+1);
    00033   } else {
    00034     // ends with /, i.e. explicit empty name.
    00035     // Should probably never happen.
    00036     return "";
    00037   }
    00038 }
    00039
    00040 void GaudiHandleBase::setName( const std::string& myName ) {
    00041   m_typeAndName = type() + '/' + myName;
    00042 }
    00043
    00044 const std::string GaudiHandleBase::pythonPropertyClassName() const {
    00045   return componentType() + "Handle";
    00046 }
    00047
    00048 const std::string GaudiHandleBase::messageName() const {
    00049   std::string propName = propertyName();
    00050   if ( propName.empty() ) {
    00051     propName = pythonPropertyClassName() + "('" + m_typeAndName + "')";
    00052   }
    00053   return parentName() + "." + propName;
    00054 }
    00055
    00056 const std::string GaudiHandleBase::pythonRepr() const {
    00057   return pythonPropertyClassName() + "('" + m_typeAndName + "')";
    00058 }
    00059
    00060 //
    00061 // GaudiHandleArrayBase implementation
    00062 //
    00063 bool GaudiHandleArrayBase::setTypesAndNames(  const std::vector< std::string >& myTypesAndNamesList ) {
    00064   clear();
    00065   std::vector< std::string >::const_iterator it = myTypesAndNamesList.begin(),
    00066     itEnd = myTypesAndNamesList.end();
    00067   for ( ; it != itEnd; ++it ) {
    00068     if ( !push_back( *it ) ) return false;
    00069   }
    00070   return true;
    00071 }
    00072
    00073 const std::vector< std::string >
    00074 GaudiHandleArrayBase::getBaseInfos( std::string (GaudiHandleBase::*pMemFunc)() const ) const {
    00075   std::vector< std::string > theList;
    00076   const GaudiHandleArrayBase::ConstBaseHandleArray& baseArray = getBaseArray();
    00077   GaudiHandleArrayBase::ConstBaseHandleArray::const_iterator it = baseArray.begin(),
    00078     itEnd = baseArray.end();
    00079   for ( ; it != itEnd; ++it ) theList.push_back( ((*it)->*pMemFunc)() );
    00080   return theList;
    00081 }
    00082
    00083 const std::vector< std::string > GaudiHandleArrayBase::typesAndNames() const {
    00084   return getBaseInfos( &GaudiHandleBase::typeAndName );
    00085 }
    00086
    00087 const std::vector< std::string > GaudiHandleArrayBase::types() const {
    00088   return getBaseInfos( &GaudiHandleBase::type );
    00089 }
    00090
    00091 const std::vector< std::string > GaudiHandleArrayBase::names() const {
    00092   return getBaseInfos( &GaudiHandleBase::name );
    00093 }
    00094
    00095 const std::string GaudiHandleArrayBase::pythonPropertyClassName() const {
    00096   return componentType() + "HandleArray";
    00097 }
    00098
    00099 const std::string GaudiHandleArrayBase::pythonRepr() const {
    00100   std::string repr = pythonPropertyClassName() + "([";
    00101   const std::vector< std::string >& theList = typesAndNames();
    00102   std::vector< std::string >::const_iterator it = theList.begin(),
    00103     itEnd = theList.end(), itLast = itEnd - 1;
    00104   for ( ; it != itEnd; ++it ) {
    00105     repr += "'" + *it + "'";
    00106     if ( it != itLast ) repr += ",";
    00107   }
    00108   repr += "])";
    00109   return repr;
    00110 }
    00111
    00112
    00113 //
    00114 // Public functions
    00115 //
    00116 std::ostream& operator<<( std::ostream& os, const GaudiHandleInfo& handle ) {
    00117   std::string msg;
    00118   const std::string& propName = handle.propertyName();
    00119   if ( !propName.empty() ) msg += propName + " = ";
    00120   msg += handle.pythonRepr();
    00121   os << msg;
    00122   return os;
    00123 }
    00124