Project
Loading...
Searching...
No Matches
GPUWorkflowHelper.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
15#include "ITStracking/IOUtils.h"
18#include <type_traits>
19
20using namespace o2::globaltracking;
21using namespace o2::gpu;
22
24 std::vector<o2::BaseCluster<float>> ITSClustersArray;
25 std::vector<int32_t> tpcLinkITS, tpcLinkTRD, tpcLinkTOF;
26 std::vector<const o2::track::TrackParCov*> globalTracks;
27 std::vector<float> globalTrackTimes;
28};
29
31{
32 auto retVal = std::make_shared<tmpDataContainer>();
33
34 if (maskCl[GID::ITS] && ioPtr.nItsClusters == 0) {
35 const auto& ITSClusterROFRec = recoCont.getITSClustersROFRecords();
36 const auto& clusITS = recoCont.getITSClusters();
37 if (clusITS.size() && ITSClusterROFRec.size()) {
38 if (calib && calib->itsPatternDict) {
39 const auto& patterns = recoCont.getITSClustersPatterns();
40 auto pattIt = patterns.begin();
41 retVal->ITSClustersArray.reserve(clusITS.size());
42 o2::its::ioutils::convertCompactClusters(clusITS, pattIt, retVal->ITSClustersArray, calib->itsPatternDict);
43 ioPtr.itsClusters = retVal->ITSClustersArray.data();
44 }
45 ioPtr.nItsClusters = clusITS.size();
46 ioPtr.itsCompClusters = clusITS.data();
47 ioPtr.nItsClusterROF = ITSClusterROFRec.size();
48 ioPtr.itsClusterROF = ITSClusterROFRec.data();
49 if (useMC) {
50 const auto& ITSClsLabels = recoCont.mcITSClusters.get();
51 ioPtr.itsClusterMC = ITSClsLabels;
52 }
53 }
54 //LOG(info) << "Got " << ioPtr.nItsClusters << " ITS Clusters";
55 }
56 if (maskTrk[GID::ITS] && ioPtr.nItsTracks == 0) {
57 const auto& ITSTracksArray = recoCont.getITSTracks();
58 const auto& ITSTrackROFRec = recoCont.getITSTracksROFRecords();
59 if (ITSTracksArray.size() && ITSTrackROFRec.size()) {
60 const auto& ITSTrackClusIdx = recoCont.getITSTracksClusterRefs();
61 ioPtr.nItsTracks = ITSTracksArray.size();
62 ioPtr.itsTracks = ITSTracksArray.data();
63 ioPtr.itsTrackClusIdx = ITSTrackClusIdx.data();
64 ioPtr.nItsTrackROF = ITSTrackROFRec.size();
65 ioPtr.itsTrackROF = ITSTrackROFRec.data();
66 if (useMC) {
67 const auto& ITSTrkLabels = recoCont.getITSTracksMCLabels();
68 ioPtr.itsTrackMC = ITSTrkLabels.data();
69 }
70 }
71 //LOG(info) << "Got " << ioPtr.nItsTracks << " ITS Tracks";
72 }
73
74 if (maskTrk[GID::ITSTPC] && ioPtr.nTracksTPCITSO2 == 0) {
75 const auto& trkITSTPC = recoCont.getTPCITSTracks();
76 if (trkITSTPC.size()) {
77 ioPtr.nTracksTPCITSO2 = trkITSTPC.size();
78 ioPtr.tracksTPCITSO2 = trkITSTPC.data();
79 }
80 //LOG(info) << "Got " << ioPtr.nTracksTPCITSO2 << " ITS-TPC Tracks";
81 }
82
83 if (maskCl[GID::TOF] && ioPtr.nTOFClusters == 0) {
84 const auto& tofClusters = recoCont.getTOFClusters();
85 if (tofClusters.size()) {
86 ioPtr.nTOFClusters = tofClusters.size();
87 ioPtr.tofClusters = tofClusters.data();
88 }
89 //LOG(info) << "Got " << ioPtr.nTOFClusters << " TOF Clusters";
90 }
91
92 if ((maskMatch[GID::TOF] || maskMatch[GID::ITSTPCTOF]) && ioPtr.nITSTPCTOFMatches == 0) {
93 const auto& itstpctofMatches = recoCont.getITSTPCTOFMatches();
94 if (itstpctofMatches.size()) {
95 ioPtr.nITSTPCTOFMatches = itstpctofMatches.size();
96 ioPtr.itstpctofMatches = itstpctofMatches.data();
97 }
98 //LOG(info) << "Got " << ioPtr.nITSTPCTOFMatches << " ITS-TPC-TOF Matches";
99 }
100
101 if ((maskMatch[GID::TOF] || maskMatch[GID::ITSTPCTRDTOF]) && ioPtr.nITSTPCTRDTOFMatches == 0) {
102 const auto& itstpctrdtofMatches = recoCont.getITSTPCTRDTOFMatches();
103 if (itstpctrdtofMatches.size()) {
104 ioPtr.nITSTPCTRDTOFMatches = itstpctrdtofMatches.size();
105 ioPtr.itstpctrdtofMatches = itstpctrdtofMatches.data();
106 }
107 //LOG(info) << "Got " << ioPtr.nITSTPCTRDTOFMatches << " ITS-TPC-TRD-TOF Matches";
108 }
109
110 if ((maskMatch[GID::TOF] || maskMatch[GID::TPCTOF]) && ioPtr.nTPCTOFMatches == 0) {
111 const auto& tpctofMatches = recoCont.getTPCTOFMatches();
112 if (tpctofMatches.size()) {
113 ioPtr.nTPCTOFMatches = tpctofMatches.size();
114 ioPtr.tpctofMatches = tpctofMatches.data();
115 }
116 //LOG(info) << "Got " << ioPtr.nTPCTOFMatches << " TPC-TOF Matches";
117 }
118
119 if ((maskMatch[GID::TOF] || maskMatch[GID::TPCTRDTOF]) && ioPtr.nTPCTRDTOFMatches == 0) {
120 const auto& tpctrdtofMatches = recoCont.getTPCTRDTOFMatches();
121 if (tpctrdtofMatches.size()) {
122 ioPtr.nTPCTRDTOFMatches = tpctrdtofMatches.size();
123 ioPtr.tpctrdtofMatches = tpctrdtofMatches.data();
124 }
125 //LOG(info) << "Got " << ioPtr.nTPCTOFMatches << " TPC-TOF Matches";
126 }
127
128 if (maskCl[GID::TRD]) {
129 recoCont.inputsTRD->fillGPUIOPtr(&ioPtr);
130 //LOG(info) << "Got " << ioPtr.nTRDTracklets << " TRD Tracklets";
131 }
132
133 if (maskTrk[GID::ITSTPCTRD] && ioPtr.nTRDTracksITSTPCTRD == 0) {
134 const auto& trdTracks = recoCont.getITSTPCTRDTracks<o2::trd::TrackTRD>();
135 if (trdTracks.size()) {
136 ioPtr.nTRDTracksITSTPCTRD = trdTracks.size();
137 ioPtr.trdTracksITSTPCTRD = trdTracks.data();
138 }
139 //LOG(info) << "Got " << ioPtr.nTRDTracksITSTPCTRD << " ITS-TPC-TRD Tracks";
140 }
141
142 if (maskTrk[GID::TPCTRD] && ioPtr.nTRDTracksTPCTRD == 0) {
143 const auto& trdTracks = recoCont.getTPCTRDTracks<o2::trd::TrackTRD>();
144 if (trdTracks.size()) {
145 ioPtr.nTRDTracksTPCTRD = trdTracks.size();
146 ioPtr.trdTracksTPCTRD = trdTracks.data();
147 }
148 //LOG(info) << "Got " << ioPtr.nTRDTracksTPCTRD << " TPC-TRD Tracks";
149 }
150
151 if (maskCl[GID::TPC] && ioPtr.clustersNative == nullptr) {
152 ioPtr.clustersNative = &recoCont.getTPCClusters();
153 //LOG(info) << "Got " << ioPtr.clustersNative->nClustersTotal << " TPC Clusters";
154 }
155
156 if (maskTrk[GID::TPC] && ioPtr.nOutputTracksTPCO2 == 0) {
157 const auto& tpcTracks = recoCont.getTPCTracks();
158 const auto& tpcClusRefs = recoCont.getTPCTracksClusterRefs();
159 ioPtr.outputTracksTPCO2 = tpcTracks.data();
160 ioPtr.nOutputTracksTPCO2 = tpcTracks.size();
161 ioPtr.outputClusRefsTPCO2 = tpcClusRefs.data();
162 ioPtr.nOutputClusRefsTPCO2 = tpcClusRefs.size();
163 if (useMC) {
164 const auto& tpcTracksMC = recoCont.getTPCTracksMCLabels();
165 ioPtr.outputTracksTPCO2MC = tpcTracksMC.data();
166 }
167 if (ioPtr.nTracksTPCITSO2) {
168 retVal->tpcLinkITS.resize(ioPtr.nOutputTracksTPCO2, -1);
169 ioPtr.tpcLinkITS = retVal->tpcLinkITS.data();
170 }
171 if (ioPtr.nITSTPCTOFMatches || ioPtr.nTPCTRDTOFMatches || ioPtr.nITSTPCTRDTOFMatches || ioPtr.nTPCTOFMatches) {
172 retVal->tpcLinkTOF.resize(ioPtr.nOutputTracksTPCO2, -1);
173 ioPtr.tpcLinkTOF = retVal->tpcLinkTOF.data();
174 }
175 if (ioPtr.nTRDTracksITSTPCTRD || ioPtr.nTRDTracksTPCTRD) {
176 retVal->tpcLinkTRD.resize(ioPtr.nOutputTracksTPCO2, -1);
177 ioPtr.tpcLinkTRD = retVal->tpcLinkTRD.data();
178 }
179 //LOG(info) << "Got " << ioPtr.nOutputTracksTPCO2 << " TPC Tracks";
180 }
181
182 auto creator = [maskTrk, &ioPtr, &recoCont, &retVal](auto& trk, GID gid, float time, float) {
183 if (gid.getSource() == GID::ITSTPCTOF) {
184 if (maskTrk[GID::TPC] && ioPtr.nTracksTPCITSO2) {
185 const auto& match = recoCont.getTOFMatch(gid);
186 const auto& trkItsTPC = ioPtr.tracksTPCITSO2[match.getTrackIndex()];
187 if (retVal->tpcLinkTOF.size()) {
188 retVal->tpcLinkTOF[trkItsTPC.getRefTPC().getIndex()] = match.getTOFClIndex();
189 }
190 if (retVal->tpcLinkITS.size()) {
191 retVal->tpcLinkITS[trkItsTPC.getRefTPC().getIndex()] = trkItsTPC.getRefITS().getIndex();
192 }
193 }
194 } else if constexpr (isTPCTrack<decltype(trk)>()) {
195 time = trk.getTime0();
196 } else if constexpr (isTPCITSTrack<decltype(trk)>()) {
197 if (maskTrk[GID::TPC] && retVal->tpcLinkITS.size()) {
198 retVal->tpcLinkITS[trk.getRefTPC().getIndex()] = trk.getRefITS().getIndex();
199 }
200 } else if constexpr (isTPCTOFTrack<decltype(trk)>()) {
201 if (maskTrk[GID::TPC] && ioPtr.nTPCTOFMatches && retVal->tpcLinkTOF.size()) {
202 const auto& match = ioPtr.tpctofMatches[trk.getRefMatch()];
203 retVal->tpcLinkTOF[match.getTrackIndex()] = match.getTOFClIndex();
204 }
205 }
206 if constexpr (std::is_base_of_v<o2::track::TrackParCov, std::decay_t<decltype(trk)>>) {
207 retVal->globalTracks.emplace_back(&trk);
208 retVal->globalTrackTimes.emplace_back(time);
209 return true;
210 } else {
211 return false;
212 }
213 };
214 recoCont.createTracksVariadic(creator);
215 if (maskTrk[GID::TPC] && retVal->tpcLinkTRD.size()) {
216 for (uint32_t i = 0; i < ioPtr.nTRDTracksTPCTRD; i++) { // TODO: This should be handled by the createTracks logic, but so far it lacks the TRD tracks
217 retVal->tpcLinkTRD[ioPtr.trdTracksTPCTRD[i].getRefGlobalTrackId().getIndex()] = i;
218 }
219 if (ioPtr.nTracksTPCITSO2) {
220 for (uint32_t i = 0; i < ioPtr.nTRDTracksITSTPCTRD; i++) {
221 retVal->tpcLinkTRD[ioPtr.tracksTPCITSO2[ioPtr.trdTracksITSTPCTRD[i].getRefGlobalTrackId().getIndex()].getRefTPC().getIndex()] = i | 0x40000000;
222 }
223 }
224 }
225 ioPtr.globalTracks = retVal->globalTracks.data();
226 ioPtr.globalTrackTimes = retVal->globalTrackTimes.data();
227
228 return retVal;
229}
int16_t time
Definition RawEventData.h:4
int32_t i
int32_t retVal
Wrapper container for different reconstructed object types.
Struct for input data required by TRD tracking workflow.
Helper class to obtain TPC clusters / digits / labels from DPL.
static std::shared_ptr< const tmpDataContainer > fillIOPtr(GPUTrackingInOutPointers &ioPtr, const o2::globaltracking::RecoContainer &recoCont, bool useMC, const GPUCalibObjectsConst *calib=nullptr, GID::mask_t maskCl=GID::MASK_ALL, GID::mask_t maskTrk=GID::MASK_ALL, GID::mask_t maskMatch=GID::MASK_ALL)
bool match(const std::vector< std::string > &queries, const char *pattern)
Definition dcs-ccdb.cxx:229
void convertCompactClusters(gsl::span< const itsmft::CompClusterExt > clusters, gsl::span< const unsigned char >::iterator &pattIt, std::vector< o2::BaseCluster< float > > &output, const itsmft::TopologyDictionary *dict)
convert compact clusters to 3D spacepoints
Definition IOUtils.cxx:49
TrackParCovF TrackParCov
Definition Track.h:33
std::vector< o2::BaseCluster< float > > ITSClustersArray
std::vector< const o2::track::TrackParCov * > globalTracks
const o2::tpc::ClusterNativeAccess & getTPCClusters() const
void createTracksVariadic(T creator, GTrackID::mask_t srcSel=GTrackID::getSourcesMask("all")) const
std::unique_ptr< o2::trd::RecoInputContainer > inputsTRD
std::unique_ptr< const o2::dataformats::MCTruthContainer< o2::MCCompLabel > > mcITSClusters
const o2::dataformats::MatchInfoTOF & getTOFMatch(GTrackID id) const
S< o2::itsmft::TopologyDictionary >::type * itsPatternDict
const o2::itsmft::CompClusterExt * itsCompClusters
const o2::tpc::ClusterNativeAccess * clustersNative
const o2::dataformats::MCTruthContainer< o2::MCCompLabel > * itsClusterMC
const o2::dataformats::MatchInfoTOF * tpctofMatches
const o2::dataformats::MatchInfoTOF * tpctrdtofMatches
const o2::MCCompLabel * itsTrackMC
const o2::dataformats::MatchInfoTOF * itstpctrdtofMatches
const GPUTRDTrack * trdTracksTPCTRD
const o2::tof::Cluster * tofClusters
const o2::BaseCluster< float > * itsClusters
const o2::itsmft::ROFRecord * itsClusterROF
const o2::dataformats::MatchInfoTOF * itstpctofMatches
const o2::its::TrackITS * itsTracks
const o2::dataformats::TrackTPCITS * tracksTPCITSO2
const o2::MCCompLabel * outputTracksTPCO2MC
const o2::itsmft::ROFRecord * itsTrackROF
const o2::tpc::TrackTPC * outputTracksTPCO2
const GPUTRDTrack * trdTracksITSTPCTRD
const o2::track::TrackParCov ** globalTracks