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)
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)
52  {
53  std::string npath = normalise(proto, path);
54  if (dc_stage(npath.c_str(), 0, 0) != 0)
55  throw cms::Exception("DCacheStorageMaker::stagein()")
56  << "Cannot stage in file '" << npath
57  << "', error was: " << dc_strerror(dc_errno)
58  << " (dc_errno=" << dc_errno << ")";
59  }
60 
61  virtual bool check (const std::string &proto,
62  const std::string &path,
63  IOOffset *size = 0)
64  {
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  {
71  struct stat64 buf;
72  if (dc_stat64 (testpath.c_str (), &buf) != 0)
73  return false;
74 
75  *size = buf.st_size;
76  }
77 
78  return true;
79  }
80 
81  virtual void setTimeout(unsigned int timeout) {
82  if (timeout != 0) dc_setOpenTimeout(timeout);
83  }
84 };
85 
CacheHint cacheHint(void) const
list file
Definition: dbtoweb.py:253
virtual Storage * open(const std::string &proto, const std::string &path, int mode)
Definition: Storage.h:8
Storage * wrapNonLocalFile(Storage *s, const std::string &proto, const std::string &path, int mode)
int path() const
Definition: HLTadd.h:3
static StorageFactory * get(void)
virtual void stagein(const std::string &proto, const std::string &path)
double f[11][100]
ReadHint readHint(void) const
int mode
Definition: AMPTWrapper.h:139
virtual bool check(const std::string &proto, const std::string &path, IOOffset *size=0)
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)