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

JobOptionsSvc.cpp

Go to the documentation of this file.
00001 // JobOptionsSvc.cpp: implementation of the JobOptionsSvc class.
00002 //
00004 
00005 #include "GaudiKernel/SvcFactory.h"
00006 #include "GaudiKernel/MsgStream.h"
00007 #include "JobOptionsSvc.h"
00008 #include "PropertyCompiler.h"
00009 #include "JobOptionsCatalogue.h"
00010 #include "JobOptionsList.h"
00011 
00012 // Instantiation of a static factory class used by clients to create
00013 // instances of this service
00014 static SvcFactory<JobOptionsSvc> s_factory;
00015 const ISvcFactory& JobOptionsSvcFactory = s_factory;
00016 
00017 // Constructor
00018 
00019 JobOptionsSvc::JobOptionsSvc(const std::string& name,ISvcLocator* svc) : Service(name,svc) {
00020         m_pmgr.declareProperty( std::string("TYPE"), m_source_type );
00021         m_pmgr.declareProperty( std::string("PATH"), m_source_path );
00022         m_source_type = "FILE";
00023         if ( 0 == getenv("JOB_OPTIONS") ) {
00024           m_source_path = "jobOptions.txt"; // Default options file in execution directory
00025         }
00026         else {
00027           m_source_path = getenv("JOB_OPTIONS");
00028         }
00029 }
00030 
00031 
00032 // Delegate IProperty implementation to PropertyMgr
00033 StatusCode JobOptionsSvc::setProperty( const Property &p ) {
00034         return m_pmgr.setProperty( p );
00035 }
00036 
00037 StatusCode JobOptionsSvc::getProperty( Property *p ) const {
00038         return m_pmgr.getProperty( p );
00039 }
00040 
00041 // IJobOptions implementation
00042 
00043 StatusCode JobOptionsSvc::setMyProperties( const std::string& client,
00044                                                                                    IProperty* myInt ) {
00045     std::vector<const Property*>* myList;
00046     StatusCode sc;
00047 
00048 // Get the list of options for this client
00049         sc = m_catalogue.optionsOf( client, myList );
00050         if( !sc.isSuccess() ) return StatusCode::SUCCESS;  // Algorithm has no options
00051 
00052 // Iterate over the list to set the options
00053         for( std::vector<const Property*>::iterator iter = myList->begin(); iter != myList->end(); iter++ )   {
00054     const StringProperty* sp = dynamic_cast<const StringProperty*>(*iter);
00055     sc = StatusCode::FAILURE;
00056     if ( 0 != sp )    {
00057                 sc = myInt->setProperty( (*iter)->name(), sp->value() );
00058     }
00059     else  {
00060       const StringArrayProperty* sap = dynamic_cast<const StringArrayProperty*>(*iter);
00061       if ( 0 != sap )   {
00062         std::string prop = "[";
00063         const std::vector<std::string>& vals = sap->value();
00064         for ( unsigned int i = 0; i < vals.size(); i++ )   {
00065           prop += vals[i];
00066           if ( i+1 < vals.size() ) prop += ", ";
00067         }
00068         prop += "] ";
00069         sc = myInt->setProperty( (*iter)->name(), prop );
00070       }
00071     }
00072                 if( !sc.isSuccess() ) {
00073                         MsgStream my_log( this->msgSvc(), this->name() );
00074                         my_log << MSG::ERROR << "Unable to set property " << (*iter)->name() 
00075                                    << " of " << client 
00076                                    << "\nCheck option and algorithm names, type and bounds" << endreq;
00077                 }
00078         }
00079         return sc;
00080 }
00081 
00082 // IService implementation and initialisation
00083 
00084 StatusCode JobOptionsSvc::initialize() {
00085     // Call base class initializer
00086         StatusCode sc = Service::initialize();
00087         if( !sc.isSuccess() ) return sc;
00088         // Read the job options
00089         sc = this->readOptions();
00090         return sc;
00091 }
00092 
00093 // IInterface implementation
00094 StatusCode JobOptionsSvc::queryInterface(const IID& riid, void** ppvInterface) {
00095   if ( IID_IJobOptionsSvc == riid )  {
00096     *ppvInterface = (IJobOptionsSvc*) this;
00097   }
00098   else if ( IID_IProperty == riid ) {
00099     *ppvInterface = (IProperty*) this;
00100   }
00101   else  {
00102     return Service::queryInterface(riid, ppvInterface);
00103   }
00104   addRef();
00105   return StatusCode::SUCCESS;
00106 }
00107 
00108 // Private member functions 
00109 
00110 StatusCode JobOptionsSvc::readOptions() {
00111         StatusCode sc;
00112         MsgStream my_log( this->msgSvc(), this->name() );
00113         if ( this->source_type() == "NONE" ) {
00114                 sc = StatusCode::SUCCESS;
00115         }
00116         else if( this->source_type() == "FILE" ) {
00117                 PropertyCompiler jR( this->source_path(), my_log, m_catalogue );
00118                 sc = jR.startCompiler();
00119         }
00120         else {
00121                 sc = StatusCode::FAILURE;
00122                 my_log << MSG::ERROR << "Unknown Job Options file type: " 
00123                            << this->source_type() << endreq;
00124         }
00125 
00126         if( sc.isSuccess() ) {
00127     // Now we have to resolve still all the entries which are references to other
00128     // Properties
00129     sc = m_catalogue.resolveOptions(my_log);
00130     if ( sc.isSuccess() )     {
00131                 my_log << MSG::INFO << "Job options successfully read in from " 
00132                        << this->source_path() << endreq; 
00133     }
00134     else    {
00135                 my_log << MSG::FATAL << "Job options references cannot be resolved." << endreq;
00136       m_catalogue.printUnresolvedOptions(my_log);
00137     }
00138         }
00139         else {
00140                 my_log << MSG::FATAL << "Failed to read in job options" << endreq;
00141         }
00142         return sc;
00143 }
00144 
00145 
00146 std::string JobOptionsSvc::source_path() const {
00147         return m_source_path;
00148 }
00149 
00150 std::string JobOptionsSvc::source_type() const {
00151         return m_source_type;
00152 }

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