| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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/filesystem/operations.hpp"
29 #include "boost/filesystem/exception.hpp"
30 #include "boost/filesystem/convenience.hpp"
31 #include "boost/algorithm/string/split.hpp"
32 #include "boost/algorithm/string/classification.hpp"
33 #include "boost/algorithm/string/trim.hpp"
34 #include "boost/algorithm/string/case_conv.hpp"
35 #include "boost/algorithm/string/replace.hpp"
36 #include "boost/format.hpp"
37 #include "boost/regex.hpp"
38
39 #include "GaudiKernel/System.h"
40 #include "GaudiKernel/ISvcLocator.h"
41 #include "GaudiKernel/IProperty.h"
42 #include "GaudiKernel/IAppMgrUI.h"
43 #include "GaudiKernel/IAlgorithm.h"
44 #include "GaudiKernel/IAlgTool.h"
45 #include "GaudiKernel/IAuditor.h"
46 #include "GaudiKernel/IAppMgrUI.h"
47 #include "GaudiKernel/Service.h"
48 #include "GaudiKernel/Bootstrap.h"
49 #include "GaudiKernel/SmartIF.h"
50 #include "GaudiKernel/HashMap.h"
51 #include "GaudiKernel/GaudiHandle.h"
52 #include "GaudiKernel/DataObjectHandleBase.h"
53 #include "GaudiKernel/DataObjectHandleProperty.h"
54
55 #include "GaudiKernel/Auditor.h"
56 #include "GaudiKernel/Service.h"
57 #include "GaudiKernel/AlgTool.h"
58 #include "GaudiKernel/Algorithm.h"
59
60 #include "GaudiKernel/Time.h"
61
62 #include <Gaudi/PluginService.h>
63
64 #include <algorithm>
65 #include <iostream>
66 #include <fstream>
67 #include <sstream>
68 #include <exception>
69 #include <set>
70 #include <vector>
71
72 #include "DsoUtils.h"
73
74 namespace po = boost::program_options;
75 namespace fs = boost::filesystem;
76
77 using namespace std;
78
79 class IConverter;
80
81 // useful typedefs
82 typedef std::vector<std::string> Strings_t;
83 typedef std::vector<fs::path> LibPathNames_t;
84
85 namespace {
86 const std::string py_tab = " ";
87
90 const boost::regex pythonIdentifier("^[a-zA-Z_][a-zA-Z0-9_]*$");
91 }
92
93 class configGenerator
94 {
96 string m_pkgName;
97
100 string m_outputDirName;
101
103 stringstream m_pyBuf;
104
107 bool m_importGaudiHandles;
108
109 bool m_importDataObjectHandles;
110
115 stringstream m_dbBuf;
116
122 GaudiUtils::HashMap<std::string, std::string> m_configurable;
123
124 public:
125 configGenerator( const string& pkgName,
126 const string& outputDirName ) :
127 m_pkgName ( pkgName ),
128 m_outputDirName ( outputDirName ),
129 m_pyBuf ( ),
130 m_importGaudiHandles( false ),
131 m_importDataObjectHandles( false ),
132 m_dbBuf ( ),
133 m_configurable ( )
134 {}
135
140 int genConfig( const Strings_t& modules, const string& userModule );
141
143 void setConfigurableModule( const std::string& moduleName )
144 {
145 m_configurable[ "Module" ] = moduleName;
146 }
147
149 void setConfigurableDefaultName( const std::string& defaultName )
150 {
151 m_configurable[ "DefaultName" ] = defaultName;
152 }
153
155 void setConfigurableAlgorithm( const std::string& cfgAlgorithm )
156 {
157 m_configurable[ "Algorithm" ] = cfgAlgorithm;
158 }
159
161 void setConfigurableAlgTool( const std::string& cfgAlgTool )
162 {
163 m_configurable[ "AlgTool" ] = cfgAlgTool;
164 }
165
167 void setConfigurableAuditor( const std::string& cfgAuditor )
168 {
169 m_configurable[ "Auditor" ] = cfgAuditor;
170 }
171
173 void setConfigurableService( const std::string& cfgService )
174 {
175 m_configurable[ "Service" ] = cfgService;
176 m_configurable[ "ApplicationMgr" ] = cfgService;
177 }
178
179 private:
180 int genComponent( const std::string& libName,
181 const std::string& componentName,
182 const std::string& componentType,
183 const vector<Property*>& properties );
184 void genImport( std::ostream& s, const boost::format& frmt,std::string indent);
185 void genHeader( std::ostream& pyOut, std::ostream& dbOut );
186 void genBody( std::ostream& pyOut,
187 std::ostream& dbOut ) {
188 pyOut << m_pyBuf.str() << flush;
189 dbOut << m_dbBuf.str() << flush;
190 }
191 void genTrailer( std::ostream& pyOut,
192 std::ostream& dbOut );
193
195 void pythonizeValue( const Property* prop,
196 string& pvalue,
197 string& ptype );
198
200 void pythonizeName( string& name );
201 };
202
203 int createAppMgr();
204
205 //--- Command main program-----------------------------------------------------
206 int main ( int argc, char** argv )
207 //-----------------------------------------------------------------------------
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 }
434
435 //-----------------------------------------------------------------------------
436 int configGenerator::genConfig( const Strings_t& libs, const string& userModule )
437 //-----------------------------------------------------------------------------
438 {
439 //--- Disable checking StatusCode -------------------------------------------
440 StatusCode::disableChecking();
441
442 const Strings_t::const_iterator endLib = libs.end();
443
444 const std::string gaudiSvc = "GaudiCoreSvc";
445 const bool isGaudiSvc = ( std::find( libs.begin(), endLib, gaudiSvc ) != endLib );
446
447 //--- Instantiate ApplicationMgr --------------------------------------------
448 if ( !isGaudiSvc && createAppMgr() ) {
449 cout << "ERROR: ApplicationMgr can not be created. Check environment" << endl;
450 return EXIT_FAILURE;
451 }
452
453 //--- Iterate over component factories --------------------------------------
454 using Gaudi::PluginService::Details::Registry;
455 Registry& registry = Registry::instance();
456
457 std::set<std::string> bkgNames = registry.loadedFactories();
458
459 ISvcLocator* svcLoc = Gaudi::svcLocator();
460 IInterface* dummySvc = new Service( "DummySvc", svcLoc );
461 dummySvc->addRef();
462
463 bool allGood = true;
464
465 // iterate over all the requested libraries
466 for ( Strings_t::const_iterator iLib=libs.begin(); iLib != endLib; ++iLib ) {
467
468 std::cout << ":::: processing library: " << *iLib << "..." << std::endl;
469
470 // reset state
471 m_importGaudiHandles = false;
472 m_importDataObjectHandles = false;
473 m_pyBuf.str("");
474 m_dbBuf.str("");
475
476 //--- Load component library ----------------------------------------------
477 System::ImageHandle handle;
478 unsigned long err = System::loadDynamicLib( *iLib, &handle );
479 if ( err != 1 ) {
480 cout << "ERROR: " << System::getLastErrorString() << endl;
481 allGood = false;
482 continue;
483 }
484
485 std::set<std::string> factories = registry.loadedFactories();
486
487 for ( std::set<std::string>::iterator it = factories.begin();
488 it != factories.end(); ++it ) {
489 const string ident = *it;
490 if ( bkgNames.find(ident) != bkgNames.end() ) {
491 if ( Gaudi::PluginService::Details::logger().level() <= 1 ) {
492 cout << "\t==> skipping [" << ident << "]..." << endl;
493 }
494 continue;
495 }
496
497 const Registry::FactoryInfo info = registry.getInfo(*it);
498 const string rtype = info.rtype;
499
500 // do not generate configurables for the Reflex-compatible aliases
501 if (info.properties.find("ReflexName") != info.properties.end())
502 continue;
503
504 // Atlas contributed code (patch #1247)
505 // Skip the generation of configurables if the component does not come
506 // from the same library we are processing (i.e. we found a symbol that
507 // is coming from a library loaded by the linker).
508 if ( !DsoUtils::inDso( info.ptr, DsoUtils::libNativeName(*iLib) ) ) {
509 cout << "WARNING: library [" << *iLib << "] exposes factory ["
510 << ident << "] which is declared in ["
511 << DsoUtils::dsoName(info.ptr) << "] !!" << endl;
512 continue;
513 }
514
515 string type;
516 bool known = true;
517 if ( ident == "ApplicationMgr" ) type = "ApplicationMgr";
518 else if ( rtype == typeid(IInterface*).name() ) type = "IInterface";
519 else if ( rtype == typeid(IAlgorithm*).name() ) type = "Algorithm";
520 else if ( rtype == typeid(IService* ).name() ) type = "Service";
521 else if ( rtype == typeid(IAlgTool* ).name() ) type = "AlgTool";
522 else if ( rtype == typeid(IAuditor* ).name() ) type = "Auditor";
523 else if ( rtype == typeid(IConverter*).name() ) type = "Converter";
524 else if ( rtype == typeid(DataObject*).name() ) type = "DataObject";
525 else type = "Unknown", known = false;
526 string name = ident;
527 // handle possible problems with templated components
528 boost::trim(name);
529
530 if ( type == "IInterface" ) {
533 continue;
534 }
535
536 if ( type == "Converter" || type == "DataObject" ) {
538 continue;
539 }
540
541 if ( !known ) {
542 cout << "WARNING: Unknown (return) type [" << System::typeinfoName(rtype.c_str()) << "] !!"
543 << " Component [" << ident << "] is skipped !"
544 << endl;
545 continue;
546 }
547
548 cout << " - component: " << info.className << " (";
549 if (info.className != name)
550 cout << name << ": ";
551 cout << type << ")" << endl;
552
553 string cname = "DefaultName";
554 SmartIF<IProperty> prop;
555 try {
556 if ( type == "Algorithm" ) {
557 prop = SmartIF<IAlgorithm>(Algorithm::Factory::create(ident, cname, svcLoc));
558 }
559 else if ( type == "Service") {
560 prop = SmartIF<IService>(Service::Factory::create(ident, cname, svcLoc));
561 }
562 else if ( type == "AlgTool") {
563 prop = SmartIF<IAlgTool>(AlgTool::Factory::create(ident, cname, type, dummySvc));
564 // FIXME: AlgTool base class increase artificially by 1 the refcount.
565 prop->release();
566 }
567 else if ( type == "Auditor") {
568 prop = SmartIF<IAuditor>(Auditor::Factory::create(ident, cname, svcLoc));
569 }
570 else if ( type == "ApplicationMgr") {
571 prop = SmartIF<ISvcLocator>(svcLoc);
572 }
573 else {
574 continue; // unknown
575 }
576 }
577 catch ( exception& e ) {
578 cout << "ERROR: Error instantiating " << name
579 << " from " << *iLib << endl;
580 cout << "ERROR: Got exception: " << e.what() << endl;
581 allGood = false;
582 continue;
583 }
584 catch ( ... ) {
585 cout << "ERROR: Error instantiating " << name
586 << " from " << *iLib << endl;
587 allGood = false;
588 continue;
589 }
590 if( prop ) {
591 if (genComponent( *iLib, name, type, prop->getProperties() )) {
592 allGood = false;
593 }
594 prop.reset();
595 } else {
596 cout << "ERROR: could not cast IInterface* object to an IProperty* !\n"
597 << "ERROR: return type from PluginSvc is [" << rtype << "]...\n"
598 << "ERROR: NO Configurable will be generated for ["
599 << name << "] !"
600 << endl;
601 allGood = false;
602 }
603 } //> end loop over factories
604
608 const std::string pyName = ( fs::path(m_outputDirName) /
609 fs::path(*iLib+"Conf.py") ).string();
610 const std::string dbName = ( fs::path(m_outputDirName) /
611 fs::path(*iLib+".confdb") ).string();
612
613 std::fstream py( pyName, std::ios_base::out|std::ios_base::trunc );
614 std::fstream db( dbName, std::ios_base::out|std::ios_base::trunc );
615
616 genHeader ( py, db );
617 if (!userModule.empty())
618 py << "from " << userModule << " import *" <<endl;
619 genBody ( py, db );
620 genTrailer( py, db );
621
622 } //> end loop over libraries
623
624 dummySvc->release();
625 dummySvc = 0;
626
627 return allGood ? EXIT_SUCCESS : EXIT_FAILURE;
628 }
629
630 void configGenerator::genImport( std::ostream& s,
631 const boost::format& frmt,
632 std::string indent = ""){
633
634 std::string::size_type pos = 0, nxtpos = 0;
635 std::string mod;
636
637 while ( std::string::npos != pos ){
638 // find end of module name
639 nxtpos = m_configurable["Module"].find_first_of(',',pos);
640
641 // Prepare import string
642 mod = m_configurable["Module"].substr(pos,nxtpos-pos);
643 std::ostringstream import;
644 import << boost::format(frmt) % mod;
645
646 // append a normal import or a try/except enclosed one depending
647 // on availability of a fall-back module (next in the list)
648 if ( std::string::npos == nxtpos ) {
649 // last possible module
650 s << indent << import.str() << "\n" << flush;
651 pos = std::string::npos;
652 } else {
653 // we have a fallback for this
654 s << indent << "try:\n"
655 << indent << py_tab << import.str() << "\n"
656 << indent << "except ImportError:\n"
657 << flush;
658 pos = nxtpos+1;
659 }
660 // increase indentation level for next iteration
661 indent += py_tab;
662 }
663 }
664
665 //-----------------------------------------------------------------------------
666 void configGenerator::genHeader( std::ostream& py,
667 std::ostream& db )
668 //-----------------------------------------------------------------------------
669 {
670 // python file part
671 std::string now = Gaudi::Time::current().format(true);
672 py << "#" << now //<< "\n"
673 << "\"\"\"Automatically generated. DO NOT EDIT please\"\"\"\n";
674 if ( m_importGaudiHandles ) {
675 py << "from GaudiKernel.GaudiHandles import *\n";
676 }
677
678 if ( m_importDataObjectHandles ) {
679 py << "from GaudiKernel.DataObjectHandleBase import *\n";
680 }
681
682 genImport(py,boost::format("from %1%.Configurable import *"));
683
684 // db file part
685 db << "## -*- ascii -*- \n"
686 << "# db file automatically generated by genconf on: "
687 << now
688 << "\n"
689 << flush;
690 }
691 //-----------------------------------------------------------------------------
692 void configGenerator::genTrailer( std::ostream& /*py*/,
693 std::ostream& db )
694 //-----------------------------------------------------------------------------
695 {
696 // db file part
697 db << "## " << m_pkgName << "\n"
698 << std::flush;
699 }
700
701 //-----------------------------------------------------------------------------
702 int
703 configGenerator::genComponent( const std::string& libName,
704 const std::string& componentName,
705 const std::string& componentType,
706 const vector<Property*>& properties )
707 //-----------------------------------------------------------------------------
708 {
709 string cname = componentName;
710 pythonizeName(cname);
711
712 typedef GaudiUtils::HashMap<std::string, std::string> PropertyDoc_t;
713 PropertyDoc_t propDoc;
714
715 m_pyBuf << "\n";
716 m_pyBuf << "class " << cname
717 << "( " << m_configurable[componentType] << " ) :"
718 << "\n";
719 m_pyBuf << " __slots__ = { \n";
720 for ( vector<Property*>::const_iterator it = properties.begin() ;
721 it != properties.end(); ++it ) {
722
723 const string pname = (*it)->name();
724 // Validate property name (it must be a valid Python identifier)
725 if (!boost::regex_match(pname, pythonIdentifier)) {
726 std::cout << "ERROR: invalid property name \"" << pname
727 << "\" in component " << cname
728 << " (invalid Python identifier)" << std::endl;
729 // try to make the buffer at least more or less valid python code.
730 m_pyBuf << " #ERROR-invalid identifier '" << pname << "'\n"
731 << " }\n";
732 return 1;
733 }
734
735 string pvalue, ptype;
736 pythonizeValue( (*it), pvalue, ptype );
737 m_pyBuf << " '" << pname << "' : " << pvalue <<", # " << ptype << "\n";
738
739 if ( (*it)->documentation() != "none" ) {
740 propDoc[pname] = (*it)->documentation();
741 }
742
743 }
744 m_pyBuf << " }\n";
745 m_pyBuf << " _propertyDocDct = { \n";
746 for ( PropertyDoc_t::const_iterator iProp = propDoc.begin();
747 iProp != propDoc.end();
748 ++iProp ) {
749 m_pyBuf << std::setw(5)
750 << "'" << iProp->first << "' : "
751 << "\"\"\" " << iProp->second << " \"\"\",\n";
752 }
753 m_pyBuf << " }\n";
754
755 m_pyBuf
756 << " def __init__(self, name = " << m_configurable["DefaultName"]
757 << ", **kwargs):\n"
758 << " super(" << cname << ", self).__init__(name)\n"
759 << " for n,v in kwargs.items():\n"
760 << " setattr(self, n, v)\n"
761 << " def getDlls( self ):\n"
762 << " return '" << libName << "'\n"
763 << " def getType( self ):\n"
764 << " return '" << componentName << "'\n"
765 << " pass # class " << cname << "\n"
766 << flush;
767
768 // name of the auto-generated module
769 const string pyName = ( fs::path(m_outputDirName) /
770 fs::path(libName+"Conf.py") ).string();
771 const string modName = fs::basename( fs::path( pyName ).leaf() );
772
773 // now the db part
774 m_dbBuf
775 << m_pkgName << "." << modName << " "
776 << libName << " " << cname
777 << "\n"
778 << flush;
779
780 return 0;
781 }
782 //-----------------------------------------------------------------------------
783 void configGenerator::pythonizeName( string& name )
784 //-----------------------------------------------------------------------------
785 {
786 static string in("<>&*,: ().");
787 static string out("__rp__s___");
788 boost::algorithm::replace_all(name, ", ", ",");
789 for ( string::iterator i = name.begin(); i != name.end(); ++i ) {
790 if ( in.find(*i) != string::npos ) *i = out[in.find(*i)];
791 }
792 }
793
794 //-----------------------------------------------------------------------------
795 void configGenerator::pythonizeValue( const Property* p,
796 string& pvalue, string& ptype )
797 //-----------------------------------------------------------------------------
798 {
799 const std::string cvalue = p->toString();
800 const type_info& ti = *p->type_info();
801 if ( ti == typeid(bool) ) {
802 pvalue = ( cvalue == "0" || cvalue == "False" || cvalue == "false" )
803 ? "False"
804 : "True";
805 ptype = "bool";
806 }
807 else if ( ti == typeid(char) || ti == typeid(signed char)
808 || ti == typeid(unsigned char) ||
809 ti == typeid(short) || ti == typeid(unsigned short) ||
810 ti == typeid(int) || ti == typeid(unsigned int) ||
811 ti == typeid(long) || ti == typeid(unsigned long) ) {
812 pvalue = cvalue;
813 ptype = "int";
814 }
815 else if ( ti == typeid(long long) || ti == typeid(unsigned long long) ) {
816 pvalue = cvalue + "L";
817 ptype = "long";
818 }
819 else if ( ti == typeid(float) || ti == typeid(double) ) {
820 // forces python to handle this as a float: put a dot in there...
821 pvalue = boost::to_lower_copy(cvalue);
822 if ( pvalue == "nan" ) {
823 pvalue = "float('nan')";
824 std::cout << "WARNING: default value for ["
825 << p->name() << "] is NaN !!"
826 << std::endl;
827 } else if ( std::string::npos == pvalue.find(".") &&
828 std::string::npos == pvalue.find("e") ) {
829 pvalue = cvalue + ".0";
830 }
831 ptype = "float";
832 }
833 else if ( ti == typeid(string) ) {
834
835 pvalue = "'"+cvalue+"'";
836 ptype = "str";
837 }
838 else if ( ti == typeid(GaudiHandleBase) ) {
839 m_importGaudiHandles = true;
840 const GaudiHandleProperty& hdl
841 = dynamic_cast<const GaudiHandleProperty&>(*p);
842 const GaudiHandleBase& base = hdl.value();
843
844 pvalue = base.pythonRepr();
845 ptype = "GaudiHandle";
846 }
847 else if ( ti == typeid(GaudiHandleArrayBase) ) {
848 m_importGaudiHandles = true;
849 const GaudiHandleArrayProperty& hdl
850 = dynamic_cast<const GaudiHandleArrayProperty&>(*p);
851 const GaudiHandleArrayBase& base = hdl.value();
852
853 pvalue = base.pythonRepr();
854 ptype = "GaudiHandleArray";
855 }
856 else if ( ti == typeid(DataObjectHandleBase) ) {
857 m_importDataObjectHandles = true;
858 const DataObjectHandleProperty& hdl
859 = dynamic_cast<const DataObjectHandleProperty&>(*p);
860 const DataObjectHandleBase& base = hdl.value();
861
862 pvalue = base.pythonRepr();
863 ptype = "DataObjectHandleBase";
864 }
865 else {
866 std::ostringstream v_str;
867 v_str.setf(std::ios::fixed); // to correctly display floats
868 p->toStream(v_str);
869 pvalue = v_str.str();
870 ptype = "list";
871 }
872 }
873
874 //-----------------------------------------------------------------------------
875 int createAppMgr()
876 //-----------------------------------------------------------------------------
877 {
878 IInterface* iface = Gaudi::createApplicationMgr();
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();
887 SmartIF<IProperty> msgSvc{SmartIF<IMessageSvc>{iface}};
888 msgSvc->setProperty("setWarning", "['DefaultName', 'PropertyMgr']");
889 msgSvc->setProperty("Format", "%T %0W%M");
890 return EXIT_SUCCESS;
891 }
GaudiHandleArrayProperty::value
const GaudiHandleArrayBase & value() const
Definition: Property.h:892
System.h
configGenerator::genConfig
int genConfig(const Strings_t &modules, const string &userModule)
main entry point of this class:
Definition: genconf.cpp:436
std::ostringstream::setf
T setf(T...args)
Algorithm.h
Gaudi.CommonGaudiConfigurables.mod
tuple mod
Definition: CommonGaudiConfigurables.py:22
SmartIF< IProperty >
std::string::empty
T empty(T...args)
GaudiHandleBase::pythonRepr
virtual std::string pythonRepr() const
Python representation of handle, i.e.
Definition: GaudiHandle.cpp:56
std::copy
T copy(T...args)
DataObjectHandleProperty.h
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
IConverter
The data converters are responsible to translate data from one representation into another...
Definition: IConverter.h:57
DataObjectHandleBase::pythonRepr
const std::string pythonRepr() const
Definition: DataObjectHandleBase.cpp:48
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
IProperty::getProperties
virtual const std::vector< Property * > & getProperties() const =0
Get list of properties.
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
Property::toString
virtual std::string toString() const =0
value -> string
IAppMgrUI.h
Strings_t
std::vector< std::string > Strings_t
Definition: genconf.cpp:79
Property::name
const std::string & name() const
property name
Definition: Property.h:45
DsoUtils.h
-*- C++ -*- /////////////////////////////
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:297
IAuditor.h
configGenerator::genComponent
int genComponent(const std::string &libName, const std::string &componentName, const std::string &componentType, const vector< Property * > &properties)
Definition: genconf.cpp:703
configGenerator::pythonizeValue
void pythonizeValue(const Property *prop, string &pvalue, string &ptype)
handle the "marshalling" of Properties
Definition: genconf.cpp:795
IAlgorithm.h
Gaudi::PluginService::Details::Logger::level
Level level() const
Definition: PluginServiceDetails.h:213
Gaudi::Time::current
static Time current(void)
Returns the current time.
Definition: Time.cpp:113
AlgTool.h
gaudirun.argv
list argv
Definition: gaudirun.py:227
configGenerator::pythonizeName
void pythonizeName(string &name)
Translates a valid C++ typename into a valid python one.
Definition: genconf.cpp:783
std::endl
T endl(T...args)
configGenerator::setConfigurableDefaultName
void setConfigurableDefaultName(const std::string &defaultName)
customize the default name for configurable instances
Definition: genconf.cpp:149
Bootstrap.h
std
STL namespace.
GaudiHandleProperty
Definition: Property.h:783
LibPathNames_t
std::vector< fs::path > LibPathNames_t
Definition: genconf.cpp:83
configGenerator::setConfigurableAlgTool
void setConfigurableAlgTool(const std::string &cfgAlgTool)
customize the configurable base class for AlgTool component
Definition: genconf.cpp:161
std::vector::end
T end(T...args)
System::ImageHandle
void * ImageHandle
Definition of an image handle.
Definition: ModuleInfo.h:30
HashMap.h
merge_files.sc
int sc
Definition: merge_files.py:167
std::stringstream
STL class.
configGenerator::m_configurable
GaudiUtils::HashMap< std::string, std::string > m_configurable
Configurable customization.
Definition: genconf.cpp:122
configGenerator::m_pyBuf
stringstream m_pyBuf
buffer of auto-generated configurables
Definition: genconf.cpp:103
Gaudi::PluginService::Details::logger
GAUDIPS_API Logger & logger()
Return the current logger instance.
Definition: PluginService.cpp:337
std::setw
T setw(T...args)
DataObjectHandleProperty
DataObjectHandleProperty.h GaudiKernel/DataObjectHandleProperty.h.
Definition: DataObjectHandleProperty.h:23
std::type_info
configGenerator::setConfigurableModule
void setConfigurableModule(const std::string &moduleName)
customize the Module name where configurable base classes are defined
Definition: genconf.cpp:143
dump_component_properties.modules
list modules
Definition: dump_component_properties.py:3
std::string
STL class.
gaudirun.options
list options
Definition: gaudirun.py:396
Service.h
std::vector::push_back
T push_back(T...args)
Gaudi::PluginService::SetDebug
GAUDIPS_API void SetDebug(int debugLevel)
Backward compatibility with Reflex.
Definition: PluginService.cpp:342
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:110
main
int main(int argc, char **argv)
Definition: genconf.cpp:206
configGenerator
Definition: genconf.cpp:93
configGenerator::m_importDataObjectHandles
bool m_importDataObjectHandles
Definition: genconf.cpp:109
prepareBenchmark.config
tuple config
Definition: prepareBenchmark.py:27
gaudirun.type
string type
Definition: gaudirun.py:151
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
std::exception::what
T what(T...args)
IService
General service interface definition.
Definition: IService.h:18
std::ostringstream
STL class.
IInterface
Definition of the basic interface.
Definition: IInterface.h:234
IProperty::setProperty
virtual StatusCode setProperty(const Property &p)=0
Set the property by property.
SmartIF.h
std::ostream_iterator
std::fstream
STL class.
IAlgTool.h
configGenerator::genHeader
void genHeader(std::ostream &pyOut, std::ostream &dbOut)
Definition: genconf.cpp:666
std::stringstream::str
T str(T...args)
Time.h
GaudiPluginService.cpluginsvc.registry
def registry()
Definition: cpluginsvc.py:63
configGenerator::m_dbBuf
stringstream m_dbBuf
buffer of generated configurables informations for the "Db" file The "Db" file is holding information...
Definition: genconf.cpp:115
configGenerator::configGenerator
configGenerator(const string &pkgName, const string &outputDirName)
Definition: genconf.cpp:125
std::exception
STL class.
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:25
configGenerator::setConfigurableAlgorithm
void setConfigurableAlgorithm(const std::string &cfgAlgorithm)
customize the configurable base class for Algorithm component
Definition: genconf.cpp:155
Gaudi::Utils::Histos::path
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
Definition: HistoTableFormat.cpp:191
DataObjectHandleBase.h
std::flush
T flush(T...args)
PluginService.h
std::string::find
T find(T...args)
std::vector::size
T size(T...args)
std::set< std::string >
GaudiHandleArrayBase
Base class of array's of various gaudihandles.
Definition: GaudiHandle.h:320
configGenerator::m_outputDirName
string m_outputDirName
absolute path to the directory where genconf will store auto-generated files (Configurables and Confi...
Definition: genconf.cpp:100
IProperty.h
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
std::vector< std::string >
IInterface::release
virtual unsigned long release()=0
Release Interface instance.
finalize_tags.basename
def basename(url)
Definition: finalize_tags.py:47
DataObjectHandleBase
DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.
Definition: DataObjectHandleBase.h:24
configGenerator::genImport
void genImport(std::ostream &s, const boost::format &frmt, std::string indent)
Definition: genconf.cpp:630
std::vector::begin
T begin(T...args)
configGenerator::m_importGaudiHandles
bool m_importGaudiHandles
switch to decide if the generated configurables need to import GaudiHandles (ie: if one of the compon...
Definition: genconf.cpp:107
configGenerator::setConfigurableService
void setConfigurableService(const std::string &cfgService)
customize the configurable base class for Service component
Definition: genconf.cpp:173
std::string::c_str
T c_str(T...args)
project_manifest.indent
def indent
Definition: project_manifest.py:11
System::moduleName
GAUDI_API const std::string & moduleName()
Get the name of the (executable/DLL) file without file-type.
Definition: ModuleInfo.cpp:54
IAlgTool
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
GaudiHandleProperty::value
const GaudiHandleBase & value() const
Definition: Property.h:832
GaudiUtils::HashMap< std::string, std::string >
gaudirun.s
string s
Definition: gaudirun.py:245
Gaudi::PluginService::Details::Registry
In-memory database of the loaded factories.
Definition: PluginServiceDetails.h:99
configGenerator::m_pkgName
string m_pkgName
name of the package we are processing
Definition: genconf.cpp:96
GaudiPluginService.cpluginsvc.factories
def factories()
Definition: cpluginsvc.py:72
IInterface::addRef
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
program_options
std::string::substr
T substr(T...args)
StatusCode::disableChecking
static GAUDI_API void disableChecking()
Definition: StatusCode.cpp:23
Property::type_info
const std::type_info * type_info() const
property type-info
Definition: Property.h:49
gaudiComponentHelp.properties
tuple properties
Definition: gaudiComponentHelp.py:37
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
configGenerator::genTrailer
void genTrailer(std::ostream &pyOut, std::ostream &dbOut)
Definition: genconf.cpp:692
DataObjectHandleProperty::value
const DataObjectHandleBase & value() const
Definition: DataObjectHandleProperty.cpp:202
System::getLastErrorString
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
Definition: System.cpp:254
GaudiHandleBase
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
Definition: GaudiHandle.h:93
plotBacklogPyRoot.argc
tuple argc
Definition: plotBacklogPyRoot.py:128
IAppMgrUI::configure
virtual StatusCode configure()=0
Configure the job.
IProperty
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:21
Service
Base class for all services.
Definition: Service.h:36
GaudiHandleArrayProperty
Definition: Property.h:841
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
ana.i
list i
Definition: ana.py:128
createAppMgr
int createAppMgr()
Definition: genconf.cpp:875
IAuditor
The IAuditor is the interface implmented by the AlgAuditor base class.
Definition: IAuditor.h:18
std::ostream
STL class.
Auditor.h
ISvcLocator.h
GaudiHandle.h
DsoUtils::libNativeName
std::string libNativeName(const std::string &libName)
Definition: DsoUtils.h:18
configGenerator::genBody
void genBody(std::ostream &pyOut, std::ostream &dbOut)
Definition: genconf.cpp:186
std::ifstream
STL class.
Gaudi::Time::format
std::string format(bool local, std::string spec="%c") const
Format the time using strftime.
Definition: Time.cpp:279
Gaudi::createApplicationMgr
GAUDI_API IAppMgrUI * createApplicationMgr(const std::string &dllname, const std::string &factname)
std::vector::reserve
T reserve(T...args)
ForwardSchedulerSimpleTest.msgSvc
tuple msgSvc
Definition: ForwardSchedulerSimpleTest.py:112
compareOutputFiles.pname
list pname
Definition: compareOutputFiles.py:392
Property::toStream
virtual void toStream(std::ostream &out) const =0
value -> stream
System::loadDynamicLib
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition: System.cpp:124
configGenerator::setConfigurableAuditor
void setConfigurableAuditor(const std::string &cfgAuditor)
customize the configurable base class for AlgTool component
Definition: genconf.cpp:167
GaudiHandleArrayBase::pythonRepr
std::string pythonRepr() const override
Python representation of array of handles, i.e.
Definition: GaudiHandle.cpp:94