CMS 3D CMS Logo

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