Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:52

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       auto file = std::make_unique<File>(path, mode);
0028       return f->wrapNonLocalFile(std::move(file), proto, path, mode);
0029     }
0030 
0031     bool check(const std::string & /*proto*/,
0032                const std::string &path,
0033                const AuxSettings &,
0034                IOOffset *size = nullptr) const override {
0035       struct stat st;
0036       if (stat(path.c_str(), &st) != 0)
0037         return false;
0038 
0039       if (size)
0040         *size = st.st_size;
0041 
0042       return true;
0043     }
0044   };
0045 }  // namespace edm::storage
0046 
0047 using namespace edm::storage;
0048 DEFINE_EDM_PLUGIN(StorageMakerFactory, LocalStorageMaker, "file");