| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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