5#ifndef TILECALIBDRAWEROFC_H
6#define TILECALIBDRAWEROFC_H
29#include "CoralBase/Blob.h"
37#define PHASE_PRECISION 0.1
69 , std::string_view author =
""
70 , std::string_view comment =
""
71 , uint64_t timeStamp = 0);
88 float getPhase(
unsigned int channel,
unsigned int adc,
unsigned int phaseIdx)
const;
108 float getOfc(
unsigned int field,
unsigned int channel,
unsigned int adc,
float phase,
unsigned int sample)
const;
117 void fillOfc (
unsigned int channel,
unsigned int adc,
float& phase,
float* w_a,
float* w_b,
float* w_c,
float* g,
float* dg )
const;
121 virtual void dump()
const;
124 virtual void dump(std::ostream& stm)
const;
141 void init(uint16_t objVersion
146 , std::string_view author=
""
147 , std::string_view comment=
""
148 , uint64_t timeStamp=0);
157 void setOfc(
unsigned int field,
unsigned int channel,
unsigned int adc,
float phase,
unsigned int sample,
float value);
163 void setPhases(
unsigned int channel,
unsigned int adc,
const std::vector<float>& phases);
179 const float*
getOfcStartAddress(
unsigned int field,
unsigned int channel,
unsigned int adc,
float& phase)
const;
182 unsigned int getOfcStartOffset(
unsigned int field,
unsigned int channel,
unsigned int adc,
float& phase)
const;
197 unsigned int getPhaseNumber(
unsigned int channel,
unsigned int adc,
float& phase)
const;
204 return *(
static_cast<const uint32_t*
>(
getAddress(0)));
211 return *(
static_cast<const int32_t*
>(
getAddress(1)));
219 if (std::abs(phase) > 1e6F) {
226 const int32_t*
pos = std::lower_bound(beg, end, db_phase);
228 if (pos == end || (*pos != db_phase && pos != beg && (*pos - db_phase) > (db_phase - *(pos - 1)))) {
250 if( objVersion == 3){
return 5; }
251 else if(objVersion == 2){
return 4; }
252 else if(objVersion == 1){
return 3; }
254 throw TileCalib::VersionConflict(
"TileCalibDrawerOfc::getNFields", objVersion);
261 ,
float phase,
unsigned int sample)
const {
263 throw TileCalib::IndexOutOfRange(
"TileCalibDrawerOfc::getA", sample,
getNSamples());
268 ,
float* w_a,
float* w_b,
float* w_c,
float* g,
float* dg)
const {
275 std::memcpy(w_a, startAddress, allSamplesSize);
276 startAddress += fieldSize;
277 std::memcpy(w_b, startAddress, allSamplesSize);
278 startAddress += fieldSize;
279 std::memcpy(g, startAddress, allSamplesSize);
280 startAddress += fieldSize;
281 std::memcpy(w_c, startAddress, allSamplesSize);
283 startAddress += fieldSize;
284 std::memcpy(dg, startAddress, allSamplesSize);
286 std::memset(dg, 0, allSamplesSize);
294 ,
float phase,
unsigned int sample,
float value) {
296 throw TileCalib::IndexOutOfRange(
"TileCalibDrawerOfc::setOfc", sample,
getNSamples());
305 if(phaseIdx >=
static_cast<unsigned int>(std::abs(
getNPhases()))){
306 throw TileCalib::IndexOutOfRange(
"TileCalibDrawerOfc::getPhaseStartAddress", phaseIdx, std::abs(
getNPhases()));
315 throw TileCalib::IndexOutOfRange(
"TileCalibDrawerOfc::getPhaseStartAddress", channel,
getNChans());
317 throw TileCalib::IndexOutOfRange(
"TileCalibDrawerOfc::getPhaseStartAddress", adc,
getNGains());
321 unsigned int nPhases = std::abs(
getNPhases());
364 if(objVer!=1 && objVer!=2 && objVer!=3){
365 throw TileCalib::VersionConflict(
"TileCalibDrawerOfc::getOfcStartAddress", objVer);
374 throw TileCalib::IndexOutOfRange(
"TileCalibDrawerOfc::getOfcStartAddress", field, nField);
379 unsigned int nPhaseAbs = std::abs(
getNPhases());
382 if(nPhaseSgn < 0) {
offset += nPhaseAbs; }
389 unsigned int lPhase = nSample * nField;
390 unsigned int lAdc = lPhase * nPhaseAbs;
391 unsigned int lChan = lAdc * nGain;
__attribute__((always_inline)) inline uint32_t TileCalibDrawerOfc
#define PHASE_PRECISION
Class for storing Optimal Filtering Coefficients (OFCs) in a coral::Blob.
uint16_t getNChans() const
Returns the number of channels stored in the BLOB.
uint16_t getNGains() const
Returns the number of gains stored for each channel.
TileCalibDrawerBase(const TileCalibDrawerBase &other)
Copy Ctor.
uint16_t getObjVersion() const
Returns the BLOB object version.
uint32_t getObjSizeUint32() const
Returns the size of a data object in units of uint32_t.
const void * getAddress(unsigned int iEle) const
Returns start address of iEle-th basic unit.
TileCalibDrawerOfc(const coral::Blob &blob)
Ctor (const).
unsigned int getPhaseNumber(unsigned int channel, unsigned int adc, float &phase) const
Returns the index for a given phase.
int32_t getNPhases() const
Returns the number of phases (WARNING: Can be negative!).
void init(uint16_t objVersion, uint32_t nSamples, int32_t nPhases, uint16_t nChans, uint16_t nGains, std::string_view author="", std::string_view comment="", uint64_t timeStamp=0)
Function for initializing a TileCalibDrawerOfc BLOB.
void setOfc(unsigned int field, unsigned int channel, unsigned int adc, float phase, unsigned int sample, float value)
Sets OFC data.
float getPhase(unsigned int channel, unsigned int adc, unsigned int phaseIdx) const
Returns the stored phase.
void fillOfc(unsigned int channel, unsigned int adc, float &phase, float *w_a, float *w_b, float *w_c, float *g, float *dg) const
Fill all OFC for optimazation.
uint32_t getNSamples() const
Returns the number of sample stored.
virtual uint16_t getType() const
Returns TileCalibType::OFC.
unsigned int getOfcStartOffset(unsigned int field, unsigned int channel, unsigned int adc, float &phase) const
void setPhases(unsigned int channel, unsigned int adc, const std::vector< float > &phases)
Sets a phase value.
FIELD
OFC field identifier.
const float * getOfcStartAddress(unsigned int field, unsigned int channel, unsigned int adc, float &phase) const
Returns pointer to first data OFC for a given field, ADC & phase.
int32_t * getPhaseStartAddress(unsigned int channel, unsigned int adc, unsigned int phaseIdx)
float getOfc(unsigned int field, unsigned int channel, unsigned int adc, float phase, unsigned int sample) const
Returns OFC data.
virtual ~TileCalibDrawerOfc()
Dtor.
virtual void dump() const
Prints out the object content to std::cout.
float * getOfcStartAddress(unsigned int field, unsigned int channel, unsigned int adc, float &phase)
const int32_t * getPhaseStartAddress(unsigned int channel, unsigned int adc, unsigned int phaseIdx) const
Returns pointer to the requested phase value.
uint32_t getNFields(uint16_t objVersion=0) const
Returns the number of fields.
static TileCalibDrawerOfc * getInstance(coral::Blob &blob, uint16_t objVersion, uint32_t nSamples, int32_t nPhases, uint16_t nChans, uint16_t nGains, std::string_view author="", std::string_view comment="", uint64_t timeStamp=0)
Returns a pointer to a non-const TileCalibDrawerOfc.
unsigned int getPhaseStartOffset(unsigned int channel, unsigned int adc, unsigned int phaseIdx) const
@ OFC
Enum for TileCalibDrawerOfc class.
static const unsigned int MAX_CHAN
Number of channels in drawer.