ATLAS Offline Software
Loading...
Searching...
No Matches
TileCalibDrawerBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include <time.h>
8#include <algorithm>
9#include <iostream>
10
11//
12//_____________________________________________________________
14 m_blob_nc(nullptr),
15 m_blob(&blob),
16 m_blobStart32(static_cast<const uint32_t*>(m_blob->startingAddress())),
17 m_blobStart16(static_cast<const uint16_t*>(m_blob->startingAddress())),
18 m_blobSize32(m_blob->size()/sizeof(uint32_t)),
19 m_isBlobOwner(false)
20{
21}
22
23//
24//_____________________________________________________________
26 m_blob_nc(&blob),
27 m_blob(&blob),
28 m_blobStart32(static_cast<const uint32_t*>(m_blob->startingAddress())),
29 m_blobStart16(static_cast<const uint16_t*>(m_blob->startingAddress())),
30 m_blobSize32(m_blob->size()/sizeof(uint32_t)),
31 m_isBlobOwner(false)
32{
33}
34
35//
36//_____________________________________________________________
38{
39 //=== delete the coral::Blob if owner
40 if(m_isBlobOwner) {delete m_blob;}
41}
42
43//
44//_____________________________________________________________
46 m_blob_nc(new coral::Blob(*other.m_blob)),
48 m_blobStart32(static_cast<const uint32_t*>(m_blob->startingAddress())),
49 m_blobStart16(static_cast<const uint16_t*>(m_blob->startingAddress())),
50 m_blobSize32(m_blob->size()/sizeof(uint32_t)),
51 m_isBlobOwner(true)
52{
53}
54
55//
56//_____________________________________________________________
59{
60 //=== catch self-assignment
61 if(&other == this) {return *this;}
62 if (m_isBlobOwner) delete m_blob;
63 m_blob_nc = other.m_blob_nc;
64 m_blob = other.m_blob;
65 m_blobStart32 = other.m_blobStart32;
66 m_blobStart16 = other.m_blobStart16;
67 m_blobSize32 = other.m_blobSize32;
68 m_isBlobOwner = other.m_isBlobOwner;
69 return *this;
70}
71
72//
73//_____________________________________________________________
74void
76{
77 //=== copy content of other blob
78 *m_blob_nc = *other.m_blob;
79 //=== and reset cached attributes
80 m_blobStart32 = static_cast<const uint32_t*>(m_blob->startingAddress());
81 m_blobStart16 = static_cast<const uint16_t*>(m_blob->startingAddress());
82 m_blobSize32 = m_blob->size()/sizeof(uint32_t);
83}
84
85//
86//_____________________________________________________________
87uint32_t
89 uint16_t objVersion,
90 uint32_t objSizeUint32,
91 uint32_t nObjs,
92 uint16_t nChans,
93 uint16_t nGains,
94 std::string_view author,
95 std::string_view comment,
96 uint64_t timeStamp)
97{
98 //=== blob data length including header in bytes
99 uint32_t dataSizeByte = (m_hdrSize32+objSizeUint32*nObjs) * sizeof(uint32_t);
100
101 //=== calculate comment length, including two ASCII NULLs to end text fields
102 uint32_t commentSizeChar(0);
103 if(author.size() || comment.size() || timeStamp){
104 commentSizeChar += author.size()+comment.size()+sizeof(uint64_t) + 2;
105 //=== force comment length to end on 4 byte boundary
106 commentSizeChar += (commentSizeChar % sizeof(uint32_t)) ?
107 (sizeof(uint32_t)-(commentSizeChar % sizeof(uint32_t))) : 0;
108 }
109
110 //=== create blob
111 uint32_t blobSizeInBytes = dataSizeByte+commentSizeChar;
112 m_blob_nc->resize(blobSizeInBytes);
113 uint32_t* blobStart32 = static_cast<uint32_t*>(m_blob_nc->startingAddress());
114 uint16_t* blobStart16 = static_cast<uint16_t*>(m_blob_nc->startingAddress());
115 m_blobSize32 = m_blob_nc->size()/sizeof(uint32_t);
116
117 m_blobStart32 = blobStart32;
118 m_blobStart16 = blobStart16;
119
120 //=== fill header
121 blobStart16[0] = objType;
122 blobStart16[1] = objVersion;
123 blobStart32[1] = objSizeUint32;
124 blobStart32[2] = nObjs;
125 blobStart16[6] = nChans;
126 blobStart16[7] = nGains;
127 blobStart32[4] = commentSizeChar/sizeof(uint32_t);
129 //==== fill comment fields
130 if(commentSizeChar){
131 if(!timeStamp) timeStamp = ::time(0);
132 uint64_t* pTimeStamp = reinterpret_cast<uint64_t*>(blobStart32+dataSizeByte/sizeof(uint32_t));
133 pTimeStamp[0] = timeStamp;
134 char* pChar = reinterpret_cast<char*>(++pTimeStamp);
135 auto iStr = author.begin();
136 for(; iStr!=author.end(); ++iStr){ *pChar = *iStr; ++pChar; }
137 *pChar = 0;
138 for(iStr=comment.begin(); iStr!=comment.end(); ++iStr){ *(++pChar) = *iStr; }
139 *(++pChar) = 0;
140 }
141
142 return (blobSizeInBytes/sizeof(uint32_t));
143}
144
145//
146//_____________________________________________________________
147std::string
149{
150 if(!getCommentSizeUint32()) return std::string("");
151 const char* iBeg =
152 reinterpret_cast<const char*>(m_blobStart32 + m_hdrSize32 +
154 sizeof(uint64_t)/sizeof(uint32_t));
155 return std::string(iBeg);
156}
157
158
160//_____________________________________________________________
161std::string
163{
164 if(!getCommentSizeUint32()) return std::string("");
165 const char* iBeg =
166 reinterpret_cast<const char*>(m_blobStart32 + m_hdrSize32 +
168 sizeof(uint64_t)/sizeof(uint32_t));
169 const char* iEnd = iBeg + getCommentSizeChar();
170 iBeg = std::find(iBeg,iEnd,0);
171 return std::string(++iBeg);
172}
173
174//
175//_____________________________________________________________
176std::string
178{
179 if(!getCommentSizeUint32()) return std::string("");
180 ::time_t timeStamp = getTimeStamp();
181 char buf[32];
182 char* iBeg = ::ctime_r(&timeStamp, buf);
183 char* iEnd = iBeg;
184 while(*iEnd!='\n'){++iEnd;}
185 return std::string(iBeg,iEnd-iBeg);
186}
187
188//
189//_____________________________________________________________
190std::string
192{
193 if(!getCommentSizeUint32()) return std::string("");
194 return getAuthor()+" ("+getDate()+"): "+getComment();
195}
196
197
198//
199//_____________________________________________________________
200void
201TileCalibDrawerBase::dumpHeader(std::ostream& stm) const
202{
203 stm << "This is a " << TileCalibType::getClassName(getObjType()) << std::endl;
204 stm << "ObjType : " << getObjType() << std::endl;
205 stm << "ObjVersion : " << getObjVersion() << std::endl;
206 stm << "ObjSize [bytes]: " << getObjSizeByte() << std::endl;
207 stm << "NObjs : " << getNObjs() << std::endl;
208 stm << "NChannels : " << getNChans() << std::endl;
209 stm << "NGains : " << getNGains() << std::endl;
211 stm << "=== No comment available ===" << std::endl;
212 }
213 else{
214 stm << "Author : " << getAuthor() << std::endl;
215 stm << "Date : " << getDate() << " ("<< getTimeStamp() << ")" << std::endl;
216 stm << "Comment: : " << getComment() << std::endl;
217 }
218}
219
221 dumpHeader(std::cout);
222}
size_t size() const
Number of registered mappings.
This class provides the core BLOB infrastructure.
uint32_t getCommentSizeUint32() const
Returns the space occupied by the comment fields in units of uint32_t.
uint16_t getNChans() const
Returns the number of channels stored in the BLOB.
TileCalibDrawerBase & operator=(const TileCalibDrawerBase &other)
Assignment operator.
virtual void clone(const TileCalibDrawerBase &other)
Initialzes Blob with content of other Blob.
uint64_t m_blobSize32
Cache blob size in units of uint32_t.
std::string getFullComment() const
Returns a formated string build from all comment fields.
std::string getComment() const
Returns the actual comment.
uint16_t getObjType() const
Returns the BLOB object type.
const uint32_t * m_blobStart32
Cache blob starting address as uint_32t*.
uint16_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).
std::string getDate() const
Returns the date of the comment as string (derived from timestamp).
const coral::Blob * m_blob
Const reference to the BLOB (always there).
void dumpHeader(std::ostream &stm) const
Prints the BLOB header summary information.
virtual ~TileCalibDrawerBase()
Dtor.
TileCalibDrawerBase(const TileCalibDrawerBase &other)
Copy Ctor.
uint32_t getNObjs() const
Returns the number of data objects stored int the BLOB.
const uint16_t * m_blobStart16
Cache blob starting address as uint_16t*.
std::string getAuthor() const
Returns the comment author.
static const unsigned int m_hdrSize32
The header size in units of uint32_t.
bool m_isBlobOwner
Is this TileCalibDrawer owner of the BLOB.
virtual void dump() const
Prints the BLOB header summary information to std::cout.
uint16_t getObjVersion() const
Returns the BLOB object version.
uint32_t getObjSizeByte() const
Returns the size of a data object in units of bytes.
uint32_t createBlob(uint16_t objType, uint16_t objVersion, uint32_t objSizeUint32, uint32_t nObjs, uint16_t nChans, uint16_t nGains, std::string_view author="", std::string_view comment="", uint64_t timeStamp=0)
(re-)creation of the referenced BLOB object.
coral::Blob * m_blob_nc
Non-const reference to the BLOB.
uint32_t getObjSizeUint32() const
Returns the size of a data object in units of uint32_t.
uint32_t getCommentSizeChar() const
Returns the space occupied by the comment fields in units of chars.
static std::string getClassName(TileCalibType::TYPE type)
Returns the class name.