ATLAS Offline Software
Loading...
Searching...
No Matches
genCLIDDB.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <iostream>
6#include <print>
7#include <string>
8
9#include "GaudiKernel/IClassManager.h"
10#include "GaudiKernel/IProperty.h"
11#include "GaudiKernel/ISvcLocator.h"
12#include "GaudiKernel/SmartIF.h"
13#include "GaudiKernel/IAppMgrUI.h"
14#include "GaudiKernel/IClassIDSvc.h"
15#include "GaudiKernel/Bootstrap.h"
16
18
19#include <boost/program_options.hpp>
20namespace po = boost::program_options;
21
22// Suppress roofit banner. Besides the output, it spins up cling and
23// spits out ubsan warnings.
24int doBanner() { return 0; }
25
26int inputError(const std::string& errDescr, const po::options_description& optDescr ) {
27 std::cerr << errDescr << "\n" << optDescr << std::endl;
28 return 1;
29}
30
31//wrote a better version!
32IAppMgrUI* initGaudi(const std::string& options, bool verbose, ISvcLocator*& svcLocator) {
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}
50
51int main(int argc, char* argv[]) {
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
Helpers for checking error return status codes and reporting errors.
#define CHECK_WITH_CONTEXT(...)
Evaluate an expression and check for errors, with an explicitly specified context name.
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
int doBanner()
Definition genCLIDDB.cxx:24
bool verbose
Definition hcg.cxx:75
int main()
Definition hello.cxx:18