Gaudi Framework, version v23r2

Home   Generated: Thu Jun 28 2012
Classes | Typedefs | Functions

genconf.cpp File Reference

#include "boost/program_options.hpp"
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/exception.hpp"
#include "boost/filesystem/convenience.hpp"
#include "boost/algorithm/string/split.hpp"
#include "boost/algorithm/string/classification.hpp"
#include "boost/algorithm/string/trim.hpp"
#include "boost/algorithm/string/case_conv.hpp"
#include "boost/format.hpp"
#include "boost/regex.hpp"
#include "GaudiKernel/System.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/IProperty.h"
#include "GaudiKernel/IAppMgrUI.h"
#include "GaudiKernel/IAlgorithm.h"
#include "GaudiKernel/IAlgTool.h"
#include "GaudiKernel/IAuditor.h"
#include "GaudiKernel/Service.h"
#include "GaudiKernel/Bootstrap.h"
#include "GaudiKernel/SmartIF.h"
#include "GaudiKernel/HashMap.h"
#include "GaudiKernel/GaudiHandle.h"
#include "GaudiKernel/Time.h"
#include "Reflex/PluginService.h"
#include "Reflex/Reflex.h"
#include "Reflex/SharedLibrary.h"
#include "RVersion.h"
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <exception>
#include <set>
#include <vector>
#include "DsoUtils.h"
Include dependency graph for genconf.cpp:

Go to the source code of this file.

Classes

class  configGenerator

Typedefs

typedef std::vector< std::stringStrings_t
typedef std::vector< fs::path > LibPathNames_t

Functions

int createAppMgr ()
int main (int argc, char **argv)
std::string getId (const Member &m)
 Given a Reflex::Member object, return the id for the configurable (name or id, if it is a string).
template<class T >
IPropertymakeInstance (const Member &member, const vector< void * > &args)

Typedef Documentation

typedef std::vector<fs::path> LibPathNames_t

Definition at line 81 of file genconf.cpp.

Definition at line 80 of file genconf.cpp.


Function Documentation

int createAppMgr (  )

Definition at line 912 of file genconf.cpp.

{
  IInterface* iface = Gaudi::createApplicationMgr();
  SmartIF<IProperty> propMgr ( iface );
  SmartIF<IAppMgrUI> appUI  ( iface );

  if ( propMgr.isValid() && appUI.isValid() ) {
    propMgr->setProperty( "JobOptionsType", "NONE" );  // No job options
    propMgr->setProperty( "AppName", "");              // No initial printout message
    propMgr->setProperty( "OutputLevel", "7");         // No other printout messages
    appUI->configure();
    return EXIT_SUCCESS;
  }
  else {
    return EXIT_FAILURE;
  }
}
std::string getId ( const Member &  m ) [inline]

Given a Reflex::Member object, return the id for the configurable (name or id, if it is a string).

non-string ids are used for the persistency (DataObjects)

Definition at line 418 of file genconf.cpp.

                                         {
      return (m.Properties().HasProperty("id") && (m.Properties().PropertyValue("id").TypeInfo() == typeid(std::string))) ?
             m.Properties().PropertyAsString("id") :
             m.Properties().PropertyAsString("name") ;
}
int main ( int  argc,
char **  argv 
)

Definition at line 201 of file genconf.cpp.

{
  fs::path pwd = fs::initial_path();
  fs::path out;
  Strings_t libs;
  std::string pkgName;

  // declare a group of options that will be allowed only on command line
  po::options_description generic("Generic options");
  generic.add_options()
    ("help,h",
     "produce this help message")
    ("package-name,p",
     po::value<string>(),
     "name of the package for which we create the configurables file")
    ("input-libraries,i",
     po::value<string>(),
     "libraries to extract the component configurables from")
    ("input-cfg,c",
     po::value<string>(),
     "path to the cfg file holding the description of the Configurable base "
     "classes, the python module holding the Configurable definitions, etc...")
    ("output-dir,o",
     po::value<string>()->default_value("../genConf"),
     "output directory for genconf files.")
    ("debug-level,d",
     po::value<int>()->default_value(0),
     "debug level")
    ("load-library,l",
     po::value< Strings_t >()->composing(),
     "preloading library")
    ;

  // declare a group of options that will be allowed both on command line
  // _and_ in configuration file
  po::options_description config("Configuration");
  config.add_options()
    ("configurable-module",
     po::value<string>()->default_value("AthenaCommon"),
     "Name of the module holding the configurable classes")
    ("configurable-default-name",
     po::value<string>()->default_value("Configurable.DefaultName"),
     "Default name for the configurable instance")
    ("configurable-algorithm",
     po::value<string>()->default_value("ConfigurableAlgorithm"),
     "Name of the configurable base class for Algorithm components")
    ("configurable-algtool",
     po::value<string>()->default_value("ConfigurableAlgTool"),
     "Name of the configurable base class for AlgTool components")
    ("configurable-auditor",
     po::value<string>()->default_value("ConfigurableAuditor"),
     "Name of the configurable base class for Auditor components")
    ("configurable-service",
     po::value<string>()->default_value("ConfigurableService"),
     "Name of the configurable base class for Service components")
    ;

  po::options_description cmdline_options;
  cmdline_options.add(generic).add(config);

  po::options_description config_file_options;
  config_file_options.add(config);

  po::options_description visible("Allowed options");
  visible.add(generic).add(config);

  po::variables_map vm;

  try {
    po::store( po::command_line_parser(argc, argv).
               options(cmdline_options).run(),
               vm );

    po::notify(vm);

    // try to read configuration from the optionally given configuration file
    if( vm.count("input-cfg") ) {
      string cfgFileName = vm["input-cfg"].as<string>();
      cfgFileName = fs::system_complete( fs::path( cfgFileName ) ).string();
      std::ifstream ifs( cfgFileName.c_str() );
      po::store( parse_config_file( ifs, config_file_options ), vm );
    }

    po::notify(vm);
  }
  catch ( po::error& err ) {
    cout << "ERR0R: error detected while parsing command options: "<< err.what() << endl;
    return EXIT_FAILURE;
  }

  //--- Process command options -----------------------------------------------
  if( vm.count("help")) {
    cout << visible << endl;
    return EXIT_FAILURE;
  }

  if( vm.count("package-name") ) {
    pkgName = vm["package-name"].as<string>();
  }
  else {
    cout << "ERROR: 'package-name' required" << endl;
    cout << visible << endl;
    return EXIT_FAILURE;
  }

  if( vm.count("input-libraries") ) {
    // re-shape the input arguments:
    //  - removes spurious spaces,
    //  - split into tokens.
    Strings_t inputLibs;
    {
      string tmp = vm["input-libraries"].as<string>();
      boost::trim(tmp);
      boost::split( inputLibs, tmp,
                    boost::is_any_of(" "),
                    boost::token_compress_on );
    }

    //
    libs.reserve( inputLibs.size() );
    for ( Strings_t::const_iterator iLib = inputLibs.begin();
          iLib != inputLibs.end();
          ++iLib ) {
      std::string lib = fs::path(*iLib).stem().string();
      if ( 0 == lib.find("lib") ) {
        lib = lib.substr(3); // For *NIX remove "lib"
      }
      // remove duplicates
      if ( !lib.empty() &&
          std::find( libs.begin(), libs.end(), lib ) == libs.end() ) {
        libs.push_back( lib );
      }
    } //> end loop over input-libraries
    if ( libs.empty() ) {
      cout << "ERROR: input component library(ies) required !\n"
           << "ERROR: 'input-libraries' argument was ["
           << vm["input-libraries"].as<string>()
           << "]"
           << endl;
      return EXIT_FAILURE;
    }
  }
  else {
    cout << "ERROR: input component library(ies) required" << endl;
    cout << visible << endl;
    return EXIT_FAILURE;
  }

  if( vm.count("output-dir") ) {
    out = fs::system_complete( fs::path( vm["output-dir"].as<string>() ) );
  }

  if ( vm.count("debug-level") ) {
    PluginService::SetDebug( vm["debug-level"].as<int>() );
  }

  if ( vm.count("load-library") ) {
    Strings_t lLib_list = vm["load-library"].as< Strings_t >();
    for (Strings_t::const_iterator lLib=lLib_list.begin();
         lLib != lLib_list.end();
         ++lLib) {
      // load done through ROOT::Reflex helper class
      SharedLibrary tmplib(*lLib) ;
      tmplib.Load() ;
    }
  }


  if ( !fs::exists( out ) ) {
    try {
      fs::create_directory(out);
    }
    catch ( fs::filesystem_error &err ) {
      cout << "ERR0R: error creating directory: "<< err.what() << endl;
      return EXIT_FAILURE;
    }
  }

  cout << ":::::: libraries : [ ";
  copy( libs.begin(), libs.end(), ostream_iterator<string>(cout, " ") );
  cout << "] ::::::" << endl;

  configGenerator py( pkgName, out.string() );
  py.setConfigurableModule     (vm["configurable-module"].as<string>());
  py.setConfigurableDefaultName(vm["configurable-default-name"].as<string>());
  py.setConfigurableAlgorithm  (vm["configurable-algorithm"].as<string>());
  py.setConfigurableAlgTool    (vm["configurable-algtool"].as<string>());
  py.setConfigurableAuditor    (vm["configurable-auditor"].as<string>());
  py.setConfigurableService    (vm["configurable-service"].as<string>());

  int sc = EXIT_FAILURE;
  try {
    sc = py.genConfig( libs );
  }
  catch ( exception& e ) {
    cout << "ERROR: Could not generate Configurable(s) !\n"
         << "ERROR: Got exception: " << e.what() << endl;
    return EXIT_FAILURE;
  }

  if ( EXIT_SUCCESS == sc ) {
    // create an empty __init__.py file in the output dir
    fstream initPy( ( out / fs::path( "__init__.py" ) ).string().c_str(),
        std::ios_base::out|std::ios_base::trunc );
    initPy << "## Hook for " << pkgName << " genConf module\n" << flush;
  }

  cout << ":::::: libraries : [ ";
  copy( libs.begin(), libs.end(), ostream_iterator<string>(cout, " ") );
  cout << "] :::::: [DONE]" << endl;

  return sc;
}
template<class T >
IProperty* makeInstance ( const Member &  member,
const vector< void * > &  args 
)

Definition at line 425 of file genconf.cpp.

{
  Object dummy;
  T* obj;
#if ROOT_VERSION_CODE < ROOT_VERSION(5,21,6)
  obj = static_cast<T*>(member.Invoke(dummy,args).Address());
#else
  member.Invoke(dummy,obj,args);
#endif
  return dynamic_cast<IProperty*>(obj);
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 23:27:32 for Gaudi Framework, version v23r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004