Project
Loading...
Searching...
No Matches
ClusterWriterSpec.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
13
14#include <algorithm>
15#include <cctype>
16#include <memory>
17#include <vector>
18#include <format>
19
22#include "Framework/DataRef.h"
23#include "TRKBase/AlmiraParam.h"
29
30using namespace o2::framework;
31
32namespace o2::trk
33{
34
35template <typename T>
37using ClustersType = std::vector<o2::trk::Cluster>;
38using PatternsType = std::vector<unsigned char>;
39using ROFrameType = std::vector<o2::trk::ROFRecord>;
41using ROFRecLblType = std::vector<o2::trk::MC2ROFRecord>;
42
44{
46 static constexpr int nLayers = o2::trk::AlmiraParam::kNLayers;
47 const auto detName = Origin.as<std::string>();
48
49 auto compClusterSizes = std::make_shared<std::vector<size_t>>(nLayers, 0);
50 auto compClustersSizeGetter = [compClusterSizes](ClustersType const& compClusters, DataRef const& ref) {
51 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
52 (*compClusterSizes)[dh->subSpecification] = compClusters.size();
53 };
54 auto logger = [detName, compClusterSizes](ROFrameType const& rofs, DataRef const& ref) {
55 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
56 const auto i = dh->subSpecification;
57 LOG(info) << detName << "ClusterWriter on layer " << i
58 << " pulled " << (*compClusterSizes)[i] << " clusters, in " << rofs.size() << " RO frames";
59 };
60 auto getIndex = [](DataRef const& ref) -> size_t {
61 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
62 return static_cast<size_t>(dh->subSpecification);
63 };
64 auto getName = [](std::string base, size_t index) -> std::string {
65 return base + "_" + std::to_string(index);
66 };
67 auto detNameLC = detName;
68 std::transform(detNameLC.begin(), detNameLC.end(), detNameLC.begin(), [](unsigned char c) { return std::tolower(c); });
69
70 std::vector<InputSpec> vecInpSpecClus, vecInpSpecPatt, vecInpSpecROF, vecInpSpecLbl;
71 vecInpSpecClus.reserve(nLayers);
72 vecInpSpecPatt.reserve(nLayers);
73 vecInpSpecROF.reserve(nLayers);
74 vecInpSpecLbl.reserve(nLayers);
75 for (int iLayer = 0; iLayer < nLayers; iLayer++) {
76 vecInpSpecClus.emplace_back(getName("compclus", iLayer), Origin, "COMPCLUSTERS", iLayer);
77 vecInpSpecPatt.emplace_back(getName("patterns", iLayer), Origin, "PATTERNS", iLayer);
78 vecInpSpecROF.emplace_back(getName("ROframes", iLayer), Origin, "CLUSTERSROF", iLayer);
79 vecInpSpecLbl.emplace_back(getName("labels", iLayer), Origin, "CLUSTERSMCTR", iLayer);
80 }
81
82 return MakeRootTreeWriterSpec(std::format("{}-cluster-writer", detNameLC).c_str(),
83 "o2clus_trk.root",
84 MakeRootTreeWriterSpec::TreeAttributes{.name = "o2sim", .title = "Tree with TRK clusters"},
85 BranchDefinition<ClustersType>{vecInpSpecClus,
86 "TRKClusterComp", "compact-cluster-branch",
87 nLayers,
88 compClustersSizeGetter,
89 getIndex,
90 getName},
91 BranchDefinition<PatternsType>{vecInpSpecPatt,
92 "TRKClusterPatt", "cluster-pattern-branch",
93 nLayers,
94 getIndex,
95 getName},
97 "TRKClustersROF", "cluster-rof-branch",
98 nLayers,
99 logger,
100 getIndex,
101 getName},
102 BranchDefinition<LabelsType>{vecInpSpecLbl,
103 "TRKClusterMCTruth", "cluster-label-branch",
104 (useMC ? nLayers : 0),
105 getIndex,
106 getName})();
107}
108
109} // namespace o2::trk
std::string getName(const TDataMember *dm, int index, int size)
int32_t i
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
A container to hold and manage MC truth information/labels.
Generate a processor spec for the RootTreeWriter utility.
GLuint index
Definition glcorearb.h:781
GLint ref
Definition glcorearb.h:291
constexpr o2::header::DataOrigin gDataOriginTRK
Definition DataHeader.h:584
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< o2::trk::Cluster > ClustersType
framework::DataProcessorSpec getClusterWriterSpec(bool useMC)
std::vector< o2::trk::ROFRecord > ROFrameType
std::vector< o2::MCCompLabel > LabelsType
std::vector< o2::trk::MC2ROFRecord > ROFRecLblType
std::vector< unsigned char > PatternsType
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
static constexpr size_t kNLayers
Definition AlmiraParam.h:28
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"