ATLAS Offline Software
Loading...
Searching...
No Matches
TileCalibDrawerDat.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TILECALIBBLOBOBJS_TILECALIBDRAWERDAT_H
6#define TILECALIBBLOBOBJS_TILECALIBDRAWERDAT_H
7
20
24#include <stdint.h>
25#include <vector>
26#include <iostream>
27#include "CoralBase/Blob.h"
28
29template<class T>
31{
32 public:
37 typedef std::vector<std::vector<T> > DefType;
38
41
42 //==================================================================
43 //== Data getter and setter methods
44 //==================================================================
49 T getData(unsigned int channel, unsigned int adc, unsigned int idx) const;
50
59 void init(const DefType& def,
60 uint16_t nChans,
61 uint16_t objVers,
62 const std::string& author="",
63 const std::string& comment="",
64 uint64_t timeStamp=0);
65
71 void setData(unsigned int channel, unsigned int adc, unsigned int idx, T data);
72
77 void setData(unsigned int channel, unsigned int adc, const std::vector<T>& data);
78
79
81 virtual void dump() const { dump(std::cout); }
84 virtual void dump(std::ostream& stm) const;
85
86 protected:
89 TileCalibDrawerDat(const coral::Blob& blob) : TileCalibDrawerBase(blob){}
92 TileCalibDrawerDat(coral::Blob& blob) : TileCalibDrawerBase(blob){}
93
100 const T* getAddress(unsigned int channel, unsigned int adc) const;
101 T* getAddress(unsigned int channel, unsigned int adc);
102};
103
104//
105//_______________________________________________________________
106template<class T> void
108 uint16_t nChans,
109 uint16_t objVers,
110 const std::string& author,
111 const std::string& comment,
112 uint64_t timeStamp)
113{
114 uint16_t nGains = def.size();
115 uint32_t objSize = nGains>0 ? def.begin()->size() * sizeof(T)/sizeof(uint32_t) : 0;
116 uint32_t nObjs = nChans*nGains;
117
118 //=== ensure all gains have the same object size
119 for(unsigned int iGain=0; iGain<nGains; ++iGain){
120 unsigned int thisSize = def[iGain].size()*sizeof(T)/sizeof(uint32_t);
121 if( thisSize != objSize ){
122 throw TileCalib::SizeConflict("TileCalibDrawerDat<T>::init",thisSize,objSize);
123 }
124 }
125
126 //=== create blob
127 createBlob(getType(), objVers, objSize, nObjs, nChans, nGains, author, comment, timeStamp);
128
129 //=== fill the blob with default
130 for(unsigned int channel=0; channel<nChans; ++channel){
131 for(unsigned int adc=0; adc<nGains; ++adc){
132 setData(channel, adc, def[adc]);
133 }
134 }
135}
136
137//
138//______________________________________________________________
139template<class T> T
140TileCalibDrawerDat<T>::getData(unsigned int channel, unsigned int adc, unsigned int idx) const
141{
142 if(idx>=getObjSizeUint32()){
143 throw TileCalib::IndexOutOfRange("TileCalibDrawerDat::getData",idx,getObjVersion());
144 }
145
146 //=== Tile Default Policy
147
148 if(channel >= getNChans()) {
149 if (channel <= TileCalibUtils::MAX_CHAN) {
150 channel = 0;
151 } else {
152 channel = channel % TileCalibUtils::MAX_CHAN;
153 if (channel >= getNChans()) channel = 0;
154 }
155 }
156
157 if(adc >= getNGains()) {adc = 0;}
158
159 return getAddress(channel,adc)[idx];
160}
161
162//
163//______________________________________________________________
164template<class T> void
165TileCalibDrawerDat<T>::setData(unsigned int channel, unsigned int adc, unsigned int idx, T data)
166{
167 //=== check for out of bounds
168 if(channel >= getNChans()){
169 throw TileCalib::IndexOutOfRange("TileCalibDrawerDat::getAddress(channel)",channel,getNChans());
170 }
171 if(adc>=getNGains()){
172 throw TileCalib::IndexOutOfRange("CaloCalibDrawerDat::getAddress(gain)",adc,getNGains());
173 }
174 if(idx>=getObjSizeUint32()){
175 throw TileCalib::IndexOutOfRange("TileCalibDrawerDat::getData",idx,getObjVersion());
176 }
177
178 getAddress(channel,adc)[idx] = data;
179}
180
181//
182//______________________________________________________________
183template<class T> void
184TileCalibDrawerDat<T>::setData(unsigned int channel, unsigned int adc, const std::vector<T>& data)
185{
186 for(typename std::vector<T>::const_iterator i=data.begin(); i!=data.end(); ++i){
187 setData(channel,adc,i-data.begin(),*i);
188 }
189}
190
191//
192//______________________________________________________________
193template<class T> const T*
194TileCalibDrawerDat<T>::getAddress(unsigned int channel, unsigned int adc) const
195{
196 unsigned int idx = channel*getNGains() + adc;
197 return static_cast<const T*>(TileCalibDrawerBase::getAddress(idx));
198}
199
200//
201//______________________________________________________________
202template<class T> T*
203TileCalibDrawerDat<T>::getAddress(unsigned int channel, unsigned int adc)
204{
205 unsigned int idx = channel*getNGains() + adc;
206 return static_cast<T*>(TileCalibDrawerBase::getAddress(idx));
207}
208
209//
210//______________________________________________________________
211template<class T> void
212TileCalibDrawerDat<T>::dump(std::ostream& stm) const
213{
215 for(unsigned int channel=0; channel<getNChans(); ++channel){
216 for(unsigned int adc=0; adc<getNGains(); ++adc){
217 stm << channel<<"/"<<adc<<":\t";
218 for(unsigned int idx=0; idx<getObjSizeUint32(); ++idx){
219 stm << getData(channel,adc,idx) << "\t";
220 }
221 stm << std::endl;
222 }
223 }
224}
225
226
227#endif
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
virtual uint16_t getType() const
Returns TileCalibDrawer::BASE.
uint16_t getNChans() const
Returns the number of channels stored in the BLOB.
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 getNGains() const
Returns the number of gains stored for each channel.
void dumpHeader(std::ostream &stm) const
Prints the BLOB header summary information.
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.
virtual void dump() const
Prints out the content of the blob to std::out.
TileCalibDrawerDat(const coral::Blob &blob)
Ctor (const).
std::vector< std::vector< T > > DefType
Object to hold default data used for initialization.
TileCalibDrawerDat(coral::Blob &blob)
Ctor (non-const).
T getData(unsigned int channel, unsigned int adc, unsigned int idx) const
Returns a single T belonging to a channel/ADC.
void setData(unsigned int channel, unsigned int adc, unsigned int idx, T data)
Sets a single T belonging to a channel/ADC.
virtual ~TileCalibDrawerDat()
Dtor.
const T * getAddress(unsigned int channel, unsigned int adc) const
Returns a pointer to the first value for the specified channel & ADC.
void init(const DefType &def, uint16_t nChans, uint16_t objVers, const std::string &author="", const std::string &comment="", uint64_t timeStamp=0)
Initializing function.
static const unsigned int MAX_CHAN
Number of channels in drawer.