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>
24#include "Framework/Logger.h"
25
26namespace o2
27{
28namespace rawdd
29{
30
35
37
39 const o2::header::DataOrigin& pDataOrig,
40 const o2::header::DataHeader::SubSpecificationType& pSubSpec) noexcept
41 : mDataDescription(pDataDesc),
42 mSubSpecification(pSubSpec),
43 mDataOrigin(pDataOrig)
44 {
45 }
46
48 const o2::header::DataHeader::SubSpecificationType& pSubSpec) noexcept
49 : EquipmentIdentifier(pDataId.dataDescription, pDataId.dataOrigin, pSubSpec)
50 {
51 }
52
54 : EquipmentIdentifier(pEid.mDataDescription, pEid.mDataOrigin, pEid.mSubSpecification)
55 {
56 }
57
59 : EquipmentIdentifier(pDh.dataDescription, pDh.dataOrigin, pDh.subSpecification)
60 {
61 }
62
63 operator o2::header::DataIdentifier() const noexcept
64 {
67 lRetId.dataOrigin = mDataOrigin;
68 return lRetId;
69 }
70
71 bool operator<(const EquipmentIdentifier& other) const noexcept
72 {
73 if (mDataDescription < other.mDataDescription) {
74 return true;
75 }
76
77 if (mDataDescription == other.mDataDescription && mDataOrigin < other.mDataOrigin) {
78 return true;
79 }
80
81 if (mDataDescription == other.mDataDescription && mDataOrigin == other.mDataOrigin &&
82 mSubSpecification < other.mSubSpecification) {
83 return true;
84 }
85
86 return false;
87 }
88
89 bool operator==(const EquipmentIdentifier& other) const noexcept
90 {
91 if (mDataDescription == other.mDataDescription &&
92 mSubSpecification == other.mSubSpecification &&
93 mDataOrigin == other.mDataOrigin) {
94 return true;
95 } else {
96 return false;
97 }
98 }
99
100 bool operator!=(const EquipmentIdentifier& other) const noexcept
101 {
102 return !(*this == other);
103 }
104
105 const std::string info() const
106 {
107 return fmt::format("{}/{}/{}",
108 std::string(mDataOrigin.str),
109 std::string(mDataDescription.str),
111 }
112};
113
117
120
122 {
123 auto lHdr = o2::header::DataHeader(
126 0, // TODO: subspecification? FLP ID? EPN ID?
127 sizeof(SubTimeFrameFileMeta));
128
129 lHdr.payloadSerializationMethod = o2::header::gSerializationMethodNone;
130
131 return lHdr;
132 }
133
134 static constexpr std::uint64_t getSizeInFile()
135 {
136 return sizeof(o2::header::DataHeader) + sizeof(SubTimeFrameFileMeta);
137 }
138
142 const std::uint64_t mStfFileVersion = 1;
143
147 std::uint64_t mStfSizeInFile;
148
152 std::uint64_t mWriteTimeMs;
153
155 {
156 using namespace std::chrono;
157 return time_point<system_clock, milliseconds>{milliseconds{mWriteTimeMs}};
158 }
159
160 std::string getTimeString()
161 {
162 using namespace std::chrono;
163 std::time_t lTime = system_clock::to_time_t(getTimePoint());
164
165 std::stringstream lTimeStream;
166 lTimeStream << std::put_time(std::localtime(&lTime), "%F %T");
167 return lTimeStream.str();
168 }
169
170 SubTimeFrameFileMeta(const std::uint64_t pStfSize)
172 {
173 mStfSizeInFile = pStfSize;
174 }
175
177 : mStfSizeInFile{0}
178 {
179 using namespace std::chrono;
180 mWriteTimeMs = time_point_cast<milliseconds>(system_clock::now()).time_since_epoch().count();
181 }
182
183 friend std::ostream& operator<<(std::ostream& pStream, const SubTimeFrameFileMeta& pMeta);
184};
185
186std::ostream& operator<<(std::ostream& pStream, const SubTimeFrameFileMeta& pMeta);
187
191
194
200 std::uint32_t mDataBlockCnt = 0;
204 std::uint64_t mOffset = 0;
206 std::uint64_t mSize = 0;
207
208 DataIndexElem() = delete;
210 const std::uint32_t pCnt,
211 const std::uint64_t pOff,
212 const std::uint64_t pSize)
215 mDataBlockCnt(pCnt),
217 mOffset(pOff),
218 mSize(pSize)
219 {
220 static_assert(sizeof(DataIndexElem) == 48,
221 "DataIndexElem changed -> Binary compatibility is lost!");
222 }
223 };
224
226
227 void clear() noexcept { mDataIndex.clear(); }
228 bool empty() const noexcept { return mDataIndex.empty(); }
229
230 void AddStfElement(const EquipmentIdentifier& pEqDataId,
231 const std::uint32_t pCnt,
232 const std::uint64_t pOffset,
233 const std::uint64_t pSize)
234 {
235 mDataIndex.emplace_back(pEqDataId, pCnt, pOffset, pSize);
236 }
237
238 std::uint64_t getSizeInFile() const
239 {
240 return sizeof(o2::header::DataHeader) + (sizeof(DataIndexElem) * mDataIndex.size());
241 }
242
243 friend std::ostream& operator<<(std::ostream& pStream, const SubTimeFrameFileDataIndex& pIndex);
244
245 private:
246 const o2::header::DataHeader getDataHeader() const
247 {
248 auto lHdr = o2::header::DataHeader(
251 0, // TODO: subspecification? FLP ID? EPN ID?
252 mDataIndex.size() * sizeof(DataIndexElem));
253
254 lHdr.payloadSerializationMethod = o2::header::gSerializationMethodNone;
255
256 return lHdr;
257 }
258
259 std::vector<DataIndexElem> mDataIndex;
260};
261
262std::ostream& operator<<(std::ostream& pStream, const SubTimeFrameFileDataIndex& pIndex);
263} // namespace rawdd
264
265} // namespace o2
266
267namespace std
268{
269template <>
270struct hash<o2::header::DataOrigin> {
272 typedef std::uint32_t result_type;
273
274 result_type operator()(argument_type const& a) const noexcept
275 {
276
277 static_assert(sizeof(o2::header::DataOrigin::ItgType) == sizeof(uint32_t) &&
278 sizeof(o2::header::DataOrigin) == 4,
279 "DataOrigin must be 4B long (uint32_t itg[1])");
280 return std::hash<o2::header::DataOrigin::ItgType>{}(a.itg[0]);
281 }
282};
283
284template <>
285struct hash<o2::header::DataDescription> {
287 typedef std::uint64_t result_type;
288
289 result_type operator()(argument_type const& a) const noexcept
290 {
291
292 static_assert(sizeof(o2::header::DataDescription::ItgType) == sizeof(uint64_t) &&
293 sizeof(o2::header::DataDescription) == 16,
294 "DataDescription must be 16B long (uint64_t itg[2])");
295
296 return std::hash<o2::header::DataDescription::ItgType>{}(a.itg[0]) ^
297 std::hash<o2::header::DataDescription::ItgType>{}(a.itg[1]);
298 }
299};
300
301inline void hash_combine(std::size_t& seed) {}
302
303template <typename T, typename... Rest>
304inline void hash_combine(std::size_t& seed, const T& v, Rest... rest)
305{
306 std::hash<T> hasher;
307 seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
308 hash_combine(seed, rest...);
309}
310
311template <>
312struct hash<o2::header::DataHeader> {
314 typedef std::size_t result_type;
315
316 result_type operator()(argument_type const& a) const noexcept
317 {
318 result_type h = (size_t(a.tfCounter) << 32) + a.subSpecification;
319 hash_combine(h, a.dataOrigin, a.dataDescription);
320 return h;
321 }
322};
323
324template <>
325struct hash<o2::header::DataIdentifier> {
327 typedef std::uint64_t result_type;
328
329 result_type operator()(argument_type const& a) const noexcept
330 {
331
332 return std::hash<o2::header::DataDescription>{}(a.dataDescription) ^
333 std::hash<o2::header::DataOrigin>{}(a.dataOrigin);
334 }
335};
336
337template <>
338struct hash<o2::rawdd::EquipmentIdentifier> {
340 typedef std::uint64_t result_type;
341
342 result_type operator()(argument_type const& a) const noexcept
343 {
344
345 return std::hash<o2::header::DataDescription>{}(a.mDataDescription) ^
346 (std::hash<o2::header::DataOrigin>{}(a.mDataOrigin) << 1) ^
347 a.mSubSpecification;
348 }
349};
350
351} //namespace std
352
353#endif /* _ALICEO2_SUBTIMEFRAME_FILE_RAWDD_H_ */
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:562
constexpr o2::header::DataOrigin gDataOriginAny
Definition DataHeader.h:560
Descriptor< gSizeDataDescriptionString > DataDescription
Definition DataHeader.h:551
std::ostream & operator<<(std::ostream &os, const o2::header::RDHAny &rdh)
Definition RDHManip.cxx:84
constexpr o2::header::SerializationMethod gSerializationMethodNone
Definition DataHeader.h:327
Descriptor< gSizeDataOriginString > DataOrigin
Definition DataHeader.h:550
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
void hash_combine(std::size_t &seed)
the main header struct
Definition DataHeader.h:618
uint32_t SubSpecificationType
Definition DataHeader.h:620
Helper struct to encode origin and description of data.
Definition DataHeader.h:757
DataDescription dataDescription
Definition DataHeader.h:759
typename internal::TraitsIntType< N >::Type ItgType
Definition DataHeader.h:214
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>
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)
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