Project
Loading...
Searching...
No Matches
ClusterWriterSpec.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 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
13
14#include <algorithm>
15#include <cctype>
16#include <memory>
17#include <vector>
18#include <format>
19
28
29using namespace o2::framework;
30
31namespace o2::itsmft
32{
33
34template <typename T>
36using CompClusType = std::vector<o2::itsmft::CompClusterExt>;
37using PatternsType = std::vector<unsigned char>;
38using ROFrameRType = std::vector<o2::itsmft::ROFRecord>;
40using ROFRecLblT = std::vector<o2::itsmft::MC2ROFRecord>;
41using namespace o2::header;
42
43template <int N>
44DataProcessorSpec getClusterWriterSpec(bool useMC, bool doStag, bool clusterROFOnly)
45{
47 const int nLayers = (doStag) ? DPLAlpideParam<N>::getNLayers() : 1;
48 const auto detName = Origin.as<std::string>();
49 // Spectators for logging
50 auto compClusterSizes = std::make_shared<std::vector<size_t>>(nLayers, 0);
51 auto compClustersSizeGetter = [compClusterSizes](CompClusType const& compClusters, DataRef const& ref) {
52 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
53 (*compClusterSizes)[dh->subSpecification] = compClusters.size();
54 };
55 auto logger = [detName, compClusterSizes, doStag](std::vector<o2::itsmft::ROFRecord> const& rofs, DataRef const& ref) {
56 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
57 const auto i = dh->subSpecification;
58 LOG(info) << detName << "ClusterWriter" << ((doStag) ? std::format(" on layer {}", i) : "")
59 << " pulled " << (*compClusterSizes)[i] << " clusters, in " << rofs.size() << " RO frames";
60 };
61 auto getIndex = [](DataRef const& ref) -> size_t {
62 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
63 return static_cast<size_t>(dh->subSpecification);
64 };
65 auto getName = [doStag](std::string base, size_t index) -> std::string {
66 if (doStag) {
67 return base += "_" + std::to_string(index);
68 }
69 return base;
70 };
71 auto detNameLC = detName;
72 std::transform(detNameLC.begin(), detNameLC.end(), detNameLC.begin(), [](unsigned char c) { return std::tolower(c); });
73 std::vector<InputSpec> vecInpSpecClus, vecInpSpecPatt, vecInpSpecROF, vecInpSpecLbl;
74 vecInpSpecClus.reserve(nLayers);
75 vecInpSpecPatt.reserve(nLayers);
76 vecInpSpecROF.reserve(nLayers);
77 vecInpSpecLbl.reserve(nLayers);
78 for (int iLayer = 0; iLayer < nLayers; iLayer++) {
79 vecInpSpecClus.emplace_back(getName("compclus", iLayer), Origin, "COMPCLUSTERS", iLayer);
80 vecInpSpecPatt.emplace_back(getName("patterns", iLayer), Origin, "PATTERNS", iLayer);
81 vecInpSpecROF.emplace_back(getName("ROframes", iLayer), Origin, "CLUSTERSROF", iLayer);
82 vecInpSpecLbl.emplace_back(getName("labels", iLayer), Origin, "CLUSTERSMCTR", iLayer);
83 }
84
85 if (clusterROFOnly) {
86 return MakeRootTreeWriterSpec(std::format("{}-cluster-writer", detNameLC).c_str(),
87 (o2::detectors::DetID::ITS == N) ? "o2clus_its.root" : "mftclusters.root",
88 MakeRootTreeWriterSpec::TreeAttributes{.name = "o2sim", .title = std::format("Tree with {} cluster ROFs only", detName)},
90 (detName + "ClustersROF").c_str(), "cluster-rof-branch",
91 nLayers,
92 logger,
93 getIndex,
94 getName})();
95 }
96
97 return MakeRootTreeWriterSpec(std::format("{}-cluster-writer", detNameLC).c_str(),
98 (o2::detectors::DetID::ITS == N) ? "o2clus_its.root" : "mftclusters.root",
99 MakeRootTreeWriterSpec::TreeAttributes{.name = "o2sim", .title = std::format("Tree with {} clusters", detName)},
100 BranchDefinition<CompClusType>{vecInpSpecClus,
101 (detName + "ClusterComp").c_str(), "compact-cluster-branch",
102 nLayers,
103 compClustersSizeGetter,
104 getIndex,
105 getName},
106 BranchDefinition<PatternsType>{vecInpSpecPatt,
107 (detName + "ClusterPatt").c_str(), "cluster-pattern-branch",
108 nLayers,
109 getIndex,
110 getName},
111 BranchDefinition<ROFrameRType>{vecInpSpecROF,
112 (detName + "ClustersROF").c_str(), "cluster-rof-branch",
113 nLayers,
114 logger,
115 getIndex,
116 getName},
117 BranchDefinition<LabelsType>{vecInpSpecLbl,
118 (detName + "ClusterMCTruth").c_str(), "cluster-label-branch",
119 (useMC ? nLayers : 0),
120 getIndex,
121 getName},
122 BranchDefinition<ROFRecLblT>{InputSpec{"MC2ROframes", ConcreteDataTypeMatcher{Origin, "CLUSTERSMC2ROF"}},
123 (detName + "ClustersMC2ROF").c_str(), "cluster-mc2rof-branch",
124 (useMC ? nLayers : 0),
125 getIndex,
126 getName})();
127}
128
129framework::DataProcessorSpec getITSClusterWriterSpec(bool useMC, bool doStag, bool clusterROFOnly) { return getClusterWriterSpec<o2::detectors::DetID::ITS>(useMC, doStag, clusterROFOnly); }
130framework::DataProcessorSpec getMFTClusterWriterSpec(bool useMC, bool doStag, bool clusterROFOnly) { return getClusterWriterSpec<o2::detectors::DetID::MFT>(useMC, doStag, clusterROFOnly); }
131
132} // namespace o2::itsmft
Definition of the ITSMFT compact cluster.
std::string getName(const TDataMember *dm, int index, int size)
int32_t i
Definition of the ITSMFT ROFrame (trigger) record.
Definition of a container to keep Monte Carlo truth external to simulation objects.
Configurable generator for RootTreeWriter processor spec.
uint32_t c
Definition RawData.h:2
static constexpr ID ITS
Definition DetID.h:63
Generate a processor spec for the RootTreeWriter utility.
GLuint index
Definition glcorearb.h:781
GLint ref
Definition glcorearb.h:291
constexpr o2::header::DataOrigin gDataOriginMFT
Definition DataHeader.h:572
constexpr o2::header::DataOrigin gDataOriginITS
Definition DataHeader.h:570
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
O2 data header classes and API, v0.1.
Definition DetID.h:49
std::vector< o2::itsmft::ROFRecord > ROFrameRType
std::vector< o2::itsmft::MC2ROFRecord > ROFRecLblT
std::vector< unsigned char > PatternsType
framework::DataProcessorSpec getClusterWriterSpec(bool useMC, bool doStag, bool clusterROFOnly=false)
std::vector< o2::itsmft::CompClusterExt > CompClusType
framework::DataProcessorSpec getITSClusterWriterSpec(bool useMC, bool doStag, bool clusterROFOnly=false)
framework::DataProcessorSpec getMFTClusterWriterSpec(bool useMC, bool doStag, bool clusterROFOnly=false)
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"