Skip to content
Snippets Groups Projects
Commit 9f29bd46 authored by Andre Sailer's avatar Andre Sailer
Browse files

DDG4: add propagating of run parameters from input files to output files

parent ab9a96e6
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "HepMC3EventReader.h" #include "HepMC3EventReader.h"
#include "DDG4/EventParameters.h" #include "DDG4/EventParameters.h"
#include "DDG4/RunParameters.h"
#include <HepMC3/ReaderFactory.h> #include <HepMC3/ReaderFactory.h>
...@@ -68,6 +69,22 @@ namespace dd4hep { ...@@ -68,6 +69,22 @@ namespace dd4hep {
} }
} }
template <class T=HepMC3::GenRunInfo> void RunParameters::ingestParameters(T const& runInfo) {
// This attributes is not the same return type as for GenEvent!
for(auto const& attr: runInfo.attributes()){
std::stringstream strstr;
if(auto int_attr = std::dynamic_pointer_cast<HepMC3::IntAttribute>(attr.second)) {
m_intValues[attr.first] = {int_attr->value()};
} else if(auto flt_attr = std::dynamic_pointer_cast<HepMC3::FloatAttribute>(attr.second)) {
m_fltValues[attr.first] = {flt_attr->value()};
} else if(auto dbl_attr = std::dynamic_pointer_cast<HepMC3::DoubleAttribute>(attr.second)) {
m_dblValues[attr.first] = {dbl_attr->value()};
} else { // anything else
m_strValues[attr.first] = {attr.second->unparsed_string()};
}
}
}
/// Base class to read hepmc3 event files /// Base class to read hepmc3 event files
/** /**
* \version 1.0 * \version 1.0
...@@ -89,6 +106,9 @@ namespace dd4hep { ...@@ -89,6 +106,9 @@ namespace dd4hep {
virtual EventReaderStatus moveToEvent(int event_number); virtual EventReaderStatus moveToEvent(int event_number);
//virtual EventReaderStatus skipEvent() { return EVENT_READER_OK; } //virtual EventReaderStatus skipEvent() { return EVENT_READER_OK; }
virtual EventReaderStatus setParameters(std::map< std::string, std::string >& parameters); virtual EventReaderStatus setParameters(std::map< std::string, std::string >& parameters);
/// register the run parameters into an extension for the run context
virtual void registerRunParameters();
}; };
} }
} }
...@@ -111,6 +131,15 @@ HEPMC3FileReader::HEPMC3FileReader(const std::string& nam) ...@@ -111,6 +131,15 @@ HEPMC3FileReader::HEPMC3FileReader(const std::string& nam)
m_directAccess = false; m_directAccess = false;
} }
void HEPMC3FileReader::registerRunParameters() {
try {
auto *parameters = new RunParameters();
parameters->ingestParameters(*(m_reader->run_info()));
context()->run().addExtension<RunParameters>(parameters);
} catch(std::exception &) {
}
}
/// moveToSpecifiedEvent, a.k.a. skipNEvents /// moveToSpecifiedEvent, a.k.a. skipNEvents
Geant4EventReader::EventReaderStatus Geant4EventReader::EventReaderStatus
HEPMC3FileReader::moveToEvent(int event_number) { HEPMC3FileReader::moveToEvent(int event_number) {
......
...@@ -137,6 +137,9 @@ namespace dd4hep { ...@@ -137,6 +137,9 @@ namespace dd4hep {
/// make sure that all parameters have been processed, otherwise throw exceptions /// make sure that all parameters have been processed, otherwise throw exceptions
virtual void checkParameters( std::map< std::string, std::string >& ); virtual void checkParameters( std::map< std::string, std::string >& );
/// Register Run Parameters
virtual void registerRunParameters() {}
}; };
/// Generic input action capable of using the Geant4EventReader class. /// Generic input action capable of using the Geant4EventReader class.
......
...@@ -165,6 +165,7 @@ int Geant4InputAction::readParticles(int evt_number, ...@@ -165,6 +165,7 @@ int Geant4InputAction::readParticles(int evt_number,
m_reader->setParameters( m_parameters ); m_reader->setParameters( m_parameters );
m_reader->checkParameters( m_parameters ); m_reader->checkParameters( m_parameters );
m_reader->setInputAction( this ); m_reader->setInputAction( this );
m_reader->registerRunParameters();
} }
catch(const exception& e) { catch(const exception& e) {
err = e.what(); err = e.what();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment