Skip to content

Commit 8cd3d58

Browse files
authored
[QC-443] Data Sampling: ptree interfaces for everything (AliceO2Group#6813)
After we move to those in QC, it will be followed up with deleting methods which expect ConfigurationInterface.
1 parent d2c0d90 commit 8cd3d58

2 files changed

Lines changed: 45 additions & 31 deletions

File tree

Utilities/DataSampling/include/DataSampling/DataSampling.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,26 @@ class DataSampling
100100
static std::vector<framework::InputSpec> InputSpecsForPolicy(configuration::ConfigurationInterface* const config, const std::string& policyName);
101101
/// \brief Provides InputSpecs to receive data for given DataSamplingPolicy
102102
static std::vector<framework::InputSpec> InputSpecsForPolicy(std::shared_ptr<configuration::ConfigurationInterface> config, const std::string& policyName);
103-
/// \brief Provides OutputSpecs of given DataSamplingPolicy
103+
/// \brief Provides InputSpecs to receive data for given DataSamplingPolicy. Expects the "dataSamplingPolicies" tree.
104+
static std::vector<framework::InputSpec> InputSpecsForPolicy(const boost::property_tree::ptree& policiesTree, const std::string& policyName);
105+
/// \brief Provides OutputSpecs of given DataSamplingPolicy.
104106
static std::vector<framework::OutputSpec> OutputSpecsForPolicy(const std::string& policiesSource, const std::string& policyName);
105-
/// \brief Provides OutputSpecs of given DataSamplingPolicy
107+
/// \brief Provides OutputSpecs of given DataSamplingPolicy.
106108
static std::vector<framework::OutputSpec> OutputSpecsForPolicy(configuration::ConfigurationInterface* const config, const std::string& policyName);
107-
/// \brief Provides the port to be used for a proxy of given DataSamplingPolicy
109+
/// \brief Provides OutputSpecs of given DataSamplingPolicy. Expects the "dataSamplingPolicies" tree.
110+
static std::vector<framework::OutputSpec> OutputSpecsForPolicy(const boost::property_tree::ptree& policiesTree, const std::string& policyName);
111+
/// \brief Provides the port to be used for a proxy of given DataSamplingPolicy.
108112
static std::optional<uint16_t> PortForPolicy(configuration::ConfigurationInterface* const config, const std::string& policyName);
109-
/// \brief Provides the port to be used for a proxy of given DataSamplingPolicy
113+
/// \brief Provides the port to be used for a proxy of given DataSamplingPolicy.
110114
static std::optional<uint16_t> PortForPolicy(const std::string& policiesSource, const std::string& policyName);
111-
/// \brief Provides the machines where given DataSamplingPolicy is enabled
115+
/// \brief Provides the port to be used for a proxy of given DataSamplingPolicy. Expects the "dataSamplingPolicies" tree.
116+
static std::optional<uint16_t> PortForPolicy(const boost::property_tree::ptree& policiesTree, const std::string& policyName);
117+
/// \brief Provides the machines where given DataSamplingPolicy is enabled.
112118
static std::vector<std::string> MachinesForPolicy(configuration::ConfigurationInterface* const config, const std::string& policyName);
113-
/// \brief Provides the port to be used for a proxy of given DataSamplingPolicy
119+
/// \brief Provides the machines where given DataSamplingPolicy is enabled.
114120
static std::vector<std::string> MachinesForPolicy(const std::string& policiesSource, const std::string& policyName);
121+
/// \brief Provides the machines where given DataSamplingPolicy is enabled. Expects the "dataSamplingPolicies" tree.
122+
static std::vector<std::string> MachinesForPolicy(const boost::property_tree::ptree& policiesTree, const std::string& policyName);
115123

116124
private:
117125
static void DoGenerateInfrastructure(Dispatcher&, framework::WorkflowSpec& workflow, boost::property_tree::ptree const& policies, size_t threads = 1);

Utilities/DataSampling/src/DataSampling.cxx

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -112,27 +112,19 @@ std::vector<InputSpec> DataSampling::InputSpecsForPolicy(const std::string& poli
112112

113113
std::vector<InputSpec> DataSampling::InputSpecsForPolicy(ConfigurationInterface* const config, const std::string& policyName)
114114
{
115-
std::vector<InputSpec> inputs;
116115
auto policiesTree = config->getRecursive("dataSamplingPolicies");
117-
118-
for (auto&& policyConfig : policiesTree) {
119-
if (policyConfig.second.get<std::string>("id") == policyName) {
120-
auto policy = DataSamplingPolicy::fromConfiguration(policyConfig.second);
121-
for (const auto& path : policy.getPathMap()) {
122-
InputSpec input = DataSpecUtils::matchingInput(path.second);
123-
inputs.push_back(input);
124-
}
125-
break;
126-
}
127-
}
128-
return inputs;
116+
return InputSpecsForPolicy(policiesTree, policyName);
129117
}
130118

131119
std::vector<InputSpec> DataSampling::InputSpecsForPolicy(std::shared_ptr<configuration::ConfigurationInterface> config, const std::string& policyName)
132120
{
133-
std::vector<InputSpec> inputs;
134121
auto policiesTree = config->getRecursive("dataSamplingPolicies");
122+
return InputSpecsForPolicy(policiesTree, policyName);
123+
}
135124

125+
std::vector<framework::InputSpec> DataSampling::InputSpecsForPolicy(const boost::property_tree::ptree& policiesTree, const std::string& policyName)
126+
{
127+
std::vector<InputSpec> inputs;
136128
for (auto&& policyConfig : policiesTree) {
137129
if (policyConfig.second.get<std::string>("id") == policyName) {
138130
auto policy = DataSamplingPolicy::fromConfiguration(policyConfig.second);
@@ -154,9 +146,13 @@ std::vector<OutputSpec> DataSampling::OutputSpecsForPolicy(const std::string& po
154146

155147
std::vector<OutputSpec> DataSampling::OutputSpecsForPolicy(ConfigurationInterface* const config, const std::string& policyName)
156148
{
157-
std::vector<OutputSpec> outputs;
158149
auto policiesTree = config->getRecursive("dataSamplingPolicies");
150+
return OutputSpecsForPolicy(policiesTree, policyName);
151+
}
159152

153+
std::vector<framework::OutputSpec> DataSampling::OutputSpecsForPolicy(const boost::property_tree::ptree& policiesTree, const std::string& policyName)
154+
{
155+
std::vector<OutputSpec> outputs;
160156
for (auto&& policyConfig : policiesTree) {
161157
if (policyConfig.second.get<std::string>("id") == policyName) {
162158
auto policy = DataSamplingPolicy::fromConfiguration(policyConfig.second);
@@ -172,6 +168,17 @@ std::vector<OutputSpec> DataSampling::OutputSpecsForPolicy(ConfigurationInterfac
172168
std::optional<uint16_t> DataSampling::PortForPolicy(configuration::ConfigurationInterface* const config, const std::string& policyName)
173169
{
174170
auto policiesTree = config->getRecursive("dataSamplingPolicies");
171+
return PortForPolicy(policiesTree, policyName);
172+
}
173+
174+
std::optional<uint16_t> DataSampling::PortForPolicy(const std::string& policiesSource, const std::string& policyName)
175+
{
176+
std::unique_ptr<ConfigurationInterface> config = ConfigurationFactory::getConfiguration(policiesSource);
177+
return PortForPolicy(config.get(), policyName);
178+
}
179+
180+
std::optional<uint16_t> DataSampling::PortForPolicy(const boost::property_tree::ptree& policiesTree, const std::string& policyName)
181+
{
175182
for (auto&& policyConfig : policiesTree) {
176183
if (policyConfig.second.get<std::string>("id") == policyName) {
177184
auto boostOptionalPort = policyConfig.second.get_optional<uint16_t>("port");
@@ -181,16 +188,21 @@ std::optional<uint16_t> DataSampling::PortForPolicy(configuration::Configuration
181188
throw std::runtime_error("Could not find the policy '" + policyName + "'");
182189
}
183190

184-
std::optional<uint16_t> DataSampling::PortForPolicy(const std::string& policiesSource, const std::string& policyName)
191+
std::vector<std::string> DataSampling::MachinesForPolicy(configuration::ConfigurationInterface* const config, const std::string& policyName)
192+
{
193+
auto policiesTree = config->getRecursive("dataSamplingPolicies");
194+
return MachinesForPolicy(policiesTree, policyName);
195+
}
196+
197+
std::vector<std::string> DataSampling::MachinesForPolicy(const std::string& policiesSource, const std::string& policyName)
185198
{
186199
std::unique_ptr<ConfigurationInterface> config = ConfigurationFactory::getConfiguration(policiesSource);
187-
return PortForPolicy(config.get(), policyName);
200+
return MachinesForPolicy(config.get(), policyName);
188201
}
189202

190-
std::vector<std::string> DataSampling::MachinesForPolicy(configuration::ConfigurationInterface* const config, const std::string& policyName)
203+
std::vector<std::string> DataSampling::MachinesForPolicy(const boost::property_tree::ptree& policiesTree, const std::string& policyName)
191204
{
192205
std::vector<std::string> machines;
193-
auto policiesTree = config->getRecursive("dataSamplingPolicies");
194206
for (auto&& policyConfig : policiesTree) {
195207
if (policyConfig.second.get<std::string>("id") == policyName) {
196208
if (policyConfig.second.count("machines") > 0) {
@@ -204,10 +216,4 @@ std::vector<std::string> DataSampling::MachinesForPolicy(configuration::Configur
204216
throw std::runtime_error("Could not find the policy '" + policyName + "'");
205217
}
206218

207-
std::vector<std::string> DataSampling::MachinesForPolicy(const std::string& policiesSource, const std::string& policyName)
208-
{
209-
std::unique_ptr<ConfigurationInterface> config = ConfigurationFactory::getConfiguration(policiesSource);
210-
return MachinesForPolicy(config.get(), policyName);
211-
}
212-
213219
} // namespace o2::utilities

0 commit comments

Comments
 (0)