Skip to content

Commit

Permalink
Add missing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Sep 20, 2024
1 parent 9722a66 commit 0f551d1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions k4FWCore/scripts/k4run
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ def main():
opts_dict = vars(opts)
for optionName, propTuple in option_db.items():
logger.info("Option name: %s %s %s", propTuple[1], optionName, opts_dict[optionName])
# After Gaudi v40 the new configurable histograms have properties that are tuples
# and by default one of the member is an empty tuple that Gaudi seems not to like
# when used in setProp - it will try to parse it as a string and fail
if "_Axis" in optionName:
propTuple[0].setProp(
propTuple[1].rsplit(".", 1)[1], tuple(x for x in opts_dict[optionName] if x != ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,22 @@

#include <string>

#include "GAUDI_VERSION.h"

#if GAUDI_MAJOR_VERSION < 40
namespace Gaudi::Accumulators {
using StaticRootHistogram = Gaudi::Accumulators::RootHistogram;
}
#endif

struct ExampleFunctionalTransformerHist final
: k4FWCore::Transformer<edm4hep::MCParticleCollection(const edm4hep::MCParticleCollection& input)> {
StatusCode initialize() override {
#if GAUDI_MAJOR_VERSION >= 40
m_customHistogram.createHistogram(*this);
#endif
return StatusCode::SUCCESS;
}
// The pairs in KeyValues can be changed from python and they correspond
// to the name of the input and output collections respectively
ExampleFunctionalTransformerHist(const std::string& name, ISvcLocator* svcLoc)
Expand All @@ -36,14 +50,25 @@ struct ExampleFunctionalTransformerHist final
// This is the function that will be called to produce the data
edm4hep::MCParticleCollection operator()(const edm4hep::MCParticleCollection& input) const override {
// Fill the histogram with the energy of one particle
++m_histograms[input[0 + !m_firstParticle.value()].getEnergy()];
++m_histogram[input[0 + !m_firstParticle.value()].getEnergy()];
#if GAUDI_MAJOR_VERSION >= 40
++m_customHistogram[input[0 + !m_firstParticle.value()].getEnergy()];
#endif
// Return an empty collection since we don't care about the collection
return {};
}

private:
// This is the histogram that will be filled, 1 is the number of dimensions of the histogram (1D)
mutable Gaudi::Accumulators::RootHistogram<1> m_histograms{this, "Histogram Name", "Histogram Title", {100, 0, 10.}};
mutable Gaudi::Accumulators::StaticRootHistogram<1> m_histogram{
this, "Histogram Name", "Histogram Title", {100, 0, 10.}};

public:
#if GAUDI_MAJOR_VERSION >= 40
// This is a histogram with title, name and bins that can be set from python
void registerCallBack(Gaudi::StateMachine::Transition, std::function<void()>) {}
mutable Gaudi::Accumulators::RootHistogram<1> m_customHistogram{this, "CustomHistogram"};
#endif

Gaudi::Property<bool> m_firstParticle{this, "FirstParticle", true};
};
Expand Down

0 comments on commit 0f551d1

Please sign in to comment.