Skip to content

Commit 8a984f4

Browse files
committed
[Benchmarks] Introduce analysis benhcmark tasks
1 parent 6e6dba1 commit 8a984f4

File tree

6 files changed

+209
-0
lines changed

6 files changed

+209
-0
lines changed

Benchmarks/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
12+
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
13+
14+
o2physics_add_dpl_workflow(dynamic
15+
SOURCES src/dynamic-column.cxx
16+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
17+
COMPONENT_NAME AnalysisBenchmark)
18+
19+
o2physics_add_dpl_workflow(dynamic-func
20+
SOURCES src/dynamic-column-func.cxx
21+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
22+
COMPONENT_NAME AnalysisBenchmark)
23+
24+
o2physics_add_dpl_workflow(configurable-expression
25+
SOURCES src/configurable-expression-column.cxx
26+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
27+
COMPONENT_NAME AnalysisBenchmark)

Benchmarks/include/tables.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
#include <Framework/AnalysisDataModel.h>
12+
13+
namespace o2::aod
14+
{
15+
namespace extensions
16+
{
17+
DECLARE_SOA_DYNAMIC_COLUMN(Direct, direct, [](float x, float y, float z, float t) -> float { return t * (x*x + y*y + z*z); });
18+
DECLARE_SOA_COLUMN(DirectM, directm, float);
19+
20+
DECLARE_SOA_DYNAMIC_COLUMN(Indirect, indirect, [](float phi, float x, float y, float z, std::function<float(float, float, float, float)> const& f) -> float { return f(phi, x, y, z); });
21+
DECLARE_SOA_COLUMN(IndirectM, indirectm, float);
22+
23+
DECLARE_SOA_CONFIGURABLE_EXPRESSION_COLUMN(Expr, expr, float, "Expr");
24+
}
25+
26+
DECLARE_SOA_TABLE(ExtTracksD, "AOD", "TRKD", extensions::Direct<aod::track::X, aod::track::Y, aod::track::Z>);
27+
DECLARE_SOA_TABLE(ExtTracksID, "AOD", "TRKID", extensions::Indirect<aod::track::Phi, aod::track::X, aod::track::Y, aod::track::Z>);
28+
29+
DECLARE_SOA_TABLE(ExtTracksDM, "AOD", "TRKDM", extensions::DirectM);
30+
DECLARE_SOA_TABLE(ExtTracksIDM, "AOD", "TRKIDM", extensions::IndirectM);
31+
32+
DECLARE_SOA_CONFIGURABLE_EXTENDED_TABLE(TracksE, TracksIU, "TRKE", extensions::Expr);
33+
34+
using TracksD = soa::Join<TracksIU, ExtTracksD>;
35+
using TracksID = soa::Join<TracksIU, ExtTracksID>;
36+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
12+
#include "Framework/runDataProcessing.h"
13+
#include "Framework/AnalysisTask.h"
14+
15+
#include "tables.h"
16+
17+
using namespace o2;
18+
using namespace o2::framework;
19+
using namespace o2::framework::expressions;
20+
21+
struct ProduceExression {
22+
Defines<aod::TracksE> te;
23+
// bin lower bounds + the rightmost upper bound
24+
Configurable<std::vector<float>> binning{"binning", {0, o2::constants::math::PIHalf, o2::constants::math::PI, o2::constants::math::PI + o2::constants::math::PIHalf, o2::constants::math::TwoPI}, "Phi binning"};
25+
// parameters for the function as a flat array, grouped by parameter
26+
Configurable<std::vector<float>> parameters{"parameters", {1.0, 1.1, 1.2, 1.3, // par 0
27+
2.0, 2.1, 2.2, 2.3, // par 1
28+
3.0, 3.1, 3.2, 3.3}, // par 2
29+
"Function parameters for each phi bin"};
30+
31+
void init(InitContext&)
32+
{
33+
// dummy function for benchmark (equivalent to dynamic-column-func.cxx)
34+
te.projectors[0] = binned((std::vector<float>)binning,
35+
(std::vector<float>)parameters,
36+
aod::track::phi, nsqrt(par(0) * aod::track::x * aod::track::x + par(1) * aod::track::y * aod::track::y + par(2) * aod::track::z * aod::track::z),
37+
LiteralNode{-1.f});
38+
}
39+
};
40+
41+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
42+
{
43+
return {adaptAnalysisTask<ProduceExression>(cfgc)};
44+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
12+
#include "Framework/runDataProcessing.h"
13+
#include "Framework/AnalysisTask.h"
14+
15+
#include "tables.h"
16+
17+
using namespace o2;
18+
using namespace o2::framework;
19+
using namespace o2::framework::expressions;
20+
21+
struct ProduceDynamicExtensionFunc {
22+
Produces<aod::ExtTracksIDM> etidm;
23+
24+
std::function<float(float, float, float, float)> callable;
25+
// bin lower bounds + the rightmost upper bound
26+
Configurable<std::vector<float>> binning{"binning", {0, o2::constants::math::PIHalf, o2::constants::math::PI, o2::constants::math::PI + o2::constants::math::PIHalf, o2::constants::math::TwoPI}, "Phi binning"};
27+
// parameters for the function as a flat array, grouped by parameter
28+
Configurable<std::vector<float>> parameters{"parameters", {1.0, 1.1, 1.2, 1.3, // par 0
29+
2.0, 2.1, 2.2, 2.3, // par 1
30+
3.0, 3.1, 3.2, 3.3}, // par 2
31+
"Function parameters for each phi bin"};
32+
33+
void init(InitContext&)
34+
{
35+
// dummy function for benchmark (equivalent to configurable-expression-column.cxx)
36+
callable = [binning = (std::vector<float>)binning, parameters = (std::vector<float>)parameters](float phi, float x, float y, float z) -> float {
37+
if (phi < binning[0]) {
38+
return -1.f;
39+
}
40+
auto n = binning.size() - 1;
41+
for (auto i = 0U; i < n; ++i) {
42+
if (phi < binning[i + 1]) {
43+
return std::sqrt(parameters[0 * n + i] * x * x + //
44+
parameters[1 * n + i] * y * y + //
45+
parameters[2 * n + i] * z * z); //
46+
}
47+
}
48+
return -1.f;
49+
};
50+
}
51+
52+
void process(aod::TracksIU const& tracks)
53+
{
54+
auto tracksID = soa::Attach<aod::TracksIU, aod::extensions::Indirect<aod::track::Phi, aod::track::X, aod::track::Y, aod::track::Z>>(tracks);
55+
for (auto& track : tracksID) {
56+
etidm(track.indirect(callable));
57+
}
58+
}
59+
};
60+
61+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
62+
{
63+
return {adaptAnalysisTask<ProduceDynamicExtensionFunc>(cfgc)};
64+
}

Benchmarks/src/dynamic-column.cxx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
12+
#include "Framework/runDataProcessing.h"
13+
#include "Framework/AnalysisTask.h"
14+
15+
#include "tables.h"
16+
17+
using namespace o2;
18+
using namespace o2::framework;
19+
using namespace o2::framework::expressions;
20+
21+
struct ProduceDynamicExtension {
22+
Produces<aod::ExtTracksDM> etdm;
23+
Configurable<float> factor{"factor", 1.0f, "Configurable factor"};
24+
25+
void process(aod::TracksIU const& tracks)
26+
{
27+
auto tracksD = soa::Attach<aod::TracksIU, aod::extensions::Direct<aod::track::X, aod::track::Y, aod::track::Z>>(tracks);
28+
for (auto& track : tracksD) {
29+
etdm(track.direct((float)factor));
30+
}
31+
}
32+
};
33+
34+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
35+
{
36+
return {adaptAnalysisTask<ProduceDynamicExtension>(cfgc)};
37+
}

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ add_subdirectory(PWGUD)
7575

7676
add_subdirectory(Tools)
7777
add_subdirectory(Tutorials)
78+
add_subdirectory(Benchmarks)
7879
add_subdirectory(EventFiltering)
7980

8081
add_subdirectory(Scripts)

0 commit comments

Comments
 (0)