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/DCacheAdaptor/interface/DCacheFile.h"
00005 #include "FWCore/Utilities/interface/Exception.h"
00006 #include <unistd.h>
00007 #include <dcap.h>
00008
00009 class DCacheStorageMaker : public StorageMaker
00010 {
00015 static std::string normalise (const std::string &proto, const std::string &path)
00016 {
00017 size_t p = path.find("/pnfs");
00018 if (p < 3)
00019 return (proto == "gsidcap") ? proto + ':' + path.substr(p) : path.substr(p);
00020
00021
00022 p = path.find_first_not_of('/');
00023
00024
00025 return proto + "://" + path.substr(p);
00026 }
00027
00028 public:
00029
00032 virtual Storage *open (const std::string &proto,
00033 const std::string &path,
00034 int mode)
00035 {
00036 StorageFactory *f = StorageFactory::get();
00037 StorageFactory::ReadHint readHint = f->readHint();
00038 StorageFactory::CacheHint cacheHint = f->cacheHint();
00039
00040 if (readHint != StorageFactory::READ_HINT_UNBUFFERED
00041 || cacheHint == StorageFactory::CACHE_HINT_STORAGE)
00042 mode &= ~IOFlags::OpenUnbuffered;
00043 else
00044 mode |= IOFlags::OpenUnbuffered;
00045
00046 Storage *file = new DCacheFile(normalise(proto, path), mode);
00047 return f->wrapNonLocalFile(file, proto, std::string(), mode);
00048 }
00049
00050 virtual void stagein (const std::string &proto,
00051 const std::string &path)
00052 {
00053 std::string npath = normalise(proto, path);
00054 if (dc_stage(npath.c_str(), 0, 0) != 0)
00055 throw cms::Exception("DCacheStorageMaker::stagein()")
00056 << "Cannot stage in file '" << npath
00057 << "', error was: " << dc_strerror(dc_errno)
00058 << " (dc_errno=" << dc_errno << ")";
00059 }
00060
00061 virtual bool check (const std::string &proto,
00062 const std::string &path,
00063 IOOffset *size = 0)
00064 {
00065 std::string testpath (normalise (proto, path));
00066 if (dc_access (testpath.c_str (), R_OK) != 0)
00067 return false;
00068
00069 if (size)
00070 {
00071 struct stat64 buf;
00072 if (dc_stat64 (testpath.c_str (), &buf) != 0)
00073 return false;
00074
00075 *size = buf.st_size;
00076 }
00077
00078 return true;
00079 }
00080
00081 virtual void setTimeout(unsigned int timeout) {
00082 if (timeout != 0) dc_setOpenTimeout(timeout);
00083 }
00084 };
00085
00086 DEFINE_EDM_PLUGIN (StorageMakerFactory, DCacheStorageMaker, "dcache");
00087 DEFINE_EDM_PLUGIN (StorageMakerFactory, DCacheStorageMaker, "dcap");
00088 DEFINE_EDM_PLUGIN (StorageMakerFactory, DCacheStorageMaker, "gsidcap");