ATLAS Offline Software
CaloCondBlobBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include <algorithm>
8 #include <ctime>
9 
10 //
11 //_____________________________________________________________
13  const coral::Blob* blob)
14  : m_blob_nc(blob_nc),
15  m_blob(blob)
16  , m_isBlobOwner(false),m_sizeOfObj(0),m_nChans(0),m_nGains(0)
17 {
18  if(uint64_t(m_blob->size())>=getHdrSize()*sizeof(uint32_t)) {
19  m_sizeOfObj=static_cast<const uint32_t*>(m_blob->startingAddress())[1];
20  //m_nChans=static_cast<uint16_t*>(m_blob->startingAddress())[6];
21  //m_nGains=static_cast<uint16_t*>(m_blob->startingAddress())[7];
22  const CaloCondBlobBase& this_c = *this;
23  m_nChans=unpacknChans(this_c.getBlobStart()[3]);
24  m_nGains=unpacknGains(this_c.getBlobStart()[3]);
25  m_pDataStart=static_cast<const void*>(this_c.getBlobStart()+getHdrSize());
26  //std::cout << "CaloCondBlobObj: nChans=" << m_nChans << " nGains=" << m_nGains << std::endl;
27  }
28  }
29 
31  : CaloCondBlobBase (nullptr, &blob)
32 {
33 }
34 
37 {
38 }
39 
40 //
41 //_____________________________________________________________
43 {
44  //=== delete the coral::Blob if owner
45  if(m_isBlobOwner) {delete m_blob;}
46 }
47 
48 //
49 //_____________________________________________________________
51  : m_blob_nc(new coral::Blob(*other.m_blob))
52  , m_blob (m_blob_nc)
53  , m_isBlobOwner(true),
54  m_sizeOfObj(other.getObjSizeUint32()),
55  m_nChans(other.getNChans()),
56  m_nGains(other.getNChans()),
57  m_pDataStart(static_cast<const void*>(getBlobStart()+getHdrSize()))
58 {
59 }
60 
61 //
62 //_____________________________________________________________
65 {
66  //=== catch self-assignment
67  if(&other == this) {return *this;}
68  if (m_isBlobOwner) delete m_blob;
69  m_blob = other.m_blob;
70  m_blob_nc = other.m_blob_nc;
71  m_isBlobOwner = false;
72  m_sizeOfObj=static_cast<const uint32_t*>(m_blob->startingAddress())[1];
75  m_pDataStart=static_cast<const void*>(getBlobStart()+getHdrSize());
76  return *this;
77 }
78 
79 
80 //
81 //_____________________________________________________________
85  uint32_t objSizeUint32,
87  uint32_t nChans,
88  uint16_t nGains,
89  const std::string& author,
90  const std::string& comment,
92 {
93 
94  //=== blob data length including header in bytes
95  const uint32_t dataSizeByte = (getHdrSize()+objSizeUint32*nObjs) * sizeof(uint32_t);
96 
97  //=== calculate comment length, including two ASCII NULLs to end text fields
98  uint32_t commentSizeChar(0);
99  if(!author.empty() || !comment.empty() || timeStamp){
100  commentSizeChar += author.size()+comment.size()+sizeof(uint64_t) + 2;
101  //=== force comment length to end on 4 byte boundary
102  commentSizeChar += (commentSizeChar % sizeof(uint32_t)) ?
103  (sizeof(uint32_t)-(commentSizeChar % sizeof(uint32_t))) : 0;
104  }
105 
106  //=== create blob
107  const uint32_t blobSizeInBytes = dataSizeByte+commentSizeChar;
108  m_blob_nc->resize(blobSizeInBytes);
109 
110  //=== fill header
111  reinterpret_cast<uint16_t*>(getBlobStart())[0] = objType;
112  reinterpret_cast<uint16_t*>(getBlobStart())[1] = objVersion;
113  getBlobStart()[1] = objSizeUint32;
114  m_sizeOfObj=objSizeUint32;
115  getBlobStart()[2] = nObjs;
116  getBlobStart()[3] = packGainAndNchans(nGains,nChans);
117  m_nChans=nChans;
118  m_nGains=nGains;
119  getBlobStart()[4] = commentSizeChar/sizeof(uint32_t);
120 
121  //==== fill comment fields
122  if(commentSizeChar){
123  if(!timeStamp) timeStamp = ::time(nullptr);
124  uint64_t* pTimeStamp = reinterpret_cast<uint64_t*>(getBlobStart()+dataSizeByte/sizeof(uint32_t));
125  pTimeStamp[0] = timeStamp;
126  char* pChar = reinterpret_cast<char*>(++pTimeStamp);
127  std::string::const_iterator iStr = author.begin();
128  for(; iStr!=author.end(); ++iStr){ *pChar = *iStr; ++pChar; }
129  *pChar = 0;
130  for(iStr=comment.begin(); iStr!=comment.end(); ++iStr){ *(++pChar) = *iStr; }
131  *(++pChar) = 0;
132  }
133 
134  m_pDataStart=static_cast<const void*>(getBlobStart()+getHdrSize());
135  return (blobSizeInBytes/sizeof(uint32_t));
136 }
137 
138 
140 
141  if (gain>0x7F)
142  throw CaloCond::InvalidBlob("CaloCondBlobBase::packGainAndNchans: Gain too large");
143 
144  if (nChans>0xFFFFFF)
145  throw CaloCond::InvalidBlob("CaloCondBlobBase::packGainAndNchans: Number of channels too large");
146 
147  return 0x80000000 | (gain << 24) | nChans;
148 }
149 
151  if (gainAndnChans & 0x80000000) { //new version: 24 bytes for the nChans, 7 for the gain
152  //std::cout << "CaloCondBlobBase: Reading gain from new version" << std::endl;
153  return (gainAndnChans>>24) & 0x7F;
154  }
155  else //Old version: 16 bigs for gain
156  //std::cout << "CaloCondBlobBase: Reading gain from old version" << std::endl;
157  return (gainAndnChans>>16) & 0xFFFF;
158 }
159 
161  if (gainAndnChans & 0x80000000) { //new version: 24 bytes for the nChans, 7 for the gain
162  //std::cout << "CaloCondBlobBase: Reading nChans from new version" << std::endl;
163  return gainAndnChans & 0xFFFFFF;
164  }
165  else //Old version: 16 bits for nChans
166  //std::cout << "CaloCondBlobBase: Reading nChangs from old version" << std::endl;
167  return gainAndnChans & 0xFFFF;
168 }
169 
170 
171 
172 
173 //
174 //_____________________________________________________________
175 std::string
177 {
178  if(!getCommentSizeUint32()) return std::string("");
179  const char* iBeg =
180  reinterpret_cast<const char*>(getBlobStart()+getHdrSize() +
182  sizeof(uint64_t)/sizeof(uint32_t));
183  return std::string(iBeg);
184 }
185 
186 
187 //
188 //_____________________________________________________________
189 std::string
191 {
192  if(!getCommentSizeUint32()) return std::string("");
193  const char* iBeg =
194  reinterpret_cast<const char*>(getBlobStart()+getHdrSize() +
196  sizeof(uint64_t)/sizeof(uint32_t));
197  const char* iEnd = iBeg + getCommentSizeChar();
198  iBeg = std::find(iBeg,iEnd,0);
199  return std::string(++iBeg);
200 }
201 
202 //
203 //_____________________________________________________________
204 std::string
206 {
207  if(!getCommentSizeUint32()) return std::string("");
208  ::time_t timeStamp = getTimeStamp();
209  char buf[26];
210  char* iBeg = ::ctime_r(&timeStamp, buf);
211  char* iEnd = iBeg;
212  while(*iEnd!='\n'){++iEnd;}
213  return std::string(iBeg,iEnd-iBeg);
214 }
215 
216 //
217 //_____________________________________________________________
218 std::string
220 {
221  if(!getCommentSizeUint32()) return std::string("");
222  return getAuthor()+" ("+getDate()+"): "+getComment();
223 }
224 
225 
226 //
227 //_____________________________________________________________
228 void
229 CaloCondBlobBase::dumpHeader(std::ostream& stm) const
230 {
231  stm << "This is a " << CaloCondType::getClassName(getObjType()) << std::endl;
232  stm << "ObjType : " << getObjType() << std::endl;
233  stm << "ObjVersion : " << getObjVersion() << std::endl;
234  stm << "ObjSize [bytes]: " << getObjSizeByte() << std::endl;
235  stm << "NObjs : " << getNObjs() << std::endl;
236  stm << "NChannels : " << getNChans() << std::endl;
237  stm << "NGains : " << getNGains() << std::endl;
238  if(!getCommentSizeUint32()){
239  stm << "=== No comment available ===" << std::endl;
240  }
241  else{
242  stm << "Author : " << getAuthor() << std::endl;
243  stm << "Date : " << getDate() << " ("<< getTimeStamp() << ")" << std::endl;
244  stm << "Comment: : " << getComment() << std::endl;
245  }
246 }
CaloCondBlobBase::getCommentSizeUint32
uint32_t getCommentSizeUint32() const
Returns the space occupied by the comment fields in units of uint32_t.
Definition: CaloCondBlobBase.h:249
checkFileSG.nObjs
nObjs
Definition: checkFileSG.py:90
CaloCondBlobBase::m_isBlobOwner
bool m_isBlobOwner
Do I own the BLOB?
Definition: CaloCondBlobBase.h:163
CaloCondBlobBase::packGainAndNchans
static uint32_t packGainAndNchans(const uint32_t gain, const uint32_t nChans)
Definition: CaloCondBlobBase.cxx:139
CaloCondBlobBase::getObjSizeUint32
uint32_t getObjSizeUint32() const
Returns the size of a data object in units of uint32_t.
Definition: CaloCondBlobBase.h:213
CaloCondBlobBase::getAuthor
std::string getAuthor() const
Returns the comment author.
Definition: CaloCondBlobBase.cxx:176
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
CaloCondBlobBase::m_nGains
unsigned m_nGains
Definition: CaloCondBlobBase.h:168
CaloCondBlobBase::m_blob_nc
coral::Blob * m_blob_nc
Non-const reference to the BLOB.
Definition: CaloCondBlobBase.h:157
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
CaloCondBlobBase::m_pDataStart
const void * m_pDataStart
Definition: CaloCondBlobBase.h:170
CaloCondBlobBase::createBlob
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.
Definition: CaloCondBlobBase.cxx:83
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:562
CaloCondBlobBase::getObjType
uint16_t getObjType() const
Returns the BLOB object type.
Definition: CaloCondBlobBase.h:193
CaloCondBlobBase::getDate
std::string getDate() const
Returns the date of the comment as string (derived from timestamp)
Definition: CaloCondBlobBase.cxx:205
TileCalibBlobPython_writeOfc.objVersion
objVersion
Definition: TileCalibBlobPython_writeOfc.py:71
CaloCondBlobBase::operator=
CaloCondBlobBase & operator=(const CaloCondBlobBase &other)
Assignment operator.
Definition: CaloCondBlobBase.cxx:64
CaloCondBlobBase.h
CaloCondBlobBase::CaloCondBlobBase
CaloCondBlobBase(const CaloCondBlobBase &other)
Copy Ctor.
Definition: CaloCondBlobBase.cxx:50
CaloCondBlobBase::getHdrSize
unsigned int getHdrSize() const
Returns the size of the header in units of uint32_t.
Definition: CaloCondBlobBase.h:85
CaloCondBlobBase::getCommentSizeChar
uint32_t getCommentSizeChar() const
Returns the space occupied by the comment fields in units of chars.
Definition: CaloCondBlobBase.h:83
coral
Definition: ISecondaryEventSelector.h:19
CaloCondBlobBase::getBlobStart
const uint32_t * getBlobStart() const
Returns the BLOB start address as uint32_t pointer.
Definition: CaloCondBlobBase.h:177
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
CaloCondBlobBase::getObjVersion
uint16_t getObjVersion() const
Returns the BLOB object version.
Definition: CaloCondBlobBase.h:203
CaloCondBlobBase::getComment
std::string getComment() const
Returns the actual comment.
Definition: CaloCondBlobBase.cxx:190
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
CaloCondBlobBase::m_nChans
unsigned m_nChans
Definition: CaloCondBlobBase.h:167
CaloCondBlobBase::dumpHeader
void dumpHeader(std::ostream &stm) const
Prints the BLOB header summary information.
Definition: CaloCondBlobBase.cxx:229
CaloCondType.h
CaloCondBlobBase::unpacknChans
static uint32_t unpacknChans(const uint32_t gainAndnChans)
Definition: CaloCondBlobBase.cxx:160
CaloCond::InvalidBlob
Thrown if coral::Blob does not conform with expected structure.
Definition: Calorimeter/CaloCondBlobObjs/CaloCondBlobObjs/Exception.h:50
CaloCondBlobAlgs_fillNoiseFromASCII.comment
string comment
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:27
CaloCondType::getClassName
static std::string getClassName(CaloCondType::TYPE type)
Returns the class name.
Definition: CaloCondType.cxx:10
CaloCondBlobBase::getNObjs
uint32_t getNObjs() const
Returns the number of data objects stored int the BLOB.
Definition: CaloCondBlobBase.h:221
CaloCondBlobBase::getNGains
uint32_t getNGains() const
Returns the number of gains stored for each channel.
Definition: CaloCondBlobBase.h:239
xAOD::timeStamp
setEventNumber timeStamp
Definition: EventInfo_v1.cxx:128
CaloCondBlobBase::m_blob
const coral::Blob * m_blob
Const reference to the BLOB (always there)
Definition: CaloCondBlobBase.h:160
CaloCondBlobBase::getFullComment
std::string getFullComment() const
Returns a formated string build from all comment fields.
Definition: CaloCondBlobBase.cxx:219
CaloCondBlobBase::getObjSizeByte
uint32_t getObjSizeByte() const
Returns the size of a data object in units of bytes.
Definition: CaloCondBlobBase.h:73
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
CaloCondBlobBase
This class provides the core BLOB infrastructure.
Definition: CaloCondBlobBase.h:42
CaloCondBlobBase::m_sizeOfObj
unsigned m_sizeOfObj
Chache of some frequently-used numbers.
Definition: CaloCondBlobBase.h:166
CaloCondBlobAlgs_fillNoiseFromASCII.author
string author
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:26
CaloCondBlobBase::~CaloCondBlobBase
virtual ~CaloCondBlobBase()
Dtor.
Definition: CaloCondBlobBase.cxx:42
CaloCondBlobBase::getTimeStamp
uint64_t getTimeStamp() const
Returns the unix timestamp of the comment (seconds since 1.1.1970)
Definition: CaloCondBlobBase.h:283
CaloCondBlobBase::unpacknGains
static uint32_t unpacknGains(const uint32_t gainAndnChans)
Definition: CaloCondBlobBase.cxx:150
CaloCondBlobAlgs_fillNoiseFromASCII.blob
blob
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:96
CaloCondBlobBase::getNChans
uint32_t getNChans() const
Returns the number of channels stored in the BLOB.
Definition: CaloCondBlobBase.h:231