ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCondBlobDat.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 CALOCONDBLOBOBJS_CALOCONDBLOBDAT_H
6#define CALOCONDBLOBOBJS_CALOCONDBLOBDAT_H
7
20
23#include <stdint.h>
24#include <vector>
25#include <ostream>
26#include <iostream>
27#include "CoralBase/Blob.h"
28
29template<class T>
31{
32 public:
37 typedef std::vector<std::vector<T> > DefType;
38
40 virtual ~CaloCondBlobDat(){}
41
42 //==================================================================
43 //== Data getter and setter methods
44 //==================================================================
49 T getData(const unsigned int channel, const unsigned int adc, const unsigned int idx) const;
50
51 //==================================================================
52 //== Optimized data getter for calibrations independent of gain and ADC
53 //==================================================================
57 T getData(const unsigned int channel) const;
58
67 void init(const DefType& def,
68 uint32_t nChans,
69 uint16_t objVers,
70 const std::string& author="",
71 const std::string& comment="",
72 uint64_t timeStamp=0);
73
79 void setData(unsigned int channel, unsigned int adc, unsigned int idx, T data);
80
85 void setData(unsigned int channel, unsigned int adc, const std::vector<T>& data);
86
87
89 virtual void dump() const { dump(std::cout); }
92 virtual void dump(std::ostream& stm) const;
93
94 protected:
96 CaloCondBlobDat(const coral::Blob& blob) : CaloCondBlobBase(blob){}
98 CaloCondBlobDat(coral::Blob& blob) : CaloCondBlobBase(blob){}
99
100
104 const T* getAddress(const unsigned int channel, const unsigned int adc) const;
105 T* getAddress(const unsigned int channel, const unsigned int adc);
106};
107
108//
109//_______________________________________________________________
110template<class T> void
112 uint32_t nChans,
113 uint16_t objVers,
114 const std::string& author,
115 const std::string& comment,
116 uint64_t timeStamp)
117{
118 uint32_t objSize = def.begin()->size() * sizeof(T)/sizeof(uint32_t);
119 uint16_t nGains = def.size();
120 uint32_t nObjs = nChans*nGains;
121 createBlob(getType(), objVers, objSize, nObjs, nChans, nGains, author, comment, timeStamp);
122
123 //=== fill the blob with default
124 for(unsigned int channel=0; channel<nChans; ++channel){
125 for(unsigned int adc=0; adc<nGains; ++adc){
126 setData(channel, adc, def[adc]);
127 }
128 }
129}
130
131//
132//______________________________________________________________
133template<class T> T
134CaloCondBlobDat<T>::getData(const unsigned int channel, const unsigned int adc, const unsigned int idx) const
135{
136 if(idx<getObjSizeUint32()){return getAddress(channel,adc)[idx];}
137 else{throw CaloCond::IndexOutOfRange("CaloCondBlobDat::getData",idx,getObjVersion());}
138}
139
140
141template<class T> T
142CaloCondBlobDat<T>::getData(const unsigned int channel) const {
143return (static_cast<const T*>(m_pDataStart))[channel];
144}
145
146
147//
148//______________________________________________________________
149template<class T> void
150CaloCondBlobDat<T>::setData(unsigned int channel, unsigned int adc, unsigned int idx, T data)
151{
152 if(idx<getObjSizeUint32()){ getAddress(channel,adc)[idx] = data;}
153 else{throw CaloCond::IndexOutOfRange("CaloCondBlobDat::setData",idx,getObjVersion());}
154}
155
156//
157//______________________________________________________________
158template<class T> void
159CaloCondBlobDat<T>::setData(unsigned int channel, unsigned int adc, const std::vector<T>& data)
160{
161 for(typename std::vector<T>::const_iterator i=data.begin(); i!=data.end(); ++i){
162 setData(channel,adc,i-data.begin(),*i);
163 }
164}
165
166//
167//______________________________________________________________
168template<class T> const T*
169CaloCondBlobDat<T>::getAddress(const unsigned int channel, const unsigned int adc) const
170{
171 //=== check for out of bounds
172 if(channel >= getNChans()){
173 throw CaloCond::IndexOutOfRange("CaloCondBlobDat::getAddress(channel)",channel,getNChans());
174 }
175 if(adc>=getNGains()){
176 throw CaloCond::IndexOutOfRange("CaloCondBlobDat::getAddress(gain)",adc,getNGains());
177 }
178
179 const unsigned int idx = channel*getNGains() + adc;
180 return static_cast<const T*>(CaloCondBlobBase::getAddress(idx));
181}
182
183//
184//______________________________________________________________
185template<class T> T*
186CaloCondBlobDat<T>::getAddress(const unsigned int channel, const unsigned int adc)
187{
188 //=== check for out of bounds
189 if(channel >= getNChans()){
190 throw CaloCond::IndexOutOfRange("CaloCondBlobDat::getAddress(channel)",channel,getNChans());
191 }
192 if(adc>=getNGains()){
193 throw CaloCond::IndexOutOfRange("CaloCondBlobDat::getAddress(gain)",adc,getNGains());
194 }
195
196 const unsigned int idx = channel*getNGains() + adc;
197 return static_cast<T*>(CaloCondBlobBase::getAddress(idx));
198}
199
200//
201//______________________________________________________________
202template<class T> void
203CaloCondBlobDat<T>::dump(std::ostream& stm) const
204{
206 for(unsigned int channel=0; channel<getNChans(); ++channel){
207 for(unsigned int adc=0; adc<getNGains(); ++adc){
208 stm << channel<<"/"<<adc<<":\t";
209 for(unsigned int idx=0; idx<getObjSizeUint32(); ++idx){
210 stm << getData(channel,adc,idx) << "\t";
211 }
212 stm << std::endl;
213 }
214 }
215}
216
217
218#endif
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
uint32_t getNGains() const
Returns the number of gains stored for each channel.
const void * getAddress(unsigned int iEle) const
Returns start address of iEle-th basic unit.
uint32_t getObjSizeUint32() const
Returns the size of a data object in units of uint32_t.
void dumpHeader(std::ostream &stm) const
Prints the BLOB header summary information.
uint32_t createBlob(uint16_t objType, uint16_t objVersion, uint32_t objSizeUint32, uint32_t nObjs, uint32_t nChans, uint16_t nGains, const std::string &author="", const std::string &comment="", uint64_t timeStamp=0)
(re-)creation of the referenced BLOB object.
CaloCondBlobBase(const CaloCondBlobBase &other)
Copy Ctor.
uint32_t getNChans() const
Returns the number of channels stored in the BLOB.
uint16_t getObjVersion() const
Returns the BLOB object version.
const void * m_pDataStart
virtual uint16_t getType() const
Returns CaloCondDrawer::BASE.
virtual void dump() const
Prints out the content of the blob to std::out.
CaloCondBlobDat(coral::Blob &blob)
Ctor.
void init(const DefType &def, uint32_t nChans, uint16_t objVers, const std::string &author="", const std::string &comment="", uint64_t timeStamp=0)
Initializing function.
const T * getAddress(const unsigned int channel, const unsigned int adc) const
Returns a pointer to the first value for the specified channel/gain.
std::vector< std::vector< T > > DefType
Object to hold default data used for initialization.
CaloCondBlobDat(const coral::Blob &blob)
Ctor.
void setData(unsigned int channel, unsigned int adc, unsigned int idx, T data)
Sets a single T belonging to a channel/gain.
virtual ~CaloCondBlobDat()
Dtor.
T getData(const unsigned int channel, const unsigned int adc, const unsigned int idx) const
Returns a single T belonging to a channel/gain.