Project
Loading...
Searching...
No Matches
ColumnDataSpecsUtils.cxx
Go to the documentation of this file.
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
16
18
21#include "Headers/DataHeader.h"
22
23namespace o2
24{
25namespace mid
26{
27namespace specs
28{
29std::string getString(std::string_view baseName, std::string_view suffix)
30{
31 return std::string(baseName) + std::string(suffix);
32}
33
34std::string getROFBind(std::string_view baseName)
35{
36 return getString(baseName, "_rof");
37}
38
39std::string getLabelsBind(std::string_view baseName)
40{
41 return getString(baseName, "_labels");
42}
43
44std::string getROFDescription(std::string_view description)
45{
46 return getString(description, "ROF");
47}
48
49std::string getLabelsDescription(std::string_view description)
50{
51 return getString(description, "LABELS");
52}
53
54std::string buildSelector(std::string_view bind, std::string_view description, int subSpec = -1)
55{
56 std::string sbind(bind.data());
57 std::string suffix;
58 if (subSpec >= 0) {
59 sbind += fmt::format("_{}", subSpec);
60 suffix += fmt::format("/{}", subSpec);
61 }
62 return fmt::format("{}:MID/{}{}", sbind, description, suffix);
63}
64
65std::string buildSelectors(std::string_view dataBind, std::string_view dataDesc, std::string_view rofDesc, std::string_view labelsDesc, bool useMC, int subSpec = -1)
66{
67 std::string selector;
68 if (!dataDesc.empty()) {
69 selector += buildSelector(dataBind, dataDesc, subSpec);
70 }
71 if (!rofDesc.empty()) {
72 if (!selector.empty()) {
73 selector += ";";
74 }
75 selector += buildSelector(getROFBind(dataBind), rofDesc, subSpec);
76 }
77 if (useMC && !labelsDesc.empty()) {
78 if (!selector.empty()) {
79 selector += ";";
80 }
81 selector += buildSelector(getLabelsBind(dataBind), labelsDesc, subSpec);
82 }
83 return selector;
84}
85
86std::vector<framework::InputSpec> buildInputSpecs(std::string_view dataBind, std::string_view dataDesc, std::string_view rofDesc)
87{
88 std::string selector;
89 for (size_t ievt = 0; ievt < NEvTypes; ++ievt) {
90 if (!selector.empty()) {
91 selector += ";";
92 }
93 selector += buildSelectors(dataBind, dataDesc, rofDesc, "", false, ievt);
94 }
95 return framework::select(selector.c_str());
96}
97
98std::vector<framework::InputSpec> buildStandardInputSpecs(std::string_view dataBind, std::string_view dataDesc, bool useMC)
99{
100 return buildStandardInputSpecs(dataBind, dataDesc, getROFDescription(dataDesc), getLabelsDescription(dataDesc), useMC);
101}
102
103std::vector<framework::InputSpec> buildStandardInputSpecs(std::string_view dataBind, std::string_view dataDesc, std::string_view rofDesc, std::string_view labelsDesc, bool useMC)
104{
105 std::string selector = buildSelectors(dataBind, dataDesc, rofDesc, labelsDesc, useMC, 0);
106 return framework::select(selector.c_str());
107}
108
109std::vector<framework::OutputSpec> buildOutputSpecs(std::string_view bind, std::string_view description)
110{
111 std::string selector;
112 for (size_t ievt = 0; ievt < NEvTypes; ++ievt) {
113 if (!selector.empty()) {
114 selector += ";";
115 }
116 selector += buildSelector(bind, description, ievt);
117 }
118 auto matchers = framework::select(selector.c_str());
119 std::vector<framework::OutputSpec> outputSpecs;
120 for (auto& matcher : matchers) {
121 outputSpecs.emplace_back(framework::DataSpecUtils::asOutputSpec(matcher));
122 }
123 return outputSpecs;
124}
125
126std::vector<framework::OutputSpec> buildStandardOutputSpecs(std::string_view dataBind, std::string_view dataDesc, bool useMC)
127{
128 auto selector = buildSelectors(dataBind, dataDesc, getROFDescription(dataDesc), getLabelsDescription(dataDesc), useMC, 0);
129 auto matchers = framework::select(selector.data());
130 std::vector<framework::OutputSpec> outputSpecs;
131 for (auto& matcher : matchers) {
132 outputSpecs.emplace_back(framework::DataSpecUtils::asOutputSpec(matcher));
133 }
134 return outputSpecs;
135}
136
137std::vector<framework::Output> buildOutputs(std::vector<framework::OutputSpec> outputSpecs)
138{
139 std::vector<framework::Output> outputs;
140 for (auto& outSpec : outputSpecs) {
142 outputs.emplace_back(framework::Output{matcher.origin, matcher.description, matcher.subSpec});
143 }
144 return outputs;
145}
146
147std::array<gsl::span<const ColumnData>, NEvTypes> getData(framework::ProcessingContext& pc, std::string_view dataBind)
148{
149 std::array<gsl::span<const ColumnData>, 3> data;
150 for (size_t ievt = 0; ievt < NEvTypes; ++ievt) {
151 data[ievt] = getInput<ColumnData>(pc, dataBind, ievt);
152 }
153
154 return data;
155}
156
157gsl::span<const ColumnData> getData(framework::ProcessingContext& pc, std::string_view dataBind, EventType eventType)
158{
159 return getInput<ColumnData>(pc, dataBind.data(), static_cast<int>(eventType));
160}
161
162std::array<gsl::span<const ROFRecord>, NEvTypes> getRofs(framework::ProcessingContext& pc, std::string_view dataBind)
163{
164 std::array<gsl::span<const ROFRecord>, 3> data;
165 for (size_t ievt = 0; ievt < NEvTypes; ++ievt) {
166 data[ievt] = getInput<ROFRecord>(pc, getROFBind(dataBind).data(), ievt);
167 }
168
169 return data;
170}
171
172gsl::span<const ROFRecord> getRofs(framework::ProcessingContext& pc, std::string_view dataBind, EventType eventType)
173{
174 return getInput<ROFRecord>(pc, getROFBind(dataBind).data(), static_cast<int>(eventType));
175}
176
177std::unique_ptr<const o2::dataformats::MCTruthContainer<MCLabel>> getLabels(framework::ProcessingContext& pc, std::string_view dataBind, EventType eventType)
178{
179 return pc.inputs().get<const o2::dataformats::MCTruthContainer<MCLabel>*>(fmt::format("{}_{}", getLabelsBind(dataBind).data(), static_cast<size_t>(eventType)));
180}
181
182} // namespace specs
183} // namespace mid
184} // namespace o2
std::vector< framework::ConcreteDataMatcher > matchers
header::DataDescription description
Utilities for MID Column Data Specs.
const auto & getData()
A container to hold and manage MC truth information/labels.
decltype(auto) get(R binding, int part=0) const
InputRecord & inputs()
The inputs associated with this processing context.
GLboolean * data
Definition glcorearb.h:298
std::vector< InputSpec > select(char const *matcher="")
std::vector< framework::InputSpec > buildStandardInputSpecs(std::string_view dataBind, std::string_view dataDesc, bool useMC)
std::string getROFDescription(std::string_view description)
std::string getLabelsBind(std::string_view baseName)
std::string getLabelsDescription(std::string_view description)
std::string getString(std::string_view baseName, std::string_view suffix)
std::unique_ptr< const o2::dataformats::MCTruthContainer< MCLabel > > getLabels(framework::ProcessingContext &pc, std::string_view dataBind, EventType eventType=EventType::Standard)
std::vector< framework::OutputSpec > buildStandardOutputSpecs(std::string_view dataBind, std::string_view dataDesc, bool useMC)
std::vector< framework::Output > buildOutputs(std::vector< framework::OutputSpec > outputSpecs)
std::string buildSelectors(std::string_view dataBind, std::string_view dataDesc, std::string_view rofDesc, std::string_view labelsDesc, bool useMC, int subSpec=-1)
std::vector< framework::InputSpec > buildInputSpecs(std::string_view dataBind, std::string_view dataDesc, std::string_view rofDesc)
std::vector< framework::OutputSpec > buildOutputSpecs(std::string_view bind, std::string_view description)
std::string getROFBind(std::string_view baseName)
std::string buildSelector(std::string_view bind, std::string_view description, int subSpec=-1)
std::array< gsl::span< const ROFRecord >, NEvTypes > getRofs(framework::ProcessingContext &pc, std::string_view dataBind)
constexpr uint32_t NEvTypes
Definition ROFRecord.h:37
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
header::DataHeader::SubSpecificationType subSpec
static ConcreteDataMatcher asConcreteDataMatcher(InputSpec const &input)
static OutputSpec asOutputSpec(InputSpec const &spec)