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 >
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:
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( 0 != 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 >
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
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 ( 0 != 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  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!" );
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 *
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&
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>
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
MsgStream & msgStream(const MSG::Level level) const
Predefined configurable message stream for the efficient printouts.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
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.
void resetMsgStream() const
Reset (delete) the current message stream object.
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
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:72
string type
Definition: gaudirun.py:126
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
Helper structure for implementation of "exists"-functions for GaudiCommon
Definition: GetData.h:316
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Definition of the basic interface.
Definition: IInterface.h:160
Helper structure for implementation of "getOrCreate"-functions for GaudiCommon ...
Definition: GetData.h:404
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.
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:210
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.