CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/Utilities/XrdAdaptor/plugins/XrdStorageMaker.cc

Go to the documentation of this file.
00001 #include "Utilities/StorageFactory/interface/StorageMaker.h"
00002 #include "Utilities/StorageFactory/interface/StorageMakerFactory.h"
00003 #include "Utilities/StorageFactory/interface/StorageFactory.h"
00004 #include "Utilities/XrdAdaptor/src/XrdFile.h"
00005 #include "XrdClient/XrdClientAdmin.hh"
00006 #include "XrdClient/XrdClientUrlSet.hh"
00007 #include "XrdClient/XrdClientEnv.hh"
00008 
00009 class XrdStorageMaker : public StorageMaker
00010 {
00011 public:
00014   virtual Storage *open (const std::string &proto,
00015                          const std::string &path,
00016                          int mode)
00017   {
00018     // The important part here is not the cache size (which will get
00019     // auto-adjusted), but the fact the cache is set to something non-zero.
00020     // If we don't do this before creating the XrdFile object, caching will be
00021     // completely disabled, resulting in poor performance.
00022     EnvPutInt(NAME_READCACHESIZE, 20*1024*1024);
00023 
00024     StorageFactory *f = StorageFactory::get();
00025     StorageFactory::ReadHint readHint = f->readHint();
00026     StorageFactory::CacheHint cacheHint = f->cacheHint();
00027 
00028     if (readHint != StorageFactory::READ_HINT_UNBUFFERED
00029         || cacheHint == StorageFactory::CACHE_HINT_STORAGE)
00030       mode &= ~IOFlags::OpenUnbuffered;
00031     else
00032       mode |=  IOFlags::OpenUnbuffered;
00033 
00034     std::string fullpath(proto + ":" + path);
00035     Storage *file = new XrdFile (fullpath, mode);
00036     return f->wrapNonLocalFile(file, proto, std::string(), mode);
00037   }
00038 
00039   virtual void stagein (const std::string &proto, const std::string &path)
00040   {
00041     std::string fullpath(proto + ":" + path);
00042     XrdClientAdmin admin(fullpath.c_str());
00043     if (admin.Connect())
00044     {
00045       XrdOucString str(fullpath.c_str());
00046       XrdClientUrlSet url(str);
00047       admin.Prepare(url.GetFile().c_str(), kXR_stage | kXR_noerrs, 0);
00048     }
00049   }
00050 
00051   virtual bool check (const std::string &proto,
00052                       const std::string &path,
00053                       IOOffset *size = 0)
00054   {
00055     std::string fullpath(proto + ":" + path);
00056     XrdClientAdmin admin(fullpath.c_str());
00057     if (! admin.Connect())
00058       return false; // FIXME: Throw?
00059 
00060     long      id;
00061     long      flags;
00062     long      modtime;
00063     long long xrdsize;
00064 
00065     XrdOucString str(fullpath.c_str());
00066     XrdClientUrlSet url(str);
00067 
00068     if (! admin.Stat(url.GetFile().c_str(), id, xrdsize, flags, modtime))
00069       return false; // FIXME: Throw?
00070 
00071     *size = xrdsize;
00072     return true;
00073   }
00074 
00075   virtual void setDebugLevel (unsigned int level)
00076   {
00077     EnvPutInt("DebugLevel", level);
00078   }
00079 };
00080 
00081 DEFINE_EDM_PLUGIN (StorageMakerFactory, XrdStorageMaker, "root");