|
| 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 | +/// \file MIDWorkflow/ColumnDataSpecsUtils.h |
| 13 | +/// \brief Utilities for MID Column Data Specs |
| 14 | +/// \author Diego Stocco <Diego.Stocco at cern.ch> |
| 15 | +/// \date 05 April 2022 |
| 16 | + |
| 17 | +#ifndef O2_MID_COLUMNDATASPECSUTILS_H |
| 18 | +#define O2_MID_COLUMNDATASPECSUTILS_H |
| 19 | + |
| 20 | +#include <array> |
| 21 | +#include <memory> |
| 22 | +#include <string> |
| 23 | +#include <string_view> |
| 24 | +#include <vector> |
| 25 | +#include <gsl/span> |
| 26 | +#include "fmt/format.h" |
| 27 | + |
| 28 | +#include "Framework/DataAllocator.h" |
| 29 | +#include "Framework/InputRecordWalker.h" |
| 30 | +#include "Framework/InputSpec.h" |
| 31 | +#include "Framework/OutputSpec.h" |
| 32 | +#include "Framework/ProcessingContext.h" |
| 33 | +#include "SimulationDataFormat/MCTruthContainer.h" |
| 34 | +#include "DataFormatsMID/ColumnData.h" |
| 35 | +#include "DataFormatsMID/ROFRecord.h" |
| 36 | +#include "MIDSimulation/MCLabel.h" |
| 37 | + |
| 38 | +namespace o2 |
| 39 | +{ |
| 40 | +namespace mid |
| 41 | +{ |
| 42 | +namespace specs |
| 43 | +{ |
| 44 | + |
| 45 | +/// Returns the input specs for MID Column Data and corresponding ROFs and labels |
| 46 | +/// \param dataBind Data binding name |
| 47 | +/// \param dataDesc Input data description |
| 48 | +/// \param useMC Builds output specs for labels |
| 49 | +/// \return Vector of input specs |
| 50 | +std::vector<framework::InputSpec> buildInputSpecs(std::string_view dataBind, std::string_view dataDesc, bool useMC); |
| 51 | + |
| 52 | +/// Returns the input specs for MID Column Data and corresponding ROFs and labels |
| 53 | +/// \param dataBind Data binding name |
| 54 | +/// \param dataDesc Input data description |
| 55 | +/// \param rofDesc Input ROF record description |
| 56 | +/// \param labelsDesc Input MC labels description |
| 57 | +/// \param useMC Builds output specs for labels |
| 58 | +/// \return Vector of input specs |
| 59 | +std::vector<framework::InputSpec> buildInputSpecs(std::string_view dataBind, std::string_view dataDesc, std::string_view rofDesc, std::string_view labelsDesc, bool useMC); |
| 60 | + |
| 61 | +/// Returns the output specs for the different event types |
| 62 | +/// \param bind Binding name |
| 63 | +/// \param description Output data description |
| 64 | +/// \return Vector of Output specs |
| 65 | +std::vector<framework::OutputSpec> buildOutputSpecs(std::string_view bind, std::string_view description); |
| 66 | + |
| 67 | +/// Returns the output specs for MID Column Data and corresponding ROFs and labels |
| 68 | +/// \param dataBind Data binding name |
| 69 | +/// \param dataDesc Output data description |
| 70 | +/// \param useMC Builds output specs for labels |
| 71 | +/// \return Vector of Output specs |
| 72 | +std::vector<framework::OutputSpec> buildStandardOutputSpecs(std::string_view dataBind, std::string_view dataDesc, bool useMC); |
| 73 | + |
| 74 | +/// Returns the inputs for the different event types |
| 75 | +/// \param pc Processing context |
| 76 | +/// \param bind Binding name |
| 77 | +/// \return Array of spans |
| 78 | +template <typename T> |
| 79 | +std::array<gsl::span<const T>, NEvTypes> getInput(framework::ProcessingContext& pc, std::string_view bind) |
| 80 | +{ |
| 81 | + std::array<gsl::span<const T>, 3> data; |
| 82 | + for (auto const& inputRef : framework::InputRecordWalker(pc.inputs())) { |
| 83 | + auto const* dh = framework::DataRefUtils::getHeader<o2::header::DataHeader*>(inputRef); |
| 84 | + auto subSpecIdx = static_cast<size_t>(dh->subSpecification); |
| 85 | + if (framework::DataRefUtils::match(inputRef, bind.data())) { |
| 86 | + data[subSpecIdx] = pc.inputs().get<gsl::span<T>>(inputRef); |
| 87 | + } |
| 88 | + } |
| 89 | + return data; |
| 90 | +} |
| 91 | + |
| 92 | +/// Gets the outputs |
| 93 | +/// \param outputSpecs Vector of output specs |
| 94 | +/// \return vector of outputs |
| 95 | +std::vector<framework::Output> buildOutputs(std::vector<framework::OutputSpec> outputSpecs); |
| 96 | + |
| 97 | +/// Returns the array of Column Data |
| 98 | +/// \param pc Processing context |
| 99 | +/// \param dataBind Data binding name |
| 100 | +/// \return Array of Column Data spans |
| 101 | +std::array<gsl::span<const ColumnData>, NEvTypes> getData(framework::ProcessingContext& pc, std::string_view dataBind); |
| 102 | + |
| 103 | +/// Returns the Column Data for the specified event type |
| 104 | +/// \param pc Processing context |
| 105 | +/// \param dataBind Data binding name |
| 106 | +/// \param eventType Event type |
| 107 | +/// \return Span of ColumnData |
| 108 | +gsl::span<const ColumnData> getData(framework::ProcessingContext& pc, std::string_view dataBind, EventType eventType); |
| 109 | + |
| 110 | +/// Returns the array of ROF records |
| 111 | +/// \param pc Processing context |
| 112 | +/// \param dataBind Data binding name |
| 113 | +/// \return Array of ROF Records spans |
| 114 | +std::array<gsl::span<const ROFRecord>, NEvTypes> getRofs(framework::ProcessingContext& pc, std::string_view dataBind); |
| 115 | + |
| 116 | +/// Returns the ROF records for the specified event type |
| 117 | +/// \param pc Processing context |
| 118 | +/// \param dataBind Data binding name |
| 119 | +/// \param eventType Event type |
| 120 | +/// \return Span of ROF records |
| 121 | +gsl::span<const ROFRecord> getRofs(framework::ProcessingContext& pc, std::string_view dataBind, EventType eventType); |
| 122 | + |
| 123 | +/// Returns the MC labels |
| 124 | +/// \param pc Processing context |
| 125 | +/// \param dataBind Data binding name |
| 126 | +/// \return Pointer to MC labels |
| 127 | +std::unique_ptr<const o2::dataformats::MCTruthContainer<MCLabel>> getLabels(framework::ProcessingContext& pc, std::string_view dataBind); |
| 128 | + |
| 129 | +} // namespace specs |
| 130 | +} // namespace mid |
| 131 | +} // namespace o2 |
| 132 | + |
| 133 | +#endif // O2_MID_COLUMNDATASPECSUTILS_H |
0 commit comments