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