12 using namespace edm::storage;
18 ex <<
"Cannot change file but operation '" << why <<
"' was called";
19 ex.
addContext(
"LocalCacheFile::" + why +
"()");
24 : image_(base->
size()),
26 storage_(std::
move(base)),
34 if (
char *
p = std::getenv(
"TMPDIR"))
38 pattern +=
"/cmssw-shadow-XXXXXX";
40 std::vector<char>
temp(pattern.c_str(), pattern.c_str() + pattern.size() + 1);
41 int fd = mkstemp(&
temp[0]);
44 ex <<
"Cannot create temporary file '" << pattern <<
"': " << strerror(errno) <<
" (error " << errno <<
")";
45 ex.
addContext(
"LocalCacheFile::LocalCacheFile");
49 file_ = std::make_unique<File>(
fd);
65 void *
window = mmap(
nullptr, len, PROT_READ | PROT_WRITE, MAP_SHARED,
file_->fd(),
start);
66 if (window == MAP_FAILED) {
68 ex <<
"Unable to map a window of local cache file: " << strerror(errno) <<
" (error " << errno <<
")";
74 nread =
storage_->read(window, len, start);
77 std::ostringstream ost;
78 ost <<
"Unable to cache " << len <<
" byte file segment at " << start <<
": ";
88 ex <<
"Unable to cache " << len <<
" byte file segment at " << start <<
": got only " << nread <<
" bytes back";
108 cache(here, here + n);
110 return file_->read(into, n);
115 return file_->read(into, n, pos);
122 end += into[
i].
size();
125 return file_->readv(into, n);
178 return file_->prefetch(what, n);
void flush(void) override
IOSize write(const void *from, IOSize n) override
virtual IOOffset size() const
edm::propagate_const< std::unique_ptr< Storage > > storage_
IOSize writev(const IOBuffer *from, IOSize n) override
void cache(IOOffset start, IOOffset end)
edm::propagate_const< std::unique_ptr< File > > file_
virtual IOOffset position() const
bool prefetch(const IOPosBuffer *what, IOSize n) override
void close(void) override
IOSize readv(IOBuffer *into, IOSize n) override
void addContext(std::string const &context)
~LocalCacheFile(void) override
LocalCacheFile(std::unique_ptr< Storage > base, const std::string &tmpdir="")
static constexpr IOOffset CHUNK_SIZE
void resize(IOOffset size) override
std::vector< char > present_
tuple size
Write out results.
static void nowrite(const std::string &why)