Skip to content

Commit

Permalink
EDM4HEP Output: extract run parameters if present
Browse files Browse the repository at this point in the history
  • Loading branch information
andresailer committed Jul 18, 2023
1 parent f54f6f9 commit 2bf9a67
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions DDG4/edm4hep/Geant4Output2EDM4hep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/// Framework include files
#include <DD4hep/Detector.h>
#include <DDG4/EventParameters.h>
#include <DDG4/RunParameters.h>
#include <DDG4/Geant4OutputAction.h>

/// edm4hep include files
Expand Down Expand Up @@ -125,6 +126,29 @@ namespace dd4hep {
}
#endif
}

template <> void RunParameters::extractParameters(podio::Frame& frame) {
for(auto const& p: this->intParameters()) {
printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str());
frame.putParameter(p.first, p.second);
}
for(auto const& p: this->fltParameters()) {
printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str());
frame.putParameter(p.first, p.second);
}
for(auto const& p: this->strParameters()) {
printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str());
frame.putParameter(p.first, p.second);
}
#if podio_VERSION_MAJOR > 0 || podio_VERSION_MINOR > 16 || podio_VERSION_PATCH > 2
// This functionality is only present in podio > 0.16.2
for (auto const& p: this->dblParameters()) {
printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str());
frame.putParameter(p.first, p.second);
}
#endif
}

} // End namespace sim
} // End namespace dd4hep
#endif // DD4HEP_DDG4_GEANT4OUTPUT2EDM4hep_H
Expand Down Expand Up @@ -278,6 +302,13 @@ void Geant4Output2EDM4hep::saveRun(const G4Run* run) {
runHeader.putParameter("DD4hepVersion", versionString());
runHeader.putParameter("detectorName", context()->detectorDescription().header().name());

RunParameters* parameters = context()->run().extension<RunParameters>(false);
// Get parameters from extension ...
if ( parameters ) {
parameters->extractParameters(m_frame);
}


m_file->writeFrame(runHeader, "runs");
}

Expand Down

0 comments on commit 2bf9a67

Please sign in to comment.