The Gaudi Framework  v38r0 (2143aa4c)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GaudiCommonImp.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 \***********************************************************************************/
11 #ifndef GAUDIALG_GAUDICOMMONIMP_H
12 #define GAUDIALG_GAUDICOMMONIMP_H 1
13 // ============================================================================
14 // Include files
15 // ============================================================================
16 #include <algorithm>
17 // ============================================================================
18 // GaudiAlg
19 // ============================================================================
20 #include "GaudiAlg/GaudiCommon.h"
21 #include "GaudiAlg/GetData.h"
22 // ============================================================================
30 // ============================================================================
31 // Templated access to the data in Gaudi Transient Store
32 // ============================================================================
33 template <class PBASE>
34 template <class TYPE>
36 GaudiCommon<PBASE>::get( IDataProviderSvc* service, std::string_view location, const bool useRootInTES ) const {
37  // check the environment
38  Assert( service, "get():: IDataProvider* points to NULL!" );
39  // get the helper object:
41  return getter( *this, service, this->fullTESLocation( location, useRootInTES ) );
42 }
43 // ============================================================================
44 // Templated access to the data in Gaudi Transient Store, no check on the content
45 // ============================================================================
46 template <class PBASE>
47 template <class TYPE>
49 GaudiCommon<PBASE>::getIfExists( IDataProviderSvc* service, std::string_view location, const bool useRootInTES ) const {
50  // check the environment
51  Assert( service, "get():: IDataProvider* points to NULL!" );
52  // get the helper object:
54  return getter( *this, service, this->fullTESLocation( location, useRootInTES ), false );
55 }
56 // ============================================================================
57 // check the existence of objects in Gaudi Transient Store
58 // ============================================================================
59 template <class PBASE>
60 template <class TYPE>
61 bool GaudiCommon<PBASE>::exist( IDataProviderSvc* service, std::string_view location, const bool useRootInTES ) const {
62  // check the environment
63  Assert( service, "exist():: IDataProvider* points to NULL!" );
64  // check the data object
66  return checker( service, this->fullTESLocation( location, useRootInTES ) );
67 }
68 // ============================================================================
69 // get the existing object from Gaudi Event Transient store
70 // or create new object register in in TES and return if object
71 // does not exist
72 // ============================================================================
73 template <class PBASE>
74 template <class TYPE, class TYPE2>
76 GaudiCommon<PBASE>::getOrCreate( IDataProviderSvc* service, std::string_view location, const bool useRootInTES ) const {
77  // check the environment
78  Assert( service, "getOrCreate():: svc points to NULL!" );
79  // get the helper object
81  return getter( *this, service, this->fullTESLocation( location, useRootInTES ), location );
82 }
83 // ============================================================================
84 // the useful method for location of tools.
85 // ============================================================================
86 template <class PBASE>
87 template <class TOOL>
88 TOOL* GaudiCommon<PBASE>::tool( std::string_view type, std::string_view name, const IInterface* parent,
89  bool create ) const {
90  // for empty names delegate to another method
91  if ( name.empty() ) return tool<TOOL>( type, parent, create );
92  Assert( this->toolSvc(), "tool():: IToolSvc* points to NULL!" );
93  // get the tool from Tool Service
94  TOOL* Tool = nullptr;
95  const StatusCode sc = this->toolSvc()->retrieveTool( type, name, Tool, parent, create );
96  if ( sc.isFailure() ) {
97  Exception(
98  std::string{ "tool():: Could not retrieve Tool '" }.append( type ).append( "'/'" ).append( name ).append( "'" ),
99  sc );
100  }
101  if ( !Tool ) {
102  Exception( std::string{ "tool():: Could not retrieve Tool '" }.append( type ).append( "'/'" ).append( name ).append(
103  "'" ) );
104  }
105  // insert tool into list of tools
106  PBASE::registerTool( Tool );
107  m_managedTools.push_back( Tool );
108  // return *VALID* located tool
109  return Tool;
110 }
111 // ============================================================================
112 // the useful method for location of tools.
113 // ============================================================================
114 template <class PBASE>
115 template <class TOOL>
116 TOOL* GaudiCommon<PBASE>::tool( std::string_view type, const IInterface* parent, bool create ) const {
117  // check the environment
118  Assert( PBASE::toolSvc(), "IToolSvc* points to NULL!" );
119  // retrieve the tool from Tool Service
120  TOOL* Tool = nullptr;
121  const StatusCode sc = this->toolSvc()->retrieveTool( type, Tool, parent, create );
122  if ( sc.isFailure() ) {
123  Exception( std::string{ "tool():: Could not retrieve Tool '" }.append( type ).append( "'" ), sc );
124  }
125  if ( !Tool ) { Exception( std::string{ "tool():: Could not retrieve Tool '" }.append( type ).append( "'" ) ); }
126  // add the tool into the list of known tools to be properly released
127  PBASE::registerTool( Tool );
128  m_managedTools.push_back( Tool );
129  // return *VALID* located tool
130  return Tool;
131 }
132 // ============================================================================
133 // the useful method for location of services
134 // ============================================================================
135 template <class PBASE>
136 template <class SERVICE>
137 SmartIF<SERVICE> GaudiCommon<PBASE>::svc( std::string_view name, const bool create ) const {
138  Assert( this->svcLoc(), "ISvcLocator* points to NULL!" );
140  // check if we already have this service
141  auto it = std::lower_bound( std::begin( m_services ), std::end( m_services ), name, GaudiCommon_details::svc_lt );
142  if ( it != std::end( m_services ) && GaudiCommon_details::svc_eq( *it, name ) ) {
143  // Try to get the requested interface
144  s = *it;
145  // check the results
146  if ( !s ) {
147  Exception( std::string{ "svc():: Could not retrieve Svc '" }.append( name ).append( "'" ), StatusCode::FAILURE );
148  }
149  } else {
150  auto baseSvc = this->svcLoc()->service( name, create );
151  // Try to get the requested interface
152  s = baseSvc;
153  // check the results
154  if ( !baseSvc || !s ) {
155  Exception( std::string{ "svc():: Could not retrieve Svc '" }.append( name ).append( "'" ), StatusCode::FAILURE );
156  }
157  // add the tool into list of known tools, to be properly released
158  addToServiceList( baseSvc );
159  }
160  // return *VALID* located service
161  return s;
162 }
163 // ============================================================================
164 // Short-cut to get a pointer to the UpdateManagerSvc
165 // ============================================================================
166 template <class PBASE>
168  if ( !m_updMgrSvc ) { m_updMgrSvc = svc<IUpdateManagerSvc>( "UpdateManagerSvc", true ); }
169  return m_updMgrSvc;
170 }
171 // ============================================================================
172 // Assertion - throw exception, if condition is not fulfilled
173 // ============================================================================
174 template <class PBASE>
175 void GaudiCommon<PBASE>::Assert( const bool ok, std::string_view msg, const StatusCode sc ) const {
176  if ( !ok ) Exception( msg, sc );
177 }
178 // ============================================================================
192 // ============================================================================
193 #define ALG_ERROR( message, code ) \
194  ( Error( message + std::string( " [ at line " ) + std::to_string( __LINE__ ) + std::string( " in file '" ) + \
195  std::string( __FILE__ ) + "']", \
196  code ) )
197 
198 // ============================================================================
199 // The END
200 // ============================================================================
201 #endif // GAUDIALG_GAUDICOMMONIMP_H
GaudiCommon.h
Gaudi::Utils::CheckData
Definition: GetData.h:318
Gaudi::Utils::GetOrCreateData
Definition: GetData.h:393
std::string
STL class.
GaudiCommon::get
Gaudi::Utils::GetData< TYPE >::return_type get(IDataProviderSvc *svc, std::string_view location, const bool useRootInTES=true) const
Templated access to the data in Gaudi Transient Store.
Definition: GaudiCommonImp.h:36
GaudiAlg.HistoUtils.location
location
Definition: HistoUtils.py:964
bug_34121.name
name
Definition: bug_34121.py:20
GaudiCommon::Assert
void Assert(const bool ok, std::string_view message="", const StatusCode sc=StatusCode::FAILURE) const
Assertion - throw exception if the given condition is not fulfilled.
Definition: GaudiCommonImp.h:175
gaudirun.s
string s
Definition: gaudirun.py:346
Gaudi::Utils::GetData< TYPE >
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
GaudiCommon::tool
TOOL * tool(std::string_view type, std::string_view name, const IInterface *parent=0, bool create=true) const
Useful method for the easy location of tools.
Definition: GaudiCommonImp.h:88
GaudiCommon_details::svc_lt
constexpr const struct GaudiCommon_details::svc_lt_t svc_lt
FixTESPathDetails::fullTESLocation
std::string fullTESLocation(std::string_view location, std::string_view rit)
Definition: FixTESPath.cpp:56
GaudiCommon::getIfExists
Gaudi::Utils::GetData< TYPE >::return_type getIfExists(IDataProviderSvc *svc, std::string_view location, const bool useRootInTES=true) const
Quicker version of the get function which bypasses the check on the retrieved data.
Definition: GaudiCommonImp.h:49
GaudiCommon::svc
SmartIF< SERVICE > svc(std::string_view name, const bool create=true) const
A useful method for the easy location of services.
Definition: GaudiCommonImp.h:137
GaudiCommon::updMgrSvc
IUpdateManagerSvc * updMgrSvc() const
Short-cut to locate the Update Manager Service.
Definition: GaudiCommonImp.h:167
StatusCode
Definition: StatusCode.h:65
GaudiCommon_details::svc_eq
constexpr const struct GaudiCommon_details::svc_eq_t svc_eq
SmartIF
Definition: IConverter.h:25
GaudiCommon::exist
bool exist(IDataProviderSvc *svc, std::string_view location, const bool useRootInTES=true) const
Check the existence of a data object or container in the Gaudi Transient Event Store.
Definition: GaudiCommonImp.h:61
std::string::append
T append(T... args)
GetData.h
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
gaudirun.type
type
Definition: gaudirun.py:160
std::lower_bound
T lower_bound(T... args)
IUpdateManagerSvc
Definition: IUpdateManagerSvc.h:142
std::begin
T begin(T... args)
IInterface
Definition: IInterface.h:237
Gaudi::Utils::GetData::return_type
_GetType< Type >::return_type return_type
the actual return type
Definition: GetData.h:120
GaudiCommon::getOrCreate
Gaudi::Utils::GetData< TYPE >::return_type getOrCreate(IDataProviderSvc *svc, std::string_view location, const bool useRootInTES=true) const
Get the existing data object from Gaudi Event Transient store.
Definition: GaudiCommonImp.h:76
std::end
T end(T... args)
IDataProviderSvc
Definition: IDataProviderSvc.h:53
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101