All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
genconf.cpp
Go to the documentation of this file.
1 #ifdef _WIN32
2 // Disable a warning in Boost program_options headers:
3 // inconsistent linkage in program_options/variables_map.hpp
4 #pragma warning( disable : 4273 )
5 
6 // Avoid conflicts between windows and the message service.
7 #define NOMSG
8 #define NOGDI
9 #endif
10 
11 #ifdef __ICC
12 // disable icc warning #279: controlling expression is constant
13 // ... a lot of noise produced by the boost/filesystem/operations.hpp
14 #pragma warning( disable : 279 )
15 // Avoid icc remark #193: zero used for undefined preprocessing identifier "_MSC_VER"
16 #if !defined( _WIN32 ) && !defined( _MSC_VER )
17 #define _MSC_VER 0
18 #endif
19 #endif
20 
21 #include "boost/program_options.hpp"
22 // the hack for remark #193 is needed only for program_options and breaks regex.
23 #if defined( __ICC ) && !defined( _WIN32 ) && ( _MSC_VER == 0 )
24 #undef _MSC_VER
25 #endif
26 
27 // Include files----------------------------------------------------------------
28 #include "boost/algorithm/string/case_conv.hpp"
29 #include "boost/algorithm/string/classification.hpp"
30 #include "boost/algorithm/string/replace.hpp"
31 #include "boost/algorithm/string/split.hpp"
32 #include "boost/algorithm/string/trim.hpp"
33 #include "boost/filesystem/convenience.hpp"
34 #include "boost/filesystem/exception.hpp"
35 #include "boost/filesystem/operations.hpp"
36 #include "boost/format.hpp"
37 #include "boost/regex.hpp"
38 
39 #include <boost/log/core.hpp>
40 #include <boost/log/expressions.hpp>
41 #include <boost/log/trivial.hpp>
42 #include <boost/log/utility/setup/common_attributes.hpp>
43 #include <boost/log/utility/setup/console.hpp>
44 
45 #include "GaudiKernel/Bootstrap.h"
49 #include "GaudiKernel/HashMap.h"
50 #include "GaudiKernel/IAlgTool.h"
51 #include "GaudiKernel/IAlgorithm.h"
52 #include "GaudiKernel/IAppMgrUI.h"
53 #include "GaudiKernel/IAppMgrUI.h"
54 #include "GaudiKernel/IAuditor.h"
55 #include "GaudiKernel/IProperty.h"
57 #include "GaudiKernel/Service.h"
58 #include "GaudiKernel/SmartIF.h"
59 #include "GaudiKernel/System.h"
60 
61 #include "GaudiKernel/AlgTool.h"
62 #include "GaudiKernel/Algorithm.h"
63 #include "GaudiKernel/Auditor.h"
64 #include "GaudiKernel/Service.h"
65 
66 #include "GaudiKernel/Time.h"
67 
68 #include <Gaudi/PluginService.h>
69 
70 #include <algorithm>
71 #include <exception>
72 #include <fstream>
73 #include <iostream>
74 #include <set>
75 #include <sstream>
76 #include <vector>
77 
78 #include "DsoUtils.h"
79 
80 namespace po = boost::program_options;
81 namespace fs = boost::filesystem;
82 
83 #define LOG_ERROR BOOST_LOG_TRIVIAL( error )
84 #define LOG_WARNING BOOST_LOG_TRIVIAL( warning )
85 #define LOG_INFO BOOST_LOG_TRIVIAL( info )
86 #define LOG_DEBUG BOOST_LOG_TRIVIAL( debug )
87 
88 using namespace std;
90 
91 class IConverter;
92 
93 // useful typedefs
96 
97 namespace
98 {
99  const std::string py_tab = " ";
100 
103  const boost::regex pythonIdentifier( "^[a-zA-Z_][a-zA-Z0-9_]*$" );
104 }
105 
107 {
109  string m_pkgName;
110 
114 
117 
121 
123 
129 
136 
137 public:
138  configGenerator( const string& pkgName, const string& outputDirName )
139  : m_pkgName( pkgName )
140  , m_outputDirName( outputDirName )
141  , m_pyBuf()
142  , m_importGaudiHandles( false )
143  , m_importDataObjectHandles( false )
144  , m_dbBuf()
145  , m_configurable()
146  {
147  }
148 
153  int genConfig( const Strings_t& modules, const string& userModule );
154 
156  void setConfigurableModule( const std::string& moduleName ) { m_configurable["Module"] = moduleName; }
157 
159  void setConfigurableDefaultName( const std::string& defaultName ) { m_configurable["DefaultName"] = defaultName; }
160 
162  void setConfigurableAlgorithm( const std::string& cfgAlgorithm ) { m_configurable["Algorithm"] = cfgAlgorithm; }
163 
165  void setConfigurableAlgTool( const std::string& cfgAlgTool ) { m_configurable["AlgTool"] = cfgAlgTool; }
166 
168  void setConfigurableAuditor( const std::string& cfgAuditor ) { m_configurable["Auditor"] = cfgAuditor; }
169 
171  void setConfigurableService( const std::string& cfgService )
172  {
173  m_configurable["Service"] = cfgService;
174  m_configurable["ApplicationMgr"] = cfgService;
175  }
176 
177 private:
178  int genComponent( const std::string& libName, const std::string& componentName, const std::string& componentType,
180  void genImport( std::ostream& s, const boost::format& frmt, std::string indent );
181  void genHeader( std::ostream& pyOut, std::ostream& dbOut );
182  void genBody( std::ostream& pyOut, std::ostream& dbOut )
183  {
184  pyOut << m_pyBuf.str() << flush;
185  dbOut << m_dbBuf.str() << flush;
186  }
187  void genTrailer( std::ostream& pyOut, std::ostream& dbOut );
188 
190  void pythonizeValue( const PropertyBase* prop, string& pvalue, string& ptype );
191 
193  void pythonizeName( string& name );
194 };
195 
196 int createAppMgr();
197 
198 void init_logging( boost::log::trivial::severity_level level )
199 {
200  namespace logging = boost::log;
201  namespace keywords = boost::log::keywords;
202  namespace expr = boost::log::expressions;
203 
204  logging::add_console_log( std::cout, keywords::format =
205  ( expr::stream << "[" << std::setw( 7 ) << std::left
206  << logging::trivial::severity << "] " << expr::smessage ) );
207 
208  logging::core::get()->set_filter( logging::trivial::severity >= level );
209 }
210 
211 //--- Command main program-----------------------------------------------------
212 int main( int argc, char** argv )
213 //-----------------------------------------------------------------------------
214 {
215  init_logging( ( System::isEnvSet( "VERBOSE" ) && !System::getEnv( "VERBOSE" ).empty() )
216  ? boost::log::trivial::info
217  : boost::log::trivial::warning );
218 
219  fs::path pwd = fs::initial_path();
220  fs::path out;
221  Strings_t libs;
222  std::string pkgName;
223  std::string userModule;
224 
225  // declare a group of options that will be allowed only on command line
226  po::options_description generic( "Generic options" );
227  generic.add_options()( "help,h", "produce this help message" )(
228  "package-name,p", po::value<string>(), "name of the package for which we create the configurables file" )(
229  "input-libraries,i", po::value<string>(), "libraries to extract the component configurables from" )(
230  "input-cfg,c", po::value<string>(), "path to the cfg file holding the description of the Configurable base "
231  "classes, the python module holding the Configurable definitions, etc..." )(
232  "output-dir,o", po::value<string>()->default_value( "../genConf" ),
233  "output directory for genconf files." )( "debug-level,d", po::value<int>()->default_value( 0 ), "debug level" )(
234  "load-library,l", po::value<Strings_t>()->composing(), "preloading library" )(
235  "user-module,m", po::value<string>(), "user-defined module to be imported by the genConf-generated one" )(
236  "no-init", "do not generate the (empty) __init__.py" );
237 
238  // declare a group of options that will be allowed both on command line
239  // _and_ in configuration file
240  po::options_description config( "Configuration" );
241  config.add_options()( "configurable-module", po::value<string>()->default_value( "AthenaCommon" ),
242  "Name of the module holding the configurable classes" )(
243  "configurable-default-name", po::value<string>()->default_value( "Configurable.DefaultName" ),
244  "Default name for the configurable instance" )( "configurable-algorithm",
245  po::value<string>()->default_value( "ConfigurableAlgorithm" ),
246  "Name of the configurable base class for Algorithm components" )(
247  "configurable-algtool", po::value<string>()->default_value( "ConfigurableAlgTool" ),
248  "Name of the configurable base class for AlgTool components" )(
249  "configurable-auditor", po::value<string>()->default_value( "ConfigurableAuditor" ),
250  "Name of the configurable base class for Auditor components" )(
251  "configurable-service", po::value<string>()->default_value( "ConfigurableService" ),
252  "Name of the configurable base class for Service components" );
253 
254  po::options_description cmdline_options;
255  cmdline_options.add( generic ).add( config );
256 
257  po::options_description config_file_options;
258  config_file_options.add( config );
259 
260  po::options_description visible( "Allowed options" );
261  visible.add( generic ).add( config );
262 
263  po::variables_map vm;
264 
265  try {
266  po::store( po::command_line_parser( argc, argv ).options( cmdline_options ).run(), vm );
267 
268  po::notify( vm );
269 
270  // try to read configuration from the optionally given configuration file
271  if ( vm.count( "input-cfg" ) ) {
272  string cfgFileName = vm["input-cfg"].as<string>();
273  cfgFileName = fs::system_complete( fs::path( cfgFileName ) ).string();
274  std::ifstream ifs( cfgFileName );
275  po::store( parse_config_file( ifs, config_file_options ), vm );
276  }
277 
278  po::notify( vm );
279  } catch ( po::error& err ) {
280  LOG_ERROR << "error detected while parsing command options: " << err.what();
281  return EXIT_FAILURE;
282  }
283 
284  //--- Process command options -----------------------------------------------
285  if ( vm.count( "help" ) ) {
286  cout << visible << endl;
287  return EXIT_FAILURE;
288  }
289 
290  if ( vm.count( "package-name" ) ) {
291  pkgName = vm["package-name"].as<string>();
292  } else {
293  LOG_ERROR << "'package-name' required";
294  cout << visible << endl;
295  return EXIT_FAILURE;
296  }
297 
298  if ( vm.count( "user-module" ) ) {
299  userModule = vm["user-module"].as<string>();
300  LOG_INFO << "INFO: will import user module " << userModule;
301  }
302 
303  if ( vm.count( "input-libraries" ) ) {
304  // re-shape the input arguments:
305  // - removes spurious spaces,
306  // - split into tokens.
307  Strings_t inputLibs;
308  {
309  string tmp = vm["input-libraries"].as<string>();
310  boost::trim( tmp );
311  boost::split( inputLibs, tmp, boost::is_any_of( " " ), boost::token_compress_on );
312  }
313 
314  //
315  libs.reserve( inputLibs.size() );
316  for ( Strings_t::const_iterator iLib = inputLibs.begin(); iLib != inputLibs.end(); ++iLib ) {
317  std::string lib = fs::path( *iLib ).stem().string();
318  if ( 0 == lib.find( "lib" ) ) {
319  lib = lib.substr( 3 ); // For *NIX remove "lib"
320  }
321  // remove duplicates
322  if ( !lib.empty() && std::find( libs.begin(), libs.end(), lib ) == libs.end() ) {
323  libs.push_back( lib );
324  }
325  } //> end loop over input-libraries
326  if ( libs.empty() ) {
327  LOG_ERROR << "input component library(ies) required !\n";
328  LOG_ERROR << "'input-libraries' argument was [" << vm["input-libraries"].as<string>() << "]";
329  return EXIT_FAILURE;
330  }
331  } else {
332  LOG_ERROR << "input component library(ies) required";
333  cout << visible << endl;
334  return EXIT_FAILURE;
335  }
336 
337  if ( vm.count( "output-dir" ) ) {
338  out = fs::system_complete( fs::path( vm["output-dir"].as<string>() ) );
339  }
340 
341  if ( vm.count( "debug-level" ) ) {
342  Gaudi::PluginService::SetDebug( vm["debug-level"].as<int>() );
343  }
344 
345  if ( vm.count( "load-library" ) ) {
346  Strings_t lLib_list = vm["load-library"].as<Strings_t>();
347  for ( Strings_t::const_iterator lLib = lLib_list.begin(); lLib != lLib_list.end(); ++lLib ) {
348  // load done through Gaudi helper class
349  System::ImageHandle tmp; // we ignore the library handle
350  unsigned long err = System::loadDynamicLib( *lLib, &tmp );
351  if ( err != 1 ) {
352  LOG_WARNING << "failed to load: " << *lLib;
353  }
354  }
355  }
356 
357  if ( !fs::exists( out ) ) {
358  try {
359  fs::create_directory( out );
360  } catch ( fs::filesystem_error& err ) {
361  LOG_ERROR << "error creating directory: " << err.what();
362  return EXIT_FAILURE;
363  }
364  }
365 
366  {
368  msg << ":::::: libraries : [ ";
369  copy( libs.begin(), libs.end(), ostream_iterator<string>( msg, " " ) );
370  msg << "] ::::::";
371  LOG_INFO << msg.str();
372  }
373 
374  configGenerator py( pkgName, out.string() );
375  py.setConfigurableModule( vm["configurable-module"].as<string>() );
376  py.setConfigurableDefaultName( vm["configurable-default-name"].as<string>() );
377  py.setConfigurableAlgorithm( vm["configurable-algorithm"].as<string>() );
378  py.setConfigurableAlgTool( vm["configurable-algtool"].as<string>() );
379  py.setConfigurableAuditor( vm["configurable-auditor"].as<string>() );
380  py.setConfigurableService( vm["configurable-service"].as<string>() );
381 
382  int sc = EXIT_FAILURE;
383  try {
384  sc = py.genConfig( libs, userModule );
385  } catch ( exception& e ) {
386  cout << "ERROR: Could not generate Configurable(s) !\n"
387  << "ERROR: Got exception: " << e.what() << endl;
388  return EXIT_FAILURE;
389  }
390 
391  if ( EXIT_SUCCESS == sc && !vm.count( "no-init" ) ) {
392  // create an empty __init__.py file in the output dir
393  fstream initPy( ( out / fs::path( "__init__.py" ) ).string(), std::ios_base::out | std::ios_base::trunc );
394  initPy << "## Hook for " << pkgName << " genConf module\n" << flush;
395  }
396 
397  {
399  msg << ":::::: libraries : [ ";
400  copy( libs.begin(), libs.end(), ostream_iterator<string>( msg, " " ) );
401  msg << "] :::::: [DONE]";
402  LOG_INFO << msg.str();
403  }
404  return sc;
405 }
406 
407 //-----------------------------------------------------------------------------
408 int configGenerator::genConfig( const Strings_t& libs, const string& userModule )
409 //-----------------------------------------------------------------------------
410 {
411  //--- Disable checking StatusCode -------------------------------------------
413 
414  const Strings_t::const_iterator endLib = libs.end();
415 
416  const std::string gaudiSvc = "GaudiCoreSvc";
417  const bool isGaudiSvc = ( std::find( libs.begin(), endLib, gaudiSvc ) != endLib );
418 
419  //--- Instantiate ApplicationMgr --------------------------------------------
420  if ( !isGaudiSvc && createAppMgr() ) {
421  cout << "ERROR: ApplicationMgr can not be created. Check environment" << endl;
422  return EXIT_FAILURE;
423  }
424 
425  //--- Iterate over component factories --------------------------------------
427  Registry& registry = Registry::instance();
428 
429  std::set<std::string> bkgNames = registry.loadedFactories();
430 
431  ISvcLocator* svcLoc = Gaudi::svcLocator();
432  IInterface* dummySvc = new Service( "DummySvc", svcLoc );
433  dummySvc->addRef();
434 
435  bool allGood = true;
436 
437  // iterate over all the requested libraries
438  for ( Strings_t::const_iterator iLib = libs.begin(); iLib != endLib; ++iLib ) {
439 
440  LOG_INFO << ":::: processing library: " << *iLib << "...";
441 
442  // reset state
443  m_importGaudiHandles = false;
444  m_importDataObjectHandles = false;
445  m_pyBuf.str( "" );
446  m_dbBuf.str( "" );
447 
448  //--- Load component library ----------------------------------------------
449  System::ImageHandle handle;
450  unsigned long err = System::loadDynamicLib( *iLib, &handle );
451  if ( err != 1 ) {
453  allGood = false;
454  continue;
455  }
456 
457  std::set<std::string> factories = registry.loadedFactories();
458 
459  for ( std::set<std::string>::iterator it = factories.begin(); it != factories.end(); ++it ) {
460  const string ident = *it;
461  if ( bkgNames.find( ident ) != bkgNames.end() ) {
463  LOG_INFO << "\t==> skipping [" << ident << "]...";
464  }
465  continue;
466  }
467 
468  const Registry::FactoryInfo info = registry.getInfo( *it );
469  const string rtype = info.rtype;
470 
471  // do not generate configurables for the Reflex-compatible aliases
472  if ( info.properties.find( "ReflexName" ) != info.properties.end() ) continue;
473 
474  // Atlas contributed code (patch #1247)
475  // Skip the generation of configurables if the component does not come
476  // from the same library we are processing (i.e. we found a symbol that
477  // is coming from a library loaded by the linker).
478  if ( !DsoUtils::inDso( info.ptr, DsoUtils::libNativeName( *iLib ) ) ) {
479  LOG_WARNING << "library [" << *iLib << "] exposes factory [" << ident << "] which is declared in ["
480  << DsoUtils::dsoName( info.ptr ) << "] !!";
481  continue;
482  }
483 
484  string type;
485  bool known = true;
486  if ( ident == "ApplicationMgr" )
487  type = "ApplicationMgr";
488  else if ( rtype == typeid( IInterface* ).name() )
489  type = "IInterface";
490  else if ( rtype == typeid( IAlgorithm* ).name() )
491  type = "Algorithm";
492  else if ( rtype == typeid( IService* ).name() )
493  type = "Service";
494  else if ( rtype == typeid( IAlgTool* ).name() )
495  type = "AlgTool";
496  else if ( rtype == typeid( IAuditor* ).name() )
497  type = "Auditor";
498  else if ( rtype == typeid( IConverter* ).name() )
499  type = "Converter";
500  else if ( rtype == typeid( DataObject* ).name() )
501  type = "DataObject";
502  else
503  type = "Unknown", known = false;
504  string name = ident;
505  // handle possible problems with templated components
506  boost::trim( name );
507 
508  if ( type == "IInterface" ) {
511  continue;
512  }
513 
514  if ( type == "Converter" || type == "DataObject" ) {
516  continue;
517  }
518 
519  if ( !known ) {
520  LOG_WARNING << "Unknown (return) type [" << System::typeinfoName( rtype.c_str() ) << "] !!"
521  << " Component [" << ident << "] is skipped !";
522  continue;
523  }
524 
525  LOG_INFO << " - component: " << info.className << " ("
526  << ( info.className != name ? ( name + ": " ) : std::string() ) << type << ")";
527 
528  string cname = "DefaultName";
529  SmartIF<IProperty> prop;
530  try {
531  if ( type == "Algorithm" ) {
532  prop = SmartIF<IAlgorithm>( Algorithm::Factory::create( ident, cname, svcLoc ) );
533  } else if ( type == "Service" ) {
534  prop = SmartIF<IService>( Service::Factory::create( ident, cname, svcLoc ) );
535  } else if ( type == "AlgTool" ) {
536  prop = SmartIF<IAlgTool>( AlgTool::Factory::create( ident, cname, type, dummySvc ) );
537  // FIXME: AlgTool base class increase artificially by 1 the refcount.
538  prop->release();
539  } else if ( type == "Auditor" ) {
540  prop = SmartIF<IAuditor>( Auditor::Factory::create( ident, cname, svcLoc ) );
541  } else if ( type == "ApplicationMgr" ) {
542  prop = SmartIF<ISvcLocator>( svcLoc );
543  } else {
544  continue; // unknown
545  }
546  } catch ( exception& e ) {
547  LOG_ERROR << "Error instantiating " << name << " from " << *iLib;
548  LOG_ERROR << "Got exception: " << e.what();
549  allGood = false;
550  continue;
551  } catch ( ... ) {
552  LOG_ERROR << "Error instantiating " << name << " from " << *iLib;
553  allGood = false;
554  continue;
555  }
556  if ( prop ) {
557  if ( genComponent( *iLib, name, type, prop->getProperties() ) ) {
558  allGood = false;
559  }
560  prop.reset();
561  } else {
562  LOG_ERROR << "could not cast IInterface* object to an IProperty* !";
563  LOG_ERROR << "return type from PluginSvc is [" << rtype << "]...";
564  LOG_ERROR << "NO Configurable will be generated for [" << name << "] !";
565  allGood = false;
566  }
567  } //> end loop over factories
568 
572  const std::string pyName = ( fs::path( m_outputDirName ) / fs::path( *iLib + "Conf.py" ) ).string();
573  const std::string dbName = ( fs::path( m_outputDirName ) / fs::path( *iLib + ".confdb" ) ).string();
574 
575  std::fstream py( pyName, std::ios_base::out | std::ios_base::trunc );
576  std::fstream db( dbName, std::ios_base::out | std::ios_base::trunc );
577 
578  genHeader( py, db );
579  if ( !userModule.empty() ) py << "from " << userModule << " import *" << endl;
580  genBody( py, db );
581  genTrailer( py, db );
582 
583  } //> end loop over libraries
584 
585  dummySvc->release();
586  dummySvc = 0;
587 
588  return allGood ? EXIT_SUCCESS : EXIT_FAILURE;
589 }
590 
592 {
593 
594  std::string::size_type pos = 0, nxtpos = 0;
596 
597  while ( std::string::npos != pos ) {
598  // find end of module name
599  nxtpos = m_configurable["Module"].find_first_of( ',', pos );
600 
601  // Prepare import string
602  mod = m_configurable["Module"].substr( pos, nxtpos - pos );
603  std::ostringstream import;
604  import << boost::format( frmt ) % mod;
605 
606  // append a normal import or a try/except enclosed one depending
607  // on availability of a fall-back module (next in the list)
608  if ( std::string::npos == nxtpos ) {
609  // last possible module
610  s << indent << import.str() << "\n" << flush;
611  pos = std::string::npos;
612  } else {
613  // we have a fallback for this
614  s << indent << "try:\n" << indent << py_tab << import.str() << "\n" << indent << "except ImportError:\n" << flush;
615  pos = nxtpos + 1;
616  }
617  // increase indentation level for next iteration
618  indent += py_tab;
619  }
620 }
621 
622 //-----------------------------------------------------------------------------
624 //-----------------------------------------------------------------------------
625 {
626  // python file part
627  std::string now = Gaudi::Time::current().format( true );
628  py << "#" << now //<< "\n"
629  << "\"\"\"Automatically generated. DO NOT EDIT please\"\"\"\n";
630  if ( m_importGaudiHandles ) {
631  py << "from GaudiKernel.GaudiHandles import *\n";
632  }
633 
634  if ( m_importDataObjectHandles ) {
635  py << "from GaudiKernel.DataObjectHandleBase import *\n";
636  }
637 
638  genImport( py, boost::format( "from %1%.Configurable import *" ) );
639 
640  // db file part
641  db << "## -*- ascii -*- \n"
642  << "# db file automatically generated by genconf on: " << now << "\n"
643  << flush;
644 }
645 //-----------------------------------------------------------------------------
647 //-----------------------------------------------------------------------------
648 {
649  // db file part
650  db << "## " << m_pkgName << "\n" << std::flush;
651 }
652 
653 //-----------------------------------------------------------------------------
654 int configGenerator::genComponent( const std::string& libName, const std::string& componentName,
655  const std::string& componentType, const vector<PropertyBase*>& properties )
656 //-----------------------------------------------------------------------------
657 {
658  string cname = componentName;
659  pythonizeName( cname );
660 
661  typedef GaudiUtils::HashMap<std::string, std::string> PropertyDoc_t;
662  PropertyDoc_t propDoc;
663 
664  m_pyBuf << "\n";
665  m_pyBuf << "class " << cname << "( " << m_configurable[componentType] << " ) :"
666  << "\n";
667  m_pyBuf << " __slots__ = { \n";
668  for ( vector<PropertyBase*>::const_iterator it = properties.begin(); it != properties.end(); ++it ) {
669 
670  const string pname = ( *it )->name();
671  // Validate property name (it must be a valid Python identifier)
672  if ( !boost::regex_match( pname, pythonIdentifier ) ) {
673  std::cout << "ERROR: invalid property name \"" << pname << "\" in component " << cname
674  << " (invalid Python identifier)" << std::endl;
675  // try to make the buffer at least more or less valid python code.
676  m_pyBuf << " #ERROR-invalid identifier '" << pname << "'\n"
677  << " }\n";
678  return 1;
679  }
680 
681  string pvalue, ptype;
682  pythonizeValue( ( *it ), pvalue, ptype );
683  m_pyBuf << " '" << pname << "' : " << pvalue << ", # " << ptype << "\n";
684 
685  if ( ( *it )->documentation() != "none" ) {
686  propDoc[pname] = ( *it )->documentation();
687  }
688  }
689  m_pyBuf << " }\n";
690  m_pyBuf << " _propertyDocDct = { \n";
691  for ( PropertyDoc_t::const_iterator iProp = propDoc.begin(); iProp != propDoc.end(); ++iProp ) {
692  m_pyBuf << std::setw( 5 ) << "'" << iProp->first << "' : "
693  << "\"\"\" " << iProp->second << " \"\"\",\n";
694  }
695  m_pyBuf << " }\n";
696 
697  m_pyBuf << " def __init__(self, name = " << m_configurable["DefaultName"] << ", **kwargs):\n"
698  << " super(" << cname << ", self).__init__(name)\n"
699  << " for n,v in kwargs.items():\n"
700  << " setattr(self, n, v)\n"
701  << " def getDlls( self ):\n"
702  << " return '" << libName << "'\n"
703  << " def getType( self ):\n"
704  << " return '" << componentName << "'\n"
705  << " pass # class " << cname << "\n"
706  << flush;
707 
708  // name of the auto-generated module
709  const string pyName = ( fs::path( m_outputDirName ) / fs::path( libName + "Conf.py" ) ).string();
710  const string modName = fs::basename( fs::path( pyName ).leaf() );
711 
712  // now the db part
713  m_dbBuf << m_pkgName << "." << modName << " " << libName << " " << cname << "\n" << flush;
714 
715  return 0;
716 }
717 //-----------------------------------------------------------------------------
719 //-----------------------------------------------------------------------------
720 {
721  static string in( "<>&*,: ()." );
722  static string out( "__rp__s___" );
723  boost::algorithm::replace_all( name, ", ", "," );
724  for ( string::iterator i = name.begin(); i != name.end(); ++i ) {
725  if ( in.find( *i ) != string::npos ) *i = out[in.find( *i )];
726  }
727 }
728 
729 //-----------------------------------------------------------------------------
730 void configGenerator::pythonizeValue( const PropertyBase* p, string& pvalue, string& ptype )
731 //-----------------------------------------------------------------------------
732 {
733  const std::string cvalue = p->toString();
734  const type_info& ti = *p->type_info();
735  if ( ti == typeid( bool ) ) {
736  pvalue = ( cvalue == "0" || cvalue == "False" || cvalue == "false" ) ? "False" : "True";
737  ptype = "bool";
738  } else if ( ti == typeid( char ) || ti == typeid( signed char ) || ti == typeid( unsigned char ) ||
739  ti == typeid( short ) || ti == typeid( unsigned short ) || ti == typeid( int ) ||
740  ti == typeid( unsigned int ) || ti == typeid( long ) || ti == typeid( unsigned long ) ) {
741  pvalue = cvalue;
742  ptype = "int";
743  } else if ( ti == typeid( long long ) || ti == typeid( unsigned long long ) ) {
744  pvalue = cvalue + "L";
745  ptype = "long";
746  } else if ( ti == typeid( float ) || ti == typeid( double ) ) {
747  // forces python to handle this as a float: put a dot in there...
748  pvalue = boost::to_lower_copy( cvalue );
749  if ( pvalue == "nan" ) {
750  pvalue = "float('nan')";
751  std::cout << "WARNING: default value for [" << p->name() << "] is NaN !!" << std::endl;
752  } else if ( std::string::npos == pvalue.find( "." ) && std::string::npos == pvalue.find( "e" ) ) {
753  pvalue = cvalue + ".0";
754  }
755  ptype = "float";
756  } else if ( ti == typeid( string ) ) {
757 
758  pvalue = "'" + cvalue + "'";
759  ptype = "str";
760  } else if ( ti == typeid( GaudiHandleBase ) ) {
761  m_importGaudiHandles = true;
762  const GaudiHandleProperty& hdl = dynamic_cast<const GaudiHandleProperty&>( *p );
763  const GaudiHandleBase& base = hdl.value();
764 
765  pvalue = base.pythonRepr();
766  ptype = "GaudiHandle";
767  } else if ( ti == typeid( GaudiHandleArrayBase ) ) {
768  m_importGaudiHandles = true;
769  const GaudiHandleArrayProperty& hdl = dynamic_cast<const GaudiHandleArrayProperty&>( *p );
770  const GaudiHandleArrayBase& base = hdl.value();
771 
772  pvalue = base.pythonRepr();
773  ptype = "GaudiHandleArray";
774  } else if ( ti == typeid( DataObjectHandleBase ) ) {
775  m_importDataObjectHandles = true;
776  const DataObjectHandleProperty& hdl = dynamic_cast<const DataObjectHandleProperty&>( *p );
777  const DataObjectHandleBase& base = hdl.value();
778 
779  pvalue = base.pythonRepr();
780  ptype = "DataObjectHandleBase";
781  } else {
782  std::ostringstream v_str;
783  v_str.setf( std::ios::showpoint ); // to correctly display floats
784  p->toStream( v_str );
785  pvalue = v_str.str();
786  ptype = "list";
787  }
788 }
789 
790 //-----------------------------------------------------------------------------
792 //-----------------------------------------------------------------------------
793 {
795  SmartIF<IAppMgrUI> appUI( iface );
796  auto propMgr = appUI.as<IProperty>();
797 
798  if ( !propMgr || !appUI ) return EXIT_FAILURE;
799  propMgr->setProperty( "JobOptionsType", "NONE" ); // No job options
800  propMgr->setProperty( "AppName", "" ); // No initial printout message
801  propMgr->setProperty( "OutputLevel", "7" ); // No other printout messages
802  appUI->configure();
804  msgSvc->setProperty( "setWarning", "['DefaultName', 'PropertyHolder']" );
805  msgSvc->setProperty( "Format", "%T %0W%M" );
806  return EXIT_SUCCESS;
807 }
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:550
int genConfig(const Strings_t &modules, const string &userModule)
main entry point of this class:
Definition: genconf.cpp:408
T setf(T...args)
T empty(T...args)
T copy(T...args)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
The data converters are responsible to translate data from one representation into another...
Definition: IConverter.h:57
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
std::vector< std::string > Strings_t
Definition: genconf.cpp:91
-*- C++ -*- /////////////////////////////
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:299
const std::string name() const
property name
Definition: Property.h:40
static Time current(void)
Returns the current time.
Definition: Time.cpp:113
list argv
Definition: gaudirun.py:227
void pythonizeName(string &name)
Translates a valid C++ typename into a valid python one.
Definition: genconf.cpp:718
#define LOG_ERROR
Definition: genconf.cpp:83
T endl(T...args)
T left(T...args)
void setConfigurableDefaultName(const std::string &defaultName)
customize the default name for configurable instances
Definition: genconf.cpp:159
STL namespace.
std::vector< fs::path > LibPathNames_t
Definition: genconf.cpp:95
void setConfigurableAlgTool(const std::string &cfgAlgTool)
customize the configurable base class for AlgTool component
Definition: genconf.cpp:165
T end(T...args)
void * ImageHandle
Definition of an image handle.
Definition: ModuleInfo.h:30
virtual std::string toString() const =0
value -> string
GaudiUtils::HashMap< std::string, std::string > m_configurable
Configurable customization.
Definition: genconf.cpp:135
stringstream m_pyBuf
buffer of auto-generated configurables
Definition: genconf.cpp:116
GAUDIPS_API Logger & logger()
Return the current logger instance.
virtual void toStream(std::ostream &out) const =0
value -> stream
T setw(T...args)
DataObjectHandleProperty.h GaudiKernel/DataObjectHandleProperty.h.
int genComponent(const std::string &libName, const std::string &componentName, const std::string &componentType, const vector< PropertyBase * > &properties)
Definition: genconf.cpp:654
void setConfigurableModule(const std::string &moduleName)
customize the Module name where configurable base classes are defined
Definition: genconf.cpp:156
STL class.
T push_back(T...args)
GAUDIPS_API void SetDebug(int debugLevel)
Backward compatibility with Reflex.
virtual StatusCode setProperty(const Gaudi::Details::PropertyBase &p)=0
Set the property by property.
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:110
int main(int argc, char **argv)
Definition: genconf.cpp:212
bool m_importDataObjectHandles
Definition: genconf.cpp:122
GAUDI_API ISvcLocator * svcLocator()
T what(T...args)
#define LOG_INFO
Definition: genconf.cpp:85
General service interface definition.
Definition: IService.h:18
Definition of the basic interface.
Definition: IInterface.h:234
STL class.
const GaudiHandleBase & value() const
Definition: Property.h:817
void genHeader(std::ostream &pyOut, std::ostream &dbOut)
Definition: genconf.cpp:623
T str(T...args)
const GaudiHandleArrayBase & value() const
Definition: Property.h:857
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
stringstream m_dbBuf
buffer of generated configurables informations for the "Db" file The "Db" file is holding information...
Definition: genconf.cpp:128
configGenerator(const string &pkgName, const string &outputDirName)
Definition: genconf.cpp:138
STL class.
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:27
std::string pythonRepr() const override
Python representation of array of handles, i.e.
Definition: GaudiHandle.cpp:94
void setConfigurableAlgorithm(const std::string &cfgAlgorithm)
customize the configurable base class for Algorithm component
Definition: genconf.cpp:162
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const =0
Get list of properties.
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition: System.cpp:570
T flush(T...args)
void init_logging(boost::log::trivial::severity_level level)
Definition: genconf.cpp:198
T find(T...args)
T size(T...args)
Base class of array&#39;s of various gaudihandles.
Definition: GaudiHandle.h:364
string m_outputDirName
absolute path to the directory where genconf will store auto-generated files (Configurables and Confi...
Definition: genconf.cpp:113
void pythonizeValue(const PropertyBase *prop, string &pvalue, string &ptype)
handle the "marshalling" of Properties
Definition: genconf.cpp:730
virtual unsigned long release()=0
Release Interface instance.
#define LOG_WARNING
Definition: genconf.cpp:84
DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.
void genImport(std::ostream &s, const boost::format &frmt, std::string indent)
Definition: genconf.cpp:591
T begin(T...args)
std::string pythonRepr() const override
Python representation of handle, i.e.
Definition: GaudiHandle.cpp:56
bool m_importGaudiHandles
switch to decide if the generated configurables need to import GaudiHandles (ie: if one of the compon...
Definition: genconf.cpp:120
void setConfigurableService(const std::string &cfgService)
customize the configurable base class for Service component
Definition: genconf.cpp:171
T c_str(T...args)
GAUDI_API const std::string & moduleName()
Get the name of the (executable/DLL) file without file-type.
Definition: ModuleInfo.cpp:54
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
string s
Definition: gaudirun.py:245
std::string pythonRepr() const override
In-memory database of the loaded factories.
string m_pkgName
name of the package we are processing
Definition: genconf.cpp:109
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
T substr(T...args)
static GAUDI_API void disableChecking()
Definition: StatusCode.cpp:23
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
void genTrailer(std::ostream &pyOut, std::ostream &dbOut)
Definition: genconf.cpp:646
const DataObjectHandleBase & value() const
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
Definition: System.cpp:256
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
Definition: GaudiHandle.h:94
virtual StatusCode configure()=0
Configure the job.
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:20
Base class for all services.
Definition: Service.h:36
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
int createAppMgr()
Definition: genconf.cpp:791
The IAuditor is the interface implmented by the AlgAuditor base class.
Definition: IAuditor.h:18
STL class.
std::string libNativeName(const std::string &libName)
Definition: DsoUtils.h:18
void genBody(std::ostream &pyOut, std::ostream &dbOut)
Definition: genconf.cpp:182
STL class.
const std::type_info * type_info() const
property type-info
Definition: Property.h:44
std::string format(bool local, std::string spec="%c") const
Format the time using strftime.
Definition: Time.cpp:279
GAUDI_API IAppMgrUI * createApplicationMgr(const std::string &dllname, const std::string &factname)
T reserve(T...args)
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition: System.cpp:126
void setConfigurableAuditor(const std::string &cfgAuditor)
customize the configurable base class for AlgTool component
Definition: genconf.cpp:168