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 
25 friend class Source;
26 
27 public:
28 
29  ClientRequest(RequestManager &manager, void *into, IOSize size, IOOffset off)
30  : m_failure_count(0),
31  m_into(into),
32  m_size(size),
33  m_off(off),
35  m_manager(manager)
36  {
37  }
38 
39  ClientRequest(RequestManager &manager, std::shared_ptr<std::vector<IOPosBuffer> > iolist, IOSize size=0)
40  : m_failure_count(0),
41  m_into(nullptr),
42  m_size(size),
43  m_off(0),
44  m_iolist(iolist),
45  m_manager(manager)
46  {
47  if (m_iolist->size() && !m_size)
48  {
49  for (IOPosBuffer const & buf : *m_iolist)
50  {
51  m_size += buf.size();
52  }
53  }
54  }
55 
56  void setStatistics(std::shared_ptr<XrdReadStatistics> stats)
57  {
58  m_stats = stats;
59  }
60 
61  virtual ~ClientRequest();
62 
63  std::future<IOSize> get_future()
64  {
65  return m_promise.get_future();
66  }
67 
71  virtual void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override;
72 
73  IOSize getSize() const {return m_size;}
74 
75  size_t getCount() const {return m_into ? 1 : m_iolist->size();}
76 
81  std::shared_ptr<Source const> getCurrentSource() const {return get_underlying_safe(m_source);}
82  std::shared_ptr<Source>& getCurrentSource() {return get_underlying_safe(m_source);}
83 
84 private:
85  std::shared_ptr<ClientRequest const> self_reference() const {return get_underlying_safe(m_self_reference);}
86  std::shared_ptr<ClientRequest>& self_reference() {return get_underlying_safe(m_self_reference);}
87 
88  unsigned m_failure_count;
89  void *m_into;
96 
97  // Some explanation is due here. When an IO is outstanding,
98  // Xrootd takes a raw pointer to this object. Hence we cannot
99  // allow it to go out of scope until some indeterminate time in the
100  // future. So, while the IO is outstanding, we take a reference to
101  // ourself to prevent the object from being unexpectedly deleted.
103 
104  std::promise<IOSize> m_promise;
105 
107 };
108 
109 }
110 
111 #endif
size
Write out results.
ClientRequest(RequestManager &manager, void *into, IOSize size, IOOffset off)
Definition: XrdRequest.h:29
std::shared_ptr< Source > & getCurrentSource()
Definition: XrdRequest.h:82
size_t getCount() const
Definition: XrdRequest.h:75
IOSize getSize() const
Definition: XrdRequest.h:73
edm::propagate_const< std::shared_ptr< std::vector< IOPosBuffer > > > m_iolist
Definition: XrdRequest.h:92
#define nullptr
edm::propagate_const< std::shared_ptr< ClientRequest > > m_self_reference
Definition: XrdRequest.h:102
edm::propagate_const< std::shared_ptr< XrdReadStatistics > > m_stats
Definition: XrdRequest.h:95
std::shared_ptr< ClientRequest > & self_reference()
Definition: XrdRequest.h:86
std::future< IOSize > get_future()
Definition: XrdRequest.h:63
QualityMetricWatch m_qmw
Definition: XrdRequest.h:106
std::shared_ptr< ClientRequest const > self_reference() const
Definition: XrdRequest.h:85
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
RequestManager & m_manager
Definition: XrdRequest.h:93
void setStatistics(std::shared_ptr< XrdReadStatistics > stats)
Definition: XrdRequest.h:56
int64_t IOOffset
Definition: IOTypes.h:19
ClientRequest(RequestManager &manager, std::shared_ptr< std::vector< IOPosBuffer > > iolist, IOSize size=0)
Definition: XrdRequest.h:39
size_t IOSize
Definition: IOTypes.h:14
std::shared_ptr< Source const > getCurrentSource() const
Definition: XrdRequest.h:81
edm::propagate_const< std::shared_ptr< Source > > m_source
Definition: XrdRequest.h:94
std::promise< IOSize > m_promise
Definition: XrdRequest.h:104
virtual void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
Definition: XrdRequest.cc:24