Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-08 02:27:21

0001 // -*- C++ -*-
0002 //
0003 // Package:     Services
0004 // Class  :     SiteLocalConfigServiceTester
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Apr 20 16:51:38 CDT 2010
0011 //
0012 
0013 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/ServiceRegistry/interface/Service.h"
0016 #include "FWCore/Catalog/interface/SiteLocalConfig.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "FWCore/Utilities/interface/Exception.h"
0019 
0020 #include <string>
0021 
0022 namespace edmtest {
0023   class SiteLocalConfigServiceTester : public edm::global::EDAnalyzer<> {
0024   public:
0025     SiteLocalConfigServiceTester(const edm::ParameterSet& iPSet);
0026 
0027     void analyze(edm::StreamID, const edm::Event&, const edm::EventSetup&) const override;
0028 
0029   private:
0030     std::string m_cacheHint;
0031     std::string m_readHint;
0032     std::string m_tempDir;
0033     unsigned int m_ttreeCacheSize;
0034     std::vector<std::string> m_nativeProtocols;
0035     bool m_valuesSet;
0036     bool m_expectedUseLocalConnectString;
0037     std::string m_expectedLocalConnectPrefix;
0038     std::string m_expectedLocalConnectSuffix;
0039   };
0040 }  // namespace edmtest
0041 
0042 using namespace edmtest;
0043 
0044 SiteLocalConfigServiceTester::SiteLocalConfigServiceTester(const edm::ParameterSet& iPSet)
0045     : m_cacheHint(iPSet.getUntrackedParameter<std::string>("sourceCacheHint")),
0046       m_readHint(iPSet.getUntrackedParameter<std::string>("sourceReadHint")),
0047       m_tempDir(iPSet.getUntrackedParameter<std::string>("sourceTempDir")),
0048       m_ttreeCacheSize(iPSet.getUntrackedParameter<unsigned int>("sourceTTreeCacheSize")),
0049       m_nativeProtocols(iPSet.getUntrackedParameter<std::vector<std::string> >("sourceNativeProtocols")),
0050       m_valuesSet(iPSet.getUntrackedParameter<bool>("sourceValuesSet", true)),
0051       m_expectedUseLocalConnectString(iPSet.getUntrackedParameter<bool>("expectedUseLocalConnectString")),
0052       m_expectedLocalConnectPrefix(iPSet.getUntrackedParameter<std::string>("expectedLocalConnectPrefix")),
0053       m_expectedLocalConnectSuffix(iPSet.getUntrackedParameter<std::string>("expectedLocalConnectSuffix")) {}
0054 
0055 static void throwNotSet(const char* iName) {
0056   throw cms::Exception("TestFailure") << "The value " << iName << " should have been set but was not";
0057 }
0058 
0059 template <typename T>
0060 static void throwWrongValue(const char* iName, const T& iExpected, const T& iRetrieved) {
0061   throw cms::Exception("TestFailure") << "The value " << iName << " should have been " << iExpected
0062                                       << " but instead was " << iRetrieved;
0063 }
0064 
0065 namespace {
0066   template <typename T>
0067   void testValue(const char* iName, const T& iExpected, const T* iRetrieved) {
0068     if (nullptr == iRetrieved) {
0069       throwNotSet(iName);
0070     } else if (*iRetrieved != iExpected) {
0071       throwWrongValue(iName, iExpected, *iRetrieved);
0072     }
0073   }
0074 
0075   template <typename T>
0076   void checkNotSet(const char* iName, const T* iRetrieved) {
0077     if (nullptr != iRetrieved) {
0078       throw cms::Exception("TestFailure")
0079           << "The value " << iName << " should not have been set but was set to " << *iRetrieved;
0080     }
0081   }
0082 
0083   void checkNotSet(const char* iName, const std::vector<std::string>* iRetrieved) {
0084     if (nullptr != iRetrieved) {
0085       throw cms::Exception("TestFailure") << "The value " << iName << " should not have been set but was set";
0086     }
0087   }
0088 
0089 }  // namespace
0090 
0091 void SiteLocalConfigServiceTester::analyze(edm::StreamID, const edm::Event&, const edm::EventSetup&) const {
0092   edm::Service<edm::SiteLocalConfig> pConfig;
0093   if (m_valuesSet) {
0094     testValue("sourceCacheTempDir", m_tempDir, pConfig->sourceCacheTempDir());
0095     testValue("sourceCacheHint", m_cacheHint, pConfig->sourceCacheHint());
0096     testValue("sourceReadHint", m_readHint, pConfig->sourceReadHint());
0097     testValue("sourceTTreeCacheSize", m_ttreeCacheSize, pConfig->sourceTTreeCacheSize());
0098     const std::vector<std::string>* protocols = pConfig->sourceNativeProtocols();
0099     if (nullptr == protocols) {
0100       throwNotSet("sourceNativeProtocols");
0101     }
0102     if (protocols->size() != m_nativeProtocols.size()) {
0103       throw cms::Exception("TestFailure") << "The value sourceNativeProtocols has size " << protocols->size()
0104                                           << " but should have had size " << m_nativeProtocols.size();
0105     }
0106     for (std::vector<std::string>::const_iterator it = protocols->begin(),
0107                                                   itEnd = protocols->end(),
0108                                                   itExpect = m_nativeProtocols.begin();
0109          it != itEnd;
0110          ++it, ++itExpect) {
0111       testValue("sourceNativeProtocols", *itExpect, &(*it));
0112     }
0113   } else {
0114     checkNotSet("sourceCacheTempDir", pConfig->sourceCacheTempDir());
0115     checkNotSet("sourceCacheHint", pConfig->sourceCacheHint());
0116     checkNotSet("sourceReadHint", pConfig->sourceReadHint());
0117     checkNotSet("sourceTTreeCacheSize", pConfig->sourceTTreeCacheSize());
0118     checkNotSet("sourceNativeProtocols", pConfig->sourceNativeProtocols());
0119   }
0120 
0121   if (pConfig->useLocalConnectString() != m_expectedUseLocalConnectString) {
0122     throw cms::Exception("TestFailure") << "The value of useLocalConnectString is \""
0123                                         << (pConfig->useLocalConnectString() ? std::string("true")
0124                                                                              : std::string("false"))
0125                                         << "\" but we expected the value \""
0126                                         << (m_expectedUseLocalConnectString ? std::string("true")
0127                                                                             : std::string("false"))
0128                                         << "\"";
0129   }
0130   if (pConfig->localConnectPrefix() != m_expectedLocalConnectPrefix) {
0131     throw cms::Exception("TestFailure") << "The value of localConnectPrefix is \"" << pConfig->localConnectPrefix()
0132                                         << "\" but we expected the value \"" << m_expectedLocalConnectPrefix << "\"";
0133   }
0134   if (pConfig->localConnectSuffix() != m_expectedLocalConnectSuffix) {
0135     throw cms::Exception("TestFailure") << "The value of localConnectSuffix is \"" << pConfig->localConnectSuffix()
0136                                         << "\" but we expected the value \"" << m_expectedLocalConnectSuffix << "\"";
0137   }
0138 }
0139 
0140 DEFINE_FWK_MODULE(SiteLocalConfigServiceTester);