File indexing completed on 2025-05-19 07:20:21
0001 #include "Utilities/StorageFactory/interface/StorageMaker.h"
0002 #include "Utilities/StorageFactory/interface/StorageMakerFactory.h"
0003 #include "Utilities/StorageFactory/interface/StorageFactory.h"
0004 #include "Utilities/DCacheAdaptor/interface/DCacheFile.h"
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 #include <unistd.h>
0007 #include <dcap.h>
0008
0009 namespace edm::storage {
0010 class DCacheStorageMaker : public StorageMaker {
0011
0012
0013
0014
0015 static std::string normalise(const std::string &proto, const std::string &path) {
0016 size_t p = path.find("/pnfs");
0017 if (p < 3)
0018 return (proto == "gsidcap") ? proto + ':' + path.substr(p) : path.substr(p);
0019
0020
0021 p = path.find_first_not_of('/');
0022
0023
0024 return proto + "://" + path.substr(p);
0025 }
0026
0027 public:
0028
0029
0030 std::unique_ptr<Storage> open(const std::string &proto,
0031 const std::string &path,
0032 int mode,
0033 AuxSettings const &aux) const override {
0034 setTimeout(aux.timeout);
0035 const StorageFactory *f = StorageFactory::get();
0036 StorageFactory::ReadHint readHint = f->readHint();
0037 StorageFactory::CacheHint cacheHint = f->cacheHint();
0038
0039 if (readHint != StorageFactory::READ_HINT_UNBUFFERED || cacheHint == StorageFactory::CACHE_HINT_STORAGE)
0040 mode &= ~IOFlags::OpenUnbuffered;
0041 else
0042 mode |= IOFlags::OpenUnbuffered;
0043
0044 return std::make_unique<DCacheFile>(normalise(proto, path), mode);
0045 }
0046
0047 void stagein(const std::string &proto, const std::string &path, const AuxSettings &aux) const override {
0048 setTimeout(aux.timeout);
0049 std::string npath = normalise(proto, path);
0050 if (dc_stage(npath.c_str(), 0, nullptr) != 0) {
0051 cms::Exception ex("FileStageInError");
0052 ex << "Cannot stage in file '" << npath << "', error was: " << dc_strerror(dc_errno)
0053 << " (dc_errno=" << dc_errno << ")";
0054 ex.addContext("Calling DCacheStorageMaker::stagein()");
0055 throw ex;
0056 }
0057 }
0058
0059 bool check(const std::string &proto,
0060 const std::string &path,
0061 const AuxSettings &aux,
0062 IOOffset *size = nullptr) const override {
0063 setTimeout(aux.timeout);
0064 std::string testpath(normalise(proto, path));
0065 if (dc_access(testpath.c_str(), R_OK) != 0)
0066 return false;
0067
0068 if (size) {
0069 struct stat64 buf;
0070 if (dc_stat64(testpath.c_str(), &buf) != 0)
0071 return false;
0072
0073 *size = buf.st_size;
0074 }
0075
0076 return true;
0077 }
0078
0079 UseLocalFile usesLocalFile() const override { return UseLocalFile::kNo; }
0080
0081 private:
0082 void setTimeout(unsigned int timeout) const {
0083 if (timeout != 0)
0084 dc_setOpenTimeout(timeout);
0085 }
0086 };
0087 }
0088
0089 using namespace edm::storage;
0090 DEFINE_EDM_PLUGIN(StorageMakerFactory, DCacheStorageMaker, "dcache");
0091 DEFINE_EDM_PLUGIN(StorageMakerFactory, DCacheStorageMaker, "dcap");
0092 DEFINE_EDM_PLUGIN(StorageMakerFactory, DCacheStorageMaker, "gsidcap");