Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-09 04:49:56

0001 #include "FWCore/Catalog/interface/FileLocator.h"
0002 #include "FWCore/Catalog/interface/SiteLocalConfig.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 #include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
0005 #include <filesystem>
0006 
0007 #include <string>
0008 
0009 #define CATCH_CONFIG_MAIN
0010 #include "catch.hpp"
0011 
0012 namespace {
0013   class TestSiteLocalConfig : public edm::SiteLocalConfig {
0014   public:
0015     TestSiteLocalConfig(std::vector<std::string> catalogs) : m_catalogs(std::move(catalogs)) {}
0016     std::vector<std::string> const& dataCatalogs(void) const final { return m_catalogs; }
0017     std::string const lookupCalibConnect(std::string const& input) const final { return std::string(); }
0018     std::string const rfioType(void) const final { return std::string(); }
0019 
0020     std::string const* sourceCacheTempDir() const final { return nullptr; }
0021     double const* sourceCacheMinFree() const final { return nullptr; }
0022     std::string const* sourceCacheHint() const final { return nullptr; }
0023     std::string const* sourceCloneCacheHint() const final { return nullptr; }
0024     std::string const* sourceReadHint() const final { return nullptr; }
0025     unsigned int const* sourceTTreeCacheSize() const final { return nullptr; }
0026     unsigned int const* sourceTimeout() const final { return nullptr; }
0027     bool enablePrefetching() const final { return false; }
0028     unsigned int debugLevel() const final { return 0; }
0029     std::vector<std::string> const* sourceNativeProtocols() const final { return nullptr; }
0030     struct addrinfo const* statisticsDestination() const final {
0031       return nullptr;
0032     }
0033     std::set<std::string> const* statisticsInfo() const final { return nullptr; }
0034     std::string const& siteName(void) const final { return m_emptyString; }
0035     bool useLocalConnectString() const final { return false; }
0036     std::string const& localConnectPrefix() const final { return m_emptyString; }
0037     std::string const& localConnectSuffix() const final { return m_emptyString; }
0038 
0039   private:
0040     std::vector<std::string> m_catalogs;
0041     std::string m_emptyString;
0042   };
0043 }  // namespace
0044 
0045 TEST_CASE("FileLocator", "[filelocator]") {
0046   std::string CMSSW_BASE(std::getenv("CMSSW_BASE"));
0047   std::string CMSSW_RELEASE_BASE(std::getenv("CMSSW_RELEASE_BASE"));
0048   std::string file_name("/src/FWCore/Catalog/test/simple_catalog.xml");
0049   std::string full_file_name = std::filesystem::exists((CMSSW_BASE + file_name).c_str())
0050                                    ? CMSSW_BASE + file_name
0051                                    : CMSSW_RELEASE_BASE + file_name;
0052 
0053   //create the services
0054   std::vector<std::string> tmp{std::string("trivialcatalog_file:") + full_file_name + "?protocol=xrd"};
0055   edm::ServiceToken tempToken(
0056       edm::ServiceRegistry::createContaining(std::unique_ptr<edm::SiteLocalConfig>(new TestSiteLocalConfig(tmp))));
0057 
0058   //make the services available
0059   SECTION("standard") {
0060     edm::ServiceRegistry::Operate operate(tempToken);
0061     edm::FileLocator fl("", 0);
0062 
0063     const std::array<const char*, 7> lfn = {{"/bha/bho",
0064                                              "bha",
0065                                              "file:bha",
0066                                              "file:/bha/bho",
0067                                              "/castor/cern.ch/cms/bha/bho",
0068                                              "rfio:/castor/cern.ch/cms/bha/bho",
0069                                              "rfio:/bha/bho"}};
0070 
0071     CHECK("/storage/path/store/group/bha/bho" == fl.pfn("/store/group/bha/bho"));
0072     for (auto file : lfn) {
0073       CHECK("" == fl.pfn(file));
0074     }
0075 
0076     CHECK(fl.lfn("/storage/path/store/group/bha/bho") == "/store/group/bha/bho");
0077     CHECK(fl.lfn("/store/group/bha/bho") == "");
0078     for (auto file : lfn) {
0079       CHECK("" == fl.lfn(file));
0080     }
0081   }
0082 
0083   SECTION("override") {
0084     edm::ServiceRegistry::Operate operate(tempToken);
0085 
0086     std::string override_file_name("/src/FWCore/Catalog/test/override_catalog.xml");
0087     std::string override_full_file_name = std::filesystem::exists((CMSSW_BASE + override_file_name).c_str())
0088                                               ? CMSSW_BASE + override_file_name
0089                                               : CMSSW_RELEASE_BASE + override_file_name;
0090 
0091     edm::FileLocator fl(("trivialcatalog_file:" + override_full_file_name + "?protocol=override").c_str());
0092 
0093     std::array<const char*, 8> lfn = {{"/store/group/bha/bho",
0094                                        "/bha/bho",
0095                                        "bha",
0096                                        "file:bha",
0097                                        "file:/bha/bho",
0098                                        "/castor/cern.ch/cms/bha/bho",
0099                                        "rfio:/castor/cern.ch/cms/bha/bho",
0100                                        "rfio:/bha/bho"}};
0101 
0102     auto const overriden_file =
0103         "/store/unmerged/relval/CMSSW_3_8_0_pre3/RelValZTT/GEN-SIM-DIGI-RAW-HLTDEBUG/START38_V2-v1/0666/"
0104         "80EC0BCD-D279-DF11-B1DB-0030487C90EE.root";
0105 
0106     CHECK("/FULL_PATH_TO_THE_FIRST_STEP_ROOT_FILE/80EC0BCD-D279-DF11-B1DB-0030487C90EE.root" == fl.pfn(overriden_file));
0107 
0108     for (auto f : lfn) {
0109       CHECK("" == fl.pfn(f));
0110     }
0111     for (auto f : lfn) {
0112       CHECK("" == fl.lfn(f));
0113     }
0114   }
0115 }