Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

AlgTool.cpp

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/GaudiKernel/src/Lib/AlgTool.cpp,v 1.1.1.1 2001/04/18 18:14:18 tlindner Exp $
00002 
00003 
00004 // Include files
00005 #include "GaudiKernel/AlgTool.h"
00006 #include "GaudiKernel/IMessageSvc.h"
00007 #include "GaudiKernel/ISvcLocator.h"
00008 #include "GaudiKernel/IJobOptionsSvc.h"
00009 #include "GaudiKernel/Algorithm.h"
00010 #include "GaudiKernel/Service.h"
00011 
00012 
00013 // IInterface::addRef
00014 unsigned long AlgTool::addRef()   {
00015   m_refCount++;
00016   return m_refCount;
00017 }
00018 
00019 // IInterface::release
00020 unsigned long AlgTool::release()   {
00021   unsigned long count = --m_refCount;
00022   if( count <= 0) {
00023     delete this;
00024   }
00025   return count;
00026 }
00027 
00028 // IInterface::queryInterface
00029 StatusCode AlgTool::queryInterface(const IID& riid, void** ppvInterface)  {
00030   if ( IID_IInterface.versionMatch(riid) )   {
00031     *ppvInterface = (IInterface*)this;
00032   }
00033   else if ( IID_IAlgTool.versionMatch(riid) )  {
00034     *ppvInterface = (IAlgTool*)this;
00035   }
00036   else if ( IID_IProperty.versionMatch(riid) )  {
00037     *ppvInterface = (IProperty*)this;
00038   }
00039   else   {
00040      return NO_INTERFACE;
00041   }
00042   addRef();
00043   return SUCCESS;
00044 }
00045 
00046 
00047 // IAlgTool::name, retrieve full name of concrete tool
00048 const std::string& AlgTool::name()   const {
00049   return m_name;
00050 }
00051 
00052 // IAlgTool::type, retrieve class of concrete tool
00053 const std::string& AlgTool::type()  const {
00054   return m_type;
00055 }
00056 
00057 // IAlgTool::parent, retrieve interface of parent 
00058 const IInterface* AlgTool::parent() const {
00059   return m_parent;
00060 }
00061 
00062 // Retrieve pointer to service locator
00063 ISvcLocator* AlgTool::serviceLocator()    {
00064   return m_svcLocator;
00065 }
00066 
00067 // Retrieve pointer to message service
00068 IMessageSvc* AlgTool::msgSvc()    {
00069   return m_messageSvc;
00070 }
00071 IMessageSvc* AlgTool::msgSvc()  const  {
00072   return m_messageSvc;
00073 }
00074 
00075 // IProperty::setProperty, delegate to the property manager
00076 StatusCode AlgTool::setProperty(const Property& p) {
00077         return m_propertyMgr->setProperty(p);
00078 }
00079 
00080 StatusCode AlgTool::setProperty(std::istream& s) {
00081         return m_propertyMgr->setProperty(s);
00082 }
00083 StatusCode AlgTool::setProperty(const std::string& n, const std::string& v) {
00084         return m_propertyMgr->setProperty(n,v);
00085 }
00086 
00087 // IProperty::getProperty, delegate to the property manager
00088 StatusCode AlgTool::getProperty(Property* p) const {
00089         return m_propertyMgr->getProperty(p);
00090 }
00091 
00092 // IProperty::getProperty, delegate to the property manager
00093 const Property& AlgTool::getProperty(const std::string& n) const {
00094   return m_propertyMgr->getProperty(n);
00095 }
00096 
00097 StatusCode AlgTool::getProperty(const std::string& n, std::string& v ) const {
00098         return m_propertyMgr->getProperty(n,v);
00099 }
00100 
00101 // IProperty::getProperties, delegate to the property manager
00102 const std::vector<Property*>& AlgTool::getProperties() const {
00103         return m_propertyMgr->getProperties();
00104 }
00105 
00106 // Use the job options service to set declared properties
00107 StatusCode AlgTool::setProperties() {
00108         IJobOptionsSvc* jos;
00109   if( m_svcLocator == 0) {
00110     return StatusCode::FAILURE;
00111   }
00112         StatusCode sc = m_svcLocator->getService( "JobOptionsSvc", IID_IJobOptionsSvc, 
00113                                             (IInterface*&) jos);
00114     if( !sc.isSuccess() )  return StatusCode::FAILURE;
00115 
00116     std::string test = name();
00117     jos->setMyProperties( name(), this );
00118     // Change my own outputlevel
00119     if( m_messageSvc ) m_messageSvc->setOutputLevel( name(), m_outputLevel );
00120 
00121         return StatusCode::SUCCESS;
00122 }
00123 
00124 
00125 //
00126 // Standard Constructor
00127 AlgTool::AlgTool( const std::string& type, const std::string& name, const IInterface* parent) :
00128   m_type( type ), m_name( name ), m_parent( parent ) {
00129   m_refCount   = 1;
00130   m_svcLocator = 0;
00131   m_messageSvc = 0;
00132   m_propertyMgr = new PropertyMgr();
00133   m_outputLevel = MSG::NIL;
00134 
00135   // Try to cast the IInterface interface to a base class Algorithm or to a 
00136   // base class Service
00137   StatusCode sc;
00138   IntegerProperty outlevel("OutputLevel", 0);
00139   Algorithm* alg = dynamic_cast<Algorithm*>(const_cast<IInterface*>(parent));
00140   // .. the parent is an algorithm
00141   if( alg != 0 ) {
00142     m_svcLocator  = alg->serviceLocator();
00143     m_messageSvc  = alg->msgSvc();
00144     // Get the OutputLevel property of the parent
00145     sc = alg->getProperty( &outlevel );
00146     if( sc.isSuccess() ) {
00147       m_outputLevel = outlevel.value();
00148     }
00149   }
00150   // ... since it is not an algorithm maybe it is a service
00151   else {
00152     Service* svc = dynamic_cast<Service*>(const_cast<IInterface*>(parent));
00153     if( svc != 0 ) {
00154       m_svcLocator  = svc->serviceLocator();
00155       m_messageSvc  = svc->msgSvc();
00156       sc = svc->getProperty( &outlevel );
00157       if( sc.isSuccess() ) {
00158         m_outputLevel = outlevel.value();
00159       }
00160     }
00161     // the parent is neither an algorithm nor a service,
00162     else {
00163         // throw exception here?
00164     }
00165   }
00166 
00167   // Declare common AlgTool properties with their defaults
00168   declareProperty( "OutputLevel", m_outputLevel);
00169 }
00170 
00171 // Standard Destructor
00172 AlgTool::~AlgTool() {
00173   delete m_propertyMgr;
00174 }

Generated at Wed Nov 21 12:22:02 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000