10 #include "TFileCacheRead.h" 22 #include "TTreeCache.h" 25 class TTreeCacheDebug :
public TTreeCache {
27 void dump(
const char *
label,
const char *trailer)
29 Long64_t
entry = fOwner->GetReadEntry();
31 << label <<
": " << entry <<
" " 32 <<
"{ fEntryMin=" << fEntryMin
33 <<
", fEntryMax=" << fEntryMax
34 <<
", fEntryNext=" << fEntryNext
35 <<
", fZipBytes=" << fZipBytes
36 <<
", fNbranches=" << fNbranches
37 <<
", fNReadOk=" << fNReadOk
38 <<
", fNReadMiss=" << fNReadMiss
39 <<
", fNReadPref=" << fNReadPref
40 <<
", fBranches=" << fBranches
41 <<
", fBrNames=" << fBrNames
42 <<
", fOwner=" << fOwner
43 <<
", fTree=" << fTree
44 <<
", fIsLearning=" << fIsLearning
45 <<
", fIsManual=" << fIsManual
46 <<
"; fBufferSizeMin=" << fBufferSizeMin
47 <<
", fBufferSize=" << fBufferSize
48 <<
", fBufferLen=" << fBufferLen
49 <<
", fBytesToPrefetch=" << fBytesToPrefetch
50 <<
", fFirstIndexToPrefetch=" << fFirstIndexToPrefetch
51 <<
", fAsyncReading=" << fAsyncReading
52 <<
", fNseek=" << fNseek
53 <<
", fNtot=" << fNtot
55 <<
", fSeekSize=" << fSeekSize
56 <<
", fSeek=" << fSeek
57 <<
", fSeekIndex=" << fSeekIndex
58 <<
", fSeekSort=" << fSeekSort
60 <<
", fSeekLen=" << fSeekLen
61 <<
", fSeekSortLen=" << fSeekSortLen
62 <<
", fSeekPos=" << fSeekPos
64 <<
", fFile=" << fFile
65 <<
", fBuffer=" << (
void *) fBuffer
66 <<
", fIsSorted=" << fIsSorted
110 Bool_t parallelopen )
111 : TFile(path,
"NET", ftitle, compress),
124 : TFile(path,
"NET", ftitle, compress),
141 gEnv->SetValue(
"TFile.AsyncReading", 1);
147 if (fOption ==
"NEW")
150 Bool_t
create = (fOption ==
"CREATE");
151 Bool_t recreate = (fOption ==
"RECREATE");
152 Bool_t
update = (fOption ==
"UPDATE");
153 Bool_t read = (fOption ==
"READ") || (fOption ==
"READWRAP");
154 Bool_t readwrap = (fOption ==
"READWRAP");
156 if (!create && !recreate && !update && !read) {
162 if (!gSystem->AccessPathName(path, kFileExists))
163 gSystem->Unlink(path);
171 if (update && gSystem->AccessPathName(path, kFileExists)) {
176 assert(read || update || create);
191 throw cms::Exception(
"TStorageFactoryFile::TStorageFactoryFile()") <<
"Cannot open file '" << path <<
"'";
208 fWritable = read ? kFALSE : kTRUE;
231 Error(
"ReadBuffer",
"Cannot read from a zombie file");
236 Error(
"ReadBuffer",
"Cannot read from a file that is not open");
253 if (TFileCacheRead *
c = GetCacheRead()) {
254 Long64_t here = GetRelOffset();
255 Bool_t async =
c->IsAsyncReading();
261 Int_t st = ReadBufferViaCache(async ?
nullptr : buf, len);
265 "ReadBufferViaCache failed. Asked to read nBytes: %d from offset: %lld with file size: %lld",
292 if (n < static_cast<IOSize>(len)) {
294 "read from Storage::xread returned %ld. Asked to read n bytes: %d from offset: %lld with file size: %lld",
300 return n ? kFALSE : kTRUE;
306 Error(
"ReadBufferAsync",
"Cannot read from a zombie file");
311 Error(
"ReadBufferAsync",
"Cannot read from a file that is not open");
373 Int_t remaining = nbuf;
376 IOSize remaining_buffer_size = 0;
379 for (Int_t
i = 0;
i < nbuf;
i++)
380 remaining_buffer_size += len[
i];
382 char *current_buffer = buf;
383 Long64_t *current_pos = pos;
384 Int_t *current_len = len;
388 while (remaining > 0) {
389 pack_count = repacker.
pack(
390 static_cast<long long int *>(current_pos), current_len, remaining, current_buffer, remaining_buffer_size);
397 std::vector<IOPosBuffer> &iov = repacker.
iov();
399 if (result != io_buffer_used) {
401 "ReadBuffersSync",
"Storage::readv returned different size result=%ld expected=%ld", result, io_buffer_used);
404 xstats.
tick(io_buffer_used);
405 repacker.
unpack(current_buffer);
408 remaining_buffer_size -= real_bytes_processed;
409 current_buffer += real_bytes_processed;
411 current_pos += pack_count;
412 current_len += pack_count;
413 remaining -= pack_count;
415 assert(remaining_buffer_size == 0);
422 Error(
"ReadBuffers",
"Cannot read from a zombie file");
427 Error(
"ReadBuffers",
"Cannot read from a file that is not open");
440 void *
const nobuf =
nullptr;
442 std::vector<IOPosBuffer> iov;
444 for (Int_t
i = 0;
i < nbuf; ++
i) {
454 success =
storage_->prefetch(&iov[0], nbuf);
459 if (TFile::ReadBuffers(buf, pos, len, nbuf)) {
460 Error(
"ReadBuffers",
"call to TFile::ReadBuffers failed after prefetch already failed.");
470 Error(
"WriteBuffer",
"Cannot write to a zombie file");
475 Error(
"WriteBuffer",
"Cannot write to a file that is not open");
480 Error(
"WriteBuffer",
"File is not writable");
489 switch ((st = WriteBufferViaCache(buf, len))) {
499 return n > 0 ? kFALSE : kTRUE;
509 Error(
"WriteBuffer",
"Error writing to cache");
532 if (flags & O_WRONLY)
534 else if (flags & O_RDWR)
538 if (flags & O_APPEND)
550 throw cms::Exception(
"TStorageFactoryFile::SysOpen()") <<
"Cannot open file '" << pathname <<
"'";
573 offset =
storage_->position(offset, rel);
Code categoryCode() const
edm::ErrorSummaryEntry Error
TStorageFactoryFile(void)
void ResetErrno(void) const override
CacheHint cacheHint(void) const
static StorageAccount::Counter * s_statsWrite
static StorageAccount::Counter * s_statsStat
#define PREFETCH_PROBE_LENGTH
void setSize(const std::string &urlOrLfn, size_t size)
Long64_t SysSeek(Int_t fd, Long64_t offset, Int_t whence) override
def create(alignables, pedeDump, additionalData, outputFile, config)
static StorageAccount::Counter * s_statsXWrite
static StorageAccount::Counter * s_statsClose
Int_t SysClose(Int_t fd) override
std::vector< Variable::Flags > flags
Bool_t ReadBufferAsync(Long64_t off, Int_t len) override
Bool_t ReadBuffer(char *buf, Int_t len) override
edm::propagate_const< std::unique_ptr< Storage > > storage_
static const StorageFactory * get(void)
IOSize realBytesProcessed() const
static StorageAccount::Counter * s_statsARead
static StorageClassToken tokenForStorageClassName(std::string const &iName)
static StorageAccount::Counter & storageCounter(StorageAccount::Counter *&c, StorageAccount::Operation operation)
static StorageAccount::Counter * s_statsCtor
int pack(long long int *pos, int *len, int nbuf, char *buf, IOSize buffer_size)
static StorageAccount::Counter * s_statsRead
static StorageAccount::Counter * s_statsXRead
static StorageAccount::Counter * s_statsFlush
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode) override
static Counter & counter(StorageClassToken token, Operation operation)
static StorageAccount::Counter * s_statsCWrite
IOSize bufferUsed() const
std::vector< IOPosBuffer > & iov()
void setException(std::exception_ptr e)
void tick(uint64_t amount=0, int64_t tick=0) const
~TStorageFactoryFile(void) override
static StorageAccount::Counter * s_statsSeek
Int_t SysSync(Int_t fd) override
static StorageAccount::Counter * s_statsOpen
Bool_t WriteBuffer(const char *buf, Int_t len) override
ClassImp(TStorageFactoryFile)
Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) override
Bool_t ReadBuffersSync(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
void Initialize(const char *name, Option_t *option="")
static StorageAccount::Counter * s_statsCPrefetch
Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime) override
static StorageAccount::Counter * s_statsCRead