Skip to content

Support multithreading in Geant4EDM4hepOutput plugin - #1417

Merged
MarkusFrankATcernch merged 3 commits into
AIDASoft:masterfrom
wdconinc:geant4-edm4hep-output-mt
Mar 13, 2025
Merged

Support multithreading in Geant4EDM4hepOutput plugin#1417
MarkusFrankATcernch merged 3 commits into
AIDASoft:masterfrom
wdconinc:geant4-edm4hep-output-mt

Conversation

@wdconinc

@wdconinc wdconinc commented Mar 12, 2025

Copy link
Copy Markdown
Contributor

This PR adds multithreading support to Geant4EDM4hepOutput. This is approached by:

  • ensuring the m_file unique_ptr to podio::ROOTWriter is only made once,
  • keeping track of the use count of the file in an atomic_size_t,
  • ensuring the G4AutoLock is acquired in scope before each m_file access,
  • closing the file when the last file user gives up access.

Additional notes:

  • context()->run() fails because runPtr() is null in multithreaded running; this leads to missing runs and meta frames. EDIT: this is not consistent... not sure why not...
  • After moving m_particles into the frame, the collection is left with a null m_storageMtx mutex pointer; this is avoided by not using clear() but moving assigning a clean new collection in place (Line 322). I suspect the clear() was added in analogy to the clear() calls below, but those are on maps, not podio collections.

Testing:

index 2a340914..736f190e 100644
--- a/DDG4/examples/SiDSim_MT.py
+++ b/DDG4/examples/SiDSim_MT.py
@@ -53,8 +53,7 @@ def setupWorker(geant4):
   logger.info("\n#PYTHON:  Configure I/O\n")
   # evt_lcio = geant4.setupLCIOOutput('LcioOutput','CLICSiD_'+time.strftime('%Y-%m-%d_%H-%M'))
   # evt_lcio.OutputLevel = Output.ERROR
-
-  geant4.setupROOTOutput('RootOutput', 'CLICSiD_' + time.strftime('%Y-%m-%d_%H-%M'))
+  geant4.setupEDM4hepOutput('EDM4hepOutput', 'CLICSiD_' + time.strftime('%Y-%m-%d_%H-%M') + ".edm4hep.root")
 
   gen = DDG4.GeneratorAction(kernel, "Geant4GeneratorActionInit/GenerationInit")
   kernel.generatorAction().adopt(gen)

TODO:

  • I'd like to add this to one of the tests, but neither SiDSim.py nor SiDSim_MT.py is already used for tests. Suggestions welcome.

BEGINRELEASENOTES

  • Support multithreading in Geant4EDM4hepOutput plugin

ENDRELEASENOTES

@github-actions

github-actions Bot commented Mar 12, 2025

Copy link
Copy Markdown

Test Results

   16 files     16 suites   6h 13m 12s ⏱️
  370 tests   370 ✅ 0 💤 0 ❌
2 887 runs  2 887 ✅ 0 💤 0 ❌

Results for commit d6d8030.

♻️ This comment has been updated with latest results.

@MarkusFrankATcernch

Copy link
Copy Markdown
Contributor

@tmadlener Thomas, could you please verify?
Thanks a lot!

@MarkusFrankATcernch

MarkusFrankATcernch commented Mar 13, 2025

Copy link
Copy Markdown
Contributor

@tmadlener Ooops sorry, I did not realize that the change is actually trivial before asking you. Sorry.

@MarkusFrankATcernch
MarkusFrankATcernch enabled auto-merge (rebase) March 13, 2025 08:10
@MarkusFrankATcernch
MarkusFrankATcernch merged commit 6ce741b into AIDASoft:master Mar 13, 2025
@wdconinc
wdconinc deleted the geant4-edm4hep-output-mt branch March 13, 2025 16:59
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