test
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 std::unique_ptr<Storage> open (const std::string &proto,
33  const std::string &path,
34  int mode,
35  AuxSettings const& aux) const override
36  {
37  setTimeout(aux.timeout);
39  StorageFactory::ReadHint readHint = f->readHint();
40  StorageFactory::CacheHint cacheHint = f->cacheHint();
41 
43  || cacheHint == StorageFactory::CACHE_HINT_STORAGE)
44  mode &= ~IOFlags::OpenUnbuffered;
45  else
47 
48  auto file = std::make_unique<DCacheFile>(normalise(proto, path), mode);
49  return f->wrapNonLocalFile(std::move(file), proto, std::string(), mode);
50  }
51 
52  virtual void stagein (const std::string &proto,
53  const std::string &path,
54  const AuxSettings& aux) const override
55  {
56  setTimeout(aux.timeout);
57  std::string npath = normalise(proto, path);
58  if (dc_stage(npath.c_str(), 0, 0) != 0) {
59  cms::Exception ex("FileStageInError");
60  ex << "Cannot stage in file '" << npath
61  << "', error was: " << dc_strerror(dc_errno)
62  << " (dc_errno=" << dc_errno << ")";
63  ex.addContext("Calling DCacheStorageMaker::stagein()");
64  throw ex;
65  }
66  }
67 
68  virtual bool check (const std::string &proto,
69  const std::string &path,
70  const AuxSettings& aux,
71  IOOffset *size = 0) const override
72  {
73  setTimeout(aux.timeout);
74  std::string testpath (normalise (proto, path));
75  if (dc_access (testpath.c_str (), R_OK) != 0)
76  return false;
77 
78  if (size)
79  {
80  struct stat64 buf;
81  if (dc_stat64 (testpath.c_str (), &buf) != 0)
82  return false;
83 
84  *size = buf.st_size;
85  }
86 
87  return true;
88  }
89 
90  private:
91 
92  void setTimeout(unsigned int timeout) const {
93  if (timeout != 0) dc_setOpenTimeout(timeout);
94  }
95 };
96 
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
virtual 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)
virtual void stagein(const std::string &proto, const std::string &path, const AuxSettings &aux) const override
def move
Definition: eostools.py:510
double f[11][100]
virtual bool check(const std::string &proto, const std::string &path, const AuxSettings &aux, IOOffset *size=0) const override
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.