Gaudi Framework, version v22r2

Home   Generated: Tue May 10 2011
Public Types | Public Member Functions | Private Member Functions | Private Attributes

JobOptionsSvc Class Reference

#include <JobOptionsSvc.h>

Inheritance diagram for JobOptionsSvc:
Inheritance graph
[legend]
Collaboration diagram for JobOptionsSvc:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::vector< const
Property * > 
PropertiesT

Public Member Functions

 JobOptionsSvc (const std::string &name, ISvcLocator *svc)
 Constructor.
virtual ~JobOptionsSvc ()
 destructor
virtual StatusCode initialize ()
 Service initialization method.
virtual StatusCode finalize ()
 Service finalization method.
virtual StatusCode setMyProperties (const std::string &client, IProperty *myInt)
 IJobOptionsSvc::setMyProperties.
virtual StatusCode addPropertyToCatalogue (const std::string &client, const Property &property)
 implementation of IJobOptionsSvc::addPropertyToCatalogue
virtual StatusCode removePropertyFromCatalogue (const std::string &client, const std::string &name)
 implementation of IJobOptionsSvc::removePropertyFromCatalogue
virtual const PropertiesTgetProperties (const std::string &client) const
 inmplementation of IJobOptionsSvc::getProperties
virtual std::vector< std::stringgetClients () const
 inmplementation of IJobOptionsSvc::getClients
virtual StatusCode readOptions (const std::string &file, const std::string &path="")
 look for file 'File' into search path 'Path' and read it to update existing JobOptionsCatalogue
StatusCode setProperty (const Property &p)
 IProperty implementation (needed for initialisation)
StatusCode getProperty (Property *p) const
std::ostreamfillStream (std::ostream &o) const
 dump the content of Properties catalogue to std::ostream
void dump (const std::string &file) const
 dump the content of Properties catalogue to the file
void dump ()
 dump the content of Properties catalogue to the predefined file

Private Member Functions

void fillParserCatalogue ()
 Fill parser catalogue before parse.
void fillServiceCatalogue ()
 Fill service catalogue after parse.
MSG::Level convertSeverity (const Gaudi::Parsers::Message::Severity &severity)
 convert the severity

Private Attributes

std::string m_source_path
std::string m_source_type
std::string m_dirSearchPath
std::string m_dump
 optional output file to dump all properties
bool m_dumped
PropertyMgr m_pmgr
Gaudi::Parsers::Catalogue m_pcatalogue
std::vector< std::stringm_included
JobOptionsCatalogue m_catalogue

Detailed Description

Definition at line 22 of file JobOptionsSvc.h.


Member Typedef Documentation

Definition at line 30 of file JobOptionsSvc.h.


Constructor & Destructor Documentation

JobOptionsSvc::JobOptionsSvc ( const std::string name,
ISvcLocator svc 
)

Constructor.

Definition at line 33 of file JobOptionsSvc.cpp.

  : base_class(name,svc)
  , m_source_path     ()
  , m_source_type     ()
  , m_dirSearchPath   ()
  , m_dump            ()
  , m_dumped ( false )
{
  std::string tmp ;
  tmp = System::getEnv ( "JOBOPTSEARCHPATH" ) ;
  if ( !tmp.empty() && ("UNKNOWN" != tmp) ) { m_dirSearchPath = tmp ; }
  tmp = System::getEnv ( "JOBOPTSDUMPFILE"  ) ;
  if ( !tmp.empty() && ("UNKNOWN" != tmp) ) { m_dump          = tmp ; }

  m_pmgr.declareProperty( "TYPE"       , m_source_type   ) ;
  m_pmgr.declareProperty( "PATH"       , m_source_path   ) ;
  m_pmgr.declareProperty( "SEARCHPATH" , m_dirSearchPath ) ;
  m_pmgr.declareProperty( "DUMPFILE"   , m_dump          ) ;
}
JobOptionsSvc::~JobOptionsSvc (  ) [virtual]

destructor

Definition at line 266 of file JobOptionsSvc.cpp.

{
  // dump needed? @attention JobOptionsSvc::finalize is never invoked!
  if ( !m_dump.empty() && !m_dumped ) { dump() ;}
}

Member Function Documentation

StatusCode JobOptionsSvc::addPropertyToCatalogue ( const std::string client,
const Property property 
) [virtual]

implementation of IJobOptionsSvc::addPropertyToCatalogue

Definition at line 153 of file JobOptionsSvc.cpp.

{
  Property* p = new StringProperty ( property.name(), "" ) ;
  if ( !property.load( *p ) ) { delete p ; return StatusCode::FAILURE ; }
  return m_catalogue.addProperty( client , p );
}
MSG::Level JobOptionsSvc::convertSeverity ( const Gaudi::Parsers::Message::Severity &  severity ) [private]

convert the severity

Definition at line 214 of file JobOptionsSvc.cpp.

{
  switch ( severity )
  {
  case Gaudi::Parsers::Message::E_ERROR   :
    return MSG::FATAL   ;
  case Gaudi::Parsers::Message::E_WARNING :
    return MSG::WARNING ;
  case Gaudi::Parsers::Message::E_NOTICE  :
    return MSG::INFO    ;
  default:
    return MSG::DEBUG   ;
  }
}
void JobOptionsSvc::dump ( const std::string file ) const

dump the content of Properties catalogue to the file

Definition at line 246 of file JobOptionsSvc.cpp.

{
  MsgStream log ( msgSvc() , name() ) ;
  std::ofstream out
    ( file.c_str() , std::ios_base::out | std::ios_base::trunc ) ;
  // perform the actual dumping
  if ( !out )
  {
    log << MSG::ERROR << "Unable to open dump-file \""+file+"\"" << endmsg ;
    return ;                                                   // RETURN
  }
  else
  { log << MSG::INFO << "Properties are dumped into \""+file+"\"" << endmsg ; }
  // perform the actual dump:
  fillStream ( out ) ;
}
void JobOptionsSvc::dump (  )

dump the content of Properties catalogue to the predefined file

< avoid double dump

Definition at line 237 of file JobOptionsSvc.cpp.

{
  // avoid double dump
  if ( m_dump.empty() || m_dumped ) { return ; }               // RETURN
  dump ( m_dump ) ;
  // avoid double dump
  m_dumped = true ; 
}
void JobOptionsSvc::fillParserCatalogue (  ) [private]

Fill parser catalogue before parse.

Definition at line 181 of file JobOptionsSvc.cpp.

                                       {
  std::vector<std::string> clients = getClients();
  for(std::vector<std::string>::const_iterator client = clients.begin();
    client != clients.end(); client++){
       const PropertiesT* props = getProperties(*client);
       for(PropertiesT::const_iterator prop = props->begin();
        prop != props->end(); prop++){
         m_pcatalogue.addProperty(*client,(*prop)->name(),
           (*prop)->toString());
        }
   }
}
void JobOptionsSvc::fillServiceCatalogue (  ) [private]

Fill service catalogue after parse.

Definition at line 195 of file JobOptionsSvc.cpp.

{
  typedef Gaudi::Parsers::Catalogue::CatalogueT      _Catalogue ;
  typedef std::vector<Gaudi::Parsers::PropertyEntry> _Entries   ;
  _Catalogue catalogue = m_pcatalogue.catalogue();
  for  ( _Catalogue::const_iterator curObj = catalogue.begin() ;
         curObj!=catalogue.end(); ++curObj)
  {
    for ( _Entries::const_iterator curProp = curObj->second.begin() ;
          curProp!=curObj->second.end(); ++curProp)
    {
      StringProperty tmp (curProp->name(), curProp->value() ) ;
      addPropertyToCatalogue ( curObj->first , tmp ) ;
    }
  }
}
std::ostream & JobOptionsSvc::fillStream ( std::ostream o ) const

dump the content of Properties catalogue to std::ostream

Definition at line 263 of file JobOptionsSvc.cpp.

{ return  o << m_pcatalogue ; }
StatusCode JobOptionsSvc::finalize ( void   ) [virtual]

Service finalization method.

Reimplemented from Service.

Definition at line 229 of file JobOptionsSvc.cpp.

{
  // dump the properties catalogue if needed
  if ( !m_dump.empty() && !m_dumped ) { dump() ;}
   // finalize the base class
  return Service::finalize() ;
}
std::vector< std::string > JobOptionsSvc::getClients (  ) const [virtual]

inmplementation of IJobOptionsSvc::getClients

Definition at line 175 of file JobOptionsSvc.cpp.

{
  return m_catalogue.getClients();
}
const JobOptionsSvc::PropertiesT * JobOptionsSvc::getProperties ( const std::string client ) const [virtual]

inmplementation of IJobOptionsSvc::getProperties

Definition at line 170 of file JobOptionsSvc.cpp.

{
  return m_catalogue.getProperties(client);
}
StatusCode JobOptionsSvc::getProperty ( Property p ) const [virtual]

Reimplemented from Service.

Definition at line 59 of file JobOptionsSvc.cpp.

{
        return m_pmgr.getProperty( p );
}
StatusCode JobOptionsSvc::initialize (  ) [virtual]

Service initialization method.

Reimplemented from Service.

Definition at line 92 of file JobOptionsSvc.cpp.

{
  // Call base class initializer
  StatusCode sc = Service::initialize();
  if( !sc.isSuccess() ) return sc;
  // Read the job options if needed
  if ( this->m_source_type == "NONE" ) {
    sc =  StatusCode::SUCCESS;
  }
  else {
    sc = this->readOptions( m_source_path , m_dirSearchPath);
  }
  return sc;
}
StatusCode JobOptionsSvc::readOptions ( const std::string file,
const std::string path = "" 
) [virtual]

look for file 'File' into search path 'Path' and read it to update existing JobOptionsCatalogue

Parameters:
Filefile name
Pathsearch path
Returns:
status code

Definition at line 107 of file JobOptionsSvc.cpp.

{
  // use the default non-empty path (if any) if no path specified
  if ( path.empty() && !m_dirSearchPath.empty() )
  { return readOptions ( file , m_dirSearchPath ) ; }
  //
  MsgStream my_log( this->msgSvc(), this->name() );
  // --------------------------------------------------------------------------
  std::vector<Gaudi::Parsers::Message> messages;
  // --------------------------------------------------------------------------
  // fillParserCatalogue();
  // --------------------------------------------------------------------------
  my_log << MSG::DEBUG                             // debug
         << "Job-options read from the file "
         << "'" << file << "'"
         << MSG::INFO                              // switch
         << std::endl ;
  // create the parser & parse the file
  Gaudi::Parsers::Parser parser (m_pcatalogue, m_included, path, my_log.stream() ) ;
  StatusCode sc = Gaudi::Parsers::parse
    ( parser , file , messages ) ;
  my_log << endmsg ;

  // --------------------------------------------------------------------------
  if ( sc.isSuccess() )
  {
    my_log << MSG::INFO
           << "Job options successfully read in from " << file << endmsg;
    fillServiceCatalogue();
  }
  else
  {
    my_log << MSG::FATAL << "Job options errors."<< endmsg;
  }
  // ----------------------------------------------------------------------------
  for ( std::vector<Gaudi::Parsers::Message>::const_iterator
          cur=messages.begin(); cur!=messages.end();cur++)
  {
    my_log << convertSeverity(cur->severity()) << cur->message() << endmsg;
  }
  // ----------------------------------------------------------------------------
  return sc;
}
StatusCode JobOptionsSvc::removePropertyFromCatalogue ( const std::string client,
const std::string name 
) [virtual]

implementation of IJobOptionsSvc::removePropertyFromCatalogue

Definition at line 163 of file JobOptionsSvc.cpp.

{
  return m_catalogue.removeProperty(client,name);
}
StatusCode JobOptionsSvc::setMyProperties ( const std::string client,
IProperty myInt 
) [virtual]

IJobOptionsSvc::setMyProperties.

Definition at line 64 of file JobOptionsSvc.cpp.

{
  const JobOptionsCatalogue::PropertiesT* props =
    m_catalogue.getProperties(client);

  if ( NULL == props ){ return StatusCode::SUCCESS; }

  bool fail = false;
  for ( std::vector<const Property*>::const_iterator cur = props->begin();
    cur != props->end(); cur++)
  {
    StatusCode sc = myInt->setProperty (**cur ) ;
    if ( sc.isFailure() )
    {
      MsgStream my_log( this->msgSvc(), this->name() );
      my_log
        << MSG::ERROR
        << "Unable to set the property '" << (*cur)->name() << "'"
        <<                        " of '" << client         << "'. "
        << "Check option and algorithm names, type and bounds."
        << endmsg;
      fail = true;
    }
  }
  return fail ? StatusCode::FAILURE : StatusCode::SUCCESS ;
}
StatusCode JobOptionsSvc::setProperty ( const Property p ) [virtual]

IProperty implementation (needed for initialisation)

Reimplemented from Service.

Definition at line 54 of file JobOptionsSvc.cpp.

{
        return m_pmgr.setProperty( p );
}

Member Data Documentation

Definition at line 96 of file JobOptionsSvc.h.

Definition at line 89 of file JobOptionsSvc.h.

optional output file to dump all properties

Definition at line 91 of file JobOptionsSvc.h.

bool JobOptionsSvc::m_dumped [private]

Definition at line 92 of file JobOptionsSvc.h.

Definition at line 95 of file JobOptionsSvc.h.

Gaudi::Parsers::Catalogue JobOptionsSvc::m_pcatalogue [private]

Definition at line 94 of file JobOptionsSvc.h.

Definition at line 93 of file JobOptionsSvc.h.

Definition at line 87 of file JobOptionsSvc.h.

Definition at line 88 of file JobOptionsSvc.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Tue May 10 2011 18:54:55 for Gaudi Framework, version v22r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004