CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DCacheStorageMaker.cc
Go to the documentation of this file.
6 #include <unistd.h>
7 #include <dcap.h>
8 
10 {
15  static std::string normalise (const std::string &proto, const std::string &path)
16  {
17  size_t p = path.find("/pnfs");
18  if (p < 3)
19  return (proto == "gsidcap") ? proto + ':' + path.substr(p) : path.substr(p);
20 
21  // remove multiple "/"
22  p = path.find_first_not_of('/');
23 
24  // it's url, return the full thing
25  return proto + "://" + path.substr(p);
26  }
27 
28 public:
29 
32  virtual Storage *open (const std::string &proto,
33  const std::string &path,
34  int mode) override
35  {
37  StorageFactory::ReadHint readHint = f->readHint();
38  StorageFactory::CacheHint cacheHint = f->cacheHint();
39 
41  || cacheHint == StorageFactory::CACHE_HINT_STORAGE)
42  mode &= ~IOFlags::OpenUnbuffered;
43  else
45 
46  Storage *file = new DCacheFile(normalise(proto, path), mode);
47  return f->wrapNonLocalFile(file, proto, std::string(), mode);
48  }
49 
50  virtual void stagein (const std::string &proto,
51  const std::string &path) override
52  {
53  std::string npath = normalise(proto, path);
54  if (dc_stage(npath.c_str(), 0, 0) != 0) {
55  cms::Exception ex("FileStageInError");
56  ex << "Cannot stage in file '" << npath
57  << "', error was: " << dc_strerror(dc_errno)
58  << " (dc_errno=" << dc_errno << ")";
59  ex.addContext("Calling DCacheStorageMaker::stagein()");
60  throw ex;
61  }
62  }
63 
64  virtual bool check (const std::string &proto,
65  const std::string &path,
66  IOOffset *size = 0) override
67  {
68  std::string testpath (normalise (proto, path));
69  if (dc_access (testpath.c_str (), R_OK) != 0)
70  return false;
71 
72  if (size)
73  {
74  struct stat64 buf;
75  if (dc_stat64 (testpath.c_str (), &buf) != 0)
76  return false;
77 
78  *size = buf.st_size;
79  }
80 
81  return true;
82  }
83 
84  virtual void setTimeout(unsigned int timeout) override {
85  if (timeout != 0) dc_setOpenTimeout(timeout);
86  }
87 };
88 
virtual void stagein(const std::string &proto, const std::string &path) override
CacheHint cacheHint(void) const
virtual bool check(const std::string &proto, const std::string &path, IOOffset *size=0) override
virtual Storage * open(const std::string &proto, const std::string &path, int mode) override
Storage * wrapNonLocalFile(Storage *s, const std::string &proto, const std::string &path, int mode)
static StorageFactory * get(void)
tuple path
else: Piece not in the list, fine.
double f[11][100]
ReadHint readHint(void) const
void addContext(std::string const &context)
Definition: Exception.cc:227
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)
tuple size
Write out results.
virtual void setTimeout(unsigned int timeout) override