| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaudiCommonImp.h
Go to the documentation of this file.
1 // $Id: GaudiCommonImp.h,v 1.11 2008/10/10 08:06:33 marcocle Exp $
2 // ============================================================================
3 #ifndef GAUDIALG_GAUDICOMMONIMP_H
4 #define GAUDIALG_GAUDICOMMONIMP_H 1
5 // ============================================================================
6 // Include files
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 >
54 inline typename Gaudi::Utils::GetData<TYPE>::return_type
55 GaudiCommon<PBASE>::get( IDataProviderSvc* service ,
56 const std::string& location,
57 const bool useRootInTES ) const
58 {
59 // check the environment
60 Assert( 0 != service , "get():: IDataProvider* points to NULL!" ) ;
61 // get the helper object:
62 Gaudi::Utils::GetData<TYPE> getter ;
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 >
72 inline typename Gaudi::Utils::GetData<TYPE>::return_type
73 GaudiCommon<PBASE>::getIfExists( IDataProviderSvc* service ,
74 const std::string& location,
75 const bool useRootInTES ) const
76 {
77 // check the environment
78 Assert( 0 != service , "get():: IDataProvider* points to NULL!" ) ;
79 // get the helper object:
80 Gaudi::Utils::GetData<TYPE> getter ;
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( 0 != service , "exist():: IDataProvider* points to NULL!" ) ;
97 // check the data object
98 Gaudi::Utils::CheckData<TYPE> checker ;
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>
109 inline typename Gaudi::Utils::GetData<TYPE>::return_type
110 GaudiCommon<PBASE>::getOrCreate( IDataProviderSvc* service ,
111 const std::string& location ,
112 const bool useRootInTES ) const
113 {
114 // check the environment
115 Assert ( 0 != service , "getOrCreate():: svc points to NULL!" ) ;
116 // get the helper object
117 Gaudi::Utils::GetOrCreateData<TYPE,TYPE2> getter ;
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 TOOL* Tool = 0 ;
134 // for empty names delegate to another method
135 if ( name.empty() )
136 {
137 Tool = tool<TOOL>( type , parent , create ) ;
138 }
139 else
140 {
141 Assert( this->toolSvc() != 0, "tool():: IToolSvc* points to NULL!" ) ;
142 // get the tool from Tool Service
143 const StatusCode sc =
144 this->toolSvc()->retrieveTool ( type , name , Tool , parent , create ) ;
145 if ( sc.isFailure() )
146 { Exception("tool():: Could not retrieve Tool '" + type + "'/'" + name + "'", sc ) ; }
147 if ( 0 == Tool )
148 { Exception("tool():: Could not retrieve Tool '" + type + "'/'" + name + "'" ) ; }
149 // add the tool into list of known tools to be properly released
150 addToToolList( Tool );
151 }
152 // return *VALID* located tool
153 return Tool ;
154 }
155 // ============================================================================
156 // the useful method for location of tools.
157 // ============================================================================
158 template < class PBASE >
159 template < class TOOL >
160 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type ,
161 const IInterface* parent ,
162 bool create ) const
163 {
164 // check the environment
165 Assert ( PBASE::toolSvc() != 0, "IToolSvc* points to NULL!" );
166 // retrieve the tool from Tool Service
167 TOOL* Tool = 0 ;
168 const StatusCode sc =
169 this->toolSvc() -> retrieveTool ( type, Tool, parent , create );
170 if ( sc.isFailure() )
171 { Exception("tool():: Could not retrieve Tool '" + type + "'", sc ) ; }
172 if ( 0 == Tool )
173 { Exception("tool():: Could not retrieve Tool '" + type + "'" ) ; }
174 // add the tool into the list of known tools to be properly released
175 addToToolList( Tool );
176 // return *VALID* located tool
177 return Tool ;
178 }
179 // ============================================================================
180 // the useful method for location of services
181 // ============================================================================
182 template < class PBASE >
183 template < class SERVICE >
184 inline SmartIF<SERVICE> GaudiCommon<PBASE>::svc( const std::string& name ,
185 const bool create ) const
186 {
187 Assert ( this->svcLoc() != 0, "ISvcLocator* points to NULL!" );
188 SmartIF<SERVICE> s;
189 // check if we already have this service
190 Services::iterator it = m_services.find(name);
191 if (it != m_services.end()) {
192 // Try to get the requested interface
193 s = it->second;
194 // check the results
195 if ( !s.isValid() ) {
196 Exception ("svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE);
197 }
198 } else {
199 SmartIF<IService>& baseSvc = this->svcLoc()->service(name, create);
200 // Try to get the requested interface
201 s = baseSvc;
202 // check the results
203 if ( !baseSvc.isValid() || !s.isValid() ) {
204 Exception ("svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE);
205 }
206 // add the tool into list of known tools, to be properly released
207 addToServiceList(baseSvc);
208 }
209 // return *VALID* located service
210 return s;
211 }
212 // ============================================================================
213 // Short-cut to get a pointer to the UpdateManagerSvc
214 // ============================================================================
215 template <class PBASE>
216 inline IUpdateManagerSvc *
217 GaudiCommon<PBASE>::updMgrSvc() const
218 {
219 if ( !m_updMgrSvc )
220 { m_updMgrSvc = svc<IUpdateManagerSvc>("UpdateManagerSvc",true); }
221 return m_updMgrSvc ;
222 }
223 // ============================================================================
224 // predefined configurable message stream for the effective printouts
225 // ============================================================================
226 template <class PBASE>
227 inline MsgStream&
228 GaudiCommon<PBASE>::msgStream ( const MSG::Level level ) const
229 {
230 if ( !m_msgStream )
231 { m_msgStream = new MsgStream ( PBASE::msgSvc() , this->name() ) ; }
232 return *m_msgStream << level ;
233 }
234 // ============================================================================
235 // Assertion - throw exception, if condition is not fulfilled
236 // ============================================================================
237 template <class PBASE>
238 inline void GaudiCommon<PBASE>::Assert( const bool ok ,
239 const std::string& msg ,
240 const StatusCode sc ) const
241 {
242 if (!ok) Exception( msg , sc );
243 }
244 // ============================================================================
245 // Delete the current message stream object
246 // ============================================================================
247 template <class PBASE>
248 inline void GaudiCommon<PBASE>::resetMsgStream() const
249 {
250 if ( 0 != m_msgStream ) { delete m_msgStream; m_msgStream = 0; }
251 }
252 // ============================================================================
253 // Assertion - throw exception, if condition is not fulfilled
254 // ============================================================================
255 template <class PBASE>
256 inline void GaudiCommon<PBASE>::Assert( const bool ok ,
257 const char* msg ,
258 const StatusCode sc ) const
259 {
260 if (!ok) Exception( msg , sc );
261 }
262 // ============================================================================
276 // ============================================================================
277 #define ALG_ERROR( message , code ) \
278 ( Error( message + \
279 std::string ( " [ at line " ) + \
280 GaudiAlg::fileLine ( __LINE__ ) + \
281 std::string ( " in file '" ) + \
282 std::string ( __FILE__ ) + "']" , code ) )
283
284 // ============================================================================
285 // The END
286 // ============================================================================
287 #endif // GAUDIALG_GAUDICOMMONIMP_H