Project
Loading...
Searching...
No Matches
GPUWorkflowSpec.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#include "Headers/DataHeader.h"
19#include "Framework/WorkflowSpec.h" // o2::framework::mergeInputs
27#include "Framework/Logger.h"
42#include "TPCFastTransform.h"
51#include "TPCBase/RDHUtils.h"
53#include "GPUO2InterfaceQA.h"
54#include "GPUO2Interface.h"
55#include "GPUO2InterfaceUtils.h"
56#include "CalibdEdxContainer.h"
57#include "GPUNewCalibValues.h"
58#include "TPCPadGainCalib.h"
59#include "TPCZSLinkMapping.h"
61#include "TPCBase/Sector.h"
62#include "TPCBase/Utils.h"
70#include "Algorithm/Parser.h"
73#include "TRDBase/Geometry.h"
80#include "GPUWorkflowInternal.h"
82// #include "Framework/ThreadPool.h"
83
84#include <TStopwatch.h>
85#include <TObjArray.h>
86#include <TH1F.h>
87#include <TH2F.h>
88#include <TH1D.h>
89#include <TGraphAsymmErrors.h>
90
91#include <filesystem>
92#include <memory>
93#include <vector>
94#include <iomanip>
95#include <stdexcept>
96#include <regex>
97#include <sys/types.h>
98#include <sys/stat.h>
99#include <fcntl.h>
100#include <chrono>
101#include <unordered_set>
102
103using namespace o2::framework;
104using namespace o2::header;
105using namespace o2::gpu;
106using namespace o2::base;
107using namespace o2::dataformats;
109
110namespace o2::gpu
111{
112
113GPURecoWorkflowSpec::GPURecoWorkflowSpec(GPURecoWorkflowSpec::CompletionPolicyData* policyData, Config const& specconfig, std::vector<int32_t> const& tpcsectors, uint64_t tpcSectorMask, std::shared_ptr<o2::base::GRPGeomRequest>& ggr, std::function<bool(o2::framework::DataProcessingHeader::StartTime)>** gPolicyOrder) : o2::framework::Task(), mPolicyData(policyData), mTPCSectorMask(tpcSectorMask), mTPCSectors(tpcsectors), mSpecConfig(specconfig), mGGR(ggr)
114{
115 if (mSpecConfig.outputCAClusters && !mSpecConfig.caClusterer && !mSpecConfig.decompressTPC) {
116 throw std::runtime_error("inconsistent configuration: cluster output is only possible if CA clusterer is activated");
117 }
118
119 mConfig.reset(new GPUO2InterfaceConfiguration);
120 mConfParam.reset(new GPUSettingsO2);
121 mTFSettings.reset(new GPUSettingsTF);
122 mTimer.reset(new TStopwatch);
123 mPipeline.reset(new GPURecoWorkflowSpec_PipelineInternals);
124
125 if (mSpecConfig.enableDoublePipeline == 1 && gPolicyOrder) {
126 *gPolicyOrder = &mPolicyOrder;
127 }
128}
129
131
133{
135 GPUO2InterfaceConfiguration& config = *mConfig.get();
136 GPUSettingsProcessingNNclusterizer& mNNClusterizerSettings = mConfig->configProcessing.nn;
137
138 if (mNNClusterizerSettings.nnLoadFromCCDB) {
139 LOG(info) << "Loading neural networks from CCDB";
140 o2::tpc::NeuralNetworkClusterizer nnClusterizerFetcher;
141 nnClusterizerFetcher.initCcdbApi(mNNClusterizerSettings.nnCCDBURL);
142 std::map<std::string, std::string> ccdbSettings = {
143 {"nnCCDBURL", mNNClusterizerSettings.nnCCDBURL},
144 {"nnCCDBPath", mNNClusterizerSettings.nnCCDBPath},
145 {"inputDType", mNNClusterizerSettings.nnInferenceInputDType},
146 {"outputDType", mNNClusterizerSettings.nnInferenceOutputDType},
147 {"outputFolder", mNNClusterizerSettings.nnLocalFolder},
148 {"nnCCDBPath", mNNClusterizerSettings.nnCCDBPath},
149 {"nnCCDBWithMomentum", std::to_string(mNNClusterizerSettings.nnCCDBWithMomentum)},
150 {"nnCCDBBeamType", mNNClusterizerSettings.nnCCDBBeamType},
151 {"nnCCDBInteractionRate", std::to_string(mNNClusterizerSettings.nnCCDBInteractionRate)}};
152
153 std::string nnFetchFolder = mNNClusterizerSettings.nnLocalFolder;
154 std::vector<std::string> evalMode = o2::utils::Str::tokenize(mNNClusterizerSettings.nnEvalMode, ':');
155
156 if (evalMode[0] == "c1") {
157 ccdbSettings["nnCCDBLayerType"] = mNNClusterizerSettings.nnCCDBClassificationLayerType;
158 ccdbSettings["nnCCDBEvalType"] = "classification_c1";
159 ccdbSettings["outputFile"] = "net_classification_c1.onnx";
160 nnClusterizerFetcher.loadIndividualFromCCDB(ccdbSettings);
161 } else if (evalMode[0] == "c2") {
162 ccdbSettings["nnCCDBLayerType"] = mNNClusterizerSettings.nnCCDBClassificationLayerType;
163 ccdbSettings["nnCCDBEvalType"] = "classification_c2";
164 ccdbSettings["outputFile"] = "net_classification_c2.onnx";
165 nnClusterizerFetcher.loadIndividualFromCCDB(ccdbSettings);
166 }
167
168 ccdbSettings["nnCCDBLayerType"] = mNNClusterizerSettings.nnCCDBRegressionLayerType;
169 ccdbSettings["nnCCDBEvalType"] = "regression_c1";
170 ccdbSettings["outputFile"] = "net_regression_c1.onnx";
171 nnClusterizerFetcher.loadIndividualFromCCDB(ccdbSettings);
172 if (evalMode[1] == "r2") {
173 ccdbSettings["nnCCDBLayerType"] = mNNClusterizerSettings.nnCCDBRegressionLayerType;
174 ccdbSettings["nnCCDBEvalType"] = "regression_c2";
175 ccdbSettings["outputFile"] = "net_regression_c2.onnx";
176 nnClusterizerFetcher.loadIndividualFromCCDB(ccdbSettings);
177 }
178 LOG(info) << "Neural network loading done!";
179 }
180
181 // Create configuration object and fill settings
182 mConfig->configGRP.solenoidBzNominalGPU = 0;
183 mTFSettings->hasSimStartOrbit = 1;
184 auto& hbfu = o2::raw::HBFUtils::Instance();
185 mTFSettings->simStartOrbit = hbfu.getFirstIRofTF(o2::InteractionRecord(0, hbfu.orbitFirstSampled)).orbit;
186
187 *mConfParam = mConfig->ReadConfigurableParam();
188 if (mConfParam->display) {
189 mDisplayFrontend.reset(GPUDisplayFrontendInterface::getFrontend(mConfig->configDisplay.displayFrontend.c_str()));
190 mConfig->configProcessing.eventDisplay = mDisplayFrontend.get();
191 if (mConfig->configProcessing.eventDisplay != nullptr) {
192 LOG(info) << "Event display enabled";
193 } else {
194 throw std::runtime_error("GPU Event Display frontend could not be created!");
195 }
196 }
197 if (mSpecConfig.enableDoublePipeline) {
198 mConfig->configProcessing.doublePipeline = 1;
199 }
200
201 mAutoSolenoidBz = mConfParam->solenoidBzNominalGPU == -1e6f;
202 mAutoContinuousMaxTimeBin = mConfig->configGRP.grpContinuousMaxTimeBin < 0;
203 if (mAutoContinuousMaxTimeBin) {
204 mConfig->configGRP.grpContinuousMaxTimeBin = GPUO2InterfaceUtils::getTpcMaxTimeBinFromNHbf(mConfParam->overrideNHbfPerTF ? mConfParam->overrideNHbfPerTF : 256);
205 }
206 if (mConfig->configProcessing.deviceNum == -2) {
207 int32_t myId = ic.services().get<const o2::framework::DeviceSpec>().inputTimesliceId;
208 int32_t idMax = ic.services().get<const o2::framework::DeviceSpec>().maxInputTimeslices;
209 mConfig->configProcessing.deviceNum = myId;
210 LOG(info) << "GPU device number selected from pipeline id: " << myId << " / " << idMax;
211 }
212 if (mConfig->configProcessing.debugLevel >= 3 && mVerbosity == 0) {
213 mVerbosity = 1;
214 }
215 mConfig->configProcessing.runMC = mSpecConfig.processMC;
216 if (mSpecConfig.outputQA) {
217 if (!mSpecConfig.processMC && !mConfig->configQA.clusterRejectionHistograms) {
218 throw std::runtime_error("Need MC information to create QA plots");
219 }
220 if (!mSpecConfig.processMC) {
221 mConfig->configQA.noMC = true;
222 }
223 mConfig->configQA.shipToQC = true;
224 if (!mConfig->configProcessing.runQA) {
225 mConfig->configQA.enableLocalOutput = false;
226 mQATaskMask = (mSpecConfig.processMC ? 15 : 0) | (mConfig->configQA.clusterRejectionHistograms ? 32 : 0);
227 mConfig->configProcessing.runQA = -mQATaskMask;
228 }
229 }
230 mConfig->configReconstruction.tpc.nWaysOuter = true;
231 mConfig->configInterface.outputToExternalBuffers = true;
232 if (mConfParam->synchronousProcessing) {
233 mConfig->configReconstruction.useMatLUT = false;
234 }
235 if (mConfig->configProcessing.rtc.optSpecialCode == -1) {
236 mConfig->configProcessing.rtc.optSpecialCode = mConfParam->synchronousProcessing;
237 }
238
239 // Configure the "GPU workflow" i.e. which steps we run on the GPU (or CPU)
240 if (mSpecConfig.outputTracks || mSpecConfig.outputCompClusters || mSpecConfig.outputCompClustersFlat) {
241 mConfig->configWorkflow.steps.set(GPUDataTypes::RecoStep::TPCConversion,
244 mConfig->configWorkflow.outputs.set(GPUDataTypes::InOutType::TPCMergedTracks);
245 mConfig->configWorkflow.steps.setBits(GPUDataTypes::RecoStep::TPCdEdx, mConfParam->rundEdx == -1 ? !mConfParam->synchronousProcessing : mConfParam->rundEdx);
246 }
247 if (mSpecConfig.outputCompClusters || mSpecConfig.outputCompClustersFlat) {
248 mConfig->configWorkflow.steps.setBits(GPUDataTypes::RecoStep::TPCCompression, true);
249 mConfig->configWorkflow.outputs.setBits(GPUDataTypes::InOutType::TPCCompressedClusters, true);
250 }
251 mConfig->configWorkflow.inputs.set(GPUDataTypes::InOutType::TPCClusters);
252 if (mSpecConfig.caClusterer) { // Override some settings if we have raw data as input
253 mConfig->configWorkflow.inputs.set(GPUDataTypes::InOutType::TPCRaw);
254 mConfig->configWorkflow.steps.setBits(GPUDataTypes::RecoStep::TPCClusterFinding, true);
255 mConfig->configWorkflow.outputs.setBits(GPUDataTypes::InOutType::TPCClusters, true);
256 }
257 if (mSpecConfig.decompressTPC) {
258 mConfig->configWorkflow.steps.setBits(GPUDataTypes::RecoStep::TPCCompression, false);
259 mConfig->configWorkflow.steps.setBits(GPUDataTypes::RecoStep::TPCDecompression, true);
260 mConfig->configWorkflow.inputs.set(GPUDataTypes::InOutType::TPCCompressedClusters);
261 mConfig->configWorkflow.outputs.setBits(GPUDataTypes::InOutType::TPCClusters, true);
262 mConfig->configWorkflow.outputs.setBits(GPUDataTypes::InOutType::TPCCompressedClusters, false);
263 if (mTPCSectorMask != 0xFFFFFFFFF) {
264 throw std::invalid_argument("Cannot run TPC decompression with a sector mask");
265 }
266 }
267 if (mSpecConfig.runTRDTracking) {
268 mConfig->configWorkflow.inputs.setBits(GPUDataTypes::InOutType::TRDTracklets, true);
269 mConfig->configWorkflow.steps.setBits(GPUDataTypes::RecoStep::TRDTracking, true);
270 }
271 if (mSpecConfig.runITSTracking) {
272 mConfig->configWorkflow.inputs.setBits(GPUDataTypes::InOutType::ITSClusters, true);
273 mConfig->configWorkflow.outputs.setBits(GPUDataTypes::InOutType::ITSTracks, true);
274 mConfig->configWorkflow.steps.setBits(GPUDataTypes::RecoStep::ITSTracking, true);
275 }
276 if (mSpecConfig.outputSharedClusterMap) {
277 mConfig->configProcessing.outputSharedClusterMap = true;
278 }
279 if (!mSpecConfig.outputTracks) {
280 mConfig->configProcessing.createO2Output = 0; // Disable O2 TPC track format output if no track output requested
281 }
282 mConfig->configProcessing.param.tpcTriggerHandling = mSpecConfig.tpcTriggerHandling;
283
284 if (mConfParam->transformationFile.size() || mConfParam->transformationSCFile.size()) {
285 LOG(fatal) << "Deprecated configurable param options GPU_global.transformationFile or transformationSCFile used\n"
286 << "Instead, link the corresponding file as <somedir>/TPC/Calib/CorrectionMap/snapshot.root and use it via\n"
287 << "--condition-remap file://<somdir>=TPC/Calib/CorrectionMap option";
288 }
289 /* if (config.configProcessing.doublePipeline && ic.services().get<ThreadPool>().poolSize != 2) {
290 throw std::runtime_error("double pipeline requires exactly 2 threads");
291 } */
292 if (config.configProcessing.doublePipeline && (mSpecConfig.readTRDtracklets || mSpecConfig.runITSTracking || !(mSpecConfig.zsOnTheFly || mSpecConfig.zsDecoder))) {
293 LOG(fatal) << "GPU two-threaded pipeline works only with TPC-only processing, and with ZS input";
294 }
295
296 if (mSpecConfig.enableDoublePipeline != 2) {
297 mGPUReco = std::make_unique<GPUO2Interface>();
298
299 // initialize TPC calib objects
300 initFunctionTPCCalib(ic);
301
302 mConfig->configCalib.fastTransform = mCalibObjects.mFastTransformHelper->getCorrMap();
303 mConfig->configCalib.fastTransformRef = mCalibObjects.mFastTransformHelper->getCorrMapRef();
304 mConfig->configCalib.fastTransformMShape = mCalibObjects.mFastTransformHelper->getCorrMapMShape();
305 mConfig->configCalib.fastTransformHelper = mCalibObjects.mFastTransformHelper.get();
306 if (mConfig->configCalib.fastTransform == nullptr) {
307 throw std::invalid_argument("GPU workflow: initialization of the TPC transformation failed");
308 }
309
310 if (mConfParam->matLUTFile.size()) {
311 LOGP(info, "Loading matlut file {}", mConfParam->matLUTFile.c_str());
312 mConfig->configCalib.matLUT = o2::base::MatLayerCylSet::loadFromFile(mConfParam->matLUTFile.c_str());
313 if (mConfig->configCalib.matLUT == nullptr) {
314 LOGF(fatal, "Error loading matlut file");
315 }
316 } else {
317 mConfig->configProcessing.lateO2MatLutProvisioningSize = 50 * 1024 * 1024;
318 }
319
320 if (mSpecConfig.readTRDtracklets) {
321 mTRDGeometry = std::make_unique<o2::trd::GeometryFlat>();
322 mConfig->configCalib.trdGeometry = mTRDGeometry.get();
323 }
324
325 mConfig->configProcessing.willProvideO2PropagatorLate = true;
326 mConfig->configProcessing.o2PropagatorUseGPUField = true;
327
328 if (mConfParam->printSettings && (mConfParam->printSettings > 1 || ic.services().get<const o2::framework::DeviceSpec>().inputTimesliceId == 0)) {
329 mConfig->configProcessing.printSettings = true;
330 if (mConfParam->printSettings > 1) {
331 mConfig->PrintParam();
332 }
333 }
334
335 // Configuration is prepared, initialize the tracker.
336 if (mGPUReco->Initialize(config) != 0) {
337 throw std::invalid_argument("GPU Reconstruction initialization failed");
338 }
339 if (mSpecConfig.outputQA) {
340 mQA = std::make_unique<GPUO2InterfaceQA>(mConfig.get());
341 }
342 if (mSpecConfig.outputErrorQA) {
343 mGPUReco->setErrorCodeOutput(&mErrorQA);
344 }
345
346 // initialize ITS
347 if (mSpecConfig.runITSTracking) {
348 initFunctionITS(ic);
349 }
350 }
351
352 if (mSpecConfig.enableDoublePipeline) {
353 initPipeline(ic);
354 if (mConfParam->dump >= 2) {
355 LOG(fatal) << "Cannot use dump-only mode with multi-threaded pipeline";
356 }
357 }
358
359 auto& callbacks = ic.services().get<CallbackService>();
360 callbacks.set<CallbackService::Id::RegionInfoCallback>([this](fair::mq::RegionInfo const& info) {
361 if (info.size == 0) {
362 return;
363 }
364 if (mSpecConfig.enableDoublePipeline) {
365 mRegionInfos.emplace_back(info);
366 }
367 if (mSpecConfig.enableDoublePipeline == 2) {
368 return;
369 }
370 if (mConfParam->registerSelectedSegmentIds != -1 && info.managed && info.id != (uint32_t)mConfParam->registerSelectedSegmentIds) {
371 return;
372 }
373 int32_t fd = 0;
374 if (mConfParam->mutexMemReg) {
375 mode_t mask = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
376 fd = open("/tmp/o2_gpu_memlock_mutex.lock", O_RDWR | O_CREAT | O_CLOEXEC, mask);
377 if (fd == -1) {
378 throw std::runtime_error("Error opening memlock mutex lock file");
379 }
380 fchmod(fd, mask);
381 if (lockf(fd, F_LOCK, 0)) {
382 throw std::runtime_error("Error locking memlock mutex file");
383 }
384 }
385 std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
386 if (mConfParam->benchmarkMemoryRegistration) {
387 start = std::chrono::high_resolution_clock::now();
388 }
389 if (mGPUReco->registerMemoryForGPU(info.ptr, info.size)) {
390 throw std::runtime_error("Error registering memory for GPU");
391 }
392 if (mConfParam->benchmarkMemoryRegistration) {
393 end = std::chrono::high_resolution_clock::now();
394 std::chrono::duration<double> elapsed_seconds = end - start;
395 LOG(info) << "Memory registration time (0x" << info.ptr << ", " << info.size << " bytes): " << elapsed_seconds.count() << " s";
396 }
397 if (mConfParam->mutexMemReg) {
398 if (lockf(fd, F_ULOCK, 0)) {
399 throw std::runtime_error("Error unlocking memlock mutex file");
400 }
401 close(fd);
402 }
403 });
404
405 mTimer->Stop();
406 mTimer->Reset();
407}
408
410{
411 LOGF(info, "GPU Reconstruction total timing: Cpu: %.3e Real: %.3e s in %d slots", mTimer->CpuTime(), mTimer->RealTime(), mTimer->Counter() - 1);
412 handlePipelineStop();
413}
414
416{
417 handlePipelineEndOfStream(ec);
418}
419
421{
422 if (mSpecConfig.enableDoublePipeline != 2) {
423 finaliseCCDBTPC(matcher, obj);
424 if (mSpecConfig.runITSTracking) {
425 finaliseCCDBITS(matcher, obj);
426 }
427 }
428 if (GRPGeomHelper::instance().finaliseCCDB(matcher, obj)) {
429 mGRPGeomUpdated = true;
430 return;
431 }
432}
433
434template <class D, class E, class F, class G, class H, class I, class J, class K>
435void GPURecoWorkflowSpec::processInputs(ProcessingContext& pc, D& tpcZSmeta, E& inputZS, F& tpcZS, G& tpcZSonTheFlySizes, bool& debugTFDump, H& compClustersDummy, I& compClustersFlatDummy, J& pCompClustersFlat, K& tmpEmptyCompClusters)
436{
437 if (mSpecConfig.enableDoublePipeline == 1) {
438 return;
439 }
440 constexpr static size_t NSectors = o2::tpc::Sector::MAXSECTOR;
441 constexpr static size_t NEndpoints = o2::gpu::GPUTrackingInOutZS::NENDPOINTS;
442
443 if (mSpecConfig.zsOnTheFly || mSpecConfig.zsDecoder) {
444 for (uint32_t i = 0; i < GPUTrackingInOutZS::NSECTORS; i++) {
445 for (uint32_t j = 0; j < GPUTrackingInOutZS::NENDPOINTS; j++) {
446 tpcZSmeta.Pointers[i][j].clear();
447 tpcZSmeta.Sizes[i][j].clear();
448 }
449 }
450 }
451 if (mSpecConfig.zsOnTheFly) {
452 tpcZSonTheFlySizes = {0};
453 // tpcZSonTheFlySizes: #zs pages per endpoint:
454 std::vector<InputSpec> filter = {{"check", ConcreteDataTypeMatcher{gDataOriginTPC, "ZSSIZES"}, Lifetime::Timeframe}};
455 bool recv = false, recvsizes = false;
456 for (auto const& ref : InputRecordWalker(pc.inputs(), filter)) {
457 if (recvsizes) {
458 throw std::runtime_error("Received multiple ZSSIZES data");
459 }
460 tpcZSonTheFlySizes = pc.inputs().get<std::array<uint32_t, NEndpoints * NSectors>>(ref);
461 recvsizes = true;
462 }
463 // zs pages
464 std::vector<InputSpec> filter2 = {{"check", ConcreteDataTypeMatcher{gDataOriginTPC, "TPCZS"}, Lifetime::Timeframe}};
465 for (auto const& ref : InputRecordWalker(pc.inputs(), filter2)) {
466 if (recv) {
467 throw std::runtime_error("Received multiple TPCZS data");
468 }
469 inputZS = pc.inputs().get<gsl::span<o2::tpc::ZeroSuppressedContainer8kb>>(ref);
470 recv = true;
471 }
472 if (!recv || !recvsizes) {
473 throw std::runtime_error("TPC ZS on the fly data not received");
474 }
475
476 uint32_t offset = 0;
477 for (uint32_t i = 0; i < NSectors; i++) {
478 uint32_t pageSector = 0;
479 for (uint32_t j = 0; j < NEndpoints; j++) {
480 pageSector += tpcZSonTheFlySizes[i * NEndpoints + j];
481 offset += tpcZSonTheFlySizes[i * NEndpoints + j];
482 }
483 if (mVerbosity >= 1) {
484 LOG(info) << "GOT ZS on the fly pages FOR SECTOR " << i << " -> pages: " << pageSector;
485 }
486 }
487 }
488 if (mSpecConfig.zsDecoder) {
489 std::vector<InputSpec> filter = {{"check", ConcreteDataTypeMatcher{gDataOriginTPC, "RAWDATA"}, Lifetime::Timeframe}};
490 auto isSameRdh = [](const char* left, const char* right) -> bool {
491 return o2::raw::RDHUtils::getFEEID(left) == o2::raw::RDHUtils::getFEEID(right) && o2::raw::RDHUtils::getDetectorField(left) == o2::raw::RDHUtils::getDetectorField(right);
492 };
493 auto checkForZSData = [](const char* ptr, uint32_t subSpec) -> bool {
494 const auto rdhLink = o2::raw::RDHUtils::getLinkID(ptr);
495 const auto detField = o2::raw::RDHUtils::getDetectorField(ptr);
496 const auto feeID = o2::raw::RDHUtils::getFEEID(ptr);
497 const auto feeLinkID = o2::tpc::rdh_utils::getLink(feeID);
498 // This check is not what it is supposed to be, but some MC SYNTHETIC data was generated with rdhLinkId set to feeLinkId, so we add some extra logic so we can still decode it
499 return detField == o2::tpc::raw_data_types::ZS && ((feeLinkID == o2::tpc::rdh_utils::UserLogicLinkID && (rdhLink == o2::tpc::rdh_utils::UserLogicLinkID || rdhLink == 0)) ||
500 (feeLinkID == o2::tpc::rdh_utils::ILBZSLinkID && (rdhLink == o2::tpc::rdh_utils::UserLogicLinkID || rdhLink == o2::tpc::rdh_utils::ILBZSLinkID || rdhLink == 0)) ||
501 (feeLinkID == o2::tpc::rdh_utils::DLBZSLinkID && (rdhLink == o2::tpc::rdh_utils::UserLogicLinkID || rdhLink == o2::tpc::rdh_utils::DLBZSLinkID || rdhLink == 0)));
502 };
503 auto insertPages = [&tpcZSmeta, checkForZSData](const char* ptr, size_t count, uint32_t subSpec) -> void {
504 if (checkForZSData(ptr, subSpec)) {
505 int32_t rawcru = o2::tpc::rdh_utils::getCRU(ptr);
506 int32_t rawendpoint = o2::tpc::rdh_utils::getEndPoint(ptr);
507 tpcZSmeta.Pointers[rawcru / 10][(rawcru % 10) * 2 + rawendpoint].emplace_back(ptr);
508 tpcZSmeta.Sizes[rawcru / 10][(rawcru % 10) * 2 + rawendpoint].emplace_back(count);
509 }
510 };
511 if (DPLRawPageSequencer(pc.inputs(), filter)(isSameRdh, insertPages, checkForZSData)) {
512 debugTFDump = true;
513 static uint32_t nErrors = 0;
514 nErrors++;
515 if (nErrors == 1 || (nErrors < 100 && nErrors % 10 == 0) || nErrors % 1000 == 0 || mNTFs % 1000 == 0) {
516 LOG(error) << "DPLRawPageSequencer failed to process TPC raw data - data most likely not padded correctly - Using slow page scan instead (this alarm is downscaled from now on, so far " << nErrors << " of " << mNTFs << " TFs affected)";
517 }
518 }
519
520 int32_t totalCount = 0;
521 for (uint32_t i = 0; i < GPUTrackingInOutZS::NSECTORS; i++) {
522 for (uint32_t j = 0; j < GPUTrackingInOutZS::NENDPOINTS; j++) {
523 tpcZSmeta.Pointers2[i][j] = tpcZSmeta.Pointers[i][j].data();
524 tpcZSmeta.Sizes2[i][j] = tpcZSmeta.Sizes[i][j].data();
525 tpcZS.sector[i].zsPtr[j] = tpcZSmeta.Pointers2[i][j];
526 tpcZS.sector[i].nZSPtr[j] = tpcZSmeta.Sizes2[i][j];
527 tpcZS.sector[i].count[j] = tpcZSmeta.Pointers[i][j].size();
528 totalCount += tpcZSmeta.Pointers[i][j].size();
529 }
530 }
531 } else if (mSpecConfig.decompressTPC) {
532 if (mSpecConfig.decompressTPCFromROOT) {
533 compClustersDummy = *pc.inputs().get<o2::tpc::CompressedClustersROOT*>("input");
534 compClustersFlatDummy.setForward(&compClustersDummy);
535 pCompClustersFlat = &compClustersFlatDummy;
536 } else {
537 pCompClustersFlat = pc.inputs().get<o2::tpc::CompressedClustersFlat*>("input").get();
538 }
539 if (pCompClustersFlat == nullptr) {
540 tmpEmptyCompClusters.reset(new char[sizeof(o2::tpc::CompressedClustersFlat)]);
541 memset(tmpEmptyCompClusters.get(), 0, sizeof(o2::tpc::CompressedClustersFlat));
542 pCompClustersFlat = (o2::tpc::CompressedClustersFlat*)tmpEmptyCompClusters.get();
543 }
544 } else if (!mSpecConfig.zsOnTheFly) {
545 if (mVerbosity) {
546 LOGF(info, "running tracking for sector(s) 0x%09x", mTPCSectorMask);
547 }
548 }
549}
550
551int32_t GPURecoWorkflowSpec::runMain(o2::framework::ProcessingContext* pc, GPUTrackingInOutPointers* ptrs, GPUInterfaceOutputs* outputRegions, int32_t threadIndex, GPUInterfaceInputUpdate* inputUpdateCallback)
552{
553 int32_t retVal = 0;
554 if (mConfParam->dump < 2) {
555 retVal = mGPUReco->RunTracking(ptrs, outputRegions, threadIndex, inputUpdateCallback);
556
557 if (retVal == 0 && mSpecConfig.runITSTracking) {
558 retVal = runITSTracking(*pc);
559 }
560 }
561
562 if (!mSpecConfig.enableDoublePipeline) { // TODO: Why is this needed for double-pipeline?
563 mGPUReco->Clear(false, threadIndex); // clean non-output memory used by GPU Reconstruction
564 }
565 return retVal;
566}
567
568void GPURecoWorkflowSpec::cleanOldCalibsTPCPtrs(calibObjectStruct& oldCalibObjects)
569{
570 if (mOldCalibObjects.size() > 0) {
571 mOldCalibObjects.pop();
572 }
573 mOldCalibObjects.emplace(std::move(oldCalibObjects));
574}
575
577{
578 constexpr static size_t NSectors = o2::tpc::Sector::MAXSECTOR;
579 constexpr static size_t NEndpoints = o2::gpu::GPUTrackingInOutZS::NENDPOINTS;
580
581 auto cput = mTimer->CpuTime();
582 auto realt = mTimer->RealTime();
583 mTimer->Start(false);
584 mNTFs++;
585
586 std::vector<gsl::span<const char>> inputs;
587
588 const o2::tpc::CompressedClustersFlat* pCompClustersFlat = nullptr;
589 size_t compClustersFlatDummyMemory[(sizeof(o2::tpc::CompressedClustersFlat) + sizeof(size_t) - 1) / sizeof(size_t)];
590 o2::tpc::CompressedClustersFlat& compClustersFlatDummy = reinterpret_cast<o2::tpc::CompressedClustersFlat&>(compClustersFlatDummyMemory);
591 o2::tpc::CompressedClusters compClustersDummy;
594 std::array<uint32_t, NEndpoints * NSectors> tpcZSonTheFlySizes;
595 gsl::span<const o2::tpc::ZeroSuppressedContainer8kb> inputZS;
596 std::unique_ptr<char[]> tmpEmptyCompClusters;
597
598 bool getWorkflowTPCInput_clusters = false, getWorkflowTPCInput_mc = false, getWorkflowTPCInput_digits = false;
599 bool debugTFDump = false;
600
601 if (mSpecConfig.processMC) {
602 getWorkflowTPCInput_mc = true;
603 }
604 if (!mSpecConfig.decompressTPC && !mSpecConfig.caClusterer) {
605 getWorkflowTPCInput_clusters = true;
606 }
607 if (!mSpecConfig.decompressTPC && mSpecConfig.caClusterer && ((!mSpecConfig.zsOnTheFly || mSpecConfig.processMC) && !mSpecConfig.zsDecoder)) {
608 getWorkflowTPCInput_digits = true;
609 }
610
611 // ------------------------------ Handle inputs ------------------------------
612
613 auto lockDecodeInput = std::make_unique<std::lock_guard<std::mutex>>(mPipeline->mutexDecodeInput);
614
616 if (pc.inputs().getPos("itsTGeo") >= 0) {
617 pc.inputs().get<o2::its::GeometryTGeo*>("itsTGeo");
618 }
619 if (GRPGeomHelper::instance().getGRPECS()->isDetReadOut(o2::detectors::DetID::TPC) && mConfParam->tpcTriggeredMode ^ !GRPGeomHelper::instance().getGRPECS()->isDetContinuousReadOut(o2::detectors::DetID::TPC)) {
620 LOG(fatal) << "configKeyValue tpcTriggeredMode does not match GRP isDetContinuousReadOut(TPC) setting";
621 }
622
624 processInputs(pc, tpcZSmeta, inputZS, tpcZS, tpcZSonTheFlySizes, debugTFDump, compClustersDummy, compClustersFlatDummy, pCompClustersFlat, tmpEmptyCompClusters); // Process non-digit / non-cluster inputs
625 const auto& inputsClustersDigits = o2::tpc::getWorkflowTPCInput(pc, mVerbosity, getWorkflowTPCInput_mc, getWorkflowTPCInput_clusters, mTPCSectorMask, getWorkflowTPCInput_digits); // Process digit and cluster inputs
626
627 const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
628 mTFSettings->tfStartOrbit = tinfo.firstTForbit;
629 mTFSettings->hasTfStartOrbit = 1;
630 mTFSettings->hasNHBFPerTF = 1;
631 mTFSettings->nHBFPerTF = mConfParam->overrideNHbfPerTF ? mConfParam->overrideNHbfPerTF : GRPGeomHelper::instance().getGRPECS()->getNHBFPerTF();
632 mTFSettings->hasRunStartOrbit = 0;
633 if (mVerbosity) {
634 LOG(info) << "TF firstTForbit " << mTFSettings->tfStartOrbit << " nHBF " << mTFSettings->nHBFPerTF << " runStartOrbit " << mTFSettings->runStartOrbit << " simStartOrbit " << mTFSettings->simStartOrbit;
635 }
636 ptrs.settingsTF = mTFSettings.get();
637
638 if (mConfParam->checkFirstTfOrbit) {
639 static uint32_t lastFirstTFOrbit = -1;
640 static uint32_t lastTFCounter = -1;
641 if (lastFirstTFOrbit != -1 && lastTFCounter != -1) {
642 int32_t diffOrbit = tinfo.firstTForbit - lastFirstTFOrbit;
643 int32_t diffCounter = tinfo.tfCounter - lastTFCounter;
644 if (diffOrbit != diffCounter * mTFSettings->nHBFPerTF) {
645 LOG(error) << "Time frame has mismatching firstTfOrbit - Last orbit/counter: " << lastFirstTFOrbit << " " << lastTFCounter << " - Current: " << tinfo.firstTForbit << " " << tinfo.tfCounter;
646 }
647 }
648 lastFirstTFOrbit = tinfo.firstTForbit;
649 lastTFCounter = tinfo.tfCounter;
650 }
651
653 decltype(o2::trd::getRecoInputContainer(pc, &ptrs, &inputTracksTRD)) trdInputContainer;
654 if (mSpecConfig.readTRDtracklets) {
655 o2::globaltracking::DataRequest dataRequestTRD;
657 inputTracksTRD.collectData(pc, dataRequestTRD);
658 trdInputContainer = std::move(o2::trd::getRecoInputContainer(pc, &ptrs, &inputTracksTRD));
659 }
660
661 void* ptrEp[NSectors * NEndpoints] = {};
662 bool doInputDigits = false, doInputDigitsMC = false;
663 if (mSpecConfig.decompressTPC) {
664 ptrs.tpcCompressedClusters = pCompClustersFlat;
665 } else if (mSpecConfig.zsOnTheFly) {
666 const uint64_t* buffer = reinterpret_cast<const uint64_t*>(&inputZS[0]);
667 o2::gpu::GPUReconstructionConvert::RunZSEncoderCreateMeta(buffer, tpcZSonTheFlySizes.data(), *&ptrEp, &tpcZS);
668 ptrs.tpcZS = &tpcZS;
669 doInputDigits = doInputDigitsMC = mSpecConfig.processMC;
670 } else if (mSpecConfig.zsDecoder) {
671 ptrs.tpcZS = &tpcZS;
672 if (mSpecConfig.processMC) {
673 throw std::runtime_error("Cannot process MC information, none available");
674 }
675 } else if (mSpecConfig.caClusterer) {
676 doInputDigits = true;
677 doInputDigitsMC = mSpecConfig.processMC;
678 } else {
679 ptrs.clustersNative = &inputsClustersDigits->clusterIndex;
680 }
681
682 if (mTPCSectorMask != 0xFFFFFFFFF) {
683 // Clean out the unused sectors, such that if they were present by chance, they are not processed, and if the values are uninitialized, we should not crash
684 for (uint32_t i = 0; i < NSectors; i++) {
685 if (!(mTPCSectorMask & (1ul << i))) {
686 if (ptrs.tpcZS) {
687 for (uint32_t j = 0; j < GPUTrackingInOutZS::NENDPOINTS; j++) {
688 tpcZS.sector[i].zsPtr[j] = nullptr;
689 tpcZS.sector[i].nZSPtr[j] = nullptr;
690 tpcZS.sector[i].count[j] = 0;
691 }
692 }
693 }
694 }
695 }
696
697 GPUTrackingInOutDigits tpcDigitsMap;
698 GPUTPCDigitsMCInput tpcDigitsMapMC;
699 if (doInputDigits) {
700 ptrs.tpcPackedDigits = &tpcDigitsMap;
701 if (doInputDigitsMC) {
702 tpcDigitsMap.tpcDigitsMC = &tpcDigitsMapMC;
703 }
704 for (uint32_t i = 0; i < NSectors; i++) {
705 tpcDigitsMap.tpcDigits[i] = inputsClustersDigits->inputDigits[i].data();
706 tpcDigitsMap.nTPCDigits[i] = inputsClustersDigits->inputDigits[i].size();
707 if (doInputDigitsMC) {
708 tpcDigitsMapMC.v[i] = inputsClustersDigits->inputDigitsMCPtrs[i];
709 }
710 }
711 }
712
713 o2::tpc::TPCSectorHeader clusterOutputSectorHeader{0};
714 if (mClusterOutputIds.size() > 0) {
715 clusterOutputSectorHeader.sectorBits = mTPCSectorMask;
716 // subspecs [0, NSectors - 1] are used to identify sector data, we use NSectors to indicate the full TPC
717 clusterOutputSectorHeader.activeSectors = mTPCSectorMask;
718 }
719
720 // ------------------------------ Prepare stage for double-pipeline before normal output preparation ------------------------------
721
722 std::unique_ptr<GPURecoWorkflow_QueueObject> pipelineContext;
723 if (mSpecConfig.enableDoublePipeline) {
724 if (handlePipeline(pc, ptrs, tpcZSmeta, tpcZS, pipelineContext)) {
725 return;
726 }
727 }
728
729 // ------------------------------ Prepare outputs ------------------------------
730
731 GPUInterfaceOutputs outputRegions;
732 using outputDataType = char;
733 using outputBufferUninitializedVector = std::decay_t<decltype(pc.outputs().make<DataAllocator::UninitializedVector<outputDataType>>(Output{"", "", 0}))>;
734 using outputBufferType = std::pair<std::optional<std::reference_wrapper<outputBufferUninitializedVector>>, outputDataType*>;
735 std::vector<outputBufferType> outputBuffers(GPUInterfaceOutputs::count(), {std::nullopt, nullptr});
736 std::unordered_set<std::string> outputsCreated;
737
738 auto setOutputAllocator = [this, &outputBuffers, &outputRegions, &pc, &outputsCreated](const char* name, bool condition, GPUOutputControl& region, auto&& outputSpec, size_t offset = 0) {
739 if (condition) {
740 auto& buffer = outputBuffers[outputRegions.getIndex(region)];
741 if (mConfParam->allocateOutputOnTheFly) {
742 region.allocator = [this, name, &buffer, &pc, outputSpec = std::move(outputSpec), offset, &outputsCreated](size_t size) -> void* {
743 size += offset;
744 if (mVerbosity) {
745 LOG(info) << "ALLOCATING " << size << " bytes for " << name << ": " << std::get<DataOrigin>(outputSpec).template as<std::string>() << "/" << std::get<DataDescription>(outputSpec).template as<std::string>() << "/" << std::get<2>(outputSpec);
746 }
747 std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
748 if (mVerbosity) {
749 start = std::chrono::high_resolution_clock::now();
750 }
751 buffer.first.emplace(pc.outputs().make<DataAllocator::UninitializedVector<outputDataType>>(std::make_from_tuple<Output>(outputSpec), size));
752 outputsCreated.insert(name);
753 if (mVerbosity) {
754 end = std::chrono::high_resolution_clock::now();
755 std::chrono::duration<double> elapsed_seconds = end - start;
756 LOG(info) << "Allocation time for " << name << " (" << size << " bytes)"
757 << ": " << elapsed_seconds.count() << "s";
758 }
759 return (buffer.second = buffer.first->get().data()) + offset;
760 };
761 } else {
762 buffer.first.emplace(pc.outputs().make<DataAllocator::UninitializedVector<outputDataType>>(std::make_from_tuple<Output>(outputSpec), mConfParam->outputBufferSize));
763 region.ptrBase = (buffer.second = buffer.first->get().data()) + offset;
764 region.size = buffer.first->get().size() - offset;
765 outputsCreated.insert(name);
766 }
767 }
768 };
769
770 auto downSizeBuffer = [](outputBufferType& buffer, size_t size) {
771 if (!buffer.first) {
772 return;
773 }
774 if (buffer.first->get().size() < size) {
775 throw std::runtime_error("Invalid buffer size requested");
776 }
777 buffer.first->get().resize(size);
778 if (size && buffer.first->get().data() != buffer.second) {
779 throw std::runtime_error("Inconsistent buffer address after downsize");
780 }
781 };
782
783 /*auto downSizeBufferByName = [&outputBuffers, &outputRegions, &downSizeBuffer](GPUOutputControl& region, size_t size) {
784 auto& buffer = outputBuffers[outputRegions.getIndex(region)];
785 downSizeBuffer(buffer, size);
786 };*/
787
788 auto downSizeBufferToSpan = [&outputBuffers, &outputRegions, &downSizeBuffer](GPUOutputControl& region, auto span) {
789 auto& buffer = outputBuffers[outputRegions.getIndex(region)];
790 if (!buffer.first) {
791 return;
792 }
793 if (span.size() && buffer.second != (char*)span.data()) {
794 throw std::runtime_error("Buffer does not match span");
795 }
796 downSizeBuffer(buffer, span.size() * sizeof(*span.data()));
797 };
798
799 setOutputAllocator("COMPCLUSTERSFLAT", mSpecConfig.outputCompClustersFlat, outputRegions.compressedClusters, std::make_tuple(gDataOriginTPC, (DataDescription) "COMPCLUSTERSFLAT", 0));
800 setOutputAllocator("CLUSTERNATIVE", mClusterOutputIds.size() > 0, outputRegions.clustersNative, std::make_tuple(gDataOriginTPC, mSpecConfig.sendClustersPerSector ? (DataDescription) "CLUSTERNATIVETMP" : (DataDescription) "CLUSTERNATIVE", NSectors, clusterOutputSectorHeader), sizeof(o2::tpc::ClusterCountIndex));
801 setOutputAllocator("CLSHAREDMAP", mSpecConfig.outputSharedClusterMap, outputRegions.sharedClusterMap, std::make_tuple(gDataOriginTPC, (DataDescription) "CLSHAREDMAP", 0));
802 setOutputAllocator("TPCOCCUPANCYMAP", mSpecConfig.outputSharedClusterMap, outputRegions.tpcOccupancyMap, std::make_tuple(gDataOriginTPC, (DataDescription) "TPCOCCUPANCYMAP", 0));
803 setOutputAllocator("TRACKS", mSpecConfig.outputTracks, outputRegions.tpcTracksO2, std::make_tuple(gDataOriginTPC, (DataDescription) "TRACKS", 0));
804 setOutputAllocator("CLUSREFS", mSpecConfig.outputTracks, outputRegions.tpcTracksO2ClusRefs, std::make_tuple(gDataOriginTPC, (DataDescription) "CLUSREFS", 0));
805 setOutputAllocator("TRACKSMCLBL", mSpecConfig.outputTracks && mSpecConfig.processMC, outputRegions.tpcTracksO2Labels, std::make_tuple(gDataOriginTPC, (DataDescription) "TRACKSMCLBL", 0));
806 setOutputAllocator("TRIGGERWORDS", mSpecConfig.caClusterer && mConfig->configProcessing.param.tpcTriggerHandling, outputRegions.tpcTriggerWords, std::make_tuple(gDataOriginTPC, (DataDescription) "TRIGGERWORDS", 0));
808 if (mSpecConfig.processMC && mSpecConfig.caClusterer) {
809 outputRegions.clusterLabels.allocator = [&clustersMCBuffer](size_t size) -> void* { return &clustersMCBuffer; };
810 }
811
812 // ------------------------------ Actual processing ------------------------------
813
814 if ((int32_t)(ptrs.tpcZS != nullptr) + (int32_t)(ptrs.tpcPackedDigits != nullptr && (ptrs.tpcZS == nullptr || ptrs.tpcPackedDigits->tpcDigitsMC == nullptr)) + (int32_t)(ptrs.clustersNative != nullptr) + (int32_t)(ptrs.tpcCompressedClusters != nullptr) != 1) {
815 throw std::runtime_error("Invalid input for gpu tracking");
816 }
817
818 const auto& holdData = o2::tpc::TPCTrackingDigitsPreCheck::runPrecheck(&ptrs, mConfig.get());
819
820 calibObjectStruct oldCalibObjects;
821 doCalibUpdates(pc, oldCalibObjects);
822
823 lockDecodeInput.reset();
824
825 if (mConfParam->dump) {
826 if (mNTFs == 1) {
827 mGPUReco->DumpSettings();
828 }
829 mGPUReco->DumpEvent(mNTFs - 1, &ptrs);
830 }
831 std::unique_ptr<GPUTrackingInOutPointers> ptrsDump;
832 if (mConfParam->dumpBadTFMode == 2) {
833 ptrsDump.reset(new GPUTrackingInOutPointers);
834 memcpy((void*)ptrsDump.get(), (const void*)&ptrs, sizeof(ptrs));
835 }
836
837 int32_t retVal = 0;
838 if (mSpecConfig.enableDoublePipeline) {
839 if (!pipelineContext->jobSubmitted) {
840 enqueuePipelinedJob(&ptrs, &outputRegions, pipelineContext.get(), true);
841 } else {
842 finalizeInputPipelinedJob(&ptrs, &outputRegions, pipelineContext.get());
843 }
844 std::unique_lock lk(pipelineContext->jobFinishedMutex);
845 pipelineContext->jobFinishedNotify.wait(lk, [context = pipelineContext.get()]() { return context->jobFinished; });
846 retVal = pipelineContext->jobReturnValue;
847 } else {
848 // uint32_t threadIndex = pc.services().get<ThreadPool>().threadIndex;
849 uint32_t threadIndex = mNextThreadIndex;
850 if (mConfig->configProcessing.doublePipeline) {
851 mNextThreadIndex = (mNextThreadIndex + 1) % 2;
852 }
853
854 retVal = runMain(&pc, &ptrs, &outputRegions, threadIndex);
855 }
856 if (retVal != 0) {
857 debugTFDump = true;
858 }
859 cleanOldCalibsTPCPtrs(oldCalibObjects);
860
861 o2::utils::DebugStreamer::instance()->flush(); // flushing debug output to file
862
863 if (debugTFDump && mNDebugDumps < mConfParam->dumpBadTFs) {
864 mNDebugDumps++;
865 if (mConfParam->dumpBadTFMode <= 1) {
866 std::string filename = std::string("tpc_dump_") + std::to_string(pc.services().get<const o2::framework::DeviceSpec>().inputTimesliceId) + "_" + std::to_string(mNDebugDumps) + ".dump";
867 FILE* fp = fopen(filename.c_str(), "w+b");
868 std::vector<InputSpec> filter = {{"check", ConcreteDataTypeMatcher{gDataOriginTPC, "RAWDATA"}, Lifetime::Timeframe}};
869 for (auto const& ref : InputRecordWalker(pc.inputs(), filter)) {
870 auto data = pc.inputs().get<gsl::span<char>>(ref);
871 if (mConfParam->dumpBadTFMode == 1) {
872 uint64_t size = data.size();
873 fwrite(&size, 1, sizeof(size), fp);
874 }
875 fwrite(data.data(), 1, data.size(), fp);
876 }
877 fclose(fp);
878 } else if (mConfParam->dumpBadTFMode == 2) {
879 mGPUReco->DumpEvent(mNDebugDumps - 1, ptrsDump.get());
880 }
881 }
882
883 if (mConfParam->dump == 2) {
884 return;
885 }
886
887 // ------------------------------ Varios postprocessing steps ------------------------------
888
889 bool createEmptyOutput = false;
890 if (retVal != 0) {
891 if (retVal == 3 && mConfig->configProcessing.ignoreNonFatalGPUErrors) {
892 if (mConfig->configProcessing.throttleAlarms) {
893 LOG(warning) << "GPU Reconstruction aborted with non fatal error code, ignoring";
894 } else {
895 LOG(alarm) << "GPU Reconstruction aborted with non fatal error code, ignoring";
896 }
897 createEmptyOutput = !mConfParam->partialOutputForNonFatalErrors;
898 } else {
899 throw std::runtime_error("GPU Reconstruction error: error code " + std::to_string(retVal));
900 }
901 }
902
903 std::unique_ptr<o2::tpc::ClusterNativeAccess> tmpEmptyClNative;
904 if (createEmptyOutput) {
905 memset(&ptrs, 0, sizeof(ptrs));
906 for (uint32_t i = 0; i < outputRegions.count(); i++) {
907 if (outputBuffers[i].first) {
908 size_t toSize = 0;
909 if (i == outputRegions.getIndex(outputRegions.compressedClusters)) {
910 toSize = sizeof(*ptrs.tpcCompressedClusters);
911 } else if (i == outputRegions.getIndex(outputRegions.clustersNative)) {
912 toSize = sizeof(o2::tpc::ClusterCountIndex);
913 }
914 outputBuffers[i].first->get().resize(toSize);
915 outputBuffers[i].second = outputBuffers[i].first->get().data();
916 if (toSize) {
917 memset(outputBuffers[i].second, 0, toSize);
918 }
919 }
920 }
921 tmpEmptyClNative = std::make_unique<o2::tpc::ClusterNativeAccess>();
922 memset(tmpEmptyClNative.get(), 0, sizeof(*tmpEmptyClNative));
923 ptrs.clustersNative = tmpEmptyClNative.get();
924 if (mSpecConfig.processMC) {
925 MCLabelContainer cont;
926 cont.flatten_to(clustersMCBuffer.first);
927 clustersMCBuffer.second = clustersMCBuffer.first;
928 tmpEmptyClNative->clustersMCTruth = &clustersMCBuffer.second;
929 }
930 } else {
931 gsl::span<const o2::tpc::TrackTPC> spanOutputTracks = {ptrs.outputTracksTPCO2, ptrs.nOutputTracksTPCO2};
932 gsl::span<const uint32_t> spanOutputClusRefs = {ptrs.outputClusRefsTPCO2, ptrs.nOutputClusRefsTPCO2};
933 gsl::span<const o2::MCCompLabel> spanOutputTracksMCTruth = {ptrs.outputTracksTPCO2MC, ptrs.outputTracksTPCO2MC ? ptrs.nOutputTracksTPCO2 : 0};
934 if (!mConfParam->allocateOutputOnTheFly) {
935 for (uint32_t i = 0; i < outputRegions.count(); i++) {
936 if (outputRegions.asArray()[i].ptrBase) {
937 if (outputRegions.asArray()[i].size == 1) {
938 throw std::runtime_error("Preallocated buffer size exceeded");
939 }
940 outputRegions.asArray()[i].checkCurrent();
941 downSizeBuffer(outputBuffers[i], (char*)outputRegions.asArray()[i].ptrCurrent - (char*)outputBuffers[i].second);
942 }
943 }
944 }
945 downSizeBufferToSpan(outputRegions.tpcTracksO2, spanOutputTracks);
946 downSizeBufferToSpan(outputRegions.tpcTracksO2ClusRefs, spanOutputClusRefs);
947 downSizeBufferToSpan(outputRegions.tpcTracksO2Labels, spanOutputTracksMCTruth);
948
949 // if requested, tune TPC tracks
950 if (ptrs.nOutputTracksTPCO2) {
951 doTrackTuneTPC(ptrs, outputBuffers[outputRegions.getIndex(outputRegions.tpcTracksO2)].first->get().data());
952 }
953
954 if (mClusterOutputIds.size() > 0 && (void*)ptrs.clustersNative->clustersLinear != (void*)(outputBuffers[outputRegions.getIndex(outputRegions.clustersNative)].second + sizeof(o2::tpc::ClusterCountIndex))) {
955 throw std::runtime_error("cluster native output ptrs out of sync"); // sanity check
956 }
957 }
958
959 if (mConfig->configWorkflow.outputs.isSet(GPUDataTypes::InOutType::TPCMergedTracks)) {
960 LOG(info) << "found " << ptrs.nOutputTracksTPCO2 << " track(s)";
961 }
962
963 if (mSpecConfig.outputCompClusters) {
966 }
967
968 if (mClusterOutputIds.size() > 0) {
969 o2::tpc::ClusterNativeAccess const& accessIndex = *ptrs.clustersNative;
970 if (mSpecConfig.sendClustersPerSector) {
971 // Clusters are shipped by sector, we are copying into per-sector buffers (anyway only for ROOT output)
972 for (uint32_t i = 0; i < NSectors; i++) {
973 if (mTPCSectorMask & (1ul << i)) {
975 clusterOutputSectorHeader.sectorBits = (1ul << i);
976 char* buffer = pc.outputs().make<char>({gDataOriginTPC, "CLUSTERNATIVE", subspec, {clusterOutputSectorHeader}}, accessIndex.nClustersSector[i] * sizeof(*accessIndex.clustersLinear) + sizeof(o2::tpc::ClusterCountIndex)).data();
977 o2::tpc::ClusterCountIndex* outIndex = reinterpret_cast<o2::tpc::ClusterCountIndex*>(buffer);
978 memset(outIndex, 0, sizeof(*outIndex));
979 for (int32_t j = 0; j < o2::tpc::constants::MAXGLOBALPADROW; j++) {
980 outIndex->nClusters[i][j] = accessIndex.nClusters[i][j];
981 }
982 memcpy(buffer + sizeof(*outIndex), accessIndex.clusters[i][0], accessIndex.nClustersSector[i] * sizeof(*accessIndex.clustersLinear));
983 if (mSpecConfig.processMC && accessIndex.clustersMCTruth) {
984 MCLabelContainer cont;
985 for (uint32_t j = 0; j < accessIndex.nClustersSector[i]; j++) {
986 const auto& labels = accessIndex.clustersMCTruth->getLabels(accessIndex.clusterOffset[i][0] + j);
987 for (const auto& label : labels) {
988 cont.addElement(j, label);
989 }
990 }
991 ConstMCLabelContainer contflat;
992 cont.flatten_to(contflat);
993 pc.outputs().snapshot({gDataOriginTPC, "CLNATIVEMCLBL", subspec, {clusterOutputSectorHeader}}, contflat);
994 }
995 }
996 }
997 } else {
998 // Clusters are shipped as single message, fill ClusterCountIndex
999 DataHeader::SubSpecificationType subspec = NSectors;
1000 o2::tpc::ClusterCountIndex* outIndex = reinterpret_cast<o2::tpc::ClusterCountIndex*>(outputBuffers[outputRegions.getIndex(outputRegions.clustersNative)].second);
1001 static_assert(sizeof(o2::tpc::ClusterCountIndex) == sizeof(accessIndex.nClusters));
1002 memcpy(outIndex, &accessIndex.nClusters[0][0], sizeof(o2::tpc::ClusterCountIndex));
1003 if (mSpecConfig.processMC && mSpecConfig.caClusterer && accessIndex.clustersMCTruth) {
1004 pc.outputs().snapshot({gDataOriginTPC, "CLNATIVEMCLBL", subspec, {clusterOutputSectorHeader}}, clustersMCBuffer.first);
1005 }
1006 }
1007 }
1008 if (mSpecConfig.outputQA) {
1009 TObjArray out;
1010 bool sendQAOutput = !createEmptyOutput && outputRegions.qa.newQAHistsCreated;
1011 auto getoutput = [sendQAOutput](auto ptr) { return sendQAOutput && ptr ? *ptr : std::decay_t<decltype(*ptr)>(); };
1012 std::vector<TH1F> copy1 = getoutput(outputRegions.qa.hist1); // Internally, this will also be used as output, so we need a non-const copy
1013 std::vector<TH2F> copy2 = getoutput(outputRegions.qa.hist2);
1014 std::vector<TH1D> copy3 = getoutput(outputRegions.qa.hist3);
1015 std::vector<TGraphAsymmErrors> copy4 = getoutput(outputRegions.qa.hist4);
1016 if (sendQAOutput) {
1017 mQA->postprocessExternal(copy1, copy2, copy3, copy4, out, mQATaskMask ? mQATaskMask : -1);
1018 }
1019 pc.outputs().snapshot({gDataOriginTPC, "TRACKINGQA", 0}, out);
1020 if (sendQAOutput) {
1021 mQA->cleanup();
1022 }
1023 }
1024 if (mSpecConfig.outputErrorQA) {
1025 pc.outputs().snapshot({gDataOriginGPU, "ERRORQA", 0}, mErrorQA);
1026 mErrorQA.clear(); // FIXME: This is a race condition once we run multi-threaded!
1027 }
1028 if (mSpecConfig.outputSharedClusterMap && !outputsCreated.contains("TPCOCCUPANCYMAP")) {
1030 }
1031 if (mSpecConfig.tpcTriggerHandling && !outputsCreated.contains("TRIGGERWORDS")) {
1033 }
1034 mTimer->Stop();
1035 LOG(info) << "GPU Reconstruction time for this TF " << mTimer->CpuTime() - cput << " s (cpu), " << mTimer->RealTime() - realt << " s (wall)";
1036}
1037
1038void GPURecoWorkflowSpec::doCalibUpdates(o2::framework::ProcessingContext& pc, calibObjectStruct& oldCalibObjects)
1039{
1040 GPUCalibObjectsConst newCalibObjects;
1041 GPUNewCalibValues newCalibValues;
1042 // check for updates of TPC calibration objects
1043 bool needCalibUpdate = false;
1044 if (mGRPGeomUpdated) {
1045 mGRPGeomUpdated = false;
1046 needCalibUpdate = true;
1047
1048 if (!mITSGeometryCreated) {
1051 mITSGeometryCreated = true;
1052 }
1053
1054 if (mAutoSolenoidBz) {
1055 newCalibValues.newSolenoidField = true;
1056 newCalibValues.solenoidField = mConfig->configGRP.solenoidBzNominalGPU = GPUO2InterfaceUtils::getNominalGPUBz(*GRPGeomHelper::instance().getGRPMagField());
1057 // Propagator::Instance()->setBz(newCalibValues.solenoidField); // Take value from o2::Propagator::UpdateField from GRPGeomHelper
1058 LOG(info) << "Updating solenoid field " << newCalibValues.solenoidField;
1059 }
1060 if (mAutoContinuousMaxTimeBin) {
1061 newCalibValues.newContinuousMaxTimeBin = true;
1062 newCalibValues.continuousMaxTimeBin = mConfig->configGRP.grpContinuousMaxTimeBin = GPUO2InterfaceUtils::getTpcMaxTimeBinFromNHbf(mTFSettings->nHBFPerTF);
1063 LOG(info) << "Updating max time bin " << newCalibValues.continuousMaxTimeBin << " (" << mTFSettings->nHBFPerTF << " orbits)";
1064 }
1065
1066 if (!mPropagatorInstanceCreated) {
1067 newCalibObjects.o2Propagator = mConfig->configCalib.o2Propagator = Propagator::Instance();
1068 if (mConfig->configProcessing.o2PropagatorUseGPUField) {
1069 mGPUReco->UseGPUPolynomialFieldInPropagator(Propagator::Instance());
1070 }
1071 mPropagatorInstanceCreated = true;
1072 }
1073
1074 if (!mMatLUTCreated) {
1075 if (mConfParam->matLUTFile.size() == 0) {
1076 newCalibObjects.matLUT = GRPGeomHelper::instance().getMatLUT();
1077 LOG(info) << "Loaded material budget lookup table";
1078 }
1079 mMatLUTCreated = true;
1080 }
1081 if (!mTRDGeometryCreated) {
1082 if (mSpecConfig.readTRDtracklets) {
1083 auto gm = o2::trd::Geometry::instance();
1084 gm->createPadPlaneArray();
1085 gm->createClusterMatrixArray();
1086 mTRDGeometry = std::make_unique<o2::trd::GeometryFlat>(*gm);
1087 newCalibObjects.trdGeometry = mConfig->configCalib.trdGeometry = mTRDGeometry.get();
1088 LOG(info) << "Loaded TRD geometry";
1089 }
1090 mTRDGeometryCreated = true;
1091 }
1092 }
1093 needCalibUpdate = fetchCalibsCCDBTPC(pc, newCalibObjects, oldCalibObjects) || needCalibUpdate;
1094 if (mSpecConfig.runITSTracking) {
1095 needCalibUpdate = fetchCalibsCCDBITS(pc) || needCalibUpdate;
1096 }
1097 if (mTPCCutAtTimeBin != mConfig->configGRP.tpcCutTimeBin) {
1098 newCalibValues.newTPCTimeBinCut = true;
1099 newCalibValues.tpcTimeBinCut = mConfig->configGRP.tpcCutTimeBin = mTPCCutAtTimeBin;
1100 needCalibUpdate = true;
1101 }
1102 if (needCalibUpdate) {
1103 LOG(info) << "Updating GPUReconstruction calibration objects";
1104 mGPUReco->UpdateCalibration(newCalibObjects, newCalibValues);
1105 }
1106}
1107
1109{
1110 Options opts;
1111 if (mSpecConfig.enableDoublePipeline) {
1112 bool send = mSpecConfig.enableDoublePipeline == 2;
1113 char* o2jobid = getenv("O2JOBID");
1114 char* numaid = getenv("NUMAID");
1115 int32_t chanid = o2jobid ? atoi(o2jobid) : (numaid ? atoi(numaid) : 0);
1116 std::string chan = std::string("name=gpu-prepare-channel,type=") + (send ? "push" : "pull") + ",method=" + (send ? "connect" : "bind") + ",address=ipc://@gpu-prepare-channel-" + std::to_string(chanid) + "-{timeslice0},transport=shmem,rateLogging=0";
1117 opts.emplace_back(o2::framework::ConfigParamSpec{"channel-config", o2::framework::VariantType::String, chan, {"Out-of-band channel config"}});
1118 }
1119 if (mSpecConfig.enableDoublePipeline == 2) {
1120 return opts;
1121 }
1122 if (mSpecConfig.outputTracks) {
1124 }
1125 return opts;
1126}
1127
1129{
1130 Inputs inputs;
1131 if (mSpecConfig.zsDecoder) {
1132 // All ZS raw data is published with subspec 0 by the o2-raw-file-reader-workflow and DataDistribution
1133 // creates subspec fom CRU and endpoint id, we create one single input route subscribing to all TPC/RAWDATA
1134 inputs.emplace_back(InputSpec{"zsraw", ConcreteDataTypeMatcher{"TPC", "RAWDATA"}, Lifetime::Timeframe});
1135 if (mSpecConfig.askDISTSTF) {
1136 inputs.emplace_back("stdDist", "FLP", "DISTSUBTIMEFRAME", 0, Lifetime::Timeframe);
1137 }
1138 }
1139 if (mSpecConfig.enableDoublePipeline == 2) {
1140 if (!mSpecConfig.zsDecoder) {
1141 LOG(fatal) << "Double pipeline mode can only work with zsraw input";
1142 }
1143 return inputs;
1144 } else if (mSpecConfig.enableDoublePipeline == 1) {
1145 inputs.emplace_back("pipelineprepare", gDataOriginGPU, "PIPELINEPREPARE", 0, Lifetime::Timeframe);
1146 }
1147 if (mSpecConfig.outputTracks || mSpecConfig.caClusterer) {
1148 // calibration objects for TPC clusterization
1149 inputs.emplace_back("tpcgain", gDataOriginTPC, "PADGAINFULL", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::CalPadGainFull)));
1150 inputs.emplace_back("tpcaltrosync", gDataOriginTPC, "ALTROSYNCSIGNAL", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::AltroSyncSignal)));
1151 }
1152 if (mSpecConfig.outputTracks) {
1153 // calibration objects for TPC tracking
1154 const auto mapSources = mSpecConfig.tpcDeadMapSources;
1155 if (mapSources != 0) {
1156 tpc::SourcesDeadMap sources((mapSources > -1) ? static_cast<tpc::SourcesDeadMap>(mapSources) : tpc::SourcesDeadMap::All);
1158 inputs.emplace_back("tpcidcpadflags", gDataOriginTPC, "IDCPADFLAGS", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::CalIDCPadStatusMapA), {}, 1)); // time-dependent
1159 }
1161 inputs.emplace_back("tpcruninfo", gDataOriginTPC, "TPCRUNINFO", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::ConfigRunInfo)));
1162 }
1163 }
1164
1165 inputs.emplace_back("tpcgainresidual", gDataOriginTPC, "PADGAINRESIDUAL", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::CalPadGainResidual), {}, 1)); // time-dependent
1166 if (mSpecConfig.tpcUseMCTimeGain) {
1167 inputs.emplace_back("tpctimegain", gDataOriginTPC, "TIMEGAIN", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::CalTimeGainMC), {}, 1)); // time-dependent
1168 } else {
1169 inputs.emplace_back("tpctimegain", gDataOriginTPC, "TIMEGAIN", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::CalTimeGain), {}, 1)); // time-dependent
1170 }
1171 inputs.emplace_back("tpctopologygain", gDataOriginTPC, "TOPOLOGYGAIN", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::CalTopologyGain)));
1172 inputs.emplace_back("tpcthreshold", gDataOriginTPC, "PADTHRESHOLD", 0, Lifetime::Condition, ccdbParamSpec("TPC/Config/FEEPad"));
1174 Options optsDummy;
1175 o2::tpc::CorrectionMapsLoaderGloOpts gloOpts{mSpecConfig.lumiScaleType, mSpecConfig.lumiScaleMode, mSpecConfig.enableMShape, mSpecConfig.enableCTPLumi};
1176 mCalibObjects.mFastTransformHelper->requestCCDBInputs(inputs, optsDummy, gloOpts); // option filled here is lost
1177 }
1178 if (mSpecConfig.decompressTPC) {
1179 inputs.emplace_back(InputSpec{"input", ConcreteDataTypeMatcher{gDataOriginTPC, mSpecConfig.decompressTPCFromROOT ? o2::header::DataDescription("COMPCLUSTERS") : o2::header::DataDescription("COMPCLUSTERSFLAT")}, Lifetime::Timeframe});
1180 } else if (mSpecConfig.caClusterer) {
1181 // We accept digits and MC labels also if we run on ZS Raw data, since they are needed for MC label propagation
1182 if ((!mSpecConfig.zsOnTheFly || mSpecConfig.processMC) && !mSpecConfig.zsDecoder) {
1183 inputs.emplace_back(InputSpec{"input", ConcreteDataTypeMatcher{gDataOriginTPC, "DIGITS"}, Lifetime::Timeframe});
1184 mPolicyData->emplace_back(o2::framework::InputSpec{"digits", o2::framework::ConcreteDataTypeMatcher{"TPC", "DIGITS"}});
1185 }
1186 } else if (mSpecConfig.runTPCTracking) {
1187 inputs.emplace_back(InputSpec{"input", ConcreteDataTypeMatcher{gDataOriginTPC, "CLUSTERNATIVE"}, Lifetime::Timeframe});
1188 mPolicyData->emplace_back(o2::framework::InputSpec{"clusters", o2::framework::ConcreteDataTypeMatcher{"TPC", "CLUSTERNATIVE"}});
1189 }
1190 if (mSpecConfig.processMC) {
1191 if (mSpecConfig.caClusterer) {
1192 if (!mSpecConfig.zsDecoder) {
1193 inputs.emplace_back(InputSpec{"mclblin", ConcreteDataTypeMatcher{gDataOriginTPC, "DIGITSMCTR"}, Lifetime::Timeframe});
1194 mPolicyData->emplace_back(o2::framework::InputSpec{"digitsmc", o2::framework::ConcreteDataTypeMatcher{"TPC", "DIGITSMCTR"}});
1195 }
1196 } else {
1197 inputs.emplace_back(InputSpec{"mclblin", ConcreteDataTypeMatcher{gDataOriginTPC, "CLNATIVEMCLBL"}, Lifetime::Timeframe});
1198 mPolicyData->emplace_back(o2::framework::InputSpec{"clustersmc", o2::framework::ConcreteDataTypeMatcher{"TPC", "CLNATIVEMCLBL"}});
1199 }
1200 }
1201
1202 if (mSpecConfig.zsOnTheFly) {
1203 inputs.emplace_back(InputSpec{"zsinput", ConcreteDataTypeMatcher{"TPC", "TPCZS"}, Lifetime::Timeframe});
1204 inputs.emplace_back(InputSpec{"zsinputsizes", ConcreteDataTypeMatcher{"TPC", "ZSSIZES"}, Lifetime::Timeframe});
1205 }
1206 if (mSpecConfig.readTRDtracklets) {
1207 inputs.emplace_back("trdctracklets", o2::header::gDataOriginTRD, "CTRACKLETS", 0, Lifetime::Timeframe);
1208 inputs.emplace_back("trdtracklets", o2::header::gDataOriginTRD, "TRACKLETS", 0, Lifetime::Timeframe);
1209 inputs.emplace_back("trdtriggerrec", o2::header::gDataOriginTRD, "TRKTRGRD", 0, Lifetime::Timeframe);
1210 inputs.emplace_back("trdtrigrecmask", o2::header::gDataOriginTRD, "TRIGRECMASK", 0, Lifetime::Timeframe);
1211 }
1212
1213 if (mSpecConfig.runITSTracking) {
1214 inputs.emplace_back("compClusters", "ITS", "COMPCLUSTERS", 0, Lifetime::Timeframe);
1215 inputs.emplace_back("patterns", "ITS", "PATTERNS", 0, Lifetime::Timeframe);
1216 inputs.emplace_back("ROframes", "ITS", "CLUSTERSROF", 0, Lifetime::Timeframe);
1217 if (mSpecConfig.itsTriggerType == 1) {
1218 inputs.emplace_back("phystrig", "ITS", "PHYSTRIG", 0, Lifetime::Timeframe);
1219 } else if (mSpecConfig.itsTriggerType == 2) {
1220 inputs.emplace_back("phystrig", "TRD", "TRKTRGRD", 0, Lifetime::Timeframe);
1221 }
1222 if (mSpecConfig.isITS3) {
1223 inputs.emplace_back("cldict", "IT3", "CLUSDICT", 0, Lifetime::Condition, ccdbParamSpec("IT3/Calib/ClusterDictionary"));
1224 inputs.emplace_back("alppar", "ITS", "ALPIDEPARAM", 0, Lifetime::Condition, ccdbParamSpec("ITS/Config/AlpideParam"));
1225 } else {
1226 inputs.emplace_back("itscldict", "ITS", "CLUSDICT", 0, Lifetime::Condition, ccdbParamSpec("ITS/Calib/ClusterDictionary"));
1227 inputs.emplace_back("itsalppar", "ITS", "ALPIDEPARAM", 0, Lifetime::Condition, ccdbParamSpec("ITS/Config/AlpideParam"));
1228 }
1229 if (mSpecConfig.itsOverrBeamEst) {
1230 inputs.emplace_back("meanvtx", "GLO", "MEANVERTEX", 0, Lifetime::Condition, ccdbParamSpec("GLO/Calib/MeanVertex", {}, 1));
1231 }
1232 if (mSpecConfig.processMC) {
1233 inputs.emplace_back("itsmclabels", "ITS", "CLUSTERSMCTR", 0, Lifetime::Timeframe);
1234 inputs.emplace_back("ITSMC2ROframes", "ITS", "CLUSTERSMC2ROF", 0, Lifetime::Timeframe);
1235 }
1236 }
1237
1238 return inputs;
1239};
1240
1242{
1243 constexpr static size_t NSectors = o2::tpc::Sector::MAXSECTOR;
1244 std::vector<OutputSpec> outputSpecs;
1245 if (mSpecConfig.enableDoublePipeline == 2) {
1246 outputSpecs.emplace_back(gDataOriginGPU, "PIPELINEPREPARE", 0, Lifetime::Timeframe);
1247 return outputSpecs;
1248 }
1249 if (mSpecConfig.outputTracks) {
1250 outputSpecs.emplace_back(gDataOriginTPC, "TRACKS", 0, Lifetime::Timeframe);
1251 outputSpecs.emplace_back(gDataOriginTPC, "CLUSREFS", 0, Lifetime::Timeframe);
1252 }
1253 if (mSpecConfig.processMC && mSpecConfig.outputTracks) {
1254 outputSpecs.emplace_back(gDataOriginTPC, "TRACKSMCLBL", 0, Lifetime::Timeframe);
1255 }
1256 if (mSpecConfig.outputCompClusters) {
1257 outputSpecs.emplace_back(gDataOriginTPC, "COMPCLUSTERS", 0, Lifetime::Timeframe);
1258 }
1259 if (mSpecConfig.outputCompClustersFlat) {
1260 outputSpecs.emplace_back(gDataOriginTPC, "COMPCLUSTERSFLAT", 0, Lifetime::Timeframe);
1261 }
1262 if (mSpecConfig.outputCAClusters) {
1263 for (auto const& sector : mTPCSectors) {
1264 mClusterOutputIds.emplace_back(sector);
1265 }
1266 if (mSpecConfig.sendClustersPerSector) {
1267 outputSpecs.emplace_back(gDataOriginTPC, "CLUSTERNATIVETMP", NSectors, Lifetime::Timeframe); // Dummy buffer the TPC tracker writes the inital linear clusters to
1268 for (const auto sector : mTPCSectors) {
1269 outputSpecs.emplace_back(gDataOriginTPC, "CLUSTERNATIVE", sector, Lifetime::Timeframe);
1270 }
1271 } else {
1272 outputSpecs.emplace_back(gDataOriginTPC, "CLUSTERNATIVE", NSectors, Lifetime::Timeframe);
1273 }
1274 if (mSpecConfig.processMC) {
1275 if (mSpecConfig.sendClustersPerSector) {
1276 for (const auto sector : mTPCSectors) {
1277 outputSpecs.emplace_back(gDataOriginTPC, "CLNATIVEMCLBL", sector, Lifetime::Timeframe);
1278 }
1279 } else {
1280 outputSpecs.emplace_back(gDataOriginTPC, "CLNATIVEMCLBL", NSectors, Lifetime::Timeframe);
1281 }
1282 }
1283 }
1284 if (mSpecConfig.outputSharedClusterMap) {
1285 outputSpecs.emplace_back(gDataOriginTPC, "CLSHAREDMAP", 0, Lifetime::Timeframe);
1286 outputSpecs.emplace_back(gDataOriginTPC, "TPCOCCUPANCYMAP", 0, Lifetime::Timeframe);
1287 }
1288 if (mSpecConfig.tpcTriggerHandling) {
1289 outputSpecs.emplace_back(gDataOriginTPC, "TRIGGERWORDS", 0, Lifetime::Timeframe);
1290 }
1291 if (mSpecConfig.outputQA) {
1292 outputSpecs.emplace_back(gDataOriginTPC, "TRACKINGQA", 0, Lifetime::Timeframe);
1293 }
1294 if (mSpecConfig.outputErrorQA) {
1295 outputSpecs.emplace_back(gDataOriginGPU, "ERRORQA", 0, Lifetime::Timeframe);
1296 }
1297
1298 if (mSpecConfig.runITSTracking) {
1299 outputSpecs.emplace_back(gDataOriginITS, "TRACKS", 0, Lifetime::Timeframe);
1300 outputSpecs.emplace_back(gDataOriginITS, "TRACKCLSID", 0, Lifetime::Timeframe);
1301 outputSpecs.emplace_back(gDataOriginITS, "ITSTrackROF", 0, Lifetime::Timeframe);
1302 outputSpecs.emplace_back(gDataOriginITS, "VERTICES", 0, Lifetime::Timeframe);
1303 outputSpecs.emplace_back(gDataOriginITS, "VERTICESROF", 0, Lifetime::Timeframe);
1304 outputSpecs.emplace_back(gDataOriginITS, "IRFRAMES", 0, Lifetime::Timeframe);
1305
1306 if (mSpecConfig.processMC) {
1307 outputSpecs.emplace_back(gDataOriginITS, "VERTICESMCTR", 0, Lifetime::Timeframe);
1308 outputSpecs.emplace_back(gDataOriginITS, "TRACKSMCTR", 0, Lifetime::Timeframe);
1309 outputSpecs.emplace_back(gDataOriginITS, "ITSTrackMC2ROF", 0, Lifetime::Timeframe);
1310 }
1311 }
1312
1313 return outputSpecs;
1314};
1315
1317{
1318 ExitPipeline();
1319 mQA.reset(nullptr);
1320 mDisplayFrontend.reset(nullptr);
1321 mGPUReco.reset(nullptr);
1322}
1323
1324} // namespace o2::gpu
Simple interface to the CDB manager.
Definition of container class for dE/dx corrections.
Class of a TPC cluster in TPC-native coordinates (row, time)
Container to store compressed TPC cluster data.
A const (ready only) version of MCTruthContainer.
Helper class to access correction maps.
Helper class to access load maps from CCDB.
A parser and sequencer utility for raw pages within DPL input.
A raw page parser for DPL input.
Wrapper container for different reconstructed object types.
Definition of the TPC Digit.
Helper class for memory management of TPC Data Formats, external from the actual data type classes to...
Definition of class for writing debug informations.
Definition of the GeometryManager class.
int32_t i
int32_t retVal
Helper for geometry and GRP related CCDB requests.
Definition of the GeometryTGeo class.
A helper class to iteratate over all parts of all input routes.
Declarations for the wrapper for the set of cylindrical material layers.
Definition of the Names Generator class.
Fetching neural networks for clusterization from CCDB.
Utilities for parsing of data sequences.
uint32_t j
Definition RawData.h:0
Struct for input data required by TRD tracking workflow.
Type wrappers for enfording a specific serialization method.
class to create TPC fast transformation
Definition of TPCFastTransform class.
Wrapper class for TPC CA Tracker algorithm.
TBranch * ptr
Configurable params for tracks ad hoc tuning.
Helper class to extract VDrift from different sources.
Helper class to obtain TPC clusters / digits / labels from DPL.
Definitions of TPC Zero Suppression Data Headers.
void checkUpdates(o2::framework::ProcessingContext &pc)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static MatLayerCylSet * loadFromFile(const std::string &inpFName="matbud.root")
GPUd() value_type estimateLTFast(o2 static GPUd() float estimateLTIncrement(const o2 PropagatorImpl * Instance(bool uninitialized=false)
Definition Propagator.h:143
gsl::span< const TruthElement > getLabels(uint32_t dataindex) const
static mask_t getSourcesMask(const std::string_view srcList)
static constexpr std::string_view NONE
keywork for no sources
void addElement(uint32_t dataindex, TruthElement const &element, bool noElement=false)
size_t flatten_to(ContainerType &container) const
static constexpr ID TPC
Definition DetID.h:64
This utility handles transparently the DPL inputs and triggers a customizable action on sequences of ...
void snapshot(const Output &spec, T const &object)
decltype(auto) make(const Output &spec, Args... args)
ServiceRegistryRef services()
Definition InitContext.h:34
A helper class to iteratate over all parts of all input routes.
int getPos(const char *name) const
decltype(auto) get(R binding, int part=0) const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
static GPUDisplayFrontendInterface * getFrontend(const char *type)
static uint32_t getTpcMaxTimeBinFromNHbf(uint32_t nHbf)
static float getNominalGPUBz(T &src)
o2::framework::Outputs outputs()
std::vector< framework::InputSpec > CompletionPolicyData
void init(o2::framework::InitContext &ic) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
o2::framework::Inputs inputs()
void run(o2::framework::ProcessingContext &pc) final
void stop() final
This is invoked on stop.
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
GPURecoWorkflowSpec(CompletionPolicyData *policyData, Config const &specconfig, std::vector< int32_t > const &tpcsectors, uint64_t tpcSectorMask, std::shared_ptr< o2::base::GRPGeomRequest > &ggr, std::function< bool(o2::framework::DataProcessingHeader::StartTime)> **gPolicyOrder=nullptr)
o2::framework::Options options()
static void RunZSEncoderCreateMeta(const uint64_t *buffer, const uint32_t *sizes, void **ptrs, GPUTrackingInOutZS *out)
static GeometryTGeo * Instance()
void fillMatrixCache(int mask) override
ClusterNativeAccess::ConstMCLabelContainerViewWithBuffer ConstMCLabelContainerViewWithBuffer
static void addOptions(std::vector< o2::framework::ConfigParamSpec > &options)
void loadIndividualFromCCDB(std::map< std::string, std::string > settings)
static constexpr int MAXSECTOR
Definition Sector.h:44
static precheckModifiedData runPrecheck(o2::gpu::GPUTrackingInOutPointers *ptrs, o2::gpu::GPUO2InterfaceConfiguration *config)
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs, bool laser=true, bool itstpcTgl=true)
static Geometry * instance()
Definition Geometry.h:33
GLint GLsizei count
Definition glcorearb.h:399
GLuint buffer
Definition glcorearb.h:655
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLuint end
Definition glcorearb.h:469
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble GLdouble right
Definition glcorearb.h:4077
GLint left
Definition glcorearb.h:1979
GLboolean * data
Definition glcorearb.h:298
GLintptr offset
Definition glcorearb.h:660
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
GLuint start
Definition glcorearb.h:469
GLint ref
Definition glcorearb.h:291
GLint GLuint mask
Definition glcorearb.h:291
GLsizei GLenum * sources
Definition glcorearb.h:2516
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
constexpr o2::header::DataOrigin gDataOriginTRD
Definition DataHeader.h:577
constexpr o2::header::DataOrigin gDataOriginITS
Definition DataHeader.h:570
constexpr o2::header::DataOrigin gDataOriginGPU
Definition DataHeader.h:592
constexpr int NSectors
Definition of a container to keep/associate and arbitrary number of labels associated to an index wit...
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
o2::header::DataDescription DataDescription
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
O2 data header classes and API, v0.1.
Definition DetID.h:49
auto get(const std::byte *buffer, size_t=0)
Definition DataHeader.h:454
Descriptor< gSizeDataDescriptionString > DataDescription
Definition DataHeader.h:551
constexpr int MAXGLOBALPADROW
Definition Constants.h:34
@ ZS
final Zero Suppression (can be ILBZS, DLBZS)
const std::unordered_map< CDBType, const std::string > CDBTypeMap
Storage name in CCDB for each calibration and parameter type.
Definition CDBTypes.h:95
@ FEEConfig
use fee config
@ IDCPadStatus
use idc pad status map
@ CalIDCPadStatusMapA
Status map of the pads (dead etc. obatined from CalIDC0)
@ CalPadGainFull
Full pad gain calibration.
@ CalPadGainResidual
ResidualpPad gain calibration (e.g. from tracks)
@ CalTimeGain
Gain variation over time.
@ CalTimeGainMC
Gain variation over time for MC.
@ AltroSyncSignal
timing of Altro chip sync. signal
auto getRecoInputContainer(o2::framework::ProcessingContext &pc, o2::gpu::GPUTrackingInOutPointers *ptrs, const o2::globaltracking::RecoContainer *inputTracks, bool mc=false)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string filename()
size_t inputTimesliceId
The time pipelining id of this particular device.
Definition DeviceSpec.h:68
void requestTracks(o2::dataformats::GlobalTrackID::mask_t src, bool mc)
void collectData(o2::framework::ProcessingContext &pc, const DataRequest &request)
S< o2::trd::GeometryFlat >::type * trdGeometry
S< o2::base::PropagatorImpl< float > >::type * o2Propagator
S< o2::base::MatLayerCylSet >::type * matLUT
const std::vector< TGraphAsymmErrors > * hist4
std::function< void *(size_t)> allocator
std::array< const o2::dataformats::ConstMCTruthContainerView< o2::MCCompLabel > *, o2::tpc::constants::MAXSECTOR > v
const o2::tpc::Digit * tpcDigits[NSECTORS]
const GPUTPCDigitsMCInput * tpcDigitsMC
const o2::tpc::ClusterNativeAccess * clustersNative
const o2::tpc::CompressedClustersFlat * tpcCompressedClusters
const GPUSettingsTF * settingsTF
const GPUTrackingInOutZS * tpcZS
const o2::MCCompLabel * outputTracksTPCO2MC
const o2::tpc::TrackTPC * outputTracksTPCO2
const GPUTrackingInOutDigits * tpcPackedDigits
GPUTrackingInOutZSSector sector[NSECTORS]
static constexpr uint32_t NSECTORS
static constexpr uint32_t NENDPOINTS
GPUOutputControl * asArray()
GPUOutputControl tpcTracksO2Labels
GPUOutputControl tpcTracksO2ClusRefs
size_t getIndex(const GPUOutputControl &v)
static constexpr size_t count()
GPUOutputControl sharedClusterMap
GPUOutputControl compressedClusters
uint32_t SubSpecificationType
Definition DataHeader.h:620
static constexpr int T2L
Definition Cartesian.h:55
static constexpr int T2GRot
Definition Cartesian.h:57
static constexpr int T2G
Definition Cartesian.h:56
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
unsigned int nClustersSector[constants::MAXSECTOR]
const o2::dataformats::ConstMCTruthContainerView< o2::MCCompLabel > * clustersMCTruth
const ClusterNative * clusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
unsigned int clusterOffset[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
const ClusterNative * clustersLinear
static std::vector< std::string > tokenize(const std::string &src, char delim, bool trimToken=true, bool skipEmpty=true)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"