DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
View.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 // Original Author: Matevz Tadel 2009 (MultiView.C)
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include <DDEve/View.h>
17 #include <DDEve/Display.h>
18 #include <DDEve/ElementList.h>
19 #include <DDEve/Utilities.h>
20 #include <DDEve/Annotation.h>
21 #include <DD4hep/InstanceCount.h>
22 
23 // Eve include files
24 #include <TEveManager.h>
25 #include <TEveWindow.h>
26 #include <TEveCalo.h>
27 #include <TGLViewer.h>
28 
29 using namespace dd4hep;
30 
31 template <typename T>
32 static inline typename T::const_iterator find(const T& cont,const std::string& str) {
33  for(typename T::const_iterator i=cont.begin(); i!=cont.end(); ++i)
34  if ( (*i).name == str ) return i;
35  return cont.end();
36 }
37 
39 View::View(Display* eve, const std::string& nam)
40  : m_eve(eve), m_view(0), m_geoScene(0), m_eveScene(0), m_global(0), m_name(nam), m_showGlobal(false)
41 {
44 }
45 
48  m_eve->UnregisterEvents(this);
49  for(Topics::iterator i=m_geoTopics.begin(); i!=m_geoTopics.end(); ++i)
50  (*i).second->DestroyElements();
51  if ( m_geoScene ) m_geoScene->DestroyElements();
52  if ( m_eveScene ) m_eveScene->DestroyElements();
53  if ( m_global ) m_global->DestroyElements();
55 }
56 
58 View& View::Build(TEveWindow* /* slot */) {
59  return *this;
60 }
61 
64  TEveScene *evt = this->eveScene();
65  TEveScene *geo = this->geoScene();
66  if ( evt ) evt->Repaint(kTRUE);
67  if ( geo ) geo->Repaint(kTRUE);
69  TGLViewer* glv = viewer()->GetGLViewer();
70  glv->PostSceneBuildSetup(kTRUE);
71  glv->SetSmartRefresh(kFALSE);
72  if ( m_eve->manager().GetViewers()->UseLightColorSet() )
73  glv->UseLightColorSet();
74  else
75  glv->UseDarkColorSet();
76  glv->RequestDraw(TGLRnrCtx::kLODHigh);
77  glv->SetSmartRefresh(kTRUE);
78 }
79 
81 TEveElementList* View::AddToGlobalItems(const std::string& nam) {
82  if ( 0 == m_global ) {
83  m_global = new ElementList(nam.c_str(), nam.c_str(), true, true);
84  if ( m_geoScene ) m_global->AddElement(geoScene());
85  if ( m_eveScene ) m_global->AddElement(eveScene());
86  if ( m_showGlobal ) m_eve->manager().AddToListTree(m_global,kFALSE);
87  }
88  return m_global;
89 }
90 
92 TEveElement* View::ImportGeoElement(TEveElement* el, TEveElementList* list) {
93  TEveScene* scene = dynamic_cast<TEveScene*>(el);
94  if ( scene ) {
95  printf("ERROR: Adding a Scene [%s] to a list. This is BAD and causes crashes!\n",scene->GetName());
96  }
97  if ( el ) list->AddElement(el);
98  return el;
99 }
100 
102 TEveElement* View::ImportGeoTopic(TEveElement* element, TEveElementList* list) {
103  return ImportGeoElement(element, list);
104 }
105 
107 TEveElement* View::ImportEventElement(TEveElement* el, TEveElementList* list) {
108  TEveScene* scene = dynamic_cast<TEveScene*>(el);
109  if ( scene ) {
110  printf("ERROR: Adding a Scene [%s] to a list. This is BAD and causes crashes!\n",scene->GetName());
111  }
112  if ( el ) {
113  printout(INFO,"View","ImportElement %s [%s] into list: %s",
114  Utilities::GetName(el), el->IsA()->GetName(), list->GetName());
115  list->AddElement(el);
116  }
117  return el;
118 }
119 
121 std::pair<bool,TEveElement*>
124  TEveElementList& global = m_eve->GetGeoTopic(sd.isValid() ? "Sensitive" : "Structure");
125  TEveElement* elt = global.FindChild(de.name());
126  return std::pair<bool,TEveElement*>(true,elt);
127 }
128 
130 std::pair<bool,TEveElement*>
133  TEveElementList& topic = GetGeoTopic(sd.isValid() ? "Sensitive" : "Structure");
134  return Utilities::LoadDetElement(de,cfg.data.defaults.load_geo,&topic);
135 }
136 
139  printout(INFO,"View","+++ Configure Geometry for view %s Config=%p.",c_name(),m_config);
142 }
143 
146  TEveElementList* l = &m_eve->GetGeoTopic("Sensitive");
147  TEveElementList* t = &GetGeoTopic("Sensitive");
148  for(TEveElementList::List_i i=l->BeginChildren(); i!=l->EndChildren(); ++i)
149  ImportGeo(*t,*i);
150 
151  l = &m_eve->GetGeoTopic("Structure");
152  t = &GetGeoTopic("Structure");
153  for(TEveElementList::List_i i=l->BeginChildren(); i!=l->EndChildren(); ++i)
154  ImportGeo(*t,*i);
155 }
156 
159  std::string dets;
160  DisplayConfiguration::Configurations::const_iterator ic;
163  const DetElement::Children& c = world.children();
164  for( ic=config.subdetectors.begin(); ic != config.subdetectors.end(); ++ic) {
165  const DisplayConfiguration::Config& cfg = *ic;
166  std::string nam = cfg.name;
167  if ( nam == "global" ) {
168  m_view->AddScene(m_eve->manager().GetGlobalScene());
169  m_view->AddScene(m_eve->manager().GetEventScene());
170  dets += nam;
171  }
172  else if ( cfg.type == DisplayConfiguration::CALODATA ) {
173  // Note: The histogram grid must be handled like a geometry item.
175  if ( ctx.config.use.empty() ) ImportGeo(ctx.calo3D);
176  printout(INFO,"View","+++ %s: add detector %s %s",name().c_str(),nam.c_str(),ctx.config.use.c_str());
177  Color_t col = ctx.calo3D->GetDataSliceColor(ctx.slice);
178  Annotation* a = new Annotation(viewer(),nam.c_str(),Annotation::DefaultMargin(),legend_y,col);
179  legend_y += a->GetTextSize();
180  dets += nam + "(Calo3D) ";
181  }
182  else if ( cfg.type == DisplayConfiguration::DETELEMENT ) {
183  DetElement::Children::const_iterator i = c.find(nam);
184  if ( i != c.end() ) {
185  DetElement de = (*i).second;
187  TEveElementList& topic = GetGeoTopic(sd.isValid() ? "Sensitive" : "Structure");
188  std::pair<bool,TEveElement*> e(false,0);
189  if ( cfg.data.defaults.load_geo > 0 ) // Create a new instance
190  e = CreateGeometry(de,cfg); // with the given number of levels
191  else if ( cfg.data.defaults.load_geo < 0 ) // Use the global geometry instance
192  e = GetGlobalGeometry(de,cfg); // with the given number of levels
193  if ( e.first && e.second ) {
194  ImportGeo(topic,e.second);
195  }
196  dets += nam + "(Geo) ";
197  }
198  }
199  }
200  printout(INFO,"ViewConfiguration","+++ Configured geometry for view %s.",c_name());
201  printout(INFO,"ViewConfiguration","+++ Detectors:%s", dets.c_str());
202 }
203 
205 void View::ImportGeoTopics(const std::string& title) {
206  printout(INFO,"View","+++ %s: Import geometry topics.",c_name());
207  for(Topics::iterator i=m_geoTopics.begin(); i!=m_geoTopics.end(); ++i) {
208  printout(INFO,"ViewConfiguration","+++ Add topic %s",(*i).second->GetName());
209  ImportGeoTopic((*i).second,m_geoScene);
210  }
211  if ( !title.empty() ) AddToGlobalItems(title);
212 }
213 
215 void View::ImportGeo(const std::string& topic, TEveElement* element) {
216  ImportGeoElement(element,&GetGeoTopic(topic));
217 }
218 
220 void View::ImportGeo(TEveElementList& topic, TEveElement* element) {
221  ImportGeoElement(element,&topic);
222 }
223 
225 void View::ImportGeo(TEveElement* el) {
227 }
228 
231  printout(INFO,"View","+++ Import event data into view %s Config=%p.",c_name(),m_config);
234 }
235 
238  TEveElementList* l = m_eve->manager().GetEventScene();
239  for(TEveElementList::List_i i=l->BeginChildren(); i!=l->EndChildren(); ++i)
240  ImportEvent(*i);
241 }
242 
246  const DetElement::Children& c = world.children();
247  DisplayConfiguration::Configurations::const_iterator ic;
248  for( ic=config.subdetectors.begin(); ic != config.subdetectors.end(); ++ic) {
249  const DisplayConfiguration::Config& cfg = *ic;
250  std::string nam = cfg.name;
251  if ( nam == "global" ) {
252  continue;
253  }
254  else if ( cfg.type == DisplayConfiguration::CALODATA ) {
255  continue;
256  }
257  else if ( cfg.type == DisplayConfiguration::COLLECTION ) {
258  // Not using the global scene!
259  if ( cfg.data.defaults.show_evt>0 ) {
260  TEveElement* child = m_eve->manager().GetEventScene()->FindChild(nam);
261  printout(INFO,"View","+++ Add collection:%s data:%p scene:%p",nam.c_str(),child,m_eveScene);
262  if ( child ) ImportEvent(child);
263  }
264  }
265  else if ( cfg.type == DisplayConfiguration::DETELEMENT ) {
266  // Not using the global scene!
267  DetElement::Children::const_iterator i = c.find(nam);
268  if ( i != c.end() && cfg.data.defaults.show_evt>0 ) {
270  if ( sd.isValid() ) {
271  // This should be configurable!
272  const char* coll = sd.readout().name();
273  TEveElement* child = m_eve->manager().GetEventScene()->FindChild(coll);
274  printout(INFO,"View","+++ Add detector event %s collection:%s data:%p scene:%p",
275  nam.c_str(),coll,child,m_eveScene);
276  if ( child ) ImportEvent(child);
277  }
278  }
279  }
280  }
281 }
282 
285 }
286 
288 void View::ImportEvent(TEveElement* el) {
289  if ( m_eveScene ) {
291  }
292 }
293 
295 TEveElementList& View::GetGeoTopic(const std::string& nam) {
296  Topics::iterator i=m_geoTopics.find(nam);
297  if ( i == m_geoTopics.end() ) {
298  TEveElementList* topic = new ElementList(nam.c_str(), nam.c_str(), true, true);
299  m_geoTopics[nam] = topic;
300  return *topic;
301  }
302  return *((*i).second);
303 }
304 
307  // Scenes
308  CreateGeoScene();
310  return *this;
311 }
312 
315  if ( 0 == m_eveScene ) {
316  std::string nam = m_name+" - Event Data";
317  std::string tool = m_name+" - Scene holding projected event-data for the view.";
318  m_eveScene = m_eve->manager().SpawnNewScene(nam.c_str(), tool.c_str());
319  }
320  return *this;
321 }
322 
325  if ( 0 == m_geoScene ) {
326  std::string nam = m_name+" - Geometry";
327  std::string tool = m_name+" - Scene holding projected geometry for the view.";
328  m_geoScene = m_eve->manager().SpawnNewScene(nam.c_str(), tool.c_str());
329  }
330  return *this;
331 }
332 
334 View& View::Map(TEveWindow* slot) {
335  slot->MakeCurrent();
336  m_view = m_eve->manager().SpawnNewViewer(m_name.c_str(), "");
337  if ( m_geoScene ) m_view->AddScene(m_geoScene);
338  if ( m_eveScene ) m_view->AddScene(m_eveScene);
339  return *this;
340 }
dd4hep::DetElement::children
const Children & children() const
Access to the list of children.
Definition: DetElement.cpp:207
dd4hep::View::ConfigureGeometry
virtual void ConfigureGeometry(const DisplayConfiguration::ViewConfig &config)
Configure a single geometry view.
Definition: View.cpp:158
dd4hep::Display
The main class of the DDEve display.
Definition: Display.h:56
dd4hep::View::c_name
const char * c_name() const
Definition: View.h:82
dd4hep::View::geoScene
TEveScene * geoScene() const
Access to the Eve geometry scene.
Definition: View.h:104
dd4hep::Detector::world
virtual DetElement world() const =0
Return reference to the top-most (world) detector element.
dd4hep::View::View
View(Display *eve, const std::string &name)
Initializing constructor.
Definition: View.cpp:39
dd4hep::View::m_eve
Display * m_eve
Definition: View.h:49
dd4hep::Annotation::DefaultTextSize
static float DefaultTextSize()
Default text size.
Definition: Annotation.cpp:50
dd4hep::SensitiveDetector
Handle class to hold the information of a sensitive detector.
Definition: DetElement.h:44
dd4hep::Display::CalodataContext::calo3D
TEveCalo3D * calo3D
Definition: Display.h:70
dd4hep::View::GetGlobalGeometry
virtual std::pair< bool, TEveElement * > GetGlobalGeometry(DetElement de, const DisplayConfiguration::Config &cfg)
Access the global instance of the subdetector geometry.
Definition: View.cpp:122
dd4hep::View::ImportEvent
virtual void ImportEvent(TEveElement *element)
Call to import event elements into the main event scene.
Definition: View.cpp:288
dd4hep::View::ConfigureGeometryFromGlobal
virtual void ConfigureGeometryFromGlobal()
Configure a single geometry view by default from the global geometry scene with all subdetectors.
Definition: View.cpp:145
dd4hep::DisplayConfiguration::COLLECTION
@ COLLECTION
Definition: DisplayConfiguration.h:50
dd4hep::Display::GetGeoTopic
virtual TEveElementList & GetGeoTopic(const std::string &name)
Access/Create an geometry topic by name.
Definition: Display.cpp:465
dd4hep::DisplayConfiguration::Config::data
union dd4hep::DisplayConfiguration::Config::Values data
dd4hep::View::Map
virtual View & Map(TEveWindow *slot)
Map the view view to the slot.
Definition: View.cpp:334
dd4hep::DisplayConfiguration::ViewConfig::subdetectors
Configurations subdetectors
Definition: DisplayConfiguration.h:122
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::DisplayConfiguration::Defaults::load_geo
char load_geo
Definition: DisplayConfiguration.h:55
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::ElementList
Local implementation with overrides of the TEveElementList.
Definition: ElementList.h:35
dd4hep::View::CreateGeometry
virtual std::pair< bool, TEveElement * > CreateGeometry(DetElement de, const DisplayConfiguration::Config &cfg)
Create a new instance of the geometry of a sub-detector.
Definition: View.cpp:131
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
dd4hep::View::~View
virtual ~View()
Default destructor.
Definition: View.cpp:47
dd4hep::View::Build
virtual View & Build(TEveWindow *slot)
Build the view view and map it to the given slot.
Definition: View.cpp:58
dd4hep::View::ConfigureGeometryFromInfo
virtual void ConfigureGeometryFromInfo()
Configure a view with geo info. Used configuration if present.
Definition: View.cpp:138
Utilities.h
dd4hep::Display::GetViewConfiguration
const ViewConfig * GetViewConfiguration(const std::string &name) const
Access a data filter by name. Data filters are used to customize views.
Definition: Display.cpp:247
TEveElementList
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: ROOTClasses.h:13
dd4hep::View::eveScene
TEveScene * eveScene() const
Access to the Eve event scene.
Definition: View.h:138
dd4hep::View::m_config
const DisplayConfiguration::ViewConfig * m_config
Definition: View.h:58
dd4hep::View::GetGeoTopic
virtual TEveElementList & GetGeoTopic(const std::string &name)
Access/Create an geometry topic by name.
Definition: View.cpp:295
dd4hep::View::ImportEventElement
virtual TEveElement * ImportEventElement(TEveElement *element, TEveElementList *list)
Call an element to a event element list.
Definition: View.cpp:107
dd4hep::View::name
const std::string & name() const
Access to the view name/title.
Definition: View.h:81
dd4hep::Display::CalodataContext::slice
int slice
Definition: Display.h:69
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::Utilities::GetName
const char * GetName(T *p)
Definition: Utilities.h:45
dd4hep::Display::GetCaloHistogram
CalodataContext & GetCaloHistogram(const std::string &name)
Access to calo data histograms by name as defined in the configuration.
Definition: Display.cpp:196
dd4hep::View::AddToGlobalItems
virtual TEveElementList * AddToGlobalItems(const std::string &nam)
Add the view to the global list of eve objects.
Definition: View.cpp:81
dd4hep::View::m_geoTopics
Topics m_geoTopics
Definition: View.h:63
slot
View TEveWindowSlot * slot
Definition: MultiView.cpp:28
dd4hep::Detector::sensitiveDetector
virtual SensitiveDetector sensitiveDetector(const std::string &name) const =0
Retrieve a sensitive detector by its name from the detector description.
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::View::ImportGeoElement
virtual TEveElement * ImportGeoElement(TEveElement *element, TEveElementList *list)
Call an element to a geometry element list.
Definition: View.cpp:92
Display.h
dd4hep::View::CreateGeoScene
virtual View & CreateGeoScene()
Create the geometry scene.
Definition: View.cpp:324
dd4hep::DisplayConfiguration::Config::Values::defaults
Defaults defaults
Definition: DisplayConfiguration.h:97
dd4hep::DisplayConfiguration::Defaults::show_evt
char show_evt
Definition: DisplayConfiguration.h:56
dd4hep::View::CreateEventScene
virtual View & CreateEventScene()
Create the event scene.
Definition: View.cpp:314
dd4hep::Display::detectorDescription
Detector & detectorDescription() const
Access to geometry hub.
Definition: Display.cpp:158
dd4hep::Annotation::DefaultMargin
static float DefaultMargin()
Default margin for placement in bottom left corner.
Definition: Annotation.cpp:54
dd4hep::View::ImportGeoTopic
virtual TEveElement * ImportGeoTopic(TEveElement *element, TEveElementList *list)
Call an element to a geometry element list.
Definition: View.cpp:102
dd4hep::Display::CalodataContext::config
DisplayConfiguration::Config config
Definition: Display.h:73
dd4hep::View::ImportEventTopics
virtual void ImportEventTopics()
Import event typics after creation.
Definition: View.cpp:284
dd4hep::View::ConfigureEventFromInfo
virtual void ConfigureEventFromInfo()
Configure a view with event info. Used configuration if present.
Definition: View.cpp:230
dd4hep::View::ConfigureEventFromGlobal
virtual void ConfigureEventFromGlobal()
Configure an event view by default from the global event scene.
Definition: View.cpp:237
dd4hep::View::m_geoScene
TEveScene * m_geoScene
Reference to the geometry scene.
Definition: View.h:53
dd4hep::View::viewer
TEveViewer * viewer() const
Access to the Eve viewer.
Definition: View.h:84
dd4hep::DisplayConfiguration::Config
Container with full display configuration.
Definition: DisplayConfiguration.h:92
dd4hep::DisplayConfiguration::CALODATA
@ CALODATA
Definition: DisplayConfiguration.h:46
dd4hep::Utilities::LoadDetElement
std::pair< bool, TEveElement * > LoadDetElement(DetElement element, int levels, TEveElement *parent)
Definition: Utilities.cpp:190
ElementList.h
dd4hep::View::ImportGeoTopics
virtual void ImportGeoTopics(const std::string &title)
Call to import geometry topics. If title is empty, do not add to global item list.
Definition: View.cpp:205
dd4hep::DisplayConfiguration::DETELEMENT
@ DETELEMENT
Definition: DisplayConfiguration.h:47
dd4hep::DisplayConfiguration::Config::name
std::string name
Definition: DisplayConfiguration.h:103
dd4hep::DisplayConfiguration::ViewConfig
View configuration.
Definition: DisplayConfiguration.h:119
dd4hep::DetElement::Children
std::map< std::string, DetElement > Children
Definition: DetElement.h:206
dd4hep::Annotation
Class to add annotations to eve viewers.
Definition: Annotation.h:34
dd4hep::View::CreateScenes
virtual View & CreateScenes()
Create the geometry and the event scene.
Definition: View.cpp:306
dd4hep::View::m_name
std::string m_name
The name of the view.
Definition: View.h:61
dd4hep::View::m_global
TEveElementList * m_global
Reference to the global item (if added.
Definition: View.h:57
dd4hep::View::m_view
TEveViewer * m_view
Reference to the view.
Definition: View.h:51
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::View::Initialize
virtual void Initialize()
Initialize the view port.
Definition: View.cpp:63
dd4hep::SensitiveDetector::readout
Readout readout() const
Access readout structure of the sensitive detector.
Definition: DetElement.cpp:420
dd4hep::View
class View View.h DDEve/View.h
Definition: View.h:45
dd4hep::Display::CalodataContext
Calorimeter data context for the DDEve event display.
Definition: Display.h:68
dd4hep::Display::UnregisterEvents
virtual void UnregisterEvents(View *view)
Unregister from the main event scene.
Definition: Display.cpp:264
InstanceCount.h
View.h
dd4hep::View::m_eveScene
TEveScene * m_eveScene
Reference to the event scene.
Definition: View.h:55
dd4hep::View::m_showGlobal
bool m_showGlobal
Definition: View.h:65
dd4hep::Display::manager
TEveManager & manager() const
Access to the EVE manager.
Definition: Display.h:131
Annotation.h
dd4hep::View::ImportGeo
virtual void ImportGeo(const std::string &topic, TEveElement *element)
Call to import geometry elements into topics.
Definition: View.cpp:215
dd4hep::DisplayConfiguration::Config::use
std::string use
Definition: DisplayConfiguration.h:105
dd4hep::View::ConfigureEvent
virtual void ConfigureEvent(const DisplayConfiguration::ViewConfig &config)
Configure a single event scene view.
Definition: View.cpp:244
dd4hep::DisplayConfiguration::Config::type
int type
Definition: DisplayConfiguration.h:106