10 #include "TFileCacheRead.h" 23 #include "TTreeCache.h" 26 class TTreeCacheDebug :
public TTreeCache {
28 void dump(
const char *
label,
const char *trailer)
30 Long64_t
entry = fOwner->GetReadEntry();
33 <<
"{ fEntryMin=" << fEntryMin
34 <<
", fEntryMax=" << fEntryMax
35 <<
", fEntryNext=" << fEntryNext
36 <<
", fZipBytes=" << fZipBytes
37 <<
", fNbranches=" << fNbranches
38 <<
", fNReadOk=" << fNReadOk
39 <<
", fNReadMiss=" << fNReadMiss
40 <<
", fNReadPref=" << fNReadPref
41 <<
", fBranches=" << fBranches
42 <<
", fBrNames=" << fBrNames
43 <<
", fOwner=" << fOwner
44 <<
", fTree=" << fTree
45 <<
", fIsLearning=" << fIsLearning
46 <<
", fIsManual=" << fIsManual
47 <<
"; fBufferSizeMin=" << fBufferSizeMin
48 <<
", fBufferSize=" << fBufferSize
49 <<
", fBufferLen=" << fBufferLen
50 <<
", fBytesToPrefetch=" << fBytesToPrefetch
51 <<
", fFirstIndexToPrefetch=" << fFirstIndexToPrefetch
52 <<
", fAsyncReading=" << fAsyncReading
53 <<
", fNseek=" << fNseek
54 <<
", fNtot=" << fNtot
56 <<
", fSeekSize=" << fSeekSize
57 <<
", fSeek=" << fSeek
58 <<
", fSeekIndex=" << fSeekIndex
59 <<
", fSeekSort=" << fSeekSort
61 <<
", fSeekLen=" << fSeekLen
62 <<
", fSeekSortLen=" << fSeekSortLen
63 <<
", fSeekPos=" << fSeekPos
65 <<
", fFile=" << fFile
66 <<
", fBuffer=" << (
void *) fBuffer
67 <<
", fIsSorted=" << fIsSorted
76 static std::atomic<StorageAccount::Counter *>
s_statsCtor =
nullptr;
77 static std::atomic<StorageAccount::Counter *>
s_statsOpen =
nullptr;
78 static std::atomic<StorageAccount::Counter *>
s_statsClose =
nullptr;
79 static std::atomic<StorageAccount::Counter *>
s_statsFlush =
nullptr;
80 static std::atomic<StorageAccount::Counter *>
s_statsStat =
nullptr;
81 static std::atomic<StorageAccount::Counter *>
s_statsSeek =
nullptr;
82 static std::atomic<StorageAccount::Counter *>
s_statsRead =
nullptr;
83 static std::atomic<StorageAccount::Counter *>
s_statsCRead =
nullptr;
85 static std::atomic<StorageAccount::Counter *>
s_statsARead =
nullptr;
86 static std::atomic<StorageAccount::Counter *>
s_statsXRead =
nullptr;
87 static std::atomic<StorageAccount::Counter *>
s_statsWrite =
nullptr;
97 c.compare_exchange_strong(expected,
v);
116 Bool_t parallelopen )
117 : TFile(
path,
"NET", ftitle, compress),
130 : TFile(
path,
"NET", ftitle, compress),
147 gEnv->SetValue(
"TFile.AsyncReading", 1);
153 if (fOption ==
"NEW")
156 Bool_t
create = (fOption ==
"CREATE");
157 Bool_t recreate = (fOption ==
"RECREATE");
158 Bool_t
update = (fOption ==
"UPDATE");
159 Bool_t
read = (fOption ==
"READ") || (fOption ==
"READWRAP");
160 Bool_t readwrap = (fOption ==
"READWRAP");
168 if (!gSystem->AccessPathName(
path, kFileExists))
169 gSystem->Unlink(
path);
177 if (
update && gSystem->AccessPathName(
path, kFileExists)) {
197 throw cms::Exception(
"TStorageFactoryFile::TStorageFactoryFile()") <<
"Cannot open file '" <<
path <<
"'";
214 fWritable =
read ? kFALSE : kTRUE;
237 Error(
"ReadBuffer",
"Cannot read from a zombie file");
242 Error(
"ReadBuffer",
"Cannot read from a file that is not open");
259 if (TFileCacheRead *
c = GetCacheRead()) {
260 Long64_t here = GetRelOffset();
261 Bool_t async =
c->IsAsyncReading();
267 Int_t st = ReadBufferViaCache(async ?
nullptr :
buf, len);
271 "ReadBufferViaCache failed. Asked to read nBytes: %d from offset: %lld with file size: %lld",
298 if (
n < static_cast<IOSize>(len)) {
300 "read from Storage::xread returned %ld. Asked to read n bytes: %d from offset: %lld with file size: %lld",
306 return n ? kFALSE : kTRUE;
312 Error(
"ReadBufferAsync",
"Cannot read from a zombie file");
317 Error(
"ReadBufferAsync",
"Cannot read from a file that is not open");
330 if (
f->cacheHint() == StorageFactory::CACHE_HINT_APPLICATION)
351 if (
f->cacheHint() == StorageFactory::CACHE_HINT_STORAGE)
379 Int_t remaining = nbuf;
382 IOSize remaining_buffer_size = 0;
385 for (Int_t
i = 0;
i < nbuf;
i++)
386 remaining_buffer_size += len[
i];
388 char *current_buffer =
buf;
389 Long64_t *current_pos =
pos;
390 Int_t *current_len = len;
394 while (remaining > 0) {
395 pack_count = repacker.
pack(
396 static_cast<long long int *>(current_pos), current_len, remaining, current_buffer, remaining_buffer_size);
403 std::vector<IOPosBuffer> &iov = repacker.
iov();
405 if (
result != io_buffer_used) {
407 "ReadBuffersSync",
"Storage::readv returned different size result=%ld expected=%ld",
result, io_buffer_used);
410 xstats.
tick(io_buffer_used);
411 repacker.
unpack(current_buffer);
414 remaining_buffer_size -= real_bytes_processed;
415 current_buffer += real_bytes_processed;
417 current_pos += pack_count;
418 current_len += pack_count;
419 remaining -= pack_count;
421 assert(remaining_buffer_size == 0);
428 Error(
"ReadBuffers",
"Cannot read from a zombie file");
433 Error(
"ReadBuffers",
"Cannot read from a file that is not open");
446 void *
const nobuf =
nullptr;
448 std::vector<IOPosBuffer> iov;
450 for (Int_t
i = 0;
i < nbuf; ++
i) {
451 iov.emplace_back(
pos[
i], nobuf, len[
i]);
465 if (TFile::ReadBuffers(
buf,
pos, len, nbuf)) {
466 Error(
"ReadBuffers",
"call to TFile::ReadBuffers failed after prefetch already failed.");
476 Error(
"WriteBuffer",
"Cannot write to a zombie file");
481 Error(
"WriteBuffer",
"Cannot write to a file that is not open");
486 Error(
"WriteBuffer",
"File is not writable");
495 switch ((st = WriteBufferViaCache(
buf, len))) {
505 return n > 0 ? kFALSE : kTRUE;
515 Error(
"WriteBuffer",
"Error writing to cache");
538 if (
flags & O_WRONLY)
540 else if (
flags & O_RDWR)
544 if (
flags & O_APPEND)
edm::ErrorSummaryEntry Error
TStorageFactoryFile(void)
static std::atomic< StorageAccount::Counter * > s_statsXRead
static StorageClassToken tokenForStorageClassName(std::string const &iName)
void setSize(const std::string &urlOrLfn, size_t size)
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
Long64_t SysSeek(Int_t fd, Long64_t offset, Int_t whence) override
def create(alignables, pedeDump, additionalData, outputFile, config)
Int_t SysClose(Int_t fd) override
static Counter & counter(StorageClassToken token, Operation operation)
static std::atomic< StorageAccount::Counter * > s_statsFlush
static std::atomic< StorageAccount::Counter * > s_statsSeek
void tick(uint64_t amount=0, int64_t tick=0) const
Bool_t ReadBufferAsync(Long64_t off, Int_t len) override
static std::atomic< StorageAccount::Counter * > s_statsCPrefetch
static std::atomic< StorageAccount::Counter * > s_statsWrite
static std::atomic< StorageAccount::Counter * > s_statsXWrite
Bool_t ReadBuffer(char *buf, Int_t len) override
static std::atomic< StorageAccount::Counter * > s_statsOpen
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
static std::atomic< StorageAccount::Counter * > s_statsRead
constexpr int PREFETCH_PROBE_LENGTH
static std::atomic< StorageAccount::Counter * > s_statsCtor
int pack(long long int *pos, int *len, int nbuf, char *buf, IOSize buffer_size)
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode) override
static std::atomic< StorageAccount::Counter * > s_statsARead
static std::atomic< StorageAccount::Counter * > s_statsCRead
static std::atomic< StorageAccount::Counter * > s_statsClose
std::vector< IOPosBuffer > & iov()
void setException(std::exception_ptr e)
void ResetErrno(void) const override
IOSize bufferUsed() const
IOSize realBytesProcessed() const
static std::atomic< StorageAccount::Counter * > s_statsCWrite
~TStorageFactoryFile(void) override
Int_t SysSync(Int_t fd) override
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)
static std::atomic< StorageAccount::Counter * > s_statsStat
void Initialize(const char *name, Option_t *option="")
Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime) override