File indexing completed on 2024-05-31 04:19:41
0001 #ifndef IOPool_Streamer_FRDFileHeader_h
0002 #define IOPool_Streamer_FRDFileHeader_h
0003
0004 #include <array>
0005 #include <cstddef>
0006 #include <cstdint>
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 namespace edm::streamer {
0022 constexpr std::array<unsigned char, 4> FRDFileHeader_id{{0x52, 0x41, 0x57, 0x5f}};
0023 constexpr std::array<unsigned char, 4> FRDFileVersion_1{{0x30, 0x30, 0x30, 0x31}};
0024 constexpr std::array<unsigned char, 4> FRDFileVersion_2{{0x30, 0x30, 0x30, 0x32}};
0025
0026 struct FRDFileHeaderIdentifier {
0027 FRDFileHeaderIdentifier(const std::array<uint8_t, 4>& id, const std::array<uint8_t, 4>& version)
0028 : id_(id), version_(version) {}
0029
0030 std::array<uint8_t, 4> id_;
0031 std::array<uint8_t, 4> version_;
0032 };
0033
0034 struct FRDFileHeaderContent_v1 {
0035 FRDFileHeaderContent_v1(uint16_t eventCount, uint32_t lumiSection, uint64_t fileSize)
0036 : headerSize_(sizeof(FRDFileHeaderContent_v1) + sizeof(FRDFileHeaderIdentifier)),
0037 eventCount_(eventCount),
0038 lumiSection_(lumiSection),
0039 fileSize_(fileSize) {}
0040
0041 uint16_t headerSize_;
0042 uint16_t eventCount_;
0043 uint32_t lumiSection_;
0044 uint64_t fileSize_;
0045 };
0046
0047 struct FRDFileHeader_v1 {
0048 FRDFileHeader_v1(uint16_t eventCount, uint32_t lumiSection, uint64_t fileSize)
0049 : id_(FRDFileHeader_id, FRDFileVersion_1), c_(eventCount, lumiSection, fileSize) {}
0050
0051 FRDFileHeaderIdentifier id_;
0052 FRDFileHeaderContent_v1 c_;
0053 };
0054
0055 struct FRDFileHeaderContent_v2 {
0056 FRDFileHeaderContent_v2(
0057 uint16_t dataType, uint16_t eventCount, uint32_t runNumber, uint32_t lumiSection, uint64_t fileSize)
0058 : headerSize_(sizeof(FRDFileHeaderContent_v2) + sizeof(FRDFileHeaderIdentifier)),
0059 dataType_(dataType),
0060 eventCount_(eventCount),
0061 runNumber_(runNumber),
0062 lumiSection_(lumiSection),
0063 fileSize_(fileSize) {}
0064
0065 uint16_t headerSize_;
0066 uint16_t dataType_;
0067 uint32_t eventCount_;
0068 uint32_t runNumber_;
0069 uint32_t lumiSection_;
0070 uint64_t fileSize_;
0071 };
0072
0073 struct FRDFileHeader_v2 {
0074 FRDFileHeader_v2(uint16_t dataType, uint16_t eventCount, uint32_t runNumber, uint32_t lumiSection, uint64_t fileSize)
0075 : id_(FRDFileHeader_id, FRDFileVersion_2), c_(dataType, eventCount, runNumber, lumiSection, fileSize) {}
0076
0077 FRDFileHeaderIdentifier id_;
0078 FRDFileHeaderContent_v2 c_;
0079 };
0080
0081 inline uint16_t getFRDFileHeaderVersion(const std::array<uint8_t, 4>& id, const std::array<uint8_t, 4>& version) {
0082 size_t i;
0083 for (i = 0; i < 4; i++)
0084 if (id[i] != FRDFileHeader_id[i])
0085 return 0;
0086 uint16_t ret = 0;
0087 for (i = 0; i < 4; i++) {
0088 if (version[i] > '9' || version[i] < '0')
0089 return 0;
0090 ret = ret * 10 + (uint16_t)(version[i] - '0');
0091 }
0092 return ret;
0093 }
0094 }
0095 #endif