34using std::istringstream;
39#include "BESUncompressManager3.h"
40#include "BESUncompress3GZ.h"
41#include "BESUncompress3BZ2.h"
42#include "BESUncompress3Z.h"
44#include "BESFileLockingCache.h"
46#include "BESInternalError.h"
49#include "TheBESKeys.h"
52static std::once_flag d_euc_init_once;
70BESUncompressManager3::~BESUncompressManager3() {}
83 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
85 BESUncompressManager3::UCIter i;
86 i = _uncompress_list.find(name);
87 if (i == _uncompress_list.end()) {
88 _uncompress_list[name] = method;
104 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
106 BESUncompressManager3::UCIter i;
107 i = _uncompress_list.find(name);
108 if (i != _uncompress_list.end()) {
148 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
150 BESDEBUG(
"uncompress2",
"BESUncompressManager3::uncompress() - src: " << src << endl );
163 std::ostringstream oss;
164 oss <<
"BESUncompressManager3::" << __func__ <<
"() - ";
165 oss <<
"The supplied Cache object is NULL. Decompression Requires An Operational Cache.";
170 string::size_type dot = src.rfind(
".");
171 if (dot == string::npos) {
172 BESDEBUG(
"uncompress2",
"BESUncompressManager3::uncompress() - no file extension" << endl );
176 string ext = src.substr(dot + 1, src.size() - dot);
182 BESDEBUG(
"uncompress2",
"BESUncompressManager3::uncompress() - not compressed " << endl );
192 BESDEBUG(
"uncompress2",
"BESUncompressManager3::uncompress() - is cached? " << src << endl );
197 BESDEBUG(
"uncompress",
"BESUncompressManager3::uncompress() - cached hit: " << cache_file << endl );
204 BESDEBUG(
"uncompress",
"BESUncompressManager3::uncompress() - caching " << cache_file << endl );
226 BESDEBUG(
"uncompress",
"BESUncompressManager3::uncompress() - cached hit: " << cache_file << endl );
235 BESDEBUG(
"uncompress",
"BESUncompressManager3::uncompress() - caught exception, unlocking cache and re-throw." << endl );
236 cache->unlock_cache();
253 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
255 strm << BESIndent::LMarg <<
"BESUncompressManager3::dump - (" << (
void *)
this <<
")" << endl;
257 if (_uncompress_list.size()) {
258 strm << BESIndent::LMarg <<
"registered uncompression methods:" << endl;
260 BESUncompressManager3::UCIter i = _uncompress_list.begin();
261 BESUncompressManager3::UCIter ie = _uncompress_list.end();
262 for (; i != ie; i++) {
263 strm << BESIndent::LMarg << (*i).first << endl;
265 BESIndent::UnIndent();
268 strm << BESIndent::LMarg <<
"registered uncompress methods: none" << endl;
270 BESIndent::UnIndent();
274BESUncompressManager3::TheManager()
276 std::call_once(d_euc_init_once,BESUncompressManager3::initialize_instance);
280void BESUncompressManager3::initialize_instance() {
283 atexit(delete_instance);
287void BESUncompressManager3::delete_instance() {
Implementation of a caching mechanism for compressed data.
virtual unsigned long long update_cache_info(const std::string &target)
Update the cache info file to include 'target'.
virtual bool create_and_lock(const std::string &target, int &fd)
Create a file in the cache and lock it for write access.
virtual void exclusive_to_shared_lock(int fd)
Transfer from an exclusive lock to a shared lock.
virtual bool get_read_lock(const std::string &target, int &fd)
Get a read-only lock on the file if it exists.
virtual bool cache_too_big(unsigned long long current_size) const
look at the cache size; is it too large? Look at the cache size and see if it is too big.
virtual void update_and_purge(const std::string &new_file)
Purge files from the cache.
virtual std::string get_cache_file_name(const std::string &src, bool mangle=true)
exception thrown if internal error encountered
static void uncompress(const std::string &src, int fd)
uncompress a file with the .bz2 file extension
static void uncompress(const std::string &src, int dest_fd)
uncompress a file with the .gz file extension
static void uncompress(const std::string &src, int fd)
uncompress a file with the .gz file extension
List of all registered decompression methods.
BESUncompressManager3()
constructs an uncompression manager adding gz, z, and bz2 uncompression methods by default.
virtual bool add_method(const std::string &name, p_bes_uncompress method)
create_and_lock a uncompress method to the list
virtual p_bes_uncompress find_method(const std::string &name)
returns the uncompression method specified
virtual bool uncompress(const std::string &src, std::string &target, BESFileLockingCache *cache)
If the file 'src' should be uncompressed, do so and return a new file name on the value-result param ...
virtual void dump(std::ostream &strm) const
dumps information about this object