CMS 3D CMS Logo

DCacheStorageMaker.cc
Go to the documentation of this file.
6 #include <unistd.h>
7 #include <dcap.h>
8 
9 namespace edm::storage {
15  static std::string normalise(const std::string &proto, const std::string &path) {
16  size_t p = path.find("/pnfs");
17  if (p < 3)
18  return (proto == "gsidcap") ? proto + ':' + path.substr(p) : path.substr(p);
19 
20  // remove multiple "/"
21  p = path.find_first_not_of('/');
22 
23  // it's url, return the full thing
24  return proto + "://" + path.substr(p);
25  }
26 
27  public:
30  std::unique_ptr<Storage> open(const std::string &proto,
31  const std::string &path,
32  int mode,
33  AuxSettings const &aux) const override {
34  setTimeout(aux.timeout);
36  StorageFactory::ReadHint readHint = f->readHint();
37  StorageFactory::CacheHint cacheHint = f->cacheHint();
38 
40  mode &= ~IOFlags::OpenUnbuffered;
41  else
43 
44  auto file = std::make_unique<DCacheFile>(normalise(proto, path), mode);
45  return f->wrapNonLocalFile(std::move(file), proto, std::string(), mode);
46  }
47 
48  void stagein(const std::string &proto, const std::string &path, const AuxSettings &aux) const override {
49  setTimeout(aux.timeout);
50  std::string npath = normalise(proto, path);
51  if (dc_stage(npath.c_str(), 0, nullptr) != 0) {
52  cms::Exception ex("FileStageInError");
53  ex << "Cannot stage in file '" << npath << "', error was: " << dc_strerror(dc_errno)
54  << " (dc_errno=" << dc_errno << ")";
55  ex.addContext("Calling DCacheStorageMaker::stagein()");
56  throw ex;
57  }
58  }
59 
60  bool check(const std::string &proto,
61  const std::string &path,
62  const AuxSettings &aux,
63  IOOffset *size = nullptr) const override {
64  setTimeout(aux.timeout);
65  std::string testpath(normalise(proto, path));
66  if (dc_access(testpath.c_str(), R_OK) != 0)
67  return false;
68 
69  if (size) {
70  struct stat64 buf;
71  if (dc_stat64(testpath.c_str(), &buf) != 0)
72  return false;
73 
74  *size = buf.st_size;
75  }
76 
77  return true;
78  }
79 
80  private:
81  void setTimeout(unsigned int timeout) const {
82  if (timeout != 0)
83  dc_setOpenTimeout(timeout);
84  }
85  };
86 } // namespace edm::storage
87 
88 using namespace edm::storage;
size
Write out results.
int64_t IOOffset
Definition: IOTypes.h:20
static std::string normalise(const std::string &proto, const std::string &path)
double f[11][100]
bool check(const std::string &proto, const std::string &path, const AuxSettings &aux, IOOffset *size=nullptr) const override
void setTimeout(unsigned int timeout) const
void addContext(std::string const &context)
Definition: Exception.cc:165
void stagein(const std::string &proto, const std::string &path, const AuxSettings &aux) const override
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::unique_ptr< Storage > open(const std::string &proto, const std::string &path, int mode, AuxSettings const &aux) const override
static const StorageFactory * get(void)
def move(src, dest)
Definition: eostools.py:511