Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:59

0001 #include <cppunit/extensions/HelperMacros.h>
0002 #include <algorithm>
0003 #include <memory>
0004 #include <string>
0005 #include <utility>
0006 #include <vector>
0007 #include "Math/RotationX.h"
0008 
0009 #include "DetectorDescription/Core/interface/DDCompactView.h"
0010 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0011 #include "DetectorDescription/Core/interface/DDMaterial.h"
0012 #include "DetectorDescription/Core/interface/DDName.h"
0013 #include "DetectorDescription/Core/interface/DDSolid.h"
0014 #include "DetectorDescription/Core/interface/DDSpecifics.h"
0015 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0016 #include "DetectorDescription/Core/interface/DDFilter.h"
0017 
0018 #include "cppunit/TestAssert.h"
0019 #include "cppunit/TestFixture.h"
0020 
0021 class testDDFilter : public CppUnit::TestFixture {
0022   CPPUNIT_TEST_SUITE(testDDFilter);
0023   CPPUNIT_TEST(checkFilters);
0024   CPPUNIT_TEST_SUITE_END();
0025 
0026 public:
0027   void setUp() override {}
0028   void tearDown() override {}
0029   void checkFilters();
0030 };
0031 
0032 CPPUNIT_TEST_SUITE_REGISTRATION(testDDFilter);
0033 
0034 namespace {
0035   std::vector<std::string> getNames(DDFilteredView& fv) {
0036     std::vector<std::string> returnValue;
0037     bool dodet = fv.firstChild();
0038     while (dodet) {
0039       auto const& lp = fv.logicalPart();
0040       returnValue.emplace_back(lp.name().name());
0041       dodet = fv.next();
0042     }
0043     return returnValue;
0044   }
0045 }  // namespace
0046 
0047 void testDDFilter::checkFilters() {
0048   //Create the geometry
0049   DDCompactView cv{};
0050   {
0051     double const kPI = std::acos(-1.);
0052 
0053     auto const& root = cv.root();
0054 
0055     DDMaterial mat{"Stuff"};
0056     {
0057       //Central
0058       auto outershape = DDSolidFactory::tubs("OuterShape", 1., 0.5, 1., 0., 2 * kPI);
0059 
0060       DDLogicalPart outerlp{"Outer", mat, outershape};
0061 
0062       cv.position(outerlp, root, 0, DDTranslation{}, DDRotation{});
0063       {
0064         DDValue val{"Volume", "Outer", 0};
0065         DDsvalues_type values;
0066         values.emplace_back(DDsvalues_Content_type(val, val));
0067 
0068         DDSpecifics ds{"OuterVolume", {"//Outer.*"}, values};
0069       }
0070 
0071       auto middleshape = DDSolidFactory::tubs("MiddleShape", 1., 0.2, 0.49, 0., 2 * kPI);
0072       DDLogicalPart middlelp{"Middle", mat, middleshape};
0073       cv.position(middlelp, outerlp, 0, DDTranslation{}, DDRotation{});
0074       {
0075         DDValue val{"Volume", "Middle", 0};
0076         DDsvalues_type values;
0077         values.emplace_back(DDsvalues_Content_type(val, val));
0078 
0079         DDSpecifics ds{"MiddleVolume", {"//Middle.*"}, values};
0080       }
0081 
0082       auto innershape = DDSolidFactory::tubs("InnerShape", 1., 0.19, 0.05, 0., 2 * kPI);
0083       DDLogicalPart innerlp{"Inner", mat, innershape};
0084       cv.position(innerlp, middlelp, 0, DDTranslation{}, DDRotation{});
0085       {
0086         DDValue val{"Volume", "Inner", 0};
0087         DDsvalues_type values;
0088         values.emplace_back(DDsvalues_Content_type(val, val));
0089 
0090         DDSpecifics ds{"InnerVolume", {"//Inner.*"}, values};
0091       }
0092     }
0093     {
0094       //Endcaps
0095       auto endshape = DDSolidFactory::tubs("EndShape", 0.1, 0.05, 1., 0., 2 * kPI);
0096 
0097       DDLogicalPart endlp{"End", mat, endshape};
0098       cv.position(endlp, root, 0, DDTranslation{0., 0., -(1.0 + 0.1)}, DDRotation{});
0099       {
0100         DDValue val{"Volume", "EMinus", 0};
0101         DDsvalues_type values;
0102         values.emplace_back(DDsvalues_Content_type(val, val));
0103         {
0104           DDValue val{"Side", "-", 0};
0105           values.emplace_back(DDsvalues_Content_type(val, val));
0106         }
0107         DDSpecifics ds{"EMinusVolume", {"//End[0]"}, values};
0108       }
0109 
0110       const DDRotation kXFlip = DDrot("xflip", std::make_unique<DDRotationMatrix>(ROOT::Math::RotationX{kPI}));
0111       cv.position(endlp, root, 1, DDTranslation{0., 0., 1.0 + 0.1}, kXFlip);
0112       {
0113         DDValue val{"Volume", "EPlus", 0};
0114         DDsvalues_type values;
0115         values.emplace_back(DDsvalues_Content_type(val, val));
0116         {
0117           DDValue val{"Side", "+", 0};
0118           values.emplace_back(DDsvalues_Content_type(val, val));
0119         }
0120 
0121         DDSpecifics ds{"EPlusVolume", {"//End[1]"}, values};
0122       }
0123       {
0124         DDValue val{"Endcap", "", 0};
0125         DDsvalues_type values;
0126         values.emplace_back(DDsvalues_Content_type(val, val));
0127 
0128         DDSpecifics ds{"Endcap", {"//End.*"}, values};
0129       }
0130     }
0131     cv.lockdown();
0132 
0133     {
0134       DDSpecificsFilter f;
0135       DDFilteredView fv(cv, f);
0136 
0137       auto const names = getNames(fv);
0138       std::vector<std::string> const expectedNames = {"Outer", "Middle", "Inner", "End", "End"};
0139 
0140       CPPUNIT_ASSERT(names == expectedNames);
0141     }
0142     {
0143       DDValue tofind("Volume", "Outer", 0);
0144       DDSpecificsFilter f;
0145       f.setCriteria(tofind, DDCompOp::equals);
0146       DDFilteredView fv(cv, f);
0147 
0148       auto const names = getNames(fv);
0149       std::vector<std::string> const expectedNames = {"Outer"};
0150       CPPUNIT_ASSERT(names == expectedNames);
0151     }
0152     {
0153       DDSpecificsMatchesValueFilter f{DDValue("Volume", "Outer", 0)};
0154       DDFilteredView fv(cv, f);
0155 
0156       auto const names = getNames(fv);
0157       std::vector<std::string> const expectedNames = {"Outer"};
0158       CPPUNIT_ASSERT(names == expectedNames);
0159     }
0160     {
0161       DDValue tofind("Volume", "Outer", 0);
0162       DDSpecificsFilter f;
0163       f.setCriteria(tofind, DDCompOp::not_equals);
0164       DDFilteredView fv(cv, f);
0165 
0166       auto const names = getNames(fv);
0167       std::vector<std::string> const expectedNames = {"Middle", "Inner", "End", "End"};
0168       CPPUNIT_ASSERT(names == expectedNames);
0169     }
0170     {
0171       DDValue tofind("Volume", "Middle", 0);
0172       DDSpecificsFilter f;
0173       f.setCriteria(tofind, DDCompOp::equals);
0174       DDFilteredView fv(cv, f);
0175 
0176       auto const names = getNames(fv);
0177       std::vector<std::string> const expectedNames = {"Middle"};
0178       CPPUNIT_ASSERT(names == expectedNames);
0179     }
0180     {
0181       DDSpecificsMatchesValueFilter f(DDValue("Volume", "Middle", 0));
0182       DDFilteredView fv(cv, f);
0183 
0184       auto const names = getNames(fv);
0185       std::vector<std::string> const expectedNames = {"Middle"};
0186       CPPUNIT_ASSERT(names == expectedNames);
0187     }
0188     {
0189       DDValue tofind("Volume", "Middle", 0);
0190       DDSpecificsFilter f;
0191       f.setCriteria(tofind, DDCompOp::not_equals);
0192       DDFilteredView fv(cv, f);
0193 
0194       auto const names = getNames(fv);
0195       std::vector<std::string> const expectedNames = {"Outer", "Inner", "End", "End"};
0196       CPPUNIT_ASSERT(names == expectedNames);
0197     }
0198     {
0199       DDValue tofind("Volume", "EPlus", 0);
0200       DDSpecificsFilter f;
0201       f.setCriteria(tofind, DDCompOp::equals);
0202       DDFilteredView fv(cv, f);
0203 
0204       auto const names = getNames(fv);
0205       std::vector<std::string> const expectedNames = {"End"};
0206       CPPUNIT_ASSERT(names == expectedNames);
0207     }
0208     {
0209       DDSpecificsMatchesValueFilter f(DDValue("Volume", "EPlus", 0));
0210       DDFilteredView fv(cv, f);
0211 
0212       auto const names = getNames(fv);
0213       std::vector<std::string> const expectedNames = {"End"};
0214       CPPUNIT_ASSERT(names == expectedNames);
0215     }
0216     {
0217       DDValue tofind("Volume", "EPlus", 0);
0218       DDSpecificsFilter f;
0219       f.setCriteria(tofind, DDCompOp::not_equals);
0220       DDFilteredView fv(cv, f);
0221 
0222       auto const names = getNames(fv);
0223       std::vector<std::string> const expectedNames = {"Outer", "Middle", "Inner", "End"};
0224       CPPUNIT_ASSERT(names == expectedNames);
0225     }
0226     {
0227       DDValue tofind("Volume", "EMinus", 0);
0228       DDSpecificsFilter f;
0229       f.setCriteria(tofind, DDCompOp::equals);
0230       DDFilteredView fv(cv, f);
0231 
0232       auto const names = getNames(fv);
0233       std::vector<std::string> const expectedNames = {"End"};
0234       CPPUNIT_ASSERT(names == expectedNames);
0235     }
0236     {
0237       DDSpecificsMatchesValueFilter f{DDValue("Volume", "EMinus", 0)};
0238       DDFilteredView fv(cv, f);
0239 
0240       auto const names = getNames(fv);
0241       std::vector<std::string> const expectedNames = {"End"};
0242       CPPUNIT_ASSERT(names == expectedNames);
0243     }
0244     {//Test one LogicalPart with different Specifics
0245      // based on placement
0246      {DDValue tofind("Side", "-", 0);
0247     DDSpecificsFilter f;
0248     f.setCriteria(tofind, DDCompOp::equals);
0249     DDFilteredView fv(cv, f);
0250 
0251     auto const names = getNames(fv);
0252     std::vector<std::string> const expectedNames = {"End"};
0253     CPPUNIT_ASSERT(names == expectedNames);
0254   }
0255   {
0256     DDSpecificsMatchesValueFilter f{DDValue("Side", "-", 0)};
0257     DDFilteredView fv(cv, f);
0258 
0259     auto const names = getNames(fv);
0260     std::vector<std::string> const expectedNames = {"End"};
0261     CPPUNIT_ASSERT(names == expectedNames);
0262   }
0263   {
0264     DDValue tofind("Side", "+", 0);
0265     DDSpecificsFilter f;
0266     f.setCriteria(tofind, DDCompOp::equals);
0267     DDFilteredView fv(cv, f);
0268 
0269     auto const names = getNames(fv);
0270     std::vector<std::string> const expectedNames = {"End"};
0271     CPPUNIT_ASSERT(names == expectedNames);
0272   }
0273   {
0274     DDSpecificsMatchesValueFilter f{DDValue("Side", "+", 0)};
0275     DDFilteredView fv(cv, f);
0276 
0277     auto const names = getNames(fv);
0278     std::vector<std::string> const expectedNames = {"End"};
0279     CPPUNIT_ASSERT(names == expectedNames);
0280   }
0281 }
0282 {
0283   DDValue tofind("Volume", "EMinus", 0);
0284   DDSpecificsFilter f;
0285   f.setCriteria(tofind, DDCompOp::not_equals);
0286   DDFilteredView fv(cv, f);
0287 
0288   auto const names = getNames(fv);
0289   std::vector<std::string> const expectedNames = {"Outer", "Middle", "Inner", "End"};
0290   CPPUNIT_ASSERT(names == expectedNames);
0291 }
0292 {
0293   DDValue tofind("Volume", "DoesntExist", 0);
0294   DDSpecificsFilter f;
0295   f.setCriteria(tofind, DDCompOp::equals);
0296   DDFilteredView fv(cv, f);
0297 
0298   auto const names = getNames(fv);
0299   std::vector<std::string> const expectedNames = {};
0300   CPPUNIT_ASSERT(names == expectedNames);
0301 }
0302 {
0303   DDSpecificsMatchesValueFilter f{DDValue("Volume", "DoesntExist", 0)};
0304   DDFilteredView fv(cv, f);
0305 
0306   auto const names = getNames(fv);
0307   std::vector<std::string> const expectedNames = {};
0308   CPPUNIT_ASSERT(names == expectedNames);
0309 }
0310 {
0311   DDValue tofind("Volume", "DoesntExist", 0);
0312   DDSpecificsFilter f;
0313   f.setCriteria(tofind, DDCompOp::not_equals);
0314   DDFilteredView fv(cv, f);
0315 
0316   auto const names = getNames(fv);
0317   std::vector<std::string> const expectedNames = {"Outer", "Middle", "Inner", "End", "End"};
0318   CPPUNIT_ASSERT(names == expectedNames);
0319 }
0320 {
0321   DDSpecificsHasNamedValueFilter f("Volume");
0322   DDFilteredView fv(cv, f);
0323 
0324   auto const names = getNames(fv);
0325   std::vector<std::string> const expectedNames = {"Outer", "Middle", "Inner", "End", "End"};
0326   CPPUNIT_ASSERT(names == expectedNames);
0327 }
0328 {
0329   DDSpecificsHasNamedValueFilter f("DoesntExist");
0330   DDFilteredView fv(cv, f);
0331 
0332   auto const names = getNames(fv);
0333   std::vector<std::string> const expectedNames = {};
0334   CPPUNIT_ASSERT(names == expectedNames);
0335 }
0336 {
0337   DDValue tofind("Endcap", "", 0);
0338   DDSpecificsFilter f;
0339   f.setCriteria(tofind, DDCompOp::equals);
0340   DDFilteredView fv(cv, f);
0341 
0342   auto const names = getNames(fv);
0343   std::vector<std::string> const expectedNames = {"End", "End"};
0344   CPPUNIT_ASSERT(names == expectedNames);
0345 }
0346 {
0347   DDSpecificsMatchesValueFilter f{DDValue("Endcap", "", 0)};
0348   DDFilteredView fv(cv, f);
0349 
0350   auto const names = getNames(fv);
0351   std::vector<std::string> const expectedNames = {"End", "End"};
0352   CPPUNIT_ASSERT(names == expectedNames);
0353 }
0354 {
0355   DDValue tofind("Endcap", "", 0);
0356   DDSpecificsFilter f;
0357   f.setCriteria(tofind, DDCompOp::not_equals);
0358   DDFilteredView fv(cv, f);
0359 
0360   auto const names = getNames(fv);
0361   std::vector<std::string> const expectedNames = {};
0362   for (auto const& n : names) {
0363     std::cout << n;
0364   }
0365   CPPUNIT_ASSERT(names == expectedNames);
0366 }
0367 {
0368   DDValue tofind("Endcap", "DoesntExist", 0);
0369   DDSpecificsFilter f;
0370   f.setCriteria(tofind, DDCompOp::not_equals);
0371   DDFilteredView fv(cv, f);
0372 
0373   auto const names = getNames(fv);
0374   std::vector<std::string> const expectedNames = {"End", "End"};
0375   CPPUNIT_ASSERT(names == expectedNames);
0376 }
0377 {
0378   DDSpecificsHasNamedValueFilter f("Endcap");
0379   DDFilteredView fv(cv, f);
0380 
0381   auto const names = getNames(fv);
0382   std::vector<std::string> const expectedNames = {"End", "End"};
0383   CPPUNIT_ASSERT(names == expectedNames);
0384 }
0385 {
0386   DDValue tofind("Volume", "EMinus", 0);
0387   DDValue tofind2("Endcap", "", 0);
0388   DDSpecificsFilter f;
0389   f.setCriteria(tofind, DDCompOp::equals);
0390   f.setCriteria(tofind2, DDCompOp::equals);
0391   DDFilteredView fv(cv, f);
0392 
0393   auto const names = getNames(fv);
0394   std::vector<std::string> const expectedNames = {"End"};
0395   CPPUNIT_ASSERT(names == expectedNames);
0396 }
0397 {
0398   auto f = make_and_ddfilter(DDSpecificsMatchesValueFilter{DDValue("Volume", "EMinus", 0)},
0399                              DDSpecificsMatchesValueFilter{DDValue("Endcap", "", 0)});
0400   DDFilteredView fv(cv, f);
0401 
0402   auto const names = getNames(fv);
0403   std::vector<std::string> const expectedNames = {"End"};
0404   CPPUNIT_ASSERT(names == expectedNames);
0405 }
0406 {
0407   DDValue tofind("Volume", "EMinus", 0);
0408   DDValue tofind2("Endcap", "", 0);
0409   DDSpecificsFilter f;
0410   f.setCriteria(tofind2, DDCompOp::equals);
0411   f.setCriteria(tofind, DDCompOp::equals);
0412   DDFilteredView fv(cv, f);
0413 
0414   auto const names = getNames(fv);
0415   std::vector<std::string> const expectedNames = {"End"};
0416   CPPUNIT_ASSERT(names == expectedNames);
0417 }
0418 {
0419   auto f = make_and_ddfilter(DDSpecificsMatchesValueFilter{DDValue("Volume", "EMinus", 0)},
0420                              DDSpecificsMatchesValueFilter{DDValue("Endcap", "", 0)});
0421   DDFilteredView fv(cv, f);
0422 
0423   auto const names = getNames(fv);
0424   std::vector<std::string> const expectedNames = {"End"};
0425   CPPUNIT_ASSERT(names == expectedNames);
0426 }
0427 {
0428   DDValue tofind("Volume", "EMinus", 0);
0429   DDValue tofind2("Endcap", "any", 0);
0430   DDSpecificsFilter f;
0431   f.setCriteria(tofind, DDCompOp::equals);
0432   f.setCriteria(tofind2, DDCompOp::not_equals);
0433   DDFilteredView fv(cv, f);
0434 
0435   auto const names = getNames(fv);
0436   std::vector<std::string> const expectedNames = {"End"};
0437   CPPUNIT_ASSERT(names == expectedNames);
0438 }
0439 {
0440   auto f = make_and_ddfilter(DDSpecificsMatchesValueFilter{DDValue("Volume", "EMinus", 0)},
0441                              DDSpecificsHasNamedValueFilter{"Endcap"});
0442   DDFilteredView fv(cv, f);
0443 
0444   auto const names = getNames(fv);
0445   std::vector<std::string> const expectedNames = {"End"};
0446   CPPUNIT_ASSERT(names == expectedNames);
0447 }
0448 {
0449   DDValue tofind("Volume", "EMinus", 0);
0450   DDValue tofind2("Endcap", "any", 0);
0451   DDSpecificsFilter f;
0452   f.setCriteria(tofind2, DDCompOp::not_equals);
0453   f.setCriteria(tofind, DDCompOp::equals);
0454   DDFilteredView fv(cv, f);
0455 
0456   auto const names = getNames(fv);
0457   std::vector<std::string> const expectedNames = {"End"};
0458   CPPUNIT_ASSERT(names == expectedNames);
0459 }
0460 {
0461   auto f = make_and_ddfilter(DDSpecificsHasNamedValueFilter{"Endcap"},
0462                              DDSpecificsMatchesValueFilter{DDValue("Volume", "EMinus", 0)});
0463   DDFilteredView fv(cv, f);
0464 
0465   auto const names = getNames(fv);
0466   std::vector<std::string> const expectedNames = {"End"};
0467   CPPUNIT_ASSERT(names == expectedNames);
0468 }
0469 {
0470   DDValue tofind("Volume", "EMinus", 0);
0471   DDValue tofind2("Endcap", "", 0);
0472   DDSpecificsFilter f;
0473   f.setCriteria(tofind, DDCompOp::equals);
0474   f.setCriteria(tofind2, DDCompOp::not_equals);
0475   DDFilteredView fv(cv, f);
0476 
0477   auto const names = getNames(fv);
0478   std::vector<std::string> const expectedNames = {};
0479   CPPUNIT_ASSERT(names == expectedNames);
0480 }
0481 {
0482   DDValue tofind("Volume", "EMinus", 0);
0483   DDValue tofind2("Endcap", "", 0);
0484   DDSpecificsFilter f;
0485   f.setCriteria(tofind, DDCompOp::equals);
0486   f.setCriteria(tofind2, DDCompOp::not_equals);
0487   DDFilteredView fv(cv, f);
0488 
0489   auto const names = getNames(fv);
0490   std::vector<std::string> const expectedNames = {};
0491   CPPUNIT_ASSERT(names == expectedNames);
0492 }
0493 {
0494   DDValue tofind("Volume", "EMinus", 0);
0495   DDValue tofind2("Endcap", "", 0);
0496   DDSpecificsFilter f;
0497   f.setCriteria(tofind2, DDCompOp::not_equals);
0498   f.setCriteria(tofind, DDCompOp::equals);
0499   DDFilteredView fv(cv, f);
0500 
0501   auto const names = getNames(fv);
0502   std::vector<std::string> const expectedNames = {};
0503   CPPUNIT_ASSERT(names == expectedNames);
0504 }
0505 }
0506 
0507 //CPPUNIT_ASSERT (bad==0);
0508 }