12 using namespace XrdAdaptor;
17 #define XRD_CL_MAX_CHUNK 512*1024
18 #define XRD_CL_MAX_SIZE 1024
38 open (name, flags, perms);
57 <<
"Destructor called on XROOTD file '" <<
m_name
58 <<
"' but the file is still open";
96 if ((name == 0) || (*name == 0)) {
98 ex <<
"Cannot open a file without a name";
104 ex <<
"Must open file '" << name <<
"' at least for read or write";
113 openflags |= XrdCl::OpenFlags::Update;
115 openflags |= XrdCl::OpenFlags::Read;
119 ex <<
"Opening file '" << name <<
"' in append mode not supported";
127 openflags |= XrdCl::OpenFlags::Delete;
128 openflags |= XrdCl::OpenFlags::New;
129 openflags |= XrdCl::OpenFlags::MakePath;
133 openflags |= XrdCl::OpenFlags::Delete;
152 XrdCl::XRootDStatus
status;
153 XrdCl::StatInfo *statInfo =
NULL;
154 if (! (status =
file->Stat(
false, statInfo)).IsOK()) {
156 ex <<
"XrdCl::File::Stat(name='" << name
157 <<
") => error '" << status.ToStr()
158 <<
"' (errno=" << status.errNo <<
", code=" << status.code <<
")";
164 m_size = statInfo->GetSize();
184 std::vector<std::string> sources;
186 std::stringstream
ss;
187 ss <<
"Active sources: ";
188 for (
auto const& it : sources)
199 <<
"XrdFile::close(name='" <<
m_name
200 <<
"') called but the file is not open";
226 if (n > 0x7fffffff) {
228 ex <<
"XrdFile::read(name='" <<
m_name <<
"', n=" << n
229 <<
") too many bytes, limit is 0x7fffffff";
243 if (n > 0x7fffffff) {
245 ex <<
"XrdFile::read(name='" <<
m_name <<
"', n=" << n
246 <<
") exceeds read size limit 0x7fffffff";
261 std::vector<IOPosBuffer> new_buf;
269 return readv(&(new_buf[0]), n);
287 std::shared_ptr<std::vector<IOPosBuffer> >
cl(
new std::vector<IOPosBuffer>);
293 cl->reserve(n > adjust ? adjust : n);
296 std::vector<std::pair<std::future<IOSize>,
IOSize>> readv_futures;
302 unsigned rollback_count = 1;
307 char * buffer =
static_cast<char *
>(into[
idx].
data());
316 cl->emplace_back(ci);
323 cl->emplace_back(ci);
325 if (cl->size() > adjust)
327 while (rollback_count--) cl->pop_back();
351 std::chrono::time_point<std::chrono::high_resolution_clock>
start,
end;
361 if (readv_futures.size() > 1)
363 for (
auto & readv_result : readv_futures)
365 if (readv_result.first.valid())
367 readv_result.first.wait();
372 for (
auto & readv_result : readv_futures)
377 const int retry_count = 5;
378 for (
int retries=0; retries<retry_count; retries++)
382 if (readv_result.first.valid())
384 result = readv_result.first.get();
389 if ((retries != retry_count-1) && (ex.
getCode() == XrdCl::errInvalidResponse))
391 edm::LogWarning(
"XrdAdaptorInternal") <<
"Got an invalid response from Xrootd server; retrying" << std::endl;
399 assert(result == readv_result.second);
410 newex <<
"A std::exception was thrown when processing an xrootd request: " << ex.
what();
418 edm::LogVerbatim(
"XrdAdaptorInternal") <<
"[" <<
m_op_count.fetch_add(1) <<
"] Time for readv: " <<
static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(end-
start).
count()) <<
" (sub-readv requests: " << readv_futures.size() <<
")" << std::endl;
426 if (n > 0x7fffffff) {
428 ex <<
"XrdFile::write(name='" <<
m_name <<
"', n=" << n
429 <<
") too many bytes, limit is 0x7fffffff";
439 ex <<
"XrdFile::write(name='" <<
m_name <<
"', n=" << n
440 <<
") failed with error '" << s.ToStr()
441 <<
"' (errno=" << s.errNo <<
", code=" << s.code <<
")";
457 if (n > 0x7fffffff) {
459 ex <<
"XrdFile::write(name='" <<
m_name <<
"', n=" << n
460 <<
") too many bytes, limit is 0x7fffffff";
467 XrdCl::XRootDStatus
s =
file->Write(pos, n, from);
470 ex <<
"XrdFile::write(name='" <<
m_name <<
"', n=" << n
471 <<
") failed with error '" << s.ToStr()
472 <<
"' (errno=" << s.errNo <<
", code=" << s.code <<
")";
478 if (static_cast<IOOffset>(pos + n) >
m_size)
500 ex <<
"XrdFile::position() called on a closed file";
523 ex <<
"XrdFile::position() called with incorrect 'whence' parameter";
542 ex <<
"XrdFile::resize(name='" <<
m_name <<
"') not implemented";
548 std::shared_ptr<XrdCl::File>
554 ex <<
"Xrd::getActiveFile(name='" <<
m_name <<
"') no active request manager";
555 ex.
addContext(
"Calling XrdFile::getActiveFile()");
edm::propagate_const< std::shared_ptr< XrdAdaptor::RequestManager > > m_requestmanager
virtual char const * what() const
virtual void resize(IOOffset size)
tuple start
Check for commandline option errors.
virtual void create(const char *name, bool exclusive=false, int perms=0666)
std::vector< Variable::Flags > flags
void set_data(void *new_buffer)
void set_size(IOSize new_size)
virtual bool prefetch(const IOPosBuffer *what, IOSize n)
void set_offset(IOOffset new_offset)
virtual IOOffset position(void) const
std::atomic< unsigned int > m_op_count
virtual IOSize readv(IOBuffer *into, IOSize n)
std::shared_ptr< XrdCl::File > getActiveFile()
element_type const * get() const
IOOffset offset(void) const
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
virtual IOOffset size(void) const
void addContext(std::string const &context)
char data[epos_bytes_allocation]
volatile std::atomic< bool > shutdown_flag false
void addConnection(cms::Exception &)
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
virtual IOSize write(const void *from, IOSize n)