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