All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/algorithm/string/replace.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/Auditor.h"
#include "GaudiKernel/AlgTool.h"
#include "GaudiKernel/Algorithm.h"
#include "GaudiKernel/Time.h"
#include <Gaudi/PluginService.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::string > Strings_t
 
typedef std::vector< fs::path > LibPathNames_t
 

Functions

int createAppMgr ()
 
int main (int argc, char **argv)
 

Typedef Documentation

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

Definition at line 81 of file genconf.cpp.

typedef std::vector<std::string> Strings_t

Definition at line 77 of file genconf.cpp.

Function Documentation

int createAppMgr ( )

Definition at line 858 of file genconf.cpp.

860 {
862  SmartIF<IProperty> propMgr ( iface );
863  SmartIF<IAppMgrUI> appUI ( iface );
864 
865  if ( propMgr.isValid() && appUI.isValid() ) {
866  propMgr->setProperty( "JobOptionsType", "NONE" ); // No job options
867  propMgr->setProperty( "AppName", ""); // No initial printout message
868  propMgr->setProperty( "OutputLevel", "7"); // No other printout messages
869  appUI->configure();
870  return EXIT_SUCCESS;
871  }
872  else {
873  return EXIT_FAILURE;
874  }
875 }
Definition of the basic interface.
Definition: IInterface.h:160
GAUDI_API IAppMgrUI * createApplicationMgr(const std::string &dllname, const std::string &factname)
int main ( int  argc,
char **  argv 
)

Definition at line 201 of file genconf.cpp.

203 {
204  fs::path pwd = fs::initial_path();
205  fs::path out;
206  Strings_t libs;
207  std::string pkgName;
208  std::string userModule;
209 
210  // declare a group of options that will be allowed only on command line
211  po::options_description generic("Generic options");
212  generic.add_options()
213  ("help,h",
214  "produce this help message")
215  ("package-name,p",
216  po::value<string>(),
217  "name of the package for which we create the configurables file")
218  ("input-libraries,i",
219  po::value<string>(),
220  "libraries to extract the component configurables from")
221  ("input-cfg,c",
222  po::value<string>(),
223  "path to the cfg file holding the description of the Configurable base "
224  "classes, the python module holding the Configurable definitions, etc...")
225  ("output-dir,o",
226  po::value<string>()->default_value("../genConf"),
227  "output directory for genconf files.")
228  ("debug-level,d",
229  po::value<int>()->default_value(0),
230  "debug level")
231  ("load-library,l",
232  po::value< Strings_t >()->composing(),
233  "preloading library")
234  ("user-module,m",
235  po::value<string>(),
236  "user-defined module to be imported by the genConf-generated one")
237  ("no-init",
238  "do not generate the (empty) __init__.py")
239  ;
240 
241  // declare a group of options that will be allowed both on command line
242  // _and_ in configuration file
243  po::options_description config("Configuration");
244  config.add_options()
245  ("configurable-module",
246  po::value<string>()->default_value("AthenaCommon"),
247  "Name of the module holding the configurable classes")
248  ("configurable-default-name",
249  po::value<string>()->default_value("Configurable.DefaultName"),
250  "Default name for the configurable instance")
251  ("configurable-algorithm",
252  po::value<string>()->default_value("ConfigurableAlgorithm"),
253  "Name of the configurable base class for Algorithm components")
254  ("configurable-algtool",
255  po::value<string>()->default_value("ConfigurableAlgTool"),
256  "Name of the configurable base class for AlgTool components")
257  ("configurable-auditor",
258  po::value<string>()->default_value("ConfigurableAuditor"),
259  "Name of the configurable base class for Auditor components")
260  ("configurable-service",
261  po::value<string>()->default_value("ConfigurableService"),
262  "Name of the configurable base class for Service components")
263  ;
264 
265  po::options_description cmdline_options;
266  cmdline_options.add(generic).add(config);
267 
268  po::options_description config_file_options;
269  config_file_options.add(config);
270 
271  po::options_description visible("Allowed options");
272  visible.add(generic).add(config);
273 
274  po::variables_map vm;
275 
276  try {
277  po::store( po::command_line_parser(argc, argv).
278  options(cmdline_options).run(),
279  vm );
280 
281  po::notify(vm);
282 
283  // try to read configuration from the optionally given configuration file
284  if( vm.count("input-cfg") ) {
285  string cfgFileName = vm["input-cfg"].as<string>();
286  cfgFileName = fs::system_complete( fs::path( cfgFileName ) ).string();
287  std::ifstream ifs( cfgFileName.c_str() );
288  po::store( parse_config_file( ifs, config_file_options ), vm );
289  }
290 
291  po::notify(vm);
292  }
293  catch ( po::error& err ) {
294  cout << "ERROR: error detected while parsing command options: "<< err.what() << endl;
295  return EXIT_FAILURE;
296  }
297 
298  //--- Process command options -----------------------------------------------
299  if( vm.count("help")) {
300  cout << visible << endl;
301  return EXIT_FAILURE;
302  }
303 
304  if( vm.count("package-name") ) {
305  pkgName = vm["package-name"].as<string>();
306  }
307  else {
308  cout << "ERROR: 'package-name' required" << endl;
309  cout << visible << endl;
310  return EXIT_FAILURE;
311  }
312 
313  if( vm.count("user-module") ) {
314  userModule = vm["user-module"].as<string>();
315  cout << "INFO: will import user module " << userModule << endl;
316  }
317 
318  if( vm.count("input-libraries") ) {
319  // re-shape the input arguments:
320  // - removes spurious spaces,
321  // - split into tokens.
322  Strings_t inputLibs;
323  {
324  string tmp = vm["input-libraries"].as<string>();
325  boost::trim(tmp);
326  boost::split( inputLibs, tmp,
327  boost::is_any_of(" "),
328  boost::token_compress_on );
329  }
330 
331  //
332  libs.reserve( inputLibs.size() );
333  for ( Strings_t::const_iterator iLib = inputLibs.begin();
334  iLib != inputLibs.end();
335  ++iLib ) {
336  std::string lib = fs::path(*iLib).stem().string();
337  if ( 0 == lib.find("lib") ) {
338  lib = lib.substr(3); // For *NIX remove "lib"
339  }
340  // remove duplicates
341  if ( !lib.empty() &&
342  std::find( libs.begin(), libs.end(), lib ) == libs.end() ) {
343  libs.push_back( lib );
344  }
345  } //> end loop over input-libraries
346  if ( libs.empty() ) {
347  cout << "ERROR: input component library(ies) required !\n"
348  << "ERROR: 'input-libraries' argument was ["
349  << vm["input-libraries"].as<string>()
350  << "]"
351  << endl;
352  return EXIT_FAILURE;
353  }
354  }
355  else {
356  cout << "ERROR: input component library(ies) required" << endl;
357  cout << visible << endl;
358  return EXIT_FAILURE;
359  }
360 
361  if( vm.count("output-dir") ) {
362  out = fs::system_complete( fs::path( vm["output-dir"].as<string>() ) );
363  }
364 
365  if ( vm.count("debug-level") ) {
366  Gaudi::PluginService::SetDebug( vm["debug-level"].as<int>() );
367  }
368 
369  if ( vm.count("load-library") ) {
370  Strings_t lLib_list = vm["load-library"].as< Strings_t >();
371  for (Strings_t::const_iterator lLib=lLib_list.begin();
372  lLib != lLib_list.end();
373  ++lLib) {
374  // load done through Gaudi helper class
375  System::ImageHandle tmp; // we ignore the library handle
376  unsigned long err = System::loadDynamicLib(*lLib, &tmp);
377  if (err != 1) {
378  cout << "WARNING: failed to load: "<< *lLib << endl;
379  }
380  }
381  }
382 
383 
384  if ( !fs::exists( out ) ) {
385  try {
386  fs::create_directory(out);
387  }
388  catch ( fs::filesystem_error &err ) {
389  cout << "ERROR: error creating directory: "<< err.what() << endl;
390  return EXIT_FAILURE;
391  }
392  }
393 
394  cout << ":::::: libraries : [ ";
395  copy( libs.begin(), libs.end(), ostream_iterator<string>(cout, " ") );
396  cout << "] ::::::" << endl;
397 
398  configGenerator py( pkgName, out.string() );
399  py.setConfigurableModule (vm["configurable-module"].as<string>());
400  py.setConfigurableDefaultName(vm["configurable-default-name"].as<string>());
401  py.setConfigurableAlgorithm (vm["configurable-algorithm"].as<string>());
402  py.setConfigurableAlgTool (vm["configurable-algtool"].as<string>());
403  py.setConfigurableAuditor (vm["configurable-auditor"].as<string>());
404  py.setConfigurableService (vm["configurable-service"].as<string>());
405 
406  int sc = EXIT_FAILURE;
407  try {
408  sc = py.genConfig( libs, userModule );
409  }
410  catch ( exception& e ) {
411  cout << "ERROR: Could not generate Configurable(s) !\n"
412  << "ERROR: Got exception: " << e.what() << endl;
413  return EXIT_FAILURE;
414  }
415 
416  if ( EXIT_SUCCESS == sc && ! vm.count("no-init")) {
417  // create an empty __init__.py file in the output dir
418  fstream initPy( ( out / fs::path( "__init__.py" ) ).string().c_str(),
419  std::ios_base::out|std::ios_base::trunc );
420  initPy << "## Hook for " << pkgName << " genConf module\n" << flush;
421  }
422 
423  cout << ":::::: libraries : [ ";
424  copy( libs.begin(), libs.end(), ostream_iterator<string>(cout, " ") );
425  cout << "] :::::: [DONE]" << endl;
426 
427  return sc;
428 }
GAUDI_API long argc()
Number of arguments passed to the commandline (==numCmdLineArgs()); just to match argv call...
Definition: System.cpp:526
std::vector< std::string > Strings_t
Definition: genconf.cpp:77
list argv
Definition: gaudirun.py:192
void * ImageHandle
Definition of an image handle.
Definition: ModuleInfo.h:30
void setConfigurableModule(const std::string &moduleName)
customize the Module name where configurable base classes are defined
Definition: genconf.cpp:138
GAUDIPS_API void SetDebug(int debugLevel)
Backward compatibility with Reflex.
list options
Definition: gaudirun.py:346
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition: System.cpp:123