The Gaudi Framework  v32r2 (46d42edc)
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>
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:
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>
40  const bool useRootInTES ) const {
41  // check the environment
42  Assert( service, "get():: IDataProvider* points to NULL!" );
43  // get the helper object:
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>
53  const bool useRootInTES ) const {
54  // check the environment
55  Assert( service, "exist():: IDataProvider* points to NULL!" );
56  // check the data object
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>
69  const bool useRootInTES ) const {
70  // check the environment
71  Assert( service, "getOrCreate():: svc points to NULL!" );
72  // get the helper object
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!" );
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>
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
IUpdateManagerSvc * updMgrSvc() const
Short-cut to locate the Update Manager Service.
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
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.
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.
constexpr const struct GaudiCommon_details::svc_eq_t svc_eq
Helper structure for implementation of "get"-functions for GaudiCommon<BASE>
Definition: GaudiCommon.h:53
T end(T... args)
Data provider interface definition.
T lower_bound(T... args)
STL class.
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.
constexpr const struct GaudiCommon_details::svc_lt_t svc_lt
Helper structure for implementation of "exists"-functions for GaudiCommon<BASE>
Definition: GetData.h:314
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Definition of the basic interface.
Definition: IInterface.h:244
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.
SmartIF< SERVICE > svc(const std::string &name, const bool create=true) const
A useful method for the easy location of services.
Helper structure for implementation of "getOrCreate"-functions for GaudiCommon<BASE>
Definition: GetData.h:388
std::string fullTESLocation(std::string_view location, std::string_view rit)
Definition: FixTESPath.cpp:46
Interface class to the Update Manager service.
T begin(T... args)
string s
Definition: gaudirun.py:318
constexpr static const auto FAILURE
Definition: StatusCode.h:86
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.
bool isFailure() const
Definition: StatusCode.h:130
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.