Skip to content

Commit

Permalink
fix: automatically register ParameterRef<T> upon Configure
Browse files Browse the repository at this point in the history
  • Loading branch information
wdconinc committed Dec 6, 2023
1 parent 7942f10 commit 57d473d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/extensions/jana/JOmniFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class JOmniFactory : public JMultifactory {
std::string m_description;
virtual void Configure(JParameterManager& parman, const std::string& prefix) = 0;
virtual void Configure(std::map<std::string, std::string> fields) = 0;
virtual ~ParameterBase() { };
};

template <typename T>
Expand Down
46 changes: 31 additions & 15 deletions src/factories/calorimetry/CalorimeterClusterRecoCoG_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace eicrecon {

using ConfigMap = std::map<std::string, algorithms::PropertyValue>;
using ConfigMap = std::map<std::string_view, algorithms::PropertyValue>;

class CalorimeterClusterRecoCoG_factory : public JOmniFactory<CalorimeterClusterRecoCoG_factory, ConfigMap> {

Expand All @@ -26,26 +26,42 @@ class CalorimeterClusterRecoCoG_factory : public JOmniFactory<CalorimeterCluster

PodioOutput<edm4eic::Cluster> m_cluster_output {this};
PodioOutput<edm4eic::MCRecoClusterParticleAssociation> m_assoc_output {this};
/*
std::vector<std::unique_ptr<ParameterBase>> m_parameters = [this](){
std::vector<std::unique_ptr<ParameterBase>> v;
v.push_back(std::make_unique<ParameterRef<std::string>>(this, "energyWeight", std::string("log")));
return v;
}();
*/
ParameterRef<std::string> m_energyWeight {this, "energyWeight", std::get<std::string>(config()["energyWeight"])};
ParameterRef<double> m_samplingFraction {this, "samplingFraction", std::get<double>(config()["samplingFraction"])};
ParameterRef<double> m_logWeightBase {this, "logWeightBase", std::get<double>(config()["logWeightBase"])};
ParameterRef<bool> m_enableEtaBounds {this, "enableEtaBounds", std::get<bool>(config()["enableEtaBounds"])};

std::vector<std::unique_ptr<ParameterBase>> m_parameters;

Service<DD4hep_service> m_geoSvc {this};
// Resource<DD4hep_service, const dd4hep::Detector*> m_detector {this, [](std::shared_ptr<DD4hep_service> s, int64_t run_nr){ return s->detector(); }}

public:
void Configure() {
m_algo = std::make_unique<AlgoT>(GetPrefix());
//m_algo->applyConfig(config());
m_algo->init(m_geoSvc().detector(), logger());
m_algo = std::make_unique<AlgoT>(GetPrefix());

for (const auto& [key, prop] : m_algo->getProperties()) {
std::visit(
[this, key = key](auto&& val) {
using T = std::decay_t<decltype(val)>;
if constexpr (std::is_fundamental_v<T>
|| std::is_same_v<T, std::string>) {
// check if defined on factory generation
auto it = config().find(key);
if (it != config().end()) {
val = std::get<T>(it->second);
config().erase(it);
}
this->m_parameters.push_back(std::move(std::make_unique<ParameterRef<T>>(this, std::string(key), val)));
logger()->debug("Adding parameter {} of type {} with default value {}", key, JTypeInfo::demangle<T>(), val);
} else {
logger()->warn("No support for parsing {} of type {}", key, JTypeInfo::demangle<T>());
}
},
prop.get()
);
}
if (config().size() > 0) {
throw JException("Algorithm config contains unrecognized entries");
}

m_algo->init(m_geoSvc().detector(), logger());
}

void ChangeRun(int64_t run_number) {
Expand Down

0 comments on commit 57d473d

Please sign in to comment.