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/GetData.h"
11 #include "GaudiAlg/GaudiCommon.h"
12 // ============================================================================
20 // ============================================================================
21 // Returns the full correct event location given the rootInTes settings
22 // ============================================================================
23 template < class PBASE >
24 inline const std::string
25 GaudiCommon<PBASE>::fullTESLocation( const std::string & location,
26  const bool useRootInTES ) const
27 {
28  // The logic is:
29  // if no R.I.T., give back location
30  // if R.I.T., this is the mapping:
31  // (note that R.I.T. contains a trailing '/')
32  // location -> result
33  // -------------------------------------------------
34  // "" -> R.I.T.[:-1] ("rit")
35  // "/Event" -> R.I.T.[:-1] ("rit")
36  // "/Event/MyObj" -> R.I.T. + "MyObj" ("rit/MyObj")
37  // "MyObj" -> R.I.T. + "MyObj" ("rit/MyObj")
38  return ( !useRootInTES || rootInTES().empty() ?
39  location
40  :
41  location.empty() || ( location == "/Event" ) ?
42  rootInTES().substr(0,rootInTES().size()-1)
43  :
44  0 == location.find("/Event/") ?
45  rootInTES() + location.substr(7)
46  :
47  rootInTES() + location );
48 }
49 // ============================================================================
50 // Templated access to the data in Gaudi Transient Store
51 // ============================================================================
52 template < class PBASE >
53 template < class TYPE >
56  const std::string& location,
57  const bool useRootInTES ) const
58 {
59  // check the environment
60  Assert( service , "get():: IDataProvider* points to NULL!" ) ;
61  // get the helper object:
63  return getter ( *this ,
64  service ,
65  fullTESLocation ( location , useRootInTES ) ) ;
66 }
67 // ============================================================================
68 // Templated access to the data in Gaudi Transient Store, no check on the content
69 // ============================================================================
70 template < class PBASE >
71 template < class TYPE >
74  const std::string& location,
75  const bool useRootInTES ) const
76 {
77  // check the environment
78  Assert( service , "get():: IDataProvider* points to NULL!" ) ;
79  // get the helper object:
81  return getter ( *this ,
82  service ,
83  fullTESLocation ( location , useRootInTES ),
84  false) ;
85 }
86 // ============================================================================
87 // check the existence of objects in Gaudi Transient Store
88 // ============================================================================
89 template < class PBASE >
90 template < class TYPE >
91 inline bool GaudiCommon<PBASE>::exist( IDataProviderSvc* service ,
92  const std::string& location ,
93  const bool useRootInTES ) const
94 {
95  // check the environment
96  Assert( service , "exist():: IDataProvider* points to NULL!" ) ;
97  // check the data object
99  return checker ( service,
100  fullTESLocation ( location , useRootInTES ) ) ;
101 }
102 // ============================================================================
103 // get the existing object from Gaudi Event Transient store
104 // or create new object register in in TES and return if object
105 // does not exist
106 // ============================================================================
107 template <class PBASE>
108 template <class TYPE,class TYPE2>
111  const std::string& location ,
112  const bool useRootInTES ) const
113 {
114  // check the environment
115  Assert ( service , "getOrCreate():: svc points to NULL!" ) ;
116  // get the helper object
118  return getter ( *this ,
119  service ,
120  fullTESLocation( location, useRootInTES ) ,
121  location ) ;
122 }
123 // ============================================================================
124 // the useful method for location of tools.
125 // ============================================================================
126 template < class PBASE >
127 template < class TOOL >
128 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type ,
129  const std::string& name ,
130  const IInterface* parent ,
131  bool create ) const
132 {
133  // for empty names delegate to another method
134  if ( name.empty() ) return tool<TOOL>( type , parent , create ) ;
135  Assert( this->toolSvc(), "tool():: IToolSvc* points to NULL!" ) ;
136  // get the tool from Tool Service
137  TOOL* Tool = nullptr ;
138  const StatusCode sc =
139  this->toolSvc()->retrieveTool ( type , name , Tool , parent , create ) ;
140  if ( sc.isFailure() )
141  { Exception("tool():: Could not retrieve Tool '" + type + "'/'" + name + "'", sc ) ; }
142  if ( !Tool )
143  { Exception("tool():: Could not retrieve Tool '" + type + "'/'" + name + "'" ) ; }
144  // add the tool into list of known tools to be properly released
145  addToToolList( Tool );
146  // return *VALID* located tool
147  return Tool ;
148 }
149 // ============================================================================
150 // the useful method for location of tools.
151 // ============================================================================
152 template < class PBASE >
153 template < class TOOL >
154 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type ,
155  const IInterface* parent ,
156  bool create ) const
157 {
158  // check the environment
159  Assert ( PBASE::toolSvc(), "IToolSvc* points to NULL!" );
160  // retrieve the tool from Tool Service
161  TOOL* Tool = nullptr ;
162  const StatusCode sc =
163  this->toolSvc() -> retrieveTool ( type, Tool, parent , create );
164  if ( sc.isFailure() )
165  { Exception("tool():: Could not retrieve Tool '" + type + "'", sc ) ; }
166  if ( !Tool )
167  { Exception("tool():: Could not retrieve Tool '" + type + "'" ) ; }
168  // add the tool into the list of known tools to be properly released
169  addToToolList( Tool );
170  // return *VALID* located tool
171  return Tool ;
172 }
173 // ============================================================================
174 // the useful method for location of services
175 // ============================================================================
176 template < class PBASE >
177 template < class SERVICE >
178 inline SmartIF<SERVICE> GaudiCommon<PBASE>::svc( const std::string& name ,
179  const bool create ) const
180 {
181  Assert ( this->svcLoc(), "ISvcLocator* points to NULL!" );
183  // check if we already have this service
184  auto it = std::lower_bound( std::begin(m_services), std::end(m_services), name, GaudiCommon_details::svc_lt );
185  if ( it != std::end(m_services) && GaudiCommon_details::svc_eq(*it,name) ) {
186  // Try to get the requested interface
187  s = *it;
188  // check the results
189  if ( !s ) {
190  Exception ("svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE);
191  }
192  } else {
193  auto baseSvc = this->svcLoc()->service(name, create);
194  // Try to get the requested interface
195  s = baseSvc;
196  // check the results
197  if ( !baseSvc || !s ) {
198  Exception ("svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE);
199  }
200  // add the tool into list of known tools, to be properly released
201  addToServiceList(baseSvc);
202  }
203  // return *VALID* located service
204  return s;
205 }
206 // ============================================================================
207 // Short-cut to get a pointer to the UpdateManagerSvc
208 // ============================================================================
209 template <class PBASE>
210 inline IUpdateManagerSvc *
212 {
213  if ( !m_updMgrSvc )
214  { m_updMgrSvc = svc<IUpdateManagerSvc>("UpdateManagerSvc",true); }
215  return m_updMgrSvc ;
216 }
217 // ============================================================================
218 // Assertion - throw exception, if condition is not fulfilled
219 // ============================================================================
220 template <class PBASE>
221 inline void GaudiCommon<PBASE>::Assert( const bool ok ,
222  const std::string& msg ,
223  const StatusCode sc ) const
224 {
225  if (!ok) Exception( msg , sc );
226 }
227 // ============================================================================
228 // Delete the current message stream object
229 // ============================================================================
230 template <class PBASE>
231 inline void GaudiCommon<PBASE>::resetMsgStream() const
232 {
233  m_msgStream.reset();
234 }
235 // ============================================================================
236 // Assertion - throw exception, if condition is not fulfilled
237 // ============================================================================
238 template <class PBASE>
239 inline void GaudiCommon<PBASE>::Assert( const bool ok ,
240  const char* msg ,
241  const StatusCode sc ) const
242 {
243  if (!ok) Exception( msg , sc );
244 }
245 // ============================================================================
259 // ============================================================================
260 #define ALG_ERROR( message , code ) \
261  ( Error( message + \
262  std::string ( " [ at line " ) + \
263  std::to_string ( __LINE__ ) + \
264  std::string ( " in file '" ) + \
265  std::string ( __FILE__ ) + "']" , code ) )
266 
267 
268 // ============================================================================
269 // The END
270 // ============================================================================
271 #endif // GAUDIALG_GAUDICOMMONIMP_H
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:14
IUpdateManagerSvc * updMgrSvc() const
Short-cut to locate the Update Manager Service.
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
void resetMsgStream() const
Helper structure for implementation of "get"-functions for GaudiCommon
Definition: GaudiCommon.h:36
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.
Data provider interface definition.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
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 "exists"-functions for GaudiCommon
Definition: GetData.h:314
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Definition of the basic interface.
Definition: IInterface.h:234
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.
Helper structure for implementation of "getOrCreate"-functions for GaudiCommon ...
Definition: GetData.h:402
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.
constexpr const struct GaudiCommon_details::svc_eq_t svc_eq
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:246
const std::string fullTESLocation(const std::string &location, const bool useRootInTES) const
Returns the full correct event location given the rootInTes settings.
constexpr const struct GaudiCommon_details::svc_lt_t svc_lt
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.
string type
Definition: gaudirun.py:151