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