| The Gaudi Framework v27r1

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

- File List
- File Members

GaudiAlgorithm.h
Go to the documentation of this file.
1 #ifndef GAUDIALG_GaudiAlgorithm_H
2 #define GAUDIALG_GaudiAlgorithm_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 #include <vector>
7 #include <string>
8 // ============================================================================
9 // GaudiKernel
10 // ============================================================================
11 #include "GaudiKernel/Algorithm.h"
12 // ============================================================================
13 // GaudiAlg
14 // ============================================================================
15 #include "GaudiAlg/GaudiAlg.h"
16 #include "GaudiAlg/GaudiCommon.h"
17 #include "GaudiKernel/DataObjectHandle.h"
18 // ============================================================================
19 // forward declarations:
20 // ============================================================================
21 class INTupleSvc ; // GaudiKernel
22 // ============================================================================
23 /* @file GaudiAlgorithm.h
24 *
25 * Header file for class GaudiAlgorithm.
26 * The actual code is mainly imported from
27 * - LHCb Calorimeter software and
28 * - LHCb C++ toolkit for smart and friendly physics analysis "LoKi"
29 *
30 * This base class allows "easy"(=="1 line") access to tools
31 * and services. This access is safe in the sense that there
32 * is no need to worry about the reference counts for tools
33 * and services.
34 *
35 * The base class allows "easy" (=="1 line") access to data in
36 * Gaudi Transient Stores. The functionality includes the checking
37 * of the presence of the data at the given location, checking the
38 * validity of the data, retrieval of valid data and "forced" retrieve
39 * of valid data (create if there is no data).
40 *
41 * The base class allows to perform an easy error, warning and exception
42 * treatments, including the accumulated statistics of exceptions, errors
43 * and warnings.
44 *
45 * The base class also includes utilities for general statistical counters.
46 *
47 * It has been reported that usage of this base class results in
48 * significant shrinkage of existing code lines.
49 *
50 * @attention
51 * See also the class GaudiCommon, which implements some of the common
52 * functionality between GaudiTool and GaudiAlgorithm.
53 *
54 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
55 * @author Chris Jones Christopher.Rob.Jones@cern.ch
56 * @date 30/06/2001
57 */
58 // ============================================================================
92 // ============================================================================
93 class GAUDI_API GaudiAlgorithm: public GaudiCommon<Algorithm>
94 {
95 public:
96 // ==========================================================================
102 StatusCode initialize() override;
103 // ==========================================================================
109 StatusCode execute () override;
110 // ==========================================================================
116 StatusCode finalize () override;
117 // ==========================================================================
124 StatusCode sysExecute () override;
125 // ==========================================================================
126 public:
127
128 // following methods cannot go in GaudiCommon since they use methods ( evtSvc()
129 // and detDvc() ) that are not members of AlgTool.
130 // Also some methods seem which are members of the base class do not seem
131 // to be found unless forwarding methods are put here ??
132
165 inline void put ( IDataProviderSvc* svc ,
166 DataObject* object ,
167 const std::string& address ,
168 const bool useRootInTES = true ) const
169 {
170 GaudiCommon<Algorithm>::put ( svc , object , address , useRootInTES ) ;
171 }
172
204 inline void put ( DataObject* object ,
205 const std::string& address ,
206 const bool useRootInTES = true ) const
207 {
208 GaudiCommon<Algorithm>::put ( evtSvc() , object , address , useRootInTES ) ;
209 }
210
243 template < class TYPE >
244 inline typename Gaudi::Utils::GetData<TYPE>::return_type
245 get ( IDataProviderSvc* svc ,
246 const std::string& location ,
247 const bool useRootInTES = true ) const
248 {
249 return GaudiCommon<Algorithm>::get<TYPE> ( svc , location , useRootInTES ) ;
250 }
251
285 template < class TYPE >
286 inline typename Gaudi::Utils::GetData<TYPE>::return_type
287 getIfExists ( IDataProviderSvc* svc ,
288 const std::string& location ,
289 const bool useRootInTES = true ) const
290 {
291 return GaudiCommon<Algorithm>::getIfExists<TYPE> ( svc , location , useRootInTES ) ;
292 }
293
320 template < class TYPE >
321 inline typename Gaudi::Utils::GetData<TYPE>::return_type
322 get ( const std::string& location,
323 const bool useRootInTES = true ) const
324 {
325 return GaudiCommon<Algorithm>::get<TYPE> ( evtSvc() , location , useRootInTES ) ;
326 }
327
360 template < class TYPE >
361 inline typename Gaudi::Utils::GetData<TYPE>::return_type
362 getIfExists ( const std::string& location ,
363 const bool useRootInTES = true ) const
364 {
365 return GaudiCommon<Algorithm>::getIfExists<TYPE> ( evtSvc() , location , useRootInTES ) ;
366 }
367
386 template < class TYPE >
387 inline TYPE* getDet ( IDataProviderSvc* svc ,
388 const std::string& location ) const
389 {
390 return GaudiCommon<Algorithm>::get<TYPE> ( svc , location , false ) ;
391 }
392
415 template < class TYPE >
416 inline typename Gaudi::Utils::GetData<TYPE>::return_type
417 getDetIfExists ( IDataProviderSvc* svc ,
418 const std::string& location ) const
419 {
420 return GaudiCommon<Algorithm>::getIfExists<TYPE> ( svc , location , false ) ;
421 }
422
440 template < class TYPE >
441 inline TYPE* getDet ( const std::string& location ) const
442 {
443 return GaudiCommon<Algorithm>::get<TYPE> ( detSvc() , location , false ) ;
444 }
445
467 template < class TYPE >
468 inline typename Gaudi::Utils::GetData<TYPE>::return_type
469 getDetIfExists ( const std::string& location ) const
470 {
471 return GaudiCommon<Algorithm>::getIfExists<TYPE> ( detSvc() , location , false ) ;
472 }
473
500 template < class TYPE >
501 inline bool exist ( IDataProviderSvc* svc ,
502 const std::string& location ,
503 const bool useRootInTES = true ) const
504 {
505 return GaudiCommon<Algorithm>::exist<TYPE> ( svc , location , useRootInTES ) ;
506 }
507
533 template < class TYPE >
534 inline bool exist ( const std::string& location ,
535 const bool useRootInTES = true ) const
536 {
537 return GaudiCommon<Algorithm>::exist<TYPE> ( evtSvc() , location , useRootInTES ) ;
538 }
539
556 template < class TYPE >
557 inline bool existDet ( IDataProviderSvc* svc ,
558 const std::string& location ) const
559 {
560 return GaudiCommon<Algorithm>::exist<TYPE> ( svc , location , false ) ;
561 }
562
578 template < class TYPE >
579 inline bool existDet ( const std::string& location ) const
580 {
581 return GaudiCommon<Algorithm>::exist<TYPE> ( detSvc() , location , false ) ;
582 }
583
611 template < class TYPE , class TYPE2 >
612 inline typename Gaudi::Utils::GetData<TYPE>::return_type
613 getOrCreate ( IDataProviderSvc* svc ,
614 const std::string& location ,
615 const bool useRootInTES = true ) const
616 {
617 return GaudiCommon<Algorithm>::getOrCreate<TYPE,TYPE2> ( svc , location , useRootInTES ) ;
618 }
619
646 template < class TYPE , class TYPE2 >
647 inline typename Gaudi::Utils::GetData<TYPE>::return_type
648 getOrCreate ( const std::string& location ,
649 const bool useRootInTES = true ) const
650 {
651 return GaudiCommon<Algorithm>::getOrCreate<TYPE,TYPE2> ( evtSvc() , location , useRootInTES ) ;
652 }
653 public:
654 // ==========================================================================
660 GaudiAlgorithm ( const std::string& name ,
661 ISvcLocator* pSvcLocator );
662 // ==========================================================================
664 ~GaudiAlgorithm() override = default;
665 // ==========================================================================
666 public:
667 // ==========================================================================
671 SmartIF<INTupleSvc>& evtColSvc () const;
672 // ==========================================================================
673 // no default/copy constructor, no assignment -- except that ROOT really
674 // wants a default constructor declared. So we define it, and don't implement
675 // it...
676 GaudiAlgorithm ( const GaudiAlgorithm& ) = delete;
677 GaudiAlgorithm& operator = ( const GaudiAlgorithm& ) = delete;
678 private :
679 GaudiAlgorithm() ;
680 // ==========================================================================
681 private:
682 // ==========================================================================
683 // Pointer to the Event Tag Collection Service
684 mutable SmartIF<INTupleSvc> m_evtColSvc ;
685 std::vector<std::string> m_vetoObjs;
688 std::vector<std::string> m_requireObjs;
689 // ==========================================================================
690
691 public:
692 using Algorithm::declareProperty;
693 template <class T>
694 Property* declareProperty
695 ( const std::string& name,
696 DataObjectHandle<T>& hndl,
697 const std::string& doc = "none" ) const
698 {
699
700 if ( hndl.mode() & Gaudi::DataHandle::Reader ) {
701 (const_cast<GaudiAlgorithm*>(this))->Algorithm::declareInput(&hndl);
702 }
703
704 if ( hndl.mode() & Gaudi::DataHandle::Writer ) {
705 (const_cast<GaudiAlgorithm*>(this))->Algorithm::declareOutput(&hndl);
706 }
707
708 if (hndl.owner() == 0) {
709 hndl.setOwner((const_cast<GaudiAlgorithm*>(this)));
710 }
711
712 return m_propertyMgr->declareProperty(name, hndl, doc);
713 }
714
715 };
716 // ============================================================================
717 // The END
718 // ============================================================================
719 #endif // GAUDIALG_GaudiAlgorithm_H
720 // ============================================================================
GaudiAlgorithm::exist
bool exist(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: GaudiAlgorithm.h:534
Algorithm.h
SmartIF< INTupleSvc >
GaudiAlgorithm::put
void put(IDataProviderSvc *svc, DataObject *object, const std::string &address, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
Definition: GaudiAlgorithm.h:165
GaudiAlgorithm::m_evtColSvc
SmartIF< INTupleSvc > m_evtColSvc
Event Tag Collection Service.
Definition: GaudiAlgorithm.h:684
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Gaudi::DataHandle::setOwner
virtual void setOwner(IDataHandleHolder *o)
Definition: DataHandle.h:44
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
GaudiCommon::put
DataObject * put(IDataProviderSvc *svc, DataObject *object, const std::string &location, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
Definition: GaudiCommon.icpp:686
GaudiAlgorithm::getOrCreate
Gaudi::Utils::GetData< TYPE >::return_type getOrCreate(const std::string &location, const bool useRootInTES=true) const
Get the existing data object from Gaudi Event Transient store.
Definition: GaudiAlgorithm.h:648
Gaudi::DataHandle::mode
virtual Mode mode() const
Definition: DataHandle.h:47
GaudiAlgorithm::getDet
TYPE * getDet(IDataProviderSvc *svc, const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiAlgorithm.h:387
GaudiAlgorithm::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: GaudiAlgorithm.h:501
Algorithm::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Algorithm.h:426
GaudiAlgorithm::getDet
TYPE * getDet(const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiAlgorithm.h:441
Gaudi::Utils::GetData
Helper structure for implementation of "get"-functions for GaudiCommon
Definition: GaudiCommon.h:36
GaudiCommon::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiCommon.icpp:280
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:45
GaudiAlgorithm::existDet
bool existDet(const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiAlgorithm.h:579
GaudiAlgorithm::getIfExists
Gaudi::Utils::GetData< TYPE >::return_type getIfExists(const std::string &location, const bool useRootInTES=true) const
Templated access to the data in Gaudi Transient Store.
Definition: GaudiAlgorithm.h:362
Gaudi::DataHandle::Reader
Definition: DataHandle.h:31
GaudiAlgorithm::existDet
bool existDet(IDataProviderSvc *svc, const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiAlgorithm.h:557
GaudiCommon.h
GaudiAlgorithm::getDetIfExists
Gaudi::Utils::GetData< TYPE >::return_type getDetIfExists(IDataProviderSvc *svc, const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiAlgorithm.h:417
std::string
STL class.
AnalysisTest.execute
def execute()
Definition: AnalysisTest.py:25
INTupleSvc
Definition: INTupleSvc.h:37
DataObjectHandle
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
Definition: AlgTool.h:24
GaudiAlgorithm::getDetIfExists
Gaudi::Utils::GetData< TYPE >::return_type getDetIfExists(const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiAlgorithm.h:469
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiAlgorithm::getIfExists
Gaudi::Utils::GetData< TYPE >::return_type getIfExists(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Templated access to the data in Gaudi Transient Store.
Definition: GaudiAlgorithm.h:287
GaudiAlgorithm
The useful base class for data processing algorithms.
Definition: GaudiAlgorithm.h:93
GaudiAlgorithm::put
void put(DataObject *object, const std::string &address, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
Definition: GaudiAlgorithm.h:204
GaudiAlg.h
GaudiCommon::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiCommon.icpp:186
GaudiAlgorithm::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: GaudiAlgorithm.h:613
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
std::vector< std::string >
GaudiCommon::operator=
GaudiCommon & operator=(const GaudiCommon &)=delete
Gaudi::DataHandle::Writer
Definition: DataHandle.h:32
GaudiCommon
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:73
GaudiAlgorithm::m_requireObjs
std::vector< std::string > m_requireObjs
process the event only if one or more of these objects are present in TES
Definition: GaudiAlgorithm.h:688
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:45
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
DataObjectHandle.h