ATLAS Offline Software
genCLIDDB.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <iostream>
6 #include <string>
7 
8 #include "GaudiKernel/IClassManager.h"
9 #include "GaudiKernel/IProperty.h"
10 #include "GaudiKernel/ISvcLocator.h"
11 #include "GaudiKernel/SmartIF.h"
12 #include "GaudiKernel/IAppMgrUI.h"
13 #include "GaudiKernel/IClassIDSvc.h"
14 #include "GaudiKernel/Bootstrap.h"
15 
17 
18 #include <boost/program_options.hpp>
19 namespace po = boost::program_options;
20 
21 // Suppress roofit banner. Besides the output, it spins up cling and
22 // spits out ubsan warnings.
23 int doBanner() { return 0; }
24 
25 int inputError(const std::string& errDescr, const po::options_description& optDescr ) {
26  std::cerr << errDescr << "\n" << optDescr << std::endl;
27  return 1;
28 }
29 
30 //wrote a better version!
31 IAppMgrUI* initGaudi(const std::string& options, bool verbose, ISvcLocator*& svcLocator) {
32  IAppMgrUI* theApp = Gaudi::createApplicationMgr();
33  SmartIF<IProperty> propMgr(theApp);
34  if(strlen(options.c_str())) {
35  CHECK_WITH_CONTEXT( propMgr->setProperty("JobOptionsPath", options), "initGaudi", nullptr );
36  } else {
37  //no joboptions given
38  CHECK_WITH_CONTEXT( propMgr->setProperty("JobOptionsType", "NONE"), "initGaudi", nullptr );
39  }
40  if (!verbose) {
41  CHECK_WITH_CONTEXT( propMgr->setProperty("OutputLevel", MSG::WARNING), "initGaudi", nullptr );
42  }
43  CHECK_WITH_CONTEXT( theApp->configure(), "initGaudi", nullptr );
44  CHECK_WITH_CONTEXT( theApp->initialize(), "initGaudi", nullptr );
45  svcLocator = Gaudi::svcLocator();
46  return theApp;
47 
48 }
49 
50 int main(int argc, char* argv[]) {
51  // Declare the supported options.
52 
53  const std::string appName("genCLIDDB");
54  po::options_description desc(appName + " allowed options");
55  desc.add_options()
56  ("help,h", "produce help message")
57  ("package,p", po::value<std::string>(), "package we want to load clids from")
58  ("input,i", po::value<std::string>(), "optional path to input clid db file")
59  ("output,o", po::value<std::string>(), "optional path to resulting clid db file")
60  ("jobopts,j", po::value<std::string>(), "name of optional job options txt file, located at ../share/jobopts")
61  ("verbose,v", po::value<bool>()->implicit_value(true), "verbose output")
62  ;
63  std::string packageName("ALL");
64  std::string inputCLIDDB;
65  std::string outFileName;
66 
67  po::variables_map vm;
68  try {
69  po::store(po::parse_command_line(argc, argv, desc), vm);
70  po::notify(vm);
71  } catch (const std::exception& e) {
72  return inputError(e.what(), desc);
73  }
74 
75  if (vm.count("help")) {
76  std::cout << desc << std::endl;
77  return 0;
78  }
79 
80  if (vm.count("package")) {
81  packageName = vm["package"].as<std::string>();
82  } else {
83  return inputError("Please specify a package using option --package.\n", desc);
84  }
85 
86  if (vm.count("output")) {
87  outFileName = vm["output"].as<std::string>();
88  } else {
89  outFileName = packageName + "_clid.db";
90  }
91 
92  bool verbose = vm.count("verbose") && vm["verbose"].as<bool>();
93 
94  // Initialize Gaudi
95  ISvcLocator* pSvcLoc(nullptr);
96  std::string jobopts("CLIDComps/minimalPrintout.opts");
97  if (vm.count("jobopts")) {
98  jobopts = vm["jobopts"].as<std::string>();
99  }
100  if (!initGaudi(jobopts, verbose, pSvcLoc)) {
101  std::cerr << "cannot initialize Gaudi" << std::endl;
102  return 2;
103  }
104 
105  // Now we can use the MessagesSvc
106  SmartIF<IMessageSvc> msgSvc(pSvcLoc);
107  CHECK_WITH_CONTEXT( msgSvc.isValid(), appName, 2 );
108 
109  MsgStream log(msgSvc, appName);
110  if (!verbose) {
111  log.setLevel(MSG::WARNING);
112  }
113 
114  SmartIF<IClassManager> pICM(pSvcLoc);
115  CHECK_WITH_CONTEXT( pICM.isValid(), appName, 2 );
116 
117  SmartIF<IClassIDSvc> pClassIDSvc(pSvcLoc->service("ClassIDSvc"));
118  CHECK_WITH_CONTEXT( pClassIDSvc.isValid(), appName, 2 );
119 
120  SmartIF<IProperty> pCLIDSvcProp(pClassIDSvc);
121  CHECK_WITH_CONTEXT( pCLIDSvcProp.isValid(), appName, 2 );
122 
123  log << MSG::INFO << "Writing clid.db for package "
124  << vm["package"].as<std::string>() << " to " << outFileName << "." << endmsg;
125 
126  // Set properties on CLIDSvc
127  std::string dbfiles("{}");
128  if (vm.count("input")) {
129  log << MSG::INFO << "Reading clid.db from " << vm["input"].as<std::string>() << "." << endmsg;
130  dbfiles = "{\"" + vm["input"].as<std::string>() + "\"}";
131  }
132  CHECK_WITH_CONTEXT( pCLIDSvcProp->setProperty("CLIDDBFiles", dbfiles), appName, 2 );
133  CHECK_WITH_CONTEXT( pCLIDSvcProp->setProperty("OutputFileName", outFileName), appName, 2 );
134 
135  // Load the module
136  CHECK_WITH_CONTEXT( pICM->loadModule(packageName), appName, 2 );
137 
138  //fill clid db
139  CHECK_WITH_CONTEXT( pClassIDSvc->reinitialize(), appName, 2 );
140 
141  //write out merged clid db on service finalize
142  return (pClassIDSvc->finalize()).isSuccess() ? 0 : -1;
143 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
initGaudi
IAppMgrUI * initGaudi(const std::string &options, bool verbose, ISvcLocator *&svcLocator)
Definition: genCLIDDB.cxx:31
CHECK_WITH_CONTEXT
#define CHECK_WITH_CONTEXT(...)
Evaluate an expression and check for errors, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:396
inputError
int inputError(const std::string &errDescr, const po::options_description &optDescr)
Definition: genCLIDDB.cxx:25
DumpGeoConfig.outFileName
string outFileName
Definition: DumpGeoConfig.py:252
CaloCondBlobAlgs_fillNoiseFromASCII.desc
desc
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:54
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
calibdata.exception
exception
Definition: calibdata.py:496
python.AtlRunQueryLib.options
options
Definition: AtlRunQueryLib.py:379
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
beamspotman.jobopts
jobopts
Definition: beamspotman.py:1106
errorcheck.h
Helpers for checking error return status codes and reporting errors.
main
int main(int argc, char *argv[])
Definition: genCLIDDB.cxx:50
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
doBanner
int doBanner()
Definition: genCLIDDB.cxx:23
python.AppMgr.theApp
theApp
Definition: AppMgr.py:771