Skip to content

Conversation

@jmcarcell
Copy link
Member

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 using std::call_once to 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_flag that 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 make SurfaceManager movable:

  • Define the move operators and create a std::once_flag in the new object (not trivially correct, since std::once_flag will always be "off" when created)
  • Use a boolean and locks instead of std::once_flag and std::use_flag to 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

  • Delay creating surfaces with the SurfaceManager plugin until they are actually needed by getting the map of surfaces with SurfaceManager::map()

ENDRELEASENOTES

Maybe a parameter should be added to control whether it's delayed or not?

@github-actions
Copy link

github-actions bot commented Dec 3, 2025

Test Results

   18 files     18 suites   6h 4m 9s ⏱️
  372 tests   372 ✅ 0 💤 0 ❌
3 278 runs  3 278 ✅ 0 💤 0 ❌

Results for commit 5309463.

♻️ This comment has been updated with latest results.

…e needed

and are obtained with `map()`. Delete the move constructor since std::once_flag
is not movable. initialize() now can be const, but this is only called within
DD4hep. Interface for users doesn't change, except now the message with the
number of elements in each surface map appears later, when they are built.
@andresailer andresailer force-pushed the delay-surface-manager branch from 4f3f727 to 5309463 Compare December 9, 2025 11:53
@andresailer andresailer merged commit 2ff0539 into AIDASoft:master Dec 9, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants