DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
View.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 // Original Author: Matevz Tadel 2009 (MultiView.C)
13 //
14 //==========================================================================
15 
16 // Framework include files
17 #include "DDEve/View.h"
18 #include "DDEve/Display.h"
19 #include "DDEve/ElementList.h"
20 #include "DDEve/Utilities.h"
21 #include "DDEve/Annotation.h"
22 #include "DD4hep/InstanceCount.h"
23 
24 // Eve include files
25 #include <TEveManager.h>
26 #include <TEveWindow.h>
27 #include <TEveCalo.h>
28 #include <TGLViewer.h>
29 
30 using namespace std;
31 using namespace DD4hep;
32 
33 template <typename T>
34 static inline typename T::const_iterator find(const T& c,const string& s) {
35  for(typename T::const_iterator i=c.begin(); i!=c.end(); ++i)
36  if ( (*i).name == s ) return i;
37  return c.end();
38 }
39 
41 View::View(Display* eve, const string& nam)
42  : m_eve(eve), m_view(0), m_geoScene(0), m_eveScene(0), m_global(0), m_name(nam), m_showGlobal(false)
43 {
46 }
47 
50  m_eve->UnregisterEvents(this);
51  for(Topics::iterator i=m_geoTopics.begin(); i!=m_geoTopics.end(); ++i)
52  (*i).second->DestroyElements();
53  if ( m_geoScene ) m_geoScene->DestroyElements();
54  if ( m_eveScene ) m_eveScene->DestroyElements();
55  if ( m_global ) m_global->DestroyElements();
57 }
58 
60 View& View::Build(TEveWindow* /* slot */) {
61  return *this;
62 }
63 
66  TEveScene *evt = this->eveScene();
67  TEveScene *geo = this->geoScene();
68  if ( evt ) evt->Repaint(kTRUE);
69  if ( geo ) geo->Repaint(kTRUE);
71  TGLViewer* glv = viewer()->GetGLViewer();
72  glv->PostSceneBuildSetup(kTRUE);
73  glv->SetSmartRefresh(kFALSE);
74  if ( m_eve->manager().GetViewers()->UseLightColorSet() )
75  glv->UseLightColorSet();
76  else
77  glv->UseDarkColorSet();
78  glv->RequestDraw(TGLRnrCtx::kLODHigh);
79  glv->SetSmartRefresh(kTRUE);
80 }
81 
84  if ( 0 == m_global ) {
85  m_global = new ElementList(nam.c_str(), nam.c_str(), true, true);
86  if ( m_geoScene ) m_global->AddElement(geoScene());
87  if ( m_eveScene ) m_global->AddElement(eveScene());
88  if ( m_showGlobal ) m_eve->manager().AddToListTree(m_global,kFALSE);
89  }
90  return m_global;
91 }
92 
94 TEveElement* View::ImportGeoElement(TEveElement* el, TEveElementList* list) {
95  TEveScene* s = dynamic_cast<TEveScene*>(el);
96  if ( s ) {
97  printf("ERROR: Adding a Scene [%s] to a list. This is BAD and causes crashes!\n",s->GetName());
98  }
99  if ( el ) list->AddElement(el);
100  return el;
101 }
102 
104 TEveElement* View::ImportGeoTopic(TEveElement* element, TEveElementList* list) {
105  return ImportGeoElement(element, list);
106 }
107 
109 TEveElement* View::ImportEventElement(TEveElement* el, TEveElementList* list) {
110  TEveScene* s = dynamic_cast<TEveScene*>(el);
111  if ( s ) {
112  printf("ERROR: Adding a Scene [%s] to a list. This is BAD and causes crashes!\n",s->GetName());
113  }
114  if ( el ) {
115  printout(INFO,"View","ImportElement %s [%s] into list: %s",
116  Utilities::GetName(el),el->IsA()->GetName(),list->GetName());
117  list->AddElement(el);
118  }
119  return el;
120 }
121 
123 pair<bool,TEveElement*>
126  TEveElementList& global = m_eve->GetGeoTopic(sd.isValid() ? "Sensitive" : "Structure");
127  TEveElement* elt = global.FindChild(de.name());
128  return pair<bool,TEveElement*>(true,elt);
129 }
130 
132 pair<bool,TEveElement*>
135  TEveElementList& topic = GetGeoTopic(sd.isValid() ? "Sensitive" : "Structure");
136  return Utilities::LoadDetElement(de,cfg.data.defaults.load_geo,&topic);
137 }
138 
141  printout(INFO,"View","+++ Configure Geometry for view %s Config=%p.",c_name(),m_config);
144 }
145 
148  TEveElementList* l = &m_eve->GetGeoTopic("Sensitive");
149  TEveElementList* t = &GetGeoTopic("Sensitive");
150  for(TEveElementList::List_i i=l->BeginChildren(); i!=l->EndChildren(); ++i)
151  ImportGeo(*t,*i);
152 
153  l = &m_eve->GetGeoTopic("Structure");
154  t = &GetGeoTopic("Structure");
155  for(TEveElementList::List_i i=l->BeginChildren(); i!=l->EndChildren(); ++i)
156  ImportGeo(*t,*i);
157 }
158 
161  string dets;
162  DisplayConfiguration::Configurations::const_iterator ic;
164  const DetElement::Children& c = m_eve->lcdd().world().children();
165  for( ic=config.subdetectors.begin(); ic != config.subdetectors.end(); ++ic) {
166  const DisplayConfiguration::Config& cfg = *ic;
167  string nam = cfg.name;
168  if ( nam == "global" ) {
169  m_view->AddScene(m_eve->manager().GetGlobalScene());
170  m_view->AddScene(m_eve->manager().GetEventScene());
171  dets += nam;
172  }
173  else if ( cfg.type == DisplayConfiguration::CALODATA ) {
174  // Note: The histogram grid must be handled like a geometry item.
176  if ( ctx.config.use.empty() ) ImportGeo(ctx.calo3D);
177  printout(INFO,"View","+++ %s: add detector %s %s",name().c_str(),nam.c_str(),ctx.config.use.c_str());
178  Color_t col = ctx.calo3D->GetDataSliceColor(ctx.slice);
179  Annotation* a = new Annotation(viewer(),nam.c_str(),Annotation::DefaultMargin(),legend_y,col);
180  legend_y += a->GetTextSize();
181  dets += nam + "(Calo3D) ";
182  }
183  else if ( cfg.type == DisplayConfiguration::DETELEMENT ) {
184  DetElement::Children::const_iterator i = c.find(nam);
185  if ( i != c.end() ) {
186  DetElement de = (*i).second;
188  TEveElementList& topic = GetGeoTopic(sd.isValid() ? "Sensitive" : "Structure");
189  pair<bool,TEveElement*> e(false,0);
190  if ( cfg.data.defaults.load_geo > 0 ) // Create a new instance
191  e = CreateGeometry(de,cfg); // with the given number of levels
192  else if ( cfg.data.defaults.load_geo < 0 ) // Use the global geometry instance
193  e = GetGlobalGeometry(de,cfg); // with the given number of levels
194  if ( e.first && e.second ) {
195  ImportGeo(topic,e.second);
196  }
197  dets += nam + "(Geo) ";
198  }
199  }
200  }
201  printout(INFO,"ViewConfiguration","+++ Configured geometry for view %s.",c_name());
202  printout(INFO,"ViewConfiguration","+++ Detectors:%s", dets.c_str());
203 }
204 
206 void View::ImportGeoTopics(const string& title) {
207  printout(INFO,"View","+++ %s: Import geometry topics.",c_name());
208  for(Topics::iterator i=m_geoTopics.begin(); i!=m_geoTopics.end(); ++i) {
209  printout(INFO,"ViewConfiguration","+++ Add topic %s",(*i).second->GetName());
210  ImportGeoTopic((*i).second,m_geoScene);
211  }
212  if ( !title.empty() ) AddToGlobalItems(title);
213 }
214 
216 void View::ImportGeo(const string& topic, TEveElement* element) {
217  ImportGeoElement(element,&GetGeoTopic(topic));
218 }
219 
221 void View::ImportGeo(TEveElementList& topic, TEveElement* element) {
222  ImportGeoElement(element,&topic);
223 }
224 
226 void View::ImportGeo(TEveElement* el) {
228 }
229 
232  printout(INFO,"View","+++ Import event data into view %s Config=%p.",c_name(),m_config);
235 }
236 
239  TEveElementList* l = m_eve->manager().GetEventScene();
240  for(TEveElementList::List_i i=l->BeginChildren(); i!=l->EndChildren(); ++i)
241  ImportEvent(*i);
242 }
243 
246  DetElement world = m_eve->lcdd().world();
247  const DetElement::Children& c = world.children();
248  DisplayConfiguration::Configurations::const_iterator ic;
249  for( ic=config.subdetectors.begin(); ic != config.subdetectors.end(); ++ic) {
250  const DisplayConfiguration::Config& cfg = *ic;
251  string nam = cfg.name;
252  if ( nam == "global" ) {
253  continue;
254  }
255  else if ( cfg.type == DisplayConfiguration::CALODATA ) {
256  continue;
257  }
258  else if ( cfg.type == DisplayConfiguration::COLLECTION ) {
259  // Not using the global scene!
260  if ( cfg.data.defaults.show_evt>0 ) {
261  TEveElement* child = m_eve->manager().GetEventScene()->FindChild(nam);
262  printout(INFO,"View","+++ Add collection:%s data:%p scene:%p",nam.c_str(),child,m_eveScene);
263  if ( child ) ImportEvent(child);
264  }
265  }
266  else if ( cfg.type == DisplayConfiguration::DETELEMENT ) {
267  // Not using the global scene!
268  DetElement::Children::const_iterator i = c.find(nam);
269  if ( i != c.end() && cfg.data.defaults.show_evt>0 ) {
271  if ( sd.isValid() ) {
272  // This should be configurable!
273  const char* coll = sd.readout().name();
274  TEveElement* child = m_eve->manager().GetEventScene()->FindChild(coll);
275  printout(INFO,"View","+++ Add detector event %s collection:%s data:%p scene:%p",
276  nam.c_str(),coll,child,m_eveScene);
277  if ( child ) ImportEvent(child);
278  }
279  }
280  }
281  }
282 }
283 
286 }
287 
289 void View::ImportEvent(TEveElement* el) {
290  if ( m_eveScene ) {
292  }
293 }
294 
296 TEveElementList& View::GetGeoTopic(const string& nam) {
297  Topics::iterator i=m_geoTopics.find(nam);
298  if ( i == m_geoTopics.end() ) {
299  TEveElementList* topic = new ElementList(nam.c_str(), nam.c_str(), true, true);
300  m_geoTopics[nam] = topic;
301  return *topic;
302  }
303  return *((*i).second);
304 }
305 
308  // Scenes
309  CreateGeoScene();
311  return *this;
312 }
313 
316  if ( 0 == m_eveScene ) {
317  string nam = m_name+" - Event Data";
318  string tool = m_name+" - Scene holding projected event-data for the view.";
319  m_eveScene = m_eve->manager().SpawnNewScene(nam.c_str(), tool.c_str());
320  }
321  return *this;
322 }
323 
326  if ( 0 == m_geoScene ) {
327  string nam = m_name+" - Geometry";
328  string tool = m_name+" - Scene holding projected geometry for the view.";
329  m_geoScene = m_eve->manager().SpawnNewScene(nam.c_str(), tool.c_str());
330  }
331  return *this;
332 }
333 
335 View& View::Map(TEveWindow* slot) {
336  slot->MakeCurrent();
337  m_view = m_eve->manager().SpawnNewViewer(m_name.c_str(), "");
338  if ( m_geoScene ) m_view->AddScene(m_geoScene);
339  if ( m_eveScene ) m_view->AddScene(m_eveScene);
340  return *this;
341 }
Handle class to hold the information of a sensitive detector.
Definition: Detector.h:47
const ViewConfig * GetViewConfiguration(const std::string &name) const
Access a data filter by name. Data filters are used to customize views.
Definition: Display.cpp:268
Display * m_eve
Definition: View.h:53
virtual DetElement world() const =0
Return reference to the top-most (world) detector element.
TEveManager & manager() const
Access to the EVE manager.
Definition: Display.h:115
const char * name() const
Access the object name (or "" if not supported by the object)
Definition: Handle.inl:36
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: ROOTClasses.h:10
TEveScene * geoScene() const
Access to the Eve geometry scene.
Definition: View.h:108
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:124
virtual TEveElement * ImportEventElement(TEveElement *element, TEveElementList *list)
Call an element to a event element list.
Definition: View.cpp:109
Topics m_geoTopics
Definition: View.h:67
std::string m_name
The name of the view.
Definition: View.h:65
virtual void ImportEvent(TEveElement *element)
Call to import event elements into the main event scene.
Definition: View.cpp:289
std::pair< bool, TEveElement * > LoadDetElement(Geometry::DetElement element, int levels, TEveElement *parent)
Definition: Utilities.cpp:189
static void decrement(T *)
Decrement count according to type information.
virtual TEveElementList & GetGeoTopic(const std::string &name)
Access/Create an geometry topic by name.
Definition: View.cpp:296
CalodataContext & GetCaloHistogram(const std::string &name)
Access to calo data histograms by name as defined in the configuration.
Definition: Display.cpp:217
bool m_showGlobal
Definition: View.h:69
Local implementation with overrides of the TEveElementList.
Definition: ElementList.h:36
virtual void ConfigureEventFromInfo()
Configure a view with event info. Used configuration if present.
Definition: View.cpp:231
DisplayConfiguration::Config config
Definition: Display.h:73
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:206
const Children & children() const
Access to the list of children.
Definition: Detector.cpp:207
TGeoShape * s
Definition: Volumes.cpp:294
Geometry::LCDD & lcdd() const
Access to geometry hub.
Definition: Display.cpp:179
virtual View & Map(TEveWindow *slot)
Map the view view to the slot.
Definition: View.cpp:335
virtual SensitiveDetector sensitiveDetector(const std::string &name) const =0
Retrieve a sensitive detector by it's name from the detector description.
return e
Definition: Volumes.cpp:297
static float DefaultMargin()
Default margin for placement in bottom left corner.
Definition: Annotation.cpp:55
virtual std::pair< bool, TEveElement * > GetGlobalGeometry(DetElement de, const DisplayConfiguration::Config &cfg)
Access the global instance of the subdetector geometry.
Definition: View.cpp:124
virtual void ImportGeo(const std::string &topic, TEveElement *element)
Call to import geometry elements into topics.
Definition: View.cpp:216
union DD4hep::DisplayConfiguration::Config::Values data
virtual void UnregisterEvents(View *view)
Unregister from the main event scene.
Definition: Display.cpp:285
virtual void ConfigureGeometryFromInfo()
Configure a view with geo info. Used configuration if present.
Definition: View.cpp:140
View TEveWindowSlot * slot
Definition: MultiView.cpp:30
const DisplayConfiguration::ViewConfig * m_config
Definition: View.h:62
virtual TEveElementList & GetGeoTopic(const std::string &name)
Access/Create an geometry topic by name.
Definition: Display.cpp:471
TEveScene * m_eveScene
Reference to the event scene.
Definition: View.h:59
TEveViewer * m_view
Reference to the view.
Definition: View.h:55
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:133
virtual TEveElementList * AddToGlobalItems(const std::string &nam)
Add the view to the global list of eve objects.
Definition: View.cpp:83
const char * GetName(T *p)
Definition: Utilities.h:45
virtual void ConfigureGeometryFromGlobal()
Configure a single geometry view by default from the global geometry scene with all subdetectors...
Definition: View.cpp:147
class View View.h DDEve/View.h
Definition: View.h:46
virtual ~View()
Default destructor.
Definition: View.cpp:49
const char * c_name() const
Definition: View.h:86
static T::const_iterator find(const T &c, const string &s)
Definition: View.cpp:34
TEveScene * m_geoScene
Reference to the geometry scene.
Definition: View.h:57
virtual void ImportEventTopics()
Import event typics after creation.
Definition: View.cpp:285
TEveScene * eveScene() const
Access to the Eve event scene.
Definition: View.h:142
virtual View & CreateGeoScene()
Create the geometry scene.
Definition: View.cpp:325
TEveElementList * m_global
Reference to the global item (if added.
Definition: View.h:61
virtual View & Build(TEveWindow *slot)
Build the view view and map it to the given slot.
Definition: View.cpp:60
virtual View & CreateScenes()
Create the geometry and the event scene.
Definition: View.cpp:307
virtual TEveElement * ImportGeoTopic(TEveElement *element, TEveElementList *list)
Call an element to a geometry element list.
Definition: View.cpp:104
virtual void Initialize()
Initialize the view port.
Definition: View.cpp:65
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
static float DefaultTextSize()
Default text size.
Definition: Annotation.cpp:51
Handle class describing a detector element.
Definition: Detector.h:172
virtual void ConfigureEvent(const DisplayConfiguration::ViewConfig &config)
Configure a single event scene view.
Definition: View.cpp:245
Readout readout() const
Access readout structure of the sensitive detector.
Definition: Detector.cpp:451
TEveViewer * viewer() const
Access to the Eve viewer.
Definition: View.h:88
virtual void ConfigureGeometry(const DisplayConfiguration::ViewConfig &config)
Configure a single geometry view.
Definition: View.cpp:160
virtual View & CreateEventScene()
Create the event scene.
Definition: View.cpp:315
std::map< std::string, DetElement > Children
Definition: Detector.h:202
virtual TEveElement * ImportGeoElement(TEveElement *element, TEveElementList *list)
Call an element to a geometry element list.
Definition: View.cpp:94
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Definition: Printout.cpp:111
virtual void ConfigureEventFromGlobal()
Configure an event view by default from the global event scene.
Definition: View.cpp:238
The main class of the DDEve display.
Definition: Display.h:57
const std::string & name() const
Access to the view name/title.
Definition: View.h:85
Class to add annotations to eve viewers.
Definition: Annotation.h:35