Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ServiceHandle.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_SERVICEHANDLE_H
2 #define GAUDIKERNEL_SERVICEHANDLE_H
3 
4 //Includes
10 #include "GaudiKernel/MsgStream.h"
12 
13 #include <string>
14 #include <stdexcept>
15 
16 // class predeclarations
17 class IAlgTool;
18 class IToolSvc;
19 class ServiceHandleProperty;
20 
21 
29 template< class T >
30 class ServiceHandle : public GaudiHandle<T> {
31 public:
32  //
33  // Constructors etc.
34  //
42  ServiceHandle( const std::string& serviceName, const std::string& theParentName )
43  : GaudiHandle<T>(serviceName, "Service", theParentName)
44  {}
45 
48  StatusCode retrieve() const { // not really const, because it updates m_pObject
49  return GaudiHandle<T>::retrieve();
50  }
51 
52 // /** Release the Service.
53 // Function must be repeated here to avoid hiding the function release( T*& ) */
54 // StatusCode release() const { // not really const, because it updates m_pObject
55 // return GaudiHandle<T>::release();
56 // }
57 
58 protected:
60  StatusCode retrieve( T*& service ) const {
62  return helper.getService(GaudiHandleBase::typeAndName(), true, T::interfaceID(), (void**)&service);
63  }
64 
65 // /** Do the real release of the Service */
66 // virtual StatusCode release( T* service ) const {
67 // return service->release();
68 // }
69 
70 private:
71  //
72  // Private helper functions
73  //
74  SmartIF<ISvcLocator>& serviceLocator() const { // not really const, because it may change m_pSvcLocator
75  if ( !m_pSvcLocator.isValid() ) {
77  if ( !m_pSvcLocator.isValid() ) {
78  throw GaudiException("SvcLocator not found", "Core component not found", StatusCode::FAILURE);
79  }
80  }
81  return m_pSvcLocator;
82  }
83 
84  SmartIF<IMessageSvc>& messageSvc() const { // not really const, because it may change m_pMessageSvc
85  if ( !m_pMessageSvc.isValid() ) {
86  m_pMessageSvc = serviceLocator(); // default message service
87  if( !m_pMessageSvc.isValid() ) {
88  throw GaudiException("Service [MessageSvc] not found",
90  }
91  }
92  return m_pMessageSvc;
93  }
94  //
95  // private data members
96  //
99 };
100 
111 template < class T >
112 class ServiceHandleArray : public GaudiHandleArray< ServiceHandle<T> > {
113 public:
114  //
115  // Constructors
116  //
119  ServiceHandleArray( const std::vector< std::string >& myTypesAndNamesList,
120  const std::string& myComponentType, const std::string& myParentName ):
121  GaudiHandleArray< ServiceHandle<T> >( myTypesAndNamesList,
122  myComponentType,
123  myParentName)
124  { }
125 
126  ServiceHandleArray( const std::string& myParentName )
127  : GaudiHandleArray< ServiceHandle<T> >( "Service", myParentName)
128  { }
129 
130  virtual bool push_back( const std::string& serviceTypeAndName ) {
131  ServiceHandle<T> handle( serviceTypeAndName,GaudiHandleInfo::parentName());
133  return true;
134  }
135 
136  virtual bool push_back( const ServiceHandle<T>& myHandle ) {
137  return push_back( myHandle.typeAndName() );
138  }
139 
140 };
141 
142 template <class T>
143 inline std::ostream& operator<<( std::ostream& os, const ServiceHandle<T>& handle ) {
144  return operator<<(os, static_cast<const GaudiHandleInfo&>(handle) );
145 }
146 
147 template <class T>
148 inline std::ostream& operator<<( std::ostream& os, const ServiceHandleArray<T>& handle ) {
149  return operator<<(os, static_cast<const GaudiHandleInfo&>(handle) );
150 }
151 
152 #endif // ! GAUDIKERNEL_SERVICEHANDLE_H

Generated at Wed Jan 30 2013 17:13:40 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004