File indexing completed on 2025-05-19 07:20:22
0001 #define _GNU_SOURCE 1
0002 #define _FILE_OFFSET_BITS 64
0003 #include "Utilities/StorageFactory/interface/StorageMaker.h"
0004 #include "Utilities/StorageFactory/interface/StorageMakerFactory.h"
0005 #include "Utilities/StorageFactory/interface/StorageFactory.h"
0006 #include "Utilities/StorageFactory/interface/File.h"
0007 #include <sys/types.h>
0008 #include <sys/stat.h>
0009 #include <unistd.h>
0010
0011 namespace edm::storage {
0012 class LocalStorageMaker : public StorageMaker {
0013 public:
0014 std::unique_ptr<Storage> open(const std::string &proto,
0015 const std::string &path,
0016 int mode,
0017 const AuxSettings &) const override {
0018 const StorageFactory *f = StorageFactory::get();
0019 StorageFactory::ReadHint readHint = f->readHint();
0020 StorageFactory::CacheHint cacheHint = f->cacheHint();
0021
0022 if (readHint != StorageFactory::READ_HINT_UNBUFFERED || cacheHint == StorageFactory::CACHE_HINT_STORAGE)
0023 mode &= ~IOFlags::OpenUnbuffered;
0024 else
0025 mode |= IOFlags::OpenUnbuffered;
0026
0027 return std::make_unique<File>(path, mode);
0028 }
0029
0030 bool check(const std::string & ,
0031 const std::string &path,
0032 const AuxSettings &,
0033 IOOffset *size = nullptr) const override {
0034 struct stat st;
0035 if (stat(path.c_str(), &st) != 0)
0036 return false;
0037
0038 if (size)
0039 *size = st.st_size;
0040
0041 return true;
0042 }
0043
0044 UseLocalFile usesLocalFile() const override { return UseLocalFile::kCheckFromPath; }
0045 };
0046 }
0047
0048 using namespace edm::storage;
0049 DEFINE_EDM_PLUGIN(StorageMakerFactory, LocalStorageMaker, "file");