File indexing completed on 2025-07-09 07:52:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/OpticalSurfaceManager.h>
0016 #include <DD4hep/detail/OpticalSurfaceManagerInterna.h>
0017 #include <DD4hep/ExtensionEntry.h>
0018 #include <DD4hep/Detector.h>
0019 #include <DD4hep/Printout.h>
0020
0021
0022 #include <string>
0023
0024 using namespace dd4hep;
0025
0026
0027 OpticalSurfaceManager OpticalSurfaceManager::getOpticalSurfaceManager(Detector& description) {
0028 return description.surfaceManager();
0029 }
0030
0031
0032 SkinSurface OpticalSurfaceManager::skinSurface(DetElement de, const std::string& nam) const {
0033 if ( de.isValid() ) {
0034 Object* o = access();
0035 std::string n = de.path() + '#' + nam;
0036 TGeoSkinSurface* surf = o->detector.manager().GetSkinSurface(n.c_str());
0037 if ( surf ) return surf;
0038 auto i = o->skinSurfaces.find(Object::LocalKey(de, nam));
0039 if ( i != o->skinSurfaces.end() ) return (*i).second;
0040 return 0;
0041 }
0042 except("SkinSurface",
0043 "++ Cannot access SkinSurface %s without valid detector element!",nam.c_str());
0044 return SkinSurface();
0045 }
0046
0047
0048 SkinSurface OpticalSurfaceManager::skinSurface(const std::string& full_nam) const {
0049 return access()->detector.manager().GetSkinSurface(full_nam.c_str());
0050 }
0051
0052
0053 BorderSurface OpticalSurfaceManager::borderSurface(DetElement de, const std::string& nam) const {
0054 if ( de.isValid() ) {
0055 Object* o = access();
0056 std::string n = de.path() + '#' + nam;
0057 TGeoBorderSurface* surf = o->detector.manager().GetBorderSurface(n.c_str());
0058 if ( surf ) return surf;
0059 auto i = o->borderSurfaces.find(Object::LocalKey(de, nam));
0060 if ( i != o->borderSurfaces.end() ) return (*i).second;
0061 return 0;
0062 }
0063 except("BorderSurface",
0064 "++ Cannot access BorderSurface %s without valid detector element!",nam.c_str());
0065 return BorderSurface();
0066 }
0067
0068
0069 BorderSurface OpticalSurfaceManager::borderSurface(const std::string& full_nam) const {
0070 return access()->detector.manager().GetBorderSurface(full_nam.c_str());
0071 }
0072
0073
0074 OpticalSurface OpticalSurfaceManager::opticalSurface(DetElement de, const std::string& nam) const {
0075 if ( de.isValid() ) {
0076 Object* o = access();
0077 std::string n = de.path() + '#' + nam;
0078 TGeoOpticalSurface* surf = o->detector.manager().GetOpticalSurface(n.c_str());
0079 if ( surf ) return surf;
0080 auto i = o->opticalSurfaces.find(n);
0081 if ( i != o->opticalSurfaces.end() ) return (*i).second;
0082 return 0;
0083 }
0084 except("OpticalSurface",
0085 "++ Cannot access OpticalSurface %s without valid detector element!",nam.c_str());
0086 return OpticalSurface();
0087 }
0088
0089
0090 OpticalSurface OpticalSurfaceManager::opticalSurface(const std::string& full_nam) const {
0091 return access()->detector.manager().GetOpticalSurface(full_nam.c_str());
0092 }
0093
0094
0095 void OpticalSurfaceManager::addSkinSurface(DetElement de, SkinSurface surf) const {
0096 if ( access()->skinSurfaces.emplace(std::make_pair(de,surf->GetName()), surf).second )
0097 return;
0098 except("OpticalSurfaceManager","++ Skin surface %s already present for DE:%s.",
0099 surf->GetName(), de.name());
0100 }
0101
0102
0103 void OpticalSurfaceManager::addBorderSurface(DetElement de, BorderSurface surf) const {
0104 if ( access()->borderSurfaces.emplace(std::make_pair(de,surf->GetName()), surf).second )
0105 return;
0106 except("OpticalSurfaceManager","++ Border surface %s already present for DE:%s.",
0107 surf->GetName(), de.name());
0108 }
0109
0110
0111 void OpticalSurfaceManager::addOpticalSurface(OpticalSurface surf) const {
0112 if ( access()->opticalSurfaces.emplace(surf->GetName(), surf).second )
0113 return;
0114 except("OpticalSurfaceManager","++ Optical surface %s already present.",
0115 surf->GetName());
0116 }
0117
0118
0119 void OpticalSurfaceManager::registerSurfaces(DetElement subdetector) {
0120 Object* o = access();
0121 std::unique_ptr<Object> extension(new Object(o->detector));
0122 for(auto& optical : o->opticalSurfaces) {
0123 o->detector.manager().AddOpticalSurface(optical.second.ptr());
0124 extension->opticalSurfaces.insert(optical);
0125 }
0126 o->opticalSurfaces.clear();
0127
0128 for(auto& skin : o->skinSurfaces) {
0129 std::string n = skin.first.first.path() + '#' + skin.first.second;
0130 skin.second->SetName(n.c_str());
0131 o->detector.manager().AddSkinSurface(skin.second.ptr());
0132 extension->skinSurfaces.insert(skin);
0133 }
0134 o->skinSurfaces.clear();
0135
0136 for(auto& border : o->borderSurfaces) {
0137 std::string n = border.first.first.path() + '#' + border.first.second;
0138 border.second->SetName(n.c_str());
0139 o->detector.manager().AddBorderSurface(border.second.ptr());
0140 extension->borderSurfaces.insert(border);
0141 }
0142 o->borderSurfaces.clear();
0143
0144 if ( extension->opticalSurfaces.empty() &&
0145 extension->borderSurfaces.empty() &&
0146 extension->skinSurfaces.empty() ) {
0147 return;
0148 }
0149 subdetector.addExtension(new detail::DeleteExtension<Object,Object>(extension.release()));
0150 }
0151