Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:54

0001 #ifndef Utilities_XrdAdaptor_XrdSource_h
0002 #define Utilities_XrdAdaptor_XrdSource_h
0003 
0004 #include "XrdCl/XrdClXRootDResponses.hh"
0005 #include "FWCore/Utilities/interface/get_underlying_safe.h"
0006 
0007 #include <memory>
0008 #include <vector>
0009 
0010 #include "QualityMetric.h"
0011 
0012 namespace XrdCl {
0013   class File;
0014 }
0015 
0016 namespace XrdAdaptor {
0017 
0018   class RequestList;
0019   class ClientRequest;
0020   class XrdSiteStatistics;
0021   class XrdStatisticsService;
0022 
0023   class Source : public std::enable_shared_from_this<Source> {
0024   public:
0025     Source(const Source &) = delete;
0026     Source &operator=(const Source &) = delete;
0027 
0028     Source(timespec now, std::unique_ptr<XrdCl::File> fileHandle, const std::string &exclude);
0029 
0030     ~Source();
0031 
0032     void handle(std::shared_ptr<ClientRequest>);
0033 
0034     void handle(RequestList &);
0035 
0036     std::shared_ptr<XrdCl::File> getFileHandle();
0037 
0038     const std::string &ID() const { return m_id; }
0039     const std::string &Site() const { return m_site; }
0040     const std::string &PrettyID() const { return m_prettyid; }
0041     const std::string &ExcludeID() const { return m_exclude; }
0042 
0043     unsigned getQuality() { return m_qm->get(); }
0044 
0045     struct timespec getLastDowngrade() const { return m_lastDowngrade; }
0046     void setLastDowngrade(struct timespec now) { m_lastDowngrade = now; }
0047 
0048     static bool getDomain(const std::string &host, std::string &domain);
0049     static bool getXrootdSite(XrdCl::File &file, std::string &site);
0050     static bool getXrootdSiteFromURL(std::string url, std::string &site);
0051 
0052     // Given a file and (possibly) a host list, determine the exclude string.
0053     static void determineHostExcludeString(XrdCl::File &file, const XrdCl::HostList *hostList, std::string &exclude);
0054 
0055     // Given a connected File object, determine whether we believe this to be a
0056     // dCache pool (dCache is a separate implementation and sometimes benefits from
0057     // implementation-specific behaviors.
0058     static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList = nullptr);
0059     static bool isDCachePool(const std::string &url);
0060 
0061     // Given an Xrootd server ID, determine the hostname to the best of our ability.
0062     static bool getHostname(const std::string &id, std::string &hostname);
0063 
0064   private:
0065     void requestCallback(/* TODO: type? */);
0066 
0067     void setXrootdSite();
0068 
0069     std::shared_ptr<XrdCl::File const> fh() const { return get_underlying_safe(m_fh); }
0070     std::shared_ptr<XrdCl::File> &fh() { return get_underlying_safe(m_fh); }
0071     std::shared_ptr<XrdSiteStatistics const> stats() const { return get_underlying_safe(m_stats); }
0072     std::shared_ptr<XrdSiteStatistics> &stats() { return get_underlying_safe(m_stats); }
0073 
0074     struct timespec m_lastDowngrade;
0075     std::string m_id;
0076     std::string m_prettyid;
0077     std::string m_site;
0078     std::string m_exclude;
0079     edm::propagate_const<std::shared_ptr<XrdCl::File>> m_fh;
0080 
0081     edm::propagate_const<std::unique_ptr<QualityMetricSource>> m_qm;
0082     edm::propagate_const<std::shared_ptr<XrdSiteStatistics>> m_stats;
0083 
0084 #ifdef XRD_FAKE_SLOW
0085     bool m_slow;
0086 #endif
0087   };
0088 
0089 }  // namespace XrdAdaptor
0090 
0091 #endif