diff --git a/bind/python/iguana-python-example.py b/bind/python/iguana-python-example.py index 5a984b25..7c402371 100755 --- a/bind/python/iguana-python-example.py +++ b/bind/python/iguana-python-example.py @@ -19,13 +19,10 @@ seq.Add('clas12::LorentzTransformer') seq.PrintSequence() -seq.SetOption('clas12::EventBuilderFilter', 'log', 'trace') +seq.SetOption('clas12::EventBuilderFilter', 'log', 'trace') +seq.SetOption('clas12::EventBuilderFilter', 'pids', [11, 211, -211]) seq.SetOption('clas12::EventBuilderFilter', 'testInt', 7) seq.SetOption('clas12::EventBuilderFilter', 'testFloat', 42.3) -# # TODO: need to marshal std::set -# seq.SetOption('clas12::EventBuilderFilter', 'pids', [11,211,-211]) -# cppyy.cppexec('iguana::option_t pids = std::set{11,211,-211};') -# seq.SetOption('clas12::EventBuilderFilter', 'pids', cppyy.gbl.pids) def prettyPrint(message, bank): print(f'{"="*30} {message} {"="*30}') diff --git a/examples/iguana-example-00-basic.cc b/examples/iguana-example-00-basic.cc index 6ac1aa70..fd50729d 100644 --- a/examples/iguana-example-00-basic.cc +++ b/examples/iguana-example-00-basic.cc @@ -31,7 +31,7 @@ int main(int argc, char **argv) { seq.SetOption("clas12::LorentzTransformer", "log", "debug"); // set algorithm options - seq.SetOption("clas12::EventBuilderFilter", "pids", std::set{11, 211, -211}); + seq.SetOption>("clas12::EventBuilderFilter", "pids", {11, 211, -211}); seq.SetOption("clas12::LorentzTransformer", "frame", "mirror"); // start the algorithms diff --git a/src/iguana/algorithms/Algorithm.cc b/src/iguana/algorithms/Algorithm.cc index 6e7147a6..ec8d1512 100644 --- a/src/iguana/algorithms/Algorithm.cc +++ b/src/iguana/algorithms/Algorithm.cc @@ -22,7 +22,7 @@ namespace iguana { if (const auto valPtr(std::get_if(&val)); valPtr) return fmt::format("{} [{}]", *valPtr, "int"); else if (const auto valPtr(std::get_if(&val)); valPtr) return fmt::format("{} [{}]", *valPtr, "double"); else if (const auto valPtr(std::get_if(&val)); valPtr) return fmt::format("{} [{}]", *valPtr, "string"); - else if (const auto valPtr(std::get_if>(&val)); valPtr) return fmt::format("({}) [{}]", fmt::join(*valPtr,", "), "set"); + else if (const auto valPtr(std::get_if>(&val)); valPtr) return fmt::format("({}) [{}]", fmt::join(*valPtr,", "), "vector"); else { m_log->Error("option '{}' type has no printer defined in Algorithm::PrintOptionValue", key); return "UNKNOWN"; diff --git a/src/iguana/algorithms/Algorithm.h b/src/iguana/algorithms/Algorithm.h index 6ea7ef0d..a49a49f1 100644 --- a/src/iguana/algorithms/Algorithm.h +++ b/src/iguana/algorithms/Algorithm.h @@ -1,8 +1,8 @@ #pragma once -#include #include #include +#include #include #include #include @@ -18,7 +18,7 @@ namespace iguana { int, double, std::string, - std::set + std::vector >; /// @brief Base class for all algorithms to inherit from @@ -107,6 +107,18 @@ namespace iguana { m_log->Debug("OPTION: {:>20} = {}", key, PrintOptionValue(key)); } + /// Cache an option of type `std::vector` and convert it to `std::set` + /// @see `Algorithm::CacheOption` + /// @param[in] key the name of the option + /// @param[in] def the default `std::vector` + /// @param[out] val reference to the `std::set` option + template + void CacheVectorOptionToSet(const std::string key, const std::vector def, std::set& val) { + std::vector vec; + CacheOption(key, def, vec); + std::copy(vec.begin(), vec.end(), std::inserter(val, val.end())); + } + /// Return a string with the value of an option along with its type /// @param key the name of the option /// @return the string value and its type diff --git a/src/iguana/algorithms/clas12/EventBuilderFilter.cc b/src/iguana/algorithms/clas12/EventBuilderFilter.cc index bb25678d..297f915d 100644 --- a/src/iguana/algorithms/clas12/EventBuilderFilter.cc +++ b/src/iguana/algorithms/clas12/EventBuilderFilter.cc @@ -11,7 +11,7 @@ namespace iguana::clas12 { void EventBuilderFilter::Start(hipo::banklist& banks) { // define options, their default values, and cache them - CacheOption("pids", std::set{11, 211}, o_pids); + CacheVectorOptionToSet("pids", {11, 211}, o_pids); CacheOption("testInt", 8, o_testInt); // TODO: remove CacheOption("testFloat", 7.0, o_testFloat); // TODO: remove