HepMC3 event record library
CompressedIO.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6/**
7 * @file CompressedIO.h
8 * @brief HepMC3 interface to bxzstr library and some routines
9 *
10 */
11#ifndef HEPMC3_COMPRESSEDIO_H
12#define HEPMC3_COMPRESSEDIO_H
13#if HEPMC3_USE_COMPRESSION
14#if HEPMC3_Z_SUPPORT
15#define BXZSTR_Z_SUPPORT 1
16#endif
17#if HEPMC3_LZMA_SUPPORT
18#define BXZSTR_LZMA_SUPPORT 1
19#endif
20#if HEPMC3_BZ2_SUPPORT
21#define BXZSTR_BZ2_SUPPORT 1
22#endif
23#if HEPMC3_ZSTD_SUPPORT
24#define BXZSTR_ZSTD_SUPPORT 1
25#endif
26#endif
27#include "HepMC3/bxzstr/bxzstr.hpp"
28
29#include <array>
30
31namespace HepMC3
32{
33using ofstream = bxz::ofstream; //!< ofstream
34using ostream = bxz::ostream; //!< ostream
35using ifstream = bxz::ifstream; //!< ifstream
36using istream = bxz::istream; //!< istream
37
38using Compression = bxz::Compression; //!< Compression types from bxzstr
39/** @brief Function to detect compression type */
40inline Compression detect_compression_type(const char* in_buff_start, const char* in_buff_end) {
41 return bxz::detect_type(in_buff_start,in_buff_end);
42}
43/** @brief Number of supported compression types */
45#if HEPMC3_Z_SUPPORT
46 +1
47#endif
48#if HEPMC3_LZMA_SUPPORT
49 +1
50#endif
51#if HEPMC3_BZ2_SUPPORT
52 +1
53#endif
54#if HEPMC3_ZSTD_SUPPORT
55 +1
56#endif
57 ;
58/** @brief Array of supported compression types */
59constexpr std::array<Compression,num_supported_compression_types> supported_compression_types{
60#if HEPMC3_Z_SUPPORT
61 Compression::z,
62#endif
63#if HEPMC3_LZMA_SUPPORT
64 Compression::lzma,
65#endif
66#if HEPMC3_BZ2_SUPPORT
67 Compression::bz2,
68#endif
69#if HEPMC3_ZSTD_SUPPORT
70 Compression::zstd,
71#endif
72};
73/** @brief Array of known compression types */
74constexpr std::array<Compression, 4> known_compression_types{
75 Compression::z,
76 Compression::lzma,
77 Compression::bz2,
78 Compression::zstd,
79};
80
81/** @brief Convert from the compression type to string */
82inline std::string to_string(HepMC3::Compression & c) {
83 switch (c) {
84 case HepMC3::Compression::z:
85 return std::string("z");
86 case HepMC3::Compression::lzma:
87 return std::string("lzma");
88 case HepMC3::Compression::bz2:
89 return std::string("bz2");
90 case HepMC3::Compression::zstd:
91 return std::string("zstd");
92 default:
93 break;
94 }
95 return std::string("plaintext");
96}
97
98}
99
100inline std::ostream& operator<<(std::ostream& os, HepMC3::Compression & c) {
101 return os << HepMC3::to_string(c);
102}
103
104
105#endif
HepMC3 main namespace.
std::string to_string(HepMC3::Compression &c)
Convert from the compression type to string.
bxz::Compression Compression
Compression types from bxzstr.
constexpr std::array< Compression, 4 > known_compression_types
Array of known compression types.
constexpr int num_supported_compression_types
Number of supported compression types.
constexpr std::array< Compression, num_supported_compression_types > supported_compression_types
Array of supported compression types.
Compression detect_compression_type(const char *in_buff_start, const char *in_buff_end)
Function to detect compression type.