-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathSubTimeFrameFile.h
More file actions
195 lines (154 loc) · 5.73 KB
/
SubTimeFrameFile.h
File metadata and controls
195 lines (154 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// Copyright 2019-2022 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \author Gvozden Nešković, Frankfurt Institute for Advanced Studies and Goethe University Frankfurt
#ifndef ALICEO2_SUBTIMEFRAME_FILE_H_
#define ALICEO2_SUBTIMEFRAME_FILE_H_
#include <chrono>
#include <iomanip>
#include <ostream>
#include <sstream>
#include <vector>
#include <Headers/DataHeader.h>
#include <SubTimeFrameDataModel.h>
namespace o2::DataDistribution
{
////////////////////////////////////////////////////////////////////////////////
/// SubTimeFrameFileMeta
////////////////////////////////////////////////////////////////////////////////
struct SubTimeFrameFileMeta {
static const o2::header::DataDescription sDataDescFileSubTimeFrame;
static const o2::header::DataHeader getDataHeader()
{
auto lHdr = o2::header::DataHeader(
SubTimeFrameFileMeta::sDataDescFileSubTimeFrame,
o2::header::gDataOriginFLP,
0, // subspecification: not used
sizeof(SubTimeFrameFileMeta));
lHdr.payloadSerializationMethod = o2::header::gSerializationMethodNone;
return lHdr;
}
static constexpr std::uint64_t getSizeInFile()
{
return sizeof(o2::header::DataHeader) + sizeof(SubTimeFrameFileMeta);
}
///
/// Version of STF file format
///
const std::uint64_t mStfFileVersion = 1;
///
/// Size of the Stf in file, including this header.
///
std::uint64_t mStfSizeInFile;
///
/// Time when Stf was written (in ms)
///
std::uint64_t mWriteTimeMs;
auto getTimePoint()
{
using namespace std::chrono;
return time_point<system_clock, milliseconds>{ milliseconds{ mWriteTimeMs } };
}
std::string getTimeString()
{
using namespace std::chrono;
std::time_t lTime = system_clock::to_time_t(getTimePoint());
std::stringstream lTimeStream;
lTimeStream << std::put_time(std::localtime(&lTime), "%F %T");
return lTimeStream.str();
}
SubTimeFrameFileMeta(const std::uint64_t pStfSize)
: SubTimeFrameFileMeta()
{
mStfSizeInFile = pStfSize;
}
SubTimeFrameFileMeta()
: mStfSizeInFile{ 0 }
{
using namespace std::chrono;
mWriteTimeMs = time_point_cast<milliseconds>(system_clock::now()).time_since_epoch().count();
}
friend std::ostream& operator<<(std::ostream& pStream, const SubTimeFrameFileMeta& pMeta);
};
std::ostream& operator<<(std::ostream& pStream, const SubTimeFrameFileMeta& pMeta);
////////////////////////////////////////////////////////////////////////////////
/// SubTimeFrameFileDataIndex
////////////////////////////////////////////////////////////////////////////////
struct SubTimeFrameFileDataIndex {
static const o2::header::DataDescription sDataDescFileStfDataIndex;
struct DataIndexElem {
/// Equipment Identifier: unrolled to pack better
o2::header::DataDescription mDataDescription;
o2::header::DataOrigin mDataOrigin;
/// Number of data blocks <data_header, data>
std::uint32_t mDataBlockCnt = 0;
/// subspecification (u64)
o2::header::DataHeader::SubSpecificationType mSubSpecification = 0;
/// Offset of data block (corresponding data header) relative to
std::uint64_t mOffset = 0;
/// Total size of data blocks including headers
std::uint64_t mSize = 0;
DataIndexElem() = delete;
DataIndexElem(const EquipmentIdentifier& pId,
const std::uint32_t pCnt,
const std::uint64_t pOff,
const std::uint64_t pSize)
: mDataDescription(pId.mDataDescription),
mDataOrigin(pId.mDataOrigin),
mDataBlockCnt(pCnt),
mSubSpecification(pId.mSubSpecification),
mOffset(pOff),
mSize(pSize)
{
static_assert(sizeof(DataIndexElem) == 48,
"DataIndexElem changed -> Binary compatibility is lost!");
}
};
SubTimeFrameFileDataIndex() = default;
void clear() noexcept { mDataIndex.clear(); }
bool empty() const noexcept { return mDataIndex.empty(); }
void AddStfElement(const EquipmentIdentifier& pEqDataId,
const std::uint32_t pCnt,
const std::uint64_t pOffset,
const std::uint64_t pSize)
{
mDataIndex.emplace_back(pEqDataId, pCnt, pOffset, pSize);
}
std::uint64_t getSizeInFile() const
{
return sizeof(o2::header::DataHeader) + (sizeof(DataIndexElem) * mDataIndex.size());
}
friend std::ostream& operator<<(std::ostream& pStream, const SubTimeFrameFileDataIndex& pIndex);
private:
const o2::header::DataHeader getDataHeader() const
{
auto lHdr = o2::header::DataHeader(
sDataDescFileStfDataIndex,
o2::header::gDataOriginAny,
0, // subspecification: not used
mDataIndex.size() * sizeof(DataIndexElem));
lHdr.payloadSerializationMethod = o2::header::gSerializationMethodNone;
return lHdr;
}
std::vector<DataIndexElem> mDataIndex;
};
std::ostream& operator<<(std::ostream& pStream, const SubTimeFrameFileDataIndex& pIndex);
////////////////////////////////////////////////////////////////////////////////
/// EosMetadata
////////////////////////////////////////////////////////////////////////////////
struct EosMetadata {
std::string mEosMetaDir;
std::string mLhcPeriod;
std::string mRunNumber;
std::string mFileType;
std::string mDetectorList;
};
} /* o2::DataDistribution */
#endif /* ALICEO2_SUBTIMEFRAME_FILE_H_ */