Skip to content

Commit c6ce5e0

Browse files
committed
Fix bug in Bayeux library servicves shutdown
1 parent c925f0c commit c6ce5e0

File tree

2 files changed

+64
-61
lines changed

2 files changed

+64
-61
lines changed

source/bxbayeux/src/detail/bayeux_library.cc.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ namespace bayeux {
148148
// static
149149
bayeux_library & bayeux_library::instantiate()
150150
{
151+
static std::unique_ptr<bayeux_library> _bxlib_handler;
151152
if (! bayeux_library::is_instantiated()) {
152-
static std::unique_ptr<bayeux_library> _bxlib_handler;
153153
if (! _bxlib_handler) {
154154
// Allocate the Bayeux library singleton and initialize it:
155155
_bxlib_handler.reset(new bayeux_library);
@@ -625,8 +625,8 @@ namespace bayeux {
625625
urnResourceResolver.reset();
626626
}
627627

628-
// DeActivate the URN info setup DB:
629-
{
628+
// Deactivate the URN info setup DB:
629+
if (_services_.has(bx_resource_db_name())) {
630630
DT_LOG_TRACE(_logging_, "Accessing URN info setup DB...");
631631
datatools::urn_db_service & urnSetupDb =
632632
_services_.grab<datatools::urn_db_service &>(bx_resource_db_name());

source/bxmctools/programs/g4/g4_production.cxx

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ int main(int argc_, char ** argv_)
104104
datatools::logger::priority logging = datatools::logger::PRIO_FATAL;
105105
bayeux::initialize(argc_, argv_, app_kernel_init_flags());
106106
try {
107+
bool run = true;
107108

108109
// Configuration parameters for the G4 manager:
109110
mctools::g4::manager_parameters params;
@@ -173,7 +174,7 @@ int main(int argc_, char ** argv_)
173174
// Collect all other options & args for the driver session:
174175
std::vector<std::string> unrecognized_opts;
175176
unrecognized_opts = po::collect_unrecognized(parsed.options,
176-
po::include_positional);
177+
po::include_positional);
177178
*/
178179

179180
// Parse specific options:
@@ -201,71 +202,73 @@ int main(int argc_, char ** argv_)
201202
if (vm.count("help")) {
202203
if (vm["help"].as<bool>()) {
203204
ui::print_usage(optPublic, std::cout);
204-
return(0);
205+
run = false;
205206
}
206207
}
207208

208-
// Fill the configuration data structure from program options:
209-
ui::process_opts(vm, optPublic, params);
210-
211-
// DLL loading:
212-
datatools::library_loader dll_loader(params.dll_loader_config);
213-
if (params.g4_visu) {
214-
std::string g4_vis_dll = "G4visXXX";
215-
if (std::find(params.dlls.begin(), params.dlls.end(), g4_vis_dll) == params.dlls.end()) {
216-
DT_LOG_NOTICE(logging, "Force the loading of the DLL '" << g4_vis_dll << "' DLL...");
217-
params.dlls.push_back(g4_vis_dll);
209+
if (run) {
210+
// Fill the configuration data structure from program options:
211+
ui::process_opts(vm, optPublic, params);
212+
213+
// DLL loading:
214+
datatools::library_loader dll_loader(params.dll_loader_config);
215+
if (params.g4_visu) {
216+
std::string g4_vis_dll = "G4visXXX";
217+
if (std::find(params.dlls.begin(), params.dlls.end(), g4_vis_dll) == params.dlls.end()) {
218+
DT_LOG_NOTICE(logging, "Force the loading of the DLL '" << g4_vis_dll << "' DLL...");
219+
params.dlls.push_back(g4_vis_dll);
220+
}
221+
std::string g4_opengl_dll = "G4OpenGL";
222+
if (std::find(params.dlls.begin(), params.dlls.end(), g4_opengl_dll) == params.dlls.end()) {
223+
DT_LOG_NOTICE(logging, "Force the loading of the DLL '" << g4_opengl_dll << "' DLL...");
224+
params.dlls.push_back(g4_opengl_dll);
225+
}
218226
}
219-
std::string g4_opengl_dll = "G4OpenGL";
220-
if (std::find(params.dlls.begin(), params.dlls.end(), g4_opengl_dll) == params.dlls.end()) {
221-
DT_LOG_NOTICE(logging, "Force the loading of the DLL '" << g4_opengl_dll << "' DLL...");
222-
params.dlls.push_back(g4_opengl_dll);
227+
for (const std::string & dll_name : params.dlls) {
228+
DT_LOG_NOTICE(logging, "Loading DLL '" << dll_name << "'...");
229+
DT_THROW_IF (dll_loader.load (dll_name) != EXIT_SUCCESS,
230+
std::logic_error,
231+
"Loading DLL '" << dll_name << "' failed !");
223232
}
224-
}
225-
for (const std::string & dll_name : params.dlls) {
226-
DT_LOG_NOTICE(logging, "Loading DLL '" << dll_name << "'...");
227-
DT_THROW_IF (dll_loader.load (dll_name) != EXIT_SUCCESS,
228-
std::logic_error,
229-
"Loading DLL '" << dll_name << "' failed !");
230-
}
231-
232-
// Variant service:
233-
std::unique_ptr<dtc::variant_service> vserv;
234-
if (variants_params.is_active()) {
235-
// Create and start the variant service:
236-
vserv.reset(new dtc::variant_service);
237-
vserv->configure(variants_params);
238-
vserv->start();
239-
// vserv->get_repository().tree_dump(std::cerr, "Repository:");
240-
}
241233

242-
{
243-
// Declare the simulation manager:
244-
DT_LOG_NOTICE(logging, "Instantiate the simulation manager...");
245-
mctools::g4::manager sim_manager;
246-
247-
// Configure the simulation manager:
248-
DT_LOG_NOTICE(logging, "Setup the simulation manager...");
249-
mctools::g4::manager_parameters::setup(params, sim_manager);
250-
251-
// Run the simulation session :
252-
DT_LOG_NOTICE(logging, "Simulation session starts...");
253-
sim_manager.run_simulation();
254-
DT_LOG_NOTICE(logging, "Simulation session is stopped.");
255-
256-
// Explicitely terminate the simulation manager:
257-
DT_LOG_NOTICE(logging, "Terminate the simulation manager...");
258-
if (sim_manager.is_initialized()) {
259-
sim_manager.reset();
234+
// Variant service:
235+
std::unique_ptr<dtc::variant_service> vserv;
236+
if (variants_params.is_active()) {
237+
// Create and start the variant service:
238+
vserv.reset(new dtc::variant_service);
239+
vserv->configure(variants_params);
240+
vserv->start();
241+
// vserv->get_repository().tree_dump(std::cerr, "Repository:");
260242
}
261243

262-
DT_LOG_NOTICE(logging, "Simulation manager is terminated.");
263-
} // Destructor is invoked here.
264-
265-
if (vserv) {
266-
// Stop the variant service:
267-
vserv->stop();
268-
vserv.reset();
244+
{
245+
// Declare the simulation manager:
246+
DT_LOG_NOTICE(logging, "Instantiate the simulation manager...");
247+
mctools::g4::manager sim_manager;
248+
249+
// Configure the simulation manager:
250+
DT_LOG_NOTICE(logging, "Setup the simulation manager...");
251+
mctools::g4::manager_parameters::setup(params, sim_manager);
252+
253+
// Run the simulation session :
254+
DT_LOG_NOTICE(logging, "Simulation session starts...");
255+
sim_manager.run_simulation();
256+
DT_LOG_NOTICE(logging, "Simulation session is stopped.");
257+
258+
// Explicitely terminate the simulation manager:
259+
DT_LOG_NOTICE(logging, "Terminate the simulation manager...");
260+
if (sim_manager.is_initialized()) {
261+
sim_manager.reset();
262+
}
263+
264+
DT_LOG_NOTICE(logging, "Simulation manager is terminated.");
265+
} // Destructor is invoked here.
266+
267+
if (vserv) {
268+
// Stop the variant service:
269+
vserv->stop();
270+
vserv.reset();
271+
}
269272
}
270273

271274
DT_LOG_TRACE(logging, "The end.");

0 commit comments

Comments
 (0)