DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
DetElementConfig.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 includes
16 #include <DD4hep/DetectorTools.h>
17 #include <DD4hep/Printout.h>
18 #include <DD4hep/Plugins.h>
19 #include <XML/DocumentHandler.h>
20 #include <XML/Utilities.h>
21 
22 // C/C++ include files
23 #include <climits>
24 
26 namespace {
27 
28  using namespace dd4hep;
29 
31 
37  long configure_detelement(Detector& detector, xml_h e) {
38  xml_comp_t x_det = e;
39  std::string path = x_det.attr<std::string>(_U(path));
40  DetElement det = detail::tools::findElement(detector, path.c_str());
41  if ( det.isValid() ) {
42  std::size_t count = 0;
43  bool propagate = det == detector.world() ? false: x_det.attr<bool>(_U(propagate), false);
44  if ( xml_dim_t x_vol = x_det.child(_U(volume), false) ) {
45  count += xml::configVolume(detector, x_vol, det.volume(), propagate, false);
46  }
47  PrintLevel lvl = x_det.attr<xml::Attribute>(_U(debug), nullptr) ? ALWAYS : DEBUG;
48  printout(lvl, "DetElementConfig", "++ Applied %ld settings to %s", count, path.c_str());
49  return 1;
50  }
51  except("DetElementConfig","FAILED: No valid DetElement. Configuration could not be applied!");
52  return 0;
53  }
54 
56 
62  long configure_sensitive(Detector& detector, xml_h e) {
63  xml_comp_t c = e;
64  std::string name = c.attr<std::string>(_U(detector));
65  std::size_t count = xml::configSensitiveDetector(detector, detector.sensitiveDetector(name), e);
66  PrintLevel lvl = c.attr<xml::Attribute>(_U(debug), nullptr) ? ALWAYS : DEBUG;
67  printout(lvl, "SensDetConfig", "++ Applied %ld settings to %s", count, name.c_str());
68  return 1;
69  }
70 
71 } // End namespace dd4hep
72 
74 DECLARE_XML_PLUGIN(DD4hep_DetElementConfig, configure_detelement)
76 DECLARE_XML_PLUGIN(DD4hep_SensitiveDetectorConfig, configure_sensitive)
dd4hep::xml::configVolume
std::size_t configVolume(dd4hep::Detector &detector, dd4hep::xml::Handle_t element, dd4hep::Volume volume, bool propagate, bool ignore_unknown_attr=false)
Configure volume properties from XML element.
Definition: Utilities.cpp:331
dd4hep::Detector::world
virtual DetElement world() const =0
Return reference to the top-most (world) detector element.
dd4hep::xml::Attribute
const XmlAttr * Attribute
Definition: XMLElements.h:38
dd4hep::debug
std::size_t debug(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:64
dd4hep::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
xml_comp_t
dd4hep::xml::Component xml_comp_t
Definition: XML.h:33
dd4hep::detail::tools::findElement
DetElement findElement(const Detector &description, const std::string &path)
Find DetElement as child of the top level volume by its absolute path.
Definition: DetectorTools.cpp:214
DocumentHandler.h
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
DetectorTools.h
dd4hep::Detector::sensitiveDetector
virtual SensitiveDetector sensitiveDetector(const std::string &name) const =0
Retrieve a sensitive detector by its name from the detector description.
_U
#define _U(a)
Definition: Tags.h:23
DECLARE_XML_PLUGIN
#define DECLARE_XML_PLUGIN(name, func)
Definition: Factories.h:321
Plugins.h
DetFactoryHelper.h
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::xml::Handle_t::attr
T attr(const Attribute a) const
Access typed attribute value by the XmlAttr.
Definition: XMLElements.h:454
Printout.h
xml_dim_t
dd4hep::xml::Dimension xml_dim_t
Definition: XML.h:31
Utilities.h
dd4hep::xml::configSensitiveDetector
std::size_t configSensitiveDetector(dd4hep::Detector &detector, dd4hep::SensitiveDetector sensitive, dd4hep::xml::Handle_t element)
Configure sensitive detector from XML element.
Definition: Utilities.cpp:378