Project
Loading...
Searching...
No Matches
CompStream.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
18#include <boost/iostreams/device/file.hpp>
19#include <boost/iostreams/stream.hpp>
20#include <boost/iostreams/copy.hpp>
21#include <boost/iostreams/filter/gzip.hpp>
22#include <boost/iostreams/filter/zlib.hpp>
23#include <boost/iostreams/filter/bzip2.hpp>
24//#include <boost/iostreams/filter/lzma.hpp>
25#include <map>
26#include <stdexcept>
27
28namespace o2
29{
30namespace io
31{
32
33namespace comp_stream_helpers
34{
35template <typename T>
37{
38 switch (method) {
40 stream.push(boost::iostreams::gzip_decompressor());
41 break;
43 stream.push(boost::iostreams::zlib_decompressor());
44 break;
46 throw std::runtime_error("lzma support not enabled");
47 //stream.push(boost::iostreams::lzma_decompressor());
48 break;
50 stream.push(boost::iostreams::bzip2_decompressor());
51 break;
53 break;
54 default:
55 throw std::invalid_argument("missing implementation");
56 }
57}
58
59template <typename T>
61{
62 switch (method) {
64 stream.push(boost::iostreams::gzip_compressor());
65 break;
67 stream.push(boost::iostreams::zlib_compressor());
68 break;
70 throw std::runtime_error("lzma support not enabled");
71 //stream.push(boost::iostreams::lzma_compressor());
72 break;
74 stream.push(boost::iostreams::bzip2_compressor());
75 break;
77 break;
78 default:
79 throw std::invalid_argument("missing implementation");
80 }
81}
82
83const std::map<std::string, CompressionMethod> Mapping = {
87 {"bzip2", CompressionMethod::Bzip2},
89};
90
91auto Method(std::string method)
92{
93 auto const& i = Mapping.find(method);
94 if (i == Mapping.end()) {
95 throw std::invalid_argument("invalid compression method: " + method);
96 }
97 return i->second;
98}
99} // namespace comp_stream_helpers
100
102 : mStreamBuffer(), mInputFile(filename, std::ios_base::in | std::ios_base::binary), std::istream(&mStreamBuffer)
103{
104 comp_stream_helpers::pushDecompressor(mStreamBuffer, method);
105 mStreamBuffer.push(mInputFile);
106}
107
108icomp_stream::icomp_stream(std::istream& backend, CompressionMethod method)
109 : mStreamBuffer(), mInputFile(), std::istream(&mStreamBuffer)
110{
111 comp_stream_helpers::pushDecompressor(mStreamBuffer, method);
112 mStreamBuffer.push(backend);
113}
114
115icomp_stream::icomp_stream(std::string filename, std::string method)
116 : mStreamBuffer(), mInputFile(filename, std::ios_base::in | std::ios_base::binary), std::istream(&mStreamBuffer)
117{
119 mStreamBuffer.push(mInputFile);
120}
121
122icomp_stream::icomp_stream(std::istream& backend, std::string method)
123 : mStreamBuffer(), mInputFile(), std::istream(&mStreamBuffer)
124{
126 mStreamBuffer.push(backend);
127}
128
130 : mStreamBuffer(), std::ostream(&mStreamBuffer)
131{
132 comp_stream_helpers::pushCompressor(mStreamBuffer, method);
133 mStreamBuffer.push(boost::iostreams::file_sink(filename));
134}
135
136ocomp_stream::ocomp_stream(std::ostream& backend, CompressionMethod method)
137 : mStreamBuffer(), std::ostream(&mStreamBuffer)
138{
139 comp_stream_helpers::pushCompressor(mStreamBuffer, method);
140 mStreamBuffer.push(backend);
141}
142
143ocomp_stream::ocomp_stream(std::string filename, std::string method)
144 : mStreamBuffer(), std::ostream(&mStreamBuffer)
145{
147 mStreamBuffer.push(boost::iostreams::file_sink(filename));
148}
149
150ocomp_stream::ocomp_stream(std::ostream& backend, std::string method)
151 : mStreamBuffer(), std::ostream(&mStreamBuffer)
152{
154 mStreamBuffer.push(backend);
155}
156} // namespace io
157} // namespace o2
Implementation of iostreams with compression filter.
int32_t i
Checks validity of hardware address (HW) and transform it to digit AbsId index.
icomp_stream(std::string filename, CompressionMethod method=CompressionMethod::None)
ocomp_stream(std::string filename, CompressionMethod method=CompressionMethod::None)
const GLuint GLenum const void * binary
Definition glcorearb.h:1898
GLuint GLuint stream
Definition glcorearb.h:1806
void pushDecompressor(T &stream, CompressionMethod method)
auto Method(std::string method)
void pushCompressor(T &stream, CompressionMethod method)
CompressionMethod
Definition CompStream.h:35
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
std::string filename()