ATLAS Offline Software
Loading...
Searching...
No Matches
initGaudi.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5/***************************************************************************
6 minimal gaudi initialization for AthenaServices unit testing
7 ------------------------------------------------------------
8 ATLAS Collaboration
9 ***************************************************************************/
10
11#include "TestTools/initGaudi.h"
12
13#include "GaudiKernel/Bootstrap.h"
14#include "GaudiKernel/IProperty.h"
15#include "GaudiKernel/ISvcLocator.h"
16#include "GaudiKernel/IAppMgrUI.h"
17#include "GaudiKernel/SmartIF.h"
18#include "GaudiKernel/ModuleIncident.h"
19#include "GaudiKernel/PathResolver.h"
20
21
22namespace Athena_test {
23
24 bool initGaudi(ISvcLocator*& pSvcLoc) {
25 return initGaudi({}, pSvcLoc);
26 }
27
28
29 bool initGaudi(const std::string& jobOptsFile, ISvcLocator*& pSvcLoc) {
30
31 std::string jobOptsPath;
32 if (!jobOptsFile.empty()) {
33 jobOptsPath = System::PathResolver::find_file(jobOptsFile, "JOBOPTSEARCHPATH");
34 if (jobOptsPath.empty()) {
35 std::cout << "\n\nCannot find job opts " << jobOptsFile << std::endl;
36 }
37 else {
38 std::cout << "\n\nInitializing Gaudi ApplicationMgr using job opts " << jobOptsPath << std::endl;
39 }
40 }
41
42 // Create an instance of ApplicationMgr
43 SmartIF<IAppMgrUI> appMgr = Gaudi::createApplicationMgr();
44 if(!appMgr.isValid()) {
45 std::cout << "Fatal error while creating the ApplicationMgr " << std::endl;
46 return false;
47 }
48
49 SmartIF<IProperty> propMgr(appMgr);
50 SmartIF<ISvcLocator> svcLoc(appMgr);
51 if(!svcLoc.isValid() || !propMgr.isValid()) {
52 std::cout << "Fatal error while retrieving AppMgr interfaces " << std::endl;
53 return false;
54 }
55
56 // Return pointer to ISvcLocator
57 pSvcLoc = svcLoc.get();
58
59 propMgr->setProperty( "EvtSel", "NONE" ).
60 orThrow("Cannnot set EvtSel property", "initGaudi");
61 if (jobOptsFile.empty()) {
62 propMgr->setProperty( "JobOptionsType", "NONE" ).
63 orThrow("Cannnot set JobOptionsType property", "initGaudi");
64 } else {
65 propMgr->setProperty( "JobOptionsType", "FILE" ).
66 orThrow("Cannnot set JobOptionsType property", "initGaudi");
67 propMgr->setProperty( "JobOptionsPath", jobOptsPath ).
68 orThrow("Cannnot set JobOptionsPath property", "initGaudi");
69 }
70
71 if (appMgr->configure().isSuccess() && appMgr->initialize().isSuccess()) {
72 std::cout<<"ApplicationMgr Ready"<<std::endl;
73 return true;
74 } else {
75 std::cout << "Fatal error while initializing the AppMgr" << std::endl;
76 return false;
77 }
78 }
79
80
81 // This is for the benefit of the tests in CLIDComps.
82 // By default, a dynamic symbol is not exported from a binary unless
83 // it's referenced by another library with which we link.
84 // A test in CLIDComps creates a ModuleLoadedIncident object in the binary
85 // and then passes it to code in CLIDComps. If ubsan is running,
86 // then it will try to verify that this object derives from ModuleIncident.
87 // But if the ModuleIncident type_info is not exported from the binary,
88 // then the type_info used by the library will be different from that
89 // in the binary, causing an ubsan warning.
90 // But this test gets linked against TestTools, so we can avoid the warning
91 // by referencing the type information here.
92 // (An alternative would be to link the binary with --export-dynamic,
93 // but that's not portable, so we don't want to put it in a package cmake.)
95 {
96 ModuleLoadedIncident inc2 ("", "");
97 }
98
99
100 InitGaudi::InitGaudi(const std::string& jobOptsFile) {
101 ISvcLocator* pSvcLoc{};
102 if (!Athena_test::initGaudi(jobOptsFile, pSvcLoc)) {
103 throw std::runtime_error("Cannot initialize Gaudi");
104 }
105 svcLoc = pSvcLoc;
106 }
107
109 auto appMgr = svcLoc.as<IAppMgrUI>();
110 appMgr->finalize().ignore();
111 appMgr->terminate().ignore();
112 }
113
114}
SmartIF< ISvcLocator > svcLoc
Definition initGaudi.h:68
InitGaudi()
Create Gaudi test fixture without job options.
Definition initGaudi.h:61
~InitGaudi()
Finalize Gaudi.
minimal gaudi initialization for AthenaServices unit testing
functions & macros to test the difference between floats
void referenceGaudiSymbols()
Definition initGaudi.cxx:94
bool initGaudi(ISvcLocator *&pSvcLoc)
Minimal Gaudi initialization for unit testing without job options.
Definition initGaudi.cxx:24