18 #include "art/Framework/Core/EDAnalyzer.h" 
   19 #include "art/Framework/Core/ModuleMacros.h" 
   20 #include "messagefacility/MessageLogger/MessageLogger.h" 
   43     std::ostringstream sstr;
 
   44     sstr << '<' << ((void*)ptr) << '>
'; 
   75   class ServicePackTest : public art::EDAnalyzer {
 
   77     explicit ServicePackTest(fhicl::ParameterSet const&);
 
   81     void beginJob() override;
 
   85     analyze(const art::Event& /* evt */) override
 
   89     void endJob() override;
 
   95     void extractProviders_test_plain();
 
   98     void extractProviders_test_permuted();
 
  101     void extractProviders_test_reduced();
 
  104     void extractProviders_tests();
 
  108     std::vector<std::string> errors; ///< list of collected errors
 
  110   }; // ServicePackTest
 
  112   DEFINE_ART_MODULE(ServicePackTest)
 
  116 //------------------------------------------------------------------------------
 
  121   //----------------------------------------------------------------------------
 
  122   ServicePackTest::ServicePackTest(const fhicl::ParameterSet& pset) : EDAnalyzer(pset) {}
 
  124   //----------------------------------------------------------------------------
 
  126   ServicePackTest::beginJob()
 
  128     extractProviders_tests();
 
  129   } // ServicePackTest::beginJob()
 
  131   //----------------------------------------------------------------------------
 
  133   ServicePackTest::endJob()
 
  135     if (errors.empty()) {
 
  136       mf::LogInfo("ServicePackTest") << "All tests were successful.";
 
  140     mf::LogError log("ServicePackTest");
 
  141     log << errors.size() << " errors detected:";
 
  143     for (std::string const& error : errors)
 
  144       log << "\n - " << error;
 
  146     throw art::Exception(art::errors::LogicError) << errors.size() << " errors detected";
 
  149   //----------------------------------------------------------------------------
 
  151   ServicePackTest::extractProviders_tests()
 
  153     extractProviders_test_plain();
 
  154     extractProviders_test_permuted();
 
  155     extractProviders_test_reduced();
 
  158   //----------------------------------------------------------------------------
 
  160   ServicePackTest::extractProviders_test_plain()
 
  163      * The test creates a ProviderPack and checks that its element as as
 
  166      * The expected value is extracted from the framework in the "traditional"
 
  170     // these are the "solutions":
 
  171     geo::GeometryCore const* geom = lar::providerFrom<geo::Geometry>();
 
  172     detinfo::LArProperties const* larprop = lar::providerFrom<detinfo::LArPropertiesService>();
 
  174     auto providers = lar::extractProviders<geo::Geometry, detinfo::LArPropertiesService>();
 
  177     if (providers.get<geo::GeometryCore>() != geom) {
 
  178       errors.push_back("wrong geometry provider (got " +
 
  179                        ::to_string(providers.get<geo::GeometryCore>()) + ", expected " +
 
  180                        ::to_string(geom) + ")");
 
  182     if (providers.get<detinfo::LArProperties>() != larprop) {
 
  183       errors.push_back("wrong LAr properties provider (got " +
 
  184                        ::to_string(providers.get<detinfo::LArProperties>()) + ", expected " +
 
  185                        ::to_string(larprop) + ")");
 
  187   } // ServicePackTest::extractProviders_test_plain()
 
  189   //----------------------------------------------------------------------------
 
  191   ServicePackTest::extractProviders_test_permuted()
 
  194      * The test creates a ProviderPack and checks that its element as as
 
  197      * The expected value is extracted from the framework in the "traditional"
 
  200      * The order of the providers is different from the order of the services;
 
  201      * in this way a "wrong" ProviderPack will be (deliberately) created,
 
  202      * and the code will have to convert it to the right pack.
 
  205     // these are the "solutions":
 
  206     geo::GeometryCore const* geom = lar::providerFrom<geo::Geometry>();
 
  207     detinfo::LArProperties const* larprop = lar::providerFrom<detinfo::LArPropertiesService>();
 
  209     auto providers = lar::extractProviders<geo::Geometry, detinfo::LArPropertiesService>();
 
  212     if (providers.get<geo::GeometryCore>() != geom) {
 
  213       errors.push_back("wrong geometry provider (got " +
 
  214                        ::to_string(providers.get<geo::GeometryCore>()) + ", expected " +
 
  215                        ::to_string(geom) + ") [permuted]");
 
  217     if (providers.get<detinfo::LArProperties>() != larprop) {
 
  218       errors.push_back("wrong LAr properties provider (got " +
 
  219                        ::to_string(providers.get<detinfo::LArProperties>()) + ", expected " +
 
  220                        ::to_string(larprop) + ") [permuted]");
 
  224   //----------------------------------------------------------------------------
 
  226   ServicePackTest::extractProviders_test_reduced()
 
  229      * The test creates a ProviderPack and checks that its element as as
 
  232      * The expected value is extracted from the framework in the "traditional"
 
  235      * We use a smaller provider pack to store the providers;
 
  236      * DetectorProperties will be dropped.
 
  239     // these are the "solutions":
 
  240     geo::GeometryCore const* geom = lar::providerFrom<geo::Geometry>();
 
  241     detinfo::LArProperties const* larprop = lar::providerFrom<detinfo::LArPropertiesService>();
 
  242     auto providers = lar::extractProviders<geo::Geometry, detinfo::LArPropertiesService>();
 
  245     if (providers.get<geo::GeometryCore>() != geom) {
 
  246       errors.push_back("wrong geometry provider (got " +
 
  247                        ::to_string(providers.get<geo::GeometryCore>()) + ", expected " +
 
  248                        ::to_string(geom) + ") [reduced]");
 
  250     if (providers.get<detinfo::LArProperties>() != larprop) {
 
  251       errors.push_back("wrong LAr properties provider (got " +
 
  252                        ::to_string(providers.get<detinfo::LArProperties>()) + ", expected " +
 
  253                        ::to_string(larprop) + ") [reduced]");
 
Utilities to manage ProviderPack objects with art. 
Utilities related to art service access. 
Access the description of detector geometry. 
std::string to_string(WindowPattern const &pattern)
art framework interface to geometry description