CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RFIOStorageMaker.cc
Go to the documentation of this file.
11 #include <cstdlib>
12 #include "shift/stager_api.h"
13 
15 {
20  {
22  // look for options
23  size_t suffix = path.find("?");
24  if (suffix == std::string::npos)
25  {
26  // convert old syntax to new but leave "host:/path" alone
27  suffix = 0;
28  if (path.find (":") == std::string::npos)
29  {
30  size_t e = path.find_first_not_of ("/");
31  if (e != std::string::npos)
32  {
33  size_t c = path.find("/castor/");
34  if ((c != std::string::npos) && (c == e-1))
35  {
36  // /castor/path -> rfio:///?path=/castor/path
37  suffix = c;
38  prefix = "rfio:///?path=";
39  }
40  else
41  {
42  c = path.find("/dpm/");
43  if ((c != std::string::npos) && (c == e-1))
44  {
45  // /dpm/path -> rfio:///dpm/path
46  suffix = c;
47  prefix = "rfio://";
48  }
49  }
50  }
51  }
52  }
53  else
54  {
55  // new syntax, leave alone except normalize host
56  prefix = path.substr(0, suffix);
57  size_t h = prefix.find_first_not_of('/');
58  size_t s = prefix.find_last_not_of('/');
59  prefix.resize(s+1);
60  prefix.replace(0,h,"rfio://");
61  prefix += '/';
62  }
63 
64  return prefix + path.substr(suffix);
65  }
66 
67 public:
69  {
70  std::string rfiotype("");
71  bool err = false;
72  try
73  {
75  if (!siteconfig.isAvailable())
76  err = true;
77  else
78  rfiotype = siteconfig->rfioType();
79  }
80  catch (const cms::Exception &e)
81  {
82  err = true;
83  }
84 
85  if (err)
86  edm::LogWarning("RFIOStorageMaker")
87  << "SiteLocalConfig Failed: SiteLocalConfigService is not loaded yet."
88  << "Will use default 'castor' RFIO implementation.";
89 
90  if (rfiotype.empty())
91  rfiotype = "castor";
92 
93  // Force Castor to move control messages out of client TCP buffers faster.
94  putenv(const_cast<char *>("RFIO_TCP_NODELAY=1"));
95 
96  RFIOPluginFactory::get()->create(rfiotype);
97  Cthread_init();
98  }
99 
100  virtual std::unique_ptr<Storage> open (const std::string &proto,
101  const std::string &path,
102  int mode,
103  const AuxSettings&) const override
104  {
106  StorageFactory::ReadHint readHint = f->readHint();
107  StorageFactory::CacheHint cacheHint = f->cacheHint();
108 
110  || cacheHint == StorageFactory::CACHE_HINT_STORAGE)
111  mode &= ~IOFlags::OpenUnbuffered;
112  else
113  mode |= IOFlags::OpenUnbuffered;
114 
115  auto file = std::make_unique<RFIOFile>(normalise(path), mode);
116  return f->wrapNonLocalFile(std::move(file), proto, std::string(), mode);
117  }
118 
119  virtual void stagein (const std::string &proto,
120  const std::string &path,
121  const AuxSettings&) const override
122  {
123  std::string npath = normalise(path);
124  size_t castor = npath.find("?path=/castor/");
125  size_t rest = npath.find("&");
126  if (proto != "rfio" || castor == std::string::npos)
127  return;
128 
129  castor += 6;
130  size_t len = (rest == std::string::npos ? rest : rest-castor);
131  std::string stagepath(npath, castor, len);
132 
133  stage_options opts;
134  opts.stage_host = getenv("STAGE_HOST");
135  opts.service_class = getenv("STAGE_SVCCLASS");
136  opts.stage_port = 0;
137  opts.stage_version = 2;
138 
139  stage_prepareToGet_filereq req;
140  req.protocol = (char *) "rfio";
141  req.filename = (char *) stagepath.c_str();
142  req.priority = 0;
143 
144  int nresp = 0;
145  stage_prepareToGet_fileresp *resp = 0;
146  int rc = stage_prepareToGet(0, &req, 1, &resp, &nresp, 0, &opts);
147  if (rc < 0) {
148  cms::Exception ex("FileStageInError");
149  ex << "Error while staging in '" << stagepath
150  << "', error was: " << rfio_serror()
151  << " (serrno=" << serrno << ")";
152  ex.addContext("Calling RFIOStorageMaker::stagein()");
153  throw ex;
154  }
155 
156  if (nresp == 1 && resp->errorCode != 0) {
157  cms::Exception ex("FileStageInError");
158  ex << "Error while staging in '" << stagepath
159  << "', stagein error was: " << resp->errorMessage
160  << " (code=" << resp->errorCode << ")";
161  ex.addContext("Calling RFIOStorageMaker::stagein()");
162  throw ex;
163  }
164 
165  free(resp->filename);
166  free(resp->errorMessage);
167  free(resp);
168  }
169 
170  virtual bool check (const std::string &/*proto*/,
171  const std::string &path,
172  const AuxSettings&,
173  IOOffset *size = 0) const override
174  {
175  std::string npath = normalise(path);
176  if (rfio_access(npath.c_str (), R_OK) != 0)
177  return false;
178 
179  if (size)
180  {
181  struct stat buf;
182  if (rfio_stat64(npath.c_str (), &buf) != 0)
183  return false;
184 
185  *size = buf.st_size;
186  }
187 
188  return true;
189  }
190 };
191 
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
int Cthread_init(void)
virtual void stagein(const std::string &proto, const std::string &path, const AuxSettings &) const override
static const StorageFactory * get(void)
int rfio_access(const char *filepath, int mode)
#define serrno
Definition: RFIO.h:10
std::string normalise(const std::string &path) const
virtual std::unique_ptr< Storage > open(const std::string &proto, const std::string &path, int mode, const AuxSettings &) const override
def move
Definition: eostools.py:510
bool isAvailable() const
Definition: Service.h:46
double f[11][100]
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
char * rfio_serror()
ReadHint readHint(void) const
void addContext(std::string const &context)
Definition: Exception.cc:227
int64_t IOOffset
Definition: IOTypes.h:19
#define DEFINE_EDM_PLUGIN(factory, type, name)
virtual std::string const rfioType(void) const =0
virtual bool check(const std::string &, const std::string &path, const AuxSettings &, IOOffset *size=0) const override
int rfio_stat64(const char *path, struct stat *statbuf)
tuple size
Write out results.
T get(const Candidate &c)
Definition: component.h:55