CMS 3D CMS Logo

XrdRequest.h
Go to the documentation of this file.
1 #ifndef Utilities_XrdAdaptor_XrdRequest_h
2 #define Utilities_XrdAdaptor_XrdRequest_h
3 
4 #include <future>
5 #include <vector>
6 
7 #include <XrdCl/XrdClXRootDResponses.hh>
8 
11 
12 #include "QualityMetric.h"
13 
14 namespace XrdAdaptor {
15 
16  class Source;
17 
18  class RequestManager;
19 
20  class XrdReadStatistics;
21 
22  class ClientRequest : public XrdCl::ResponseHandler {
23  friend class Source;
24 
25  public:
26  ClientRequest(const ClientRequest &) = delete;
27  ClientRequest &operator=(const ClientRequest &) = delete;
28 
29  ClientRequest(RequestManager &manager, void *into, IOSize size, IOOffset off)
30  : m_failure_count(0), m_into(into), m_size(size), m_off(off), m_iolist(nullptr), m_manager(manager) {}
31 
32  ClientRequest(RequestManager &manager, std::shared_ptr<std::vector<IOPosBuffer>> iolist, IOSize size = 0)
33  : m_failure_count(0), m_into(nullptr), m_size(size), m_off(0), m_iolist(iolist), m_manager(manager) {
34  if (!m_iolist->empty() && !m_size) {
35  for (IOPosBuffer const &buf : *m_iolist) {
36  m_size += buf.size();
37  }
38  }
39  }
40 
41  void setStatistics(std::shared_ptr<XrdReadStatistics> stats) { m_stats = stats; }
42 
43  ~ClientRequest() override;
44 
45  std::future<IOSize> get_future() { return m_promise.get_future(); }
46 
50  void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override;
51 
52  IOSize getSize() const { return m_size; }
53 
54  size_t getCount() const { return m_into ? 1 : m_iolist->size(); }
55 
60  std::shared_ptr<Source const> getCurrentSource() const { return get_underlying_safe(m_source); }
61  std::shared_ptr<Source> &getCurrentSource() { return get_underlying_safe(m_source); }
62 
63  private:
64  std::shared_ptr<ClientRequest const> self_reference() const { return get_underlying_safe(m_self_reference); }
65  std::shared_ptr<ClientRequest> &self_reference() { return get_underlying_safe(m_self_reference); }
66 
67  unsigned m_failure_count;
68  void *m_into;
75 
76  // Some explanation is due here. When an IO is outstanding,
77  // Xrootd takes a raw pointer to this object. Hence we cannot
78  // allow it to go out of scope until some indeterminate time in the
79  // future. So, while the IO is outstanding, we take a reference to
80  // ourself to prevent the object from being unexpectedly deleted.
82 
83  std::promise<IOSize> m_promise;
84 
86  };
87 
88 } // namespace XrdAdaptor
89 
90 #endif
XrdAdaptor::ClientRequest::getSize
IOSize getSize() const
Definition: XrdRequest.h:52
XrdAdaptor::ClientRequest::~ClientRequest
~ClientRequest() override
Definition: XrdRequest.cc:21
XrdAdaptor::ClientRequest::m_source
edm::propagate_const< std::shared_ptr< Source > > m_source
Definition: XrdRequest.h:73
XrdAdaptor::ClientRequest::self_reference
std::shared_ptr< ClientRequest const > self_reference() const
Definition: XrdRequest.h:64
XrdAdaptor::ClientRequest::self_reference
std::shared_ptr< ClientRequest > & self_reference()
Definition: XrdRequest.h:65
XrdAdaptor::ClientRequest::m_iolist
edm::propagate_const< std::shared_ptr< std::vector< IOPosBuffer > > > m_iolist
Definition: XrdRequest.h:71
XrdAdaptor::ClientRequest::getCurrentSource
std::shared_ptr< Source > & getCurrentSource()
Definition: XrdRequest.h:61
mps_update.status
status
Definition: mps_update.py:68
XrdAdaptor::ClientRequest::m_failure_count
unsigned m_failure_count
Definition: XrdRequest.h:67
XrdAdaptor::ClientRequest::ClientRequest
ClientRequest(RequestManager &manager, void *into, IOSize size, IOOffset off)
Definition: XrdRequest.h:29
XrdAdaptor::ClientRequest::m_into
void * m_into
Definition: XrdRequest.h:68
edm::get_underlying_safe
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
Definition: get_underlying_safe.h:41
Storage.h
XrdAdaptor::ClientRequest::m_qmw
QualityMetricWatch m_qmw
Definition: XrdRequest.h:85
XrdAdaptor::ClientRequest::operator=
ClientRequest & operator=(const ClientRequest &)=delete
edm::propagate_const
Definition: propagate_const.h:32
XrdAdaptor::ClientRequest::get_future
std::future< IOSize > get_future()
Definition: XrdRequest.h:45
XrdAdaptor::QualityMetricWatch
Definition: QualityMetric.h:20
XrdAdaptor::ClientRequest::ClientRequest
ClientRequest(RequestManager &manager, std::shared_ptr< std::vector< IOPosBuffer >> iolist, IOSize size=0)
Definition: XrdRequest.h:32
XrdAdaptor::ClientRequest::HandleResponse
void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
Definition: XrdRequest.cc:23
XrdAdaptor::ClientRequest::m_off
IOOffset m_off
Definition: XrdRequest.h:70
XrdAdaptor::ClientRequest::m_stats
edm::propagate_const< std::shared_ptr< XrdReadStatistics > > m_stats
Definition: XrdRequest.h:74
XrdAdaptor::ClientRequest::getCount
size_t getCount() const
Definition: XrdRequest.h:54
XrdAdaptor::ClientRequest::m_size
IOSize m_size
Definition: XrdRequest.h:69
XrdAdaptor::ClientRequest::ClientRequest
ClientRequest(const ClientRequest &)=delete
IOOffset
int64_t IOOffset
Definition: IOTypes.h:19
XrdAdaptor::ClientRequest::setStatistics
void setStatistics(std::shared_ptr< XrdReadStatistics > stats)
Definition: XrdRequest.h:41
dqmMemoryStats.stats
stats
Definition: dqmMemoryStats.py:134
visDQMUpload.buf
buf
Definition: visDQMUpload.py:160
XrdAdaptor::Source
Definition: XrdSource.h:23
QualityMetric.h
XrdAdaptor::ClientRequest::getCurrentSource
std::shared_ptr< Source const > getCurrentSource() const
Definition: XrdRequest.h:60
IOPosBuffer
Definition: IOPosBuffer.h:7
XrdAdaptor::ClientRequest::m_promise
std::promise< IOSize > m_promise
Definition: XrdRequest.h:83
XrdAdaptor::ClientRequest::m_self_reference
edm::propagate_const< std::shared_ptr< ClientRequest > > m_self_reference
Definition: XrdRequest.h:81
XrdAdaptor::ClientRequest::m_manager
RequestManager & m_manager
Definition: XrdRequest.h:72
XrdAdaptor::RequestManager
Definition: XrdRequestManager.h:44
IOSize
size_t IOSize
Definition: IOTypes.h:14
get_underlying_safe.h
XrdAdaptor
Definition: QualityMetric.h:14
XrdAdaptor::ClientRequest
Definition: XrdRequest.h:22
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
CollectionTags_cfi.Source
Source
Definition: CollectionTags_cfi.py:11