00001
00002
00003
00004
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
00014 unsigned long AlgTool::addRef() {
00015 m_refCount++;
00016 return m_refCount;
00017 }
00018
00019
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
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
00048 const std::string& AlgTool::name() const {
00049 return m_name;
00050 }
00051
00052
00053 const std::string& AlgTool::type() const {
00054 return m_type;
00055 }
00056
00057
00058 const IInterface* AlgTool::parent() const {
00059 return m_parent;
00060 }
00061
00062
00063 ISvcLocator* AlgTool::serviceLocator() {
00064 return m_svcLocator;
00065 }
00066
00067
00068 IMessageSvc* AlgTool::msgSvc() {
00069 return m_messageSvc;
00070 }
00071 IMessageSvc* AlgTool::msgSvc() const {
00072 return m_messageSvc;
00073 }
00074
00075
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
00088 StatusCode AlgTool::getProperty(Property* p) const {
00089 return m_propertyMgr->getProperty(p);
00090 }
00091
00092
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
00102 const std::vector<Property*>& AlgTool::getProperties() const {
00103 return m_propertyMgr->getProperties();
00104 }
00105
00106
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
00119 if( m_messageSvc ) m_messageSvc->setOutputLevel( name(), m_outputLevel );
00120
00121 return StatusCode::SUCCESS;
00122 }
00123
00124
00125
00126
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
00136
00137 StatusCode sc;
00138 IntegerProperty outlevel("OutputLevel", 0);
00139 Algorithm* alg = dynamic_cast<Algorithm*>(const_cast<IInterface*>(parent));
00140
00141 if( alg != 0 ) {
00142 m_svcLocator = alg->serviceLocator();
00143 m_messageSvc = alg->msgSvc();
00144
00145 sc = alg->getProperty( &outlevel );
00146 if( sc.isSuccess() ) {
00147 m_outputLevel = outlevel.value();
00148 }
00149 }
00150
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
00162 else {
00163
00164 }
00165 }
00166
00167
00168 declareProperty( "OutputLevel", m_outputLevel);
00169 }
00170
00171
00172 AlgTool::~AlgTool() {
00173 delete m_propertyMgr;
00174 }