ATLAS Offline Software
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 //_____________________________________________________________
17  , int32_t nPhases
18  , uint16_t nChans
19  , uint16_t nGains
20  , const std::string& author
21  , const std::string& comment
23 {
25  calibDrawer->init(objVersion, nSamples, nPhases, nChans, nGains, author, comment, timeStamp);
26  return calibDrawer;
27 }
28 
29 //
30 //_____________________________________________________________
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 //_______________________________________________________________
93  , int32_t nPhases
94  , uint16_t nChans
95  , uint16_t nGains
96  , const std::string& author
97  , const std::string& comment
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 //______________________________________________________________
144 void 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) {
158  ++idx;
159  }
160 
161 }
162 
163 //
164 //______________________________________________________________
165 void 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 }
ReadOfcFromCool.phase
phase
Definition: ReadOfcFromCool.py:127
TileCalibDrawerBase::getBlobSize
long getBlobSize() const
Returns the BLOB size in units of bytes.
Definition: TileCalibDrawerBase.h:92
TileCalibDrawerOfc::getOfc
float getOfc(unsigned int field, unsigned int channel, unsigned int adc, float phase, unsigned int sample) const
Returns OFC data.
TileCalib::IndexOutOfRange
Thrown if an index is out of range.
Definition: TileCalorimeter/TileCalib/TileCalibBlobObjs/TileCalibBlobObjs/Exception.h:141
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
TileCalibDrawerBase::getNGains
uint16_t getNGains() const
Returns the number of gains stored for each channel.
TileCalibBlobPython_writeOfc.phases
phases
Definition: TileCalibBlobPython_writeOfc.py:89
TileCalibDrawerBase::m_hdrSize32
static const unsigned int m_hdrSize32
The header size in units of uint32_t.
Definition: TileCalibDrawerBase.h:138
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TileCalib::InvalidBlob
Thrown if coral::Blob does not conform with expected structure.
Definition: TileCalorimeter/TileCalib/TileCalibBlobObjs/TileCalibBlobObjs/Exception.h:63
PHASE_PRECISION
#define PHASE_PRECISION
Class for storing Optimal Filtering Coefficients (OFCs) in a coral::Blob.
Definition: TileCalibDrawerOfc.h:38
TileCalibDrawerOfc::initCheck
void initCheck()
Definition: TileCalibDrawerOfc.cxx:58
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
TileCalibDrawerOfc::getNPhases
int32_t getNPhases() const
Returns the number of phases (WARNING: Can be negative!)
TileCalibDrawerOfc::setPhases
void setPhases(unsigned int channel, unsigned int adc, const std::vector< float > &phases)
Sets a phase value.
Definition: TileCalibDrawerOfc.cxx:144
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
TileCalibDrawerBase::dumpHeader
void dumpHeader(std::ostream &stm) const
Prints the BLOB header summary information.
Definition: TileCalibDrawerBase.cxx:200
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
TileCalib::SizeConflict
Thrown if BLOB size is not correct.
Definition: TileCalorimeter/TileCalib/TileCalibBlobObjs/TileCalibBlobObjs/Exception.h:120
TileCalibDrawerOfc::init
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.
Definition: TileCalibDrawerOfc.cxx:91
pi
#define pi
Definition: TileMuonFitter.cxx:65
TileCalibBlobPython_writeOfc.objVersion
objVersion
Definition: TileCalibBlobPython_writeOfc.py:71
TileCalibDrawerBase::getObjVersion
uint16_t getObjVersion() const
Returns the BLOB object version.
TileCalibDrawerBase::getObjSizeByte
uint32_t getObjSizeByte() const
Returns the size of a data object in units of bytes.
Definition: TileCalibDrawerBase.h:102
TileCalibDrawerOfc::getType
virtual uint16_t getType() const
Returns TileCalibType::OFC.
Definition: TileCalibDrawerOfc.h:51
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:113
TileCalibDrawerBase
This class provides the core BLOB infrastructure.
Definition: TileCalibDrawerBase.h:59
lumiFormat.i
int i
Definition: lumiFormat.py:85
D3PDSizeSummary.ff
ff
Definition: D3PDSizeSummary.py:305
TileCalibDrawerOfc::dump
virtual void dump() const
Prints out the object content to std::cout.
Definition: TileCalibDrawerOfc.h:122
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
CaloCondBlobAlgs_fillNoiseFromASCII.comment
string comment
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:27
TileCalibDrawerBase::createBlob
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.
Definition: TileCalibDrawerBase.cxx:87
TileCalibDrawerOfc::getPhase
float getPhase(unsigned int channel, unsigned int adc, unsigned int phaseIdx) const
Returns the stored phase.
BchCleanup.calibDrawer
calibDrawer
Definition: BchCleanup.py:217
xAOD::timeStamp
setEventNumber timeStamp
Definition: EventInfo_v1.cxx:128
TileCalibDrawerOfc
Definition: TileCalibDrawerOfc.h:40
CheckAppliedSFs.pu
pu
Definition: CheckAppliedSFs.py:311
TileCalibDrawerOfc::getInstance
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.
Definition: TileCalibDrawerOfc.cxx:14
TileCalibDrawerBase::getObjType
uint16_t getObjType() const
Returns the BLOB object type.
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
CaloCondBlobAlgs_fillNoiseFromASCII.author
string author
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:26
TileCalibDrawerOfc::TileCalibDrawerOfc
TileCalibDrawerOfc(const coral::Blob &blob)
Ctor (const).
Definition: TileCalibDrawerOfc.cxx:42
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
TileCalibDrawerOfc::getNSamples
uint32_t getNSamples() const
Returns the number of sample stored.
TileCalibDrawerOfc::getPhaseStartAddress
const int32_t * getPhaseStartAddress(unsigned int channel, unsigned int adc, unsigned int phaseIdx) const
Returns pointer to the requested phase value.
TileCalibDrawerOfc::getNFields
uint32_t getNFields(uint16_t objVersion=0) const
Returns the number of fields.
TileCalib::TypeConflict
Thrown if object type in BLOB does not agree with class type.
Definition: TileCalorimeter/TileCalib/TileCalibBlobObjs/TileCalibBlobObjs/Exception.h:99
LArDigits2NtupleDumper.nSamples
nSamples
Definition: LArDigits2NtupleDumper.py:70
TileCalibDrawerOfc.h
zero
void zero(TH2 *h)
zero the contents of a 2d histogram
Definition: comparitor.cxx:436
TileCalibDrawerBase::getAddress
const void * getAddress(unsigned int iEle) const
Returns start address of iEle-th basic unit.
CaloCondBlobAlgs_fillNoiseFromASCII.blob
blob
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:96