File indexing completed on 2024-09-07 04:35:58
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 }
0046
0047 void testDDFilter::checkFilters() {
0048
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
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
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 {
0245
0246 {
0247 DDValue tofind("Side", "-", 0);
0248 DDSpecificsFilter f;
0249 f.setCriteria(tofind, DDCompOp::equals);
0250 DDFilteredView fv(cv, f);
0251
0252 auto const names = getNames(fv);
0253 std::vector<std::string> const expectedNames = {"End"};
0254 CPPUNIT_ASSERT(names == expectedNames);
0255 }
0256 {
0257 DDSpecificsMatchesValueFilter f{DDValue("Side", "-", 0)};
0258 DDFilteredView fv(cv, f);
0259
0260 auto const names = getNames(fv);
0261 std::vector<std::string> const expectedNames = {"End"};
0262 CPPUNIT_ASSERT(names == expectedNames);
0263 }
0264 {
0265 DDValue tofind("Side", "+", 0);
0266 DDSpecificsFilter f;
0267 f.setCriteria(tofind, DDCompOp::equals);
0268 DDFilteredView fv(cv, f);
0269
0270 auto const names = getNames(fv);
0271 std::vector<std::string> const expectedNames = {"End"};
0272 CPPUNIT_ASSERT(names == expectedNames);
0273 }
0274 {
0275 DDSpecificsMatchesValueFilter f{DDValue("Side", "+", 0)};
0276 DDFilteredView fv(cv, f);
0277
0278 auto const names = getNames(fv);
0279 std::vector<std::string> const expectedNames = {"End"};
0280 CPPUNIT_ASSERT(names == expectedNames);
0281 }
0282 }
0283 {
0284 DDValue tofind("Volume", "EMinus", 0);
0285 DDSpecificsFilter f;
0286 f.setCriteria(tofind, DDCompOp::not_equals);
0287 DDFilteredView fv(cv, f);
0288
0289 auto const names = getNames(fv);
0290 std::vector<std::string> const expectedNames = {"Outer", "Middle", "Inner", "End"};
0291 CPPUNIT_ASSERT(names == expectedNames);
0292 }
0293 {
0294 DDValue tofind("Volume", "DoesntExist", 0);
0295 DDSpecificsFilter f;
0296 f.setCriteria(tofind, DDCompOp::equals);
0297 DDFilteredView fv(cv, f);
0298
0299 auto const names = getNames(fv);
0300 std::vector<std::string> const expectedNames = {};
0301 CPPUNIT_ASSERT(names == expectedNames);
0302 }
0303 {
0304 DDSpecificsMatchesValueFilter f{DDValue("Volume", "DoesntExist", 0)};
0305 DDFilteredView fv(cv, f);
0306
0307 auto const names = getNames(fv);
0308 std::vector<std::string> const expectedNames = {};
0309 CPPUNIT_ASSERT(names == expectedNames);
0310 }
0311 {
0312 DDValue tofind("Volume", "DoesntExist", 0);
0313 DDSpecificsFilter f;
0314 f.setCriteria(tofind, DDCompOp::not_equals);
0315 DDFilteredView fv(cv, f);
0316
0317 auto const names = getNames(fv);
0318 std::vector<std::string> const expectedNames = {"Outer", "Middle", "Inner", "End", "End"};
0319 CPPUNIT_ASSERT(names == expectedNames);
0320 }
0321 {
0322 DDSpecificsHasNamedValueFilter f("Volume");
0323 DDFilteredView fv(cv, f);
0324
0325 auto const names = getNames(fv);
0326 std::vector<std::string> const expectedNames = {"Outer", "Middle", "Inner", "End", "End"};
0327 CPPUNIT_ASSERT(names == expectedNames);
0328 }
0329 {
0330 DDSpecificsHasNamedValueFilter f("DoesntExist");
0331 DDFilteredView fv(cv, f);
0332
0333 auto const names = getNames(fv);
0334 std::vector<std::string> const expectedNames = {};
0335 CPPUNIT_ASSERT(names == expectedNames);
0336 }
0337 {
0338 DDValue tofind("Endcap", "", 0);
0339 DDSpecificsFilter f;
0340 f.setCriteria(tofind, DDCompOp::equals);
0341 DDFilteredView fv(cv, f);
0342
0343 auto const names = getNames(fv);
0344 std::vector<std::string> const expectedNames = {"End", "End"};
0345 CPPUNIT_ASSERT(names == expectedNames);
0346 }
0347 {
0348 DDSpecificsMatchesValueFilter f{DDValue("Endcap", "", 0)};
0349 DDFilteredView fv(cv, f);
0350
0351 auto const names = getNames(fv);
0352 std::vector<std::string> const expectedNames = {"End", "End"};
0353 CPPUNIT_ASSERT(names == expectedNames);
0354 }
0355 {
0356 DDValue tofind("Endcap", "", 0);
0357 DDSpecificsFilter f;
0358 f.setCriteria(tofind, DDCompOp::not_equals);
0359 DDFilteredView fv(cv, f);
0360
0361 auto const names = getNames(fv);
0362 std::vector<std::string> const expectedNames = {};
0363 for (auto const& n : names) {
0364 std::cout << n;
0365 }
0366 CPPUNIT_ASSERT(names == expectedNames);
0367 }
0368 {
0369 DDValue tofind("Endcap", "DoesntExist", 0);
0370 DDSpecificsFilter f;
0371 f.setCriteria(tofind, DDCompOp::not_equals);
0372 DDFilteredView fv(cv, f);
0373
0374 auto const names = getNames(fv);
0375 std::vector<std::string> const expectedNames = {"End", "End"};
0376 CPPUNIT_ASSERT(names == expectedNames);
0377 }
0378 {
0379 DDSpecificsHasNamedValueFilter f("Endcap");
0380 DDFilteredView fv(cv, f);
0381
0382 auto const names = getNames(fv);
0383 std::vector<std::string> const expectedNames = {"End", "End"};
0384 CPPUNIT_ASSERT(names == expectedNames);
0385 }
0386 {
0387 DDValue tofind("Volume", "EMinus", 0);
0388 DDValue tofind2("Endcap", "", 0);
0389 DDSpecificsFilter f;
0390 f.setCriteria(tofind, DDCompOp::equals);
0391 f.setCriteria(tofind2, DDCompOp::equals);
0392 DDFilteredView fv(cv, f);
0393
0394 auto const names = getNames(fv);
0395 std::vector<std::string> const expectedNames = {"End"};
0396 CPPUNIT_ASSERT(names == expectedNames);
0397 }
0398 {
0399 auto f = make_and_ddfilter(DDSpecificsMatchesValueFilter{DDValue("Volume", "EMinus", 0)},
0400 DDSpecificsMatchesValueFilter{DDValue("Endcap", "", 0)});
0401 DDFilteredView fv(cv, f);
0402
0403 auto const names = getNames(fv);
0404 std::vector<std::string> const expectedNames = {"End"};
0405 CPPUNIT_ASSERT(names == expectedNames);
0406 }
0407 {
0408 DDValue tofind("Volume", "EMinus", 0);
0409 DDValue tofind2("Endcap", "", 0);
0410 DDSpecificsFilter f;
0411 f.setCriteria(tofind2, DDCompOp::equals);
0412 f.setCriteria(tofind, DDCompOp::equals);
0413 DDFilteredView fv(cv, f);
0414
0415 auto const names = getNames(fv);
0416 std::vector<std::string> const expectedNames = {"End"};
0417 CPPUNIT_ASSERT(names == expectedNames);
0418 }
0419 {
0420 auto f = make_and_ddfilter(DDSpecificsMatchesValueFilter{DDValue("Volume", "EMinus", 0)},
0421 DDSpecificsMatchesValueFilter{DDValue("Endcap", "", 0)});
0422 DDFilteredView fv(cv, f);
0423
0424 auto const names = getNames(fv);
0425 std::vector<std::string> const expectedNames = {"End"};
0426 CPPUNIT_ASSERT(names == expectedNames);
0427 }
0428 {
0429 DDValue tofind("Volume", "EMinus", 0);
0430 DDValue tofind2("Endcap", "any", 0);
0431 DDSpecificsFilter f;
0432 f.setCriteria(tofind, DDCompOp::equals);
0433 f.setCriteria(tofind2, DDCompOp::not_equals);
0434 DDFilteredView fv(cv, f);
0435
0436 auto const names = getNames(fv);
0437 std::vector<std::string> const expectedNames = {"End"};
0438 CPPUNIT_ASSERT(names == expectedNames);
0439 }
0440 {
0441 auto f = make_and_ddfilter(DDSpecificsMatchesValueFilter{DDValue("Volume", "EMinus", 0)},
0442 DDSpecificsHasNamedValueFilter{"Endcap"});
0443 DDFilteredView fv(cv, f);
0444
0445 auto const names = getNames(fv);
0446 std::vector<std::string> const expectedNames = {"End"};
0447 CPPUNIT_ASSERT(names == expectedNames);
0448 }
0449 {
0450 DDValue tofind("Volume", "EMinus", 0);
0451 DDValue tofind2("Endcap", "any", 0);
0452 DDSpecificsFilter f;
0453 f.setCriteria(tofind2, DDCompOp::not_equals);
0454 f.setCriteria(tofind, DDCompOp::equals);
0455 DDFilteredView fv(cv, f);
0456
0457 auto const names = getNames(fv);
0458 std::vector<std::string> const expectedNames = {"End"};
0459 CPPUNIT_ASSERT(names == expectedNames);
0460 }
0461 {
0462 auto f = make_and_ddfilter(DDSpecificsHasNamedValueFilter{"Endcap"},
0463 DDSpecificsMatchesValueFilter{DDValue("Volume", "EMinus", 0)});
0464 DDFilteredView fv(cv, f);
0465
0466 auto const names = getNames(fv);
0467 std::vector<std::string> const expectedNames = {"End"};
0468 CPPUNIT_ASSERT(names == expectedNames);
0469 }
0470 {
0471 DDValue tofind("Volume", "EMinus", 0);
0472 DDValue tofind2("Endcap", "", 0);
0473 DDSpecificsFilter f;
0474 f.setCriteria(tofind, DDCompOp::equals);
0475 f.setCriteria(tofind2, DDCompOp::not_equals);
0476 DDFilteredView fv(cv, f);
0477
0478 auto const names = getNames(fv);
0479 std::vector<std::string> const expectedNames = {};
0480 CPPUNIT_ASSERT(names == expectedNames);
0481 }
0482 {
0483 DDValue tofind("Volume", "EMinus", 0);
0484 DDValue tofind2("Endcap", "", 0);
0485 DDSpecificsFilter f;
0486 f.setCriteria(tofind, DDCompOp::equals);
0487 f.setCriteria(tofind2, DDCompOp::not_equals);
0488 DDFilteredView fv(cv, f);
0489
0490 auto const names = getNames(fv);
0491 std::vector<std::string> const expectedNames = {};
0492 CPPUNIT_ASSERT(names == expectedNames);
0493 }
0494 {
0495 DDValue tofind("Volume", "EMinus", 0);
0496 DDValue tofind2("Endcap", "", 0);
0497 DDSpecificsFilter f;
0498 f.setCriteria(tofind2, DDCompOp::not_equals);
0499 f.setCriteria(tofind, DDCompOp::equals);
0500 DDFilteredView fv(cv, f);
0501
0502 auto const names = getNames(fv);
0503 std::vector<std::string> const expectedNames = {};
0504 CPPUNIT_ASSERT(names == expectedNames);
0505 }
0506 }
0507
0508
0509 }