diff --git a/DDCore/include/DD4hep/Handle.h b/DDCore/include/DD4hep/Handle.h index e1109ec07dee8b35fcb91ca19b558935fbdfa45a..9f72bc4e96148d6d8c16de3659a3356868341418 100644 --- a/DDCore/include/DD4hep/Handle.h +++ b/DDCore/include/DD4hep/Handle.h @@ -91,26 +91,23 @@ namespace dd4hep { /// Single and only data member: Reference to the actual element. T* m_element = 0; + /// 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(element ? detail::safe_cast<T>::template cast(element) : 0) + : m_element(element ? detail::safe_cast<T>::cast(element) : 0) { } - /// Initializing constructor from unrelated handle with type checking template <typename Q> Handle(const Handle<Q>& element) - : m_element(element.m_element ? detail::safe_cast<T>::template cast(element.m_element) : 0) + : m_element(element.m_element ? detail::safe_cast<T>::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; diff --git a/DDCore/include/DD4hep/Shapes.h b/DDCore/include/DD4hep/Shapes.h index 057aba4fc7e82fb6e24037db4d07aaef2caeb1d7..1872f1df81c1496550f2e4d62c8517e048ac0d3d 100644 --- a/DDCore/include/DD4hep/Shapes.h +++ b/DDCore/include/DD4hep/Shapes.h @@ -33,6 +33,7 @@ #include "TGeoPcon.h" #include "TGeoSphere.h" #include "TGeoArb8.h" +#include "TGeoTrd1.h" #include "TGeoTrd2.h" #include "TGeoTube.h" #include "TGeoEltu.h" @@ -40,6 +41,7 @@ #include "TGeoTorus.h" #include "TGeoHalfSpace.h" #include "TGeoCompositeShape.h" +#include "TGeoShapeAssembly.h" #ifdef __GNUC__ #pragma GCC diagnostic pop #endif diff --git a/DDCore/src/Handle.cpp b/DDCore/src/Handle.cpp index 99202cd8063630865c7097312986752f117298c1..24d17a5217a6190f01581ebb373ff176bce03f8a 100644 --- a/DDCore/src/Handle.cpp +++ b/DDCore/src/Handle.cpp @@ -293,7 +293,10 @@ DD4HEP_INSTANTIATE_HANDLE(TGeoCombiTrans); DD4HEP_INSTANTIATE_HANDLE(TGeoGenTrans); #include "TGeoNode.h" -DD4HEP_INSTANTIATE_HANDLE(TGeoNode); +DD4HEP_INSTANTIATE_HANDLE_CODE(RAW,TGeoAtt); +DD4HEP_INSTANTIATE_HANDLE_CODE(RAW,TAtt3D); +DD4HEP_INSTANTIATE_HANDLE_CODE(RAW,TAttLine); +DD4HEP_INSTANTIATE_HANDLE(TGeoNode,TGeoAtt); DD4HEP_INSTANTIATE_HANDLE(TGeoNodeMatrix); DD4HEP_INSTANTIATE_HANDLE(TGeoNodeOffset); @@ -313,7 +316,8 @@ DD4HEP_INSTANTIATE_HANDLE(TGeoNodeOffset); #include "TGeoVolume.h" #include "TGeoCompositeShape.h" #include "TGeoShapeAssembly.h" -DD4HEP_INSTANTIATE_HANDLE(TGeoVolume,TGeoAtt); +DD4HEP_INSTANTIATE_HANDLE(TGeoVolumeAssembly,TGeoVolume,TGeoAtt); +DD4HEP_INSTANTIATE_HANDLE(TGeoVolume,TGeoAtt,TAttLine,TAtt3D); DD4HEP_INSTANTIATE_HANDLE(TGeoShape); DD4HEP_INSTANTIATE_HANDLE(TGeoBBox,TGeoShape); @@ -323,12 +327,12 @@ 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(TGeoHype,TGeoTube); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoPgon,TGeoPcon); DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTube); -DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoEltu); -DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTubeSeg); -DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTrap); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoEltu,TGeoTube); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTubeSeg,TGeoTube); +DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTrap,TGeoArb8); DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTrd1); DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoTrd2); DD4HEP_INSTANTIATE_SHAPE_HANDLE(TGeoSphere); diff --git a/examples/ClientTests/CMakeLists.txt b/examples/ClientTests/CMakeLists.txt index 1560460b077002770e9d4cf051f3e5fde30912c2..24186cc85bfcd510c6ab24be66caf0bae9f4659c 100644 --- a/examples/ClientTests/CMakeLists.txt +++ b/examples/ClientTests/CMakeLists.txt @@ -99,6 +99,14 @@ dd4hep_add_test_reg( ClientTests_Bitfield64_BarrelSides2 -plugin DD4hepVolumeMgrTest all REGEX_PASS "Volume:Shell_2 IDDesc:OK \\[S\\] vid:0000000000010002 system:0002 barrel:0001") # +# Test handle casting procedures. +dd4hep_add_test_reg( ClientTests_Check_Handle_Casts + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh" + EXEC_ARGS geoPluginRun + -volmgr -destroy -input file:${CMAKE_CURRENT_SOURCE_DIR}/compact/Check_Handles.xml + -plugin DD4hepDetectorVolumeDump + REGEX_PASS "| PASSED casts: 86 FAILED casts: 86 |") +# # foreach (test Assemblies BoxTrafos IronCylinder LheD_tracker MagnetFields MaterialTester MiniTel SectorBarrelCalorimeter SiliconBlock NestedSimple NestedDetectors diff --git a/examples/ClientTests/compact/Check_Handles.xml b/examples/ClientTests/compact/Check_Handles.xml new file mode 100644 index 0000000000000000000000000000000000000000..2468d394a0317913051d936271e33d5a60dcb0a2 --- /dev/null +++ b/examples/ClientTests/compact/Check_Handles.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd"> + + <includes> + <gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/elements.xml"/> + <gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/materials.xml"/> + </includes> + + <define> + <constant name="world_size" value="30*m"/> + <constant name="world_x" value="world_size"/> + <constant name="world_y" value="world_size"/> + <constant name="world_z" value="world_size"/> + </define> + + <display> + <vis name="Invisible" showDaughters="false" visible="false"/> + <vis name="InvisibleWithChildren" showDaughters="true" visible="false"/> + <vis name="VisibleGreen" alpha="1.0" r="0.0" g="1.0" b="0.0" drawingStyle="solid" lineStyle="solid" showDaughters="true" visible="true"/> + </display> + + <limits> + <limitset name="cal_limits"> + <limit name="step_length_max" particles="*" value="5.0" unit="mm" /> + </limitset> + </limits> + + <detectors> + <detector id="1" name="Shell" type="DD4hep_Check_Handles" readout="ContainmentHits" vis="VisibleGreen" limits="cal_limits" region="Bla"> + <dimensions rmin="10*cm" rmax="500*cm" z="600*cm" phiBins="64" /> + </detector> + </detectors> + + <readouts> + <readout name="ContainmentHits"> + <id>system:8,barrel:16,module:16</id> + </readout> + </readouts> + <regions> + <region name="Bla" eunit="MeV" lunit="mm" cut="0.001" threshold="0.001"> + <limitsetref name="SiRegionLimitSet"/> + </region> + </regions> + + <fields> + <field name="GlobalSolenoid" type="solenoid" + inner_field="5.0*tesla" + outer_field="-1.5*tesla" + zmax="2*m" + outer_radius="3*m"> + </field> + </fields> +</lccdd> diff --git a/examples/ClientTests/src/Check_Handles.cpp b/examples/ClientTests/src/Check_Handles.cpp new file mode 100644 index 0000000000000000000000000000000000000000..60300dc2b222c60f04e58792aa854ee4248b4085 --- /dev/null +++ b/examples/ClientTests/src/Check_Handles.cpp @@ -0,0 +1,200 @@ +//========================================================================== +// 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 +// +//========================================================================== + +// Framework includes +#include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/Printout.h" +#include "DD4hep/Detector.h" +#include "DD4hep/Objects.h" +#include "DD4hep/World.h" + +using namespace dd4hep; +using namespace dd4hep::detail; + +namespace { + typedef std::pair<int,int> Result; + std::pair<int,int>& operator += (std::pair<int,int>& left, const std::pair<int,int>& right) { + left.first += right.first; + left.second += right.second; + return left; + } + template <typename T, typename Q> Result test_handle(T& from) { + Result r(0,0); + try { + Q to(from); + if ( to.ptr() && from.ptr() ) { + printout(INFO,"Check_Handles","PASSED: Handle Construction from %s to %s.", + typeName(typeid(T)).c_str(),typeName(typeid(Q)).c_str()); + ++r.first; + } + else if ( !to.ptr() && from.ptr() ) { + printout(INFO,"Check_Handles","FAILED: Handle Construction from %s to %s.", + typeName(typeid(T)).c_str(),typeName(typeid(Q)).c_str()); + ++r.second; + } + } + catch(const std::exception& e) { + printout(INFO,"Check_Handles", "FAILED: Handle Construction from %s to %s. [Exception]", + typeName(typeid(T)).c_str(),typeName(typeid(Q)).c_str()); + ++r.second; + } + try { + Q to = from; + if ( to.ptr() && from.ptr() ) { + printout(INFO,"Check_Handles","PASSED: Assignment from %s to %s.", + typeName(typeid(T)).c_str(),typeName(typeid(Q)).c_str()); + ++r.first; + } + else if ( !to.ptr() && from.ptr() ) { + printout(INFO,"Check_Handles","FAILED: Assignment from %s to %s.", + typeName(typeid(T)).c_str(),typeName(typeid(Q)).c_str()); + ++r.second; + } + } + catch(const std::exception& e) { + printout(INFO,"Check_Handles","FAILED: Assignment from %s to %s. [Exception]", + typeName(typeid(T)).c_str(),typeName(typeid(Q)).c_str()); + ++r.second; + } + return r; + } + template <typename T> Result check_handle(T& h) { + Result r(0,0); + r += test_handle<T, T>(h); + r += test_handle<T, Handle<typename T::Object> >(h); + r += test_handle<T, Handle<NamedObject> >(h); + r += test_handle<T, Handle<TObject> >(h); + r += test_handle<T, Handle<TNamed> >(h); + return r; + } + Result check_handle(Solid& h) { + Result r(0,0); + r += test_handle<Solid, Solid>(h); + r += test_handle<Solid, Box>(h); + r += test_handle<Solid, HalfSpace>(h); + r += test_handle<Solid, Polycone>(h); + r += test_handle<Solid, ConeSegment>(h); + r += test_handle<Solid, Tube>(h); + r += test_handle<Solid, EllipticalTube>(h); + r += test_handle<Solid, Cone>(h); + r += test_handle<Solid, Trap>(h); + r += test_handle<Solid, Trapezoid>(h); + r += test_handle<Solid, Paraboloid>(h); + r += test_handle<Solid, Hyperboloid>(h); + r += test_handle<Solid, PolyhedraRegular>(h); + r += test_handle<Solid, Torus>(h); + r += test_handle<Solid, Sphere>(h); + r += test_handle<Solid, EightPointSolid>(h); + r += test_handle<Solid, SubtractionSolid>(h); + r += test_handle<Solid, UnionSolid>(h); + r += test_handle<Solid, IntersectionSolid>(h); + r += test_handle<Solid, Handle<TGeoShape> >(h); + r += test_handle<Solid, Handle<TGeoBBox> >(h); + r += test_handle<Solid, Handle<TGeoCone> >(h); + r += test_handle<Solid, Handle<TGeoArb8> >(h); + r += test_handle<Solid, Handle<TGeoConeSeg> >(h); + r += test_handle<Solid, Handle<TGeoParaboloid> >(h); + r += test_handle<Solid, Handle<TGeoPcon> >(h); + r += test_handle<Solid, Handle<TGeoHype> >(h); + r += test_handle<Solid, Handle<TGeoPgon> >(h); + r += test_handle<Solid, Handle<TGeoTube> >(h); + r += test_handle<Solid, Handle<TGeoEltu> >(h); + r += test_handle<Solid, Handle<TGeoTubeSeg> >(h); + r += test_handle<Solid, Handle<TGeoTrap> >(h); + r += test_handle<Solid, Handle<TGeoTrd1> >(h); + r += test_handle<Solid, Handle<TGeoTrd2> >(h); + r += test_handle<Solid, Handle<TGeoSphere> >(h); + r += test_handle<Solid, Handle<TGeoTorus> >(h); + r += test_handle<Solid, Handle<TGeoHalfSpace> >(h); + r += test_handle<Solid, Handle<TGeoShapeAssembly> >(h); + r += test_handle<Solid, Handle<TGeoCompositeShape> >(h); + return r; + } + Result check_handle(Volume& h) { + Result r(0,0); + r += test_handle<Volume, Volume>(h); + r += test_handle<Volume, Assembly>(h); + r += test_handle<Volume, Handle<TGeoAtt> >(h); + r += test_handle<Volume, Handle<NamedObject> >(h); + r += test_handle<Volume, Handle<TObject> >(h); + r += test_handle<Volume, Handle<TNamed> >(h); + r += test_handle<Volume, Handle<TGeoAtt> >(h); + r += test_handle<Volume, Handle<TAttLine> >(h); + r += test_handle<Volume, Handle<TAtt3D> >(h); + return r; + } + Result check_handle(Assembly& h) { + Result r(0,0); + r += test_handle<Assembly, Assembly>(h); + r += test_handle<Assembly, Volume>(h); + r += test_handle<Assembly, Handle<TGeoAtt> >(h); + r += test_handle<Assembly, Handle<NamedObject> >(h); + r += test_handle<Assembly, Handle<TObject> >(h); + r += test_handle<Assembly, Handle<TNamed> >(h); + r += test_handle<Assembly, Handle<TGeoAtt> >(h); + r += test_handle<Assembly, Handle<TAttLine> >(h); + r += test_handle<Assembly, Handle<TAtt3D> >(h); + return r; + } + Result check_handle(PlacedVolume& h) { + Result r(0,0); + r += test_handle<PlacedVolume, PlacedVolume>(h); + r += test_handle<PlacedVolume, Handle<NamedObject> >(h); + r += test_handle<PlacedVolume, Handle<TObject> >(h); + r += test_handle<PlacedVolume, Handle<TNamed> >(h); + return r; + } +} + +static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens) { + // XML detector object: DDCore/XML/XMLDetector.h + xml_dim_t x_det = e; + xml_dim_t x_det_dim(x_det.dimensions()); + DetElement d_det(x_det.nameStr(),x_det.id()); + Assembly calo_vol(x_det.nameStr()+"_envelope"); + VisAttr vis = description.visAttributes(x_det.visStr()); + Region reg = description.region(x_det.regionStr()); + LimitSet lim = description.limitSet(x_det.limitsStr()); + + // Declare this sensitive detector as a calorimeter + Tube tub(x_det_dim.rmin(), x_det_dim.rmax(), x_det_dim.z()/2.0,0.0,2*M_PI); + Volume tub_vol(x_det.nameStr()+"_tube",tub,description.material("Iron")); + calo_vol.placeVolume(tub_vol).addPhysVolID("module",1); + sens.setType("calorimeter"); + tub_vol.setSensitiveDetector(sens); + + // Place the calo inside the world + PlacedVolume calo_plv = description.pickMotherVolume(d_det).placeVolume(calo_vol); + calo_plv.addPhysVolID("system",x_det.id()); + calo_plv.addPhysVolID("barrel",0); + d_det.setPlacement(calo_plv); + Result result(0,0); + Solid sol = tub; + result += check_handle(calo_plv); + result += check_handle(tub_vol); + result += check_handle(sol); + result += check_handle(calo_vol); + result += check_handle(d_det); + result += check_handle(sens); + result += check_handle(vis); + result += check_handle(lim); + result += check_handle(reg); + + //result += test_handle<Assembly,Region>(calo_vol); + printout(INFO,"Check_Handles","+-----------------------------------------------------------------+"); + printout(INFO,"Check_Handles","| PASSED casts: %-4d FAILED casts: %-4d |", + result.first, result.second); + printout(INFO,"Check_Handles","+-----------------------------------------------------------------+"); + return d_det; +} +DECLARE_DETELEMENT(DD4hep_Check_Handles,create_detector) diff --git a/examples/ClientTests/src/IronCylinder_geo.cpp b/examples/ClientTests/src/IronCylinder_geo.cpp index 9f73e53df3110b43a5228fc7530076f13fc88460..c061759c071d8b5792d9b984e2b99119772bfce2 100644 --- a/examples/ClientTests/src/IronCylinder_geo.cpp +++ b/examples/ClientTests/src/IronCylinder_geo.cpp @@ -25,10 +25,9 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s // XML dimension object: DDCore/XML/XMLDimension.h xml_dim_t x_det_dim(x_det.dimensions()); - double inner_r = x_det_dim.rmin(); - double outer_r = x_det_dim.rmax(); - Assembly calo_vol(x_det.nameStr()+"_envelope"); - PlacedVolume pv; + double inner_r = x_det_dim.rmin(); + double outer_r = x_det_dim.rmax(); + Assembly calo_vol(x_det.nameStr()+"_envelope"); // Set envelope volume attributes calo_vol.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());