File indexing completed on 2024-04-06 12:05:30
0001 #include <cppunit/extensions/HelperMacros.h>
0002
0003 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0004 #include "DetectorDescription/DDCMS/interface/DDDetector.h"
0005 #include "FWCore/ParameterSet/interface/FileInPath.h"
0006 #include "DD4hep/Detector.h"
0007
0008 #include <string>
0009 #include <memory>
0010 #include <vector>
0011
0012 #include "cppunit/TestAssert.h"
0013 #include "cppunit/TestFixture.h"
0014
0015 using namespace cms;
0016
0017 class testDDFilteredViewLevel : public CppUnit::TestFixture {
0018 CPPUNIT_TEST_SUITE(testDDFilteredViewLevel);
0019 CPPUNIT_TEST(checkFilteredView);
0020 CPPUNIT_TEST_SUITE_END();
0021
0022 public:
0023 void setUp() override;
0024 void tearDown() override {}
0025 void checkFilteredView();
0026
0027 private:
0028 std::string fileName_;
0029 std::vector<int> refPos_{0, 0, 6, 2, 2};
0030 };
0031
0032 CPPUNIT_TEST_SUITE_REGISTRATION(testDDFilteredViewLevel);
0033
0034 void testDDFilteredViewLevel::setUp() {
0035 fileName_ = edm::FileInPath("Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml").fullPath();
0036 }
0037
0038 void testDDFilteredViewLevel::checkFilteredView() {
0039 std::unique_ptr<DDDetector> det = std::make_unique<DDDetector>("DUMMY", fileName_);
0040 DDFilteredView fview(det.get(), det->description()->worldVolume());
0041 bool doContinue(true);
0042 int count = 1;
0043 auto testPos = fview.navPos();
0044 while (fview.next(0) && doContinue) {
0045 std::cout << "#" << count << ": ";
0046 std::cout << fview.level() << " level: " << fview.name() << " is a "
0047 << cms::dd::name(cms::DDSolidShapeMap, fview.shape()) << "\n";
0048 std::cout << "Full path to it is " << fview.path() << "\n";
0049 auto copyNos = fview.copyNos();
0050 for (auto it : copyNos) {
0051 std::cout << it << ", ";
0052 }
0053 std::cout << "\n";
0054 auto pos = fview.navPos();
0055 for (auto it : pos) {
0056 std::cout << it << ", ";
0057 }
0058
0059 fview.parent();
0060 std::cout << "\n"
0061 << fview.level() << " level: " << fview.name() << " is a "
0062 << cms::dd::name(cms::DDSolidShapeMap, fview.shape()) << "\n";
0063
0064 if (count == 45) {
0065 testPos = fview.navPos();
0066 }
0067 if (count == 50) {
0068 doContinue = false;
0069 }
0070 count++;
0071 std::cout << "\n";
0072 }
0073 fview.goTo(testPos);
0074 std::cout << "Go to #45\n";
0075 std::cout << fview.level() << " level: " << fview.name() << " is a "
0076 << cms::dd::name(cms::DDSolidShapeMap, fview.shape()) << "\n";
0077 std::cout << "Full path to it is " << fview.path() << "\n";
0078 auto copyNos = fview.copyNos();
0079 for (auto it : copyNos) {
0080 std::cout << it << ", ";
0081 }
0082 std::cout << "\n";
0083 count = 0;
0084 auto pos = fview.navPos();
0085 for (auto it : pos) {
0086 std::cout << it << ", ";
0087 CPPUNIT_ASSERT(it == testPos[count++]);
0088 }
0089 std::cout << "\n";
0090 count = 0;
0091 for (auto it : testPos) {
0092 std::cout << it << ", ";
0093 CPPUNIT_ASSERT(it == refPos_[count++]);
0094 }
0095 std::cout << "\n";
0096 }