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/DataObjectHandleBase.h"
#include "GaudiKernel/DataObjectHandleProperty.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::stringStrings_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 83 of file genconf.cpp.

Definition at line 79 of file genconf.cpp.

Function Documentation

int createAppMgr ( )

Definition at line 875 of file genconf.cpp.

877 {
879  SmartIF<IAppMgrUI> appUI ( iface );
880  auto propMgr = appUI.as<IProperty>();
881 
882  if ( !propMgr || !appUI ) return EXIT_FAILURE;
883  propMgr->setProperty( "JobOptionsType", "NONE" ); // No job options
884  propMgr->setProperty( "AppName", ""); // No initial printout message
885  propMgr->setProperty( "OutputLevel", "7"); // No other printout messages
886  appUI->configure();
888  msgSvc->setProperty("setWarning", "['DefaultName', 'PropertyMgr']");
889  msgSvc->setProperty("Format", "%T %0W%M");
890  return EXIT_SUCCESS;
891 }
Definition of the basic interface.
Definition: IInterface.h:234
virtual StatusCode setProperty(const Property &p)=0
Set the property by property.
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:21
GAUDI_API IAppMgrUI * createApplicationMgr(const std::string &dllname, const std::string &factname)
int main ( int  argc,
char **  argv 
)

Definition at line 206 of file genconf.cpp.

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