Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-01 22:41:11

0001 #ifndef STORAGE_FACTORY_LOCAL_CACHE_FILE_H
0002 #define STORAGE_FACTORY_LOCAL_CACHE_FILE_H
0003 
0004 #include "Utilities/StorageFactory/interface/Storage.h"
0005 #include "Utilities/StorageFactory/interface/File.h"
0006 #include "FWCore/Utilities/interface/propagate_const.h"
0007 #include <vector>
0008 #include <string>
0009 #include <memory>
0010 
0011 namespace edm::storage {
0012   /** Proxy class to copy a file locally in large chunks. */
0013   class LocalCacheFile : public Storage {
0014   public:
0015     LocalCacheFile(std::unique_ptr<Storage> base, const std::string &tmpdir = "");
0016     ~LocalCacheFile(void) override;
0017 
0018     using Storage::read;
0019     using Storage::write;
0020 
0021     bool prefetch(const IOPosBuffer *what, IOSize n) override;
0022     IOSize read(void *into, IOSize n) override;
0023     IOSize read(void *into, IOSize n, IOOffset pos) override;
0024     IOSize readv(IOBuffer *into, IOSize n) override;
0025     IOSize readv(IOPosBuffer *into, IOSize n) override;
0026     IOSize write(const void *from, IOSize n) override;
0027     IOSize write(const void *from, IOSize n, IOOffset pos) override;
0028     IOSize writev(const IOBuffer *from, IOSize n) override;
0029     IOSize writev(const IOPosBuffer *from, IOSize n) override;
0030 
0031     IOOffset position(IOOffset offset, Relative whence = SET) override;
0032     void resize(IOOffset size) override;
0033     void flush(void) override;
0034     void close(void) override;
0035 
0036   private:
0037     void cache(IOOffset start, IOOffset end);
0038 
0039     IOOffset image_;
0040     std::vector<char> present_;
0041     edm::propagate_const<std::unique_ptr<File>> file_;
0042     edm::propagate_const<std::unique_ptr<Storage>> storage_;
0043     bool closedFile_;
0044     unsigned int cacheCount_;
0045     unsigned int cacheTotal_;
0046   };
0047 }  // namespace edm::storage
0048 #endif  // STORAGE_FACTORY_LOCAL_CACHE_FILE_H