diff --git a/DDCore/include/DD4hep/DetElement.h b/DDCore/include/DD4hep/DetElement.h index e2ffc8184e5d1e21ca2c5f5c888521453b9bc1fa..caf3df31030acee19eb6e7fa6f273f0bca48f3ec 100644 --- a/DDCore/include/DD4hep/DetElement.h +++ b/DDCore/include/DD4hep/DetElement.h @@ -227,14 +227,17 @@ namespace dd4hep { DetElement(const DetElement& e) = default; /// Constructor to hold handled object - DetElement(Object* object_ptr) : Handle<DetElementObject>(object_ptr) { } + DetElement(Object* obj) : Handle<DetElementObject>(obj) { } /// Clone constructor - DetElement(Object* data, const std::string& name, const std::string& type); + DetElement(Object* obj, const std::string& name, const std::string& type); /// Templated constructor for handle conversions template <typename Q> DetElement(const Handle<Q>& e) : Handle<DetElementObject>(e) {} + /// Constructor to hold handled object + DetElement(NamedObject* obj) : Handle<DetElementObject>(obj) { } + #ifdef __MAKECINT__ /// Constructor to copy handle DetElement(const Ref_t& e) : Handle<DetElementObject>(e) { } diff --git a/DDCore/include/DD4hep/Detector.h b/DDCore/include/DD4hep/Detector.h index 47a7970cafb006e44fa8e6073038f69c156cde32..cdc32d40f89fc780e593a3d07c9510232af43576 100644 --- a/DDCore/include/DD4hep/Detector.h +++ b/DDCore/include/DD4hep/Detector.h @@ -10,8 +10,8 @@ // Author : M.Frank // //========================================================================== -#ifndef DD4HEP_Detector_Detector_H -#define DD4HEP_Detector_Detector_H +#ifndef DD4HEP_DETECTOR_DETECTOR_H +#define DD4HEP_DETECTOR_DETECTOR_H #include "DD4hep/Version.h" @@ -231,23 +231,23 @@ namespace dd4hep { virtual Detector& add(CartesianField entry) = 0; /// Add a new constant by named reference to the detector description - virtual Detector& addConstant(const Ref_t& element) = 0; + virtual Detector& addConstant(const Handle<NamedObject>& element) = 0; /// Add a new visualisation attribute by named reference to the detector description - virtual Detector& addVisAttribute(const Ref_t& element) = 0; + virtual Detector& addVisAttribute(const Handle<NamedObject>& element) = 0; /// Add a new limit set by named reference to the detector description - virtual Detector& addLimitSet(const Ref_t& limset) = 0; + virtual Detector& addLimitSet(const Handle<NamedObject>& limset) = 0; /// Add a new id descriptor by named reference to the detector description - virtual Detector& addIDSpecification(const Ref_t& element) = 0; + virtual Detector& addIDSpecification(const Handle<NamedObject>& element) = 0; /// Add a new detector region by named reference to the detector description - virtual Detector& addRegion(const Ref_t& region) = 0; + virtual Detector& addRegion(const Handle<NamedObject>& region) = 0; /// Add a new detector readout by named reference to the detector description - virtual Detector& addReadout(const Ref_t& readout) = 0; + virtual Detector& addReadout(const Handle<NamedObject>& readout) = 0; /// Add a new sensitive detector by named reference to the detector description - virtual Detector& addSensitiveDetector(const Ref_t& element) = 0; + virtual Detector& addSensitiveDetector(const Handle<NamedObject>& element) = 0; /// Add a new subdetector by named reference to the detector description - virtual Detector& addDetector(const Ref_t& detector) = 0; + virtual Detector& addDetector(const Handle<NamedObject>& detector) = 0; /// Add a field component by named reference to the detector description - virtual Detector& addField(const Ref_t& field) = 0; + virtual Detector& addField(const Handle<NamedObject>& field) = 0; /// Deprecated call (use fromXML): Read compact geometry description or alignment file virtual void fromCompact(const std::string& fname, DetectorBuildType type = BUILD_DEFAULT) = 0; @@ -348,5 +348,5 @@ namespace dd4hep { return constantAsString(name); } #endif -} /* End namespace dd4hep */ -#endif /* DD4HEP_Detector_Detector_H */ +} /* End namespace dd4hep */ +#endif /* DD4HEP_DETECTOR_DETECTOR_H */ diff --git a/DDCore/include/DD4hep/DetectorData.h b/DDCore/include/DD4hep/DetectorData.h index 765ca3df840d649acde8bd040990b67abc90a7cd..9ab7233de05de738cf42dbb135fadc9893847a2f 100644 --- a/DDCore/include/DD4hep/DetectorData.h +++ b/DDCore/include/DD4hep/DetectorData.h @@ -11,8 +11,8 @@ // //========================================================================== -#ifndef DD4HEP_DDCORE_DetectorDATA_H -#define DD4HEP_DDCORE_DetectorDATA_H +#ifndef DD4HEP_DDCORE_DETECTORDATA_H +#define DD4HEP_DDCORE_DETECTORDATA_H // Framework includes #include "DD4hep/Detector.h" @@ -60,7 +60,7 @@ namespace dd4hep { /// Default constructor ObjectHandleMap() { } - void append(const Ref_t& e, bool throw_on_doubles = true) { + void append(const Handle<NamedObject>& e, bool throw_on_doubles = true) { if (e.isValid()) { std::string n = e.name(); std::pair<iterator, bool> r = this->insert(std::make_pair(n, e.ptr())); @@ -71,7 +71,7 @@ namespace dd4hep { throw InvalidObjectError("Attempt to add an invalid object."); } - template <typename T> void append(const Ref_t& e, bool throw_on_doubles = true) { + template <typename T> void append(const Handle<NamedObject>& e, bool throw_on_doubles = true) { T* obj = dynamic_cast<T*>(e.ptr()); if (obj) { this->append(e, throw_on_doubles); @@ -82,42 +82,50 @@ namespace dd4hep { }; protected: - TGeoManager* m_manager; - ObjectHandleMap m_readouts; - ObjectHandleMap m_idDict; - ObjectHandleMap m_limits; - ObjectHandleMap m_regions; - ObjectHandleMap m_detectors; - - ObjectHandleMap m_sensitive; - ObjectHandleMap m_display; - ObjectHandleMap m_fields; - - ObjectHandleMap m_motherVolumes; - + /** All elments of the big detector description common block ;-0 */ + /// Reference to the geometry manager object from ROOT + TGeoManager* m_manager; + /// Map of readout descriptors indexed by subdetector name + ObjectHandleMap m_readouts; + /// Map of readout IDDescriptors indexed by hit collection name + ObjectHandleMap m_idDict; + /// Map of limit sets + ObjectHandleMap m_limits; + /// Map of regions settings for the simulation + ObjectHandleMap m_regions; + /// The map of top level sub-detector objects indexed by name + ObjectHandleMap m_detectors; + /// The map of top level sub-detector sensitive detector objects indexed by the detector name + ObjectHandleMap m_sensitive; + /// The map of display attributes in use + ObjectHandleMap m_display; + /// The map of electro magnet field components for the global overlay field + ObjectHandleMap m_fields; // GDML fields - ObjectHandleMap m_define; + ObjectHandleMap m_define; + + std::map<std::string,Volume> m_motherVolumes; - DetElement m_world; - DetElement m_trackers; - Volume m_worldVol; - Volume m_trackingVol; + DetElement m_world; + DetElement m_trackers; + Volume m_worldVol; + Volume m_trackingVol; - Material m_materialAir; - Material m_materialVacuum; - VisAttr m_invisibleVis; - OverlayedField m_field; - Header m_header; - Detector::Properties m_properties; - DetectorBuildType m_buildType; + Material m_materialAir; + Material m_materialVacuum; + VisAttr m_invisibleVis; + OverlayedField m_field; + Header m_header; + Detector::Properties m_properties; + DetectorBuildType m_buildType; /// Definition of the extension type - ObjectExtensions m_extensions; + ObjectExtensions m_extensions; /// Volume manager reference - VolumeManager m_volManager; + VolumeManager m_volManager; /// Flag to inhibit the access to global constants. Value set by constants section 'Detector_InhibitConstants' - bool m_inhibitConstants; + bool m_inhibitConstants; protected: /// Default constructor @@ -137,5 +145,5 @@ namespace dd4hep { void adoptData(DetectorData& source); }; -} /* End namespace dd4hep */ -#endif /* DD4HEP_DDCORE_DetectorDATA_H */ +} /* End namespace dd4hep */ +#endif /* DD4HEP_DDCORE_DETECTORDATA_H */ diff --git a/DDCore/include/DD4hep/Factories.h b/DDCore/include/DD4hep/Factories.h index feecdc82fde898114c431dcf54d4310f7bb3cea7..037b50b813f65a9cf4b05840318aedc8d738d2d9 100644 --- a/DDCore/include/DD4hep/Factories.h +++ b/DDCore/include/DD4hep/Factories.h @@ -109,6 +109,19 @@ namespace dd4hep { static Handle<NamedObject> create(Detector& description, xml::Handle_t e); }; + /// Standard factory to create ROOT objects from an XML representation. + /** + * + * \author M.Frank + * \version 1.0 + * \date 2012/07/31 + * \ingroup DD4HEP_CORE + */ + template <typename T> class XMLObjectFactory : public PluginFactoryBase { + public: + static Handle<TObject> create(Detector& description, xml::Handle_t e); + }; + /// Read an arbitrary XML document and analyze it's content /** * @@ -135,7 +148,7 @@ namespace dd4hep { static long create(Detector& description, xml::RefElement& handle, xml::Handle_t element); }; - /// Standard factory to create Detector elements from the compact XML representation. + /// Standard factory to create Detector elements from an XML representation. /** * * \author M.Frank @@ -194,6 +207,9 @@ namespace { DD4HEP_PLUGIN_FACTORY_ARGS_2(ns::Named*,dd4hep::Detector*,ns::xml_h*) { return dd4hep::XMLElementFactory<P>::create(*a0,*a1).ptr(); } + DD4HEP_PLUGIN_FACTORY_ARGS_2(TObject*,dd4hep::Detector*,ns::xml_h*) + { return dd4hep::XMLObjectFactory<P>::create(*a0,*a1).ptr(); } + DD4HEP_PLUGIN_FACTORY_ARGS_2(long,dd4hep::Detector*,ns::xml_h*) { return make_return<long>(dd4hep::XMLDocumentReaderFactory<P>::create(*a0,*a1)); } @@ -249,6 +265,11 @@ namespace { template <> Ref_t XMLElementFactory<xml_element_##name>::create(dd4hep::Detector& l,ns::xml_h e) {return func(l,e);} \ DD4HEP_PLUGINSVC_FACTORY(xml_element_##name,name,NamedObject*(dd4hep::Detector*,ns::xml_h*),__LINE__) } +// Call function of the type [void* (*func)(dd4hep::Detector& description, xml_h handle)] +#define DECLARE_XML_SHAPE(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,xml_element_##name) {\ + template <> Handle<TObject> XMLObjectFactory<xml_element_##name>::create(dd4hep::Detector& l,ns::xml_h e) {return func(l,e);} \ + DD4HEP_PLUGINSVC_FACTORY(xml_element_##name,name,TObject*(dd4hep::Detector*,ns::xml_h*),__LINE__) } + // Call function of the type [long (*func)(dd4hep::Detector& description, xml_h handle)] #define DECLARE_XML_DOC_READER(name,func) DD4HEP_OPEN_PLUGIN(dd4hep,xml_document_##name) { \ template <> long XMLDocumentReaderFactory<xml_document_##name>::create(dd4hep::Detector& l,ns::xml_h e) {return func(l,e);} \ diff --git a/DDCore/include/DD4hep/Handle.h b/DDCore/include/DD4hep/Handle.h index 3c1137855582dbe626522b97dbb0d6b4d2e31dd1..e1109ec07dee8b35fcb91ca19b558935fbdfa45a 100644 --- a/DDCore/include/DD4hep/Handle.h +++ b/DDCore/include/DD4hep/Handle.h @@ -14,12 +14,12 @@ #define DD4HEP_HANDLE_H // Framework include files -#include "DD4hep/config.h" #include "DD4hep/Primitives.h" #include <string> #include <typeinfo> #include <stdexcept> +#include <type_traits> // Conversion factor from radians to degree: 360/(2*PI) #ifndef RAD_2_DEGREE @@ -56,11 +56,10 @@ namespace dd4hep { return 0xFEEDAFFEDEADFACEULL; } - /// Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects. /** * The Handle is the base class to access all objects in dd4hep. - * Objects, which consist ONLY of data are NEVER passed directly. + * Objects, which consist ONLY of data, which are NEVER passed directly. * They are ALWAYS passed using handles. Such handles are 'handy' ;-). * Assignment is to and from different handles is possible using concrete * type checking. @@ -92,20 +91,26 @@ namespace dd4hep { /// Single and only data member: Reference to the actual element. T* m_element = 0; - /// Defaulot constructor + /// Default constructor Handle() = default; /// Copy constructor Handle(const Handle<T>& element) = default; /// Initializing constructor from pointer Handle(T* element) : m_element(element) { } + /// Initializing constructor from unrelated pointer with type checking - template <typename Q> Handle(Q* element) : m_element((T*)element) - { verifyObject(); } + template <typename Q> Handle(Q* element) + : m_element(element ? detail::safe_cast<T>::template cast(element) : 0) + { } + /// Initializing constructor from unrelated handle with type checking - template <typename Q> Handle(const Handle<Q>& element) : m_element((T*)element.m_element) - { verifyObject(); } + template <typename Q> Handle(const Handle<Q>& element) + : m_element(element.m_element ? detail::safe_cast<T>::template cast(element.m_element) : 0) + { } + /// Assignment operator Handle<T>& operator=(const Handle<T>& element) = default; + /// Boolean operator == used for RB tree insertions bool operator==(const Handle<T>& element) const { return m_element == element.m_element; @@ -163,8 +168,6 @@ namespace dd4hep { /** Very compact way to check the validity of a handle with exception thrown. */ T* access() const; - /// Verify the object type after a (re-)assignment - void verifyObject() const; /// Access the object name (or "" if not supported by the object) const char* name() const; /// Assign a new named object. Note: object references must be managed by the user diff --git a/DDCore/include/DD4hep/Primitives.h b/DDCore/include/DD4hep/Primitives.h index ddb2ec2f3da7836904fc3d436c908e54eaa6abd4..d39f57bfa9666e0b99d504960b4451020cec0c3e 100644 --- a/DDCore/include/DD4hep/Primitives.h +++ b/DDCore/include/DD4hep/Primitives.h @@ -13,6 +13,9 @@ #ifndef DD4HEP_DD4HEP_PRIMITIVES_H #define DD4HEP_DD4HEP_PRIMITIVES_H +// Framework include files +#include "DD4hep/config.h" + // C/C++ include files #include <map> #include <list> @@ -242,6 +245,33 @@ namespace dd4hep { static const value_t* null_pointer() { return (value_t*)0; } }; + /// Safe cast mechanism using pre-linked conversions. + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP + */ +#ifdef DD4HEP_USE_SAFE_CAST + template <typename TO> class safe_cast { + public: + template <typename FROM> static TO* cast(FROM* from); + template <typename FROM> static TO* cast(const FROM* from); + template <typename FROM> static TO* cast_non_null(FROM* from); + template <typename FROM> static TO* cast_non_null(const FROM* from); + }; +#else + template <typename TO> class safe_cast { + public: + static TO* cast(TO* from); + static TO* cast_non_null(TO* from); + template <typename FROM> static TO* cast(FROM* from) { return cast((TO*)from; } + template <typename FROM> static TO* cast(const FROM* from) { return cast((TO*)from; } + template <typename FROM> static TO* cast_non_null(FROM* from) { return cast_non_null((TO*)from; } + template <typename FROM> static TO* cast_non_null(const FROM* from) { return cast_non_null((TO*)from; } + }; +#endif + template<typename C> struct ClearOnReturn { C& container; ClearOnReturn(C& c) : container(c) { } diff --git a/DDCore/include/DD4hep/VolumeManager.h b/DDCore/include/DD4hep/VolumeManager.h index 1878f3802fad1b67912e0a1c7afd5fbdfe870463..536d886ef872434dca1eadf0b2a1e1827ae027eb 100644 --- a/DDCore/include/DD4hep/VolumeManager.h +++ b/DDCore/include/DD4hep/VolumeManager.h @@ -50,7 +50,7 @@ namespace dd4hep { class VolumeManagerContext { public: /// Handle to the closest Detector element - DetElement element{0}; + DetElement element; /// Placement identifier VolumeID identifier = 0; /// Ignore mask of the placement identifier diff --git a/DDCore/include/DD4hep/config.h b/DDCore/include/DD4hep/config.h index c3594389b08d4a4feb53be19dbf05b84f04fe531..87e602a26d490d2fc4b1cd4a879d00ef1d6b4e4f 100644 --- a/DDCore/include/DD4hep/config.h +++ b/DDCore/include/DD4hep/config.h @@ -13,7 +13,9 @@ #ifndef DD4HEP_CONFIG_H #define DD4HEP_CONFIG_H -#define DD4HEP_INSTANCE_COUNTS +#define DD4HEP_INSTANCE_COUNTS 1 +#define DD4HEP_USE_SAFE_CAST 1 + #ifdef DD4HEP_INSTANCE_COUNTS #define INCREMENT_COUNTER InstanceCount::increment(this) #define DECREMENT_COUNTER InstanceCount::decrement(this) diff --git a/DDCore/include/DD4hep/detail/Handle.inl b/DDCore/include/DD4hep/detail/Handle.inl index 3a01f0b2b712f168accc2702bf8ebbe8f08915f9..56d1e2f34eff6c9422d1f64286917b7c9e8b6818 100644 --- a/DDCore/include/DD4hep/detail/Handle.inl +++ b/DDCore/include/DD4hep/detail/Handle.inl @@ -45,33 +45,75 @@ namespace dd4hep { invalidHandleError(typeid(T)); return 0; // We have thrown an exception before - does not harm! } - } /* End namespace dd4hep */ -#if 0 -#include <iostream> - std::cout << "element:" << (void*)m_element << std::endl;\ - std::cout << "type: " << (char*)(m_element ? typeName(typeid(*m_element)).c_str() : "---") << std::endl;\ - std::cout << "type: " << (void*)(m_element ? &typeid(*m_element) : 0) << std::endl;\ - std::cout << "target: " << typeName(typeid(X)) << std::endl;\ - std::cout << "target: " << (void*)&typeid(X) << std::endl;\ - std::cout << "cast: " << dynamic_cast<X*>((TObject*)m_element) << std::endl;\ - std::cout << "cast: " << dynamic_cast<X*>(m_element) << std::endl;\ +#ifdef DD4HEP_USE_SAFE_CAST + +#define DD4HEP_SAFE_CAST_IMPLEMENTATION(FROM, TO) \ + namespace dd4hep { namespace detail { \ + template <> template <> TO* safe_cast<TO>::cast<FROM>(FROM* p) \ + { return dynamic_cast<TO*>(p); } \ + template <> template <> TO* safe_cast<TO>::cast<FROM>(const FROM* p) \ + { return const_cast<TO*>(dynamic_cast<const TO*>(p)); } \ + template <> template <> TO* safe_cast<TO>::cast_non_null<FROM>(FROM* p) { \ + TO* ptr = dynamic_cast<TO*>(p); \ + if ( ptr ) return ptr; \ + invalidHandleAssignmentError(typeid(FROM),typeid(TO)); \ + return ptr; \ + } \ + template <> template <> TO* safe_cast<TO>::cast_non_null<FROM>(const FROM* p) { \ + return safe_cast<TO>::cast_non_null<FROM>(const_cast<FROM*>(p)); \ + } \ + }} + +// Predefined simple cast map +#define DD4HEP_IMPLEMENT_SAFE_CAST(FROM,TO) \ + DD4HEP_SAFE_CAST_IMPLEMENTATION(FROM,TO) \ + DD4HEP_SAFE_CAST_IMPLEMENTATION(TO,FROM) + +// Predefined cast map including standard object types +#define DD4HEP_IMPLEMENT_SAFE_NAMED_CAST(FROM) \ + DD4HEP_IMPLEMENT_SAFE_CAST(FROM,TObject) \ + DD4HEP_IMPLEMENT_SAFE_CAST(FROM,NamedObject) \ + DD4HEP_IMPLEMENT_SAFE_CAST(FROM,TNamed) \ + DD4HEP_SAFE_CAST_IMPLEMENTATION(FROM,FROM) + +#else + +#define DD4HEP_SAFE_CAST_IMPLEMENTATION(FROM, TO) \ + namespace dd4hep { namespace detail { \ + template <> FROM* safe_cast<FROM>::cast(FROM* p) \ + { return dynamic_cast<FROM*>(p); } \ + template <> template <> FROM* safe_cast<FROM>::cast_non_null(FROM* p) { \ + FROM* ptr = const_cast<FROM*>(dynamic_cast<const FROM*>(p)); \ + if ( !ptr ) invalidHandleError(typeid(FROM)); \ + return ptr; \ + } \ + }} +// Predefined simple cast map +#define DD4HEP_IMPLEMENT_SAFE_CAST(FROM,TO) DD4HEP_SAFE_CAST_IMPLEMENTATION(FROM,FROM) + +// Predefined cast map including standard object types +#define DD4HEP_IMPLEMENT_SAFE_NAMED_CAST(FROM) DD4HEP_SAFE_CAST_IMPLEMENTATION(FROM,FROM) #endif -#define DD4HEP_INSTANTIATE_HANDLE(X) \ - namespace dd4hep { \ - template <> void Handle<X>::verifyObject() const { \ - increment_object_validations(); \ - if (m_element && dynamic_cast<X*>(m_element) == 0) { \ - bad_assignment(typeid(*m_element), typeid(X)); \ - } \ - }} \ +// Predefined cast map for shapes +#define DD4HEP_IMPLEMENT_SAFE_SHAPE_CAST(FROM) \ + DD4HEP_IMPLEMENT_SAFE_CAST(FROM,TGeoShape) \ + DD4HEP_IMPLEMENT_SAFE_CAST(FROM,TGeoBBox) + +#define DD4HEP_INSTANTIATE_HANDLE(X) \ + DD4HEP_IMPLEMENT_SAFE_NAMED_CAST(X) \ template class dd4hep::Handle<X> +#define DD4HEP_INSTANTIATE_SHAPE_HANDLE(X) \ + DD4HEP_IMPLEMENT_SAFE_SHAPE_CAST(X) \ + DD4HEP_INSTANTIATE_HANDLE(X) + #define DD4HEP_INSTANTIATE_HANDLE_NAMED(X) \ + DD4HEP_IMPLEMENT_SAFE_NAMED_CAST(X) \ namespace dd4hep { \ template <> const char* Handle<X>::name() const \ { return this->m_element ? this->m_element->name.c_str() : ""; } \ @@ -80,15 +122,18 @@ namespace dd4hep { this->m_element = p; \ p->name = n; \ p->type = t; \ - } \ - template <> void Handle<X>::verifyObject() const { \ - increment_object_validations(); \ - if (m_element && dynamic_cast<X*>((NamedObject*)m_element) == 0) {\ - bad_assignment(typeid(*m_element), typeid(X)); \ - } \ - }} \ + }} \ template class dd4hep::Handle<X> +#define DD4HEP_INSTANTIATE_HANDLE_RAW(X) \ + namespace dd4hep { \ + template <> void \ + Handle<X>::assign(X* n, const std::string&, const std::string&) \ + { this->m_element = n;} \ + template <> const char* Handle<X>::name() const { return ""; } \ + } \ + template class dd4hep::Handle<X> + #define DD4HEP_INSTANTIATE_HANDLE_UNNAMED(X) \ namespace dd4hep { \ template <> void \ @@ -97,3 +142,12 @@ namespace dd4hep { template <> const char* Handle<X>::name() const { return ""; } \ } \ DD4HEP_INSTANTIATE_HANDLE(X) + +#define DD4HEP_CONCAT_MACROS(name, serial) name##_##serial +#define DD4HEP_SEGMENTATION_HANDLE_IMPLEMENTATION(X,serial) \ + namespace { \ + typedef dd4hep::SegmentationWrapper<X> DD4HEP_CONCAT_MACROS(Wrapper,serial); } \ + DD4HEP_IMPLEMENT_SAFE_CAST(DD4HEP_CONCAT_MACROS(Wrapper,serial),dd4hep::SegmentationObject) \ + DD4HEP_INSTANTIATE_HANDLE_UNNAMED(DD4HEP_CONCAT_MACROS(Wrapper,serial)) + +#define DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(X) DD4HEP_SEGMENTATION_HANDLE_IMPLEMENTATION(X,__LINE__) diff --git a/DDCore/include/DD4hep/detail/VolumeManagerInterna.h b/DDCore/include/DD4hep/detail/VolumeManagerInterna.h index aac622b6e2b42c48a59b690992b7ce97dbf8280a..749608111a4e3fea7508511cfc1349f221dcbf64 100644 --- a/DDCore/include/DD4hep/detail/VolumeManagerInterna.h +++ b/DDCore/include/DD4hep/detail/VolumeManagerInterna.h @@ -52,19 +52,19 @@ namespace dd4hep { /// The container of placements managed by this instance std::map<VolumeID, VolumeManagerContext*> volumes; /// The Detector element handle managed by this instance - DetElement detector{0}; + DetElement detector; /// The ID descriptor object IDDescriptor id; /// The reference to the TOP level VolumeManager - VolumeManagerObject* top = 0; + VolumeManagerObject* top = 0; /// The system field descriptor - const BitFieldValue* system; + const BitFieldValue* system = 0; /// System identifier - VolumeID sysID = 0; + VolumeID sysID = 0; /// Sub-detector mask - VolumeID detMask = ~0x0ULL; + VolumeID detMask = ~0x0ULL; /// Population flags - int flags = VolumeManager::NONE; + int flags = VolumeManager::NONE; public: /// Default constructor VolumeManagerObject() = default; diff --git a/DDCore/include/XML/detail/Detector.h b/DDCore/include/XML/detail/Detector.h index 4e093a93cb19d85024121e4244fe10e87d93fcf7..20132c70d24e064a80376cf1240fa96121a9b0f9 100644 --- a/DDCore/include/XML/detail/Detector.h +++ b/DDCore/include/XML/detail/Detector.h @@ -18,6 +18,7 @@ * Include XML/XMLDetector.h or JSON/Detector.h ! */ +class TObject; /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -55,7 +56,7 @@ namespace dd4hep { bool isRadiator() const; /// Create a shape using the plugin mechanism from an XML element - NamedObject* createShape() const; + TObject* createShape() const; }; /// XML Handle_t class extending the XML handle Dimension diff --git a/DDCore/include/XML/detail/Detector.imp b/DDCore/include/XML/detail/Detector.imp index bc983bea5e131e6e321c7136edbf50ed864e9815..60b88176d8e54ee1cb356ae070b4f0438da90e18 100644 --- a/DDCore/include/XML/detail/Detector.imp +++ b/DDCore/include/XML/detail/Detector.imp @@ -42,17 +42,17 @@ bool Component::isRadiator() const { return val == 'T' || val == 'Y'; } -dd4hep::NamedObject* Component::createShape() const { +TObject* Component::createShape() const { using namespace dd4hep::detail; Dimension child_dim(m_element); std::string typ = child_dim.typeStr(); std::string fac = typ + "__shape_constructor"; Handle_t solid_elt = m_element; Detector* description = 0; - NamedObject* solid = PluginService::Create<NamedObject*>(fac, description, &solid_elt); + TObject* solid = PluginService::Create<TObject*>(fac, description, &solid_elt); if ( !solid ) { PluginDebug dbg; - PluginService::Create<NamedObject*>(typ, description, &solid_elt); + PluginService::Create<TObject*>(typ, description, &solid_elt); throw std::runtime_error("Failed to create solid of type " + typ + ". " + dbg.missingFactory(typ)); } return solid; diff --git a/DDCore/src/AlignmentsInterna.cpp b/DDCore/src/AlignmentsInterna.cpp index c38804070591b275534939bcc2a88f72c97be203..afcc54bc259e44a7742a8841bcf682fd717d8ec6 100644 --- a/DDCore/src/AlignmentsInterna.cpp +++ b/DDCore/src/AlignmentsInterna.cpp @@ -26,10 +26,11 @@ using namespace dd4hep::detail; DD4HEP_INSTANTIATE_HANDLE_NAMED(AlignmentObject); DD4HEP_INSTANTIATE_HANDLE_UNNAMED(AlignmentData); +DD4HEP_IMPLEMENT_SAFE_CAST(AlignmentObject,ConditionObject) /// Default constructor AlignmentObject::AlignmentObject() - : ConditionObject(), alignment_data(0)//, source_key(0) + : ConditionObject(), alignment_data(0) { InstanceCount::increment(this); flags = Condition::ALIGNMENT_DERIVED; diff --git a/DDCore/src/DetElement.cpp b/DDCore/src/DetElement.cpp index 704f8e27f048692dfee93bc844b11c4df261a16a..e21fa261416ef7ea3fd709a376aa5fc697337cfe 100644 --- a/DDCore/src/DetElement.cpp +++ b/DDCore/src/DetElement.cpp @@ -225,21 +225,23 @@ DetElement DetElement::child(const string& child_name) const { /// Access to the detector elements's parent DetElement DetElement::parent() const { Object* o = ptr(); - return (o) ? o->parent : 0; + return (o) ? o->parent : DetElement(); } /// Access to the world object. Only possible once the geometry is closed. DetElement DetElement::world() const { Object* o = ptr(); - return (o) ? o->world() : 0; + return (o) ? o->world() : World(); } +/// Simple checking routine void DetElement::check(bool cond, const string& msg) const { if (cond) { throw runtime_error("dd4hep: " + msg); } } +/// Add a new child subdetector element DetElement& DetElement::add(DetElement sdet) { if (isValid()) { pair<Children::iterator, bool> r = object<Object>().children.insert(make_pair(sdet.name(), sdet)); diff --git a/DDCore/src/DetectorHelper.cpp b/DDCore/src/DetectorHelper.cpp index bd91eee26983c96366ad20ff26ef552b4ad255cf..25ddc312e2cf5a54e0a39fd89f4358436b5b76a2 100644 --- a/DDCore/src/DetectorHelper.cpp +++ b/DDCore/src/DetectorHelper.cpp @@ -38,7 +38,7 @@ SensitiveDetector DetectorHelper::sensitiveDetector(DetElement detector) const } } } - return SensitiveDetector(0); + return SensitiveDetector(); } /// Find a detector element by it's system ID @@ -48,6 +48,6 @@ DetElement DetectorHelper::detectorByID(int id) const { DetElement de(i.second); if ( de.id() == id ) return de; } - return DetElement(0); + return DetElement(); } diff --git a/DDCore/src/DetectorImp.cpp b/DDCore/src/DetectorImp.cpp index 0c8dc2fedf4e637f75f05d7a04dbfef386afaf17..47253ea4d60db7bcaebfef101d804f034d579e36 100644 --- a/DDCore/src/DetectorImp.cpp +++ b/DDCore/src/DetectorImp.cpp @@ -172,7 +172,7 @@ void* DetectorImp::userExtension(const type_info& info, bool alert) const { void DetectorImp::declareMotherVolume(const string& detector_name, const Volume& vol) { if ( !detector_name.empty() ) { if ( vol.isValid() ) { - HandleMap::const_iterator i = m_motherVolumes.find(detector_name); + auto i = m_motherVolumes.find(detector_name); if (i == m_motherVolumes.end()) { m_motherVolumes.insert(make_pair(detector_name,vol)); return; @@ -188,7 +188,7 @@ void DetectorImp::declareMotherVolume(const string& detector_name, const Volume& Volume DetectorImp::pickMotherVolume(const DetElement& de) const { if ( de.isValid() ) { string de_name = de.name(); - HandleMap::const_iterator i = m_motherVolumes.find(de_name); + auto i = m_motherVolumes.find(de_name); if (i == m_motherVolumes.end()) { return m_worldVol; } @@ -197,7 +197,7 @@ Volume DetectorImp::pickMotherVolume(const DetElement& de) const { throw runtime_error("Detector: Attempt access mother volume of invalid detector [Invalid-handle]"); } -Detector& DetectorImp::addDetector(const Ref_t& ref_det) { +Detector& DetectorImp::addDetector(const Handle<NamedObject>& ref_det) { DetElement det_element(ref_det); DetectorHelper helper(this); DetElement existing_det = helper.detectorByID(det_element.id()); @@ -234,7 +234,7 @@ Detector& DetectorImp::addDetector(const Ref_t& ref_det) { } /// Add a new constant by named reference to the detector description -Detector& DetectorImp::addConstant(const Ref_t& x) { +Detector& DetectorImp::addConstant(const Handle<NamedObject>& x) { if ( strcmp(x.name(),"Detector_InhibitConstants") == 0 ) { const char* title = x->GetTitle(); char c = ::toupper(title[0]); @@ -255,7 +255,7 @@ Constant DetectorImp::constant(const string& name) const { /// Typed access to constants: access string values string DetectorImp::constantAsString(const string& name) const { if ( !m_inhibitConstants ) { - Ref_t c = constant(name); + Handle<NamedObject> c = constant(name); if (c.isValid()) return c->GetTitle(); throw runtime_error("Detector:constantAsString: The constant " + name + " is not known to the system."); @@ -280,7 +280,7 @@ double DetectorImp::constantAsDouble(const string& name) const { } /// Add a field component by named reference to the detector description -Detector& DetectorImp::addField(const Ref_t& x) { +Detector& DetectorImp::addField(const Handle<NamedObject>& x) { m_field.add(x); m_fields.append(x); return *this; @@ -290,7 +290,7 @@ Detector& DetectorImp::addField(const Ref_t& x) { Material DetectorImp::material(const string& name) const { TGeoMedium* mat = m_manager->GetMedium(name.c_str()); if (mat) { - return Material(Ref_t(mat)); + return Material(mat); } throw runtime_error("Cannot find a material referenced by name:" + name); } @@ -364,10 +364,10 @@ vector<DetElement> DetectorImp::detectors(unsigned int includeFlag, unsigned int /// Access a set of subdetectors according to several sensitive types. vector<DetElement> DetectorImp::detectors(const string& type1, - const string& type2, - const string& type3, - const string& type4, - const string& type5 ) { + const string& type2, + const string& type3, + const string& type4, + const string& type5 ) { if ( m_manager->IsClosed() ) { vector<DetElement> v; DetectorTypeMap::const_iterator i, end=m_detectorTypes.end(); @@ -386,7 +386,7 @@ vector<DetElement> DetectorImp::detectors(const string& type1, throw runtime_error("detectors("+type1+","+type2+",...): Detectors can only selected by type once the geometry is closed!"); } -Handle<TObject> DetectorImp::getRefChild(const HandleMap& e, const string& name, bool do_throw) const { +Handle<NamedObject> DetectorImp::getRefChild(const HandleMap& e, const string& name, bool do_throw) const { HandleMap::const_iterator i = e.find(name); if (i != e.end()) { return (*i).second; diff --git a/DDCore/src/DetectorImp.h b/DDCore/src/DetectorImp.h index 6ee28422fa0bc29ebd9eeb9fd9a9cf5e80845e9e..50d4f7122c4ca33adad50d5a14a77706e2608f11 100644 --- a/DDCore/src/DetectorImp.h +++ b/DDCore/src/DetectorImp.h @@ -99,7 +99,7 @@ namespace dd4hep { /// Access an existing extension object from the Detector instance virtual void* userExtension(const std::type_info& info, bool alert=true) const; - virtual Handle<TObject> getRefChild(const HandleMap& e, const std::string& name, bool throw_if_not = true) const; + virtual Handle<NamedObject> getRefChild(const HandleMap& e, const std::string& name, bool throw_if_not = true) const; /// Register new mother volume using the detector name. virtual void declareMotherVolume(const std::string& detector_name, const Volume& vol); @@ -312,42 +312,42 @@ namespace dd4hep { } /// Add a new constant by named reference to the detector description - virtual Detector& addConstant(const Ref_t& x); + virtual Detector& addConstant(const Handle<NamedObject>& x); /// Add a new limit set by named reference to the detector description - virtual Detector& addLimitSet(const Ref_t& x) { + virtual Detector& addLimitSet(const Handle<NamedObject>& x) { m_limits.append(x); __R; } /// Add a new detector region by named reference to the detector description - virtual Detector& addRegion(const Ref_t& x) { + virtual Detector& addRegion(const Handle<NamedObject>& x) { m_regions.append(x); __R; } /// Add a new id descriptor by named reference to the detector description - virtual Detector& addIDSpecification(const Ref_t& x) { + virtual Detector& addIDSpecification(const Handle<NamedObject>& x) { m_idDict.append(x); __R; } /// Add a new detector readout by named reference to the detector description - virtual Detector& addReadout(const Ref_t& x) { + virtual Detector& addReadout(const Handle<NamedObject>& x) { m_readouts.append(x); __R; } /// Add a new visualisation attribute by named reference to the detector description - virtual Detector& addVisAttribute(const Ref_t& x) { + virtual Detector& addVisAttribute(const Handle<NamedObject>& x) { m_display.append(x); __R; } /// Add a new sensitive detector by named reference to the detector description - virtual Detector& addSensitiveDetector(const Ref_t& x) { + virtual Detector& addSensitiveDetector(const Handle<NamedObject>& x) { m_sensitive.append(x); __R; } /// Add a new subdetector by named reference to the detector description - virtual Detector& addDetector(const Ref_t& x); + virtual Detector& addDetector(const Handle<NamedObject>& x); /// Add a field component by named reference to the detector description - virtual Detector& addField(const Ref_t& x); + virtual Detector& addField(const Handle<NamedObject>& x); #undef __R }; diff --git a/DDCore/src/DetectorInterna.cpp b/DDCore/src/DetectorInterna.cpp index a25f979a01633956a75237c8f7d22619b152449a..3472d154463765eab5828f0226edd2d46d2a1126 100644 --- a/DDCore/src/DetectorInterna.cpp +++ b/DDCore/src/DetectorInterna.cpp @@ -32,6 +32,8 @@ typedef detail::tools::ElementPath ElementPath; DD4HEP_INSTANTIATE_HANDLE_NAMED(WorldObject); DD4HEP_INSTANTIATE_HANDLE_NAMED(DetElementObject); DD4HEP_INSTANTIATE_HANDLE_NAMED(SensitiveDetectorObject); +DD4HEP_IMPLEMENT_SAFE_CAST(WorldObject,DetElementObject) + /// Default constructor SensitiveDetectorObject::SensitiveDetectorObject() diff --git a/DDCore/src/GridPhiEta.cpp b/DDCore/src/GridPhiEta.cpp deleted file mode 100644 index f75fc3d23739b3b12b4763ffc7d524a9585d5aa5..0000000000000000000000000000000000000000 --- a/DDCore/src/GridPhiEta.cpp +++ /dev/null @@ -1,17 +0,0 @@ -//========================================================================== -// AIDA Detector description implementation -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see $DD4hepINSTALL/LICENSE. -// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. -// -// Author : M.Frank -// -//========================================================================== - -#include "DD4hep/GridPhiEta.h" -#include "DD4hep/detail/Handle.inl" - -DD4HEP_INSTANTIATE_HANDLE_UNNAMED(dd4hep::DDSegmentation::GridPhiEta); diff --git a/DDCore/src/GridRPhiEta.cpp b/DDCore/src/GridRPhiEta.cpp deleted file mode 100644 index dbfe02fd5575bdd8e900fc96a6d612c8e0562e31..0000000000000000000000000000000000000000 --- a/DDCore/src/GridRPhiEta.cpp +++ /dev/null @@ -1,17 +0,0 @@ -//========================================================================== -// AIDA Detector description implementation -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see $DD4hepINSTALL/LICENSE. -// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. -// -// Author : M.Frank -// -//========================================================================== - -#include "DD4hep/GridRPhiEta.h" -#include "DD4hep/detail/Handle.inl" - -DD4HEP_INSTANTIATE_HANDLE_UNNAMED(dd4hep::DDSegmentation::GridRPhiEta); diff --git a/DDCore/src/Handle.cpp b/DDCore/src/Handle.cpp index 1d996039e6d4b566f5079087ee72407821355256..921f91d759ee01515f30c5fdcc888112c45a541a 100644 --- a/DDCore/src/Handle.cpp +++ b/DDCore/src/Handle.cpp @@ -272,8 +272,14 @@ namespace dd4hep { #include "TColor.h" DD4HEP_INSTANTIATE_HANDLE_UNNAMED(Detector); -DD4HEP_INSTANTIATE_HANDLE_UNNAMED(TObject); -DD4HEP_INSTANTIATE_HANDLE(TNamed); +DD4HEP_INSTANTIATE_HANDLE_RAW(TObject); +DD4HEP_INSTANTIATE_HANDLE_RAW(TNamed); +DD4HEP_SAFE_CAST_IMPLEMENTATION(TObject,TObject) +DD4HEP_SAFE_CAST_IMPLEMENTATION(TNamed,TNamed) +DD4HEP_SAFE_CAST_IMPLEMENTATION(NamedObject,NamedObject) +DD4HEP_IMPLEMENT_SAFE_CAST(TObject,TNamed) +DD4HEP_IMPLEMENT_SAFE_CAST(TObject,NamedObject) +DD4HEP_IMPLEMENT_SAFE_CAST(TNamed,NamedObject) #include "TGeoMedium.h" #include "TGeoMaterial.h" @@ -312,27 +318,29 @@ DD4HEP_INSTANTIATE_HANDLE(TGeoNodeOffset); #include "TGeoCompositeShape.h" #include "TGeoShapeAssembly.h" DD4HEP_INSTANTIATE_HANDLE(TGeoVolume); -DD4HEP_INSTANTIATE_HANDLE(TGeoBBox); -DD4HEP_INSTANTIATE_HANDLE(TGeoCone); -DD4HEP_INSTANTIATE_HANDLE(TGeoArb8); -DD4HEP_INSTANTIATE_HANDLE(TGeoConeSeg); -DD4HEP_INSTANTIATE_HANDLE(MyConeSeg); -DD4HEP_INSTANTIATE_HANDLE(TGeoParaboloid); -DD4HEP_INSTANTIATE_HANDLE(TGeoPcon); -DD4HEP_INSTANTIATE_HANDLE(TGeoHype); -DD4HEP_INSTANTIATE_HANDLE(TGeoPgon); -DD4HEP_INSTANTIATE_HANDLE(TGeoTube); -DD4HEP_INSTANTIATE_HANDLE(TGeoEltu); -DD4HEP_INSTANTIATE_HANDLE(TGeoTubeSeg); -DD4HEP_INSTANTIATE_HANDLE(TGeoTrap); -DD4HEP_INSTANTIATE_HANDLE(TGeoTrd1); -DD4HEP_INSTANTIATE_HANDLE(TGeoTrd2); -DD4HEP_INSTANTIATE_HANDLE(TGeoSphere); -DD4HEP_INSTANTIATE_HANDLE(TGeoTorus); -DD4HEP_INSTANTIATE_HANDLE(TGeoHalfSpace); DD4HEP_INSTANTIATE_HANDLE(TGeoShape); -DD4HEP_INSTANTIATE_HANDLE(TGeoShapeAssembly); -DD4HEP_INSTANTIATE_HANDLE(TGeoCompositeShape); +DD4HEP_INSTANTIATE_HANDLE(TGeoBBox); +DD4HEP_IMPLEMENT_SAFE_CAST(TGeoShape,TGeoBBox) + +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoCone); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoArb8); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoConeSeg); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(MyConeSeg); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoParaboloid); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoPcon); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoHype); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoPgon); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTube); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoEltu); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTubeSeg); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTrap); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTrd1); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTrd2); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoSphere); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTorus); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoHalfSpace); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoShapeAssembly); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoCompositeShape); // Volume Placements (needed by "Volumes.cpp") #include "TGeoPhysicalNode.h" diff --git a/DDCore/src/NamedObject.cpp b/DDCore/src/NamedObject.cpp index d4790882cb119309d9b44e4b47f22c56cadc29d7..92f8127bfa12fdc6070e3c1e0bd721b6670b3fe1 100644 --- a/DDCore/src/NamedObject.cpp +++ b/DDCore/src/NamedObject.cpp @@ -14,13 +14,24 @@ // Framework includes #include "DD4hep/NamedObject.h" #include "DD4hep/detail/Handle.inl" -#include "TObject.h" +#include "TNamed.h" using namespace std; using namespace dd4hep; using namespace dd4hep::detail; -DD4HEP_INSTANTIATE_HANDLE_NAMED(NamedObject); +namespace dd4hep { + template <> const char* Handle<NamedObject>::name() const { + return this->m_element ? this->m_element->name.c_str() : ""; + } + template <> void + Handle<NamedObject>::assign(NamedObject* p, const string& n, const string& t){ + m_element = p; + p->name = n; + p->type = t; + } +} +template class dd4hep::Handle<NamedObject>; /// Initializing constructor NamedObject::NamedObject(const char* nam, const char* typ) diff --git a/DDCore/src/Plugins.cpp b/DDCore/src/Plugins.cpp index f2b26de3a501c46630c5b144626d3b34acc6a2ba..c953e68101cd9f6380f7c3322af45742114944cb 100644 --- a/DDCore/src/Plugins.cpp +++ b/DDCore/src/Plugins.cpp @@ -176,6 +176,7 @@ void PluginService::addFactory(const std::string& id, stub_t stub, DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(NamedObject*, (Detector*,xml::Handle_t*,Ref_t*)) DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(NamedObject*, (Detector*,xml::Handle_t*)) DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(NamedObject*, (Detector*)) +DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(TObject*, (Detector*,xml::Handle_t*)) DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(long, (Detector*,xml::Handle_t*)) DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(long, (Detector*,xml::Handle_t const*)) DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(long, (Detector*, int, char**)) diff --git a/DDCore/src/Segmentations.cpp b/DDCore/src/Segmentations.cpp index c100a1e943eb44e91b25917e790887989a0cbdfc..bfd86ba0697edece8e00cb8ce8fcded57485c75e 100644 --- a/DDCore/src/Segmentations.cpp +++ b/DDCore/src/Segmentations.cpp @@ -117,50 +117,47 @@ Handle<SensitiveDetectorObject> Segmentation::sensitive() const { return data<Object>()->sensitive; } -#define IMPLEMENT_SEGMENTATION_HANDLE(X) \ - DD4HEP_INSTANTIATE_HANDLE_UNNAMED(SegmentationWrapper<DDSegmentation::X>); - #include "DDSegmentation/NoSegmentation.h" -IMPLEMENT_SEGMENTATION_HANDLE(NoSegmentation) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::NoSegmentation); #include "DDSegmentation/CartesianGrid.h" -IMPLEMENT_SEGMENTATION_HANDLE(CartesianGrid) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::CartesianGrid); #include "DDSegmentation/CartesianGridXY.h" -IMPLEMENT_SEGMENTATION_HANDLE(CartesianGridXY) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::CartesianGridXY); #include "DDSegmentation/CartesianGridXZ.h" -IMPLEMENT_SEGMENTATION_HANDLE(CartesianGridXZ) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::CartesianGridXZ); #include "DDSegmentation/CartesianGridYZ.h" -IMPLEMENT_SEGMENTATION_HANDLE(CartesianGridYZ) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::CartesianGridYZ); #include "DDSegmentation/CartesianGridXYZ.h" -IMPLEMENT_SEGMENTATION_HANDLE(CartesianGridXYZ) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::CartesianGridXYZ); #include "DDSegmentation/TiledLayerGridXY.h" -IMPLEMENT_SEGMENTATION_HANDLE(TiledLayerGridXY) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::TiledLayerGridXY); #include "DDSegmentation/MegatileLayerGridXY.h" -IMPLEMENT_SEGMENTATION_HANDLE(MegatileLayerGridXY) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::MegatileLayerGridXY); #include "DDSegmentation/WaferGridXY.h" -IMPLEMENT_SEGMENTATION_HANDLE(WaferGridXY) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::WaferGridXY); #include "DDSegmentation/PolarGridRPhi.h" -IMPLEMENT_SEGMENTATION_HANDLE(PolarGridRPhi) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::PolarGridRPhi); #include "DDSegmentation/PolarGridRPhi2.h" -IMPLEMENT_SEGMENTATION_HANDLE(PolarGridRPhi2) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::PolarGridRPhi2); #include "DDSegmentation/GridPhiEta.h" -IMPLEMENT_SEGMENTATION_HANDLE(GridPhiEta) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::GridPhiEta); #include "DDSegmentation/GridRPhiEta.h" -IMPLEMENT_SEGMENTATION_HANDLE(GridRPhiEta) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::GridRPhiEta); #include "DDSegmentation/ProjectiveCylinder.h" -IMPLEMENT_SEGMENTATION_HANDLE(ProjectiveCylinder) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::ProjectiveCylinder); #include "DDSegmentation/MultiSegmentation.h" -IMPLEMENT_SEGMENTATION_HANDLE(MultiSegmentation) +DD4HEP_IMPLEMENT_SEGMENTATION_HANDLE(DDSegmentation::MultiSegmentation); diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp index c7f531e32c2301b509c4d710cb3e686cda471135..be49f9b4f3c770258d33398e339f1926e0871e2d 100644 --- a/DDCore/src/VolumeManager.cpp +++ b/DDCore/src/VolumeManager.cpp @@ -587,7 +587,7 @@ DetElement VolumeManager::lookupDetector(VolumeID volume_id) const { return c->element; } except("VolumeManager","lookupContext: Failed to search Volume context [Invalid Manager Handle]"); - return 0; + return DetElement(); } /// Lookup the closest subdetector detector element in the hierarchy according to a contained 64 bit hit ID diff --git a/DDCore/src/XML/Utilities.cpp b/DDCore/src/XML/Utilities.cpp index 147dda5be23ec40cc1a95e799155a5802c3816d0..7dd5a5fdabf160083774c43249a8b6f6b41c07a0 100644 --- a/DDCore/src/XML/Utilities.cpp +++ b/DDCore/src/XML/Utilities.cpp @@ -18,31 +18,32 @@ #include "DD4hep/Detector.h" #include "DD4hep/DetFactoryHelper.h" +class TObject; + using namespace std; using namespace dd4hep; using namespace dd4hep::detail; /// Create a solid shape using the plugin mechanism from the attributes of the XML element -Solid -dd4hep::xml::createShape(Detector& description, const std::string& shape_type, xml::Element element) { +Solid dd4hep::xml::createShape(Detector& description, + const std::string& shape_type, + xml::Element element) { string fac = shape_type + "__shape_constructor"; xml::Handle_t solid_elt = element; - Solid solid = Ref_t(PluginService::Create<NamedObject*>(fac, &description, &solid_elt)); + Solid solid = Solid(PluginService::Create<TObject*>(fac, &description, &solid_elt)); if ( !solid.isValid() ) { PluginDebug dbg; - PluginService::Create<NamedObject*>(shape_type, &description, &solid_elt); + PluginService::Create<TObject*>(shape_type, &description, &solid_elt); except("xml::createShape","Failed to create solid of type %s [%s]", shape_type.c_str(),dbg.missingFactory(shape_type).c_str()); } return solid; } - - - -Volume dd4hep::xml::createPlacedEnvelope( dd4hep::Detector& description, dd4hep::xml::Handle_t e , - dd4hep::DetElement sdet ){ - +Volume dd4hep::xml::createPlacedEnvelope( dd4hep::Detector& description, + dd4hep::xml::Handle_t e, + dd4hep::DetElement sdet) +{ xml_det_t x_det = e; string det_name = x_det.nameStr(); @@ -69,9 +70,7 @@ Volume dd4hep::xml::createPlacedEnvelope( dd4hep::Detector& description, dd4hep: Volume envelope ; if( x_shape.typeStr() == "Assembly" ){ - envelope = Assembly( det_name+"_assembly" ) ; - } else { // ---- create a shape from the specified xml element -------- Box env_solid = xml_comp_t( x_shape ).createShape(); @@ -100,45 +99,34 @@ Volume dd4hep::xml::createPlacedEnvelope( dd4hep::Detector& description, dd4hep: if( useRot && usePos ){ env_pv = mother.placeVolume( envelope , Transform3D( rot, pos ) ) ; - } else if( useRot ){ env_pv = mother.placeVolume( envelope , rot ) ; - } else if( usePos ){ env_pv = mother.placeVolume( envelope , pos ) ; - } else { env_pv = mother.placeVolume( envelope ); } // ---------------------------------------------- - env_pv.addPhysVolID("system", sdet.id()); - sdet.setPlacement( env_pv ) ; - envelope.setAttributes( description,x_det.regionStr(),x_det.limitsStr(),x_env.visStr()); - - return envelope ; + return envelope; } -void dd4hep::xml::setDetectorTypeFlag( dd4hep::xml::Handle_t e, dd4hep::DetElement sdet ){ - +void dd4hep::xml::setDetectorTypeFlag( dd4hep::xml::Handle_t e, dd4hep::DetElement sdet ) { xml_det_t x_det = e; string det_name = x_det.nameStr(); try{ - xml_comp_t x_dettype = x_det.child( dd4hep::xml::Strng_t("type_flags") ) ; - + xml_comp_t x_dettype = x_det.child( dd4hep::xml::Strng_t("type_flags") ) ; unsigned int typeFlag = x_dettype.type() ; - printout(DEBUG,"Utilities","+++ setDetectorTypeFlags for detector :%s set to 0x%x", det_name.c_str(), typeFlag ) ; - sdet.setTypeFlag( typeFlag ) ; - } catch(std::runtime_error){ - - printout(INFO,"Utilities","+++ setDetectorTypeFlags for detector :%s no xml element <type_flags/> found - nothing to set ", det_name.c_str() ) ; + printout(INFO,"Utilities", + "+++ setDetectorTypeFlags for detector :%s no xml element <type_flags/> found - nothing to set ", + det_name.c_str() ) ; } } diff --git a/DDCore/src/plugins/DetectorFields.cpp b/DDCore/src/plugins/DetectorFields.cpp index c409ae7051b4e26d52390791d611f2827c310e97..0c7647129321e5cb98fdcf52d714df6743abef6b 100644 --- a/DDCore/src/plugins/DetectorFields.cpp +++ b/DDCore/src/plugins/DetectorFields.cpp @@ -13,13 +13,16 @@ // Framework includes #include "DD4hep/FieldTypes.h" +#include "DD4hep/MatrixHelpers.h" #include "DD4hep/DetFactoryHelper.h" using namespace dd4hep; -static Ref_t convert_constant_field(Detector&, xml_h field, Ref_t object) { +static Handle<NamedObject> convert_constant_field(Detector&, xml_h field, Handle<NamedObject> object) { xml_doc_t doc = xml_elt_t(field).document(); ConstantField* fld = object.data<ConstantField>(); + field.setAttr(_U(name), object->GetName()); + field.setAttr(_U(type), object->GetTitle()); field.setAttr(_U(lunit), "mm"); //field.setAttr(_U(funit),"tesla"); if (fld->type == CartesianField::ELECTRIC) @@ -36,9 +39,11 @@ static Ref_t convert_constant_field(Detector&, xml_h field, Ref_t object) { } DECLARE_XML_PROCESSOR(ConstantField_Convert2Detector,convert_constant_field) -static Ref_t convert_solenoid(Detector&, xml_h field, Ref_t object) { +static Handle<NamedObject> convert_solenoid(Detector&, xml_h field, Handle<NamedObject> object) { char text[128]; SolenoidField* fld = object.data<SolenoidField>(); + field.setAttr(_U(name), object->GetName()); + field.setAttr(_U(type), object->GetTitle()); field.setAttr(_U(lunit), "mm"); field.setAttr(_U(funit), "tesla"); ::snprintf(text, sizeof(text), "%g/mm", fld->outerRadius); @@ -54,10 +59,11 @@ static Ref_t convert_solenoid(Detector&, xml_h field, Ref_t object) { return object; } DECLARE_XML_PROCESSOR(solenoid_Convert2Detector,convert_solenoid) +DECLARE_XML_PROCESSOR(SolenoidMagnet_Convert2Detector,convert_solenoid) -static Ref_t convert_dipole(Detector&, xml_h field, Ref_t object) { +static Handle<NamedObject> convert_dipole(Detector&, xml_h field, Handle<NamedObject> object) { char text[128]; - xml_doc_t doc = xml_elt_t(field).document(); + xml_doc_t doc = xml_elt_t(field).document(); DipoleField* fld = object.data<DipoleField>(); field.setAttr(_U(lunit), "mm"); field.setAttr(_U(funit), "tesla"); @@ -74,5 +80,44 @@ static Ref_t convert_dipole(Detector&, xml_h field, Ref_t object) { } return object; } -DECLARE_XML_PROCESSOR(DipoleField_Convert2Detector,convert_dipole) +DECLARE_XML_PROCESSOR(DipoleMagnet_Convert2Detector,convert_dipole) +//DECLARE_XML_PROCESSOR(DipoleField_Convert2Detector,convert_dipole) + + +static Handle<NamedObject> convert_multipole(Detector&, xml_h field, Handle<NamedObject> object) { + xml_doc_t doc = xml_elt_t(field).document(); + MultipoleField* ptr = object.data<MultipoleField>(); + RotationZYX rot; + Position pos; + + field.setAttr(_U(lunit), "mm"); + field.setAttr(_U(funit), "tesla"); + field.setAttr(_U(name), object->GetName()); + field.setAttr(_U(type), object->GetTitle()); + field.setAttr(_U(Z), ptr->B_z); + Transform3D inv = ptr->transform.Inverse(); + detail::matrix::_decompose(inv, pos, rot); + xml_elt_t x_pos = xml_elt_t(doc, _U(position)); + x_pos.setAttr(_U(x),pos.x()); + x_pos.setAttr(_U(y),pos.y()); + x_pos.setAttr(_U(z),pos.z()); + field.append(x_pos); + + xml_elt_t x_rot = xml_elt_t(doc, _U(rotation)); + x_pos.setAttr(_U(x),rot.Theta()); + x_pos.setAttr(_U(y),rot.Phi()); + x_pos.setAttr(_U(z),rot.Psi()); + field.append(x_rot); + if ( ptr->volume.isValid() ) { + // Disentangle shape ? + } + + for( double c : ptr->coefficents ) { + xml_dim_t x_coeff = xml_elt_t(doc, _U(coefficient)); + x_coeff.setAttr(_U(value),c); + field.append(x_coeff); + } + return object; +} +DECLARE_XML_PROCESSOR(MultipoleMagnet_Convert2Detector,convert_multipole) diff --git a/DDCore/src/plugins/JsonProcessor.cpp b/DDCore/src/plugins/JsonProcessor.cpp index d7ac2c302129f6ea206172065c532c1b42a950b2..d6e7e3f7d1eef891d106cc96589fd086a4310b64 100644 --- a/DDCore/src/plugins/JsonProcessor.cpp +++ b/DDCore/src/plugins/JsonProcessor.cpp @@ -101,8 +101,8 @@ template <> void Converter<detector>::operator()(json_h element) const { sd.setReadout(ro); description.addSensitiveDetector(sd); } - Ref_t sens = sd; - DetElement det(Ref_t(PluginService::Create<NamedObject*>(type, &description, &element, &sens))); + Handle<NamedObject> sens = sd; + DetElement det(PluginService::Create<NamedObject*>(type, &description, &element, &sens)); if (det.isValid()) { setChildTitles(make_pair(name, det)); if ( sd.isValid() ) { diff --git a/DDCore/src/plugins/LCDDConverter.cpp b/DDCore/src/plugins/LCDDConverter.cpp index a7d8da0e587fa773beeafe53d3b460318cdeff14..10dbc3f97d8ebb5f2b056c1df56c1d15f4c685d2 100644 --- a/DDCore/src/plugins/LCDDConverter.cpp +++ b/DDCore/src/plugins/LCDDConverter.cpp @@ -93,12 +93,11 @@ namespace { #endif bool is_volume(const TGeoVolume* volume) { - Volume v = Ref_t(volume); + Volume v(volume); return v.data() != 0; } bool is_placement(PlacedVolume node) { - PlacedVolume v = Ref_t(node); - return v.data() != 0; + return node.data() != 0; } string genName(const string& n) { return n; } @@ -659,8 +658,8 @@ xml_h LCDDConverter::handleVolume(const string& /* name */, Volume volume) const xml_h vol = geo.xmlVolumes[volume]; if (!vol) { const TGeoVolume* v = volume; - Volume _v = Ref_t(v); - string n = genName(v->GetName(),v); + Volume _v(v); + string n = genName(v->GetName(),v); TGeoMedium* medium = v->GetMedium(); TGeoShape* sh = v->GetShape(); xml_ref_t sol = handleSolid(sh->GetName(), sh); @@ -723,10 +722,10 @@ xml_h LCDDConverter::handleVolume(const string& /* name */, Volume volume) const /// Dump logical volume in GDML format to output stream xml_h LCDDConverter::handleVolumeVis(const string& /* name */, const TGeoVolume* volume) const { GeometryInfo& geo = data(); - xml_h vol = geo.xmlVolumes[volume]; + xml_h vol = geo.xmlVolumes[volume]; if (!vol) { const TGeoVolume* v = volume; - Volume _v = Ref_t(v); + Volume _v(volume); if (is_volume(volume)) { VisAttr vis = _v.visAttributes(); if (vis.isValid()) { @@ -743,11 +742,11 @@ xml_h LCDDConverter::handleVolumeVis(const string& /* name */, const TGeoVolume* /// Dump logical volume in GDML format to output stream void LCDDConverter::collectVolume(const string& /* name */, const TGeoVolume* volume) const { - Volume v = Ref_t(volume); + Volume v(volume); if ( is_volume(volume) ) { - GeometryInfo& geo = data(); - Region reg = v.region(); - LimitSet lim = v.limitSet(); + GeometryInfo& geo = data(); + Region reg = v.region(); + LimitSet lim = v.limitSet(); SensitiveDetector det = v.sensitiveDetector(); if (lim.isValid()) geo.limits.insert(lim); @@ -928,7 +927,7 @@ xml_h LCDDConverter::handleIdSpec(const std::string& name, IDDescriptor id_spec) xml_h id = geo.xmlIdSpecs[id_spec]; if (!id) { int length = 0, start = 0; - IDDescriptor desc = Ref_t(id_spec); + IDDescriptor desc = id_spec; geo.doc_idDict.append(id = xml_elt_t(geo.doc, _U(idspec))); id.setAttr(_U(name), name); const IDDescriptor::FieldMap& fm = desc.fields(); @@ -996,7 +995,7 @@ xml_h LCDDConverter::handleField(const std::string& /* name */, OverlayedField f GeometryInfo& geo = data(); xml_h field = geo.xmlFields[f]; if (!field) { - Ref_t fld(f); + Handle<NamedObject> fld(f); string type = f->GetTitle(); field = xml_elt_t(geo.doc, Unicode(type)); field.setAttr(_U(name), f->GetName()); diff --git a/DDCore/src/plugins/ShapePlugins.cpp b/DDCore/src/plugins/ShapePlugins.cpp index a77a3678c84a97ddd433bc1d8b67d92522162e06..d32be9c6f88348bc194947da49299a2e94e1fa67 100644 --- a/DDCore/src/plugins/ShapePlugins.cpp +++ b/DDCore/src/plugins/ShapePlugins.cpp @@ -19,19 +19,19 @@ using namespace std; using namespace dd4hep; using namespace dd4hep::detail; -static Ref_t create_Assembly(Detector&, xml_h e) { +static Handle<TObject> create_Assembly(Detector&, xml_h e) { xml_dim_t dim(e); - return Ref_t(new TGeoShapeAssembly()); + return Handle<TObject>(new TGeoShapeAssembly()); } -DECLARE_XMLELEMENT(Assembly__shape_constructor,create_Assembly) +DECLARE_XML_SHAPE(Assembly__shape_constructor,create_Assembly) -static Ref_t create_Box(Detector&, xml_h e) { +static Handle<TObject> create_Box(Detector&, xml_h e) { xml_dim_t dim(e); return Box(dim.dx(),dim.dy(),dim.dz()); } -DECLARE_XMLELEMENT(Box__shape_constructor,create_Box) +DECLARE_XML_SHAPE(Box__shape_constructor,create_Box) -static Ref_t create_HalfSpace(Detector&, xml_h e) { +static Handle<TObject> create_HalfSpace(Detector&, xml_h e) { xml_dim_t dim(e); xml_dim_t point = e.child(_U(point)); xml_dim_t normal = e.child(_U(normal)); @@ -39,9 +39,9 @@ static Ref_t create_HalfSpace(Detector&, xml_h e) { double n[3] = { normal.x(), normal.y(), normal.z()}; return HalfSpace(p, n); } -DECLARE_XMLELEMENT(HalfSpace__shape_constructor,create_HalfSpace) +DECLARE_XML_SHAPE(HalfSpace__shape_constructor,create_HalfSpace) -static Ref_t create_Polycone(Detector&, xml_h element) { +static Handle<TObject> create_Polycone(Detector&, xml_h element) { xml_dim_t e(element); int num = 0; vector<double> rmin,rmax,z; @@ -57,78 +57,78 @@ static Ref_t create_Polycone(Detector&, xml_h element) { } return Polycone(start,deltaphi,rmin,rmax,z); } -DECLARE_XMLELEMENT(Polycone__shape_constructor,create_Polycone) +DECLARE_XML_SHAPE(Polycone__shape_constructor,create_Polycone) -static Ref_t create_ConeSegment(Detector&, xml_h element) { +static Handle<TObject> create_ConeSegment(Detector&, xml_h element) { xml_dim_t e(element); return ConeSegment(e.rmin(0.0),e.rmax(),e.dz(0.0),e.startphi(0.0),e.deltaphi(2*M_PI)); } -DECLARE_XMLELEMENT(ConeSegment__shape_constructor,create_ConeSegment) +DECLARE_XML_SHAPE(ConeSegment__shape_constructor,create_ConeSegment) -static Ref_t create_Tube(Detector&, xml_h element) { +static Handle<TObject> create_Tube(Detector&, xml_h element) { xml_dim_t e(element); return Tube(e.rmin(0.0),e.rmax(),e.dz(0.0),e.startphi(0.0),e.deltaphi(2*M_PI)); } -DECLARE_XMLELEMENT(Tube__shape_constructor,create_Tube) +DECLARE_XML_SHAPE(Tube__shape_constructor,create_Tube) -static Ref_t create_EllipticalTube(Detector&, xml_h element) { +static Handle<TObject> create_EllipticalTube(Detector&, xml_h element) { xml_dim_t e(element); return EllipticalTube(e.a(),e.b(),e.dz()); } -DECLARE_XMLELEMENT(EllipticalTube__shape_constructor,create_EllipticalTube) +DECLARE_XML_SHAPE(EllipticalTube__shape_constructor,create_EllipticalTube) -static Ref_t create_Cone(Detector&, xml_h element) { +static Handle<TObject> create_Cone(Detector&, xml_h element) { xml_dim_t e(element); double rmi1 = e.rmin1(0.0), rma1 = e.rmax1(); return Cone(e.z(0.0),rmi1,rma1,e.rmin2(rmi1),e.rmax2(rma1)); } -DECLARE_XMLELEMENT(Cone__shape_constructor,create_Cone) +DECLARE_XML_SHAPE(Cone__shape_constructor,create_Cone) -static Ref_t create_Trap(Detector&, xml_h element) { +static Handle<TObject> create_Trap(Detector&, xml_h element) { xml_dim_t e(element); if ( e.hasAttr(_U(dz)) ) return Trap(e.dz(),e.dy(),e.dx(),_toDouble(_Unicode(pLTX))); return Trap(e.z(0.0),e.theta(),e.phi(0),e.y1(),e.x1(),e.x2(),e.alpha(),e.y2(),e.x3(),e.x4(),e.alpha2()); } -DECLARE_XMLELEMENT(Trap__shape_constructor,create_Trap) +DECLARE_XML_SHAPE(Trap__shape_constructor,create_Trap) -static Ref_t create_Trapezoid(Detector&, xml_h element) { +static Handle<TObject> create_Trapezoid(Detector&, xml_h element) { xml_dim_t e(element); return Trapezoid(e.x1(),e.x2(),e.y1(),e.y2(),e.z(0.0)); } -DECLARE_XMLELEMENT(Trapezoid__shape_constructor,create_Trapezoid) +DECLARE_XML_SHAPE(Trapezoid__shape_constructor,create_Trapezoid) -static Ref_t create_Torus(Detector&, xml_h element) { +static Handle<TObject> create_Torus(Detector&, xml_h element) { xml_dim_t e(element); return Torus(e.r(),e.rmin(),e.rmax(),e.phi(M_PI),e.deltaphi(2.*M_PI)); } -DECLARE_XMLELEMENT(Torus__shape_constructor,create_Torus) +DECLARE_XML_SHAPE(Torus__shape_constructor,create_Torus) -static Ref_t create_Sphere(Detector&, xml_h element) { +static Handle<TObject> create_Sphere(Detector&, xml_h element) { xml_dim_t e(element); return Sphere(e.rmin(),e.rmax(),e.theta(0e0),e.deltatheta(M_PI),e.phi(0e0),e.deltaphi(2.*M_PI)); } -DECLARE_XMLELEMENT(Sphere__shape_constructor,create_Sphere) +DECLARE_XML_SHAPE(Sphere__shape_constructor,create_Sphere) -static Ref_t create_Paraboloid(Detector&, xml_h element) { +static Handle<TObject> create_Paraboloid(Detector&, xml_h element) { xml_dim_t e(element); return Paraboloid(e.rmin(0.0),e.rmax(),e.dz()); } -DECLARE_XMLELEMENT(Paraboloid__shape_constructor,create_Paraboloid) +DECLARE_XML_SHAPE(Paraboloid__shape_constructor,create_Paraboloid) -static Ref_t create_Hyperboloid(Detector&, xml_h element) { +static Handle<TObject> create_Hyperboloid(Detector&, xml_h element) { xml_dim_t e(element); return Hyperboloid(e.rmin(), e.inner_stereo(), e.rmax(), e.outer_stereo(), e.dz()); } -DECLARE_XMLELEMENT(Hyperboloid__shape_constructor,create_Hyperboloid) +DECLARE_XML_SHAPE(Hyperboloid__shape_constructor,create_Hyperboloid) -static Ref_t create_PolyhedraRegular(Detector&, xml_h element) { +static Handle<TObject> create_PolyhedraRegular(Detector&, xml_h element) { xml_dim_t e(element); return PolyhedraRegular(e.numsides(),e.rmin(),e.rmax(),e.dz()); } -DECLARE_XMLELEMENT(PolyhedraRegular__shape_constructor,create_PolyhedraRegular) +DECLARE_XML_SHAPE(PolyhedraRegular__shape_constructor,create_PolyhedraRegular) -static Ref_t create_EightPointSolid(Detector&, xml_h element) { +static Handle<TObject> create_EightPointSolid(Detector&, xml_h element) { xml_dim_t e(element); double v[8][2]; int num = 0; @@ -140,7 +140,7 @@ static Ref_t create_EightPointSolid(Detector&, xml_h element) { } return EightPointSolid(e.dz(),&v[0][0]); } -DECLARE_XMLELEMENT(EightPointSolid__shape_constructor,create_EightPointSolid) +DECLARE_XML_SHAPE(EightPointSolid__shape_constructor,create_EightPointSolid) @@ -152,7 +152,7 @@ DECLARE_XMLELEMENT(EightPointSolid__shape_constructor,create_EightPointSolid) * @date 03/2015 * @author F.Gaede, CERN/DESY */ -static Ref_t create_BooleanShape(Detector&, xml_h element) { +static Handle<TObject> create_BooleanShape(Detector&, xml_h element) { xml_det_t e(element); @@ -225,8 +225,6 @@ static Ref_t create_BooleanShape(Detector&, xml_h element) { throw std::runtime_error(std::string(" create_BooleanShape - unknown operation given: ") + op + std::string(" - needs to be one of 'subtraction','union' or 'intersection' ") ) ; } - - return resultSolid ; } -DECLARE_XMLELEMENT(BooleanShape__shape_constructor,create_BooleanShape) +DECLARE_XML_SHAPE(BooleanShape__shape_constructor,create_BooleanShape) diff --git a/DDDB/src/DDDBHelper.cpp b/DDDB/src/DDDBHelper.cpp index 6de660fc7a968afeed87e2879ac7f4900f2b05d8..141132be80efd2d75f8c3092a865343a499e742d 100644 --- a/DDDB/src/DDDBHelper.cpp +++ b/DDDB/src/DDDBHelper.cpp @@ -96,5 +96,5 @@ std::pair<DetElement,std::string> DDDBHelper::getConditionEntry(const std::strin auto i = m_detCond.find(key); if ( i != m_detCond.end() ) return (*i).second; - return make_pair(DetElement(0),""); + return make_pair(DetElement(),""); } diff --git a/DDDB/src/plugins/DDDB2Objects.cpp b/DDDB/src/plugins/DDDB2Objects.cpp index 3042a3943e9b44bb7866341b1ab614ef243953f2..5ae1987871bc7287e026617558efc543d79bfc99 100644 --- a/DDDB/src/plugins/DDDB2Objects.cpp +++ b/DDDB/src/plugins/DDDB2Objects.cpp @@ -769,7 +769,7 @@ namespace dd4hep { } Volume vol; DDDBCatalog* support = 0; - DetElement det(0), parent_element(0); + DetElement det, parent_element; if ( context->print_detelem ) { printout(INFO,"CNV<Catalog>","++ Starting catalog %p %s [cref:%d/%d lref:%d/%d lv:%s sup:%s np:%s] Cond:%s ", (void*)object, diff --git a/DDG4/CMakeLists.txt b/DDG4/CMakeLists.txt index 99440da5e5408de8e0904dfaee188bb4a3a921aa..e9f6e1c187f33a57014388c016a1d409cdf75230 100644 --- a/DDG4/CMakeLists.txt +++ b/DDG4/CMakeLists.txt @@ -68,5 +68,5 @@ dd4hep_add_executable(pyddg4 USES [ROOT REQUIRED COMPONENTS PyROOT] OPTIONAL [PYTHON REQUIRED SOURCES pyddg4.cpp]) #---Package installation procedure(s) ---------------------------------------------- -dd4hep_install_dir(examples DESTINATION examples/DDG4) -dd4hep_install_files(FILES python/*.py python/*.C DESTINATION python) +dd4hep_install_dir(examples DESTINATION ${DD4hep_DIR}/examples/DDG4) +dd4hep_install_files(FILES python/*.py python/*.C DESTINATION ${DD4hep_DIR}/python) diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index 4e2b83137706c9e473a6ff0657ae2de5f3bf3413..31efceb846d2ae04f69e370b133c7e8005378923 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -597,7 +597,7 @@ void* Geant4Converter::handleVolume(const string& name, const TGeoVolume* volume if (volIt == info.g4Volumes.end() ) { PrintLevel lvl = debugVolumes ? ALWAYS : outputLevel; const TGeoVolume* v = volume; - Volume _v = Ref_t(v); + Volume _v(v); string n = v->GetName(); TGeoMedium* med = v->GetMedium(); TGeoShape* sh = v->GetShape(); @@ -666,7 +666,7 @@ void* Geant4Converter::handleVolume(const string& name, const TGeoVolume* volume void* Geant4Converter::collectVolume(const string& /* name */, const TGeoVolume* volume) const { Geant4GeometryInfo& info = data(); const TGeoVolume* v = volume; - Volume _v = Ref_t(v); + Volume _v(v); Region reg = _v.region(); LimitSet lim = _v.limitSet(); SensitiveDetector det = _v.sensitiveDetector(); @@ -809,7 +809,7 @@ void* Geant4Converter::handleRegion(Region region, const set<const TGeoVolume*>& G4Region* g4 = data().g4Regions[region]; if (!g4) { PrintLevel lvl = debugRegions ? ALWAYS : outputLevel; - Region r = Ref_t(region); + Region r = region; g4 = new G4Region(r.name()); // set production cut if( not r.useDefaultCut() ) { @@ -856,7 +856,7 @@ void* Geant4Converter::handleRegion(Region region, const set<const TGeoVolume*>& void* Geant4Converter::handleLimitSet(LimitSet limitset, const set<const TGeoVolume*>& /* volumes */) const { G4UserLimits* g4 = data().g4Limits[limitset]; if (!g4) { - LimitSet ls = Ref_t(limitset); + LimitSet ls = limitset; g4 = new G4UserLimits(limitset->GetName()); const set<Limit>& limits = ls.limits(); for (LimitSet::Object::const_iterator i = limits.begin(); i != limits.end(); ++i) { @@ -949,7 +949,7 @@ void Geant4Converter::handleProperties(Detector::Properties& prp) const { void Geant4Converter::printSensitive(SensitiveDetector sens_det, const set<const TGeoVolume*>& /* volumes */) const { Geant4GeometryInfo& info = data(); set<const TGeoVolume*>& volset = info.sensitives[sens_det]; - SensitiveDetector sd = Ref_t(sens_det); + SensitiveDetector sd = sens_det; stringstream str; printout(INFO, "Geant4Converter", "++ SensitiveDetector: %-18s %-20s Hits:%-16s", sd.name(), ("[" + sd.type() + "]").c_str(), diff --git a/DDG4/src/Geant4Converter.cpp.save b/DDG4/src/Geant4Converter.cpp.save deleted file mode 100644 index 556540503865c49bab48a57a04fa6673fc01d6bb..0000000000000000000000000000000000000000 --- a/DDG4/src/Geant4Converter.cpp.save +++ /dev/null @@ -1,937 +0,0 @@ -// $Id: Geant4Converter.cpp 788 2013-09-20 17:04:50Z gaede $ -//==================================================================== -// AIDA Detector description implementation -//-------------------------------------------------------------------- -// -// Author : M.Frank -// -//==================================================================== - -#include "DD4hep/Detector.h" -#include "DD4hep/Plugins.h" -#include "DD4hep/Volumes.h" -#include "DD4hep/Printout.h" -#include "DDG4/Geant4Field.h" -#include "DDG4/Geant4Converter.h" -#include "DDG4/Factories.h" -#include "DDG4/Geant4SensitiveDetector.h" - -// ROOT includes -#include "TROOT.h" -#include "TColor.h" -#include "TGeoNode.h" -#include "TGeoShape.h" -#include "TGeoCone.h" -#include "TGeoPcon.h" -#include "TGeoPgon.h" -#include "TGeoSphere.h" -#include "TGeoTorus.h" -#include "TGeoTube.h" -#include "TGeoTrd1.h" -#include "TGeoTrd2.h" -#include "TGeoArb8.h" -#include "TGeoMatrix.h" -#include "TGeoBoolNode.h" -#include "TGeoParaboloid.h" -#include "TGeoCompositeShape.h" -#include "TGeoShapeAssembly.h" -#include "TClass.h" -#include "TMath.h" - -#include "G4VSensitiveDetector.hh" -#include "G4VisAttributes.hh" -#include "G4ProductionCuts.hh" -#include "G4VUserRegionInformation.hh" -// Geant4 include files -#include "G4Element.hh" -#include "G4SDManager.hh" -#include "G4Assembly.hh" -#include "G4Box.hh" -#include "G4Trd.hh" -#include "G4Tubs.hh" -#include "G4Cons.hh" -#include "G4Torus.hh" -#include "G4Sphere.hh" -#include "G4Polycone.hh" -#include "G4Polyhedra.hh" -#include "G4UnionSolid.hh" -#include "G4Paraboloid.hh" -#include "G4SubtractionSolid.hh" -#include "G4IntersectionSolid.hh" - -#include "G4Region.hh" -#include "G4UserLimits.hh" -#include "G4VSensitiveDetector.hh" - -#include "G4LogicalVolume.hh" -#include "G4Material.hh" -#include "G4Element.hh" -#include "G4Isotope.hh" -#include "G4Transform3D.hh" -#include "G4ThreeVector.hh" -#include "G4PVPlacement.hh" -#include "G4ElectroMagneticField.hh" -#include "G4FieldManager.hh" - -#include "G4ReflectionFactory.hh" - -#include <iostream> -#include <iomanip> -#include <sstream> - -using namespace dd4hep::sim; -using namespace dd4hep::detail; -using namespace dd4hep; -using namespace std; - -#define private public -#include "G4AssemblyVolume.hh" -#undef private - -struct Geant4AssemblyVolume : public G4AssemblyVolume { - Geant4AssemblyVolume() {} - size_t placeVolume(G4LogicalVolume* pPlacedVolume, - G4Transform3D& transformation) { - size_t id = fTriplets.size(); - this->AddPlacedVolume(pPlacedVolume,transformation); - return id; - } - void imprint( std::vector<G4VPhysicalVolume*>& nodes, - G4LogicalVolume* pMotherLV, - G4Transform3D& transformation, - G4int copyNumBase, - G4bool surfCheck ); - -}; - -void Geant4AssemblyVolume::imprint( std::vector<G4VPhysicalVolume*>& nodes, - G4LogicalVolume* pMotherLV, - G4Transform3D& transformation, - G4int copyNumBase, - G4bool surfCheck ) -{ - G4AssemblyVolume* pAssembly = this; - unsigned int numberOfDaughters; - if( copyNumBase == 0 ) { - numberOfDaughters = pMotherLV->GetNoDaughters(); - } - else { - numberOfDaughters = copyNumBase; - } - // We start from the first available index - numberOfDaughters++; - ImprintsCountPlus(); - - std::vector<G4AssemblyTriplet> triplets = pAssembly->fTriplets; - for( unsigned int i = 0; i < triplets.size(); i++ ) { - G4Transform3D Ta( *(triplets[i].GetRotation()), - triplets[i].GetTranslation() ); - if ( triplets[i].IsReflection() ) { Ta = Ta * G4ReflectZ3D(); } - - G4Transform3D Tfinal = transformation * Ta; - - if ( triplets[i].GetVolume() ) - { - // Generate the unique name for the next PV instance - // The name has format: - // - // av_WWW_impr_XXX_YYY_ZZZ - // where the fields mean: - // WWW - assembly volume instance number - // XXX - assembly volume imprint number - // YYY - the name of a log. volume we want to make a placement of - // ZZZ - the log. volume index inside the assembly volume - // - std::stringstream pvName; - pvName << "av_" - << GetAssemblyID() - << "_impr_" - << GetImprintsCount() - << "_" - << triplets[i].GetVolume()->GetName().c_str() - << "_pv_" - << i - << std::ends; - - // Generate a new physical volume instance inside a mother - // (as we allow 3D transformation use G4ReflectionFactory to - // take into account eventual reflection) - // - G4PhysicalVolumesPair pvPlaced - = G4ReflectionFactory::Instance()->Place( Tfinal, - pvName.str().c_str(), - triplets[i].GetVolume(), - pMotherLV, - false, - numberOfDaughters + i, - surfCheck ); - - // Register the physical volume created by us so we can delete it later - // - fPVStore.push_back( pvPlaced.first ); - nodes.push_back(pvPlaced.first); - if ( pvPlaced.second ) { // Supported by G4, but not by TGeo! - fPVStore.push_back( pvPlaced.second ); - G4Exception("G4AssemblyVolume::MakeImprint(..)", - "GeomVol0003", FatalException, - "Fancy construct popping new mother from the stack!"); - } - } - else if ( triplets[i].GetAssembly() ) { - // Place volumes in this assembly with composed transformation - G4Exception("G4AssemblyVolume::MakeImprint(..)", - "GeomVol0003", FatalException, - "Assemblies within assembliesare not supported."); - } - else { - G4Exception("G4AssemblyVolume::MakeImprint(..)", - "GeomVol0003", FatalException, - "Triplet has no volume and no assembly"); - } - } -} - -namespace { - static TGeoNode* s_topPtr; - static string indent = ""; - struct MyTransform3D : public G4Transform3D { - MyTransform3D(double XX, double XY, double XZ, double DX, - double YX, double YY, double YZ, double DY, - double ZX, double ZY, double ZZ, double DZ) - : G4Transform3D(XX,XY,XZ,DX,YX,YY,YZ,DY,ZX,ZY,ZZ,DZ) {} - }; - - void handleName(const TGeoNode* n) { - TGeoVolume* v = n->GetVolume(); - TGeoMedium* m = v->GetMedium(); - TGeoShape* s = v->GetShape(); - string nam; - printout(DEBUG,"G4","TGeoNode:'%s' Vol:'%s' Shape:'%s' Medium:'%s'", - n->GetName(),v->GetName(),s->GetName(),m->GetName()); - } - - class G4UserRegionInformation : public G4VUserRegionInformation { - public: - Region region; - double threshold; - bool storeSecondaries; - G4UserRegionInformation() : threshold(0.0), storeSecondaries(false) {} - virtual ~G4UserRegionInformation() {} - virtual void Print() const { - if ( region.isValid() ) - printout(DEBUG,"Region","Name:%s",region.name()); - } - }; -} - -/// Initializing Constructor -Geant4Converter::Geant4Converter( Detector& description ) - : Geant4Mapping(description), m_checkOverlaps(true) -{ - this->Geant4Mapping::init(); -} - -/// Standard destructor -Geant4Converter::~Geant4Converter() { -} - -/// Dump element in GDML format to output stream -void* Geant4Converter::handleElement(const string& name, const TGeoElement* element) const { - G4Element* g4e = data().g4Elements[element]; - if ( !g4e ) { - g4e = G4Element::GetElement(name,false); - if ( !g4e ) { - if ( element->GetNisotopes() > 1 ) { - g4e = new G4Element(name,element->GetTitle(),element->GetNisotopes()); - for(int i=0, n=element->GetNisotopes(); i<n; ++i) { - TGeoIsotope* iso = element->GetIsotope(i); - G4Isotope* g4iso = G4Isotope::GetIsotope(iso->GetName(),false); - if ( !g4iso ) { - g4iso = new G4Isotope(iso->GetName(),iso->GetZ(),iso->GetN(),iso->GetA()); - } - g4e->AddIsotope(g4iso,element->GetRelativeAbundance(i)); - } - } - else { - g4e = new G4Element(element->GetTitle(),name,element->Z(),element->A()*(g/mole)); - } - stringstream str; - str << (*g4e); - printout(DEBUG,"Geant4Converter","++ Created G4 %s",str.str().c_str()); - } - data().g4Elements[element] = g4e; - } - return g4e; -} - -/// Dump material in GDML format to output stream -void* Geant4Converter::handleMaterial(const string& name, const TGeoMedium* medium) const { - G4Material* mat = data().g4Materials[medium]; - if ( !mat ) { - mat = G4Material::GetMaterial(name,false); - if ( !mat ) { - TGeoMaterial* m = medium->GetMaterial(); - G4State state = kStateUndefined; - double density = m->GetDensity()*(gram/cm3); - if ( density < 1e-25 ) density = 1e-25; - switch(m->GetState()) { - case TGeoMaterial::kMatStateSolid: - state = kStateSolid; - break; - case TGeoMaterial::kMatStateLiquid: - state = kStateLiquid; - break; - case TGeoMaterial::kMatStateGas: - state = kStateGas; - break; - default: - case TGeoMaterial::kMatStateUndefined: - state = kStateUndefined; - break; - } - if ( m->IsMixture() ) { - double A_total = 0.0; - TGeoMixture* mix = (TGeoMixture*)m; - int nElements = mix->GetNelements(); - mat = new G4Material(name,density,nElements, - state, - m->GetTemperature(), - m->GetPressure()); - for(int i=0; i<nElements; ++i) - A_total += (mix->GetAmixt())[i]; - for(int i=0; i<nElements; ++i) { - TGeoElement* e = mix->GetElement(i); - G4Element* g4e = (G4Element*)handleElement(e->GetName(),e); - if ( !g4e ) { - printout(ERROR,"Material","Missing component %s for material %s.", - e->GetName(), mix->GetName()); - } - mat->AddElement(g4e,(mix->GetAmixt())[i]/A_total); - } - } - else { - mat = new G4Material(name,m->GetZ(),m->GetA(),density,state, - m->GetTemperature(),m->GetPressure()); - } - stringstream str; - str << (*mat); - printout(DEBUG,"Geant4Converter","++ Created G4 %s",str.str().c_str()); - } - data().g4Materials[medium] = mat; - } - return mat; -} - -/// Dump solid in GDML format to output stream -void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) const { - G4VSolid* solid = 0; - if ( shape ) { - if ( 0 != (solid=data().g4Solids[shape]) ) { - return solid; - } - else if ( shape->IsA() == TGeoShapeAssembly::Class() ) { - solid = (G4VSolid*)new G4Assembly(); - } - else if ( shape->IsA() == TGeoBBox::Class() ) { - const TGeoBBox* s = (const TGeoBBox*)shape; - solid = new G4Box(name,s->GetDX()*CM_2_MM,s->GetDY()*CM_2_MM,s->GetDZ()*CM_2_MM); - } - else if ( shape->IsA() == TGeoTube::Class() ) { - const TGeoTube* s = (const TGeoTube*)shape; - solid = new G4Tubs(name,s->GetRmin()*CM_2_MM,s->GetRmax()*CM_2_MM,s->GetDz()*CM_2_MM,0,2.*M_PI); - } - else if ( shape->IsA() == TGeoTubeSeg::Class() ) { - const TGeoTubeSeg* s = (const TGeoTubeSeg*)shape; - solid = new G4Tubs(name,s->GetRmin()*CM_2_MM,s->GetRmax()*CM_2_MM,s->GetDz()*CM_2_MM,s->GetPhi1()*DEGREE_2_RAD,s->GetPhi2()*DEGREE_2_RAD); - } - else if ( shape->IsA() == TGeoTrd1::Class() ) { - const TGeoTrd1* s = (const TGeoTrd1*)shape; - solid = new G4Trd(name,s->GetDx1()*CM_2_MM,s->GetDx2()*CM_2_MM,s->GetDy()*CM_2_MM,s->GetDy()*CM_2_MM,s->GetDz()*CM_2_MM); - } - else if ( shape->IsA() == TGeoTrd2::Class() ) { - const TGeoTrd2* s = (const TGeoTrd2*)shape; - solid = new G4Trd(name,s->GetDx1()*CM_2_MM,s->GetDx2()*CM_2_MM,s->GetDy1()*CM_2_MM,s->GetDy2()*CM_2_MM,s->GetDz()*CM_2_MM); - } - else if ( shape->IsA() == TGeoPgon::Class() ) { - const TGeoPgon* s = (const TGeoPgon*)shape; - double phi_start = s->GetPhi1()*DEGREE_2_RAD; - double phi_total = (s->GetDphi()+s->GetPhi1())*DEGREE_2_RAD; - vector<double> rmin, rmax, z; - for( Int_t i=0; i<s->GetNz(); ++i ) { - rmin.push_back(s->GetRmin(i)*CM_2_MM); - rmax.push_back(s->GetRmax(i)*CM_2_MM); - z.push_back(s->GetZ(i)*CM_2_MM); - } - solid = new G4Polyhedra(name,phi_start,phi_total,s->GetNedges(),s->GetNz(),&z[0],&rmin[0],&rmax[0]); - } - else if ( shape->IsA() == TGeoPcon::Class() ) { - const TGeoPcon* s = (const TGeoPcon*)shape; - double phi_start = s->GetPhi1()*DEGREE_2_RAD; - double phi_total = (s->GetDphi()+s->GetPhi1())*DEGREE_2_RAD; - vector<double> rmin, rmax, z; - for( Int_t i=0; i<s->GetNz(); ++i ) { - rmin.push_back(s->GetRmin(i)*CM_2_MM); - rmax.push_back(s->GetRmax(i)*CM_2_MM); - z.push_back(s->GetZ(i)*CM_2_MM); - } - solid = new G4Polycone(name,phi_start,phi_total,s->GetNz(),&z[0],&rmin[0],&rmax[0]); - } - else if ( shape->IsA() == TGeoConeSeg::Class() ) { - const TGeoConeSeg* s = (const TGeoConeSeg*)shape; - solid = new G4Cons(name, - s->GetRmin1()*CM_2_MM, - s->GetRmax1()*CM_2_MM, - s->GetRmin2()*CM_2_MM, - s->GetRmax2()*CM_2_MM, - s->GetDz()*CM_2_MM, - s->GetPhi1()*DEGREE_2_RAD, - s->GetPhi2()*DEGREE_2_RAD); - } - else if ( shape->IsA() == TGeoParaboloid::Class() ) { - const TGeoParaboloid* s = (const TGeoParaboloid*)shape; - solid = new G4Paraboloid(name,s->GetDz()*CM_2_MM,s->GetRlo()*CM_2_MM,s->GetRhi()*CM_2_MM); - } - else if ( shape->IsA() == TGeoSphere::Class() ) { - const TGeoSphere* s = (const TGeoSphere*)shape; - solid = new G4Sphere(name,s->GetRmin()*CM_2_MM,s->GetRmax()*CM_2_MM, - s->GetPhi1()*DEGREE_2_RAD,s->GetPhi2()*DEGREE_2_RAD, - s->GetTheta1()*DEGREE_2_RAD,s->GetTheta2()*DEGREE_2_RAD); - } - else if ( shape->IsA() == TGeoTorus::Class() ) { - const TGeoTorus* s = (const TGeoTorus*)shape; - solid = new G4Torus(name,s->GetRmin()*CM_2_MM,s->GetRmax()*CM_2_MM, s->GetR()*CM_2_MM, - s->GetPhi1()*DEGREE_2_RAD,s->GetDphi()*DEGREE_2_RAD); - } - else if ( shape->IsA() == TGeoCompositeShape::Class() ) { - const TGeoCompositeShape* s = (const TGeoCompositeShape*)shape; - const TGeoBoolNode* boolean = s->GetBoolNode(); - TGeoBoolNode::EGeoBoolType oper = boolean->GetBooleanOperator(); - TGeoMatrix* m = boolean->GetRightMatrix(); - G4VSolid* left = (G4VSolid*)handleSolid(name+"_left", boolean->GetLeftShape()); - G4VSolid* right = (G4VSolid*)handleSolid(name+"_right",boolean->GetRightShape()); - const Double_t *t = m->GetTranslation(); - const Double_t *r = m->GetRotationMatrix(); - - if ( !left ) { - throw runtime_error("G4Converter: No left Geant4 Solid present for composite shape:"+name); - } - if ( !right ) { - throw runtime_error("G4Converter: No right Geant4 Solid present for composite shape:"+name); - } - - if ( m->IsRotation() ) { - MyTransform3D transform(r[0],r[1],r[2],t[0]*CM_2_MM, - r[3],r[4],r[5],t[1]*CM_2_MM, - r[6],r[7],r[8],t[2]*CM_2_MM); - if ( oper == TGeoBoolNode::kGeoSubtraction ) - solid = new G4SubtractionSolid(name,left,right,transform); - else if ( oper == TGeoBoolNode::kGeoUnion ) - solid = new G4UnionSolid(name,left,right,transform); - else if ( oper == TGeoBoolNode::kGeoIntersection ) - solid = new G4IntersectionSolid(name,left,right,transform); - } - else { - G4ThreeVector transform(t[0]*CM_2_MM,t[1]*CM_2_MM,t[2]*CM_2_MM); - if ( oper == TGeoBoolNode::kGeoSubtraction ) - solid = new G4SubtractionSolid(name,left,right,0,transform); - else if ( oper == TGeoBoolNode::kGeoUnion ) - solid = new G4UnionSolid(name,left,right,0,transform); - else if ( oper == TGeoBoolNode::kGeoIntersection ) - solid = new G4IntersectionSolid(name,left,right,0,transform); - } - } - - if ( !solid ) { - string err = "Failed to handle unknown solid shape:" + - name + " of type " + string(shape->IsA()->GetName()); - throw runtime_error(err); - } - data().g4Solids[shape] = solid; - } - return solid; -} - -/// Dump logical volume in GDML format to output stream -void* Geant4Converter::handleVolume(const string& name, const TGeoVolume* volume) const { - Geant4GeometryInfo& info = data(); - G4LogicalVolume* vol = info.g4Volumes[volume]; - if ( !vol ) { - const TGeoVolume* v = volume; - Volume _v = Ref_t(v); - string n = v->GetName(); - TGeoMedium* m = v->GetMedium(); - TGeoShape* s = v->GetShape(); - G4VSolid* solid = (G4VSolid*)handleSolid(s->GetName(),s); - G4Material* medium = 0; - bool assembly = s->IsA() == TGeoShapeAssembly::Class(); - - SensitiveDetector det = _v.sensitiveDetector(); - G4VSensitiveDetector* sd = 0; - - if ( det.isValid() ) { - sd = info.g4SensDets[det.ptr()]; - if ( !sd ) { - throw runtime_error("G4Cnv::volume["+name+"]: + FATAL Failed to " - "access Geant4 sensitive detector."); - } - sd->Activate(true); - } - LimitSet lim = _v.limitSet(); - G4UserLimits* user_limits = 0; - if ( lim.isValid() ) { - user_limits = info.g4Limits[lim.ptr()]; - if ( !user_limits ) { - throw runtime_error("G4Cnv::volume["+name+"]: + FATAL Failed to " - "access Geant4 user limits."); - } - } - VisAttr vis = _v.visAttributes(); - G4VisAttributes* vis_attr = 0; - if ( vis.isValid() ) { - vis_attr = (G4VisAttributes*)handleVis(vis.name(),vis.ptr()); - } - Region reg = _v.region(); - G4Region* region = 0; - if ( reg.isValid() ) { - region = info.g4Regions[reg.ptr()]; - if ( !region ) { - throw runtime_error("G4Cnv::volume["+name+"]: + FATAL Failed to " - "access Geant4 region."); - } - } - - printout(DEBUG,"Geant4Converter","++ Convert Volume %-32s: %p %s/%s assembly:%s sensitive:%s", - n.c_str(),v,s->IsA()->GetName(),v->IsA()->GetName(),(assembly ? "YES" : "NO"), - (det.isValid() ? "YES" : "NO")); - - - if ( assembly ) { - vol = (G4LogicalVolume*)new G4AssemblyVolume(); - info.g4Volumes[v] = vol; - return vol; - } - medium = (G4Material*)handleMaterial(m->GetName(),m); - if ( !solid ) { - throw runtime_error("G4Converter: No Geant4 Solid present for volume:"+n); - } - if ( !medium ) { - throw runtime_error("G4Converter: No Geant4 material present for volume:"+n); - } - if ( user_limits ) { - printout(DEBUG,"++ Volume + Apply LIMITS settings:%-24s to volume %s.",lim.name(),_v.name()); - } - vol = new G4LogicalVolume(solid,medium,n,0,sd,user_limits); - if ( region ) { - printout(DEBUG,"Geant4Converter","++ Volume + Apply REGION settings: %s to volume %s.",reg.name(),_v.name()); - vol->SetRegion(region); - region->AddRootLogicalVolume(vol); - } - if ( vis_attr ) { - vol->SetVisAttributes(vis_attr); - } - if ( sd ) { - printout(DEBUG,"Geant4Converter","++ Volume: + %s <> %s Solid:%s Mat:%s SD:%s", - name.c_str(),vol->GetName().c_str(),solid->GetName().c_str(), - medium->GetName().c_str(),sd->GetName().c_str()); - } - info.g4Volumes[v] = vol; - printout(DEBUG,"Geant4Converter", "++ Volume + %s converted: %p ---> G4: %p",n.c_str(),v,vol); - } - return vol; -} - -/// Dump logical volume in GDML format to output stream -void* Geant4Converter::collectVolume(const string& /* name */, const TGeoVolume* volume) const { - Geant4GeometryInfo& info = data(); - const TGeoVolume* v = volume; - Volume _v = Ref_t(v); - Region reg = _v.region(); - LimitSet lim = _v.limitSet(); - SensitiveDetector det = _v.sensitiveDetector(); - - if ( lim.isValid() ) info.limits[lim.ptr()].insert(v); - if ( reg.isValid() ) info.regions[reg.ptr()].insert(v); - if ( det.isValid() ) info.sensitives[det.ptr()].insert(v); - return (void*)v; -} - -/// Dump volume placement in GDML format to output stream -void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) const { - static Double_t identity_rot[] = { 1., 0., 0., 0., 1., 0., 0., 0., 1. }; - Geant4GeometryInfo& info = data(); - PlacementMap::const_iterator g4it = info.g4Placements.find(node); - G4VPhysicalVolume* g4 = (g4it == info.g4Placements.end()) ? 0 : (*g4it).second; - if ( !g4 ) { - TGeoVolume* mot_vol = node->GetMotherVolume(); - TGeoVolume* vol = node->GetVolume(); - TGeoMatrix* trafo = node->GetMatrix(); - if ( !trafo ) { - printout(FATAL,"Geant4Converter","++ Attempt to handle placement without transformation:%p %s of type %s vol:%p", - node,node->GetName(),node->IsA()->GetName(),vol); - } - else if ( 0 == vol ) { - printout(FATAL,"Geant4Converter","++ Unknown G4 volume:%p %s of type %s vol:%s ptr:%p", - node,node->GetName(),node->IsA()->GetName(),vol->IsA()->GetName(),vol); - } - else { - int copy = node->GetNumber(); - G4LogicalVolume* g4vol = info.g4Volumes[vol]; - G4LogicalVolume* g4mot = info.g4Volumes[mot_vol]; - Geant4AssemblyVolume* ass_mot = (Geant4AssemblyVolume*)g4mot; - Geant4AssemblyVolume* ass_dau = (Geant4AssemblyVolume*)g4vol; - const Double_t* trans = trafo->GetTranslation(); - const Double_t* rot = trafo->IsRotation() ? trafo->GetRotationMatrix() : identity_rot; - bool daughter_is_assembly = vol->IsA() == TGeoVolumeAssembly::Class(); - bool mother_is_assembly = mot_vol ? mot_vol->IsA() == TGeoVolumeAssembly::Class() : false; - MyTransform3D transform(rot[0],rot[1],rot[2],trans[0]*CM_2_MM, - rot[3],rot[4],rot[5],trans[1]*CM_2_MM, - rot[6],rot[7],rot[8],trans[2]*CM_2_MM); - CLHEP::HepRotation rotmat=transform.getRotation(); - - if ( mother_is_assembly ) { // Mother is an assembly: - printout(DEBUG,"Geant4Converter","++ Assembly: AddPlacedVolume: %16p dau:%s " - "Tr:x=%8.3f y=%8.3f z=%8.3f Rot:phi=%7.3f theta=%7.3f psi=%7.3f\n", - ass_mot,g4vol ? g4vol->GetName().c_str() : "---", - transform.dx(),transform.dy(),transform.dz(), - rotmat.getPhi(),rotmat.getTheta(),rotmat.getPsi()); - size_t id = ass_mot->placeVolume(g4vol,transform); - info.g4AssemblyChildren[ass_mot].push_back(make_pair(id,node)); - return 0; - } - else if ( daughter_is_assembly ) { - printout(DEBUG,"Geant4Converter","++ Assembly: makeImprint: %16p dau:%s " - "Tr:x=%8.3f y=%8.3f z=%8.3f Rot:phi=%7.3f theta=%7.3f psi=%7.3f\n", - ass_dau,g4mot ? g4mot->GetName().c_str() : "---", - transform.dx(),transform.dy(),transform.dz(), - rotmat.getPhi(),rotmat.getTheta(),rotmat.getPsi()); - std::vector<G4VPhysicalVolume*> phys_volumes; - AssemblyChildMap::iterator i = info.g4AssemblyChildren.find(ass_dau); - if ( i == info.g4AssemblyChildren.end() ) { - printout(ERROR, "Geant4Converter", "++ Non-existing assembly [%p]",ass_dau); - } - const AssemblyChildren& v = (*i).second; - ass_dau->imprint(phys_volumes,g4mot,transform,copy,m_checkOverlaps); - if ( v.size() != phys_volumes.size() ) { - printout(ERROR, "Geant4Converter", "++ Unexpected number of placements in assembly: %ld <> %ld.", - v.size(), phys_volumes.size()); - } - for(size_t j=0; j<v.size(); ++j) { - info.g4Placements[v[j].second] = phys_volumes[j]; - } - return 0; - } - g4 = new G4PVPlacement(transform, // no rotation - g4vol, // its logical volume - name, // its name - g4mot, // its mother (logical) volume - false, // no boolean operations - copy, // its copy number - m_checkOverlaps); - } - info.g4Placements[node] = g4; - } - else { - printout(ERROR, "Geant4Converter", "++ Attempt to DOUBLE-place physical volume: %s No:%d", - name.c_str(),node->GetNumber()); - } - return g4; -} - -/// Convert the geometry type region into the corresponding Geant4 object(s). -void* Geant4Converter::handleRegion(const TNamed* region, const set<const TGeoVolume*>& /* volumes */) const { - G4Region* g4 = data().g4Regions[region]; - if ( !g4 ) { - Region r = Ref_t(region); - g4 = new G4Region(r.name()); - // set production cut - G4ProductionCuts* cuts = new G4ProductionCuts(); - cuts->SetProductionCut(r.cut()); - g4->SetProductionCuts(cuts); - - // create region info with storeSecondaries flag - G4UserRegionInformation* info = new G4UserRegionInformation(); - info->region = r; - info->threshold = r.threshold(); - info->storeSecondaries = r.storeSecondaries(); - g4->SetUserInformation(info); - - printout(INFO, "Geant4Converter", "++ Converted region settings of:%s.",r.name()); - vector<string>& limits = r.limits(); - for(vector<string>::const_iterator i=limits.begin(); i!=limits.end(); ++i) { - const string& nam = *i; - LimitSet ls = m_detDesc.limitSet(nam); - if ( ls.isValid() ) { - bool found = false; - const LimitMap& lm = data().g4Limits; - for(LimitMap::const_iterator j=lm.begin(); j!=lm.end();++j) { - if ( nam == (*j).first->GetName() ) { - g4->SetUserLimits((*j).second); - found = true; - break; - } - } - if ( found ) continue; - } - throw runtime_error("G4Region: Failed to resolve user limitset:"+*i); - } - data().g4Regions[region] = g4; - } - return g4; -} - -/// Convert the geometry type LimitSet into the corresponding Geant4 object(s). -void* Geant4Converter::handleLimitSet(const TNamed* limitset, const set<const TGeoVolume*>& /* volumes */) const { - G4UserLimits* g4 = data().g4Limits[limitset]; - if ( !g4 ) { - LimitSet ls = Ref_t(limitset); - g4 = new G4UserLimits(limitset->GetName()); - const set<Limit>& limits = ls.limits(); - for(LimitSet::Object::const_iterator i=limits.begin(); i!=limits.end(); ++i) { - const Limit& l = *i; - if ( l.name == "step_length_max" ) - g4->SetMaxAllowedStep(l.value); - else if ( l.name == "track_length_max" ) - g4->SetMaxAllowedStep(l.value); - else if ( l.name == "time_max" ) - g4->SetUserMaxTime(l.value); - else if ( l.name == "ekin_min" ) - g4->SetUserMinEkine(l.value); - else if ( l.name == "range_min" ) - g4->SetUserMinRange(l.value); - else - throw runtime_error("Unknown Geant4 user limit: "+l.toString()); - } - data().g4Limits[limitset] = g4; - } - return g4; -} - -/// Convert the geometry type SensitiveDetector into the corresponding Geant4 object(s). -void* Geant4Converter::handleSensitive(const TNamed* sens_det, const set<const TGeoVolume*>& /* volumes */) const { - Geant4GeometryInfo& info = data(); - G4VSensitiveDetector* g4 = info.g4SensDets[sens_det]; - if ( !g4 ) { - SensitiveDetector sd = Ref_t(sens_det); - string type = sd.type(), name = sd.name(); - g4 = PluginService::Create<G4VSensitiveDetector*>(type,name,&m_detDesc); - if ( !g4 ) { - string tmp = type; - tmp[0] = ::toupper(tmp[0]); - type = "Geant4"+tmp; - g4 = PluginService::Create<G4VSensitiveDetector*>(type,name,&m_detDesc); - if ( !g4 ) { - PluginDebug dbg; - g4 = ROOT::Reflex::PluginService::Create<G4VSensitiveDetector*>(type,name,&m_detDesc); - throw runtime_error("Geant4Converter<SensitiveDetector>: FATAL Failed to " - "create Geant4 sensitive detector factory "+name+" of type "+type+"."); - } - } - g4->Activate(true); - G4SDManager::GetSDMpointer()->AddNewDetector(g4); - info.g4SensDets[sens_det] = g4; - } - return g4; -} - -/// Convert the geometry visualisation attributes to the corresponding Geant4 object(s). -void* Geant4Converter::handleVis(const string& /* name */, const TNamed* vis) const { - Geant4GeometryInfo& info = data(); - G4VisAttributes* g4 = info.g4Vis[vis]; - if ( !g4 ) { - float r=0, g=0, b=0; - VisAttr attr = Ref_t(vis); - int style = attr.lineStyle(); - attr.rgb(r,g,b); - g4 = new G4VisAttributes(attr.visible(),G4Colour(r,g,b,attr.alpha())); - //g4->SetLineWidth(attr->GetLineWidth()); - g4->SetDaughtersInvisible(!attr.showDaughters()); - if ( style == VisAttr::SOLID ) { - g4->SetLineStyle(G4VisAttributes::unbroken); - g4->SetForceWireframe(false); - g4->SetForceSolid(true); - } - else if ( style == VisAttr::WIREFRAME || style == VisAttr::DASHED ) { - g4->SetLineStyle(G4VisAttributes::dashed); - g4->SetForceSolid(false); - g4->SetForceWireframe(true); - } - info.g4Vis[vis] = g4; - } - return g4; -} - -/// Handle the geant 4 specific properties -void Geant4Converter::handleProperties(Detector::Properties& prp) const { - map<string,string> processors; - static int s_idd = 9999999; - string id; - for(Detector::Properties::const_iterator i=prp.begin(); i!=prp.end(); ++i) { - const string& nam = (*i).first; - const Detector::PropertyValues& vals = (*i).second; - if ( nam.substr(0,6) == "geant4" ) { - Detector::PropertyValues::const_iterator id_it = vals.find("id"); - if ( id_it != vals.end() ) { - id= (*id_it).second; - } - else { - char txt[32]; - ::sprintf(txt,"%d",++s_idd); - id = txt; - } - processors.insert(make_pair(id,nam)); - } - } - for(map<string,string>::const_iterator i=processors.begin(); i!=processors.end(); ++i) { - const Geant4Converter* ptr = this; - string nam = (*i).second; - const Detector::PropertyValues& vals = prp[nam]; - string type = vals.find("type")->second; - string tag = type + "_Geant4_action"; - long result = ROOT::Reflex::PluginService::Create<long>(tag,&m_detDesc,ptr,&vals); - if ( 0 == result ) { - throw runtime_error("Failed to locate plugin to interprete files of type" - " \""+tag+"\" - no factory:"+type); - } - result = *(long*)result; - if ( result != 1 ) { - throw runtime_error("Failed to invoke the plugin "+tag+" of type "+type); - } - printout(INFO, "Geant4Converter", "+++++ Executed Successfully Geant4 setup module *%s*.",type.c_str()); - } -} - - -/// Convert the geometry type SensitiveDetector into the corresponding Geant4 object(s). -void* Geant4Converter::printSensitive(const TNamed* sens_det, const set<const TGeoVolume*>& /* volumes */) const { - Geant4GeometryInfo& info = data(); - G4VSensitiveDetector* g4 = info.g4SensDets[sens_det]; - ConstVolumeSet& volset = info.sensitives[sens_det]; - SensitiveDetector sd = Ref_t(sens_det); - stringstream str; - - printout(INFO, "Geant4Converter", "++ SensitiveDetector: %-18s %-20s Hits:%-16s", - sd.name(), ("["+sd.type()+"]").c_str(),sd.hitsCollection().c_str()); - str << " | " - << "Cutoff:" << setw(6) << left << sd.energyCutoff() - << setw(5) << right << volset.size() << " volumes "; - if ( sd.region().isValid() ) str << " Region:" << setw(12) << left << sd.region().name(); - if ( sd.limits().isValid() ) str << " Limits:" << setw(12) << left << sd.limits().name(); - str << "."; - printout(INFO, "Geant4Converter", str.str().c_str()); - - for(ConstVolumeSet::iterator i=volset.begin(); i!=volset.end();++i) { - map<const TGeoVolume*, G4LogicalVolume*>::iterator v = info.g4Volumes.find(*i); - G4LogicalVolume* vol = (*v).second; - str.str(""); - str << " | " - << "Volume:" << setw(24) << left << vol->GetName() - << " " << vol->GetNoDaughters() << " daughters."; - printout(INFO, "Geant4Converter", str.str().c_str()); - } - return g4; -} - -string printSolid(G4VSolid* sol) { - stringstream str; - if ( typeid(*sol) == typeid(G4Box) ) { - const G4Box* b = (G4Box*)sol; - str << "++ Box: x=" << b->GetXHalfLength() << " y=" << b->GetYHalfLength() << " z=" << b->GetZHalfLength(); - } - else if ( typeid(*sol) == typeid(G4Tubs) ) { - const G4Tubs* t = (const G4Tubs*)sol; - str << " Tubs: Ri=" << t->GetInnerRadius() << " Ra=" << t->GetOuterRadius() - << " z/2=" << t->GetZHalfLength() << " Phi=" << t->GetStartPhiAngle() - << "..." << t->GetDeltaPhiAngle (); - } - return str.str(); -} - -/// Print G4 placement -void* Geant4Converter::printPlacement(const string& name, const TGeoNode* node) const { - Geant4GeometryInfo& info = data(); - G4VPhysicalVolume* g4 = info.g4Placements[node]; - G4LogicalVolume* vol = info.g4Volumes[node->GetVolume()]; - G4LogicalVolume* mot = info.g4Volumes[node->GetMotherVolume()]; - G4VSolid* sol = vol->GetSolid(); - G4ThreeVector tr = g4->GetObjectTranslation(); - - G4VSensitiveDetector* sd = vol->GetSensitiveDetector(); - if ( !sd ) return g4; - - stringstream str; - str << "G4Cnv::placement: + " << name << " No:" << node->GetNumber() - << " Vol:" << vol->GetName() << " Solid:" << sol->GetName(); - printout(DEBUG,"G4Placement",str.str().c_str()); - str.str(""); - str << " |" - << " Loc: x=" << tr.x() << " y=" << tr.y() << " z=" << tr.z(); - printout(DEBUG,"G4Placement",str.str().c_str()); - printout(DEBUG,"G4Placement",printSolid(sol).c_str()); - str.str(""); - str << " |" - << " Ndau:" << vol->GetNoDaughters() << " physvols." - << " Mat:" << vol->GetMaterial()->GetName() - << " Mother:" << (char*)(mot ? mot->GetName().c_str() : "---"); - printout(DEBUG,"G4Placement",str.str().c_str()); - str.str(""); - str << " |" - << " SD:" << (char*)(sd ? sd->GetName().c_str() : "---"); - printout(DEBUG,"G4Placement",str.str().c_str()); - return g4; -} - -template <typename O, typename C, typename F> void handle(const O* o, const C& c, F pmf) { - for(typename C::const_iterator i=c.begin(); i != c.end(); ++i) { - (o->*pmf)((*i)->GetName(),*i); - } -} - -template <typename O, typename C, typename F> void handleMap(const O* o, const C& c, F pmf) { - for(typename C::const_iterator i=c.begin(); i != c.end(); ++i) - (o->*pmf)((*i).first, (*i).second); -} - -template <typename O, typename C, typename F> void handleRMap(const O* o, const C& c, F pmf) { - for(typename C::const_reverse_iterator i=c.rbegin(); i != c.rend(); ++i) - handle(o, (*i).second, pmf); -} - -/// Create geometry conversion -Geant4Converter& Geant4Converter::create(DetElement top) { - Geant4GeometryInfo& geo = this->init(); - m_data->clear(); - collect(top, geo); - s_topPtr = top.placement().ptr(); - m_checkOverlaps = false; - - // We do not have to handle defines etc. - // All positions and the like are not really named. - // Hence, start creating the G4 objects for materials, solids and log volumes. - Material mat = m_detDesc.material("Argon"); - handleMaterial(mat.name(),mat.ptr()); - mat = m_detDesc.material("Silicon"); - handleMaterial(mat.name(),mat.ptr()); - - handle(this, geo.volumes, &Geant4Converter::collectVolume); - handle(this, geo.solids, &Geant4Converter::handleSolid); - printout(INFO,"Geant4Converter","++ Handled %ld solids.",geo.solids.size()); - handle(this, geo.vis, &Geant4Converter::handleVis); - printout(INFO,"Geant4Converter","++ Handled %ld visualization attributes.",geo.vis.size()); - handleMap(this, geo.sensitives, &Geant4Converter::handleSensitive); - printout(INFO,"Geant4Converter","++ Handled %ld sensitive detectors.",geo.sensitives.size()); - handleMap(this, geo.limits, &Geant4Converter::handleLimitSet); - printout(INFO,"Geant4Converter","++ Handled %ld limit sets.",geo.limits.size()); - handleMap(this, geo.regions, &Geant4Converter::handleRegion); - printout(INFO,"Geant4Converter","++ Handled %ld regions.",geo.regions.size()); - handle(this, geo.volumes, &Geant4Converter::handleVolume); - printout(INFO,"Geant4Converter","++ Handled %ld volumes.",geo.volumes.size()); - // Now place all this stuff appropriately - handleRMap(this, *m_data, &Geant4Converter::handlePlacement); - //==================== Fields - handleProperties(m_detDesc.properties()); - - //handleMap(this, geo.sensitives, &Geant4Converter::printSensitive); - //handleRMap(this, *m_data, &Geant4Converter::printPlacement); - geo.valid = true; - return *this; -} diff --git a/DDG4/src/Geant4VolumeManager.cpp b/DDG4/src/Geant4VolumeManager.cpp index cb36b0c98b90bff3ad96586d4211460f9c98d75f..4090ba2238c79d87ff029b58aa1e78d567a9aee1 100644 --- a/DDG4/src/Geant4VolumeManager.cpp +++ b/DDG4/src/Geant4VolumeManager.cpp @@ -76,7 +76,7 @@ namespace { /// Scan a single physical volume and look for sensitive elements below void scanPhysicalVolume(const TGeoNode* node, PlacedVolume::VolIDs ids, SensitiveDetector& sd, Chain& chain) { - PlacedVolume pv = Ref_t(node); + PlacedVolume pv = node; Volume vol = pv.volume(); PlacedVolume::VolIDs pv_ids = pv.volIDs(); diff --git a/UtilityApps/src/materialScan.cpp b/UtilityApps/src/materialScan.cpp index 91a33806d5b5e7969e6256929461bf9606a7beda..467ad1aec9a644c93b421be9c251e340f22138ca 100644 --- a/UtilityApps/src/materialScan.cpp +++ b/UtilityApps/src/materialScan.cpp @@ -58,6 +58,8 @@ int main_wrapper(int argc, char** argv) { direction = (p1-p0).unit(); MaterialManager matMgr( description.world().volume() ) ; + //MaterialManager matMgr( description.world() ) ; + const MaterialVec& materials = matMgr.materialsBetween(p0, p1); double sum_x0 = 0; double sum_lambda = 0; diff --git a/examples/AlignDet/CMakeLists.txt b/examples/AlignDet/CMakeLists.txt index 10d51bf8b708d83b36b17c058dbe02dba4a67d2c..97ae44895661dab40b40fc5121f0b2861ef33edf 100644 --- a/examples/AlignDet/CMakeLists.txt +++ b/examples/AlignDet/CMakeLists.txt @@ -21,7 +21,7 @@ dd4hep_package ( AlignDet MAJOR 0 MINOR 0 PATCH 1 ) dd4hep_add_plugin( AlignDetExample SOURCES src/*.cpp ) -dd4hep_install_dir( compact DESTINATION examples/AlignDet ) +dd4hep_install_dir( compact DESTINATION ${DD4hep_DIR}/examples/AlignDet ) dd4hep_configure_scripts( AlignDet DEFAULT_SETUP WITH_TESTS) #