Delay creating surfaces with the SurfaceManager plugin until it's needed #1532
+14
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, when this plugin is enabled in a detector xml file it will always be loaded, even when never used (for example, running ddsim). I propose to only create the surfaces and manager when the surfaces are actually used. For this, I'm making use of the single entrypoint for the SurfaceManager,
map(), to create the maps there usingstd::call_onceto make this also work in multithreaded contexts. This means, for example, running ddsim won't create these maps that can take some time depending on the detector (for example, for CLD_o2_v06).With this change, the message with the keys and number of surface maps appears when it's created, instead of after building the detector. One change is that, because of the
std::once_flagthat is not copiable nor movable, the move constructor has to be deleted. I think however this class is not supposed to be moved, at least I haven't found any occurrences. There are two alternatives to makeSurfaceManagermovable:std::once_flagin the new object (not trivially correct, sincestd::once_flagwill always be "off" when created)std::once_flagandstd::use_flagto control initialization, also the move operator would need to be locked.Originally proposed in #1304. But this is a different implementation that will create all the maps as soon as
map()is called.BEGINRELEASENOTES
SurfaceManager::map()ENDRELEASENOTES
Maybe a parameter should be added to control whether it's delayed or not?