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