CMS 3D CMS Logo

LocalStorageMaker.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/StorageFactory/interface/File.h"
00005 #include <unistd.h>
00006 #include <sys/stat.h>
00007 
00008 class LocalStorageMaker : public StorageMaker
00009 {
00010 public:
00011   virtual Storage *open (const std::string &proto,
00012                          const std::string &path,
00013                          int mode,
00014                          const std::string &tmpdir)
00015   {
00016     StorageFactory *f = StorageFactory::get();
00017     StorageFactory::ReadHint readHint = f->readHint();
00018     StorageFactory::CacheHint cacheHint = f->cacheHint();
00019 
00020     if (readHint != StorageFactory::READ_HINT_UNBUFFERED
00021         || cacheHint == StorageFactory::CACHE_HINT_STORAGE)
00022       mode &= ~IOFlags::OpenUnbuffered;
00023     else
00024       mode |= IOFlags::OpenUnbuffered;
00025 
00026     return new File (path, mode); 
00027   }
00028 
00029   virtual bool check (const std::string &proto,
00030                       const std::string &path,
00031                       IOOffset *size = 0)
00032   {
00033     struct stat st;
00034     if (stat (path.c_str(), &st) != 0)
00035       return false;
00036 
00037     if (size)
00038       *size = st.st_size;
00039 
00040     return true;
00041   }
00042 };
00043 
00044 DEFINE_EDM_PLUGIN (StorageMakerFactory, LocalStorageMaker, "file");

Generated on Tue Jun 9 17:48:53 2009 for CMSSW by  doxygen 1.5.4