Project
Loading...
Searching...
No Matches
SubTimeFrameFile.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12// Adapthed with minimal changes from Gvozden Nescovic code to read sTFs files created by DataDistribution
13
14#ifndef _ALICEO2_SUBTIMEFRAME_FILE_RAWDD_H_
15#define _ALICEO2_SUBTIMEFRAME_FILE_RAWDD_H_
16
17#include <chrono>
18#include <iomanip>
19#include <ostream>
20#include <sstream>
21#include <vector>
22
23#include <Headers/DataHeader.h>
26#include "Framework/Logger.h"
27
28namespace o2
29{
30namespace rawdd
31{
32
37
39
41 const o2::header::DataOrigin& pDataOrig,
42 const o2::header::DataHeader::SubSpecificationType& pSubSpec) noexcept
43 : mDataDescription(pDataDesc),
44 mSubSpecification(pSubSpec),
45 mDataOrigin(pDataOrig)
46 {
47 }
48
50 const o2::header::DataHeader::SubSpecificationType& pSubSpec) noexcept
51 : EquipmentIdentifier(pDataId.dataDescription, pDataId.dataOrigin, pSubSpec)
52 {
53 }
54
56 : EquipmentIdentifier(pEid.mDataDescription, pEid.mDataOrigin, pEid.mSubSpecification)
57 {
58 }
59
61 : EquipmentIdentifier(pDh.dataDescription, pDh.dataOrigin, pDh.subSpecification)
62 {
63 }
64
65 operator o2::header::DataIdentifier() const noexcept
66 {
69 lRetId.dataOrigin = mDataOrigin;
70 return lRetId;
71 }
72
73 bool operator<(const EquipmentIdentifier& other) const noexcept
74 {
75 if (mDataDescription < other.mDataDescription) {
76 return true;
77 }
78
79 if (mDataDescription == other.mDataDescription && mDataOrigin < other.mDataOrigin) {
80 return true;
81 }
82
83 if (mDataDescription == other.mDataDescription && mDataOrigin == other.mDataOrigin &&
84 mSubSpecification < other.mSubSpecification) {
85 return true;
86 }
87
88 return false;
89 }
90
91 bool operator==(const EquipmentIdentifier& other) const noexcept
92 {
93 if (mDataDescription == other.mDataDescription &&
94 mSubSpecification == other.mSubSpecification &&
95 mDataOrigin == other.mDataOrigin) {
96 return true;
97 } else {
98 return false;
99 }
100 }
101
102 bool operator!=(const EquipmentIdentifier& other) const noexcept
103 {
104 return !(*this == other);
105 }
106
107 const std::string info() const
108 {
109 return fmt::format("{}/{}/{}",
110 std::string(mDataOrigin.str),
111 std::string(mDataDescription.str),
113 }
114};
115
119
122
124 {
125 auto lHdr = o2::header::DataHeader(
128 0, // TODO: subspecification? FLP ID? EPN ID?
129 sizeof(SubTimeFrameFileMeta));
130
131 lHdr.payloadSerializationMethod = o2::header::gSerializationMethodNone;
132
133 return lHdr;
134 }
135
136 static constexpr std::uint64_t getSizeInFile()
137 {
138 return sizeof(o2::header::DataHeader) + sizeof(SubTimeFrameFileMeta);
139 }
140
144 const std::uint64_t mStfFileVersion = 1;
145
149 std::uint64_t mStfSizeInFile;
150
154 std::uint64_t mWriteTimeMs;
155
156 auto getTimePoint() const
157 {
158 using namespace std::chrono;
159 return time_point<system_clock, milliseconds>{milliseconds{mWriteTimeMs}};
160 }
161
162 std::string getTimeString() const
163 {
164 using namespace std::chrono;
165 std::time_t lTime = system_clock::to_time_t(getTimePoint());
166
167 std::stringstream lTimeStream;
168 lTimeStream << std::put_time(std::localtime(&lTime), "%F %T");
169 return lTimeStream.str();
170 }
171
172 const std::string info() const
173 {
174 return fmt::format("Size in file: {} Time: {} Version: {}", mStfSizeInFile, getTimeString(), mStfFileVersion);
175 }
176
177 SubTimeFrameFileMeta(const std::uint64_t pStfSize)
179 {
180 mStfSizeInFile = pStfSize;
181 }
182
184 : mStfSizeInFile{0}
185 {
186 using namespace std::chrono;
187 mWriteTimeMs = time_point_cast<milliseconds>(system_clock::now()).time_since_epoch().count();
188 }
189
190 friend std::ostream& operator<<(std::ostream& pStream, const SubTimeFrameFileMeta& pMeta);
191};
192
193std::ostream& operator<<(std::ostream& pStream, const SubTimeFrameFileMeta& pMeta);
194
198
201
207 std::uint32_t mDataBlockCnt = 0;
211 std::uint64_t mOffset = 0;
213 std::uint64_t mSize = 0;
214
215 DataIndexElem() = delete;
217 const std::uint32_t pCnt,
218 const std::uint64_t pOff,
219 const std::uint64_t pSize)
222 mDataBlockCnt(pCnt),
224 mOffset(pOff),
225 mSize(pSize)
226 {
227 static_assert(sizeof(DataIndexElem) == 48,
228 "DataIndexElem changed -> Binary compatibility is lost!");
229 }
230
231 const std::string info() const
232 {
234 }
235 };
236
238
239 void clear() noexcept { mDataIndex.clear(); }
240 bool empty() const noexcept { return mDataIndex.empty(); }
241
242 void AddStfElement(const EquipmentIdentifier& pEqDataId,
243 const std::uint32_t pCnt,
244 const std::uint64_t pOffset,
245 const std::uint64_t pSize)
246 {
247 mDataIndex.emplace_back(pEqDataId, pCnt, pOffset, pSize);
248 }
249
250 std::uint64_t getSizeInFile() const
251 {
252 return sizeof(o2::header::DataHeader) + (sizeof(DataIndexElem) * mDataIndex.size());
253 }
254
255 const std::vector<DataIndexElem>& getDataIndex() const { return mDataIndex; }
256
257 friend std::ostream& operator<<(std::ostream& pStream, const SubTimeFrameFileDataIndex& pIndex);
258
259 private:
260 const o2::header::DataHeader getDataHeader() const
261 {
262 auto lHdr = o2::header::DataHeader(
265 0, // TODO: subspecification? FLP ID? EPN ID?
266 mDataIndex.size() * sizeof(DataIndexElem));
267
268 lHdr.payloadSerializationMethod = o2::header::gSerializationMethodNone;
269
270 return lHdr;
271 }
272
273 std::vector<DataIndexElem> mDataIndex;
274};
275
276std::ostream& operator<<(std::ostream& pStream, const SubTimeFrameFileDataIndex& pIndex);
277} // namespace rawdd
278
279} // namespace o2
280
281namespace std
282{
283template <>
284struct hash<o2::header::DataOrigin> {
286 typedef std::uint32_t result_type;
287
288 result_type operator()(argument_type const& a) const noexcept
289 {
290
291 static_assert(sizeof(o2::header::DataOrigin::ItgType) == sizeof(uint32_t) &&
292 sizeof(o2::header::DataOrigin) == 4,
293 "DataOrigin must be 4B long (uint32_t itg[1])");
294 return std::hash<o2::header::DataOrigin::ItgType>{}(a.itg[0]);
295 }
296};
297
298template <>
299struct hash<o2::header::DataDescription> {
301 typedef std::uint64_t result_type;
302
303 result_type operator()(argument_type const& a) const noexcept
304 {
305
306 static_assert(sizeof(o2::header::DataDescription::ItgType) == sizeof(uint64_t) &&
307 sizeof(o2::header::DataDescription) == 16,
308 "DataDescription must be 16B long (uint64_t itg[2])");
309
310 return std::hash<o2::header::DataDescription::ItgType>{}(a.itg[0]) ^
311 std::hash<o2::header::DataDescription::ItgType>{}(a.itg[1]);
312 }
313};
314
315inline void hash_combine(std::size_t& seed) {}
316
317template <typename T, typename... Rest>
318inline void hash_combine(std::size_t& seed, const T& v, Rest... rest)
319{
320 std::hash<T> hasher;
321 seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
322 hash_combine(seed, rest...);
323}
324
325template <>
326struct hash<o2::header::DataHeader> {
328 typedef std::size_t result_type;
329
330 result_type operator()(argument_type const& a) const noexcept
331 {
332 result_type h = (size_t(a.tfCounter) << 32) + a.subSpecification;
333 hash_combine(h, a.dataOrigin, a.dataDescription);
334 return h;
335 }
336};
337
338template <>
339struct hash<o2::header::DataIdentifier> {
341 typedef std::uint64_t result_type;
342
343 result_type operator()(argument_type const& a) const noexcept
344 {
345
346 return std::hash<o2::header::DataDescription>{}(a.dataDescription) ^
347 std::hash<o2::header::DataOrigin>{}(a.dataOrigin);
348 }
349};
350
351template <>
352struct hash<o2::rawdd::EquipmentIdentifier> {
354 typedef std::uint64_t result_type;
355
356 result_type operator()(argument_type const& a) const noexcept
357 {
358
359 return std::hash<o2::header::DataDescription>{}(a.mDataDescription) ^
360 (std::hash<o2::header::DataOrigin>{}(a.mDataOrigin) << 1) ^
361 a.mSubSpecification;
362 }
363};
364
365} //namespace std
366
367#endif /* _ALICEO2_SUBTIMEFRAME_FILE_RAWDD_H_ */
uint32_t hash
unsigned int uint32_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
Class for time synchronization of RawReader instances.
const GLdouble * v
Definition glcorearb.h:832
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
constexpr o2::header::DataOrigin gDataOriginFLP
Definition DataHeader.h:565
constexpr o2::header::DataOrigin gDataOriginAny
Definition DataHeader.h:563
Descriptor< gSizeDataDescriptionString > DataDescription
Definition DataHeader.h:554
std::ostream & operator<<(std::ostream &os, const o2::header::RDHAny &rdh)
Definition RDHManip.cxx:84
constexpr o2::header::SerializationMethod gSerializationMethodNone
Definition DataHeader.h:330
Descriptor< gSizeDataOriginString > DataOrigin
Definition DataHeader.h:553
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
void hash_combine(std::size_t &seed)
static std::string describe(InputSpec const &spec)
the main header struct
Definition DataHeader.h:623
Helper struct to encode origin and description of data.
Definition DataHeader.h:762
DataDescription dataDescription
Definition DataHeader.h:764
typename internal::TraitsIntType< N >::Type ItgType
Definition DataHeader.h:213
o2::header::DataDescription mDataDescription
EquipmentIdentifier(const o2::header::DataHeader &pDh) noexcept
o2::header::DataHeader::SubSpecificationType mSubSpecification
bool operator==(const EquipmentIdentifier &other) const noexcept
bool operator!=(const EquipmentIdentifier &other) const noexcept
EquipmentIdentifier(const o2::header::DataDescription &pDataDesc, const o2::header::DataOrigin &pDataOrig, const o2::header::DataHeader::SubSpecificationType &pSubSpec) noexcept
bool operator<(const EquipmentIdentifier &other) const noexcept
EquipmentIdentifier(const EquipmentIdentifier &pEid) noexcept
o2::header::DataOrigin mDataOrigin
const std::string info() const
EquipmentIdentifier(const o2::header::DataIdentifier &pDataId, const o2::header::DataHeader::SubSpecificationType &pSubSpec) noexcept
o2::header::DataHeader::SubSpecificationType mSubSpecification
subspecification (u64)
DataIndexElem(const EquipmentIdentifier &pId, const std::uint32_t pCnt, const std::uint64_t pOff, const std::uint64_t pSize)
std::uint64_t mSize
Total size of data blocks including headers.
std::uint64_t mOffset
Offset of data block (corresponding data header) relative to.
o2::header::DataDescription mDataDescription
Equipment Identifier: unrolled to pack better.
std::uint32_t mDataBlockCnt
Number of data blocks <data_header, data>
const std::vector< DataIndexElem > & getDataIndex() const
void AddStfElement(const EquipmentIdentifier &pEqDataId, const std::uint32_t pCnt, const std::uint64_t pOffset, const std::uint64_t pSize)
static const o2::header::DataDescription sDataDescFileStfDataIndex
SubTimeFrameFileDataIndex.
friend std::ostream & operator<<(std::ostream &pStream, const SubTimeFrameFileDataIndex &pIndex)
friend std::ostream & operator<<(std::ostream &pStream, const SubTimeFrameFileMeta &pMeta)
static const o2::header::DataHeader getDataHeader()
static constexpr std::uint64_t getSizeInFile()
static const o2::header::DataDescription sDataDescFileSubTimeFrame
SubTimeFrameFileMeta.
SubTimeFrameFileMeta(const std::uint64_t pStfSize)
const std::string info() const
result_type operator()(argument_type const &a) const noexcept
o2::header::DataDescription argument_type
result_type operator()(argument_type const &a) const noexcept
o2::header::DataIdentifier argument_type
result_type operator()(argument_type const &a) const noexcept
result_type operator()(argument_type const &a) const noexcept
result_type operator()(argument_type const &a) const noexcept
o2::rawdd::EquipmentIdentifier argument_type
VectorOfTObjectPtrs other