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