Back to home page

Project CMSSW displayed by LXR

 
 

    


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  * 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 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;  //not FRD file header
0086     uint16_t ret = 0;
0087     for (i = 0; i < 4; i++) {
0088       if (version[i] > '9' || version[i] < '0')
0089         return 0;  //NaN sequence
0090       ret = ret * 10 + (uint16_t)(version[i] - '0');
0091     }
0092     return ret;
0093   }
0094 }  // namespace edm::streamer
0095 #endif