| The Gaudi Framework v32r1 (f65d50dc)

GaudiCommonImp.h
Go to the documentation of this file.
1 #ifndef GAUDIALG_GAUDICOMMONIMP_H
2 #define GAUDIALG_GAUDICOMMONIMP_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 #include <algorithm>
7 // ============================================================================
8 // GaudiAlg
9 // ============================================================================
10 #include "GaudiAlg/GaudiCommon.h"
11 #include "GaudiAlg/GetData.h"
12 // ============================================================================
20 // ============================================================================
21 // Templated access to the data in Gaudi Transient Store
22 // ============================================================================
23 template <class PBASE>
24 template <class TYPE>
25 inline typename Gaudi::Utils::GetData<TYPE>::return_type
26 GaudiCommon<PBASE>::get( IDataProviderSvc* service, const std::string& location, const bool useRootInTES ) const {
27 // check the environment
28 Assert( service, "get():: IDataProvider* points to NULL!" );
29 // get the helper object:
30 Gaudi::Utils::GetData<TYPE> getter;
31 return getter( *this, service, this->fullTESLocation( location, useRootInTES ) );
32 }
33 // ============================================================================
34 // Templated access to the data in Gaudi Transient Store, no check on the content
35 // ============================================================================
36 template <class PBASE>
37 template <class TYPE>
38 inline typename Gaudi::Utils::GetData<TYPE>::return_type
39 GaudiCommon<PBASE>::getIfExists( IDataProviderSvc* service, const std::string& location,
40 const bool useRootInTES ) const {
41 // check the environment
42 Assert( service, "get():: IDataProvider* points to NULL!" );
43 // get the helper object:
44 Gaudi::Utils::GetData<TYPE> getter;
45 return getter( *this, service, this->fullTESLocation( location, useRootInTES ), false );
46 }
47 // ============================================================================
48 // check the existence of objects in Gaudi Transient Store
49 // ============================================================================
50 template <class PBASE>
51 template <class TYPE>
52 inline bool GaudiCommon<PBASE>::exist( IDataProviderSvc* service, const std::string& location,
53 const bool useRootInTES ) const {
54 // check the environment
55 Assert( service, "exist():: IDataProvider* points to NULL!" );
56 // check the data object
57 Gaudi::Utils::CheckData<TYPE> checker;
58 return checker( service, this->fullTESLocation( location, useRootInTES ) );
59 }
60 // ============================================================================
61 // get the existing object from Gaudi Event Transient store
62 // or create new object register in in TES and return if object
63 // does not exist
64 // ============================================================================
65 template <class PBASE>
66 template <class TYPE, class TYPE2>
67 inline typename Gaudi::Utils::GetData<TYPE>::return_type
68 GaudiCommon<PBASE>::getOrCreate( IDataProviderSvc* service, const std::string& location,
69 const bool useRootInTES ) const {
70 // check the environment
71 Assert( service, "getOrCreate():: svc points to NULL!" );
72 // get the helper object
73 Gaudi::Utils::GetOrCreateData<TYPE, TYPE2> getter;
74 return getter( *this, service, this->fullTESLocation( location, useRootInTES ), location );
75 }
76 // ============================================================================
77 // the useful method for location of tools.
78 // ============================================================================
79 template <class PBASE>
80 template <class TOOL>
81 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type, const std::string& name, const IInterface* parent,
82 bool create ) const {
83 // for empty names delegate to another method
84 if ( name.empty() ) return tool<TOOL>( type, parent, create );
85 Assert( this->toolSvc(), "tool():: IToolSvc* points to NULL!" );
86 // get the tool from Tool Service
87 TOOL* Tool = nullptr;
88 const StatusCode sc = this->toolSvc()->retrieveTool( type, name, Tool, parent, create );
89 if ( sc.isFailure() ) { Exception( "tool():: Could not retrieve Tool '" + type + "'/'" + name + "'", sc ); }
90 if ( !Tool ) { Exception( "tool():: Could not retrieve Tool '" + type + "'/'" + name + "'" ); }
91 // insert tool into list of tools
92 PBASE::registerTool( Tool );
93 m_managedTools.push_back( Tool );
94 // return *VALID* located tool
95 return Tool;
96 }
97 // ============================================================================
98 // the useful method for location of tools.
99 // ============================================================================
100 template <class PBASE>
101 template <class TOOL>
102 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type, const IInterface* parent, bool create ) const {
103 // check the environment
104 Assert( PBASE::toolSvc(), "IToolSvc* points to NULL!" );
105 // retrieve the tool from Tool Service
106 TOOL* Tool = nullptr;
107 const StatusCode sc = this->toolSvc()->retrieveTool( type, Tool, parent, create );
108 if ( sc.isFailure() ) { Exception( "tool():: Could not retrieve Tool '" + type + "'", sc ); }
109 if ( !Tool ) { Exception( "tool():: Could not retrieve Tool '" + type + "'" ); }
110 // add the tool into the list of known tools to be properly released
111 PBASE::registerTool( Tool );
112 m_managedTools.push_back( Tool );
113 // return *VALID* located tool
114 return Tool;
115 }
116 // ============================================================================
117 // the useful method for location of services
118 // ============================================================================
119 template <class PBASE>
120 template <class SERVICE>
121 inline SmartIF<SERVICE> GaudiCommon<PBASE>::svc( const std::string& name, const bool create ) const {
122 Assert( this->svcLoc(), "ISvcLocator* points to NULL!" );
123 SmartIF<SERVICE> s;
124 // check if we already have this service
125 auto it = std::lower_bound( std::begin( m_services ), std::end( m_services ), name, GaudiCommon_details::svc_lt );
126 if ( it != std::end( m_services ) && GaudiCommon_details::svc_eq( *it, name ) ) {
127 // Try to get the requested interface
128 s = *it;
129 // check the results
130 if ( !s ) { Exception( "svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE ); }
131 } else {
132 auto baseSvc = this->svcLoc()->service( name, create );
133 // Try to get the requested interface
134 s = baseSvc;
135 // check the results
136 if ( !baseSvc || !s ) { Exception( "svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE ); }
137 // add the tool into list of known tools, to be properly released
138 addToServiceList( baseSvc );
139 }
140 // return *VALID* located service
141 return s;
142 }
143 // ============================================================================
144 // Short-cut to get a pointer to the UpdateManagerSvc
145 // ============================================================================
146 template <class PBASE>
147 inline IUpdateManagerSvc* GaudiCommon<PBASE>::updMgrSvc() const {
148 if ( !m_updMgrSvc ) { m_updMgrSvc = svc<IUpdateManagerSvc>( "UpdateManagerSvc", true ); }
149 return m_updMgrSvc;
150 }
151 // ============================================================================
152 // Assertion - throw exception, if condition is not fulfilled
153 // ============================================================================
154 template <class PBASE>
155 inline void GaudiCommon<PBASE>::Assert( const bool ok, const std::string& msg, const StatusCode sc ) const {
156 if ( !ok ) Exception( msg, sc );
157 }
158 // ============================================================================
159 // Assertion - throw exception, if condition is not fulfilled
160 // ============================================================================
161 template <class PBASE>
162 inline void GaudiCommon<PBASE>::Assert( const bool ok, const char* msg, const StatusCode sc ) const {
163 if ( !ok ) Exception( msg, sc );
164 }
165 // ============================================================================
179 // ============================================================================
180 #define ALG_ERROR( message, code ) \
181 ( Error( message + std::string( " [ at line " ) + std::to_string( __LINE__ ) + std::string( " in file '" ) + \
182 std::string( __FILE__ ) + "']", \
183 code ) )
184
185 // ============================================================================
186 // The END
187 // ============================================================================
188 #endif // GAUDIALG_GAUDICOMMONIMP_H
GaudiCommon::updMgrSvc
IUpdateManagerSvc * updMgrSvc() const
Short-cut to locate the Update Manager Service.
Definition: GaudiCommonImp.h:147
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
GaudiCommon::getIfExists
Gaudi::Utils::GetData< TYPE >::return_type getIfExists(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Quicker version of the get function which bypasses the check on the retrieved data.
Definition: GaudiCommonImp.h:39
GaudiCommon::tool
TOOL * tool(const std::string &type, const std::string &name, const IInterface *parent=0, bool create=true) const
Useful method for the easy location of tools.
Definition: GaudiCommonImp.h:81
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
GaudiCommon_details::svc_eq
constexpr const struct GaudiCommon_details::svc_eq_t svc_eq
GaudiPython.HistoUtils.location
location
Definition: HistoUtils.py:936
Gaudi::Utils::GetData
Helper structure for implementation of "get"-functions for GaudiCommon<BASE>
Definition: GaudiCommon.h:53
std::end
T end(T... args)
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:43
std::lower_bound
T lower_bound(T... args)
GetData.h
GaudiCommon.h
std::string
STL class.
GaudiCommon::Assert
void Assert(const bool ok, const std::string &message="", const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
Assertion - throw exception if the given condition is not fulfilled.
Definition: GaudiCommonImp.h:155
GaudiCommon_details::svc_lt
constexpr const struct GaudiCommon_details::svc_lt_t svc_lt
Gaudi::Utils::CheckData
Helper structure for implementation of "exists"-functions for GaudiCommon<BASE>
Definition: GetData.h:314
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
IInterface
Definition of the basic interface.
Definition: IInterface.h:244
gaudirun.type
type
Definition: gaudirun.py:142
GaudiCommon::get
Gaudi::Utils::GetData< TYPE >::return_type get(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Templated access to the data in Gaudi Transient Store.
Definition: GaudiCommonImp.h:26
GaudiCommon::svc
SmartIF< SERVICE > svc(const std::string &name, const bool create=true) const
A useful method for the easy location of services.
Definition: GaudiCommonImp.h:121
Gaudi::Utils::GetOrCreateData
Helper structure for implementation of "getOrCreate"-functions for GaudiCommon<BASE>
Definition: GetData.h:388
FixTESPathDetails::fullTESLocation
std::string fullTESLocation(std::string_view location, std::string_view rit)
Definition: FixTESPath.cpp:40
IUpdateManagerSvc
Interface class to the Update Manager service.
Definition: IUpdateManagerSvc.h:132
std::begin
T begin(T... args)
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
gaudirun.s
string s
Definition: gaudirun.py:316
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
GaudiCommon::exist
bool exist(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Check the existence of a data object or container in the Gaudi Transient Event Store.
Definition: GaudiCommonImp.h:52
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
GaudiCommon::getOrCreate
Gaudi::Utils::GetData< TYPE >::return_type getOrCreate(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Get the existing data object from Gaudi Event Transient store.
Definition: GaudiCommonImp.h:68