Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Utilities/interface/Exception.h"
0002 #include "Utilities/DavixAdaptor/interface/DavixFile.h"
0003 #include "Utilities/StorageFactory/interface/StorageFactory.h"
0004 #include "Utilities/StorageFactory/interface/StorageMaker.h"
0005 #include "Utilities/StorageFactory/interface/StorageMakerFactory.h"
0006 #include <davix.hpp>
0007 #include <unistd.h>
0008 
0009 namespace edm::storage {
0010   class DavixStorageMaker : public StorageMaker {
0011   public:
0012     /** Open a storage object for the given URL (protocol + path), using the
0013       @a mode bits.  No temporary files are downloaded.  */
0014     std::unique_ptr<Storage> open(const std::string &proto,
0015                                   const std::string &path,
0016                                   int mode,
0017                                   AuxSettings const &aux) const override {
0018       std::string newurl((proto == "web" ? "http" : proto) + ":" + path);
0019       return std::make_unique<DavixFile>(newurl, mode);
0020     }
0021 
0022     bool check(const std::string &proto,
0023                const std::string &path,
0024                const AuxSettings &aux,
0025                IOOffset *size = nullptr) const override {
0026       std::string newurl((proto == "web" ? "http" : proto) + ":" + path);
0027       Davix::DavixError *err = nullptr;
0028       Davix::Context c;
0029       Davix::DavPosix davixPosix(&c);
0030       Davix::StatInfo info;
0031       davixPosix.stat64(nullptr, newurl, &info, &err);
0032       if (err) {
0033         std::unique_ptr<Davix::DavixError> davixErrManaged(err);
0034         cms::Exception ex("FileCheckError");
0035         ex << "Check failed with error " << err->getErrMsg().c_str() << " and error code" << err->getStatus();
0036         ex.addContext("Calling DavixFile::check()");
0037         throw ex;
0038       }
0039       if (size) {
0040         *size = info.size;
0041       }
0042       return true;
0043     }
0044 
0045     UseLocalFile usesLocalFile() const override { return UseLocalFile::kNo; }
0046   };
0047 }  // namespace edm::storage
0048 
0049 using namespace edm::storage;
0050 DEFINE_EDM_PLUGIN(StorageMakerFactory, DavixStorageMaker, "http");
0051 DEFINE_EDM_PLUGIN(StorageMakerFactory, DavixStorageMaker, "https");
0052 DEFINE_EDM_PLUGIN(StorageMakerFactory, DavixStorageMaker, "web");