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();
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
112 Bool_t parallelopen )
113 : TFile(
path,
"NET", ftitle, compress),
126 : TFile(
path,
"NET", ftitle, compress),
143 gEnv->SetValue(
"TFile.AsyncReading", 1);
149 if (fOption ==
"NEW")
152 Bool_t
create = (fOption ==
"CREATE");
153 Bool_t recreate = (fOption ==
"RECREATE");
154 Bool_t
update = (fOption ==
"UPDATE");
155 Bool_t
read = (fOption ==
"READ") || (fOption ==
"READWRAP");
156 Bool_t readwrap = (fOption ==
"READWRAP");
164 if (!gSystem->AccessPathName(
path, kFileExists))
165 gSystem->Unlink(
path);
173 if (
update && gSystem->AccessPathName(
path, kFileExists)) {
193 throw cms::Exception(
"TStorageFactoryFile::TStorageFactoryFile()") <<
"Cannot open file '" <<
path <<
"'";
210 fWritable =
read ? kFALSE : kTRUE;
233 Error(
"ReadBuffer",
"Cannot read from a zombie file");
238 Error(
"ReadBuffer",
"Cannot read from a file that is not open");
255 if (TFileCacheRead *
c = GetCacheRead()) {
256 Long64_t here = GetRelOffset();
257 Bool_t async =
c->IsAsyncReading();
263 Int_t st = ReadBufferViaCache(async ?
nullptr :
buf, len);
267 "ReadBufferViaCache failed. Asked to read nBytes: %d from offset: %lld with file size: %lld",
294 if (
n < static_cast<IOSize>(len)) {
296 "read from Storage::xread returned %ld. Asked to read n bytes: %d from offset: %lld with file size: %lld",
302 return n ? kFALSE : kTRUE;
308 Error(
"ReadBufferAsync",
"Cannot read from a zombie file");
313 Error(
"ReadBufferAsync",
"Cannot read from a file that is not open");
326 if (
f->cacheHint() == StorageFactory::CACHE_HINT_APPLICATION)
347 if (
f->cacheHint() == StorageFactory::CACHE_HINT_STORAGE)
375 Int_t remaining = nbuf;
378 IOSize remaining_buffer_size = 0;
381 for (Int_t
i = 0;
i < nbuf;
i++)
382 remaining_buffer_size += len[
i];
384 char *current_buffer =
buf;
385 Long64_t *current_pos =
pos;
386 Int_t *current_len = len;
390 while (remaining > 0) {
391 pack_count = repacker.
pack(
392 static_cast<long long int *>(current_pos), current_len, remaining, current_buffer, remaining_buffer_size);
399 std::vector<IOPosBuffer> &iov = repacker.
iov();
401 if (
result != io_buffer_used) {
403 "ReadBuffersSync",
"Storage::readv returned different size result=%ld expected=%ld",
result, io_buffer_used);
406 xstats.
tick(io_buffer_used);
407 repacker.
unpack(current_buffer);
410 remaining_buffer_size -= real_bytes_processed;
411 current_buffer += real_bytes_processed;
413 current_pos += pack_count;
414 current_len += pack_count;
415 remaining -= pack_count;
417 assert(remaining_buffer_size == 0);
424 Error(
"ReadBuffers",
"Cannot read from a zombie file");
429 Error(
"ReadBuffers",
"Cannot read from a file that is not open");
442 void *
const nobuf =
nullptr;
444 std::vector<IOPosBuffer> iov;
446 for (Int_t
i = 0;
i < nbuf; ++
i) {
447 iov.emplace_back(
pos[
i], nobuf, len[
i]);
461 if (TFile::ReadBuffers(
buf,
pos, len, nbuf)) {
462 Error(
"ReadBuffers",
"call to TFile::ReadBuffers failed after prefetch already failed.");
472 Error(
"WriteBuffer",
"Cannot write to a zombie file");
477 Error(
"WriteBuffer",
"Cannot write to a file that is not open");
482 Error(
"WriteBuffer",
"File is not writable");
491 switch ((st = WriteBufferViaCache(
buf, len))) {
501 return n > 0 ? kFALSE : kTRUE;
511 Error(
"WriteBuffer",
"Error writing to cache");
534 if (
flags & O_WRONLY)
536 else if (
flags & O_RDWR)
540 if (
flags & O_APPEND)
edm::ErrorSummaryEntry Error
TStorageFactoryFile(void)
static StorageAccount::Counter * s_statsWrite
static StorageAccount::Counter * s_statsStat
static StorageClassToken tokenForStorageClassName(std::string const &iName)
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
static Counter & counter(StorageClassToken token, Operation operation)
void tick(uint64_t amount=0, int64_t tick=0) const
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< edm::storage::Storage > > storage_
static StorageAccount::Counter * s_statsARead
static StorageAccount::Counter & storageCounter(StorageAccount::Counter *&c, StorageAccount::Operation operation)
constexpr int PREFETCH_PROBE_LENGTH
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 StorageAccount::Counter * s_statsCWrite
std::vector< IOPosBuffer > & iov()
void setException(std::exception_ptr e)
void ResetErrno(void) const override
IOSize bufferUsed() const
IOSize realBytesProcessed() 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
std::unique_ptr< GeometricDet > construct(DDCompactView const &cpv, std::vector< int > const &detidShifts)
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