DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
DisplayConfigurationParser.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
15 #include <DD4hep/Detector.h>
16 #include <DD4hep/DetectorLoad.h>
17 #include <DD4hep/Printout.h>
18 #include <XML/Conversions.h>
19 #include <XML/XMLElements.h>
20 #include <XML/DocumentHandler.h>
22 
23 #include <DDEve/Display.h>
25 
26 // C/C++ include files
27 #include <stdexcept>
28 
29 using namespace dd4hep;
30 
31 namespace dd4hep { namespace {
33  class ddeve;
34  class view;
35  class panel;
36  class calodata;
37  class calodata_configs;
38  class detelement;
39  class include;
40  class display;
41  class collection;
42  class collection_configs;
43  }
44 
47 
49  template <> void Converter<ddeve>::operator()(xml_h seq) const;
50  template <> void Converter<display>::operator()(xml_h seq) const;
51  template <> void Converter<view>::operator()(xml_h seq) const;
52  template <> void Converter<panel>::operator()(xml_h seq) const;
53  template <> void Converter<include>::operator()(xml_h seq) const;
54  template <> void Converter<calodata>::operator()(xml_h e) const;
55  template <> void Converter<calodata_configs>::operator()(xml_h e) const;
56  template <> void Converter<collection>::operator()(xml_h e) const;
57  template <> void Converter<collection_configs>::operator()(xml_h e) const;
58  template <> void Converter<detelement>::operator()(xml_h seq) const;
59 }
60 
61 #define DECL_TAG(x) xml::Strng_t u_##x(#x)
62 namespace {
63  DECL_TAG(clone);
64  DECL_TAG(load_geo);
65  DECL_TAG(show_evt);
66  DECL_TAG(use);
67  DECL_TAG(emax);
68  DECL_TAG(hits);
69  DECL_TAG(n_eta);
70  DECL_TAG(eta_min);
71  DECL_TAG(eta_max);
72  DECL_TAG(n_phi);
73  DECL_TAG(phi_min);
74  DECL_TAG(phi_max);
75  DECL_TAG(calodata);
76  DECL_TAG(towerH);
77  DECL_TAG(visLevel);
78  DECL_TAG(loadLevel);
79 }
80 
81 static void extract(DisplayConfiguration::Config& c, xml_h e, int typ) {
82  c.name = e.attr<std::string>(_U(name));
83  c.type = typ;
84  c.data.defaults.show_evt = e.hasAttr(u_show_evt) ? e.attr<int>(u_show_evt) : 1;
85  c.data.defaults.load_geo = e.hasAttr(u_load_geo) ? e.attr<int>(u_load_geo) : -1;
86  c.data.defaults.color = e.hasAttr(_U(color)) ? e.attr<int>(_U(color)) : 0xBBBBBB;
87  c.data.defaults.alpha = e.hasAttr(_U(alpha)) ? e.attr<float>(_U(alpha)) : -1.0;
88  c.data.calo3d.emax = e.hasAttr(u_emax) ? e.attr<float>(u_emax) : 25.0;
89  c.data.calo3d.towerH = e.hasAttr(u_towerH) ? e.attr<float>(u_towerH) : 25.0;
90  if ( e.hasAttr(_U(dz)) ) c.data.calo3d.dz = e.attr<float>(_U(dz));
91  if ( e.hasAttr(_U(rmin)) ) c.data.calo3d.rmin = e.attr<float>(_U(rmin));
92  if ( e.hasAttr(u_use) ) c.use = e.attr<std::string>(u_use);
93  if ( e.hasAttr(u_hits) ) c.hits = e.attr<std::string>(u_hits);
94  if ( e.hasAttr(_U(threshold)) ) c.data.calo3d.threshold = e.attr<float>(_U(threshold));
95 }
96 
105 template <> void Converter<detelement>::operator()(xml_h e) const {
106  Configurations* configs = (Configurations*)param;
109  configs->push_back(c);
110 }
111 template <> void Converter<panel>::operator()(xml_h e) const {
112  Configurations* configs = (Configurations*)param;
114  extract(c,e,DisplayConfiguration::PANEL);
115  configs->push_back(c);
116 }
117 template <> void Converter<calodata_configs>::operator()(xml_h e) const {
118  Configurations* configs = (Configurations*)param;
120  extract(c,e,DisplayConfiguration::CALODATA);
121  configs->push_back(c);
122 }
123 
124 template <> void Converter<collection_configs>::operator()(xml_h e) const {
125  Configurations* configs = (Configurations*)param;
127  c.name = e.attr<std::string>(_U(name));
129  c.data.hits.color = e.hasAttr(_U(color)) ? e.attr<int>(_U(color)) : 0xBBBBBB;
130  c.data.hits.alpha = e.hasAttr(_U(alpha)) ? e.attr<float>(_U(alpha)) : -1.0;
131  c.data.hits.emax = e.hasAttr(u_emax) ? e.attr<float>(u_emax) : 25.0;
132  c.data.hits.towerH = e.hasAttr(u_towerH) ? e.attr<float>(u_towerH) : 25.0;
133  c.data.hits.threshold = e.hasAttr(_U(threshold)) ? e.attr<float>(_U(threshold)) : 0.0;
134  if ( e.hasAttr(u_hits) ) c.hits = e.attr<std::string>(u_hits);
135  if ( e.hasAttr(u_use) ) c.use = e.attr<std::string>(u_use);
136  configs->push_back(c);
137 }
138 
150 template <> void Converter<view>::operator()(xml_h e) const {
151  ViewConfigurations* configs = (ViewConfigurations*)param;
153  extract(c,e,DisplayConfiguration::VIEW);
154  c.name = e.attr<std::string>(_U(name));
155  c.type = e.attr<std::string>(_U(type));
156  c.show_structure = e.hasAttr(_U(structure)) ? e.attr<bool>(_U(structure)) : true;
157  c.show_sensitive = e.hasAttr(_U(sensitive)) ? e.attr<bool>(_U(sensitive)) : true;
158  printout(INFO,"DisplayConfiguration","+++ View: %s sensitive:%d structure:%d.",
159  c.name.c_str(), c.show_sensitive, c.show_structure);
160  xml_coll_t(e,_Unicode(panel)).for_each(Converter<panel>(description,&c.subdetectors));
161  xml_coll_t(e,_Unicode(detelement)).for_each(Converter<detelement>(description,&c.subdetectors));
162  xml_coll_t(e,_Unicode(calodata)).for_each(Converter<calodata_configs>(description,&c.subdetectors));
163  xml_coll_t(e,_Unicode(collection)).for_each(Converter<collection_configs>(description,&c.subdetectors));
164  configs->push_back(c);
165 }
166 
178 template <> void Converter<calodata>::operator()(xml_h e) const {
179  Configurations* configs = (Configurations*)param;
181  c.name = e.attr<std::string>(_U(name));
183  if ( e.hasAttr(u_use) ) {
184  c.use = e.attr<std::string>(u_use);
185  c.hits = e.attr<std::string>(u_hits);
186  }
187  else {
188  c.hits = e.attr<std::string>(u_hits);
189  c.data.calodata.n_eta = e.attr<int>(u_n_eta);
190  c.data.calodata.eta_min = e.attr<float>(u_eta_min);
191  c.data.calodata.eta_max = e.attr<float>(u_eta_max);
192  c.data.calodata.n_phi = e.attr<int>(u_n_phi);
193  c.data.calodata.phi_min = e.attr<float>(u_phi_min);
194  c.data.calodata.phi_max = e.attr<float>(u_phi_max);
195  c.data.calodata.dz = e.attr<float>(_U(dz));
196  c.data.calodata.rmin = e.attr<float>(_U(rmin));
197  c.data.calodata.color = e.attr<int>(_U(color));
198  c.data.calodata.alpha = e.attr<float>(_U(alpha));
199  c.data.calodata.emax = e.hasAttr(u_emax) ? e.attr<float>(u_emax) : 25.0;
200  if ( e.hasAttr(u_towerH) ) c.data.calodata.towerH = e.attr<float>(u_towerH);
201  if ( e.hasAttr(_U(threshold)) ) c.data.calodata.threshold = e.attr<float>(_U(threshold));
202  }
203  configs->push_back(c);
204 }
205 
217 template <> void Converter<collection>::operator()(xml_h e) const {
218  Configurations* configs = (Configurations*)param;
220  c.name = e.attr<std::string>(_U(name));
221  c.hits = e.attr<std::string>(u_hits);
223  c.use = e.hasAttr(u_use) ? e.attr<std::string>(u_use) : std::string();
224  c.data.hits.size = e.attr<float>(_U(size));
225  c.data.hits.type = e.attr<float>(_U(type));
226  c.data.hits.color = e.hasAttr(_U(color)) ? e.attr<int>(_U(color)) : kRed;
227  c.data.hits.alpha = e.hasAttr(_U(alpha)) ? e.attr<float>(_U(alpha)) : 1.0;
228  c.data.hits.width = e.hasAttr(_U(width)) ? e.attr<float>(_U(width)) : 1.0;
229  c.data.hits.emax = e.hasAttr(u_emax) ? e.attr<float>(u_emax) : 25.0;
230  c.data.hits.towerH = e.hasAttr(u_towerH) ? e.attr<float>(u_towerH) : 25.0;
231  c.data.hits.threshold = e.hasAttr(_U(threshold)) ? e.attr<float>(_U(threshold)) : 0;
232  configs->push_back(c);
233 }
234 
246 template <> void Converter<include>::operator()(xml_h e) const {
247  if ( e ) {
248  DetectorLoad* load = dynamic_cast<DetectorLoad*>(&this->description);
249  if ( load ) {
250  load->processXML(e, e.attr<std::string>(_U(ref)));
251  return;
252  }
253  except("DisplayConfiguration","++ Invalid DetectorLoad instance in XML converter <include>");
254  }
255  except("DisplayConfiguration","++ Attempt to parse invalid include statement [Invalid XML element]");
256 }
257 
269 template <> void Converter<display>::operator()(xml_h e) const {
270  Display* d = (Display*)param;
271  if ( e.hasAttr(_Unicode(visLevel)) ) d->setVisLevel(e.attr<int>(_Unicode(visLevel)));
272  if ( e.hasAttr(_Unicode(eventHandler)) ) d->setEventHandlerName(e.attr<std::string>(_Unicode(eventHandler)));
273  if ( e.hasAttr(_Unicode(loadLevel)) ) d->setLoadLevel(e.attr<int>(_Unicode(loadLevel)));
274 }
275 
287 template <> void Converter<ddeve>::operator()(xml_h e) const {
288  Display* disp = (Display*)param;
289  DisplayConfiguration cfg(disp);
291  xml_coll_t(e,_Unicode(display)).for_each(Converter<display>(description,disp));
292  xml_coll_t(e,_Unicode(include)).for_each(Converter<include>(description,disp));
293  xml_coll_t(e,_Unicode(calodata)).for_each(Converter<calodata>(description,&cfg.calodata));
294  xml_coll_t(e,_Unicode(collection)).for_each(Converter<collection>(description,&cfg.collections));
295  xml_coll_t(e,_Unicode(view)).for_each(Converter<view>(description,&cfg.views));
296  disp->ImportConfiguration(cfg);
297 }
298 
299 #include <TEveProjections.h>
306 static long setup_DDEve(Detector& description, const xml_h& e) {
307  Display* display = description.extension<Display>();
308  static bool first = true;
309  if ( first ) {
310  first = false;
311 #define add_root_enum(x) xml::_toDictionary(xml::Strng_t(#x),int(x))
312  add_root_enum(kBlack);
313  add_root_enum(kWhite);
314  add_root_enum(kOrange);
315  add_root_enum(kBlue);
316  add_root_enum(kAzure);
317  add_root_enum(kRed);
318  add_root_enum(kCyan);
319  add_root_enum(kPink);
320  add_root_enum(kGreen);
321  add_root_enum(kViolet);
322  add_root_enum(kYellow);
323  add_root_enum(kTeal);
324  add_root_enum(kMagenta);
325  add_root_enum(kSpring);
326  add_root_enum(kTeal);
327 
328  add_root_enum(kDot);
329  add_root_enum(kPlus);
330  add_root_enum(kStar);
331  add_root_enum(kCircle);
332  add_root_enum(kMultiply);
333  add_root_enum(kFullDotSmall);
334  add_root_enum(kFullDotMedium);
335  add_root_enum(kFullDotLarge);
336  add_root_enum(kFullCircle);
337  add_root_enum(kFullSquare);
338  add_root_enum(kFullTriangleUp);
339  add_root_enum(kFullTriangleDown);
340  add_root_enum(kOpenCircle);
341  add_root_enum(kOpenSquare);
342  add_root_enum(kOpenTriangleUp);
343  add_root_enum(kOpenDiamond);
344  add_root_enum(kOpenCross);
345  add_root_enum(kFullStar);
346  add_root_enum(kOpenStar);
347  add_root_enum(kOpenTriangleDown);
348  add_root_enum(kFullDiamond);
349  add_root_enum(kFullCross);
350  add_root_enum(TEveProjection::kPT_RPhi);
351  add_root_enum(TEveProjection::kPT_RhoZ);
352  add_root_enum(TEveProjection::kPT_3D);
353  add_root_enum(TEveProjection::kPP_Plane);
354  add_root_enum(TEveProjection::kPP_Distort);
355  add_root_enum(TEveProjection::kPP_Full);
356  add_root_enum(TEveProjection::kGM_Polygons);
357  add_root_enum(TEveProjection::kGM_Segments);
358  }
359  (dd4hep::Converter<dd4hep::ddeve>(description,display))(e);
360  return 1;
361 }
362 DECLARE_XML_DOC_READER(ddeve,setup_DDEve)
dd4hep::Display
The main class of the DDEve display.
Definition: Display.h:56
dd4hep::DisplayConfiguration::Calo3D::rmin
float rmin
Definition: DisplayConfiguration.h:64
dd4hep::DisplayConfiguration::Config::Values::calodata
Calodata calodata
Definition: DisplayConfiguration.h:99
dd4hep::DisplayConfiguration::Config::Values::hits
Hits hits
Definition: DisplayConfiguration.h:101
DECL_TAG
#define DECL_TAG(x)
Definition: DisplayConfigurationParser.cpp:61
dd4hep::DisplayConfiguration::Calodata::rmin
float rmin
Definition: DisplayConfiguration.h:69
Detector.h
DisplayConfiguration.h
dd4hep::DisplayConfiguration::COLLECTION
@ COLLECTION
Definition: DisplayConfiguration.h:50
dd4hep::DisplayConfiguration::Config::data
union dd4hep::DisplayConfiguration::Config::Values data
dd4hep::DisplayConfiguration::Calodata::eta_max
float eta_max
Definition: DisplayConfiguration.h:70
dd4hep::DisplayConfiguration::ViewConfig::subdetectors
Configurations subdetectors
Definition: DisplayConfiguration.h:122
dd4hep::Display::setLoadLevel
void setLoadLevel(int new_level)
Set Eve Geometry load level in manager (either from XML or BEFORE XML file was loaded)
Definition: Display.h:137
dd4hep::DisplayConfiguration::Defaults::load_geo
char load_geo
Definition: DisplayConfiguration.h:55
dd4hep::DisplayConfiguration::ViewConfig::show_structure
bool show_structure
Definition: DisplayConfiguration.h:124
dd4hep::Configurations
DisplayConfiguration::Configurations Configurations
Definition: DisplayConfigurationParser.cpp:45
dd4hep::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
dd4hep::DisplayConfiguration::VIEW
@ VIEW
Definition: DisplayConfiguration.h:48
dd4hep::DisplayConfiguration::Defaults::color
int color
Definition: DisplayConfiguration.h:58
dd4hep::DisplayConfiguration::ViewConfig::show_sensitive
bool show_sensitive
Definition: DisplayConfiguration.h:123
xml_coll_t
dd4hep::xml::Collection_t xml_coll_t
Definition: ConditionsRepository.cpp:35
dd4hep::DisplayConfiguration::Hits::towerH
float towerH
Definition: DisplayConfiguration.h:86
dd4hep::ViewConfigurations
DisplayConfiguration::ViewConfigurations ViewConfigurations
Definition: DisplayConfigurationParser.cpp:46
_Unicode
#define _Unicode(a)
Definition: Tags.h:24
DocumentHandler.h
dd4hep::DisplayConfiguration::Calodata::towerH
float towerH
Definition: DisplayConfiguration.h:69
dd4hep::DisplayConfiguration::Calodata::phi_min
float phi_min
Definition: DisplayConfiguration.h:71
dd4hep::xml::Collection_t::for_each
void for_each(T oper) const
Loop processor using function object.
Definition: XMLElements.h:667
dd4hep::DisplayConfiguration::Calo3D::threshold
float threshold
Definition: DisplayConfiguration.h:64
Display.h
dd4hep::DisplayConfiguration::Config::Values::defaults
Defaults defaults
Definition: DisplayConfiguration.h:97
dd4hep::DisplayConfiguration::Defaults::show_evt
char show_evt
Definition: DisplayConfiguration.h:56
dd4hep::DisplayConfiguration::Hits::width
float width
Definition: DisplayConfiguration.h:84
dd4hep::DisplayConfiguration::Hits::type
int type
Definition: DisplayConfiguration.h:88
_U
#define _U(a)
Definition: Tags.h:23
dd4hep::DisplayConfiguration::Calo3D::dz
float dz
Definition: DisplayConfiguration.h:64
dd4hep::DisplayConfiguration::Calodata::eta_min
float eta_min
Definition: DisplayConfiguration.h:70
dd4hep::DisplayConfiguration::Calodata::n_eta
short n_eta
Definition: DisplayConfiguration.h:72
dd4hep::DisplayConfiguration::Hits::threshold
float threshold
Definition: DisplayConfiguration.h:85
dd4hep::DetectorLoad
Data implementation class of the Detector interface.
Definition: DetectorLoad.h:44
dd4hep::DisplayConfiguration::Calodata::n_phi
short n_phi
Definition: DisplayConfiguration.h:73
dd4hep::DisplayConfiguration::Config
Container with full display configuration.
Definition: DisplayConfiguration.h:92
dd4hep::DisplayConfiguration::CALODATA
@ CALODATA
Definition: DisplayConfiguration.h:46
dd4hep::DisplayConfiguration::ViewConfig::type
std::string type
Definition: DisplayConfiguration.h:121
dd4hep::DisplayConfiguration::PANEL
@ PANEL
Definition: DisplayConfiguration.h:49
DECLARE_XML_DOC_READER
#define DECLARE_XML_DOC_READER(name, func)
Definition: Factories.h:316
dd4hep::Display::setEventHandlerName
void setEventHandlerName(const std::string &nam)
Set Event Handler Plugin name.
Definition: Display.h:141
dd4hep::DisplayConfiguration::Config::Values::calo3d
Calo3D calo3d
Definition: DisplayConfiguration.h:98
dd4hep::DisplayConfiguration::ViewConfigurations
std::list< ViewConfig > ViewConfigurations
Definition: DisplayConfiguration.h:134
dd4hep::DisplayConfiguration::DETELEMENT
@ DETELEMENT
Definition: DisplayConfiguration.h:47
DetFactoryHelper.h
dd4hep::DisplayConfiguration::Config::name
std::string name
Definition: DisplayConfiguration.h:103
dd4hep::DisplayConfiguration::ViewConfig
View configuration.
Definition: DisplayConfiguration.h:119
dd4hep::DisplayConfiguration::Hits::size
float size
Definition: DisplayConfiguration.h:83
dd4hep::DisplayConfiguration::Calodata::threshold
float threshold
Definition: DisplayConfiguration.h:69
Conversions.h
dd4hep::DisplayConfiguration::Hits::emax
float emax
Definition: DisplayConfiguration.h:87
XMLElements.h
dd4hep::DisplayConfiguration::Calodata::emax
float emax
Definition: DisplayConfiguration.h:69
dd4hep::DisplayConfiguration
Generic display configuration structure for DDEve.
Definition: DisplayConfiguration.h:40
dd4hep::Detector::extension
IFACE * extension(bool alert=true) const
Access extension element by the type.
Definition: Detector.h:342
DetectorLoad.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::DisplayConfiguration::Calo3D::emax
float emax
Definition: DisplayConfiguration.h:64
dd4hep::DisplayConfiguration::Calodata::dz
float dz
Definition: DisplayConfiguration.h:69
dd4hep::DisplayConfiguration::Config::hits
std::string hits
Definition: DisplayConfiguration.h:104
dd4hep::xml::Handle_t::hasAttr
bool hasAttr(const XmlChar *t) const
Check for the existence of a named attribute.
Definition: XMLElements.cpp:673
dd4hep::Display::ImportConfiguration
void ImportConfiguration(const DisplayConfiguration &config)
Import configuration parameters.
Definition: Display.cpp:183
dd4hep::DisplayConfiguration::Calo3D::towerH
float towerH
Definition: DisplayConfiguration.h:64
dd4hep::DisplayConfiguration::Defaults::alpha
float alpha
Definition: DisplayConfiguration.h:59
dd4hep::DisplayConfiguration::Configurations
std::vector< Config > Configurations
Definition: DisplayConfiguration.h:116
add_root_enum
#define add_root_enum(x)
dd4hep::xml::Handle_t::attr
T attr(const Attribute a) const
Access typed attribute value by the XmlAttr.
Definition: XMLElements.h:454
Printout.h
dd4hep::DetectorLoad::processXML
virtual void processXML(const std::string &fname, xml::UriReader *entity_resolver=0)
Process XML unit and adopt all data from source structure.
Definition: DetectorLoad.cpp:49
dd4hep::DisplayConfiguration::Config::use
std::string use
Definition: DisplayConfiguration.h:105
dd4hep::Display::setVisLevel
void setVisLevel(int new_level)
Set Vis level in geo manager (either from XML or BEFORE XML file was loaded)
Definition: Display.h:135
dd4hep::DisplayConfiguration::Calodata::phi_max
float phi_max
Definition: DisplayConfiguration.h:71
dd4hep::DisplayConfiguration::Config::type
int type
Definition: DisplayConfiguration.h:106