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