12#ifndef ALICEO2_TPC_CALDET_H_
13#define ALICEO2_TPC_CALDET_H_
27#ifndef GPUCA_ALIGPUCODE
29#include <fmt/format.h>
56 CalDet(
PadSubset padSusbset) : mName{
"PadCalibrationObject"}, mData{}, mPadSubset{padSusbset} { initData(); }
64 const std::vector<CalType>&
getData()
const {
return mData; }
65 std::vector<CalType>&
getData() {
return mData; }
74 const T
getValue(
const int sec,
const int globalPadInSector)
const;
75 void setValue(
const int sec,
const int globalPadInSector,
const T&
value);
76 void setValue(
const int sec,
const int rowInSector,
const int padInRow,
const T&
value);
82 const T
getValue(
const Sector sec,
const int rowInSector,
const int padInRow)
const;
84 void setName(
const std::string_view
name,
bool nameCalArrays =
true)
91 const std::string&
getName()
const {
return mName; }
113 template <
typename U = T>
116 if (mData.size() == 0) {
122 for (
const auto&
data : mData) {
123 const auto& vals =
data.getData();
124 sum += std::accumulate(vals.begin(), vals.end(), U{0});
125 nVal +=
static_cast<U
>(vals.size());
128 return (nVal > 0) ?
sum / nVal : U{0};
131 template <
typename U = T>
134 if (mData.size() == 0) {
139 for (
const auto&
data : mData) {
140 const auto& vals =
data.getData();
141 sum +=
data.template getSum<U>();
149 std::vector<CalType> mData;
165 auto padPos = mapper.
padPos(globalPadInSector);
166 const auto globalRow = padPos.getRow();
168 int rocNumber = sector;
169 int padInROC = globalPadInSector;
171 if (globalPadInSector >= padsInIROC) {
173 padInROC -= padsInIROC;
176 switch (mPadSubset) {
178 return mData[rocNumber].getValue(padInROC);
187 const auto mappedPad = padPos.getPad();
204 const size_t mappedRow =
row % nRows;
206 const size_t mappedPad = pad % nPads;
209 switch (mPadSubset) {
211 return mData[
roc].getValue(mappedRow, mappedPad);
222 assert(dataRow < mData.size());
230#ifndef GPUCA_ALIGPUCODE
231 static bool printMsg =
true;
233 LOG(error) <<
"Out of bound access in TPC CalDet ROC " <<
roc <<
" row " <<
row <<
" pad " << pad <<
" (no more messages printed)";
239 return mData[dataRow].getValue(
index);
255 const size_t nRows = info.getNumberOfPadRows();
256 const size_t mappedRow =
row % nRows;
257 const size_t nPads = info.getPadsInRowRegion(mappedRow);
258 const size_t mappedPad = pad % nPads;
260 switch (mPadSubset) {
264 const size_t rowROC = mappedRow + info.getGlobalRowOffset() - irocOffset;
267 return mData[
roc].getValue(channel);
274 return mData[cru].getValue(mappedRow, mappedPad);
286 int padInROC = globalPadInSector;
288 if (globalPadInSector >= padsInIROC) {
290 padInROC -= padsInIROC;
292 mData[
roc].setValue(padInROC,
value);
300 int rowInROC = rowInSector;
301 const int rowsInIROC = 63;
302 if (rowInSector >= rowsInIROC) {
304 rowInROC -= rowsInIROC;
306 mData[
roc].setValue(rowInROC, padInRow,
value);
314 int rowInROC = rowInSector;
315 const int rowsInIROC = 63;
316 if (rowInSector >= rowsInIROC) {
318 rowInROC -= rowsInIROC;
320 return mData[
roc].getValue(rowInROC, padInRow);
323#ifndef GPUCA_ALIGPUCODE
331 if (mPadSubset !=
other.mPadSubset) {
332 LOG(error) <<
"Pad subste type of the objects it not compatible";
336 for (
size_t i = 0;
i < mData.size(); ++
i) {
348 if (mPadSubset !=
other.mPadSubset) {
349 LOG(error) <<
"Pad subste type of the objects it not compatible";
353 for (
size_t i = 0;
i < mData.size(); ++
i) {
365 if (mPadSubset !=
other.mPadSubset) {
366 LOG(error) <<
"Pad subste type of the objects it not compatible";
370 for (
size_t i = 0;
i < mData.size(); ++
i) {
382 if (mPadSubset !=
other.mPadSubset) {
383 LOG(error) <<
"Pad subste type of the objects it not compatible";
387 for (
size_t i = 0;
i < mData.size(); ++
i) {
397 for (
auto& cal : mData) {
407 for (
auto& cal : mData) {
417 for (
auto& cal : mData) {
427 for (
auto& cal : mData) {
437 for (
auto& cal : mData) {
449 if (mPadSubset !=
other.mPadSubset) {
450 LOG(error) <<
"Pad subste type of the objects it not compatible";
454 for (
size_t i = 0;
i < mData.size(); ++
i) {
455 if (!(mData[
i] ==
other.mData[
i])) {
481void CalDet<T>::initData()
487 bool hasData = mData.size() > 0;
489 switch (mPadSubset) {
492 frmt =
"{}_ROC_{:02d}";
497 frmt =
"{}_Partition_{:02d}";
502 frmt =
"{}_Region_{:02d}";
507 for (
size_t i = 0;
i <
size; ++
i) {
509 mData.push_back(CalType(mPadSubset,
i));
511 mData[
i].setName(fmt::format(fmt::runtime(frmt), mName,
i));
std::enable_if_t< std::is_signed< T >::value, bool > hasData(const CalArray< T > &cal)
unsigned char region() const
const CalDet & operator-=(const CalDet &other)
const CalDet & operator-=(const T &val)
CalDet(PadSubset padSusbset)
const T getValue(const CRU cru, const size_t row, const size_t pad) const
const CalDet & operator+=(const CalDet &other)
friend CalDet< U > operator+(const CalDet< U > &, const CalDet< U > &)
const CalType & getCalArray(size_t position) const
CalDet & operator=(CalDet const &)=default
void setValue(const int sec, const int globalPadInSector, const T &value)
const CalDet & operator=(const T &val)
void setValue(const int sec, const int rowInSector, const int padInRow, const T &value)
const CalDet & operator/=(const T &val)
bool operator==(const CalDet &other) const
CalDet(const std::string_view name, const PadSubset padSusbset=PadSubset::ROC)
const CalDet & operator*=(const CalDet &other)
PadSubset getPadSubset() const
const CalDet & multiply(const T &val)
const CalDet & operator*=(const T &val)
const T getValue(const ROC roc, const size_t row, const size_t pad) const
CalDet(CalDet const &)=default
const CalDet & operator/=(const CalDet &other)
const T getValue(const int sec, const int globalPadInSector) const
CalType & getCalArray(size_t position)
void setName(const std::string_view name, bool nameCalArrays=true)
const T getValue(const Sector sec, const int rowInSector, const int padInRow) const
const std::vector< CalType > & getData() const
const CalDet & operator+=(const T &val)
friend CalDet< U > operator-(const CalDet< U > &, const CalDet< U > &)
const std::string & getName() const
std::vector< CalType > & getData()
const PadPos & padPos(GlobalPadNumber padNumber) const
int getNumberOfRowsROC(ROC roc) const
int getNumberOfPadsInRowROC(int roc, int row) const
static Mapper & instance(const std::string mappingDir="")
static constexpr unsigned short getPadsInIROC()
const PadRegionInfo & getPadRegionInfo(const unsigned char region) const
static constexpr unsigned int NREGIONS
total number of regions in one sector
GlobalPadNumber getPadNumberInROC(const PadROCPos &rocPadPosition) const
static constexpr unsigned int OFFSETCRUGLOBAL[PADROWS]
row offset in cru for given global pad row
static constexpr unsigned short getNumberOfIROCs()
static constexpr unsigned REGION[PADROWS]
region for global pad row
Pad and row inside a ROC.
static constexpr int MAXSECTOR
GLuint const GLchar * name
GLsizei const GLfloat * value
CalDet< T > operator+(const CalDet< T > &c1, const CalDet< T > &c2)
PadSubset
Definition of the different pad subsets.
@ Partition
Partitions (up to 36*5)
@ Region
Regions (up to 36*10)
CalDet< T > operator-(const CalDet< T > &c1, const CalDet< T > &c2)
DataT sum(const Vector< DataT, N > &a)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
VectorOfTObjectPtrs other
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"