forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGPUTPCTrackerComponent.cxx
More file actions
709 lines (610 loc) · 22.4 KB
/
GPUTPCTrackerComponent.cxx
File metadata and controls
709 lines (610 loc) · 22.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file GPUTPCTrackerComponent.cxx
/// \author Sergey Gorbunov, Ivan Kisel, David Rohr
#include "GPUTPCTrackerComponent.h"
#include "GPUReconstruction.h"
#include "GPUChainTracking.h"
#include "GPUParam.h"
#include "AliHLTTPCRawCluster.h"
#include "AliHLTTPCClusterXYZ.h"
#include "AliHLTTPCClusterMCData.h"
#include "AliHLTTPCGeometry.h"
#include "AliHLTTPCDefinitions.h"
#include "GPUTPCDefinitions.h"
#include "AliExternalTrackParam.h"
#include "TMath.h"
#include "AliCDBEntry.h"
#include "AliCDBManager.h"
#include "TObjString.h"
#include "TObjArray.h"
#include "GPUTPCSliceOutput.h"
#include "GPUTPCClusterData.h"
#include "GPUTPCGMMergedTrackHit.h"
#if __GNUC__ >= 3
using namespace std;
#endif
using namespace GPUCA_NAMESPACE::gpu;
const AliHLTComponentDataType GPUTPCDefinitions::fgkTrackletsDataType = AliHLTComponentDataTypeInitializer("CATRACKL", kAliHLTDataOriginTPC);
/** ROOT macro for the implementation of ROOT specific class methods */
ClassImp(GPUTPCTrackerComponent);
GPUTPCTrackerComponent::GPUTPCTrackerComponent()
: fSolenoidBz(0), fMinNTrackClusters(-1), fMinTrackPt(GPUCA_MIN_TRACK_PTB5_DEFAULT), fClusterZCut(500.), mNeighboursSearchArea(0), fClusterErrorCorrectionY(0), fClusterErrorCorrectionZ(0), fBenchmark("CATracker"), fAllowGPU(0), fGPUHelperThreads(-1), fCPUTrackers(0), fGlobalTracking(0), fGPUDeviceNum(-1), fGPUType("CPU"), fGPUStuckProtection(0), fAsync(0), fSearchWindowDZDR(0.), fRec(0), fChain(0), fAsyncProcessor()
{
// see header file for class documentation
// or
// refer to README to build package
// or
// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
}
GPUTPCTrackerComponent::GPUTPCTrackerComponent(const GPUTPCTrackerComponent&)
: AliHLTProcessor(), fSolenoidBz(0), fMinNTrackClusters(-1), fMinTrackPt(GPUCA_MIN_TRACK_PTB5_DEFAULT), fClusterZCut(500.), mNeighboursSearchArea(0), fClusterErrorCorrectionY(0), fClusterErrorCorrectionZ(0), fBenchmark("CATracker"), fAllowGPU(0), fGPUHelperThreads(-1), fCPUTrackers(0), fGlobalTracking(0), fGPUDeviceNum(-1), fGPUType("CPU"), fGPUStuckProtection(0), fAsync(0), fSearchWindowDZDR(0.), fRec(0), fChain(0), fAsyncProcessor()
{
// see header file for class documentation
HLTFatal("copy constructor untested");
}
GPUTPCTrackerComponent& GPUTPCTrackerComponent::operator=(const GPUTPCTrackerComponent&)
{
// see header file for class documentation
HLTFatal("assignment operator untested");
return *this;
}
GPUTPCTrackerComponent::~GPUTPCTrackerComponent()
{
// see header file for class documentation
if (fRec) {
delete fRec;
}
}
//
// Public functions to implement AliHLTComponent's interface.
// These functions are required for the registration process
//
const char* GPUTPCTrackerComponent::GetComponentID()
{
// see header file for class documentation
return "TPCCATracker";
}
void GPUTPCTrackerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
{
// see header file for class documentation
list.clear();
list.push_back(AliHLTTPCDefinitions::RawClustersDataType());
list.push_back(AliHLTTPCDefinitions::ClustersXYZDataType());
list.push_back(AliHLTTPCDefinitions::AliHLTDataTypeClusterMCInfo());
}
AliHLTComponentDataType GPUTPCTrackerComponent::GetOutputDataType()
{
// see header file for class documentation
return GPUTPCDefinitions::fgkTrackletsDataType;
}
void GPUTPCTrackerComponent::GetOutputDataSize(uint64_t& constBase, double& inputMultiplier)
{
// define guess for the output data size
constBase = 10000; // minimum size
inputMultiplier = 0.6; // size relative to input
}
AliHLTComponent* GPUTPCTrackerComponent::Spawn()
{
// see header file for class documentation
return new GPUTPCTrackerComponent;
}
void GPUTPCTrackerComponent::SetDefaultConfiguration()
{
// Set default configuration for the CA tracker component
// Some parameters can be later overwritten from the OCDB
fSolenoidBz = -5.00668;
fMinNTrackClusters = -1;
fMinTrackPt = GPUCA_MIN_TRACK_PTB5_DEFAULT;
fClusterZCut = 500.;
mNeighboursSearchArea = 0;
fClusterErrorCorrectionY = 0;
fClusterErrorCorrectionZ = 0;
fBenchmark.Reset();
fBenchmark.SetTimer(0, "total");
fBenchmark.SetTimer(1, "reco");
}
int32_t GPUTPCTrackerComponent::ReadConfigurationString(const char* arguments)
{
// Set configuration parameters for the CA tracker component from the string
int32_t iResult = 0;
if (!arguments) {
return iResult;
}
TString allArgs = arguments;
TString argument;
int32_t bMissingParam = 0;
TObjArray* pTokens = allArgs.Tokenize(" ");
int32_t nArgs = pTokens ? pTokens->GetEntries() : 0;
for (int32_t i = 0; i < nArgs; i++) {
argument = ((TObjString*)pTokens->At(i))->GetString();
if (argument.IsNull()) {
continue;
}
if (argument.CompareTo("-solenoidBz") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
continue;
}
if (argument.CompareTo("-minNClustersOnTrack") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
fMinNTrackClusters = ((TObjString*)pTokens->At(i))->GetString().Atoi();
HLTInfo("minNClustersOnTrack set to: %d", fMinNTrackClusters);
continue;
}
if (argument.CompareTo("-minTrackPt") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
fMinTrackPt = ((TObjString*)pTokens->At(i))->GetString().Atof();
HLTInfo("minTrackPt set to: %f", fMinTrackPt);
continue;
}
if (argument.CompareTo("-clusterZCut") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
fClusterZCut = TMath::Abs(((TObjString*)pTokens->At(i))->GetString().Atof());
HLTInfo("ClusterZCut set to: %f", fClusterZCut);
continue;
}
if (argument.CompareTo("-neighboursSearchArea") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
mNeighboursSearchArea = TMath::Abs(((TObjString*)pTokens->At(i))->GetString().Atof());
HLTInfo("NeighboursSearchArea set to: %f", mNeighboursSearchArea);
continue;
}
if (argument.CompareTo("-errorCorrectionY") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
fClusterErrorCorrectionY = ((TObjString*)pTokens->At(i))->GetString().Atof();
HLTInfo("Cluster Y error correction factor set to: %f", fClusterErrorCorrectionY);
continue;
}
if (argument.CompareTo("-errorCorrectionZ") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
fClusterErrorCorrectionZ = ((TObjString*)pTokens->At(i))->GetString().Atof();
HLTInfo("Cluster Z error correction factor set to: %f", fClusterErrorCorrectionZ);
continue;
}
if (argument.CompareTo("-allowGPU") == 0) {
fAllowGPU = 1;
HLTInfo("Will try to run tracker on GPU");
continue;
}
if (argument.CompareTo("-GlobalTracking") == 0) {
fGlobalTracking = 1;
HLTInfo("Global Tracking Activated");
continue;
}
if (argument.CompareTo("-GPUHelperThreads") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
fGPUHelperThreads = ((TObjString*)pTokens->At(i))->GetString().Atoi();
HLTInfo("Number of GPU Helper Threads set to: %d", fGPUHelperThreads);
continue;
}
if (argument.CompareTo("-CPUTrackers") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
fCPUTrackers = ((TObjString*)pTokens->At(i))->GetString().Atoi();
HLTInfo("Number of CPU Trackers set to: %d", fCPUTrackers);
continue;
}
if (argument.CompareTo("-SearchWindowDZDR") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
fSearchWindowDZDR = ((TObjString*)pTokens->At(i))->GetString().Atof();
HLTInfo("Search Window DZDR set to: %f", fSearchWindowDZDR);
continue;
}
if (argument.CompareTo("-GPUDeviceNum") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
fGPUDeviceNum = ((TObjString*)pTokens->At(i))->GetString().Atoi();
HLTInfo("Using GPU Device Number %d", fGPUDeviceNum);
continue;
}
if (argument.CompareTo("-GPUType") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
fGPUType = ((TObjString*)pTokens->At(i))->GetString();
continue;
}
if (argument.CompareTo("-GPUStuckProtection") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
fGPUStuckProtection = ((TObjString*)pTokens->At(i))->GetString().Atoi();
continue;
}
if (argument.CompareTo("-AsyncGPUStuckProtection") == 0) {
if ((bMissingParam = (++i >= pTokens->GetEntries()))) {
break;
}
fAsync = ((TObjString*)pTokens->At(i))->GetString().Atoi();
continue;
}
HLTError("Unknown option \"%s\"", argument.Data());
iResult = -EINVAL;
}
delete pTokens;
if (bMissingParam) {
HLTError("Specifier missed for parameter \"%s\"", argument.Data());
iResult = -EINVAL;
}
return iResult;
}
int32_t GPUTPCTrackerComponent::ReadCDBEntry(const char* cdbEntry, const char* chainId)
{
// see header file for class documentation
const char* defaultNotify = "";
if (!cdbEntry) {
cdbEntry = "HLT/ConfigTPC/TPCCATracker";
defaultNotify = " (default)";
chainId = 0;
}
HLTInfo("configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, (chainId != nullptr && chainId[0] != 0) ? chainId : "<none>");
AliCDBEntry* pEntry = AliCDBManager::Instance()->Get(cdbEntry); //,GetRunNo());
if (!pEntry) {
HLTError("cannot fetch object \"%s\" from CDB", cdbEntry);
return -EINVAL;
}
TObjString* pString = dynamic_cast<TObjString*>(pEntry->GetObject());
if (!pString) {
HLTError("configuration object \"%s\" has wrong type, required TObjString", cdbEntry);
return -EINVAL;
}
HLTInfo("received configuration object string: \"%s\"", pString->GetString().Data());
return ReadConfigurationString(pString->GetString().Data());
}
int32_t GPUTPCTrackerComponent::Configure(const char* cdbEntry, const char* chainId, const char* commandLine)
{
// Configure the component
// There are few levels of configuration,
// parameters which are set on one step can be overwritten on the next step
//* read hard-coded values
SetDefaultConfiguration();
//* read the default CDB entry
int32_t iResult1 = ReadCDBEntry(nullptr, chainId);
//* read magnetic field
fSolenoidBz = GetBz();
//* read the actual CDB entry if required
int32_t iResult2 = (cdbEntry) ? ReadCDBEntry(cdbEntry, chainId) : 0;
//* read extra parameters from input (if they are)
int32_t iResult3 = 0;
if (commandLine && commandLine[0] != '\0') {
HLTInfo("received configuration string from HLT framework: \"%s\"", commandLine);
iResult3 = ReadConfigurationString(commandLine);
}
if (fRec) {
ConfigureSlices();
}
return iResult1 ? iResult1 : (iResult2 ? iResult2 : iResult3);
}
int32_t GPUTPCTrackerComponent::ConfigureSlices()
{
// Initialize the tracker slices
GPUSettingsRec rec;
GPUSettingsGRP grp;
GPUSettingsProcessing devProc;
grp.solenoidBzNominalGPU = fSolenoidBz;
grp.grpContinuousMaxTimeBin = 0; // triggered events
if (mNeighboursSearchArea > 0) {
rec.tpc.neighboursSearchArea = mNeighboursSearchArea;
}
if (fClusterErrorCorrectionY > 1.e-4) {
rec.tpc.clusterError2CorrectionY = fClusterErrorCorrectionY * fClusterErrorCorrectionY;
}
if (fClusterErrorCorrectionZ > 1.e-4) {
rec.tpc.clusterError2CorrectionZ = fClusterErrorCorrectionZ * fClusterErrorCorrectionZ;
}
rec.tpc.minNClustersTrackSeed = fMinNTrackClusters;
rec.SetMinTrackPtB5(fMinTrackPt * fabsf(fSolenoidBz / 5));
rec.tpc.searchWindowDZDR = fSearchWindowDZDR;
devProc.nDeviceHelperThreads = fGPUHelperThreads;
rec.tpc.globalTracking = fGlobalTracking;
devProc.stuckProtection = fGPUStuckProtection;
rec.nonConsecutiveIDs = true;
rec.tpc.mergerReadFromTrackerDirectly = false;
devProc.ompThreads = 1;
devProc.ompKernels = false;
GPURecoStepConfiguration steps;
steps.steps.set(GPUDataTypes::RecoStep::TPCSliceTracking);
steps.inputs.set(GPUDataTypes::InOutType::TPCClusters);
steps.outputs.set(GPUDataTypes::InOutType::TPCSectorTracks);
fRec->SetSettings(&grp, &rec, &devProc, &steps);
fChain->LoadClusterErrors();
return fRec->Init();
}
void* GPUTPCTrackerComponent::TrackerInit(void* par)
{
// Create tracker instance and set parameters
fRec = GPUReconstruction::CreateInstance(fAllowGPU ? fGPUType.Data() : "CPU", true);
if (fRec == nullptr) {
return ((void*)-1);
}
fChain = fRec->AddChain<GPUChainTracking>();
if (ConfigureSlices()) {
return ((void*)-1);
}
return (nullptr);
}
int32_t GPUTPCTrackerComponent::DoInit(int argc, const char** argv)
{
if (fRec) {
return EINPROGRESS;
}
// Configure the CA tracker component
TString arguments = "";
for (int32_t i = 0; i < argc; i++) {
if (!arguments.IsNull()) {
arguments += " ";
}
arguments += argv[i];
}
int32_t retVal = Configure(nullptr, nullptr, arguments.Data());
if (retVal == 0) {
if (fAsync) {
if (fAsyncProcessor.Initialize(1)) {
return (-ENODEV);
}
void* initRetVal;
if (fAsyncProcessor.InitializeAsyncMemberTask(this, &GPUTPCTrackerComponent::TrackerInit, nullptr, &initRetVal) != 0) {
return (-ENODEV);
}
if (initRetVal) {
return (-ENODEV);
}
} else {
if (TrackerInit(nullptr) != nullptr) {
return (-ENODEV);
}
}
}
return (retVal);
}
void* GPUTPCTrackerComponent::TrackerExit(void* par)
{
if (fRec) {
delete fRec;
}
fRec = nullptr;
return (nullptr);
}
int32_t GPUTPCTrackerComponent::DoDeinit()
{
// see header file for class documentation
if (fAsync) {
void* initRetVal = nullptr;
fAsyncProcessor.InitializeAsyncMemberTask(this, &GPUTPCTrackerComponent::TrackerExit, nullptr, &initRetVal);
fAsyncProcessor.Deinitialize();
} else {
TrackerExit(nullptr);
}
return 0;
}
int32_t GPUTPCTrackerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
{
// Reconfigure the component from OCDB .
return Configure(cdbEntry, chainId, nullptr);
}
int32_t GPUTPCTrackerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks)
{
//* process event
if (!fRec) {
HLTError("CATracker not initialized properly");
return -ENOENT;
}
AliHLTTPCTrackerWrapperData tmpPar;
tmpPar.fEvtData = &evtData;
tmpPar.fBlocks = blocks;
tmpPar.mOutputPtr = outputPtr;
tmpPar.fSize = &size;
tmpPar.mOutputBlocks = &outputBlocks;
static int32_t trackerTimeout = 0;
if (trackerTimeout) {
size = 0;
return (0);
}
int32_t retVal;
if (fAsync) {
void* asyncRetVal = nullptr;
if (fAsyncProcessor.InitializeAsyncMemberTask(this, &GPUTPCTrackerComponent::TrackerDoEvent, &tmpPar, &asyncRetVal, fAsync) != 0) {
HLTError("Tracking timed out, disabling this tracker instance");
trackerTimeout = 1;
size = 0;
return (-ENODEV);
} else {
retVal = (int32_t)(size_t)asyncRetVal;
}
} else {
retVal = (int32_t)(size_t)TrackerDoEvent(&tmpPar);
}
return (retVal);
}
void* GPUTPCTrackerComponent::TrackerDoEvent(void* par)
{
AliHLTTPCTrackerWrapperData* tmpPar = reinterpret_cast<AliHLTTPCTrackerWrapperData*>(par);
const AliHLTComponentEventData& evtData = *(tmpPar->fEvtData);
const AliHLTComponentBlockData* blocks = tmpPar->fBlocks;
AliHLTUInt8_t* outputPtr = tmpPar->mOutputPtr;
AliHLTUInt32_t& size = *(tmpPar->fSize);
vector<AliHLTComponentBlockData>& outputBlocks = *(tmpPar->mOutputBlocks);
AliHLTUInt32_t maxBufferSize = size;
size = 0; // output size
if (GetFirstInputBlock(kAliHLTDataTypeSOR) || GetFirstInputBlock(kAliHLTDataTypeEOR)) {
return 0;
}
fBenchmark.StartNewEvent();
fBenchmark.Start(0);
// Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "CA::DoEvent()" );
if (evtData.fBlockCnt <= 0) {
HLTWarning("no blocks in event");
return 0;
}
// Prepare everything for all slices
const AliHLTTPCClusterXYZData* clustersXYZ[NSLICES][fgkNPatches] = {nullptr};
const AliHLTTPCRawClusterData* clustersRaw[NSLICES][fgkNPatches] = {nullptr};
for (uint64_t ndx = 0; ndx < evtData.fBlockCnt; ndx++) {
const AliHLTComponentBlockData& pBlock = blocks[ndx];
int32_t slice = AliHLTTPCDefinitions::GetMinSliceNr(pBlock);
int32_t patch = AliHLTTPCDefinitions::GetMinPatchNr(pBlock);
if (pBlock.fDataType == AliHLTTPCDefinitions::RawClustersDataType()) {
clustersRaw[slice][patch] = (const AliHLTTPCRawClusterData*)pBlock.fPtr;
} else if (pBlock.fDataType == AliHLTTPCDefinitions::ClustersXYZDataType()) {
clustersXYZ[slice][patch] = (const AliHLTTPCClusterXYZData*)pBlock.fPtr;
}
}
GPUTPCClusterData* clusterData[NSLICES] = {nullptr};
int32_t nClusters[NSLICES] = {0};
int32_t nClustersTotal = 0;
for (int32_t slice = 0; slice < NSLICES; slice++) {
int32_t nClustersSliceTotal = 0;
for (int32_t patch = 0; patch < 6; patch++) {
if (clustersXYZ[slice][patch]) {
nClustersSliceTotal += clustersXYZ[slice][patch]->fCount;
}
}
if (nClustersSliceTotal > 500000) {
HLTWarning("Too many clusters in tracker input: Slice %d, Number of Clusters %d, slice not included in tracking", slice, nClustersSliceTotal);
nClusters[slice] = nClustersSliceTotal;
} else if (nClustersSliceTotal == 0) {
nClusters[slice] = nClustersSliceTotal;
} else {
clusterData[slice] = new GPUTPCClusterData[nClustersSliceTotal];
nClusters[slice] = nClustersSliceTotal;
GPUTPCClusterData* pCluster = clusterData[slice];
for (int32_t patch = 0; patch < 6; patch++) {
if (clustersXYZ[slice][patch] != nullptr && clustersRaw[slice][patch] != nullptr) {
const AliHLTTPCClusterXYZData& clXYZ = *clustersXYZ[slice][patch];
const AliHLTTPCRawClusterData& clRaw = *clustersRaw[slice][patch];
if (clXYZ.fCount != clRaw.fCount) {
HLTError("Number of entries in raw and xyz clusters are not mached %d vs %d", clXYZ.fCount, clRaw.fCount);
continue;
}
const int32_t firstRow = AliHLTTPCGeometry::GetFirstRow(patch);
for (int32_t ic = 0; ic < clXYZ.fCount; ic++) {
const AliHLTTPCClusterXYZ& c = clXYZ.fClusters[ic];
const AliHLTTPCRawCluster& cRaw = clRaw.fClusters[ic];
if (c.GetZ() > fClusterZCut || c.GetZ() < -fClusterZCut) {
continue;
}
if (c.GetX() < 1.f) {
continue; // cluster xyz position was not calculated for whatever reason
}
pCluster->id = AliHLTTPCGeometry::CreateClusterID(slice, patch, ic);
pCluster->x = c.GetX();
pCluster->y = c.GetY();
pCluster->z = c.GetZ();
pCluster->row = firstRow + cRaw.GetPadRow();
pCluster->flags = cRaw.GetFlags();
if (cRaw.GetSigmaPad2() < kAlmost0 || cRaw.GetSigmaTime2() < kAlmost0) {
pCluster->flags |= GPUTPCGMMergedTrackHit::flagSingle;
}
pCluster->amp = cRaw.GetCharge();
#ifdef GPUCA_FULL_CLUSTERDATA
pCluster->pad = cRaw.GetPad();
pCluster->time = cRaw.GetTime();
pCluster->ampMax = cRaw.GetQMax();
pCluster->sigmaPad2 = cRaw.GetSigmaPad2();
pCluster->sigmaTime2 = cRaw.GetSigmaTime2();
#endif
pCluster++;
}
}
}
nClusters[slice] = pCluster - clusterData[slice];
nClustersTotal += nClusters[slice];
HLTDebug("Read %d->%d hits for slice %d", nClustersSliceTotal, nClusters[slice], slice);
}
}
if (nClustersTotal == 0) {
// No input, skip processing
fBenchmark.Stop(0);
return (0);
}
fChain->ClearIOPointers();
for (int32_t i = 0; i < NSLICES; i++) {
fChain->mIOPtrs.clusterData[i] = clusterData[i];
fChain->mIOPtrs.nClusterData[i] = nClusters[i];
}
// Prepare Output
fRec->SetOutputControl(outputPtr, maxBufferSize);
// reconstruct the event
fBenchmark.Start(1);
try {
fRec->PrepareEvent();
} catch (const std::bad_alloc& e) {
printf("Memory Allocation Error\n");
return ((void*)(size_t)-EINVAL);
}
if (fChain->RunTPCTrackingSlices()) {
HLTError("Error running tracking!");
return ((void*)(size_t)-EINVAL);
}
if (fChain->CheckErrorCodes()) {
return ((void*)(size_t)-EINVAL);
}
fBenchmark.Stop(1);
HLTInfo("Processed %d clusters", nClustersTotal);
for (int32_t i = 0; i < NSLICES; i++) {
fChain->GetTPCSliceTrackers()[i].Clear();
}
int32_t ret = 0;
size = 0;
if (fRec->OutputControl().size == 1) {
HLTWarning("Output buffer size exceeded buffer size %d, tracks are not stored", maxBufferSize);
ret = -ENOSPC;
} else {
for (int32_t slice = 0; slice < NSLICES; slice++) {
GPUTPCSliceOutput* pOut = fChain->GetTPCSliceTrackers()[slice].Output();
if (!pOut) {
continue;
}
HLTDebug("%d tracks found for slice %d", pOut->NTracks(), slice);
uint32_t blockSize = pOut->Size();
if (blockSize > 0) {
AliHLTComponentBlockData bd;
FillBlockData(bd);
bd.fOffset = ((char*)pOut - (char*)outputPtr);
bd.fSize = blockSize;
bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification(slice, slice, 0, fgkNPatches);
bd.fDataType = GPUTPCDefinitions::fgkTrackletsDataType;
outputBlocks.push_back(bd);
size += bd.fSize;
fBenchmark.AddOutput(bd.fSize);
}
}
}
for (int32_t i = 0; i < NSLICES; i++) {
if (clusterData[i]) {
delete[] clusterData[i];
}
}
fBenchmark.Stop(0);
HLTInfo(fBenchmark.GetStatistics());
return ((void*)(size_t)ret);
}