Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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       const StorageFactory *f = StorageFactory::get();
0019       std::string newurl((proto == "web" ? "http" : proto) + ":" + path);
0020       auto file = std::make_unique<DavixFile>(newurl, mode);
0021       return f->wrapNonLocalFile(std::move(file), proto, std::string(), mode);
0022     }
0023 
0024     bool check(const std::string &proto,
0025                const std::string &path,
0026                const AuxSettings &aux,
0027                IOOffset *size = nullptr) const override {
0028       std::string newurl((proto == "web" ? "http" : proto) + ":" + path);
0029       Davix::DavixError *err = nullptr;
0030       Davix::Context c;
0031       Davix::DavPosix davixPosix(&c);
0032       Davix::StatInfo info;
0033       davixPosix.stat64(nullptr, newurl, &info, &err);
0034       if (err) {
0035         std::unique_ptr<Davix::DavixError> davixErrManaged(err);
0036         cms::Exception ex("FileCheckError");
0037         ex << "Check failed with error " << err->getErrMsg().c_str() << " and error code" << err->getStatus();
0038         ex.addContext("Calling DavixFile::check()");
0039         throw ex;
0040       }
0041       if (size) {
0042         *size = info.size;
0043       }
0044       return true;
0045     }
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");