Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 // Returns the full correct event location given the rootInTes settings
22 // ============================================================================
23 template <class PBASE>
25  const bool useRootInTES ) const {
26  // The logic is:
27  // if no R.I.T., give back location
28  // if R.I.T., this is the mapping:
29  // (note that R.I.T. contains a trailing '/')
30  // location -> result
31  // -------------------------------------------------
32  // "" -> R.I.T.[:-1] ("rit")
33  // "/Event" -> R.I.T.[:-1] ("rit")
34  // "/Event/MyObj" -> R.I.T. + "MyObj" ("rit/MyObj")
35  // "MyObj" -> R.I.T. + "MyObj" ("rit/MyObj")
36  return ( !useRootInTES || rootInTES().empty()
37  ? location
38  : location.empty() || ( location == "/Event" )
39  ? rootInTES().substr( 0, rootInTES().size() - 1 )
40  : 0 == location.find( "/Event/" )
41  ? rootInTES() + location.substr( 7 )
42  : location[0] == '/' ? rootInTES() + location.substr( 1 ) : rootInTES() + location );
43 }
44 // ============================================================================
45 // Templated access to the data in Gaudi Transient Store
46 // ============================================================================
47 template <class PBASE>
48 template <class TYPE>
50 GaudiCommon<PBASE>::get( IDataProviderSvc* service, const std::string& location, const bool useRootInTES ) const {
51  // check the environment
52  Assert( service, "get():: IDataProvider* points to NULL!" );
53  // get the helper object:
55  return getter( *this, service, fullTESLocation( location, useRootInTES ) );
56 }
57 // ============================================================================
58 // Templated access to the data in Gaudi Transient Store, no check on the content
59 // ============================================================================
60 template <class PBASE>
61 template <class TYPE>
64  const bool useRootInTES ) const {
65  // check the environment
66  Assert( service, "get():: IDataProvider* points to NULL!" );
67  // get the helper object:
69  return getter( *this, service, fullTESLocation( location, useRootInTES ), false );
70 }
71 // ============================================================================
72 // check the existence of objects in Gaudi Transient Store
73 // ============================================================================
74 template <class PBASE>
75 template <class TYPE>
77  const bool useRootInTES ) const {
78  // check the environment
79  Assert( service, "exist():: IDataProvider* points to NULL!" );
80  // check the data object
82  return checker( service, fullTESLocation( location, useRootInTES ) );
83 }
84 // ============================================================================
85 // get the existing object from Gaudi Event Transient store
86 // or create new object register in in TES and return if object
87 // does not exist
88 // ============================================================================
89 template <class PBASE>
90 template <class TYPE, class TYPE2>
93  const bool useRootInTES ) const {
94  // check the environment
95  Assert( service, "getOrCreate():: svc points to NULL!" );
96  // get the helper object
98  return getter( *this, service, fullTESLocation( location, useRootInTES ), location );
99 }
100 // ============================================================================
101 // the useful method for location of tools.
102 // ============================================================================
103 template <class PBASE>
104 template <class TOOL>
105 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type, const std::string& name, const IInterface* parent,
106  bool create ) const {
107  // for empty names delegate to another method
108  if ( name.empty() ) return tool<TOOL>( type, parent, create );
109  Assert( this->toolSvc(), "tool():: IToolSvc* points to NULL!" );
110  // get the tool from Tool Service
111  TOOL* Tool = nullptr;
112  const StatusCode sc = this->toolSvc()->retrieveTool( type, name, Tool, parent, create );
113  if ( sc.isFailure() ) { Exception( "tool():: Could not retrieve Tool '" + type + "'/'" + name + "'", sc ); }
114  if ( !Tool ) { Exception( "tool():: Could not retrieve Tool '" + type + "'/'" + name + "'" ); }
115  // insert tool into list of tools
116  PBASE::registerTool( Tool );
117  m_managedTools.push_back( Tool );
118  // return *VALID* located tool
119  return Tool;
120 }
121 // ============================================================================
122 // the useful method for location of tools.
123 // ============================================================================
124 template <class PBASE>
125 template <class TOOL>
126 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type, const IInterface* parent, bool create ) const {
127  // check the environment
128  Assert( PBASE::toolSvc(), "IToolSvc* points to NULL!" );
129  // retrieve the tool from Tool Service
130  TOOL* Tool = nullptr;
131  const StatusCode sc = this->toolSvc()->retrieveTool( type, Tool, parent, create );
132  if ( sc.isFailure() ) { Exception( "tool():: Could not retrieve Tool '" + type + "'", sc ); }
133  if ( !Tool ) { Exception( "tool():: Could not retrieve Tool '" + type + "'" ); }
134  // add the tool into the list of known tools to be properly released
135  PBASE::registerTool( Tool );
136  m_managedTools.push_back( Tool );
137  // return *VALID* located tool
138  return Tool;
139 }
140 // ============================================================================
141 // the useful method for location of services
142 // ============================================================================
143 template <class PBASE>
144 template <class SERVICE>
145 inline SmartIF<SERVICE> GaudiCommon<PBASE>::svc( const std::string& name, const bool create ) const {
146  Assert( this->svcLoc(), "ISvcLocator* points to NULL!" );
148  // check if we already have this service
149  auto it = std::lower_bound( std::begin( m_services ), std::end( m_services ), name, GaudiCommon_details::svc_lt );
150  if ( it != std::end( m_services ) && GaudiCommon_details::svc_eq( *it, name ) ) {
151  // Try to get the requested interface
152  s = *it;
153  // check the results
154  if ( !s ) { Exception( "svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE ); }
155  } else {
156  auto baseSvc = this->svcLoc()->service( name, create );
157  // Try to get the requested interface
158  s = baseSvc;
159  // check the results
160  if ( !baseSvc || !s ) { Exception( "svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE ); }
161  // add the tool into list of known tools, to be properly released
162  addToServiceList( baseSvc );
163  }
164  // return *VALID* located service
165  return s;
166 }
167 // ============================================================================
168 // Short-cut to get a pointer to the UpdateManagerSvc
169 // ============================================================================
170 template <class PBASE>
172  if ( !m_updMgrSvc ) { m_updMgrSvc = svc<IUpdateManagerSvc>( "UpdateManagerSvc", true ); }
173  return m_updMgrSvc;
174 }
175 // ============================================================================
176 // Assertion - throw exception, if condition is not fulfilled
177 // ============================================================================
178 template <class PBASE>
179 inline void GaudiCommon<PBASE>::Assert( const bool ok, const std::string& msg, const StatusCode sc ) const {
180  if ( !ok ) Exception( msg, sc );
181 }
182 // ============================================================================
183 // Assertion - throw exception, if condition is not fulfilled
184 // ============================================================================
185 template <class PBASE>
186 inline void GaudiCommon<PBASE>::Assert( const bool ok, const char* msg, const StatusCode sc ) const {
187  if ( !ok ) Exception( msg, sc );
188 }
189 // ============================================================================
203 // ============================================================================
204 #define ALG_ERROR( message, code ) \
205  ( Error( message + std::string( " [ at line " ) + std::to_string( __LINE__ ) + std::string( " in file '" ) + \
206  std::string( __FILE__ ) + "']", \
207  code ) )
208 
209 // ============================================================================
210 // The END
211 // ============================================================================
212 #endif // GAUDIALG_GAUDICOMMONIMP_H
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
T empty(T...args)
IUpdateManagerSvc * updMgrSvc() const
Short-cut to locate the Update Manager Service.
constexpr const struct GaudiCommon_details::svc_eq_t svc_eq
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.
Helper structure for implementation of "get"-functions for GaudiCommon<BASE>
Definition: GaudiCommon.h:54
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.
T end(T...args)
Data provider interface definition.
T lower_bound(T...args)
bool isFailure() const
Definition: StatusCode.h:130
constexpr auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
STL class.
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
Helper structure for implementation of "getOrCreate"-functions for GaudiCommon<BASE> ...
Definition: GetData.h:388
Interface class to the Update Manager service.
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.
T find(T...args)
T begin(T...args)
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.
string s
Definition: gaudirun.py:312
constexpr static const auto FAILURE
Definition: StatusCode.h:86
T substr(T...args)
const std::string fullTESLocation(const std::string &location, const bool useRootInTES) const
Returns the full correct event location given the rootInTes settings.
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.
SmartIF< SERVICE > svc(const std::string &name, const bool create=true) const
A useful method for the easy location of services.