Warning, /include/Parsers/detail/Detector.imp is written in an unsupported language. File is not indexed.
0001 //==========================================================================
0002 // AIDA Detector description implementation
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author : M.Frank
0011 //
0012 //==========================================================================
0013
0014
0015 /**
0016 * Note: Do NEVER include this file directly!
0017 *
0018 * Use the specific include files in the XML or JSON directory!
0019 * Also NO header guards!
0020 */
0021
0022
0023 // Framework include files
0024 #include <DD4hep/Plugins.h>
0025 #include <DD4hep/Detector.h>
0026
0027 namespace detail { class Detector; }
0028
0029 std::string Component::materialStr() const {
0030 return m_element.attr < std::string > (_U(material));
0031 }
0032
0033 bool Component::isSensitive() const {
0034 char val = m_element.hasAttr(_U(sensitive)) ? m_element.attr < std::string > (_U(sensitive))[0] : 'f';
0035 val = ::toupper(val);
0036 return val == 'T' || val == 'Y';
0037 }
0038
0039 bool Component::isRadiator() const {
0040 char val = m_element.hasAttr(_U(radiator)) ? m_element.attr < std::string > (_U(radiator))[0] : 'f';
0041 val = ::toupper(val);
0042 return val == 'T' || val == 'Y';
0043 }
0044
0045 TObject* Component::createShape() const {
0046 using namespace dd4hep::detail;
0047 Dimension child_dim(m_element);
0048 std::string typ = child_dim.typeStr();
0049 std::string fac = typ + "__shape_constructor";
0050 Handle_t solid_elt = m_element;
0051 Detector* description = 0;
0052 TObject* solid = PluginService::Create<TObject*>(fac, description, &solid_elt);
0053 if ( !solid ) {
0054 PluginDebug dbg;
0055 PluginService::Create<TObject*>(typ, description, &solid_elt);
0056 throw std::runtime_error("Failed to create solid of type " + typ + ". " + dbg.missingFactory(typ));
0057 }
0058 return solid;
0059 }
0060
0061 TObject* Component::runConstructor(const std::string& ctor_typ) const {
0062 using namespace dd4hep::detail;
0063 Dimension child_dim(m_element);
0064 std::string typ = child_dim.typeStr();
0065 std::string fac = typ + "__" + ctor_typ + "_constructor";
0066 Handle_t solid_elt = m_element;
0067 Detector* description = 0;
0068 TObject* solid = PluginService::Create<TObject*>(fac, description, &solid_elt);
0069 if ( !solid ) {
0070 PluginDebug dbg;
0071 PluginService::Create<TObject*>(typ, description, &solid_elt);
0072 throw std::runtime_error("Failed to create solid of type " + typ + ". " + dbg.missingFactory(typ));
0073 }
0074 return solid;
0075 }
0076
0077 int DetElement::id() const {
0078 return m_element.hasAttr(_U(id)) ? m_element.attr<int>(_U(id)) : -1;
0079 }
0080
0081 bool DetElement::isSensitive() const {
0082 char val = m_element.hasAttr(_U(sensitive)) ? m_element.attr < std::string > (_U(sensitive))[0] : 'f';
0083 val = ::toupper(val);
0084 return val == 'T' || val == 'Y';
0085 }
0086
0087 std::string DetElement::materialStr() const {
0088 Handle_t h = m_element.child(_U(material));
0089 if (h && h.hasAttr(_U(name))) {
0090 return h.attr < std::string > (_U(name));
0091 }
0092 return "";
0093 }
0094
0095 void DetElement::check(bool condition, const std::string& msg) const {
0096 if (condition) {
0097 throw std::runtime_error(msg);
0098 }
0099 }
0100
0101 bool DetElement::isTracker() const {
0102 if (m_element) {
0103 std::string typ = attr < std::string > (_U(type));
0104 if (typ.find("Tracker") != std::string::npos && hasAttr(_U(readout))) {
0105 return true;
0106 }
0107 }
0108 return false;
0109 }
0110
0111 bool DetElement::isCalorimeter() const {
0112 if (m_element) {
0113 std::string typ = attr < std::string > (_U(type));
0114 if (typ.find("Calorimeter") != std::string::npos && hasAttr(_U(readout))) {
0115 return true;
0116 }
0117 }
0118 return false;
0119 }
0120
0121 bool DetElement::isInsideTrackingVolume() const {
0122 if (m_element && hasAttr(_U(insideTrackingVolume)) )
0123 return attr<bool>(_U(insideTrackingVolume));
0124 else if ( isTracker() )
0125 return true;
0126 return false;
0127 }