HepMC3 event record library: CompressedIO.h Source File

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{
33 using ofstream = bxz::ofstream; //!< ofstream
34 using ostream = bxz::ostream; //!< ostream
35 using ifstream = bxz::ifstream; //!< ifstream
36 using istream = bxz::istream; //!< istream
37
38 using Compression = bxz::Compression; //!< Compression types from bxzstr
39/** @brief Function to detect compression type */
40 inline 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 */
44 constexpr int num_supported_compression_types = 0
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 */
59 constexpr 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 */
74 constexpr 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 */
82 inline 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
HepMC3 main namespace.
Definition AnalysisExample.h:24
HepMC3::to_string
std::string to_string(HepMC3::Compression &c)
Convert from the compression type to string.
Definition CompressedIO.h:82
HepMC3::Compression
bxz::Compression Compression
Compression types from bxzstr.
Definition CompressedIO.h:38
HepMC3::known_compression_types
constexpr std::array< Compression, 4 > known_compression_types
Array of known compression types.
Definition CompressedIO.h:74
HepMC3::num_supported_compression_types
constexpr int num_supported_compression_types
Number of supported compression types.
Definition CompressedIO.h:44
HepMC3::supported_compression_types
constexpr std::array< Compression, num_supported_compression_types > supported_compression_types
Array of supported compression types.
Definition CompressedIO.h:59
HepMC3::detect_compression_type
Compression detect_compression_type(const char *in_buff_start, const char *in_buff_end)
Function to detect compression type.
Definition CompressedIO.h:40