Project
Loading...
Searching...
No Matches
GPUO2InterfaceUtils.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
14
15#include "GPUO2InterfaceUtils.h"
17#include "GPUO2InterfaceRefit.h"
18#include "TPCPadGainCalib.h"
19#include "CalibdEdxContainer.h"
20#include "TPCBase/Sector.h"
22#include "GPUParam.h"
26#include "TPCBase/CRU.h"
27#include "TPCBase/RDHUtils.h"
29#include <gsl/span>
30
31using namespace o2::gpu;
32
33using DigitArray = std::array<gsl::span<const o2::tpc::Digit>, o2::tpc::Sector::MAXSECTOR>;
34
35std::unique_ptr<TPCPadGainCalib> GPUO2InterfaceUtils::getPadGainCalibDefault()
36{
37 return std::make_unique<TPCPadGainCalib>();
38}
39
40std::unique_ptr<TPCPadGainCalib> GPUO2InterfaceUtils::getPadGainCalib(const o2::tpc::CalDet<float>& in)
41{
42 return std::make_unique<TPCPadGainCalib>(in);
43}
44
45std::unique_ptr<o2::tpc::CalibdEdxContainer> GPUO2InterfaceUtils::getCalibdEdxContainerDefault()
46{
47 return std::make_unique<o2::tpc::CalibdEdxContainer>();
48}
49
50template <>
51void GPUO2InterfaceUtils::RunZSEncoder<DigitArray>(const DigitArray& in, std::unique_ptr<uint64_t[]>* outBuffer, uint32_t* outSizes, o2::raw::RawFileWriter* raw, const o2::InteractionRecord* ir, int32_t version, bool verify, float threshold, bool padding, std::function<void(std::vector<o2::tpc::Digit>&)> digitsFilter)
52{
54 param.SetDefaults(5.00668);
55 o2::gpu::GPUReconstructionConvert::RunZSEncoder(in, outBuffer, outSizes, raw, ir, param, version, verify, threshold, padding, digitsFilter);
56}
57template <>
58void GPUO2InterfaceUtils::RunZSEncoder<DigitArray>(const DigitArray& in, std::unique_ptr<uint64_t[]>* outBuffer, uint32_t* outSizes, o2::raw::RawFileWriter* raw, const o2::InteractionRecord* ir, GPUO2InterfaceConfiguration& config, int32_t version, bool verify, bool padding, std::function<void(std::vector<o2::tpc::Digit>&)> digitsFilter)
59{
61 param.SetDefaults(&config.configGRP, &config.configReconstruction, &config.configProcessing, nullptr);
62 o2::gpu::GPUReconstructionConvert::RunZSEncoder(in, outBuffer, outSizes, raw, ir, param, version, verify, config.configReconstruction.tpc.zsThreshold, padding, digitsFilter);
63}
64
65void GPUO2InterfaceUtils::GPUReconstructionZSDecoder::DecodePage(std::vector<o2::tpc::Digit>& outputBuffer, const void* page, uint32_t tfFirstOrbit, const GPUParam* param, uint32_t triggerBC)
66{
68 if (o2::raw::RDHUtils::getMemorySize(*rdh) == sizeof(o2::header::RAWDataHeader)) {
69 return;
70 }
71 o2::tpc::TPCZSHDR* const hdr = (o2::tpc::TPCZSHDR*)(o2::tpc::rdh_utils::getLink(o2::raw::RDHUtils::getFEEID(*rdh)) == o2::tpc::rdh_utils::DLBZSLinkID ? ((const char*)page + o2::raw::RDHUtils::getMemorySize(*rdh) - sizeof(o2::tpc::TPCZSHDRV2)) : ((const char*)page + sizeof(o2::header::RAWDataHeader)));
72
73 if (mDecoders.size() < hdr->version + 1) {
74 mDecoders.resize(hdr->version + 1);
75 }
76 if (mDecoders[hdr->version] == nullptr) {
78 }
79 mDecoders[hdr->version](outputBuffer, page, tfFirstOrbit, triggerBC);
80}
81
82std::unique_ptr<GPUParam> GPUO2InterfaceUtils::getFullParam(float solenoidBz, uint32_t nHbfPerTf, std::unique_ptr<GPUO2InterfaceConfiguration>* pConfiguration, std::unique_ptr<GPUSettingsO2>* pO2Settings, bool* autoMaxTimeBin)
83{
84 std::unique_ptr<GPUParam> retVal = std::make_unique<GPUParam>();
85 std::unique_ptr<GPUO2InterfaceConfiguration> tmpConfig;
86 std::unique_ptr<GPUSettingsO2> tmpSettingsO2;
87 if (!pConfiguration) {
88 tmpConfig = std::make_unique<GPUO2InterfaceConfiguration>();
89 pConfiguration = &tmpConfig;
90 (*pConfiguration)->configGRP.grpContinuousMaxTimeBin = -1;
91 } else if (!*pConfiguration) {
92 *pConfiguration = std::make_unique<GPUO2InterfaceConfiguration>();
93 (*pConfiguration)->configGRP.grpContinuousMaxTimeBin = -1;
94 }
95 (*pConfiguration)->configGRP.solenoidBzNominalGPU = solenoidBz;
96 if (pO2Settings && *pO2Settings) {
97 **pO2Settings = (*pConfiguration)->ReadConfigurableParam();
98 } else {
99 if (!pO2Settings) {
100 pO2Settings = &tmpSettingsO2;
101 }
102 *pO2Settings = std::make_unique<GPUSettingsO2>((*pConfiguration)->ReadConfigurableParam());
103 }
104 if (nHbfPerTf == 0) {
105 nHbfPerTf = (*pO2Settings)->overrideNHbfPerTF ? (*pO2Settings)->overrideNHbfPerTF : 256;
106 }
107 if (autoMaxTimeBin) {
108 *autoMaxTimeBin = (*pConfiguration)->configGRP.grpContinuousMaxTimeBin == -1;
109 }
110 if ((*pConfiguration)->configGRP.grpContinuousMaxTimeBin == -1) {
111 (*pConfiguration)->configGRP.grpContinuousMaxTimeBin = GPUO2InterfaceUtils::getTpcMaxTimeBinFromNHbf(nHbfPerTf);
112 }
113 retVal->SetDefaults(&(*pConfiguration)->configGRP, &(*pConfiguration)->configReconstruction, &(*pConfiguration)->configProcessing, nullptr);
114 return retVal;
115}
116
117std::shared_ptr<GPUParam> GPUO2InterfaceUtils::getFullParamShared(float solenoidBz, uint32_t nHbfPerTf, std::unique_ptr<GPUO2InterfaceConfiguration>* pConfiguration, std::unique_ptr<GPUSettingsO2>* pO2Settings, bool* autoMaxTimeBin)
118{
119 return std::move(getFullParam(solenoidBz, nHbfPerTf, pConfiguration, pO2Settings, autoMaxTimeBin));
120}
121
122void GPUO2InterfaceUtils::paramUseExternalOccupancyMap(GPUParam* param, uint32_t nHbfPerTf, const uint32_t* occupancymap, int32_t occupancyMapSize)
123{
124 size_t expectedOccMapSize = nHbfPerTf ? GPUO2InterfaceRefit::fillOccupancyMapGetSize(nHbfPerTf, param) : 0;
125 if (occupancyMapSize != -1 && nHbfPerTf && (size_t)occupancyMapSize != expectedOccMapSize) {
126 throw std::runtime_error("Received occupancy map of wrong size, most likely --configKeyValues or HBperTF of map creator and map consumer are different");
127 }
128 if (occupancymap && occupancyMapSize > sizeof(*occupancymap) && occupancymap[1] != (param->rec.tpc.occupancyMapTimeBins * 0x10000 + param->rec.tpc.occupancyMapTimeBinsAverage)) {
129 throw std::runtime_error("Occupancy map has invalid paramters occupancyMapTimeBins and occupancyMapTimeBinsAverage");
130 }
131 if (occupancymap) {
132 param->occupancyTotal = *occupancymap;
133 if (param->rec.tpc.occupancyMapTimeBins) {
134 param->occupancyMap = occupancymap + 2;
135 }
136 }
137}
138
Definition of container class for dE/dx corrections.
uint16_t padding
Definition of the TPC Digit.
int32_t retVal
uint32_t version
Definition RawData.h:8
Definitions of TPC Zero Suppression Data Headers.
static size_t fillOccupancyMapGetSize(uint32_t nHbfPerTf, const GPUParam *param=nullptr)
void DecodePage(std::vector< o2::tpc::Digit > &outputBuffer, const void *page, uint32_t tfFirstOrbit, const GPUParam *param, uint32_t triggerBC=0)
static std::unique_ptr< TPCPadGainCalib > getPadGainCalibDefault()
static void paramUseExternalOccupancyMap(GPUParam *param, uint32_t nHbfPerTf, const uint32_t *occupancymap, int32_t occupancyMapSize)
static std::unique_ptr< TPCPadGainCalib > getPadGainCalib(const o2::tpc::CalDet< float > &in)
static uint32_t getTpcMaxTimeBinFromNHbf(uint32_t nHbf)
static std::unique_ptr< GPUParam > getFullParam(float solenoidBz, uint32_t nHbfPerTf=0, std::unique_ptr< GPUO2InterfaceConfiguration > *pConfiguration=nullptr, std::unique_ptr< GPUSettingsO2 > *pO2Settings=nullptr, bool *autoMaxTimeBin=nullptr)
static std::unique_ptr< o2::tpc::CalibdEdxContainer > getCalibdEdxContainerDefault()
static std::shared_ptr< GPUParam > getFullParamShared(float solenoidBz, uint32_t nHbfPerTf=0, std::unique_ptr< GPUO2InterfaceConfiguration > *pConfiguration=nullptr, std::unique_ptr< GPUSettingsO2 > *pO2Settings=nullptr, bool *autoMaxTimeBin=nullptr)
static void RunZSEncoder(const S &in, std::unique_ptr< uint64_t[]> *outBuffer, uint32_t *outSizes, o2::raw::RawFileWriter *raw, const o2::InteractionRecord *ir, const GPUParam &param, int32_t version, bool verify, float threshold=0.f, bool padding=false, std::function< void(std::vector< o2::tpc::Digit > &)> digitsFilter=nullptr)
static std::function< void(std::vector< o2::tpc::Digit > &, const void *, uint32_t, uint32_t)> GetDecoder(int32_t version, const GPUParam *param)
static constexpr int MAXSECTOR
Definition Sector.h:44
std::array< gsl::span< const o2::tpc::Digit >, Sector::MAXSECTOR > DigitArray
GLenum GLfloat param
Definition glcorearb.h:271
constexpr int LHCMaxBunches
RAWDataHeaderV7 RAWDataHeader
constexpr int LHCBCPERTIMEBIN
Definition Constants.h:38
void SetDefaults(float solenoidBz)
Definition GPUParam.cxx:33
unsigned char version
o2::InteractionRecord ir(0, 0)