test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions
RFIOStorageMaker Class Reference
Inheritance diagram for RFIOStorageMaker:
StorageMaker

Public Member Functions

virtual bool check (const std::string &, const std::string &path, const AuxSettings &, IOOffset *size=0) const override
 
virtual std::unique_ptr< Storageopen (const std::string &proto, const std::string &path, int mode, const AuxSettings &) const override
 
 RFIOStorageMaker ()
 
virtual void stagein (const std::string &proto, const std::string &path, const AuxSettings &) const override
 
- Public Member Functions inherited from StorageMaker
 StorageMaker ()=default
 
virtual ~StorageMaker ()=default
 

Private Member Functions

std::string normalise (const std::string &path) const
 

Detailed Description

Definition at line 14 of file RFIOStorageMaker.cc.

Constructor & Destructor Documentation

RFIOStorageMaker::RFIOStorageMaker ( )
inline

Definition at line 68 of file RFIOStorageMaker.cc.

References Cthread_init(), alignCSCRings::e, reco::get(), edm::Service< T >::isAvailable(), edm::SiteLocalConfig::rfioType(), and AlCaHLTBitMon_QueryRunRegistry::string.

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  }
int Cthread_init(void)
bool isAvailable() const
Definition: Service.h:46
virtual std::string const rfioType(void) const =0
T get(const Candidate &c)
Definition: component.h:55

Member Function Documentation

virtual bool RFIOStorageMaker::check ( const std::string &  ,
const std::string &  path,
const AuxSettings ,
IOOffset size = 0 
) const
inlineoverridevirtual

Reimplemented from StorageMaker.

Definition at line 170 of file RFIOStorageMaker.cc.

References normalise(), rfio_access(), rfio_stat64(), findQualityFiles::size, and AlCaHLTBitMon_QueryRunRegistry::string.

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  }
int rfio_access(const char *filepath, int mode)
std::string normalise(const std::string &path) const
int rfio_stat64(const char *path, struct stat *statbuf)
tuple size
Write out results.
std::string RFIOStorageMaker::normalise ( const std::string &  path) const
inlineprivate

Normalise new RFIO TURL style. Handle most obvious mis-spellings like excess '/' characters and /dpm vs. /castor syntax differences.

Definition at line 19 of file RFIOStorageMaker.cc.

References EnergyCorrector::c, alignCSCRings::e, h, alignCSCRings::s, AlCaHLTBitMon_QueryRunRegistry::string, and createPayload::suffix.

Referenced by check(), open(), and stagein().

20  {
21  std::string prefix;
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  }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
virtual std::unique_ptr<Storage> RFIOStorageMaker::open ( const std::string &  proto,
const std::string &  path,
int  mode,
const AuxSettings  
) const
inlineoverridevirtual

Implements StorageMaker.

Definition at line 100 of file RFIOStorageMaker.cc.

References StorageFactory::CACHE_HINT_STORAGE, StorageFactory::cacheHint(), f, mergeVDriftHistosByStation::file, StorageFactory::get(), alignBH_cfg::mode, eostools::move(), normalise(), IOFlags::OpenUnbuffered, StorageFactory::READ_HINT_READAHEAD, StorageFactory::readHint(), AlCaHLTBitMon_QueryRunRegistry::string, and StorageFactory::wrapNonLocalFile().

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
114 
115  auto file = std::make_unique<RFIOFile>(normalise(path), mode);
116  return f->wrapNonLocalFile(std::move(file), proto, std::string(), mode);
117  }
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
static const StorageFactory * get(void)
std::string normalise(const std::string &path) const
def move
Definition: eostools.py:510
double f[11][100]
ReadHint readHint(void) const
virtual void RFIOStorageMaker::stagein ( const std::string &  proto,
const std::string &  path,
const AuxSettings  
) const
inlineoverridevirtual

Reimplemented from StorageMaker.

Definition at line 119 of file RFIOStorageMaker.cc.

References cms::Exception::addContext(), normalise(), geometryDiff::opts, rfio_serror(), serrno, and AlCaHLTBitMon_QueryRunRegistry::string.

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  }
#define serrno
Definition: RFIO.h:10
std::string normalise(const std::string &path) const
char * rfio_serror()