CMS 3D CMS Logo

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