CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/Utilities/StorageFactory/plugins/LocalStorageMaker.cc

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