Skip to content

Commit dce5610

Browse files
committed
DPL Analysis: initial support for Condition configurable
1 parent 32937c1 commit dce5610

4 files changed

Lines changed: 113 additions & 0 deletions

File tree

Framework/Core/include/Framework/AnalysisManagers.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
#include "Framework/ProcessingContext.h"
1919
#include "Framework/EndOfStreamContext.h"
2020
#include "Framework/HistogramRegistry.h"
21+
#include "Framework/CCDBParamSpec.h"
2122
#include "Framework/ConfigParamSpec.h"
2223
#include "Framework/ConfigParamRegistry.h"
2324
#include "Framework/ConfigurableHelpers.h"
25+
#include "Framework/Condition.h"
2426
#include "Framework/InitContext.h"
2527
#include "Framework/ConfigContext.h"
2628
#include "Framework/RootConfigParamHelpers.h"
@@ -155,6 +157,46 @@ struct FilterManager<expressions::Filter> {
155157
}
156158
};
157159

160+
/// A manager which takes care of condition objects
161+
template <typename T>
162+
struct ConditionManager {
163+
template <typename ANY>
164+
static bool appendCondition(std::vector<InputSpec>& inputs, ANY& x)
165+
{
166+
if constexpr (std::is_base_of_v<ConditionGroup, ANY>) {
167+
homogeneous_apply_refs<true>([&inputs](auto& y) { return ConditionManager<std::decay_t<decltype(y)>>::appendCondition(inputs, y); }, x);
168+
return true;
169+
} else {
170+
return false;
171+
}
172+
}
173+
174+
template <typename ANY>
175+
static bool newDataframe(InputRecord& record, ANY& x)
176+
{
177+
if constexpr (std::is_base_of_v<ConfigurableGroup, ANY>) {
178+
homogeneous_apply_refs<true>([&record](auto&& y) { return ConditionManager<std::decay_t<decltype(y)>>::newDataframe(record, y); }, x);
179+
return true;
180+
} else {
181+
return false;
182+
}
183+
}
184+
};
185+
186+
template <typename OBJ>
187+
struct ConditionManager<Condition<OBJ>> {
188+
static bool appendCondition(std::vector<InputSpec>& inputs, Condition<OBJ>& what)
189+
{
190+
inputs.emplace_back(InputSpec{what.path, "AODC", compile_time_hash(what.path.c_str()), Lifetime::Condition, ccdbParamSpec(what.path)});
191+
return true;
192+
}
193+
static bool newDataframe(InputRecord& inputs, Condition<OBJ>& what)
194+
{
195+
what.instance(inputs.get<OBJ>(what.path));
196+
return true;
197+
}
198+
};
199+
158200
/// SFINAE placeholder
159201
template <typename T>
160202
struct OutputManager {

Framework/Core/include/Framework/AnalysisTask.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "Framework/AlgorithmSpec.h"
1717
#include "Framework/CallbackService.h"
1818
#include "Framework/ConfigContext.h"
19+
#include "Framework/Condition.h"
1920
#include "Framework/ControlService.h"
2021
#include "Framework/DataProcessorSpec.h"
2122
#include "Framework/Expressions.h"
@@ -530,6 +531,8 @@ DataProcessorSpec adaptAnalysisTask(ConfigContext const& ctx, Args&&... args)
530531

531532
/// make sure options and configurables are set before expression infos are created
532533
homogeneous_apply_refs([&options, &hash](auto& x) { return OptionManager<std::decay_t<decltype(x)>>::appendOption(options, x); }, *task.get());
534+
/// extract conditions and append them as inputs
535+
homogeneous_apply_refs([&inputs](auto& x) { return ConditionManager<std::decay_t<decltype(x)>>::appendCondition(inputs, x); }, *task.get());
533536

534537
/// parse process functions defined by corresponding configurables
535538
if constexpr (has_process_v<T>) {
@@ -605,6 +608,8 @@ DataProcessorSpec adaptAnalysisTask(ConfigContext const& ctx, Args&&... args)
605608
}
606609

607610
return [task, expressionInfos](ProcessingContext& pc) mutable {
611+
// load the ccdb object from their cache
612+
homogeneous_apply_refs([&pc](auto&& x) { return ConditionManager<std::decay_t<decltype(x)>>::newDataframe(pc.inputs(), x); }, *task.get());
608613
// reset partitions once per dataframe
609614
homogeneous_apply_refs([](auto&& x) { return PartitionManager<std::decay_t<decltype(x)>>::newDataframe(x); }, *task.get());
610615
// reset selections for the next dataframe
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
#ifndef O2_FRAMEWORK_CONDITION_H_
12+
#define O2_FRAMEWORK_CONDITION_H_
13+
#include <string>
14+
15+
namespace o2::framework
16+
{
17+
18+
template <typename T>
19+
struct Condition {
20+
std::string path;
21+
T* instance;
22+
using type = T;
23+
24+
Condition(std::string path)
25+
: path(std::move(path))
26+
{
27+
}
28+
29+
operator T()
30+
{
31+
return *this->value;
32+
}
33+
34+
T const* operator->() const
35+
{
36+
return this->value;
37+
}
38+
};
39+
40+
/// Can be used to group together a number of Configurables
41+
/// to overcome the limit of 100 Configurables per task.
42+
/// In order to do so you can do:
43+
///
44+
/// struct MyTask {
45+
/// struct : ConditionGroup {
46+
/// Condition<SomeConditionObject> someCondition{...};
47+
/// } group;
48+
/// };
49+
///
50+
/// and access it with
51+
///
52+
/// group.aCut;
53+
struct ConditionGroup {
54+
};
55+
56+
} // namespace o2::framework
57+
#endif // O2_FRAMEWORK_CONDITION_H_

Framework/Core/test/test_AnalysisTask.cxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,19 @@ struct JTask {
129129
}
130130
};
131131

132+
struct TestCCDBObject {
133+
int SomeObject;
134+
};
135+
132136
struct KTask {
133137
struct : public ConfigurableGroup {
134138
Configurable<int> anInt{"someConfigurable", {}, "Some Configurable Object"};
135139
Configurable<int> anotherInt{"someOtherConfigurable", {}, "Some Configurable Object"};
136140
} foo;
137141
Configurable<int> anThirdInt{"someThirdConfigurable", {}, "Some Configurable Object"};
142+
struct : public ConditionGroup {
143+
Condition<TestCCDBObject> test{"path"};
144+
} conditions;
138145
std::unique_ptr<int> someInt;
139146
std::shared_ptr<int> someSharedInt;
140147
};
@@ -192,9 +199,11 @@ BOOST_AUTO_TEST_CASE(AdaptorCompilation)
192199
BOOST_CHECK_EQUAL(task9.inputs.size(), 4);
193200

194201
auto task10 = adaptAnalysisTask<JTask>(*cfgc, TaskName{"test10"});
202+
BOOST_CHECK_EQUAL(task10.inputs.size(), 1);
195203

196204
auto task11 = adaptAnalysisTask<KTask>(*cfgc, TaskName{"test11"});
197205
BOOST_CHECK_EQUAL(task11.options.size(), 3);
206+
BOOST_CHECK_EQUAL(task11.inputs.size(), 1);
198207
}
199208

200209
BOOST_AUTO_TEST_CASE(TestPartitionIteration)

0 commit comments

Comments
 (0)