-
Notifications
You must be signed in to change notification settings - Fork 490
Expand file tree
/
Copy pathGPUO2InterfaceUtils.cxx
More file actions
150 lines (135 loc) · 7.23 KB
/
GPUO2InterfaceUtils.cxx
File metadata and controls
150 lines (135 loc) · 7.23 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
// 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 GPUO2Interface.cxx
/// \author David Rohr
#include "GPUO2InterfaceUtils.h"
#include "GPUO2InterfaceConfiguration.h"
#include "GPUO2InterfaceRefit.h"
#include "TPCPadGainCalib.h"
#include "CalibdEdxContainer.h"
#include "TPCBase/Sector.h"
#include "DataFormatsTPC/Digit.h"
#include "GPUParam.h"
#include "GPUReconstructionConvert.h"
#include "DataFormatsTPC/Digit.h"
#include "DetectorsRaw/RDHUtils.h"
#include "TPCBase/CRU.h"
#include "TPCBase/RDHUtils.h"
#include "DataFormatsTPC/ZeroSuppression.h"
#include "GPUTPCClusterOccupancyMap.h"
#include <gsl/span>
using namespace o2::gpu;
using DigitArray = std::array<gsl::span<const o2::tpc::Digit>, o2::tpc::Sector::MAXSECTOR>;
std::unique_ptr<TPCPadGainCalib> GPUO2InterfaceUtils::getPadGainCalibDefault()
{
return std::make_unique<TPCPadGainCalib>();
}
std::unique_ptr<TPCPadGainCalib> GPUO2InterfaceUtils::getPadGainCalib(const o2::tpc::CalDet<float>& in)
{
return std::make_unique<TPCPadGainCalib>(in);
}
std::unique_ptr<o2::tpc::CalibdEdxContainer> GPUO2InterfaceUtils::getCalibdEdxContainerDefault()
{
return std::make_unique<o2::tpc::CalibdEdxContainer>();
}
template <>
void 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)
{
GPUParam param;
param.SetDefaults(5.00668, false);
o2::gpu::GPUReconstructionConvert::RunZSEncoder(in, outBuffer, outSizes, raw, ir, param, version, verify, threshold, padding, digitsFilter);
}
template <>
void 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)
{
GPUParam param;
param.SetDefaults(&config.configGRP, &config.configReconstruction, &config.configProcessing, nullptr);
o2::gpu::GPUReconstructionConvert::RunZSEncoder(in, outBuffer, outSizes, raw, ir, param, version, verify, config.configReconstruction.tpc.zsThreshold, padding, digitsFilter);
}
void GPUO2InterfaceUtils::GPUReconstructionZSDecoder::DecodePage(std::vector<o2::tpc::Digit>& outputBuffer, const void* page, uint32_t tfFirstOrbit, const GPUParam* param, uint32_t triggerBC)
{
const o2::header::RAWDataHeader* rdh = (const o2::header::RAWDataHeader*)page;
if (o2::raw::RDHUtils::getMemorySize(*rdh) == sizeof(o2::header::RAWDataHeader)) {
return;
}
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)));
if (mDecoders.size() < hdr->version + 1) {
mDecoders.resize(hdr->version + 1);
}
if (mDecoders[hdr->version] == nullptr) {
mDecoders[hdr->version] = GPUReconstructionConvert::GetDecoder(hdr->version, param);
}
mDecoders[hdr->version](outputBuffer, page, tfFirstOrbit, triggerBC);
}
std::unique_ptr<GPUParam> GPUO2InterfaceUtils::getFullParam(float solenoidBz, uint32_t nHbfPerTf, std::unique_ptr<GPUO2InterfaceConfiguration>* pConfiguration, std::unique_ptr<GPUSettingsO2>* pO2Settings, bool* autoMaxTimeBin)
{
std::unique_ptr<GPUParam> retVal = std::make_unique<GPUParam>();
std::unique_ptr<GPUO2InterfaceConfiguration> tmpConfig;
std::unique_ptr<GPUSettingsO2> tmpSettingsO2;
if (!pConfiguration) {
tmpConfig = std::make_unique<GPUO2InterfaceConfiguration>();
pConfiguration = &tmpConfig;
(*pConfiguration)->configGRP.grpContinuousMaxTimeBin = -1;
} else if (!*pConfiguration) {
*pConfiguration = std::make_unique<GPUO2InterfaceConfiguration>();
(*pConfiguration)->configGRP.grpContinuousMaxTimeBin = -1;
}
(*pConfiguration)->configGRP.solenoidBzNominalGPU = solenoidBz;
if (pO2Settings && *pO2Settings) {
**pO2Settings = (*pConfiguration)->ReadConfigurableParam();
} else {
if (!pO2Settings) {
pO2Settings = &tmpSettingsO2;
}
*pO2Settings = std::make_unique<GPUSettingsO2>((*pConfiguration)->ReadConfigurableParam());
}
if (nHbfPerTf == 0) {
nHbfPerTf = (*pO2Settings)->overrideNHbfPerTF ? (*pO2Settings)->overrideNHbfPerTF : 256;
}
if (autoMaxTimeBin) {
*autoMaxTimeBin = (*pConfiguration)->configGRP.grpContinuousMaxTimeBin == -1;
}
if ((*pConfiguration)->configGRP.grpContinuousMaxTimeBin == -1) {
(*pConfiguration)->configGRP.grpContinuousMaxTimeBin = GPUO2InterfaceUtils::getTpcMaxTimeBinFromNHbf(nHbfPerTf);
}
retVal->SetDefaults(&(*pConfiguration)->configGRP, &(*pConfiguration)->configReconstruction, &(*pConfiguration)->configProcessing, nullptr);
return retVal;
}
std::shared_ptr<GPUParam> GPUO2InterfaceUtils::getFullParamShared(float solenoidBz, uint32_t nHbfPerTf, std::unique_ptr<GPUO2InterfaceConfiguration>* pConfiguration, std::unique_ptr<GPUSettingsO2>* pO2Settings, bool* autoMaxTimeBin)
{
return std::move(getFullParam(solenoidBz, nHbfPerTf, pConfiguration, pO2Settings, autoMaxTimeBin));
}
void GPUO2InterfaceUtils::paramUseExternalOccupancyMap(GPUParam* param, uint32_t nHbfPerTf, const uint32_t* occupancymap, int32_t occupancyMapSize)
{
size_t expectedOccMapSize = nHbfPerTf ? GPUO2InterfaceRefit::fillOccupancyMapGetSize(nHbfPerTf, param) : 0;
if (occupancyMapSize != -1 && nHbfPerTf && (size_t)occupancyMapSize != expectedOccMapSize) {
throw std::runtime_error("Received occupancy map of wrong size, most likely --configKeyValues or HBperTF of map creator and map consumer are different");
}
if (occupancymap && occupancyMapSize > sizeof(*occupancymap) && occupancymap[1] != (param->rec.tpc.occupancyMapTimeBins * 0x10000 + param->rec.tpc.occupancyMapTimeBinsAverage)) {
throw std::runtime_error("Occupancy map has invalid paramters occupancyMapTimeBins and occupancyMapTimeBinsAverage");
}
if (occupancymap) {
param->occupancyTotal = *occupancymap;
if (param->rec.tpc.occupancyMapTimeBins) {
param->occupancyMap = occupancymap + 2;
param->occupancyMapSize = GPUTPCClusterOccupancyMapBin::getNBins(*param);
}
}
}
uint32_t GPUO2InterfaceUtils::getTpcMaxTimeBinFromNHbf(uint32_t nHbf)
{
return (nHbf * o2::constants::lhc::LHCMaxBunches + 2 * o2::tpc::constants::LHCBCPERTIMEBIN - 2) / o2::tpc::constants::LHCBCPERTIMEBIN;
}
float GPUO2InterfaceUtils::getNominalGPUBzFromCurrent(float l3curr)
{
float al3curr = CAMath::Abs(l3curr);
return (CAMath::Abs(al3curr - 12000) < CAMath::Abs(al3curr - 30000) ? (2.04487f / 12000.f) : (5.00668f / 30000.f)) * l3curr;
}