Skip to content

Commit

Permalink
Move base IO class to separate file.
Browse files Browse the repository at this point in the history
  • Loading branch information
alja authored and abh3 committed Jun 30, 2016
1 parent 923085a commit 37ea140
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 53 deletions.
1 change: 1 addition & 0 deletions src/XrdFileCache.cmake
Expand Up @@ -21,6 +21,7 @@ add_library(
XrdFileCache/XrdFileCacheFile.cc XrdFileCache/XrdFileCacheFile.hh
XrdFileCache/XrdFileCacheStats.hh
XrdFileCache/XrdFileCacheInfo.cc XrdFileCache/XrdFileCacheInfo.hh
XrdFileCache/XrdFileCacheIO.hh
XrdFileCache/XrdFileCacheIOEntireFile.cc XrdFileCache/XrdFileCacheIOEntireFile.hh
XrdFileCache/XrdFileCacheIOFileBlock.cc XrdFileCache/XrdFileCacheIOFileBlock.hh
XrdFileCache/XrdFileCacheDecision.hh)
Expand Down
4 changes: 1 addition & 3 deletions src/XrdFileCache/XrdFileCache.cc
Expand Up @@ -100,9 +100,8 @@ void Cache::Detach(XrdOucCacheIO* io)
delete io;
}

// XXXX MT: is the following needed ???
//______________________________________________________________________________


void Cache::getFilePathFromURL(const char* iUrl, std::string &result) const
{
XrdCl::URL url(iUrl);
Expand All @@ -118,7 +117,6 @@ Cache::HaveFreeWritingSlots()
return s_writeQ.size < maxWriteWaits;
}


//______________________________________________________________________________
void
Cache::AddWriteTask(Block* b, bool fromRead)
Expand Down
45 changes: 3 additions & 42 deletions src/XrdFileCache/XrdFileCache.hh
Expand Up @@ -30,6 +30,7 @@ namespace XrdCl {
}
namespace XrdFileCache {
class File;
class IO;
}

namespace XrdFileCache
Expand All @@ -39,9 +40,6 @@ namespace XrdFileCache
//----------------------------------------------------------------------------
class Cache : public XrdOucCache
{
friend class IOEntireFile;
friend class IOFileBlock;

public:
//---------------------------------------------------------------------
//! Constructor
Expand Down Expand Up @@ -93,12 +91,10 @@ namespace XrdFileCache

void Prefetch();

private:
//! Decrease attached count. Called from IO::Detach().
void Detach(XrdOucCacheIO *);

//! Transfor URL to path on local disk.
void getFilePathFromURL(const char* url, std::string& res) const;
private:

//! Short log alias.
XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
Expand All @@ -114,7 +110,7 @@ namespace XrdFileCache
WriteQ() : condVar(0), size(0) {}
XrdSysCondVar condVar; //!< write list condVar
size_t size; //!< cache size of a container
std::list<Block*> queue; //!< container
std::list<Block*> queue; //!< container
};

WriteQ s_writeQ;
Expand All @@ -124,41 +120,6 @@ namespace XrdFileCache
FileList m_files;
};

//----------------------------------------------------------------------------
//! Base cache-io class that implements XrdOucCacheIO abstract methods.
//----------------------------------------------------------------------------
class IO : public XrdOucCacheIO
{
friend class File;

public:
IO (XrdOucCacheIO &io, XrdOucCacheStats &stats, Cache &cache) :
m_io(io), m_statsGlobal(stats), m_cache(cache) {}

//! Original data source.
virtual XrdOucCacheIO *Base() { return &m_io; }

//! Original data source URL.
virtual long long FSize() { return m_io.FSize(); }

//! Original data source URL.
virtual const char *Path() { return m_io.Path(); }

virtual int Sync() { return 0; }

virtual int Trunc(long long Offset) { errno = ENOTSUP; return -1; }

virtual int Write(char *Buffer, long long Offset, int Length)
{ errno = ENOTSUP; return -1; }


protected:
XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }

XrdOucCacheIO &m_io; //!< original data source
XrdOucCacheStats &m_statsGlobal; //!< reference to Cache statistics
Cache &m_cache; //!< reference to Cache needed in detach
};
}

#endif
7 changes: 3 additions & 4 deletions src/XrdFileCache/XrdFileCacheIOEntireFile.cc
Expand Up @@ -37,12 +37,11 @@ IOEntireFile::IOEntireFile(XrdOucCacheIO &io, XrdOucCacheStats &stats, Cache & c
m_file(0)
{
clLog()->Info(XrdCl::AppMsg, "IO::IO() [%p] %s", this, m_io.Path());

std::string fname;
m_cache.getFilePathFromURL(io.Path(), fname);
XrdCl::URL url(io.Path());
std::string fname = Factory::GetInstance().RefConfiguration().m_cache_dir + url.GetPath();

m_file = new File(io, fname, 0, io.FSize());

}

IOEntireFile::~IOEntireFile()
Expand Down
1 change: 1 addition & 0 deletions src/XrdFileCache/XrdFileCacheIOEntireFile.hh
Expand Up @@ -21,6 +21,7 @@
#include <string>

#include "XrdSys/XrdSysPthread.hh"
#include "XrdFileCacheIO.hh"
#include "XrdFileCache.hh"
#include "XrdFileCacheStats.hh"
#include "XrdFileCacheFile.hh"
Expand Down
5 changes: 3 additions & 2 deletions src/XrdFileCache/XrdFileCacheIOFileBlock.cc
Expand Up @@ -86,8 +86,9 @@ void IOFileBlock::GetBlockSizeFromPath()
//______________________________________________________________________________
File* IOFileBlock::newBlockFile(long long off, int blocksize, XrdOucCacheIO* io)
{
std::string fname;
m_cache.getFilePathFromURL(io->Path(), fname);
XrdCl::URL url(io->Path());
std::string fname = Factory::GetInstance().RefConfiguration().m_cache_dir + url.GetPath();

std::stringstream ss;
ss << fname;
char offExt[64];
Expand Down
3 changes: 1 addition & 2 deletions src/XrdFileCache/XrdFileCacheIOFileBlock.hh
Expand Up @@ -23,8 +23,7 @@
#include "XrdOuc/XrdOucCache.hh"
#include "XrdSys/XrdSysPthread.hh"

#include "XrdFileCache.hh"
#include "XrdFileCacheFile.hh"
#include "XrdFileCacheIO.hh"

class XrdSysError;
class XrdOssDF;
Expand Down

0 comments on commit 37ea140

Please sign in to comment.