Skip to content

Commit

Permalink
fix: use std::vector in option_t instead of std::set
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Dec 19, 2023
1 parent afccd9b commit fb3e72b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
7 changes: 2 additions & 5 deletions bind/python/iguana-python-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>{11,211,-211};')
# seq.SetOption('clas12::EventBuilderFilter', 'pids', cppyy.gbl.pids)

def prettyPrint(message, bank):
print(f'{"="*30} {message} {"="*30}')
Expand Down
2 changes: 1 addition & 1 deletion examples/iguana-example-00-basic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>{11, 211, -211});
seq.SetOption<std::vector<int>>("clas12::EventBuilderFilter", "pids", {11, 211, -211});
seq.SetOption("clas12::LorentzTransformer", "frame", "mirror");

// start the algorithms
Expand Down
2 changes: 1 addition & 1 deletion src/iguana/algorithms/Algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace iguana {
if (const auto valPtr(std::get_if<int>(&val)); valPtr) return fmt::format("{} [{}]", *valPtr, "int");
else if (const auto valPtr(std::get_if<double>(&val)); valPtr) return fmt::format("{} [{}]", *valPtr, "double");
else if (const auto valPtr(std::get_if<std::string>(&val)); valPtr) return fmt::format("{} [{}]", *valPtr, "string");
else if (const auto valPtr(std::get_if<std::set<int>>(&val)); valPtr) return fmt::format("({}) [{}]", fmt::join(*valPtr,", "), "set<int>");
else if (const auto valPtr(std::get_if<std::vector<int>>(&val)); valPtr) return fmt::format("({}) [{}]", fmt::join(*valPtr,", "), "vector<int>");
else {
m_log->Error("option '{}' type has no printer defined in Algorithm::PrintOptionValue", key);
return "UNKNOWN";
Expand Down
16 changes: 14 additions & 2 deletions src/iguana/algorithms/Algorithm.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <set>
#include <variant>
#include <vector>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <functional>
Expand All @@ -18,7 +18,7 @@ namespace iguana {
int,
double,
std::string,
std::set<int>
std::vector<int>
>;

/// @brief Base class for all algorithms to inherit from
Expand Down Expand Up @@ -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 <typename T>
void CacheVectorOptionToSet(const std::string key, const std::vector<T> def, std::set<T>& val) {
std::vector<T> 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
Expand Down
2 changes: 1 addition & 1 deletion src/iguana/algorithms/clas12/EventBuilderFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>{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

Expand Down

0 comments on commit fb3e72b

Please sign in to comment.