Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-12 03:09:27

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  * FRD File Header optionally found at the beginning of the FRD RAW file
0010  *
0011  * Version 1 Format:
0012  *   uint8_t [4] - id contanining 4 characters: 0x52, 0x41, 0x57, 0x5f  "RAW_"
0013  *   uint8_t [4] - version string 4 characters: 0x30, 0x30, 0x30, 0x31  "0001"
0014  *   uint16_t - header size: 24
0015  *   uint16_t - number of events in the RAW file
0016  *   uint32_t - lumisection
0017  *   uint64_t - total size of the raw file (including header)
0018  *
0019  * */
0020 
0021 constexpr std::array<unsigned char, 4> FRDFileHeader_id{{0x52, 0x41, 0x57, 0x5f}};
0022 constexpr std::array<unsigned char, 4> FRDFileVersion_1{{0x30, 0x30, 0x30, 0x31}};
0023 
0024 struct FRDFileHeader_v1 {
0025   FRDFileHeader_v1() = default;
0026 
0027   FRDFileHeader_v1(uint16_t eventCount, uint32_t lumiSection, uint64_t fileSize)
0028       : id_{FRDFileHeader_id},
0029         version_{FRDFileVersion_1},
0030         headerSize_(sizeof(FRDFileHeader_v1)),
0031         eventCount_(eventCount),
0032         lumiSection_(lumiSection),
0033         fileSize_(fileSize) {}
0034 
0035   std::array<uint8_t, 4> id_;
0036   std::array<uint8_t, 4> version_;
0037   uint16_t headerSize_;
0038   uint16_t eventCount_;
0039   uint32_t lumiSection_;
0040   uint64_t fileSize_;
0041 };
0042 
0043 inline uint16_t getFRDFileHeaderVersion(const std::array<uint8_t, 4>& id, const std::array<uint8_t, 4>& version) {
0044   size_t i;
0045   for (i = 0; i < 4; i++)
0046     if (id[i] != FRDFileHeader_id[i])
0047       return 0;  //not FRD file header
0048   uint16_t ret = 0;
0049   for (i = 0; i < 4; i++) {
0050     if (version[i] > '9' || version[i] < '0')
0051       return 0;  //NaN sequence
0052     ret = ret * 10 + (uint16_t)(version[i] - '0');
0053   }
0054   return ret;
0055 }
0056 
0057 #endif