| The Gaudi Framework v28r2p1 (f1a77ff4)

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