Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-05-19 07:20:22

0001 #ifndef STORAGE_FACTORY_STORAGE_FACTORY_H
0002 #define STORAGE_FACTORY_STORAGE_FACTORY_H
0003 
0004 #include "Utilities/StorageFactory/interface/StorageMaker.h"
0005 #include "Utilities/StorageFactory/interface/LocalFileSystem.h"
0006 #include "Utilities/StorageFactory/interface/IOTypes.h"
0007 #include "Utilities/StorageFactory/interface/IOFlags.h"
0008 
0009 #include <memory>
0010 #include <string>
0011 #include <tuple>
0012 
0013 #include "oneapi/tbb/concurrent_unordered_map.h"
0014 
0015 namespace edm::storage {
0016   class Storage;
0017   class StorageProxyMaker;
0018   class StorageFactory {
0019   public:
0020     enum CacheHint { CACHE_HINT_APPLICATION, CACHE_HINT_STORAGE, CACHE_HINT_LAZY_DOWNLOAD, CACHE_HINT_AUTO_DETECT };
0021 
0022     enum ReadHint { READ_HINT_UNBUFFERED, READ_HINT_READAHEAD, READ_HINT_AUTO };
0023 
0024     static const StorageFactory *get(void);
0025     static StorageFactory *getToModify(void);
0026 
0027     // in GB
0028     static double defaultMinTempFree() { return 4.; }
0029     static std::string defaultTempDir();
0030 
0031     ~StorageFactory(void);
0032 
0033     // implicit copy constructor
0034     // implicit assignment operator
0035 
0036     void setCacheHint(CacheHint value);
0037     CacheHint cacheHint(void) const;
0038 
0039     void setReadHint(ReadHint value);
0040     ReadHint readHint(void) const;
0041 
0042     bool enableAccounting(bool enabled);
0043     bool accounting(void) const;
0044 
0045     void setTimeout(unsigned int timeout);
0046     unsigned int timeout(void) const;
0047 
0048     void setDebugLevel(unsigned int level);
0049     unsigned int debugLevel(void) const;
0050 
0051     void setTempDir(const std::string &s, double minFreeSpace);
0052     std::string tempDir(void) const;
0053     std::string tempPath(void) const;
0054     double tempMinFree(void) const;
0055 
0056     void setStorageProxyMakers(std::vector<std::unique_ptr<StorageProxyMaker>> makers);
0057 
0058     void stagein(const std::string &url) const;
0059     std::unique_ptr<Storage> open(const std::string &url, const int mode = IOFlags::OpenRead) const;
0060     bool check(const std::string &url, IOOffset *size = nullptr) const;
0061 
0062   private:
0063     typedef oneapi::tbb::concurrent_unordered_map<std::string, std::shared_ptr<StorageMaker>> MakerTable;
0064 
0065     StorageFactory(void);
0066     StorageMaker *getMaker(const std::string &proto) const;
0067     StorageMaker *getMaker(const std::string &url, std::string &protocol, std::string &rest) const;
0068 
0069     // Returns
0070     // - Storage 's' possibly wrapped in LocalCacheFile
0071     // - bool telling if LocalCacheFile is used
0072     std::tuple<std::unique_ptr<Storage>, bool> wrapNonLocalFile(std::unique_ptr<Storage> s,
0073                                                                 const std::string &proto,
0074                                                                 const std::string &path,
0075                                                                 const int mode) const;
0076 
0077     mutable MakerTable m_makers;
0078     CacheHint m_cacheHint;
0079     ReadHint m_readHint;
0080     bool m_accounting;
0081     double m_tempfree;
0082     std::string m_temppath;
0083     std::string m_tempdir;
0084     std::string m_unusableDirWarnings;
0085     unsigned int m_timeout;
0086     unsigned int m_debugLevel;
0087     LocalFileSystem m_lfs;
0088     std::vector<std::unique_ptr<StorageProxyMaker>> m_storageProxyMakers_;
0089     static StorageFactory s_instance;
0090   };
0091 }  // namespace edm::storage
0092 #endif  // STORAGE_FACTORY_STORAGE_FACTORY_H