ATLAS Offline Software
Loading...
Searching...
No Matches
genCLIDDB.cxx File Reference
#include <iostream>
#include <print>
#include <string>
#include "GaudiKernel/IClassManager.h"
#include "GaudiKernel/IProperty.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/SmartIF.h"
#include "GaudiKernel/IAppMgrUI.h"
#include "GaudiKernel/IClassIDSvc.h"
#include "GaudiKernel/Bootstrap.h"
#include "AthenaKernel/errorcheck.h"
#include <boost/program_options.hpp>

Go to the source code of this file.

Functions

int doBanner ()
int inputError (const std::string &errDescr, const po::options_description &optDescr)
IAppMgrUI * initGaudi (const std::string &options, bool verbose, ISvcLocator *&svcLocator)
int main (int argc, char *argv[])

Function Documentation

◆ doBanner()

int doBanner ( )

Definition at line 24 of file genCLIDDB.cxx.

24{ return 0; }

◆ initGaudi()

IAppMgrUI * initGaudi ( const std::string & options,
bool verbose,
ISvcLocator *& svcLocator )

Definition at line 32 of file genCLIDDB.cxx.

32 {
33 IAppMgrUI* theApp = Gaudi::createApplicationMgr();
34 SmartIF<IProperty> propMgr(theApp);
35 if(strlen(options.c_str())) {
36 CHECK_WITH_CONTEXT( propMgr->setProperty("JobOptionsPath", options), "initGaudi", nullptr );
37 } else {
38 //no joboptions given
39 CHECK_WITH_CONTEXT( propMgr->setProperty("JobOptionsType", "NONE"), "initGaudi", nullptr );
40 }
41 if (!verbose) {
42 CHECK_WITH_CONTEXT( propMgr->setProperty("OutputLevel", MSG::WARNING), "initGaudi", nullptr );
43 }
44 CHECK_WITH_CONTEXT( theApp->configure(), "initGaudi", nullptr );
45 CHECK_WITH_CONTEXT( theApp->initialize(), "initGaudi", nullptr );
46 svcLocator = Gaudi::svcLocator();
47 return theApp;
48
49}
#define CHECK_WITH_CONTEXT(...)
Evaluate an expression and check for errors, with an explicitly specified context name.
bool verbose
Definition hcg.cxx:75

◆ inputError()

int inputError ( const std::string & errDescr,
const po::options_description & optDescr )

Definition at line 26 of file genCLIDDB.cxx.

26 {
27 std::cerr << errDescr << "\n" << optDescr << std::endl;
28 return 1;
29}

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 51 of file genCLIDDB.cxx.

51 {
52 // Declare the supported options.
53
54 const std::string appName("genCLIDDB");
55 po::options_description desc(appName + " allowed options");
56 desc.add_options()
57 ("help,h", "produce help message")
58 ("package,p", po::value<std::string>(), "package we want to load clids from")
59 ("input,i", po::value<std::string>(), "optional path to input clid db file")
60 ("output,o", po::value<std::string>(), "optional path to resulting clid db file")
61 ("jobopts,j", po::value<std::string>(), "name of optional job options txt file, located at ../share/jobopts")
62 ("verbose,v", po::value<bool>()->implicit_value(true), "verbose output")
63 ;
64 std::string packageName("ALL");
65 std::string inputCLIDDB;
66 std::string outFileName;
67
68 po::variables_map vm;
69 try {
70 po::store(po::parse_command_line(argc, argv, desc), vm);
71 po::notify(vm);
72 } catch (const std::exception& e) {
73 return inputError(e.what(), desc);
74 }
75
76 if (vm.count("help")) {
77 std::cout << desc << std::endl;
78 return 0;
79 }
80
81 if (vm.count("package")) {
82 packageName = vm["package"].as<std::string>();
83 } else {
84 return inputError("Please specify a package using option --package.\n", desc);
85 }
86
87 if (vm.count("output")) {
88 outFileName = vm["output"].as<std::string>();
89 } else {
90 outFileName = packageName + "_clid.db";
91 }
92
93 bool verbose = vm.count("verbose") && vm["verbose"].as<bool>();
94
95 // Initialize Gaudi
96 ISvcLocator* pSvcLoc(nullptr);
97 std::string jobopts("CLIDComps/minimalPrintout.opts");
98 if (vm.count("jobopts")) {
99 jobopts = vm["jobopts"].as<std::string>();
100 }
101 if (!initGaudi(jobopts, verbose, pSvcLoc)) {
102 std::println (std::cerr, "cannot initialize Gaudi");
103 return 2;
104 }
105
106 // Now we can use the MessagesSvc
107 SmartIF<IMessageSvc> msgSvc(pSvcLoc);
108 CHECK_WITH_CONTEXT( msgSvc.isValid(), appName, 2 );
109
110 MsgStream log(msgSvc, appName);
111 if (!verbose) {
112 log.setLevel(MSG::WARNING);
113 }
114
115 SmartIF<IClassManager> pICM(pSvcLoc);
116 CHECK_WITH_CONTEXT( pICM.isValid(), appName, 2 );
117
118 SmartIF<IClassIDSvc> pClassIDSvc(pSvcLoc->service("ClassIDSvc"));
119 CHECK_WITH_CONTEXT( pClassIDSvc.isValid(), appName, 2 );
120
121 SmartIF<IProperty> pCLIDSvcProp(pClassIDSvc);
122 CHECK_WITH_CONTEXT( pCLIDSvcProp.isValid(), appName, 2 );
123
124 log << MSG::INFO << "Writing clid.db for package "
125 << vm["package"].as<std::string>() << " to " << outFileName << "." << endmsg;
126
127 // Set properties on CLIDSvc
128 std::string dbfiles("{}");
129 if (vm.count("input")) {
130 log << MSG::INFO << "Reading clid.db from " << vm["input"].as<std::string>() << "." << endmsg;
131 dbfiles = "{\"" + vm["input"].as<std::string>() + "\"}";
132 }
133 CHECK_WITH_CONTEXT( pCLIDSvcProp->setProperty("CLIDDBFiles", dbfiles), appName, 2 );
134 CHECK_WITH_CONTEXT( pCLIDSvcProp->setProperty("OutputFileName", outFileName), appName, 2 );
135
136 // Load the module
137 CHECK_WITH_CONTEXT( pICM->loadModule(packageName), appName, 2 );
138
139 //fill clid db
140 CHECK_WITH_CONTEXT( pClassIDSvc->reinitialize(), appName, 2 );
141
142 //write out merged clid db on service finalize
143 return (pClassIDSvc->finalize()).isSuccess() ? 0 : -1;
144}
#define endmsg
IAppMgrUI * initGaudi(const std::string &options, bool verbose, ISvcLocator *&svcLocator)
Definition genCLIDDB.cxx:32
int inputError(const std::string &errDescr, const po::options_description &optDescr)
Definition genCLIDDB.cxx:26