Commit 6dd7825e authored by cvs2svn's avatar cvs2svn
Browse files

This commit was manufactured by cvs2svn to create branch 'GAUDI_v18r6b'.

git-svn-id: svn+ssh://svn.cern.ch/reps/gaudi/distribution/branches/GAUDI/GAUDI_v18r6b@3081 53ecefc3-a64d-0410-9bdf-b8581fa3287e
parent e4658526
// $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/AlgFactory.h,v 1.5 2006/01/10 20:03:57 hmd Exp $
#ifndef GAUDIKERNEL_ALGFACTORY_H
#define GAUDIKERNEL_ALGFACTORY_H
// Include files
#include "GaudiKernel/IAlgFactory.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/FactoryTable.h"
#include "GaudiKernel/System.h"
#include <string>
#include <typeinfo>
/** @class AlgFactory AlgFactory.h GaudiKernel/AlgFactory.h
The AlgFactory is a template for defining concrete algorithm factories
@author Pere Mato
*/
template <class ConcreteAlgorithm>
class AlgFactory : virtual public IAlgFactory {
std::string m_algType;
std::string m_ident;
public:
/// Default constructor
AlgFactory() {
// Get the class name using the RTTI.
m_algType = System::typeinfoName( typeid(ConcreteAlgorithm) );
m_ident = "Algorithm ";
m_ident += m_algType;
FactoryTable::instance()->addFactory( this );
}
/// Default Destructor
virtual ~AlgFactory() {
}
/// Service type name
virtual const std::string& algType() const {
return m_algType;
}
/// Create an instance of a concrete algorithm
virtual IAlgorithm* instantiate(const std::string& name, ISvcLocator *svcloc) const {
return new ConcreteAlgorithm(name, svcloc );
}
/// Create an instance of a generic Gaudi object: Method is disabled!
virtual IInterface* instantiate( IInterface *parent ) const {
ISvcLocator* svcloc = dynamic_cast<ISvcLocator*>(parent);
return new ConcreteAlgorithm(m_algType, svcloc );
return 0;
}
virtual unsigned long addRef() const {
return 1;
}
virtual unsigned long release() const {
return 1;
}
virtual const std::string& ident() const {
return m_ident;
}
/// IInterface implementation
virtual unsigned long addRef() {
return 1;
}
virtual unsigned long release() {
return 1;
}
virtual StatusCode queryInterface(const InterfaceID& riid, void** ppISvc) {
if( IID_IAlgFactory == riid ) {
*ppISvc = (IAlgFactory*) this;
}
else if ( IID_IFactory == riid ) {
*ppISvc = (IFactory *) this;
}
else if ( IID_IInterface == riid ) {
*ppISvc = (IInterface *) this;
}
else {
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}
};
// Macros to declare components
#define DECLARE_ALGORITHM(x) extern const IAlgFactory& x##Factory; x##Factory.addRef();
// Macros to declare components in a C++ namespace
#define DECLARE_NAMESPACE_ALGORITHM(n,x) extern const IAlgFactory& n##x##Factory; n##x##Factory.addRef();
// Macros to declare component factories
#define DECLARE_ALGORITHM_FACTORY(x) \
static const AlgFactory<x> s_##x##Factory; \
const IAlgFactory& x##Factory = s_##x##Factory;
// Macros to declare component factories in a C++ namespace
#define DECLARE_NAMESPACE_ALGORITHM_FACTORY(n,x) \
static const AlgFactory<n::x> s_##n##x##Factory; \
const IAlgFactory& n##x##Factory = s_##n##x##Factory;
#endif // GAUDIKERNEL_ALGFACTORY_H
// $Id: AlgTool.h,v 1.13 2006/06/06 16:16:23 hmd Exp $
#ifndef GAUDIKERNEL_ALGTOOL_H
#define GAUDIKERNEL_ALGTOOL_H
// Include files
#include "GaudiKernel/IAlgTool.h"
#include "GaudiKernel/IProperty.h"
#include "GaudiKernel/IService.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/IMessageSvc.h"
#include "GaudiKernel/IToolSvc.h"
#include "GaudiKernel/PropertyMgr.h"
#include <vector>
#include <list>
// Forward declarations
/** @class AlgTool AlgTool.h GaudiKernel/AlgTool.h
*
* Base class from which all the concrete tool classes
* should be derived. Specific methods for doing something
* usefull should be implemented in the concrete tools.
* Sub-types of this class could implement an additional
* interface for behaviour common to sets of concrete tools
* (for example vertexers).
*
* @author Gloria Corti
* @author Pere Mato
*/
class AlgTool : public virtual IAlgTool,
public virtual IProperty {
public:
/// Query for a given interface
virtual StatusCode queryInterface(const InterfaceID& riid, void** ppvUnknown);
/// Reference Interface instance.
virtual unsigned long addRef();
/// Release Interface instance.
virtual unsigned long release();
/// Retrieve full identifying name of the concrete tool object.
virtual const std::string& name() const;
/// Retrieve type (concrete class) of the sub-algtool.
virtual const std::string& type() const;
/// Retrieve parent of the sub-algtool.
virtual const IInterface* parent() const;
/// Initialize AlgTool
virtual StatusCode initialize();
/// Finalize AlgTool
virtual StatusCode finalize();
/// Default implementations for IProperty interface.
virtual StatusCode setProperty( const Property& p );
virtual StatusCode setProperty( const std::string& s );
virtual StatusCode setProperty( const std::string& n, const std::string& v);
virtual StatusCode getProperty(Property* p) const;
virtual const Property& getProperty( const std::string& name) const;
virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
virtual const std::vector<Property*>& getProperties( ) const;
/** Standard Constructor.
* @param type the concrete class of the sub-algtool
* @param name the full name of the concrete sub-algtool
* @param parent the parent of the concrete sub-algtool
*/
AlgTool( const std::string& type,
const std::string& name,
const IInterface* parent);
/// Retrieve pointer to service locator.
ISvcLocator* serviceLocator() const;
/// shortcut for the methos service locator
ISvcLocator* svcLoc() const { return serviceLocator() ; }
/// Retrieve pointer to message service.
IMessageSvc* msgSvc() const;
/// The standard ToolSvc service, Return a pointer to the service if present
IToolSvc* toolSvc() const;
/** Method for setting declared properties to the values specified in the
* jobOptions via the job option service. This method is called by the
* ToolSvc after creating the concrete tool, before passing it to the
* requesting parent and does not need to be called explicitly.
*/
StatusCode setProperties();
/** Access a service by name,
* creating it if it doesn't already exist.
*/
template <class T>
StatusCode service
( const std::string& name, T*& svc, bool createIf = false ) const {
return service_i(name, createIf, T::interfaceID(), (void**)&svc);
}
/** Access a service by name, type creating it if it doesn't already exist.
*/
template <class T>
StatusCode service( const std::string& type, const std::string& name, T*& svc) const {
return service_i(type, name, T::interfaceID(), (void**)&svc);
}
/// declare interface
void declInterface( const InterfaceID&, void*);
template <class I> class declareInterface {
public:
template <class T> declareInterface(T* tool) {
tool->declInterface( I::interfaceID(), (I*)tool);
}
};
/// Declare named properties
template <class T>
StatusCode declareProperty( const std::string& name, T& property ) const {
m_propertyMgr->declareProperty(name, property);
return StatusCode::SUCCESS;
}
protected:
/// get tool's output level
int outputLevel () const { return (int)m_outputLevel ; }
/// Accessor for the Message level property
IntegerProperty & outputLevelProperty() { return m_outputLevel; }
protected:
// Standard destructor.
virtual ~AlgTool();
private:
typedef std::list<std::pair<InterfaceID,void*> > InterfaceList;
IntegerProperty m_outputLevel; ///< AlgTool output level
std::string m_type; ///< AlgTool type (concrete class name)
const std::string m_name; ///< AlgTool full name
const IInterface* m_parent; ///< AlgTool parent
unsigned long m_refCount; ///< Reference counter
mutable ISvcLocator* m_svcLocator; ///< Pointer to Service Locator service
mutable IMessageSvc* m_messageSvc; ///< Message service
mutable IToolSvc* m_ptoolSvc; ///< Tool service
PropertyMgr* m_propertyMgr; ///< Property Manager
InterfaceList m_interfaceList; ///< Interface list
std::string m_threadID; ///< Thread Id for Alg Tool
/** implementation of service method */
StatusCode service_i(const std::string& algName,
bool createIf,
const InterfaceID& iid,
void** ppSvc) const;
StatusCode service_i(const std::string& svcType,
const std::string& svcName,
const InterfaceID& iid,
void** ppS) const;
};
#endif // GAUDIKERNEL_ALGTOOL_H
// $Id: Algorithm.h,v 1.23 2006/06/06 16:16:23 hmd Exp $
#ifndef GAUDIKERNEL_ALGORITHM_H
#define GAUDIKERNEL_ALGORITHM_H
// Include files
#include "GaudiKernel/IProperty.h"
#include "GaudiKernel/IAlgorithm.h"
#include "GaudiKernel/IService.h"
#include "GaudiKernel/PropertyMgr.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/IMessageSvc.h"
#include <string>
#include <vector>
// Extra include files (forward declarations should be sufficient)
#include "GaudiKernel/IDataProviderSvc.h"
#include "GaudiKernel/IHistogramSvc.h"
#include "GaudiKernel/IConversionSvc.h"
#include "GaudiKernel/INTupleSvc.h"
#include "GaudiKernel/IChronoStatSvc.h"
#include "GaudiKernel/IRndmGenSvc.h"
#include "GaudiKernel/IAuditorSvc.h"
#include "GaudiKernel/IToolSvc.h"
#include "GaudiKernel/IMonitorSvc.h"
#include "GaudiKernel/Property.h"
// #include "GaudiKernel/IAIDATupleSvc.h"
/** @class Algorithm Algorithm.h GaudiKernel/Algorithm.h
*
* Base class from which all concrete algorithm classes should
* be derived.
* In order for a concrete algorithm class to do anything
* useful the methods initialize(), execute() and finalize()
* should be overridden.
* The base class provides utility methods for accessing
* standard services (event data service etc.); for declaring
* properties which may be configured by the job options
* service; and for creating sub algorithms.
* The only base class functionality which may be used in the
* constructor of a concrete algorithm is the declaration of
* member variables as properties. All other functionality,
* i.e. the use of services and the creation of sub-algorithms,
* may be used only in initialise() and afterwards (see the
* Gaudi user guide).
*
* @author Paul Maley
* @author Pere Mato
* @author David Quarrie
* @date 1998
*/
class Algorithm : virtual public IAlgorithm,
virtual public IProperty {
public:
/** Constructor
* @param name The algorithm object's name
* @param svcloc A pointer to a service location service
*/
Algorithm( const std::string& name, ISvcLocator *svcloc );
/// Destructor
virtual ~Algorithm();
/** Initialization method invoked by the framework. This method is responsible
* for any bookkeeping of initialization required by the framework itself.
* It will in turn invoke the initialize() method of the derived algorithm,
* and of any sub-algorithms which it creates.
*/
virtual StatusCode sysInitialize();
/** The actions to be performed by the algorithm on an event. This method is
* invoked once per event for top level algorithms by the application
* manager.
* This method invokes execute() method.
* For sub-algorithms either the sysExecute() method or execute() method
* must be EXPLICITLY invoked by the parent algorithm.
*/
virtual StatusCode sysExecute();
/** System finalization. This method invokes the finalize() method of a
* concrete algorithm and the finalize() methods of all of that algorithm's
* sub algorithms.
*/
virtual StatusCode sysFinalize();
/** The identifying name of the algorithm object. This is the name of a
* particular instantiation of an algorithm object as opposed to the name
* of the algorithm itself, e.g. "LinearTrackFit" may be the name of a
* concrete algorithm class,
* whereas "ApproxTrackFit" and "BestTrackFit" may be two instantiations
* of the class configured to find tracks with different fit criteria.
*/
virtual const std::string& name() const;
/// the default (empty) implementation of IAlgorithm::initialize() methoda
virtual StatusCode initialize () { return StatusCode::SUCCESS ; }
/// the default (empty) implementation of IAlgorithm::finalize() methoda
virtual StatusCode finalize () { return StatusCode::SUCCESS ; }
/// Has this algorithm been executed since the last reset?
virtual bool isExecuted( ) const;
/// Set the executed flag to the specified state
virtual StatusCode setExecuted( bool state );
/** Reset the executed state of the Algorithm for the duration
* of the current event.
*/
virtual StatusCode resetExecuted( );
/** Algorithm begin run. This method is called at the beginning
* of the event loop.
*/
virtual StatusCode beginRun();
/// Algorithm end run. This method is called at the end of the event loop
virtual StatusCode endRun();
/// Is this algorithm enabled or disabled?
virtual bool isEnabled( ) const;
/// Did this algorithm pass or fail its filter criterion for the last event?
virtual bool filterPassed( ) const;
/// Set the filter passed flag to the specified state
virtual StatusCode setFilterPassed( bool state );
/// Access a service by name, creating it if it doesn't already exist.
template <class T>
StatusCode service
( const std::string& name, T*& psvc, bool createIf = false ) const {
return service_i(name, createIf, T::interfaceID(), (void**)&psvc);
}
/// Access a service by name and type, creating it if it doesn't already exist.
template <class T>
StatusCode service( const std::string& svcType, const std::string& svcName,
T*& psvc) const {
return service_i(svcType, svcName, T::interfaceID(), (void**)&psvc);
}
/// Set the outputlevel for current algorithm
void setOutputLevel( int level );
/** The standard auditor service.May not be invoked before sysInitialize()
* has been invoked.
*/
IAuditorSvc* auditorSvc() const;
/** The standard Chrono & Stat service,
* Return a pointer to the service if present
*/
IChronoStatSvc* chronoSvc() const;
/// Obsoleted name, kept due to the backwards compatibility
IChronoStatSvc* chronoStatService() const;
/** The standard detector data service.
* May not be invoked before sysInitialize() has been invoked.
*/
IDataProviderSvc* detSvc() const;
/// Obsoleted name, kept due to the backwards compatibility
IDataProviderSvc* detDataService() const;
/** The standard detector data persistency conversion service.
* May not be invoked before sysInitialize() has been invoked.
*/
IConversionSvc* detCnvSvc() const;
/// Obsoleted name, kept due to the backwards compatibility
IConversionSvc* detDataCnvService() const;
/** The standard event data service.
* May not be invoked before sysInitialize() has been invoked.
*/
IDataProviderSvc* eventSvc() const;
/// shortcut for method eventSvc
IDataProviderSvc* evtSvc () const { return eventSvc() ; }
/// Obsoleted name, kept due to the backwards compatibility
IDataProviderSvc* eventDataService() const;
/** The standard event data persistency conversion service.
* May not be invoked before sysInitialize() has been invoked.
*/
IConversionSvc* eventCnvSvc() const;
/// Obsoleted name, kept due to the backwards compatibility
IConversionSvc* eventDataCnvService() const;
/** The standard histogram service.
* May not be invoked before sysInitialize() has been invoked.
*/
IHistogramSvc* histoSvc() const;
/// Obsoleted name, kept due to the backwards compatibility
IHistogramSvc* histogramDataService() const;
/** The standard message service.
* Returns a pointer to the standard message service.
* May not be invoked before sysInitialize() has been invoked.
*/
IMessageSvc* msgSvc() const;
/// Obsoleted name, kept due to the backwards compatibility
IMessageSvc* messageService() const;
/** The standard N tuple service.
* Returns a pointer to the N tuple service if present.
*/
INTupleSvc* ntupleSvc() const;
/// Obsoleted name, kept due to the backwards compatibility
INTupleSvc* ntupleService() const;
/** AIDA-based NTuple service
* Returns a pointer to the AIDATuple service if present.
*/
// IAIDATupleSvc* atupleSvc() const;
/** The standard RandomGen service,
* Return a pointer to the service if present
*/
IRndmGenSvc* randSvc() const;
/// The standard ToolSvc service, Return a pointer to the service if present
IToolSvc* toolSvc() const;
/** The standard service locator.
* Returns a pointer to the service locator service.
* This service may be used by an algorithm to request
* any services it requires in addition to those provided by default.
*/
ISvcLocator* serviceLocator() const;
/// shortcut for method serviceLocator
ISvcLocator* svcLoc () const { return serviceLocator() ; }
/** Create a sub algorithm.
* A call to this method creates a child algorithm object.
* Note that the returned pointer is to Algorithm
* (as opposed to IAlgorithm), and thus the methods of IProperty
* are also available for the direct setting of the sub-algorithm's
* properties. Using this mechanism instead of creating daughter
* algorithms directly via the new operator is prefered since then
* the framework may take care of all of the necessary book-keeping.
* @param type The concrete algorithm class of the sub algorithm
* @param name The name to be given to the sub algorithm
* @param pSubAlg Set to point to the newly created algorithm object
*/
StatusCode createSubAlgorithm( const std::string& type,
const std::string& name, Algorithm*& pSubAlg );
/// List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms
std::vector<Algorithm*>* subAlgorithms() const;
/// Implementation of IProperty::setProperty
virtual StatusCode setProperty( const Property& p );
/// Implementation of IProperty::setProperty
virtual StatusCode setProperty( const std::string& s );
/// Implementation of IProperty::setProperty
virtual StatusCode setProperty( const std::string& n, const std::string& v);
/// Implementation of IProperty::getProperty
virtual StatusCode getProperty(Property* p) const;
/// Implementation of IProperty::getProperty
virtual const Property& getProperty( const std::string& name) const;
/// Implementation of IProperty::getProperty
virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
/// Implementation of IProperty::getProperties
virtual const std::vector<Property*>& getProperties( ) const;
/** Set the algorithm's properties.
* This method requests the job options service
* to set the values of any declared properties.
* The method is invoked from within sysInitialize() by the framework
* and does not need to be explicitly
* called by a concrete algorithm.
*/
StatusCode setProperties();
/// Declare named properties
template <class T>
StatusCode declareProperty( const std::string& name, T& property ) const {
m_propertyMgr->declareProperty(name, property);
return StatusCode::SUCCESS;
}
/// Declare remote named properties
StatusCode declareRemoteProperty( const std::string& name, IProperty* rsvc,
const std::string& rname = "" ) const {
m_propertyMgr->declareRemoteProperty(name, rsvc, rname);
return StatusCode::SUCCESS;
}
/// Declare named monitoring information items
template <class T>
void declareInfo( const std::string& name, const T& var, const std::string& desc ) const {
// If not already located try to locate it without forcing a creation
if( ! m_pMonitorSvc ) service_i("MonitorSvc", false, IMonitorSvc::interfaceID(), (void**)&m_pMonitorSvc);
if( m_pMonitorSvc ) m_pMonitorSvc->declareInfo(name, var, desc, this);
}
/// Methods for IInterface::addRef()
unsigned long addRef();
/// Methods for IInterface::release()
unsigned long release();
/// Methods for IInterface::queryInterface()
StatusCode queryInterface(const InterfaceID& riid, void**);
protected:
/// Has the Algorithm already been initialized?
bool isInitialized( ) const;
/// Set the Algorithm initialized state
void setInitialized( );
/// Has the Algorithm already been finalized?
bool isFinalized( ) const;
/// Set the Algorithm finalized state
void setFinalized( );
/// retrieve the Algorithm output level
int outputLevel() const { return (int)m_outputLevel ; }
/// Accessor for the Message level property
IntegerProperty & outputLevelProperty() { return m_outputLevel; }
private:
long m_refCount; ///< Counter for references to Algorithm
std::string m_name; ///< Algorithm's name for identification
std::vector<Algorithm *>* m_subAlgms; ///< Sub algorithms
mutable IMessageSvc* m_MS; ///< Message service
mutable IDataProviderSvc* m_EDS; ///< Event data service
mutable IConversionSvc* m_ECS; ///< Event conversion service
mutable IDataProviderSvc* m_DDS; ///< Detector data service
mutable IConversionSvc* m_DCS; ///< Detector conversion service
mutable IHistogramSvc* m_HDS; ///< Histogram data service
mutable INTupleSvc* m_NTS; ///< N tuple service
// mutable IAIDATupleSvc* m_ATS; ///< AIDA tuple service
mutable IChronoStatSvc* m_CSS; ///< Chrono & Stat Service
mutable IRndmGenSvc* m_RGS; ///< Random Number Generator Service
mutable IAuditorSvc* m_pAuditorSvc; ///< Auditor Service
mutable IToolSvc* m_ptoolSvc; ///< ToolSvc Service