File indexing completed on 2024-04-06 12:02:15
0001 #include <cmath>
0002
0003 #include "CondFormats/HcalObjects/interface/HcalConvertedPedestalsGPU.h"
0004 #include "FWCore/Utilities/interface/typelookup.h"
0005 #include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h"
0006
0007 namespace {
0008 float convert(float const x, int const i, HcalQIECoder const& coder, HcalQIEShape const& shape) {
0009 int const x1 = static_cast<int>(std::floor(x));
0010 int const x2 = static_cast<int>(std::floor(x + 1));
0011 float const y2 = coder.charge(shape, x2, i);
0012 float const y1 = coder.charge(shape, x1, i);
0013 return (y2 - y1) * (x - x1) + y1;
0014 }
0015 }
0016
0017
0018 HcalConvertedPedestalsGPU::HcalConvertedPedestalsGPU(HcalPedestals const& pedestals,
0019 HcalQIEData const& qieData,
0020 HcalQIETypes const& qieTypes)
0021 : totalChannels_{pedestals.getAllContainers()[0].second.size() + pedestals.getAllContainers()[1].second.size()},
0022 offsetForHashes_{static_cast<uint32_t>(pedestals.getAllContainers()[0].second.size())},
0023 values_(totalChannels_ * 4) {
0024 #ifdef HCAL_MAHI_CPUDEBUG
0025 std::cout << "hello from converted pedestals" << std::endl;
0026 std::cout << "pedestals HB values = " << pedestals.getAllContainers()[0].second.size()
0027 << " HE values = " << pedestals.getAllContainers()[1].second.size() << std::endl;
0028 std::cout << "qiedata HB values = " << qieData.getAllContainers()[0].second.size()
0029 << " HE values = " << qieData.getAllContainers()[1].second.size() << std::endl;
0030 #endif
0031
0032
0033 auto const pedestalsAll = pedestals.getAllContainers();
0034 auto const qieDataAll = qieData.getAllContainers();
0035 auto const qieTypesAll = qieTypes.getAllContainers();
0036
0037
0038 auto const unitIsADC = pedestals.isADC();
0039
0040
0041 auto const& pedestalBarrelValues = pedestalsAll[0].second;
0042 auto const& qieDataBarrelValues = qieDataAll[0].second;
0043 auto const& qieTypesBarrelValues = qieTypesAll[0].second;
0044
0045 #ifdef HCAL_MAHI_CPUDEBUG
0046 assert(pedestalBarrelValues.size() == qieDataBarrelValues.size());
0047 assert(pedestalBarrelValues.size() == qieTypesBarrelValues.size());
0048 #endif
0049
0050 for (uint64_t i = 0; i < pedestalBarrelValues.size(); ++i) {
0051 auto const& qieCoder = qieDataBarrelValues[i];
0052 auto const qieType = qieTypesBarrelValues[i].getValue() > 1 ? 1 : 0;
0053 auto const& qieShape = qieData.getShape(qieType);
0054
0055 values_[i * 4] = unitIsADC ? convert(pedestalBarrelValues[i].getValue(0), 0, qieCoder, qieShape)
0056 : pedestalBarrelValues[i].getValue(0);
0057 values_[i * 4 + 1] = unitIsADC ? convert(pedestalBarrelValues[i].getValue(1), 1, qieCoder, qieShape)
0058 : pedestalBarrelValues[i].getValue(1);
0059 values_[i * 4 + 2] = unitIsADC ? convert(pedestalBarrelValues[i].getValue(2), 2, qieCoder, qieShape)
0060 : pedestalBarrelValues[i].getValue(2);
0061 values_[i * 4 + 3] = unitIsADC ? convert(pedestalBarrelValues[i].getValue(3), 3, qieCoder, qieShape)
0062 : pedestalBarrelValues[i].getValue(3);
0063 }
0064
0065
0066 auto const& pedestalEndcapValues = pedestalsAll[1].second;
0067 auto const& qieDataEndcapValues = qieDataAll[1].second;
0068 auto const& qieTypesEndcapValues = qieTypesAll[1].second;
0069
0070 #ifdef HCAL_MAHI_CPUDEBUG
0071 assert(pedestalEndcapValues.size() == qieDataEndcapValues.size());
0072 assert(pedestalEndcapValues.size() == qieTypesEndcapValues.size());
0073 #endif
0074
0075 auto const offset = pedestalBarrelValues.size();
0076 for (uint64_t i = 0; i < pedestalEndcapValues.size(); ++i) {
0077 auto const& qieCoder = qieDataEndcapValues[i];
0078 auto const qieType = qieTypesEndcapValues[i].getValue() > 1 ? 1 : 0;
0079 auto const& qieShape = qieData.getShape(qieType);
0080 auto const off = offset + i;
0081
0082 values_[off * 4] = unitIsADC ? convert(pedestalEndcapValues[i].getValue(0), 0, qieCoder, qieShape)
0083 : pedestalEndcapValues[i].getValue(0);
0084 values_[off * 4 + 1] = unitIsADC ? convert(pedestalEndcapValues[i].getValue(1), 1, qieCoder, qieShape)
0085 : pedestalEndcapValues[i].getValue(1);
0086 values_[off * 4 + 2] = unitIsADC ? convert(pedestalEndcapValues[i].getValue(2), 2, qieCoder, qieShape)
0087 : pedestalEndcapValues[i].getValue(2);
0088 values_[off * 4 + 3] = unitIsADC ? convert(pedestalEndcapValues[i].getValue(3), 3, qieCoder, qieShape)
0089 : pedestalEndcapValues[i].getValue(3);
0090
0091 #ifdef HCAL_MAHI_CPUDEBUG
0092 if (pedestalEndcapValues[i].rawId() == DETID_TO_DEBUG) {
0093 printf("qietype = %d\n", qieType);
0094 printf("ped0 = %f ped1 = %f ped2 = %f ped3 = %f\n",
0095 pedestalEndcapValues[i].getValue(0),
0096 pedestalEndcapValues[i].getValue(1),
0097 pedestalEndcapValues[i].getValue(2),
0098 pedestalEndcapValues[i].getValue(3));
0099 printf("converted: ped0 = %f ped1 = %f ped2 = %f ped3 = %f\n",
0100 values_[off * 4],
0101 values_[off * 4 + 1],
0102 values_[off * 4 + 2],
0103 values_[off * 4 + 3]);
0104 }
0105 #endif
0106 }
0107 }
0108
0109 HcalConvertedPedestalsGPU::Product const& HcalConvertedPedestalsGPU::getProduct(cudaStream_t stream) const {
0110 auto const& product = product_.dataForCurrentDeviceAsync(
0111 stream, [this](HcalConvertedPedestalsGPU::Product& product, cudaStream_t stream) {
0112
0113 product.values = cms::cuda::make_device_unique<float[]>(values_.size(), stream);
0114
0115
0116 cms::cuda::copyAsync(product.values, values_, stream);
0117 });
0118
0119 return product;
0120 }
0121
0122 TYPELOOKUP_DATA_REG(HcalConvertedPedestalsGPU);