CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
TStorageFactoryFile Class Reference

#include <TStorageFactoryFile.h>

Inheritance diagram for TStorageFactoryFile:

Public Member Functions

 ClassDefOverride (TStorageFactoryFile, 0)
 
Bool_t ReadBuffer (char *buf, Int_t len) override
 
Bool_t ReadBuffer (char *buf, Long64_t pos, Int_t len) override
 
Bool_t ReadBufferAsync (Long64_t off, Int_t len) override
 
Bool_t ReadBuffers (char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) override
 
void ResetErrno (void) const override
 
 TStorageFactoryFile (const char *name, Option_t *option, const char *ftitle, Int_t compress, Int_t netopt, Bool_t parallelopen=kFALSE)
 
 TStorageFactoryFile (const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1)
 
Bool_t WriteBuffer (const char *buf, Int_t len) override
 
 ~TStorageFactoryFile (void) override
 

Protected Member Functions

Int_t SysClose (Int_t fd) override
 
Int_t SysOpen (const char *pathname, Int_t flags, UInt_t mode) override
 
Long64_t SysSeek (Int_t fd, Long64_t offset, Int_t whence) override
 
Int_t SysStat (Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime) override
 
Int_t SysSync (Int_t fd) override
 

Private Member Functions

void Initialize (const char *name, Option_t *option="")
 
Bool_t ReadBuffersSync (char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
 
void releaseStorage ()
 
 TStorageFactoryFile (void)
 

Private Attributes

edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
 

Detailed Description

TFile wrapper around #StorageFactory and #Storage.

Definition at line 17 of file TStorageFactoryFile.h.

Constructor & Destructor Documentation

◆ TStorageFactoryFile() [1/3]

TStorageFactoryFile::TStorageFactoryFile ( const char *  name,
Option_t *  option,
const char *  ftitle,
Int_t  compress,
Int_t  netopt,
Bool_t  parallelopen = kFALSE 
)

Definition at line 111 of file TStorageFactoryFile.cc.

References Initialize(), fileinputsource_cfi::option, castor_dqm_sourceclient_file_cfg::path, and edm::threadLocalException::setException().

117  : TFile(path, "NET", ftitle, compress), // Pass "NET" to prevent local access in base class
118  storage_() {
119  try {
121  } catch (...) {
122  edm::threadLocalException::setException(std::current_exception()); // capture
123  }
124 }
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
void setException(std::exception_ptr e)
void Initialize(const char *name, Option_t *option="")

◆ TStorageFactoryFile() [2/3]

TStorageFactoryFile::TStorageFactoryFile ( const char *  name,
Option_t *  option = "",
const char *  ftitle = "",
Int_t  compress = 1 
)

Definition at line 126 of file TStorageFactoryFile.cc.

References Initialize(), fileinputsource_cfi::option, castor_dqm_sourceclient_file_cfg::path, and edm::threadLocalException::setException().

130  : TFile(path, "NET", ftitle, compress), // Pass "NET" to prevent local access in base class
131  storage_() {
132  try {
134  } catch (...) {
135  edm::threadLocalException::setException(std::current_exception()); // capture
136  }
137 }
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
void setException(std::exception_ptr e)
void Initialize(const char *name, Option_t *option="")

◆ ~TStorageFactoryFile()

TStorageFactoryFile::~TStorageFactoryFile ( void  )
override

Definition at line 221 of file TStorageFactoryFile.cc.

221 { Close(); }

◆ TStorageFactoryFile() [3/3]

TStorageFactoryFile::TStorageFactoryFile ( void  )
private

Definition at line 102 of file TStorageFactoryFile.cc.

References DDDCmsTrackerContruction::construct(), s_statsCtor, dqmMemoryStats::stats, and storageCounter().

102  : storage_() {
104  stats.tick(0);
105 }
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
static std::atomic< StorageAccount::Counter * > s_statsCtor
std::unique_ptr< GeometricDet > construct(DDCompactView const &cpv, std::vector< int > const &detidShifts)

Member Function Documentation

◆ ClassDefOverride()

TStorageFactoryFile::ClassDefOverride ( TStorageFactoryFile  ,
 
)

◆ Initialize()

void TStorageFactoryFile::Initialize ( const char *  name,
Option_t *  option = "" 
)
private

Definition at line 139 of file TStorageFactoryFile.cc.

References cms::cuda::assert(), DDDCmsTrackerContruction::construct(), beamerCreator::create(), MillePedeFileConverter_cfg::e, Exception, get, g4SimHits_cfi::Init, edm::Service< T >::isAvailable(), edm::errors::NotFound, edm::storage::IOFlags::OpenCreate, edm::storage::IOFlags::OpenRead, edm::storage::IOFlags::OpenWrap, edm::storage::IOFlags::OpenWrite, fileinputsource_cfi::option, castor_dqm_sourceclient_file_cfg::path, fileinputsource_cfi::read, s_statsCtor, edm::storage::StatisticsSenderService::setSize(), dqmMemoryStats::stats, storage_, storageCounter(), and update.

Referenced by TStorageFactoryFile().

139  {
141 
142  // Enable AsyncReading.
143  // This was the default for 5.27, but turned off by default for 5.32.
144  // In our testing, AsyncReading is the fastest mechanism available.
145  // In 5.32, the AsyncPrefetching mechanism is preferred, but has been a
146  // performance hit in our "average case" tests.
147  gEnv->SetValue("TFile.AsyncReading", 1);
148 
149  // Parse options; at the moment we only accept read!
150  fOption = option;
151  fOption.ToUpper();
152 
153  if (fOption == "NEW")
154  fOption = "CREATE";
155 
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");
161 
162  if (!create && !recreate && !update && !read) {
163  read = true;
164  fOption = "READ";
165  }
166 
167  if (recreate) {
168  if (!gSystem->AccessPathName(path, kFileExists))
169  gSystem->Unlink(path);
170 
171  recreate = false;
172  create = true;
173  fOption = "CREATE";
174  }
175  assert(!recreate);
176 
177  if (update && gSystem->AccessPathName(path, kFileExists)) {
178  update = kFALSE;
179  create = kTRUE;
180  }
181 
182  assert(read || update || create);
183 
184  int openFlags = IOFlags::OpenRead;
185  if (!read)
186  openFlags |= IOFlags::OpenWrite;
187  if (create)
188  openFlags |= IOFlags::OpenCreate;
189  //if (recreate) openFlags |= IOFlags::OpenCreate | IOFlags::OpenTruncate;
190  if (readwrap)
191  openFlags |= IOFlags::OpenWrap;
192 
193  // Open storage
194  if (!(storage_ = StorageFactory::get()->open(path, openFlags))) {
195  MakeZombie();
196  gDirectory = gROOT;
197  throw cms::Exception("TStorageFactoryFile::TStorageFactoryFile()") << "Cannot open file '" << path << "'";
198  }
199 
200  // Record the statistics.
201  try {
203  if (statsService.isAvailable()) {
204  statsService->setSize(path, storage_->size());
205  }
206  } catch (edm::Exception const &e) {
207  if (e.categoryCode() != edm::errors::NotFound) {
208  throw;
209  }
210  }
211 
212  fRealName = path;
213  fD = 0; // sorry, meaningless
214  fWritable = read ? kFALSE : kTRUE;
215 
216  Init(create);
217 
218  stats.tick(0);
219 }
void setSize(const std::string &urlOrLfn, size_t size)
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
def create(alignables, pedeDump, additionalData, outputFile, config)
assert(be >=bs)
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
static std::atomic< StorageAccount::Counter * > s_statsCtor
#define update(a, b)
bool isAvailable() const
Definition: Service.h:40
#define get
std::unique_ptr< GeometricDet > construct(DDCompactView const &cpv, std::vector< int > const &detidShifts)

◆ ReadBuffer() [1/2]

Bool_t TStorageFactoryFile::ReadBuffer ( char *  buf,
Int_t  len 
)
override

Definition at line 234 of file TStorageFactoryFile.cc.

References visDQMUpload::buf, HltBtagPostValidation_cff::c, dqmiodumpmetadata::n, fileinputsource_cfi::read, s_statsCPrefetch, s_statsCRead, s_statsRead, s_statsXRead, dqmMemoryStats::stats, storage_, storageCounter(), and edm::storage::StorageAccount::Stamp::tick().

Referenced by ReadBuffer().

234  {
235  // Check that it's valid to access this file.
236  if (IsZombie()) {
237  Error("ReadBuffer", "Cannot read from a zombie file");
238  return kTRUE;
239  }
240 
241  if (!IsOpen()) {
242  Error("ReadBuffer", "Cannot read from a file that is not open");
243  return kTRUE;
244  }
245 
246  // Read specified byte range from the storage. Returns kTRUE in
247  // case of error. Note that ROOT uses this function recursively
248  // to fill the cache; we use a flag to make sure our accounting
249  // is reflected in a comprehensible manner. The "read" counter
250  // will include both, "readc" indicates how much read from the
251  // cache, "readu" indicates how much we failed to read from the
252  // cache (excluding those recursive reads), and "readx" counts
253  // the amount actually passed to read from the storage object.
255 
256  // If we have a cache, read from there first. This returns 0
257  // if the block hasn't been prefetched, 1 if it was in cache,
258  // and 2 if there was an error.
259  if (TFileCacheRead *c = GetCacheRead()) {
260  Long64_t here = GetRelOffset();
261  Bool_t async = c->IsAsyncReading();
262 
263  StorageAccount::Stamp cstats(async
264  ? storageCounter(s_statsCPrefetch, StorageAccount::Operation::readPrefetchToCache)
265  : storageCounter(s_statsCRead, StorageAccount::Operation::readViaCache));
266 
267  Int_t st = ReadBufferViaCache(async ? nullptr : buf, len);
268 
269  if (st == 2) {
270  Error("ReadBuffer",
271  "ReadBufferViaCache failed. Asked to read nBytes: %d from offset: %lld with file size: %lld",
272  len,
273  here,
274  GetSize());
275  return kTRUE;
276  }
277 
278  if (st == 1) {
279  if (async) {
280  cstats.tick(len);
281  Seek(here);
282  } else {
283  cstats.tick(len);
284  stats.tick(len);
285  return kFALSE;
286  }
287  }
288  }
289 
290  // FIXME: Re-enable read-ahead if the data wasn't in cache.
291  // if (! st) storage_->caching(true, -1, s_readahead);
292 
293  // A real read
294  StorageAccount::Stamp xstats(storageCounter(s_statsXRead, StorageAccount::Operation::readActual));
295  IOSize n = storage_->xread(buf, len);
296  xstats.tick(n);
297  stats.tick(n);
298  if (n < static_cast<IOSize>(len)) {
299  Error("ReadBuffer",
300  "read from Storage::xread returned %ld. Asked to read n bytes: %d from offset: %lld with file size: %lld",
301  n,
302  len,
303  GetRelOffset(),
304  GetSize());
305  }
306  return n ? kFALSE : kTRUE;
307 }
edm::ErrorSummaryEntry Error
static std::atomic< StorageAccount::Counter * > s_statsXRead
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
static std::atomic< StorageAccount::Counter * > s_statsCPrefetch
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
static std::atomic< StorageAccount::Counter * > s_statsRead
size_t IOSize
Definition: IOTypes.h:15
static std::atomic< StorageAccount::Counter * > s_statsCRead

◆ ReadBuffer() [2/2]

Bool_t TStorageFactoryFile::ReadBuffer ( char *  buf,
Long64_t  pos,
Int_t  len 
)
override

Definition at line 227 of file TStorageFactoryFile.cc.

References visDQMUpload::buf, and ReadBuffer().

227  {
228  // This function needs to be optimized to minimize seeks.
229  // See TFile::ReadBuffer(char *buf, Long64_t pos, Int_t len) in ROOT 5.27.06.
230  Seek(pos);
231  return ReadBuffer(buf, len);
232 }
Bool_t ReadBuffer(char *buf, Int_t len) override

◆ ReadBufferAsync()

Bool_t TStorageFactoryFile::ReadBufferAsync ( Long64_t  off,
Int_t  len 
)
override

Definition at line 309 of file TStorageFactoryFile.cc.

References f, get, edm::storage::PREFETCH_PROBE_LENGTH, s_statsARead, dqmMemoryStats::stats, storage_, and storageCounter().

309  {
310  // Check that it's valid to access this file.
311  if (IsZombie()) {
312  Error("ReadBufferAsync", "Cannot read from a zombie file");
313  return kTRUE;
314  }
315 
316  if (!IsOpen()) {
317  Error("ReadBufferAsync", "Cannot read from a file that is not open");
318  return kTRUE;
319  }
320 
321  StorageAccount::Stamp stats(storageCounter(s_statsARead, StorageAccount::Operation::readAsync));
322 
323  // If asynchronous reading is disabled, bail out now, regardless
324  // whether the underlying storage supports prefetching. If it is
325  // forced on, pretend it's on, even if the storage doesn't support
326  // it, as this turns off the caching in ROOT's side.
328 
329  // Verify that we never using async reads in app-only mode
330  if (f->cacheHint() == StorageFactory::CACHE_HINT_APPLICATION)
331  return kTRUE;
332 
333  // Let the I/O method indicate if it can do client-side prefetch.
334  // If it does, then for example TTreeCache will drop its own cache
335  // and will use the client-side cache of the actual I/O layer.
336  // If len is zero ROOT is probing for prefetch support.
337  if (len) {
338  // FIXME: Synchronise caching.
339  // storage_->caching(true, -1, 0);
340  ;
341  }
342 
343  IOPosBuffer iov(off, (void *)nullptr, len ? len : PREFETCH_PROBE_LENGTH);
344  if (storage_->prefetch(&iov, 1)) {
345  stats.tick(len);
346  return kFALSE;
347  }
348 
349  // Always ask ROOT to use async reads in storage-only mode,
350  // regardless of whether the storage system supports it.
351  if (f->cacheHint() == StorageFactory::CACHE_HINT_STORAGE)
352  return kFALSE;
353 
354  // Prefetching not available right now.
355  return kTRUE;
356 }
edm::ErrorSummaryEntry Error
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
constexpr int PREFETCH_PROBE_LENGTH
Definition: Storage.h:18
double f[11][100]
static std::atomic< StorageAccount::Counter * > s_statsARead
#define get

◆ ReadBuffers()

Bool_t TStorageFactoryFile::ReadBuffers ( char *  buf,
Long64_t *  pos,
Int_t *  len,
Int_t  nbuf 
)
override

Definition at line 425 of file TStorageFactoryFile.cc.

References visDQMUpload::buf, mps_fire::i, ReadBuffersSync(), s_statsARead, storage_, storageCounter(), summarizeEdmComparisonLogfiles::success, edm::storage::StorageAccount::Stamp::tick(), and dqmMemoryStats::total.

425  {
426  // Check that it's valid to access this file.
427  if (IsZombie()) {
428  Error("ReadBuffers", "Cannot read from a zombie file");
429  return kTRUE;
430  }
431 
432  if (!IsOpen()) {
433  Error("ReadBuffers", "Cannot read from a file that is not open");
434  return kTRUE;
435  }
436 
437  // For synchronous reads, we have special logic to optimize the I/O requests
438  // from ROOT before handing it to the storage.
439  if (buf) {
440  return ReadBuffersSync(buf, pos, len, nbuf);
441  }
442  // For an async read, we assume the storage system is smart enough to do the
443  // optimization itself.
444 
445  // Read from underlying storage.
446  void *const nobuf = nullptr;
447  Int_t total = 0;
448  std::vector<IOPosBuffer> iov;
449  iov.reserve(nbuf);
450  for (Int_t i = 0; i < nbuf; ++i) {
451  iov.emplace_back(pos[i], nobuf, len[i]);
452  total += len[i];
453  }
454 
455  // Null buffer means asynchronous reads into I/O system's cache.
456  bool success;
457  StorageAccount::Stamp astats(storageCounter(s_statsARead, StorageAccount::Operation::readAsync));
458  // Synchronise low-level cache with the supposed cache in TFile.
459  // storage_->caching(true, -1, 0);
460  success = storage_->prefetch(iov.data(), nbuf);
461  astats.tick(total);
462 
463  // If it didn't suceeed, pass down to the base class.
464  if (not success) {
465  if (TFile::ReadBuffers(buf, pos, len, nbuf)) {
466  Error("ReadBuffers", "call to TFile::ReadBuffers failed after prefetch already failed.");
467  return kTRUE;
468  }
469  }
470  return kFALSE;
471 }
edm::ErrorSummaryEntry Error
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
static std::atomic< StorageAccount::Counter * > s_statsARead
Bool_t ReadBuffersSync(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)

◆ ReadBuffersSync()

Bool_t TStorageFactoryFile::ReadBuffersSync ( char *  buf,
Long64_t *  pos,
Int_t *  len,
Int_t  nbuf 
)
private

Most storage systems are not prepared for the onslaught of small reads that ROOT will perform, even if they implement a vectored read interface.

Typically, on the server side, the loop is unrolled and the reads are issued sequentially - giving the OS no hint that you're about to read a very close-by byte in the near future. Normally, OS read-ahead takes care of such situations; because the storage server has so many clients, and ROOT reads look random to the OS, the read-ahead becomes disabled.

Hence, this function will repack the application-layer request into an optimized storage-layer request. The resulting request to the storage layer typically has a slightly larger number of bytes, but far less individual reads.

On average, the server's disks see a smaller number of overall reads, the number of bytes transferred over the network increases modestly (around 10%), and the single application request becomes one-to-two I/O transactions. A clear win for all cases except high-latency WAN.

Definition at line 358 of file TStorageFactoryFile.cc.

References cms::cuda::assert(), visDQMUpload::buf, ReadRepacker::bufferUsed(), mps_fire::i, ReadRepacker::iov(), ReadRepacker::pack(), ReadRepacker::realBytesProcessed(), mps_fire::result, s_statsXRead, storage_, storageCounter(), edm::storage::StorageAccount::Stamp::tick(), and ReadRepacker::unpack().

Referenced by ReadBuffers().

358  {
379  Int_t remaining = nbuf; // Number of read requests left to process.
380  Int_t pack_count; // Number of read requests processed by this iteration.
381 
382  IOSize remaining_buffer_size = 0;
383  // Calculate the remaining buffer size for the ROOT-owned buffer by adding
384  // the size of the various requests.
385  for (Int_t i = 0; i < nbuf; i++)
386  remaining_buffer_size += len[i];
387 
388  char *current_buffer = buf;
389  Long64_t *current_pos = pos;
390  Int_t *current_len = len;
391 
392  ReadRepacker repacker;
393 
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);
397 
398  int real_bytes_processed = repacker.realBytesProcessed();
399  IOSize io_buffer_used = repacker.bufferUsed();
400 
401  // Issue readv, then unpack buffers.
402  StorageAccount::Stamp xstats(storageCounter(s_statsXRead, StorageAccount::Operation::readActual));
403  std::vector<IOPosBuffer> &iov = repacker.iov();
404  IOSize result = storage_->readv(&iov[0], iov.size());
405  if (result != io_buffer_used) {
406  Error(
407  "ReadBuffersSync", "Storage::readv returned different size result=%ld expected=%ld", result, io_buffer_used);
408  return kTRUE;
409  }
410  xstats.tick(io_buffer_used);
411  repacker.unpack(current_buffer);
412 
413  // Update the location of the unused part of the input buffer.
414  remaining_buffer_size -= real_bytes_processed;
415  current_buffer += real_bytes_processed;
416 
417  current_pos += pack_count;
418  current_len += pack_count;
419  remaining -= pack_count;
420  }
421  assert(remaining_buffer_size == 0);
422  return kFALSE;
423 }
edm::ErrorSummaryEntry Error
static std::atomic< StorageAccount::Counter * > s_statsXRead
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
assert(be >=bs)
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
int pack(long long int *pos, int *len, int nbuf, char *buf, IOSize buffer_size)
Definition: ReadRepacker.cc:21
void unpack(char *buf)
size_t IOSize
Definition: IOTypes.h:15
std::vector< IOPosBuffer > & iov()
Definition: ReadRepacker.h:47
IOSize bufferUsed() const
Definition: ReadRepacker.h:49
IOSize realBytesProcessed() const
Definition: ReadRepacker.h:54

◆ releaseStorage()

void TStorageFactoryFile::releaseStorage ( )
inlineprivate

Definition at line 58 of file TStorageFactoryFile.h.

References edm::get_underlying_safe(), and storage_.

Referenced by SysClose().

58 { get_underlying_safe(storage_).release(); }
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_

◆ ResetErrno()

void TStorageFactoryFile::ResetErrno ( void  ) const
override

Definition at line 602 of file TStorageFactoryFile.cc.

602 { TSystem::ResetErrno(); }

◆ SysClose()

Int_t TStorageFactoryFile::SysClose ( Int_t  fd)
overrideprotected

Definition at line 563 of file TStorageFactoryFile.cc.

References releaseStorage(), s_statsClose, dqmMemoryStats::stats, storage_, and storageCounter().

563  {
564  StorageAccount::Stamp stats(storageCounter(s_statsClose, StorageAccount::Operation::close));
565 
566  if (storage_) {
567  storage_->close();
568  releaseStorage();
569  }
570 
571  stats.tick();
572  return 0;
573 }
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
static std::atomic< StorageAccount::Counter * > s_statsClose

◆ SysOpen()

Int_t TStorageFactoryFile::SysOpen ( const char *  pathname,
Int_t  flags,
UInt_t  mode 
)
overrideprotected

Definition at line 530 of file TStorageFactoryFile.cc.

References Exception, HLT_2024v12_cff::flags, get, O_NONBLOCK, edm::storage::IOFlags::OpenAppend, edm::storage::IOFlags::OpenCreate, edm::storage::IOFlags::OpenExclusive, edm::storage::IOFlags::OpenNonBlock, edm::storage::IOFlags::OpenRead, edm::storage::IOFlags::OpenTruncate, edm::storage::IOFlags::OpenWrite, BTVHLTOfflineSource_cfi::pathname, s_statsOpen, dqmMemoryStats::stats, storage_, and storageCounter().

530  {
531  StorageAccount::Stamp stats(storageCounter(s_statsOpen, StorageAccount::Operation::open));
532 
533  if (storage_) {
534  storage_->close();
535  }
536 
537  int openFlags = IOFlags::OpenRead;
538  if (flags & O_WRONLY)
539  openFlags = IOFlags::OpenWrite;
540  else if (flags & O_RDWR)
541  openFlags |= IOFlags::OpenWrite;
542  if (flags & O_CREAT)
543  openFlags |= IOFlags::OpenCreate;
544  if (flags & O_APPEND)
545  openFlags |= IOFlags::OpenAppend;
546  if (flags & O_EXCL)
547  openFlags |= IOFlags::OpenExclusive;
548  if (flags & O_TRUNC)
549  openFlags |= IOFlags::OpenTruncate;
550  if (flags & O_NONBLOCK)
551  openFlags |= IOFlags::OpenNonBlock;
552 
553  if (!(storage_ = StorageFactory::get()->open(pathname, openFlags))) {
554  MakeZombie();
555  gDirectory = gROOT;
556  throw cms::Exception("TStorageFactoryFile::SysOpen()") << "Cannot open file '" << pathname << "'";
557  }
558 
559  stats.tick();
560  return 0;
561 }
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
static std::atomic< StorageAccount::Counter * > s_statsOpen
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
#define O_NONBLOCK
Definition: SysFile.h:23
#define get

◆ SysSeek()

Long64_t TStorageFactoryFile::SysSeek ( Int_t  fd,
Long64_t  offset,
Int_t  whence 
)
overrideprotected

Definition at line 575 of file TStorageFactoryFile.cc.

References DiLeptonHelp::END, hltrates_dqm_sourceclient-live_cfg::offset, RefreshWebPage::rel, s_statsSeek, L1DTConfigBti_cff::SET, dqmMemoryStats::stats, storage_, and storageCounter().

575  {
576  StorageAccount::Stamp stats(storageCounter(s_statsSeek, StorageAccount::Operation::seek));
577  Storage::Relative rel = (whence == SEEK_SET ? Storage::SET : whence == SEEK_CUR ? Storage::CURRENT : Storage::END);
578 
579  offset = storage_->position(offset, rel);
580  stats.tick();
581  return offset;
582 }
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
static std::atomic< StorageAccount::Counter * > s_statsSeek
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_

◆ SysStat()

Int_t TStorageFactoryFile::SysStat ( Int_t  fd,
Long_t *  id,
Long64_t *  size,
Long_t *  flags,
Long_t *  modtime 
)
overrideprotected

Definition at line 591 of file TStorageFactoryFile.cc.

References HLT_2024v12_cff::flags, s_statsStat, findQualityFiles::size, edm_modernize_messagelogger::stat, dqmMemoryStats::stats, storage_, and storageCounter().

591  {
593  // FIXME: Most of this is unsupported or makes no sense with Storage
594  *id = ::Hash(fRealName);
595  *size = storage_->size();
596  *flags = 0;
597  *modtime = 0;
598  stats.tick();
599  return 0;
600 }
size
Write out results.
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
std::string Hash
Definition: Types.h:43
static std::atomic< StorageAccount::Counter * > s_statsStat

◆ SysSync()

Int_t TStorageFactoryFile::SysSync ( Int_t  fd)
overrideprotected

Definition at line 584 of file TStorageFactoryFile.cc.

References s_statsFlush, dqmMemoryStats::stats, storage_, and storageCounter().

584  {
585  StorageAccount::Stamp stats(storageCounter(s_statsFlush, StorageAccount::Operation::flush));
586  storage_->flush();
587  stats.tick();
588  return 0;
589 }
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
static std::atomic< StorageAccount::Counter * > s_statsFlush
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_

◆ WriteBuffer()

Bool_t TStorageFactoryFile::WriteBuffer ( const char *  buf,
Int_t  len 
)
override

Definition at line 473 of file TStorageFactoryFile.cc.

References visDQMUpload::buf, dqmiodumpmetadata::n, s_statsCWrite, s_statsWrite, s_statsXWrite, dqmMemoryStats::stats, storage_, storageCounter(), edm::storage::StorageAccount::Stamp::tick(), and writeEcalDQMStatus::write.

473  {
474  // Check that it's valid to access this file.
475  if (IsZombie()) {
476  Error("WriteBuffer", "Cannot write to a zombie file");
477  return kTRUE;
478  }
479 
480  if (!IsOpen()) {
481  Error("WriteBuffer", "Cannot write to a file that is not open");
482  return kTRUE;
483  }
484 
485  if (!fWritable) {
486  Error("WriteBuffer", "File is not writable");
487  return kTRUE;
488  }
489 
491  StorageAccount::Stamp cstats(storageCounter(s_statsCWrite, StorageAccount::Operation::writeViaCache));
492 
493  // Try first writing via a cache, and if that's not possible, directly.
494  Int_t st;
495  switch ((st = WriteBufferViaCache(buf, len))) {
496  case 0:
497  // Actual write.
498  {
499  StorageAccount::Stamp xstats(storageCounter(s_statsXWrite, StorageAccount::Operation::writeActual));
500  IOSize n = storage_->xwrite(buf, len);
501  xstats.tick(n);
502  stats.tick(n);
503 
504  // FIXME: What if it's a short write?
505  return n > 0 ? kFALSE : kTRUE;
506  }
507 
508  case 1:
509  cstats.tick(len);
510  stats.tick(len);
511  return kFALSE;
512 
513  case 2:
514  default:
515  Error("WriteBuffer", "Error writing to cache");
516  return kTRUE;
517  }
518 }
edm::ErrorSummaryEntry Error
static StorageAccount::Counter & storageCounter(std::atomic< StorageAccount::Counter *> &c, StorageAccount::Operation operation)
static std::atomic< StorageAccount::Counter * > s_statsWrite
static std::atomic< StorageAccount::Counter * > s_statsXWrite
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
size_t IOSize
Definition: IOTypes.h:15
static std::atomic< StorageAccount::Counter * > s_statsCWrite

Member Data Documentation

◆ storage_

edm::propagate_const<std::unique_ptr<edm::storage::Storage> > TStorageFactoryFile::storage_
private