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
DisplayConfigurationParser.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 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DD4hep/LCDD.h"
17 #include "DD4hep/LCDDLoad.h"
18 #include "DD4hep/Printout.h"
19 #include "XML/Conversions.h"
20 #include "XML/XMLElements.h"
21 #include "XML/DocumentHandler.h"
23 
24 #include "DDEve/Display.h"
26 
27 // C/C++ include files
28 #include <stdexcept>
29 
30 using namespace std;
31 using namespace DD4hep;
32 
33 
34 namespace DD4hep { namespace {
36  class ddeve;
37  class view;
38  class panel;
39  class calodata;
40  class calodata_configs;
41  class detelement;
42  class include;
43  class display;
44  class collection;
45  class collection_configs;
46  }
47 
50 
52  template <> void Converter<ddeve>::operator()(xml_h seq) const;
53  template <> void Converter<display>::operator()(xml_h seq) const;
54  template <> void Converter<view>::operator()(xml_h seq) const;
55  template <> void Converter<panel>::operator()(xml_h seq) const;
56  template <> void Converter<include>::operator()(xml_h seq) const;
57  template <> void Converter<calodata>::operator()(xml_h e) const;
58  template <> void Converter<calodata_configs>::operator()(xml_h e) const;
59  template <> void Converter<collection>::operator()(xml_h e) const;
60  template <> void Converter<collection_configs>::operator()(xml_h e) const;
61  template <> void Converter<detelement>::operator()(xml_h seq) const;
62 }
63 
64 #define DECL_TAG(x) XML::Strng_t u_##x(#x)
65 namespace {
66  DECL_TAG(clone);
67  DECL_TAG(load_geo);
68  DECL_TAG(show_evt);
69  DECL_TAG(use);
70  DECL_TAG(emax);
71  DECL_TAG(hits);
72  DECL_TAG(n_eta);
73  DECL_TAG(eta_min);
74  DECL_TAG(eta_max);
75  DECL_TAG(n_phi);
76  DECL_TAG(phi_min);
77  DECL_TAG(phi_max);
78  DECL_TAG(calodata);
79  DECL_TAG(towerH);
80  DECL_TAG(visLevel);
81  DECL_TAG(loadLevel);
82 }
83 
84 static void extract(DisplayConfiguration::Config& c, xml_h e, int typ) {
85  c.name = e.attr<string>(_U(name));
86  c.type = typ;
87  c.data.defaults.show_evt = e.hasAttr(u_show_evt) ? e.attr<int>(u_show_evt) : 1;
88  c.data.defaults.load_geo = e.hasAttr(u_load_geo) ? e.attr<int>(u_load_geo) : -1;
89  c.data.defaults.color = e.hasAttr(_U(color)) ? e.attr<int>(_U(color)) : 0xBBBBBB;
90  c.data.defaults.alpha = e.hasAttr(_U(alpha)) ? e.attr<float>(_U(alpha)) : -1.0;
91  c.data.calo3d.emax = e.hasAttr(u_emax) ? e.attr<float>(u_emax) : 25.0;
92  c.data.calo3d.towerH = e.hasAttr(u_towerH) ? e.attr<float>(u_towerH) : 25.0;
93  if ( e.hasAttr(_U(dz)) ) c.data.calo3d.dz = e.attr<float>(_U(dz));
94  if ( e.hasAttr(_U(rmin)) ) c.data.calo3d.rmin = e.attr<float>(_U(rmin));
95  if ( e.hasAttr(_U(threshold)) ) c.data.calo3d.threshold = e.attr<float>(_U(threshold));
96  if ( e.hasAttr(u_hits) ) c.hits = e.attr<string>(u_hits);
97  if ( e.hasAttr(u_use) ) c.use = e.attr<string>(u_use);
98 }
99 
108 template <> void Converter<detelement>::operator()(xml_h e) const {
109  Configurations* configs = (Configurations*)param;
111  extract(c,e,DisplayConfiguration::DETELEMENT);
112  configs->push_back(c);
113 }
114 template <> void Converter<panel>::operator()(xml_h e) const {
115  Configurations* configs = (Configurations*)param;
117  extract(c,e,DisplayConfiguration::PANEL);
118  configs->push_back(c);
119 }
120 template <> void Converter<calodata_configs>::operator()(xml_h e) const {
121  Configurations* configs = (Configurations*)param;
123  extract(c,e,DisplayConfiguration::CALODATA);
124  configs->push_back(c);
125 }
126 
127 template <> void Converter<collection_configs>::operator()(xml_h e) const {
128  Configurations* configs = (Configurations*)param;
130  c.name = e.attr<string>(_U(name));
131  c.type = DisplayConfiguration::COLLECTION;
132  c.data.hits.color = e.hasAttr(_U(color)) ? e.attr<int>(_U(color)) : 0xBBBBBB;
133  c.data.hits.alpha = e.hasAttr(_U(alpha)) ? e.attr<float>(_U(alpha)) : -1.0;
134  c.data.hits.emax = e.hasAttr(u_emax) ? e.attr<float>(u_emax) : 25.0;
135  c.data.hits.towerH = e.hasAttr(u_towerH) ? e.attr<float>(u_towerH) : 25.0;
136  c.data.hits.threshold = e.hasAttr(_U(threshold)) ? e.attr<float>(_U(threshold)) : 0.0;
137  if ( e.hasAttr(u_hits) ) c.hits = e.attr<string>(u_hits);
138  if ( e.hasAttr(u_use) ) c.use = e.attr<string>(u_use);
139  configs->push_back(c);
140 }
141 
153 template <> void Converter<view>::operator()(xml_h e) const {
154  ViewConfigurations* configs = (ViewConfigurations*)param;
156  extract(c,e,DisplayConfiguration::VIEW);
157  c.type = e.attr<string>(_U(type));
158  c.show_structure = e.hasAttr(_U(structure)) ? e.attr<bool>(_U(structure)) : true;
159  c.show_sensitive = e.hasAttr(_U(sensitive)) ? e.attr<bool>(_U(sensitive)) : true;
160  c.name = e.attr<string>(_U(name));
161  printout(INFO,"DisplayConfiguration","+++ View: %s sensitive:%d structure:%d.",
162  c.name.c_str(), c.show_sensitive, c.show_structure);
167  configs->push_back(c);
168 }
169 
181 template <> void Converter<calodata>::operator()(xml_h e) const {
182  Configurations* configs = (Configurations*)param;
184  c.name = e.attr<string>(_U(name));
185  c.type = DisplayConfiguration::CALODATA;
186  if ( e.hasAttr(u_use) ) {
187  c.use = e.attr<string>(u_use);
188  c.hits = e.attr<string>(u_hits);
189  }
190  else {
191  c.hits = e.attr<string>(u_hits);
192  c.data.calodata.n_eta = e.attr<int>(u_n_eta);
193  c.data.calodata.eta_min = e.attr<float>(u_eta_min);
194  c.data.calodata.eta_max = e.attr<float>(u_eta_max);
195  c.data.calodata.n_phi = e.attr<int>(u_n_phi);
196  c.data.calodata.phi_min = e.attr<float>(u_phi_min);
197  c.data.calodata.phi_max = e.attr<float>(u_phi_max);
198  c.data.calodata.dz = e.attr<float>(_U(dz));
199  c.data.calodata.rmin = e.attr<float>(_U(rmin));
200  c.data.calodata.color = e.attr<int>(_U(color));
201  c.data.calodata.alpha = e.attr<float>(_U(alpha));
202  c.data.calodata.emax = e.hasAttr(u_emax) ? e.attr<float>(u_emax) : 25.0;
203  if ( e.hasAttr(u_towerH) ) c.data.calodata.towerH = e.attr<float>(u_towerH);
204  if ( e.hasAttr(_U(threshold)) ) c.data.calodata.threshold = e.attr<float>(_U(threshold));
205  }
206  configs->push_back(c);
207 }
208 
220 template <> void Converter<collection>::operator()(xml_h e) const {
221  Configurations* configs = (Configurations*)param;
223  c.name = e.attr<string>(_U(name));
224  c.type = DisplayConfiguration::COLLECTION;
225  c.hits = e.attr<string>(u_hits);
226  c.data.hits.size = e.attr<float>(_U(size));
227  c.data.hits.type = e.attr<float>(_U(type));
228  c.data.hits.color = e.hasAttr(_U(color)) ? e.attr<int>(_U(color)) : kRed;
229  c.data.hits.alpha = e.hasAttr(_U(alpha)) ? e.attr<float>(_U(alpha)) : 1.0;
230  c.data.hits.width = e.hasAttr(_U(width)) ? e.attr<float>(_U(width)) : 1.0;
231  c.data.hits.emax = e.hasAttr(u_emax) ? e.attr<float>(u_emax) : 25.0;
232  c.data.hits.towerH = e.hasAttr(u_towerH) ? e.attr<float>(u_towerH) : 25.0;
233  c.data.hits.threshold = e.hasAttr(_U(threshold)) ? e.attr<float>(_U(threshold)) : 0;
234  configs->push_back(c);
235 }
236 
248 template <> void Converter<include>::operator()(xml_h e) const {
249  LCDDLoad* load = dynamic_cast<LCDDLoad*>(&this->lcdd);
250  load->processXML(e,e.attr<string>(_U(ref)));
251 }
252 
264 template <> void Converter<display>::operator()(xml_h e) const {
265  Display* d = (Display*)param;
266  if ( e.hasAttr(_Unicode(visLevel)) ) d->setVisLevel(e.attr<int>(_Unicode(visLevel)));
267  if ( e.hasAttr(_Unicode(eventHandler)) ) d->setEventHandlerName(e.attr<std::string>(_Unicode(eventHandler)));
268  if ( e.hasAttr(_Unicode(loadLevel)) ) d->setLoadLevel(e.attr<int>(_Unicode(loadLevel)));
269 }
270 
282 template <> void Converter<ddeve>::operator()(xml_h e) const {
283  Display* disp = (Display*)param;
284  DisplayConfiguration cfg(disp);
286  xml_coll_t(e,_Unicode(display)).for_each(Converter<display>(lcdd,disp));
287  xml_coll_t(e,_Unicode(include)).for_each(Converter<include>(lcdd,disp));
288  xml_coll_t(e,_Unicode(calodata)).for_each(Converter<calodata>(lcdd,&cfg.calodata));
289  xml_coll_t(e,_Unicode(collection)).for_each(Converter<collection>(lcdd,&cfg.collections));
290  xml_coll_t(e,_Unicode(view)).for_each(Converter<view>(lcdd,&cfg.views));
291  disp->ImportConfiguration(cfg);
292 }
293 
294 #include "TEveProjections.h"
301 static long setup_DDEve(lcdd_t& lcdd, const xml_h& e) {
302  Display* display = lcdd.extension<Display>();
303  static bool first = true;
304  if ( first ) {
305  first = false;
306 #define add_root_enum(x) XML::_toDictionary(XML::Strng_t(#x),int(x))
307  add_root_enum(kOrange);
308  add_root_enum(kBlue);
309  add_root_enum(kAzure);
310  add_root_enum(kRed);
311  add_root_enum(kCyan);
312  add_root_enum(kPink);
313  add_root_enum(kGreen);
314  add_root_enum(kViolet);
315  add_root_enum(kYellow);
316  add_root_enum(kTeal);
317  add_root_enum(kMagenta);
318  add_root_enum(kSpring);
319  add_root_enum(kTeal);
320 
321  add_root_enum(kDot);
322  add_root_enum(kPlus);
323  add_root_enum(kStar);
324  add_root_enum(kCircle);
325  add_root_enum(kMultiply);
326  add_root_enum(kFullDotSmall);
327  add_root_enum(kFullDotMedium);
328  add_root_enum(kFullDotLarge);
329  add_root_enum(kFullCircle);
330  add_root_enum(kFullSquare);
331  add_root_enum(kFullTriangleUp);
332  add_root_enum(kFullTriangleDown);
333  add_root_enum(kOpenCircle);
334  add_root_enum(kOpenSquare);
335  add_root_enum(kOpenTriangleUp);
336  add_root_enum(kOpenDiamond);
337  add_root_enum(kOpenCross);
338  add_root_enum(kFullStar);
339  add_root_enum(kOpenStar);
340  add_root_enum(kOpenTriangleDown);
341  add_root_enum(kFullDiamond);
342  add_root_enum(kFullCross);
343  add_root_enum(TEveProjection::kPT_RPhi);
344  add_root_enum(TEveProjection::kPT_RhoZ);
345  add_root_enum(TEveProjection::kPT_3D);
346  add_root_enum(TEveProjection::kPP_Plane);
347  add_root_enum(TEveProjection::kPP_Distort);
348  add_root_enum(TEveProjection::kPP_Full);
349  add_root_enum(TEveProjection::kGM_Polygons);
350  add_root_enum(TEveProjection::kGM_Segments);
351  }
352  (DD4hep::Converter<DD4hep::ddeve>(lcdd,display))(e);
353  return 1;
354 }
#define add_root_enum(x)
virtual void processXML(const std::string &fname, XML::UriReader *entity_resolver=0)
Process XML unit and adopt all data from source structure.
Definition: LCDDLoad.cpp:47
static void extract(DisplayConfiguration::Config &c, xml_h e, int typ)
T attr(const Attribute a) const
Access typed attribute value by the XmlAttr.
Definition: XMLElements.h:435
bool hasAttr(const XmlChar *t) const
Check for the existence of a named attribute.
void setVisLevel(int new_level)
Set Vis level in geo manager (either from XML or BEFORE XML file was loaded)
Definition: Display.h:119
T * extension(bool alert=true) const
Access extension element by the type.
Definition: LCDD.h:300
void setLoadLevel(int new_level)
Set Eve Geometry load level in manager (either from XML or BEFORE XML file was loaded) ...
Definition: Display.h:121
Data implementation class of the LCDD interface.
Definition: LCDDLoad.h:42
#define _U(a)
Definition: XMLTags.h:27
std::list< ViewConfig > ViewConfigurations
std::vector< Config > Configurations
return e
Definition: Volumes.cpp:297
union DD4hep::DisplayConfiguration::Config::Values data
static pair< TClass *, void * > load(TBranch *branch, int entry)
#define DECL_TAG(x)
DisplayConfiguration DisplayConfiguration.h DDEve/DisplayConfiguration.h.
Basic conversion objects for handling DD4hep XML files.
Definition: Conversions.h:38
DisplayConfiguration::ViewConfigurations ViewConfigurations
void setEventHandlerName(std::string eventHandlerName)
Set Event Handler Plugin name.
Definition: Display.h:123
DisplayConfiguration::Configurations Configurations
static long setup_DDEve(lcdd_t &lcdd, const xml_h &e)
void ImportConfiguration(const DisplayConfiguration &config)
Import configuration parameters.
Definition: Display.cpp:204
#define _Unicode(a)
Definition: XMLTags.h:28
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:361
DD4hep::XML::Collection_t xml_coll_t
void for_each(T oper) const
Loop processor using function object.
Definition: XMLElements.h:587
#define DECLARE_XML_DOC_READER(name, func)
Definition: Factories.h:236
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Definition: Printout.cpp:111
The main class of the DDEve display.
Definition: Display.h:57