Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:01

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
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 // C/C++ includes
0022 #include <sstream>
0023 #include <iomanip>
0024 
0025 using namespace dd4hep;
0026 
0027 /// static accessor calling DD4hepOpticalSurfaceManagerPlugin if necessary
0028 OpticalSurfaceManager OpticalSurfaceManager::getOpticalSurfaceManager(Detector& description)  {
0029   return description.surfaceManager();
0030 }
0031 
0032 /// Access skin surface by its identifier
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 /// Access skin surface by its full name
0049 SkinSurface  OpticalSurfaceManager::skinSurface(const std::string& full_nam)  const   {
0050   return access()->detector.manager().GetSkinSurface(full_nam.c_str());
0051 }
0052 
0053 /// Access border surface by its identifier
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 /// Access border surface by its full name
0070 BorderSurface  OpticalSurfaceManager::borderSurface(const std::string& full_nam)  const   {
0071   return access()->detector.manager().GetBorderSurface(full_nam.c_str());
0072 }
0073 
0074 /// Access optical surface data by its identifier
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 /// Access optical surface data by its identifier
0091 OpticalSurface OpticalSurfaceManager::opticalSurface(const std::string& full_nam)  const   {
0092   return access()->detector.manager().GetOpticalSurface(full_nam.c_str());
0093 }
0094 
0095 /// Add skin surface to manager
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 /// Add border surface to manager
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 /// Add optical surface data to manager
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 /// Register the temporary surface objects with the TGeoManager
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