Report problems to ATLAS LXR Team (with time and IP address indicated)

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: linux ]
Version: head ] [ nightly ] [ GaudiDev ]
  Links to LXR source navigation pages for stable releases [ 12.*.* ]   [ 13.*.* ]   [ 14.*.* ]   [ 15.*.* ] 

001 // $Id: GaudiCommonImp.h,v 1.11 2008/10/10 08:06:33 marcocle Exp $
002 // ============================================================================
003 #ifndef GAUDIALG_GAUDICOMMONIMP_H
004 #define GAUDIALG_GAUDICOMMONIMP_H 1
005 // ============================================================================
006 // Include files
007 // ============================================================================
008 // GaudiAlg
009 // ============================================================================
010 #include "GaudiAlg/GetData.h"
011 #include "GaudiAlg/GaudiCommon.h"
012 // ============================================================================
013 /** @file
014  *  The implementation of inline/templated methods for class GaudiCommon
015  *  @see    GaudiCommon
016  *  @author Vanya BELYAEV Ivan.Belyaev@itep.ru
017  *  @author Chris Jones   Christopher.Rob.Jones@cern.ch
018  *  @date   2004-01-19
019  */
020 // ============================================================================
021 // Returns the full correct event location given the rootInTes settings
022 // ============================================================================
023 template < class PBASE >
024 inline const std::string
025 GaudiCommon<PBASE>::fullTESLocation( const std::string & location,
026                                      const bool useRootInTES ) const
027 {
028   // The logic is:
029   // if no R.I.T., give back location
030   // if R.I.T., this is the mapping:
031   // (note that R.I.T. contains a trailing '/')
032   //  location       -> result
033   //  -------------------------------------------------
034   //  ""             -> R.I.T.[:-1]      ("rit")
035   //  "/Event"       -> R.I.T.[:-1]      ("rit")
036   //  "/Event/MyObj" -> R.I.T. + "MyObj" ("rit/MyObj")
037   //  "MyObj"        -> R.I.T. + "MyObj" ("rit/MyObj")
038   return ( !useRootInTES || rootInTES().empty() ?
039            location
040          :
041            location.empty() || ( location == "/Event" ) ?
042              rootInTES().substr(0,rootInTES().size()-1)
043            :
044              0 == location.find("/Event/") ?
045                rootInTES() + location.substr(7)
046              : 
047                rootInTES() + location );
048 }
049 // ============================================================================
050 // Templated access to the data in Gaudi Transient Store
051 // ============================================================================
052 template < class PBASE >
053 template < class TYPE  >
054 inline typename Gaudi::Utils::GetData<TYPE>::return_type
055 GaudiCommon<PBASE>::get( IDataProviderSvc*  service ,
056                          const std::string& location,
057                          const bool useRootInTES ) const
058 {
059   // check the environment
060   Assert( 0 != service ,    "get():: IDataProvider* points to NULL!"      ) ;
061   // get the helper object:
062   Gaudi::Utils::GetData<TYPE> helper ;
063   return helper ( *this , service , 
064                   fullTESLocation ( location , useRootInTES ) ) ;
065 }
066 // ============================================================================
067 // check the existence of objects in Gaudi Transient Store
068 // ============================================================================
069 template < class PBASE >
070 template < class TYPE  >
071 inline bool GaudiCommon<PBASE>::exist( IDataProviderSvc*  service  ,
072                                        const std::string& location ,
073                                        const bool useRootInTES ) const
074 {
075   // check the environment
076   Assert( 0 != service , "exist():: IDataProvider* points to NULL!"      ) ;
077   // check the data object
078   const std::string & fullLoc = fullTESLocation( location, useRootInTES );
079   SmartDataPtr<TYPE> obj( service , fullLoc ) ;
080   return obj ? true : false ;
081 }
082 // ============================================================================
083 
084 // ============================================================================
085 // get the existing object from Gaudi Event Transient store
086 // or create new object register in in TES and return if object
087 // does not exist
088 // ============================================================================
089 template <class PBASE>
090 template <class TYPE,class TYPE2>
091 inline TYPE* GaudiCommon<PBASE>::getOrCreate( IDataProviderSvc* svc ,
092                                               const std::string& location ,
093                                               const bool useRootInTES  ) const
094 {
095   // check the environment
096   Assert( 0 != svc , "getOrCreate():: svc points to NULL!" ) ;
097   const std::string & fullLoc = fullTESLocation( location, useRootInTES );
098   SmartDataPtr<TYPE> obj ( svc , fullLoc ) ;
099   if ( !obj )
100   {
101     TYPE2* o = new TYPE2() ;
102     put ( svc , o , location ) ; // do not use fullLoc here as put recreates it
103     return o ;
104   }
105   TYPE* aux = obj ;
106   if( !aux )
107   { Exception ( "getOrCreate():: No valid data at '" + fullLoc + "'" ) ; }
108   // return located *VALID* data
109   return aux ;
110 }
111 // ============================================================================
112 
113 // ============================================================================
114 // the useful method for location of tools.
115 // ============================================================================
116 template < class PBASE >
117 template < class TOOL  >
118 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type           ,
119                                        const std::string& name           ,
120                                        const IInterface*  parent         ,
121                                        bool               create         ) const
122 {
123   TOOL* Tool = 0 ;
124   // for empty names delegate to another method
125   if ( name.empty() )
126   {
127     Tool = tool<TOOL>( type , parent , create ) ;
128   }
129   else
130   {
131     Assert( 0 != this->toolSvc() , "tool():: IToolSvc* points to NULL!" ) ;
132     // get the tool from Tool Service
133     const StatusCode sc =
134       this->toolSvc()->retrieveTool ( type , name , Tool , parent , create ) ;
135     if ( sc.isFailure() )
136     { Exception("tool():: Could not retrieve Tool '" + type + "'/'" + name + "'", sc ) ; }
137     if ( 0 == Tool )
138     { Exception("tool():: Could not retrieve Tool '" + type + "'/'" + name + "'"     ) ; }
139     // add the tool into list of known tools to be properly released
140     addToToolList( Tool );
141   }
142   // return *VALID* located tool
143   return Tool ;
144 }
145 // ============================================================================
146 
147 // ============================================================================
148 // the useful method for location of tools.
149 // ============================================================================
150 template < class PBASE >
151 template < class TOOL  >
152 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type   ,
153                                        const IInterface*  parent ,
154                                        bool               create ) const
155 {
156   // check the environment
157   Assert ( 0 != PBASE::toolSvc() , "IToolSvc* points to NULL!" );
158   // retrieve the tool from Tool Service
159   TOOL* Tool = 0 ;
160   const StatusCode sc =
161     this->toolSvc() -> retrieveTool ( type, Tool, parent , create   );
162   if ( sc.isFailure() )
163   { Exception("tool():: Could not retrieve Tool '" + type + "'", sc ) ; }
164   if ( 0 == Tool )
165   { Exception("tool():: Could not retrieve Tool '" + type + "'"     ) ; }
166   // add the tool into the list of known tools to be properly released
167   addToToolList( Tool );
168   // return *VALID* located tool
169   return Tool ;
170 }
171 // ============================================================================
172 
173 // ============================================================================
174 // the useful method for location of services
175 // ============================================================================
176 template < class PBASE   >
177 template < class SERVICE >
178 inline SERVICE* GaudiCommon<PBASE>::svc( const std::string& name   ,
179                                          const bool         create ) const
180 {
181   SERVICE* s = 0 ;
182   Assert ( 0 != this->svcLoc() , "ISvcLocator* points to NULL!" );
183   // retrieve the service using templated method Algorithm::service
184   StatusCode sc = this->svcLoc() -> service( name , s , create ) ;
185   // check the results
186   if ( sc.isFailure() )
187   { Exception ( "svc():: Could not retrieve Svc '" + name + "'", sc ) ; }
188   if ( 0 == s         )
189   { Exception ( "svc():: Could not retrieve Svc '" + name + "'"     ) ; }
190   // add the tool into list of known tools, to be properly released
191   addToServiceList( s, name  ) ;
192   // return *VALID* located service
193   return s ;
194 }
195 // ============================================================================
196 
197 // ============================================================================
198 // Short-cut  to get a pointer to the UpdateManagerSvc
199 // ============================================================================
200 template <class PBASE>
201 inline IUpdateManagerSvc *
202 GaudiCommon<PBASE>::updMgrSvc() const
203 {
204   if ( !m_updMgrSvc )
205   { m_updMgrSvc = svc<IUpdateManagerSvc>("UpdateManagerSvc",true); }
206   return m_updMgrSvc ;
207 }
208 // ============================================================================
209 
210 // ============================================================================
211 // Short-cut  to get a pointer to the
212 // ============================================================================
213 template <class PBASE>
214 inline IDataProviderSvc *
215 GaudiCommon<PBASE>::fastContainersSvc() const
216 {
217   if ( !m_fastContainersSvc )
218   { m_fastContainersSvc = svc<IDataProviderSvc>("FastContainersSvc",true); }
219   return m_fastContainersSvc ;
220 }
221 
222 // ============================================================================
223 // Get a fast container
224 // ============================================================================
225 template < class PBASE   >
226 template < class T >
227 inline TransientFastContainer<T> *
228 GaudiCommon<PBASE>::getFastContainer( const std::string &location,
229                                       typename TransientFastContainer<T>::size_type initial )
230 {
231   typedef TransientFastContainer<T> container_type;
232 
233   IDataProviderSvc* svc = fastContainersSvc();
234   Assert( 0 != svc , "getFastContainer(): cannot get FastContainersSvc" );
235 
236   container_type *ptr = NULL;
237   SmartDataPtr<container_type> obj( svc, location );
238   if (!obj){
239     ptr = new container_type(initial);
240     StatusCode status = svc->registerObject(location,ptr);
241     if ( !status.isSuccess() ){
242       Exception("getFastContainer(): cannot register '" +
243                 System::typeinfoName( typeid( *ptr ) ) +
244                 "' at address '" + location + "'"  , status );
245     }
246   } else {
247     ptr = obj;
248     if ( !ptr ){
249       Exception("getFastContainer(): No valid container at '" + location + "'");
250     }
251   }
252 
253   return ptr;
254 }
255 // ============================================================================
256 
257 // ============================================================================
258 // predefined configurable message stream for the effective printouts
259 // ============================================================================
260 template <class PBASE>
261 inline MsgStream&
262 GaudiCommon<PBASE>::msgStream ( const MSG::Level level ) const
263 {
264   if ( !m_msgStream )
265   { m_msgStream = new MsgStream ( PBASE::msgSvc() , this->name() ) ; }
266   return *m_msgStream << level ;
267 }
268 // ============================================================================
269 
270 // ============================================================================
271 // Assertion - throw exception, if condition is not fulfilled
272 // ============================================================================
273 template <class PBASE>
274 inline StatusCode GaudiCommon<PBASE>::Assert( const bool         OK  ,
275                                               const std::string& msg ,
276                                               const StatusCode   sc  ) const
277 {
278   return ( OK ? StatusCode(StatusCode::SUCCESS, true) : Exception( msg , sc ) ) ;
279 }
280 // ============================================================================
281 
282 // ============================================================================
283 // Delete the current message stream object
284 // ============================================================================
285 template <class PBASE>
286 inline void GaudiCommon<PBASE>::resetMsgStream() const
287 {
288   if ( 0 != m_msgStream ) { delete m_msgStream; m_msgStream = 0; }
289 }
290 // ============================================================================
291 
292 // ============================================================================
293 // Assertion - throw exception, if condition is not fulfilled
294 // ============================================================================
295 template <class PBASE>
296 inline StatusCode
297 GaudiCommon<PBASE>::Assert( const bool        OK  ,
298                             const char*       msg ,
299                             const StatusCode  sc  ) const
300 {
301   return OK ? StatusCode(StatusCode::SUCCESS, true) : Exception( msg , sc ) ;
302 }
303 // ============================================================================
304 
305 // ============================================================================
306 /** @def ALG_ERROR
307  *  Small and simple macro to add into error message the file name
308  *  and the line number for easy location of the problematic lines.
309  *
310  *  @code
311  *
312  *  if ( a < 0 ) { return ALG_ERROR( "'a' is negative" , 301 ) ; }
313  *
314  *  @endcode
315  *
316  *  @author Vanya BELYAEV Ivan.Belyaev@itep.ru
317  *  @date 2002-10-29
318  */
319 // ============================================================================
320 #define ALG_ERROR( message , code )                                     \
321   ( Error( message                                   +                  \
322            std::string             ( " [ at line " ) +                  \
323            GaudiAlg::fileLine      (   __LINE__    ) +                  \
324            std::string             ( " in file '"  ) +                  \
325            std::string             (   __FILE__    ) + "']" , code ) )
326 
327 // ============================================================================
328 
329 #endif // GAUDIALG_GAUDICOMMONIMP_H
330 

source navigation ] diff markup ] identifier search ] general search ]

Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems
This page was automatically generated by the LXR engine. Valid HTML 4.01!