Project
Loading...
Searching...
No Matches
ClusterizerSpec.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
19#include <array>
20#include <vector>
21#include <chrono>
22#include <gsl/gsl>
23#include "fmt/format.h"
27#include "Framework/Logger.h"
28#include "Framework/Output.h"
29#include "Framework/Task.h"
42
43namespace of = o2::framework;
44
45namespace o2
46{
47namespace mid
48{
49
51{
52 public:
53 ClusterizerDeviceDPL(bool isMC) : mIsMC(isMC) {}
55
57 {
58 bool isClusterizerInit = false;
59 if (mIsMC) {
60 mCorrelation.clear();
61 isClusterizerInit = mClusterizer.init([&](size_t baseIndex, size_t relatedIndex) { mCorrelation.push_back({baseIndex, relatedIndex}); });
62 } else {
63 isClusterizerInit = mClusterizer.init();
64 }
65 if (!isClusterizerInit) {
66 LOG(error) << "Initialization of MID clusterizer device failed";
67 }
68
69 auto stop = [this]() {
70 double scaleFactor = (mNROFs == 0) ? 0. : 1.e6 / mNROFs;
71 LOG(info) << "Processing time / " << mNROFs << " ROFs: full: " << mTimer.count() * scaleFactor << " us pre-clustering: " << mTimerPreCluster.count() * scaleFactor << " us clustering: " << mTimerCluster.count() * scaleFactor << " us";
72 };
73 ic.services().get<of::CallbackService>().set<of::CallbackService::Id::Stop>(stop);
74 }
75
77 {
78 auto tStart = std::chrono::high_resolution_clock::now();
79
80 gsl::span<const ColumnData> patterns = specs::getData(pc, "mid_cluster_in", EventType::Standard);
81 gsl::span<const ROFRecord> inROFRecords = specs::getRofs(pc, "mid_cluster_in", EventType::Standard);
82
83 // Pre-clustering
84 auto tAlgoStart = std::chrono::high_resolution_clock::now();
85 mPreClusterizer.process(patterns, inROFRecords);
86 mTimerPreCluster += std::chrono::high_resolution_clock::now() - tAlgoStart;
87 LOG(debug) << "Generated " << mPreClusterizer.getPreClusters().size() << " PreClusters";
88
89 // Clustering
90 tAlgoStart = std::chrono::high_resolution_clock::now();
91 mClusterizer.process(mPreClusterizer.getPreClusters(), mPreClusterizer.getROFRecords());
92 mTimerCluster += std::chrono::high_resolution_clock::now() - tAlgoStart;
93
94 if (mIsMC) {
95 // Labelling
96 auto labels = specs::getLabels(pc, "mid_cluster_in");
97 mPreClusterLabeler.process(mPreClusterizer.getPreClusters(), *labels, mPreClusterizer.getROFRecords(), inROFRecords);
98 mClusterLabeler.process(mPreClusterizer.getPreClusters(), mPreClusterLabeler.getContainer(), mClusterizer.getClusters(), mCorrelation);
99 // Clear the index correlations that will be used in the next cluster processing
100 mCorrelation.clear();
101
102 pc.outputs().snapshot(of::Output{"MID", "CLUSTERSLABELS", 0}, mClusterLabeler.getContainer());
103 LOG(debug) << "Sent " << mClusterLabeler.getContainer().getIndexedSize() << " indexed clusters";
104 }
105
106 pc.outputs().snapshot(of::Output{"MID", "CLUSTERS", 0}, mClusterizer.getClusters());
107 LOG(debug) << "Sent " << mClusterizer.getClusters().size() << " clusters";
108 pc.outputs().snapshot(of::Output{"MID", "CLUSTERSROF", 0}, mClusterizer.getROFRecords());
109 LOG(debug) << "Sent " << mClusterizer.getROFRecords().size() << " ROF";
110
111 mTimer += std::chrono::high_resolution_clock::now() - tStart;
112 mNROFs += inROFRecords.size();
113 }
114
115 private:
116 bool mIsMC = false;
117 PreClusterizer mPreClusterizer{};
118 Clusterizer mClusterizer{};
119 PreClusterLabeler mPreClusterLabeler{};
120 ClusterLabeler mClusterLabeler{};
121 std::vector<std::array<size_t, 2>> mCorrelation{};
122 std::chrono::duration<double> mTimer{0};
123 std::chrono::duration<double> mTimerPreCluster{0};
124 std::chrono::duration<double> mTimerCluster{0};
125 unsigned long mNROFs{0};
126};
127
128framework::DataProcessorSpec getClusterizerSpec(bool isMC, std::string_view inDataDesc, std::string_view inRofDesc, std::string_view inLabelsDesc)
129{
130 std::vector<of::OutputSpec> outputSpecs{of::OutputSpec{header::gDataOriginMID, "CLUSTERS"}, of::OutputSpec{header::gDataOriginMID, "CLUSTERSROF"}};
131
132 if (isMC) {
133 outputSpecs.emplace_back(of::OutputSpec{header::gDataOriginMID, "CLUSTERSLABELS"});
134 }
135 auto inputSpecs = specs::buildInputSpecs("mid_cluster_in", inDataDesc, inRofDesc, inLabelsDesc, isMC);
136
138 "MIDClusterizer",
139 {inputSpecs},
140 {outputSpecs},
141 of::AlgorithmSpec{of::adaptFromTask<o2::mid::ClusterizerDeviceDPL>(isMC)}};
142}
143} // namespace mid
144} // namespace o2
ClusterLabeler for MID.
Utilities for MID Column Data Specs.
Strip pattern (aka digits)
Reconstructed MID cluster.
Label for MID.
A helper class to iteratate over all parts of all input routes.
Definition of a container to keep Monte Carlo truth external to simulation objects.
Pre-cluster structure for MID.
Cluster reconstruction algorithm for MID.
Data processor specs for MID clustering device.
Definition of the MID event record.
PreClusterLabeler for MID.
Pre-cluster reconstruction algorithm for MID.
std::ostringstream debug
void snapshot(const Output &spec, T const &object)
ServiceRegistryRef services()
Definition InitContext.h:34
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
void process(gsl::span< const PreCluster > preClusters, const o2::dataformats::MCTruthContainer< MCCompLabel > &inMCContainer, gsl::span< const Cluster > clusters, gsl::span< const std::array< size_t, 2 > > correlations)
const o2::dataformats::MCTruthContainer< MCClusterLabel > & getContainer()
void init(o2::framework::InitContext &ic)
void run(o2::framework::ProcessingContext &pc)
const std::vector< Cluster > & getClusters()
Gets the vector of reconstructed clusters.
Definition Clusterizer.h:55
const std::vector< ROFRecord > & getROFRecords()
Gets the vector of clusters RO frame records.
Definition Clusterizer.h:58
bool init(std::function< void(size_t, size_t)> func=[](size_t, size_t) {})
void process(gsl::span< const PreCluster > preClusters, bool accumulate=false)
const o2::dataformats::MCTruthContainer< MCCompLabel > & getContainer()
void process(gsl::span< const PreCluster > preClusters, const o2::dataformats::MCTruthContainer< MCLabel > &inMCContainer, gsl::span< const ROFRecord > rofRecordsPC, gsl::span< const ROFRecord > rofRecordsData)
Pre-clustering algorithm for MID.
const std::vector< ROFRecord > & getROFRecords()
Gets the vector of pre-clusters RO frame records.
void process(gsl::span< const ColumnData > stripPatterns, bool accumulate=false)
const std::vector< PreCluster > & getPreClusters()
Gets the vector of reconstructed pre-clusters.
constexpr o2::header::DataOrigin gDataOriginMID
Definition DataHeader.h:573
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< framework::InputSpec > buildInputSpecs(std::string_view dataBind, std::string_view dataDesc, bool useMC)
std::array< gsl::span< const ColumnData >, NEvTypes > getData(framework::ProcessingContext &pc, std::string_view dataBind)
std::unique_ptr< const o2::dataformats::MCTruthContainer< MCLabel > > getLabels(framework::ProcessingContext &pc, std::string_view dataBind)
std::array< gsl::span< const ROFRecord >, NEvTypes > getRofs(framework::ProcessingContext &pc, std::string_view dataBind)
framework::DataProcessorSpec getClusterizerSpec(bool isMC, std::string_view inDataDesc, std::string_view inRofDesc, std::string_view inLabelsDesc)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"