-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathschemaEvolution.cxx
More file actions
89 lines (78 loc) · 2.93 KB
/
schemaEvolution.cxx
File metadata and controls
89 lines (78 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "Framework/runDataProcessing.h"
#include "Framework/AnalysisTask.h"
#include "Framework/AnalysisDataModel.h"
// This example shows how schema evolution of tables can be implemented
// Here two tables are defined, EtaPhiV2 has an additional member compared to EtaPhiV1
// It is shown how an example task can use a template, and can be instantiated to work
// on both.
namespace o2::aod
{
namespace etaphi
{
DECLARE_SOA_COLUMN(Eta, eta, float);
DECLARE_SOA_COLUMN(AbsEta, absEta, float);
DECLARE_SOA_COLUMN(Phi, phi, float);
} // namespace etaphi
DECLARE_SOA_TABLE(EtaPhiV1, "AOD", "ETAPHI", etaphi::Eta, etaphi::Phi);
DECLARE_SOA_TABLE(EtaPhiV2, "AOD", "ETAPHIV2", etaphi::Eta, etaphi::AbsEta, etaphi::Phi);
} // namespace o2::aod
using namespace o2;
using namespace o2::framework;
// Producer of EtaPhiV1
struct ATask {
Produces<aod::EtaPhiV1> etaphi;
void process(aod::Tracks const& tracks)
{
for (auto& track : tracks) {
float phi = asin(track.snp()) + track.alpha() + static_cast<float>(M_PI);
float eta = log(tan(0.25f * static_cast<float>(M_PI) - 0.5f * atan(track.tgl())));
etaphi(eta, phi);
}
}
};
// Producer of EtaPhiV2
struct BTask {
Produces<aod::EtaPhiV2> etaphi;
void process(aod::Tracks const& tracks)
{
for (auto& track : tracks) {
float phi = asin(track.snp()) + track.alpha() + static_cast<float>(M_PI);
float eta = log(tan(0.25f * static_cast<float>(M_PI) - 0.5f * atan(track.tgl())));
etaphi(eta, std::abs(eta), phi);
}
}
};
// Consumper of both EtaPhiV1 and EtaPhiV2
// InputTable is a template which is then specified below when the workflow is defined
template <typename InputTable>
struct CTask {
void process(InputTable const& etaPhis)
{
constexpr bool isV2 = std::is_same<InputTable, aod::EtaPhiV2>::value;
for (auto& etaPhi : etaPhis) {
LOGF(info, "(%f, %f)", etaPhi.eta(), etaPhi.phi());
if constexpr (isV2) {
// This line is only compiled if this is templated with EtaPhiV2
LOGF(info, "We have the new data model (%f)", etaPhi.absEta());
}
}
}
};
WorkflowSpec defineDataProcessing(ConfigContext const&)
{
return WorkflowSpec{
adaptAnalysisTask<ATask>("produce-etaphi-v1"),
adaptAnalysisTask<BTask>("produce-etaphi-v2"),
adaptAnalysisTask<CTask<aod::EtaPhiV1>>("consume-etaphi-v1"), // here CTask is added with EtaPhiV1 input
adaptAnalysisTask<CTask<aod::EtaPhiV2>>("consume-etaphi-v2"), // here CTask is added with EtaPhiV2 input
};
}