diff --git a/DDG4/edm4hep/EDM4hepFileReader.cpp b/DDG4/edm4hep/EDM4hepFileReader.cpp index 563f8ce66..6a38b9c9e 100644 --- a/DDG4/edm4hep/EDM4hepFileReader.cpp +++ b/DDG4/edm4hep/EDM4hepFileReader.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -77,6 +78,21 @@ namespace dd4hep::sim { } } + template void FileParameters::ingestParameters(T const& source) { + for(auto const& key: source.template getKeys()) { + m_intValues[key] = source.template get>(key).value(); + } + for(auto const& key: source.template getKeys()) { + m_fltValues[key] = source.template get>(key).value(); + } + for(auto const& key: source.template getKeys()) { + m_dblValues[key] = source.template get>(key).value(); + } + for(auto const& key: source.template getKeys()) { + m_strValues[key] = source.template get>(key).value(); + } + } + /// Class to read EDM4hep files /** * \version 1.0 @@ -127,15 +143,18 @@ namespace dd4hep::sim { } catch(std::invalid_argument&) { // we ignore if we do not have runs information } + context()->run().addExtension(parameters); + + auto *fileParameters = new FileParameters(); try { podio::Frame metaFrame = m_reader.readFrame("metadata", 0); - parameters->ingestParameters(metaFrame.getParameters()); + fileParameters->ingestParameters(metaFrame.getParameters()); } catch (std::runtime_error& e) { // we ignore if we do not have metadata information } catch(std::invalid_argument&) { // we ignore if we do not have metadata information } - context()->run().addExtension(parameters); + context()->run().addExtension(fileParameters); } catch(std::exception &e) { printout(ERROR,"EDM4hepFileReader::registerRunParameters","Failed to register run parameters: %s", e.what()); } diff --git a/DDG4/edm4hep/Geant4Output2EDM4hep.cpp b/DDG4/edm4hep/Geant4Output2EDM4hep.cpp index fec904d00..7818be1db 100644 --- a/DDG4/edm4hep/Geant4Output2EDM4hep.cpp +++ b/DDG4/edm4hep/Geant4Output2EDM4hep.cpp @@ -16,6 +16,7 @@ /// Framework include files #include #include +#include #include #include @@ -157,6 +158,27 @@ namespace dd4hep { printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str()); frame.putParameter(p.first, p.second); } +#endif + } + template <> void FileParameters::extractParameters(podio::Frame& frame) { + for(auto const& p: this->intParameters()) { + printout(DEBUG, "Geant4OutputEDM4hep", "Saving meta parameter: %s", p.first.c_str()); + frame.putParameter(p.first, p.second); + } + for(auto const& p: this->fltParameters()) { + printout(DEBUG, "Geant4OutputEDM4hep", "Saving meta parameter: %s", p.first.c_str()); + frame.putParameter(p.first, p.second); + } + for(auto const& p: this->strParameters()) { + printout(DEBUG, "Geant4OutputEDM4hep", "Saving meta parameter: %s", p.first.c_str()); + frame.putParameter(p.first, p.second); + } +#if PODIO_BUILD_VERSION > PODIO_VERSION(0, 16, 2) + // This functionality is only present in podio > 0.16.2 + for (auto const& p: this->dblParameters()) { + printout(DEBUG, "Geant4OutputEDM4hep", "Saving meta parameter: %s", p.first.c_str()); + frame.putParameter(p.first, p.second); + } #endif } @@ -303,7 +325,7 @@ void Geant4Output2EDM4hep::saveRun(const G4Run* run) { // --- write an edm4hep::RunHeader --------- // Runs are just Frames with different contents in EDM4hep / podio. We simply // store everything as parameters for now - podio::Frame runHeader {}; + podio::Frame runHeader {}; for (const auto& [key, value] : m_runHeader) runHeader.putParameter(key, value); @@ -312,13 +334,21 @@ void Geant4Output2EDM4hep::saveRun(const G4Run* run) { runHeader.putParameter("GEANT4Version", G4Version); runHeader.putParameter("DD4hepVersion", versionString()); runHeader.putParameter("detectorName", context()->detectorDescription().header().name()); - - RunParameters* parameters = context()->run().extension(false); - if ( parameters ) { - parameters->extractParameters(runHeader); + { + RunParameters* parameters = context()->run().extension(false); + if ( parameters ) { + parameters->extractParameters(runHeader); + } + m_file->writeFrame(runHeader, "runs"); + } + { + podio::Frame metaFrame {}; + FileParameters* parameters = context()->run().extension(false); + if ( parameters ) { + parameters->extractParameters(metaFrame); + } + m_file->writeFrame(metaFrame, "meta"); } - - m_file->writeFrame(runHeader, "runs"); } void Geant4Output2EDM4hep::begin(const G4Event* event) { diff --git a/DDG4/include/DDG4/EventParameters.h b/DDG4/include/DDG4/EventParameters.h index ee1d08649..8b02490b5 100644 --- a/DDG4/include/DDG4/EventParameters.h +++ b/DDG4/include/DDG4/EventParameters.h @@ -12,10 +12,7 @@ #ifndef DDG4_EVENTPARAMETERS_H #define DDG4_EVENTPARAMETERS_H -#include -#include -#include - +#include /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -28,21 +25,12 @@ namespace dd4hep { * \version 1.0 * \ingroup DD4HEP_SIMULATION */ - class EventParameters { + class EventParameters : public ExtensionParameters { protected: - int m_runNumber = -1; - int m_eventNumber = -1; - std::map> m_intValues {}; - std::map> m_fltValues {}; - std::map> m_strValues {}; - std::map> m_dblValues {}; + int m_runNumber = -1; + int m_eventNumber = -1; public: - /// Initializing constructor - EventParameters() = default; - /// Default destructor - ~EventParameters() = default; - /// Set the event parameters void setRunNumber(int runNumber); void setEventNumber(int eventNumber); @@ -50,21 +38,10 @@ namespace dd4hep { int runNumber() const { return m_runNumber; } /// Get the event number int eventNumber() const { return m_eventNumber; } - /// Copy the parameters from source template void ingestParameters(T const& source); /// Put parameters into destination template void extractParameters(T& destination); - - /// Get the int event parameters - auto const& intParameters() const { return m_intValues; } - /// Get the float event parameters - auto const& fltParameters() const { return m_fltValues; } - /// Get the string event parameters - auto const& strParameters() const { return m_strValues; } - /// Get the double event parameters - auto const& dblParameters() const { return m_dblValues; } - }; } /* End namespace sim */ diff --git a/DDG4/include/DDG4/ExtensionParameters.h b/DDG4/include/DDG4/ExtensionParameters.h new file mode 100644 index 000000000..cd9108e3c --- /dev/null +++ b/DDG4/include/DDG4/ExtensionParameters.h @@ -0,0 +1,52 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// +//========================================================================== +#ifndef DDG4_EXTENSIONPARAMETERS_H +#define DDG4_EXTENSIONPARAMETERS_H + +#include +#include +#include + + +/// Namespace for the AIDA detector description toolkit +namespace dd4hep { + + /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit + namespace sim { + + /// Extension to pass input data to output data + /** + * \version 1.0 + * \ingroup DD4HEP_SIMULATION + */ + class ExtensionParameters { + protected: + std::map> m_intValues {}; + std::map> m_fltValues {}; + std::map> m_strValues {}; + std::map> m_dblValues {}; + + public: + /// Get the int parameters + auto const& intParameters() const { return m_intValues; } + /// Get the float parameters + auto const& fltParameters() const { return m_fltValues; } + /// Get the string parameters + auto const& strParameters() const { return m_strValues; } + /// Get the double parameters + auto const& dblParameters() const { return m_dblValues; } + + }; + + } /* End namespace sim */ +} /* End namespace dd4hep */ +#endif // DDG4_EXTENSIONPARAMETERS_H diff --git a/DDG4/include/DDG4/FileParameters.h b/DDG4/include/DDG4/FileParameters.h new file mode 100644 index 000000000..4cfb12d7d --- /dev/null +++ b/DDG4/include/DDG4/FileParameters.h @@ -0,0 +1,38 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// +//========================================================================== +#ifndef DDG4_FILEPARAMETERS_H +#define DDG4_FILEPARAMETERS_H + +#include + +/// Namespace for the AIDA detector description toolkit +namespace dd4hep { + + /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit + namespace sim { + + /// Extension to pass input run data to output run data + /** + * \version 1.0 + * \ingroup DD4HEP_SIMULATION + */ + class FileParameters: public ExtensionParameters { + public: + /// Copy the parameters from source + template void ingestParameters(T const& source); + /// Put parameters into destination + template void extractParameters(T& destination); + }; + + } /* End namespace sim */ +} /* End namespace dd4hep */ +#endif // DDG4_FILEPARAMETERS_H diff --git a/DDG4/include/DDG4/RunParameters.h b/DDG4/include/DDG4/RunParameters.h index 05557f18e..c6d8ea891 100644 --- a/DDG4/include/DDG4/RunParameters.h +++ b/DDG4/include/DDG4/RunParameters.h @@ -12,10 +12,7 @@ #ifndef DDG4_RUNPARAMETERS_H #define DDG4_RUNPARAMETERS_H -#include -#include -#include - +#include /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -28,39 +25,19 @@ namespace dd4hep { * \version 1.0 * \ingroup DD4HEP_SIMULATION */ - class RunParameters { + class RunParameters: ExtensionParameters { protected: - std::map> m_intValues {}; - std::map> m_fltValues {}; - std::map> m_strValues {}; - std::map> m_dblValues {}; - int m_runNumber = -1; + int m_runNumber = -1; public: - /// Initializing constructor - RunParameters() = default; - /// Default destructor - ~RunParameters() = default; - /// Set the Run parameters void setRunNumber(int runNumber); /// Get the run number int runNumber() const { return m_runNumber; } - /// Copy the parameters from source template void ingestParameters(T const& source); /// Put parameters into destination template void extractParameters(T& destination); - - /// Get the int Run parameters - auto const& intParameters() const { return m_intValues; } - /// Get the float Run parameters - auto const& fltParameters() const { return m_fltValues; } - /// Get the string Run parameters - auto const& strParameters() const { return m_strValues; } - /// Get the double Run parameters - auto const& dblParameters() const { return m_dblValues; } - }; } /* End namespace sim */