Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:09:25

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2018 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 ///  Boost include(s)
0010 #define BOOST_TEST_MODULE AbortList Tests
0011 
0012 #include <boost/test/included/unit_test.hpp>
0013 // leave blank line
0014 
0015 #include <boost/test/data/test_case.hpp>
0016 // leave blank line
0017 
0018 #include <boost/test/output_test_stream.hpp>
0019 // leave blank line
0020 
0021 #include "Fatras/Kernel/SelectorList.hpp"
0022 
0023 namespace bdata = boost::unit_test::data;
0024 namespace tt = boost::test_tools;
0025 
0026 namespace Fatras {
0027 
0028 namespace Test {
0029 
0030 /// needed are : object, environment
0031 struct Object {
0032   int feature = 0;
0033   std::string name = "";
0034 };
0035 
0036 struct Environment {
0037   int pickFeature = 1;
0038 };
0039 
0040 /// Selector that selectos on the Feature
0041 /// Only acts on the object
0042 struct FeatureSelector {
0043 
0044   int select_on = 0;
0045 
0046   /// call operator
0047   template <typename detector_t, typename particle_t>
0048   bool operator()(const detector_t &, const particle_t &object) const {
0049     return object.feature == select_on;
0050   }
0051 };
0052 
0053 /// Selector that selectos on the Name
0054 /// Only acts on the object
0055 struct NameSelector {
0056 
0057   std::string select_on = "";
0058 
0059   /// call operator
0060   template <typename detector_t, typename particle_t>
0061   bool operator()(const detector_t &environment,
0062                   const particle_t &object) const {
0063     return object.name == select_on;
0064   }
0065 };
0066 
0067 /// Selector that selectos on the Feature
0068 /// given an environment
0069 struct EnvironmentSelector {
0070 
0071   /// call operator
0072   template <typename detector_t, typename particle_t>
0073   bool operator()(const detector_t &environmet,
0074                   const particle_t &object) const {
0075     return object.feature == environmet.pickFeature;
0076   }
0077 };
0078 
0079 // This tests the implementation of the selector list
0080 BOOST_AUTO_TEST_CASE(SelectorList_test) {
0081 
0082   // An object with name and features
0083   Object o1;
0084   o1.name = "o";
0085   o1.feature = 1;
0086 
0087   Environment en1;
0088   en1.pickFeature = 1;
0089 
0090   // Selector that trifers on the feature
0091   FeatureSelector selector1;
0092   selector1.select_on = 1;
0093   // the wrong feature value
0094   FeatureSelector selector2;
0095   selector2.select_on = 2;
0096 
0097   // test that the feature value 1 is selected
0098   BOOST_TEST(selector1(en1, o1));
0099   // test that the feature value 2 is selected
0100   BOOST_TEST(!selector2(en1, o1));
0101 
0102   // Let's test this with the selector list
0103   SelectorListAND<FeatureSelector> selectorList11;
0104   auto &sl11 = selectorList11.template get<FeatureSelector>();
0105   sl11.select_on = 1;
0106 
0107   SelectorListAND<FeatureSelector> selectorList12;
0108   auto &sl12 = selectorList12.template get<FeatureSelector>();
0109   sl12.select_on = 2;
0110 
0111   // test that the feature value 1 is selected
0112   BOOST_TEST(selectorList11(en1, o1));
0113   // test that the feature value 2 is selected
0114   BOOST_TEST(!selectorList12(en1, o1));
0115 
0116   // make a combined selector lsit
0117   SelectorListAND<FeatureSelector, NameSelector> o1List;
0118   auto &s1 = o1List.get<FeatureSelector>();
0119   s1.select_on = 1;
0120   auto &so = o1List.get<NameSelector>();
0121   so.select_on = "o";
0122 
0123   // test that the feature value 1 is selected
0124   BOOST_TEST(o1List(en1, o1));
0125 
0126   // make a combined selector lsit
0127   SelectorListAND<FeatureSelector, NameSelector> o2List;
0128   auto &s2 = o2List.template get<FeatureSelector>();
0129   s2.select_on = 2;
0130   so = o2List.template get<NameSelector>();
0131   so.select_on = "o";
0132 
0133   // test that the feature value 1 is selected
0134   BOOST_TEST(!o2List(en1, o1));
0135 
0136   // Pick ont he environment
0137   EnvironmentSelector eselector1;
0138   BOOST_TEST(eselector1(en1, o1));
0139 }
0140 
0141 } // namespace Test
0142 } // namespace Fatras