ATLAS Offline Software
Loading...
Searching...
No Matches
TileCalibDrawerOfc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <iostream>
7#include <set>
8#include <algorithm>
9
10
11//
12//_____________________________________________________________
14 , uint16_t objVersion
15 , uint32_t nSamples
16 , int32_t nPhases
17 , uint16_t nChans
18 , uint16_t nGains
19 , std::string_view author
20 , std::string_view comment
21 , uint64_t timeStamp)
22{
23 TileCalibDrawerOfc* calibDrawer = new TileCalibDrawerOfc(blob);
24 calibDrawer->init(objVersion, nSamples, nPhases, nChans, nGains, author, comment, timeStamp);
25 return calibDrawer;
26}
27
28//
29//_____________________________________________________________
30const TileCalibDrawerOfc* TileCalibDrawerOfc::getInstance(const coral::Blob& blob) {
31
32 //=== const Blob needs to be correctly formated
33 if(blob.size() < static_cast<long>(m_hdrSize32)) {
34 throw TileCalib::InvalidBlob("TileCalibDrawerOfc::getInstance");
35 }
36 return (new TileCalibDrawerOfc(blob));
37}
38
39//
40//_______________________________________________________________
43{
44 initCheck();
45}
46
47//
48//_______________________________________________________________
51{
52 initCheck();
53}
54
55//
56//_______________________________________________________________
58{
59 if(getBlobSize()){
60
61 //=== check for correct blob type
62 if(getObjType() != getType()){
63 throw TileCalib::TypeConflict("TileCalibDrawerOfc::Ctor", getObjType(), getType());
64 }
65
66 //=== check for correct object size
67 unsigned int blobObjSize = getObjSizeByte();
68 unsigned int thisObjSize = 0;
69 if( getObjVersion() == 1){
70 //=== set object size to base unit (4 bytes)
71 thisObjSize = sizeof(uint32_t);
72 }
73 else if(getObjVersion() == 2){
74 //=== set object size to base unit (4 bytes)
75 thisObjSize = sizeof(uint32_t);
76 }
77 else if(getObjVersion() == 3){
78 //=== set object size to base unit (4 bytes)
79 thisObjSize = sizeof(uint32_t);
80 }
81 if(blobObjSize != thisObjSize){
82 throw TileCalib::SizeConflict("TileCalibDrawerOfc::Ctor", thisObjSize, blobObjSize);
83 }
84
85 }
86}
87
88//
89//_______________________________________________________________
90void TileCalibDrawerOfc::init(uint16_t objVersion
91 , uint32_t nSamples
92 , int32_t nPhases
93 , uint16_t nChans
94 , uint16_t nGains
95 , std::string_view author
96 , std::string_view comment
97 , uint64_t timeStamp)
98{
99 const uint16_t extraHeaderSize(2);
100 uint16_t objType = getType();
101 uint32_t objSize = 1; // everything is either uint32_t or float
102 uint32_t objCount = extraHeaderSize;
103
104 //=== if nPhases<0, use one phase table for ADCs
105 //=== otherwise use one table per ADC
106 unsigned int nPhasesAbs = std::abs(nPhases);
107 int nPhasesSgn = nPhases < 0 ? -1 : 1;
108 unsigned int phasesSize = nPhasesAbs;
109 if(nPhasesSgn > 0){ phasesSize *= nChans*nGains; }
110 objCount += phasesSize;
111
112 uint32_t nFields = getNFields(objVersion);
113 objCount += ( nSamples * nFields * nGains * nPhasesAbs * nChans );
114
115 //=== create blob of correct type and size
116 uint32_t blobLengthUint32 =
117 createBlob(objType, objVersion, objSize, objCount, nChans, nGains, author, comment, timeStamp);
118
119 //=== fill header
120 uint32_t* pu = static_cast<uint32_t*>(getAddress(0));
121 *pu = nSamples;
122 int32_t* pi = reinterpret_cast<int32_t*>(++pu);
123 *pi = nPhases;
124 //=== initialize phase field to zero
125 for(unsigned int iPhase = 0; iPhase < phasesSize; ++iPhase){
126 *(++pi) = int32_t(0);
127 }
128
129 //=== initialize rest of blob to zero
130 for(unsigned int i = 0; i < blobLengthUint32 - (m_hdrSize32 + extraHeaderSize + phasesSize); ++i){
131 *(++pi) = 0; //zero float = zero int
132 }
133}
134
135
136//
137//______________________________________________________________
138void TileCalibDrawerOfc::setPhases(unsigned int channel, unsigned int adc, const std::vector<float>& phases) {
139
140 std::set<int32_t> phaseSet;
141 for (const float phase : phases) {
142 phaseSet.insert((int32_t) std::round(phase * (1 / PHASE_PRECISION))); // Phases are stored as int(10*phase) in DB
143 }
144
145 if(int(phaseSet.size()) != std::abs(getNPhases())){
146 throw TileCalib::IndexOutOfRange("TileCalibDrawerOfc::setPhases", phaseSet.size(), std::abs(getNPhases()));
147 }
148
149 unsigned int idx(0);
150 for (const int32_t phase : phaseSet) {
151 *(getPhaseStartAddress(channel, adc, idx)) = phase;
152 ++idx;
153 }
154
155}
156
157//
158//______________________________________________________________
159void TileCalibDrawerOfc::dump(std::ostream& stm) const {
161 unsigned int channel = 0;
162 for(int iPhase = 0; iPhase < std::abs(getNPhases()); ++iPhase){
163 for(unsigned int sample = 0; sample < getNSamples(); ++sample){
164 for(unsigned int adc = 0; adc < getNGains(); ++adc){
165 float phase = getPhase(channel, adc, iPhase);
166 stm << channel << "/" << phase << "/" << sample << "/" << adc << "\t";
167 for(unsigned int field = 0; field < getNFields(getObjVersion()); ++field){
168 stm << getOfc(field,channel, adc, phase, sample) << "\t";
169 }
170 stm << std::endl;
171 }
172 }
173 }
174}
175
177 dump(std::cout);
178}
#define PHASE_PRECISION
Class for storing Optimal Filtering Coefficients (OFCs) in a coral::Blob.
#define pi
uint16_t getObjType() const
Returns the BLOB object type.
uint16_t getNGains() const
Returns the number of gains stored for each channel.
long getBlobSize() const
Returns the BLOB size in units of bytes.
void dumpHeader(std::ostream &stm) const
Prints the BLOB header summary information.
TileCalibDrawerBase(const TileCalibDrawerBase &other)
Copy Ctor.
static const unsigned int m_hdrSize32
The header size in units of uint32_t.
uint16_t getObjVersion() const
Returns the BLOB object version.
uint32_t getObjSizeByte() const
Returns the size of a data object in units of bytes.
uint32_t createBlob(uint16_t objType, uint16_t objVersion, uint32_t objSizeUint32, uint32_t nObjs, uint16_t nChans, uint16_t nGains, std::string_view author="", std::string_view comment="", uint64_t timeStamp=0)
(re-)creation of the referenced BLOB object.
const void * getAddress(unsigned int iEle) const
Returns start address of iEle-th basic unit.
TileCalibDrawerOfc(const coral::Blob &blob)
Ctor (const).
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.
float getPhase(unsigned int channel, unsigned int adc, unsigned int phaseIdx) const
Returns the stored phase.
uint32_t getNSamples() const
Returns the number of sample stored.
virtual uint16_t getType() const
Returns TileCalibType::OFC.
void setPhases(unsigned int channel, unsigned int adc, const std::vector< float > &phases)
Sets a phase value.
float getOfc(unsigned int field, unsigned int channel, unsigned int adc, float phase, unsigned int sample) const
Returns OFC data.
virtual void dump() const
Prints out the object content to std::cout.
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.
Thrown if coral::Blob does not conform with expected structure.
Thrown if object type in BLOB does not agree with class type.