DD4hep  1.28.0
Detector Description Toolkit for High Energy Physics
OpticalSurfaceManager.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
17 #include <DD4hep/ExtensionEntry.h>
18 #include <DD4hep/Detector.h>
19 #include <DD4hep/Printout.h>
20 
21 // C/C++ includes
22 #include <sstream>
23 #include <iomanip>
24 
25 using namespace dd4hep;
26 
29  return description.surfaceManager();
30 }
31 
33 SkinSurface OpticalSurfaceManager::skinSurface(DetElement de, const std::string& nam) const {
34  if ( de.isValid() ) {
35  Object* o = access();
36  std::string n = de.path() + '#' + nam;
37  TGeoSkinSurface* surf = o->detector.manager().GetSkinSurface(n.c_str());
38  if ( surf ) return surf;
39  auto i = o->skinSurfaces.find(Object::LocalKey(de, nam));
40  if ( i != o->skinSurfaces.end() ) return (*i).second;
41  return 0;
42  }
43  except("SkinSurface",
44  "++ Cannot access SkinSurface %s without valid detector element!",nam.c_str());
45  return SkinSurface();
46 }
47 
49 SkinSurface OpticalSurfaceManager::skinSurface(const std::string& full_nam) const {
50  return access()->detector.manager().GetSkinSurface(full_nam.c_str());
51 }
52 
55  if ( de.isValid() ) {
56  Object* o = access();
57  std::string n = de.path() + '#' + nam;
58  TGeoBorderSurface* surf = o->detector.manager().GetBorderSurface(n.c_str());
59  if ( surf ) return surf;
60  auto i = o->borderSurfaces.find(Object::LocalKey(de, nam));
61  if ( i != o->borderSurfaces.end() ) return (*i).second;
62  return 0;
63  }
64  except("BorderSurface",
65  "++ Cannot access BorderSurface %s without valid detector element!",nam.c_str());
66  return BorderSurface();
67 }
68 
70 BorderSurface OpticalSurfaceManager::borderSurface(const std::string& full_nam) const {
71  return access()->detector.manager().GetBorderSurface(full_nam.c_str());
72 }
73 
76  if ( de.isValid() ) {
77  Object* o = access();
78  std::string n = de.path() + '#' + nam;
79  TGeoOpticalSurface* surf = o->detector.manager().GetOpticalSurface(n.c_str());
80  if ( surf ) return surf;
81  auto i = o->opticalSurfaces.find(n);
82  if ( i != o->opticalSurfaces.end() ) return (*i).second;
83  return 0;
84  }
85  except("OpticalSurface",
86  "++ Cannot access OpticalSurface %s without valid detector element!",nam.c_str());
87  return OpticalSurface();
88 }
89 
91 OpticalSurface OpticalSurfaceManager::opticalSurface(const std::string& full_nam) const {
92  return access()->detector.manager().GetOpticalSurface(full_nam.c_str());
93 }
94 
97  if ( access()->skinSurfaces.emplace(std::make_pair(de,surf->GetName()), surf).second )
98  return;
99  except("OpticalSurfaceManager","++ Skin surface %s already present for DE:%s.",
100  surf->GetName(), de.name());
101 }
102 
105  if ( access()->borderSurfaces.emplace(std::make_pair(de,surf->GetName()), surf).second )
106  return;
107  except("OpticalSurfaceManager","++ Border surface %s already present for DE:%s.",
108  surf->GetName(), de.name());
109 }
110 
113  if ( access()->opticalSurfaces.emplace(surf->GetName(), surf).second )
114  return;
115  except("OpticalSurfaceManager","++ Optical surface %s already present.",
116  surf->GetName());
117 }
118 
121  Object* o = access();
122  std::unique_ptr<Object> extension(new Object(o->detector));
123  for(auto& optical : o->opticalSurfaces) {
124  o->detector.manager().AddOpticalSurface(optical.second.ptr());
125  extension->opticalSurfaces.insert(optical);
126  }
127  o->opticalSurfaces.clear();
128 
129  for(auto& skin : o->skinSurfaces) {
130  std::string n = skin.first.first.path() + '#' + skin.first.second;
131  skin.second->SetName(n.c_str());
132  o->detector.manager().AddSkinSurface(skin.second.ptr());
133  extension->skinSurfaces.insert(skin);
134  }
135  o->skinSurfaces.clear();
136 
137  for(auto& border : o->borderSurfaces) {
138  std::string n = border.first.first.path() + '#' + border.first.second;
139  border.second->SetName(n.c_str());
140  o->detector.manager().AddBorderSurface(border.second.ptr());
141  extension->borderSurfaces.insert(border);
142  }
143  o->borderSurfaces.clear();
144 
145  if ( extension->opticalSurfaces.empty() &&
146  extension->borderSurfaces.empty() &&
147  extension->skinSurfaces.empty() ) {
148  return;
149  }
150  subdetector.addExtension(new detail::DeleteExtension<Object,Object>(extension.release()));
151 }
152 
dd4hep::Detector::manager
virtual TGeoManager & manager() const =0
Access the geometry manager of this instance.
dd4hep::DetElement::path
const std::string & path() const
Path of the detector element (not necessarily identical to placement path!)
Definition: DetElement.cpp:157
dd4hep::OpticalSurfaceManager::opticalSurface
OpticalSurface opticalSurface(const std::string &full_name) const
Access optical surface data by its full name.
Definition: OpticalSurfaceManager.cpp:91
dd4hep::detail::OpticalSurfaceManagerObject
This structure describes the internal data of the volume manager object.
Definition: OpticalSurfaceManagerInterna.h:43
dd4hep::detail::OpticalSurfaceManagerObject::detector
Detector & detector
Reference to the main detector description object.
Definition: OpticalSurfaceManagerInterna.h:48
dd4hep::OpticalSurfaceManager::addSkinSurface
void addSkinSurface(DetElement de, SkinSurface surf) const
Add skin surface to manager.
Definition: OpticalSurfaceManager.cpp:96
Detector.h
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::OpticalSurfaceManager::addOpticalSurface
void addOpticalSurface(OpticalSurface surf) const
Add optical surface data to manager.
Definition: OpticalSurfaceManager.cpp:112
dd4hep::OpticalSurfaceManager::getOpticalSurfaceManager
static OpticalSurfaceManager getOpticalSurfaceManager(Detector &description)
static accessor calling DD4hepOpticalSurfaceManagerPlugin if necessary
Definition: OpticalSurfaceManager.cpp:28
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::detail::OpticalSurfaceManagerObject::skinSurfaces
std::map< LocalKey, SkinSurface > skinSurfaces
Definition: OpticalSurfaceManagerInterna.h:49
dd4hep::detail::DeleteExtension
Implementation class for the object extension mechanism.
Definition: ExtensionEntry.h:122
OpticalSurfaceManager.h
dd4hep::OpticalSurfaceManager::registerSurfaces
void registerSurfaces(DetElement subdetector)
Register the temporary surface objects with the TGeoManager.
Definition: OpticalSurfaceManager.cpp:120
dd4hep::SkinSurface
Class to support the handling of optical surfaces.
Definition: OpticalSurfaces.h:111
dd4hep::Detector::surfaceManager
virtual OpticalSurfaceManager surfaceManager() const =0
Access the optical surface manager.
dd4hep::OpticalSurfaceManager::addBorderSurface
void addBorderSurface(DetElement de, BorderSurface surf) const
Add border surface to manager.
Definition: OpticalSurfaceManager.cpp:104
dd4hep::OpticalSurfaceManager::borderSurface
BorderSurface borderSurface(const std::string &full_name) const
Access border surface by its full name.
Definition: OpticalSurfaceManager.cpp:70
dd4hep::OpticalSurfaceManager::Object
detail::OpticalSurfaceManagerObject Object
Definition: OpticalSurfaceManager.h:39
dd4hep::Handle< detail::OpticalSurfaceManagerObject >::access
detail::OpticalSurfaceManagerObject * access() const
Checked object access. Throws invalid handle runtime exception if invalid handle.
dd4hep::detail::OpticalSurfaceManagerObject::borderSurfaces
std::map< LocalKey, BorderSurface > borderSurfaces
Definition: OpticalSurfaceManagerInterna.h:50
dd4hep::detail::OpticalSurfaceManagerObject::LocalKey
std::pair< DetElement, std::string > LocalKey
Definition: OpticalSurfaceManagerInterna.h:45
dd4hep::DetElement::addExtension
void * addExtension(ExtensionEntry *entry) const
Add an extension object to the detector element.
Definition: DetElement.cpp:65
OpticalSurfaceManagerInterna.h
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::BorderSurface
Class to support the handling of optical surfaces.
Definition: OpticalSurfaces.h:155
dd4hep::detail::OpticalSurfaceManagerObject::opticalSurfaces
std::map< std::string, OpticalSurface > opticalSurfaces
Definition: OpticalSurfaceManagerInterna.h:51
Printout.h
dd4hep::OpticalSurface
Class to support the handling of optical surfaces.
Definition: OpticalSurfaces.h:42
ExtensionEntry.h
dd4hep::OpticalSurfaceManager::skinSurface
SkinSurface skinSurface(const std::string &full_name) const
Access skin surface by its full name.
Definition: OpticalSurfaceManager.cpp:49
dd4hep::OpticalSurfaceManager
Class to support the handling of optical surfaces.
Definition: OpticalSurfaceManager.h:37