CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
29 
30  ClientRequest(const ClientRequest &) = delete;
31  ClientRequest &operator=(const ClientRequest &) = delete;
32 
33  ClientRequest(RequestManager &manager, void *into, IOSize size, IOOffset off)
34  : m_failure_count(0), m_into(into), m_size(size), m_off(off), m_iolist(nullptr), m_manager(manager) {}
35 
36  ClientRequest(RequestManager &manager, std::shared_ptr<std::vector<IOPosBuffer>> iolist, IOSize size = 0)
37  : m_failure_count(0), m_into(nullptr), m_size(size), m_off(0), m_iolist(iolist), m_manager(manager) {
38  if (!m_iolist->empty() && !m_size) {
39  for (edm::storage::IOPosBuffer const &buf : *m_iolist) {
40  m_size += buf.size();
41  }
42  }
43  }
44 
45  void setStatistics(std::shared_ptr<XrdReadStatistics> stats) { m_stats = stats; }
46 
47  ~ClientRequest() override;
48 
49  std::future<edm::storage::IOSize> get_future() { return m_promise.get_future(); }
50 
54  void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override;
55 
56  edm::storage::IOSize getSize() const { return m_size; }
57 
58  size_t getCount() const { return m_into ? 1 : m_iolist->size(); }
59 
64  std::shared_ptr<Source const> getCurrentSource() const { return get_underlying_safe(m_source); }
65  std::shared_ptr<Source> &getCurrentSource() { return get_underlying_safe(m_source); }
66 
67  private:
68  std::shared_ptr<ClientRequest const> self_reference() const { return get_underlying_safe(m_self_reference); }
69  std::shared_ptr<ClientRequest> &self_reference() { return get_underlying_safe(m_self_reference); }
70 
71  unsigned m_failure_count;
72  void *m_into;
79 
80  // Some explanation is due here. When an IO is outstanding,
81  // Xrootd takes a raw pointer to this object. Hence we cannot
82  // allow it to go out of scope until some indeterminate time in the
83  // future. So, while the IO is outstanding, we take a reference to
84  // ourself to prevent the object from being unexpectedly deleted.
86 
87  std::promise<edm::storage::IOSize> m_promise;
88 
90  };
91 
92 } // namespace XrdAdaptor
93 
94 #endif
int64_t IOOffset
Definition: IOTypes.h:20
ClientRequest(RequestManager &manager, void *into, IOSize size, IOOffset off)
Definition: XrdRequest.h:33
edm::storage::IOSize IOSize
Definition: XrdRequest.h:27
std::shared_ptr< Source > & getCurrentSource()
Definition: XrdRequest.h:65
size_t getCount() const
Definition: XrdRequest.h:58
ClientRequest(RequestManager &manager, std::shared_ptr< std::vector< IOPosBuffer >> iolist, IOSize size=0)
Definition: XrdRequest.h:36
list status
Definition: mps_update.py:107
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
edm::storage::IOOffset IOOffset
Definition: XrdRequest.h:28
edm::propagate_const< std::shared_ptr< ClientRequest > > m_self_reference
Definition: XrdRequest.h:85
std::future< edm::storage::IOSize > get_future()
Definition: XrdRequest.h:49
edm::propagate_const< std::shared_ptr< XrdReadStatistics > > m_stats
Definition: XrdRequest.h:78
ClientRequest(const ClientRequest &)=delete
std::promise< edm::storage::IOSize > m_promise
Definition: XrdRequest.h:87
edm::storage::IOOffset m_off
Definition: XrdRequest.h:74
std::shared_ptr< ClientRequest > & self_reference()
Definition: XrdRequest.h:69
QualityMetricWatch m_qmw
Definition: XrdRequest.h:89
ClientRequest & operator=(const ClientRequest &)=delete
std::shared_ptr< ClientRequest const > self_reference() const
Definition: XrdRequest.h:68
edm::storage::IOSize m_size
Definition: XrdRequest.h:73
size_t IOSize
Definition: IOTypes.h:15
RequestManager & m_manager
Definition: XrdRequest.h:76
void setStatistics(std::shared_ptr< XrdReadStatistics > stats)
Definition: XrdRequest.h:45
edm::storage::IOSize getSize() const
Definition: XrdRequest.h:56
edm::propagate_const< std::shared_ptr< std::vector< edm::storage::IOPosBuffer > > > m_iolist
Definition: XrdRequest.h:75
std::shared_ptr< Source const > getCurrentSource() const
Definition: XrdRequest.h:64
edm::propagate_const< std::shared_ptr< Source > > m_source
Definition: XrdRequest.h:77
tuple size
Write out results.
void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
Definition: XrdRequest.cc:23