ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCondBlobBase.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef CALOCONDBLOBOBJS_CALOCONDBLOBBASE_H
6#define CALOCONDBLOBOBJS_CALOCONDBLOBBASE_H
7
31
32
33#include <stdint.h>
34#include <vector>
35#include <string>
36#include <ostream>
37#include <iostream>
38#include "CoralBase/Blob.h"
42
44 public:
46 virtual ~CaloCondBlobBase();
51
53 virtual uint16_t getType() const {return CaloCondType::BASE;}
54
56 virtual void dump() const { dumpHeader(std::cout); }
59 virtual void dump(std::ostream& stm) const {dumpHeader(stm);}
60
61
62 //==================================================================
63 //== Accessor methods for the header
64 //==================================================================
66 long getBlobSize() const {return m_blob->size(); }
68 uint16_t getObjType() const;
70 uint16_t getObjVersion() const;
72 uint32_t getObjSizeUint32() const;
74 uint32_t getObjSizeByte() const {return getObjSizeUint32()*sizeof(uint32_t);}
76 uint32_t getNObjs() const;
78 uint32_t getNChans() const;
80 uint32_t getNGains() const;
82 uint32_t getCommentSizeUint32() const;
84 uint32_t getCommentSizeChar() const {return getCommentSizeUint32()*sizeof(uint32_t);}
86 unsigned int getHdrSize() const {return 5;}
87
88 //==================================================================
89 //== Accessor methods for the comment fields
90 //==================================================================
92 std::string getAuthor() const;
94 std::string getComment() const;
96 uint64_t getTimeStamp() const;
98 std::string getDate() const;
100 std::string getFullComment() const;
101
102
103 //==================================================================
104 //== Blob field access
105 //==================================================================
108 const void* getAddress(unsigned int iEle) const;
109 void* getAddress(unsigned int iEle);
110
111
112 protected:
114 CaloCondBlobBase(const coral::Blob& blob);
115
117 CaloCondBlobBase(coral::Blob& blob);
118
129 uint32_t createBlob(uint16_t objType,
130 uint16_t objVersion,
131 uint32_t objSizeUint32,
132 uint32_t nObjs,
133 uint32_t nChans,
134 uint16_t nGains,
135 const std::string& author="",
136 const std::string& comment="",
137 uint64_t timeStamp=0);
138
141 void dumpHeader(std::ostream& stm) const;
142
143 private:
145 CaloCondBlobBase(coral::Blob* blob_nc, const coral::Blob* blob);
146
147 static uint32_t packGainAndNchans(const uint32_t gain, const uint32_t nChans);
148 static uint32_t unpacknGains(const uint32_t gainAndnChans);
149 static uint32_t unpacknChans(const uint32_t gainAndnChans);
150
152 const uint32_t* getBlobStart() const;
154 uint32_t* getBlobStart();
155
158 coral::Blob* m_blob_nc;
159
161 const coral::Blob* m_blob;
162
165
167 unsigned m_sizeOfObj;
168 unsigned m_nChans;
169 unsigned m_nGains;
170protected:
171 const void* m_pDataStart;
172};
173
174
175//
176//_________________________________________________________
177inline const uint32_t*
179{
180 return static_cast<const uint32_t*>(m_blob->startingAddress());
181}
182
183//
184//_________________________________________________________
185inline uint32_t*
187{
188 return static_cast<uint32_t*>(m_blob_nc->startingAddress());
189}
190
191//
192//_________________________________________________________
193inline uint16_t
195{
196 if(uint64_t(m_blob->size())<getHdrSize()*sizeof(uint32_t))
197 throw CaloCond::InvalidBlob("CaloCondBlobBase::getObjType");
198 return static_cast<const uint16_t*>(m_blob->startingAddress())[0];
199}
200
201//
202//_________________________________________________________
203inline uint16_t
205{
206 if(uint64_t(m_blob->size())<getHdrSize()*sizeof(uint32_t))
207 throw CaloCond::InvalidBlob("CaloCondBlobBase::getObjVersion");
208 return static_cast<const uint16_t*>(m_blob->startingAddress())[1];
209}
210
211//
212//_________________________________________________________
213inline uint32_t
218
219//
220//_________________________________________________________
221inline uint32_t
223{
224 if(uint64_t(m_blob->size())<getHdrSize()*sizeof(uint32_t))
225 throw CaloCond::InvalidBlob("CaloCondBlobBase::getNObjs");
226 return static_cast<const uint32_t*>(m_blob->startingAddress())[2];
227}
228
229//
230//_________________________________________________________
231inline uint32_t
233{
234 return m_nChans;
235}
236
237//
238//_________________________________________________________
239inline uint32_t
241{
242 return m_nGains;
243
244
245}
246
247//
248//_________________________________________________________
249inline uint32_t
251{
252 if(uint64_t(m_blob->size())<getHdrSize()*sizeof(uint32_t))
253 throw CaloCond::InvalidBlob("CaloCondBlobBase::getCommentSizeUint32");
254 return static_cast<const uint32_t*>(m_blob->startingAddress())[4];
255}
256
257//
258//_________________________________________________________
259inline const void*
260CaloCondBlobBase::getAddress(unsigned int iEle) const
261{
262 if(iEle>=getNObjs()){
263 throw CaloCond::IndexOutOfRange("CaloCondBlobBase::getAddress", iEle, getNObjs());
264 }
265 return static_cast<const void*>
266 ( getBlobStart() + getHdrSize() + getObjSizeUint32()*iEle );
267}
268
269//
270//_________________________________________________________
271inline void*
273{
274 if(iEle>=getNObjs()){
275 throw CaloCond::IndexOutOfRange("CaloCondBlobBase::getAddress", iEle, getNObjs());
276 }
277 return static_cast<void*>
278 ( getBlobStart() + getHdrSize() + getObjSizeUint32()*iEle );
279}
280
281//
282//_________________________________________________________
283inline uint64_t
285{
286 if(!getCommentSizeUint32()) return 0;
287 auto p = reinterpret_cast<const uint8_t*>(getBlobStart()+getHdrSize() +
289 return CxxUtils::get_unaligned64 (p);
290}
291
292#endif
uint32_t * getBlobStart()
Returns the BLOB start address as uint32_t pointer.
uint16_t getObjType() const
Returns the BLOB object type.
virtual void dump(std::ostream &stm) const
Prints the BLOB header summary information.
std::string getDate() const
Returns the date of the comment as string (derived from timestamp)
CaloCondBlobBase & operator=(const CaloCondBlobBase &other)
Assignment operator.
virtual ~CaloCondBlobBase()
Dtor.
uint32_t getNGains() const
Returns the number of gains stored for each channel.
uint64_t getTimeStamp() const
Returns the unix timestamp of the comment (seconds since 1.1.1970)
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.
const uint32_t * getBlobStart() const
Returns the BLOB start address as uint32_t pointer.
static uint32_t packGainAndNchans(const uint32_t gain, const uint32_t nChans)
bool m_isBlobOwner
Do I own the BLOB?
std::string getAuthor() const
Returns the comment author.
static uint32_t unpacknGains(const uint32_t gainAndnChans)
uint32_t getCommentSizeUint32() const
Returns the space occupied by the comment fields in units of uint32_t.
unsigned m_sizeOfObj
Chache of some frequently-used numbers.
static uint32_t unpacknChans(const uint32_t gainAndnChans)
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 getNObjs() const
Returns the number of data objects stored int the BLOB.
std::string getComment() const
Returns the actual comment.
uint32_t getNChans() const
Returns the number of channels stored in the BLOB.
void * getAddress(unsigned int iEle)
uint32_t getObjSizeByte() const
Returns the size of a data object in units of bytes.
uint16_t getObjVersion() const
Returns the BLOB object version.
uint32_t getCommentSizeChar() const
Returns the space occupied by the comment fields in units of chars.
coral::Blob * m_blob_nc
Non-const reference to the BLOB.
std::string getFullComment() const
Returns a formated string build from all comment fields.
unsigned int getHdrSize() const
Returns the size of the header in units of uint32_t.
const coral::Blob * m_blob
Const reference to the BLOB (always there)
virtual void dump() const
Prints the BLOB header summary information to std::cout.
long getBlobSize() const
Returns the BLOB size.
const void * m_pDataStart
virtual uint16_t getType() const
Returns CaloCondDrawer::BASE.
@ BASE
Enum for CaloCondBlobBase class.
Thrown if coral::Blob does not conform with expected structure.
Read little-endian values through possibly unaligned pointers.
uint64_t get_unaligned64(const uint8_t *ATH_RESTRICT &p)
Read an 8-byte little-endian value from a possibly unaligned pointer.