diff --git a/DDCore/CMakeLists.txt b/DDCore/CMakeLists.txt index a21b875d90cbd9e789a5b7f56d489777e24552a4..3ce3fffa772e27d66b7d8ccc22b896fe4cd5be51 100644 --- a/DDCore/CMakeLists.txt +++ b/DDCore/CMakeLists.txt @@ -22,12 +22,18 @@ else() file(GLOB parser_sources ) endif() +file(GLOB headers include/DD4hep/*.h) +file(GLOB internal_headers include/DD4hep/objects/*.h) +list(APPEND headers ${CMAKE_SOURCE_DIR}/DDSegmentation/include/DDSegmentation/BitField64.h) +list(APPEND headers ${CMAKE_SOURCE_DIR}/DDSegmentation/include/DDSegmentation/Segmentation.h) +list(REMOVE_ITEM headers ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/DetFactoryHelper.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/Factories.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/Plugins.h + ) +root_generate_dictionary( G__DD4hep ${headers} ${internal_headers} LINKDEF include/ROOT/LinkDef.h) +list(APPEND sources G__DD4hep.cxx) + if(DD4HEP_USE_PYROOT) - file(GLOB headers include/DD4hep/*.h) - list(REMOVE_ITEM headers ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/DetFactoryHelper.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/Factories.h) - root_generate_dictionary( G__DD4hep ${headers} LINKDEF include/ROOT/LinkDef.h) - list(APPEND sources G__DD4hep.cxx) add_definitions(-DDD4HEP_USE_PYROOT) set(libraries ${libraries} PyROOT) endif() diff --git a/DDCore/include/DD4hep/Conditions.h b/DDCore/include/DD4hep/Conditions.h index 42738ed14aa5159dbea752a1d6396a645b90faa2..0f8fb5eb0d6131b34168dc5e1de97b098583618d 100644 --- a/DDCore/include/DD4hep/Conditions.h +++ b/DDCore/include/DD4hep/Conditions.h @@ -29,8 +29,8 @@ namespace DD4hep { class DetElement; namespace ConditionsInterna { - class Container; - class Object; + class ConditionContainer; + class ConditionObject; class Entry; class IOV; } @@ -76,9 +76,9 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - class Condition: public Handle<ConditionsInterna::Object> { + class Condition: public Handle<ConditionsInterna::ConditionObject> { public: - typedef ConditionsInterna::Object Object; + typedef ConditionsInterna::ConditionObject Object; typedef ConditionsInterna::Entry Entry; typedef ConditionsInterna::IOV IOV; @@ -151,15 +151,15 @@ namespace DD4hep { }; /// Initializing constructor - inline Condition::Condition(Object* p) : Handle<Object>(p) { + inline Condition::Condition(Condition::Object* p) : Handle<Condition::Object>(p) { } /// Copy constructor - inline Condition::Condition(const Condition& c) : Handle<Object>(c) { + inline Condition::Condition(const Condition& c) : Handle<Condition::Object>(c) { } /// Default constructor - inline Condition::Condition() : Handle<Object>() { + inline Condition::Condition() : Handle<Condition::Object>() { } /** @class Conditions Conditions.h DD4hep/Conditions.h @@ -171,9 +171,9 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct Conditions : public Handle<ConditionsInterna::Container> { + struct Conditions : public Handle<ConditionsInterna::ConditionContainer> { /// Standard object type - typedef ConditionsInterna::Container Object; + typedef ConditionsInterna::ConditionContainer Object; /// Local helper definition typedef ConditionsInterna::Entry Entry; diff --git a/DDCore/include/DD4hep/Detector.h b/DDCore/include/DD4hep/Detector.h index 1befd60ef007cbd42f5a3ecd3531e159f7d0eb32..f9cc577302f10c244b71fc976c8fcacdfb426310 100644 --- a/DDCore/include/DD4hep/Detector.h +++ b/DDCore/include/DD4hep/Detector.h @@ -256,7 +256,7 @@ namespace DD4hep { #ifdef __MAKECINT__ /// Constructor to copy handle - DetElement(const Ref_t& e) + DetElement(const Ref_t& e) : RefObject(e) { } #endif diff --git a/DDCore/include/DD4hep/Dictionary.h b/DDCore/include/DD4hep/Dictionary.h new file mode 100644 index 0000000000000000000000000000000000000000..37320bbee4d60fb9dd1bd1be2ff75360bca17c4d --- /dev/null +++ b/DDCore/include/DD4hep/Dictionary.h @@ -0,0 +1,284 @@ +// +// LinkDef.h +// +// +// Created by Pere Mato on 22/1/12. +// Copyright 2012 __MyCompanyName__. All rights reserved. +// + +#ifndef DD4HEP_GEOMETRY_DICTIONARY_H +#define DD4HEP_GEOMETRY_DICTIONARY_H + +#include "DD4hep/LCDDData.h" +#include "DD4hep/Conditions.h" +#include "DD4hep/FieldTypes.h" +#include "DD4hep/objects/ObjectsInterna.h" +#include "DD4hep/objects/DetectorInterna.h" +#include "DD4hep/objects/ConditionsInterna.h" +#include "DD4hep/objects/VolumeManagerInterna.h" + +#include <vector> +#include <map> +typedef DD4hep::Geometry::PlacedVolumeExtension::VolID VolID; + + +// ------------------------------------------------------------------------- +// Regular DD4hep dictionaries +// ------------------------------------------------------------------------- +#ifdef __CINT__ +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ namespace DD4hep; +#pragma link C++ namespace DD4hep::Geometry; +#pragma link C++ namespace DD4hep::DDSegmentation; + +template pair<unsigned int, string>; +#pragma link C++ class pair<unsigned int,std::string>+; + +template class DD4hep::Geometry::Handle<NamedObject>; +template class map<string, DD4hep::Geometry::Handle<DD4hep::NamedObject> >; +#pragma link C++ class DD4hep::NamedObject+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::NamedObject>+; +#pragma link C++ class pair<string, DD4hep::Geometry::Handle<DD4hep::NamedObject> >+; +#pragma link C++ class map<string, DD4hep::Geometry::Handle<DD4hep::NamedObject> >+; +#pragma link C++ class map<string, DD4hep::Geometry::Handle<DD4hep::NamedObject> >::iterator; +#pragma link C++ class map<string, DD4hep::Geometry::Handle<DD4hep::NamedObject> >::const_iterator; + +#pragma link C++ class DD4hep::ObjectExtensions+; +template class DD4hep::Geometry::Handle<TNamed>; +#pragma link C++ class DD4hep::Geometry::Handle<TNamed>+; + +#pragma link C++ class DD4hep::Geometry::LCDD+; +#pragma link C++ class DD4hep::Geometry::LCDDData+; +#pragma link C++ class DD4hep::Geometry::LCDDData::ObjectHandleMap+; +#pragma link C++ class DD4hep::Geometry::LCDD::PropertyValues+; +#pragma link C++ class DD4hep::Geometry::LCDD::Properties+; + +// These below are the Namedobject instances to be generated .... +//#pragma link C++ class DD4hep::Geometry::LCDD::HandleMap+; +//#pragma link C++ class DD4hep::Geometry::LCDD::HandleMap::iterator; +//#pragma link C++ class DD4hep::Geometry::LCDD::HandleMap::const_iterator; +//#pragma link C++ class DD4hep::Geometry::LCDD::HandleMap::key_type; // == std::string +//#pragma link C++ class DD4hep::Geometry::LCDD::HandleMap::value_type+; + +#pragma link C++ class DD4hep::Geometry::VolumeManager+; +#pragma link C++ class DD4hep::Geometry::VolumeManagerObject+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::VolumeManagerObject>+; + +#pragma link C++ class DD4hep::Geometry::CartesianField+; +#pragma link C++ class DD4hep::Geometry::CartesianField::Object+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::CartesianField::Object>+; +#pragma link C++ class DD4hep::Geometry::OverlayedField+; +#pragma link C++ class DD4hep::Geometry::OverlayedField::Object+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::OverlayedField::Object>+; + +// FieldTypes.h +#pragma link C++ class DD4hep::Geometry::ConstantField+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::ConstantField>+; +#pragma link C++ class DD4hep::Geometry::SolenoidField+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::SolenoidField>+; +#pragma link C++ class DD4hep::Geometry::DipoleField+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::DipoleField>+; + +#pragma link C++ class DD4hep::Geometry::IDDescriptor+; +#pragma link C++ class DD4hep::Geometry::IDDescriptorObject+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::IDDescriptorObject>+; + +// Objects.h +#pragma link C++ class DD4hep::Geometry::Author+; +#pragma link C++ class vector<DD4hep::Geometry::Author>+; +#pragma link C++ class DD4hep::Geometry::Header+; +#pragma link C++ class DD4hep::Geometry::HeaderObject+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::HeaderObject>+; + +#pragma link C++ class DD4hep::Geometry::Constant+; +#pragma link C++ class vector<DD4hep::Geometry::Constant>+; +#pragma link C++ class DD4hep::Geometry::Atom+; +#pragma link C++ class vector<DD4hep::Geometry::Atom>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoElement>+; +#pragma link C++ class DD4hep::Geometry::Material+; +#pragma link C++ class vector<DD4hep::Geometry::Material>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoMedium>+; +#pragma link C++ class DD4hep::Geometry::VisAttr+; +#pragma link C++ class vector<DD4hep::Geometry::VisAttr>+; +#pragma link C++ class DD4hep::Geometry::VisAttrObject+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::VisAttrObject>+; +#pragma link C++ class DD4hep::Geometry::AlignmentEntry+; +#pragma link C++ class DD4hep::Geometry::Limit+; +#pragma link C++ class set<DD4hep::Geometry::Limit>+; +#pragma link C++ class vector<DD4hep::Geometry::Limit>+; +#pragma link C++ class DD4hep::Geometry::LimitSet+; +#pragma link C++ class vector<DD4hep::Geometry::LimitSet>+; +#pragma link C++ class DD4hep::Geometry::LimitSetObject+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::LimitSetObject>+; +#pragma link C++ class DD4hep::Geometry::Region+; +#pragma link C++ class DD4hep::Geometry::RegionObject+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::RegionObject>+; +#pragma link C++ class vector<DD4hep::Geometry::Region>+; + +// Readout.h +#pragma link C++ class vector<pair<size_t,string> >+; +#pragma link C++ class DD4hep::Geometry::Segmentation+; +#pragma link C++ class DD4hep::Geometry::SegmentationObject+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::SegmentationObject>+; +#pragma link C++ class DD4hep::Geometry::Readout+; +#pragma link C++ class DD4hep::Geometry::ReadoutObject+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::ReadoutObject>+; +#pragma link C++ class vector<DD4hep::Geometry::Readout>+; +#pragma link C++ class vector<DD4hep::Geometry::IDDescriptor>+; + +#pragma link C++ class DD4hep::Geometry::Alignment+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoPhysicalNode>+; + +#pragma link C++ class DD4hep::Geometry::Condition+; +#pragma link C++ class vector<DD4hep::Geometry::Condition>+; +#pragma link C++ class DD4hep::Geometry::ConditionsInterna::ConditionObject+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::ConditionsInterna::ConditionObject>+; + +#pragma link C++ class DD4hep::Geometry::Conditions+; +#pragma link C++ class DD4hep::Geometry::ConditionsInterna::ConditionContainer+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::ConditionsInterna::ConditionContainer>+; + +// DetElement.h +#pragma link C++ class DD4hep::Geometry::DetElement+; +#pragma link C++ class DD4hep::Geometry::DetElementObject+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::DetElementObject>+; +#pragma link C++ class vector<DD4hep::Geometry::DetElement>+; +#pragma link C++ class pair<string,DD4hep::Geometry::DetElement>+; +#pragma link C++ class map<string,DD4hep::Geometry::DetElement>+; + +#pragma link C++ class DD4hep::Geometry::SensitiveDetector+; +#pragma link C++ class DD4hep::Geometry::SensitiveDetectorObject+; +#pragma link C++ class DD4hep::Geometry::Handle<DD4hep::Geometry::SensitiveDetectorObject>+; +#pragma link C++ class vector<DD4hep::Geometry::SensitiveDetector>+; + +// Volume.h +#pragma link C++ class DD4hep::Geometry::Volume+; +#pragma link C++ class DD4hep::Geometry::VolumeExtension+; +#pragma link C++ class vector<DD4hep::Geometry::Volume>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoVolume>+; + +#pragma link C++ class DD4hep::Geometry::PlacedVolume+; +template vector<pair<string, int> >; +template vector<pair<string, int> >::iterator; +#pragma link C++ class vector<pair<string, int> >+; +#pragma link C++ class vector<pair<string, int> >::iterator; +#pragma link C++ class DD4hep::Geometry::PlacedVolumeExtension::VolIDs+; +#pragma link C++ class DD4hep::Geometry::PlacedVolumeExtension+; +#pragma link C++ class vector<DD4hep::Geometry::PlacedVolume>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoNode>+; + + +// Shapes.h +#pragma link C++ class DD4hep::Geometry::Polycone+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoPcon>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoPcon>+; + +#pragma link C++ class DD4hep::Geometry::ConeSegment+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoConeSeg>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoConeSeg>+; + +#pragma link C++ class DD4hep::Geometry::Box+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoBBox>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoBBox>+; + +#pragma link C++ class DD4hep::Geometry::Torus+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoTorus>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoTorus>+; + +#pragma link C++ class DD4hep::Geometry::Cone+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoCone>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoCone>+; + +#pragma link C++ class DD4hep::Geometry::Tube+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoTubeSeg>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoTubeSeg>+; + +#pragma link C++ class DD4hep::Geometry::Trap+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoTrap>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoTrap>+; + +#pragma link C++ class DD4hep::Geometry::Trapezoid+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoTrd2>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoTrd2>+; + +#pragma link C++ class DD4hep::Geometry::Sphere+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoSphere>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoSphere>+; + +#pragma link C++ class DD4hep::Geometry::Paraboloid+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoParaboloid>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoParaboloid>+; + +#pragma link C++ class DD4hep::Geometry::PolyhedraRegular+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoPgon>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoPgon>+; + +#pragma link C++ class DD4hep::Geometry::BooleanSolid+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoCompositeShape>+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoCompositeShape>+; + +#pragma link C++ class DD4hep::Geometry::SubtractionSolid+; +#pragma link C++ class DD4hep::Geometry::UnionSolid+; +#pragma link C++ class DD4hep::Geometry::IntersectionSolid+; + +#pragma link C++ class pair<string, string>+; +#pragma link C++ class map<string, string>+; +#pragma link C++ class pair<string, map<string, string> >+; +#pragma link C++ class map<string, map<string, string> >+; + +#pragma link C++ class DD4hep::Geometry::LCDD+; + +#pragma link C++ function DD4hep::Geometry::_toDictionary(const string&, const string&); + +#endif // __CINT__ + + +// ------------------------------------------------------------------------- +// DDSegmentation dictionaries +// ------------------------------------------------------------------------- +#ifdef __HAVE_DDSEGMENTATION__ +#include "DDSegmentation/Segmentation.h" +#include "DDSegmentation/CartesianGrid.h" +#include "DDSegmentation/CartesianGridXY.h" +#include "DDSegmentation/CartesianGridXYZ.h" +#include "DDSegmentation/CartesianGridXZ.h" +#include "DDSegmentation/CylindricalSegmentation.h" +#include "DDSegmentation/ProjectiveCylinder.h" +#include "DDSegmentation/SegmentationParameter.h" +#include "DDSegmentation/TiledLayerSegmentation.h" +typedef DD4hep::DDSegmentation::CellID CellID; + +#ifdef __CINT__ +#pragma link C++ class DD4hep::DDSegmentation::SegmentationParameter+; +#pragma link C++ class DD4hep::DDSegmentation::TypedSegmentationParameter<int>+; + +#pragma link C++ class DD4hep::DDSegmentation::TypedSegmentationParameter<float>+; +#pragma link C++ class DD4hep::DDSegmentation::TypedSegmentationParameter<double>+; +#pragma link C++ class DD4hep::DDSegmentation::TypedSegmentationParameter<string>+; +#if 0 +/// Severe problem due to template specialization! +#pragma link C++ class DD4hep::DDSegmentation::TypedSegmentationParameter<std::vector<int> >+; +#pragma link C++ class DD4hep::DDSegmentation::TypedSegmentationParameter<std::vector<float> >+; +#pragma link C++ class DD4hep::DDSegmentation::TypedSegmentationParameter<std::vector<double> >+; +#pragma link C++ class DD4hep::DDSegmentation::TypedSegmentationParameter<std::vector<std::string> >+; +#endif + +#pragma link C++ class DD4hep::DDSegmentation::Segmentation+; +#pragma link C++ class DD4hep::DDSegmentation::CartesianGrid+; +#pragma link C++ class DD4hep::DDSegmentation::CartesianGridXY+; +#pragma link C++ class DD4hep::DDSegmentation::CartesianGridXYZ+; +#pragma link C++ class DD4hep::DDSegmentation::CartesianGridXZ+; +#pragma link C++ class DD4hep::DDSegmentation::CylindricalSegmentation+; +#pragma link C++ class DD4hep::DDSegmentation::ProjectiveCylinder+; +#pragma link C++ class DD4hep::DDSegmentation::TiledLayerSegmentation+; + +#pragma link C++ class DD4hep::DDSegmentation::BitFieldValue+; +#pragma link C++ class DD4hep::DDSegmentation::BitField64+; + +#endif // __CINT__ +#endif // __HAVE_DDSEGMENTATION__ + +#endif // DD4HEP_GEOMETRY_DICTIONARY_H diff --git a/DDCore/include/DD4hep/Factories.h b/DDCore/include/DD4hep/Factories.h index f3d853cb03dba8e6588709b0c969fdcd8c2713a1..28d4ba197cbb4a77543730a50c3ba11e98cbb931 100644 --- a/DDCore/include/DD4hep/Factories.h +++ b/DDCore/include/DD4hep/Factories.h @@ -14,6 +14,7 @@ #endif #include "RVersion.h" #include "DD4hep/Detector.h" +#include "DD4hep/NamedObject.h" #include "XML/XMLElements.h" #include <cstdarg> @@ -25,8 +26,9 @@ namespace DD4hep { * XML sub-namespace declaration */ namespace XML { - struct Handle_t; + class Handle_t; } + class NamedObject; /* * Geometry sub-namespace declaration @@ -34,9 +36,9 @@ namespace DD4hep { namespace Geometry { // Forward declarations - struct LCDD; - struct SensitiveDetector; - struct DetElement; + class LCDD; + class SensitiveDetector; + class DetElement; template <typename T> class ConstructionFactory { public: @@ -129,7 +131,7 @@ namespace { } }; - template <typename P> class Factory<P, TNamed*(DD4hep::Geometry::LCDD*)> { + template <typename P> class Factory<P, DD4hep::NamedObject*(DD4hep::Geometry::LCDD*)> { public: typedef DD4hep::Geometry::LCDD LCDD; typedef DD4hep::Geometry::Ref_t Ref_t; @@ -150,7 +152,7 @@ namespace { } }; - template <typename P> class Factory<P, TNamed*(DD4hep::Geometry::LCDD*, DD4hep::XML::Handle_t*)> { + template <typename P> class Factory<P, DD4hep::NamedObject*(DD4hep::Geometry::LCDD*, DD4hep::XML::Handle_t*)> { public: typedef DD4hep::Geometry::LCDD LCDD; typedef DD4hep::XML::Handle_t xml_h; @@ -175,7 +177,7 @@ namespace { } }; - template <typename P> class Factory<P, TNamed*(DD4hep::Geometry::LCDD*, DD4hep::XML::Handle_t*, DD4hep::Geometry::Ref_t*)> { + template <typename P> class Factory<P, DD4hep::NamedObject*(DD4hep::Geometry::LCDD*, DD4hep::XML::Handle_t*, DD4hep::Geometry::Ref_t*)> { public: typedef DD4hep::Geometry::LCDD LCDD; typedef DD4hep::XML::Handle_t xml_h; @@ -191,18 +193,18 @@ namespace { } #define DECLARE_DETELEMENT_FACTORY(x) \ - PLUGINSVC_FACTORY(x,TNamed*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*,DD4hep::Geometry::Ref_t*)) + PLUGINSVC_FACTORY(x,DD4hep::NamedObject*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*,DD4hep::Geometry::Ref_t*)) #define DECLARE_NAMESPACE_DETELEMENT_FACTORY(n,x) using n::x; \ - PLUGINSVC_FACTORY(x,TNamed*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*,DD4hep::Geometry::Ref_t*)) + PLUGINSVC_FACTORY(x,DD4hep::NamedObject*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*,DD4hep::Geometry::Ref_t*)) #define DECLARE_NAMED_APPLY_FACTORY(n,x) using n::x;\ PLUGINSVC_FACTORY_WITH_ID(x,std::string(#x),long(DD4hep::Geometry::LCDD*,int, char**)) #define DECLARE_NAMED_TRANSLATION_FACTORY(n,x) using n::x;\ - PLUGINSVC_FACTORY_WITH_ID(x,std::string(#x),TNamed*(DD4hep::Geometry::LCDD*)) + PLUGINSVC_FACTORY_WITH_ID(x,std::string(#x),DD4hep::NamedObject*(DD4hep::Geometry::LCDD*)) #define DECLARE_NAMED_XMLELEMENT_FACTORY(n,x) using n::x;\ - PLUGINSVC_FACTORY_WITH_ID(x,std::string(#x),TNamed*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*)) + PLUGINSVC_FACTORY_WITH_ID(x,std::string(#x),DD4hep::NamedObject*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*)) #define DECLARE_NAMED_DETELEMENT_FACTORY(n,x) using n::x;\ - PLUGINSVC_FACTORY_WITH_ID(x,std::string(#x),TNamed*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*,DD4hep::Geometry::Ref_t*)) + PLUGINSVC_FACTORY_WITH_ID(x,std::string(#x),DD4hep::NamedObject*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*,DD4hep::Geometry::Ref_t*)) #define DECLARE_APPLY(name,func) \ namespace DD4hep { namespace Geometry { namespace { struct name {}; } \ @@ -225,7 +227,7 @@ namespace { namespace DD4hep { namespace Geometry { namespace { struct xml_element_##name {}; } \ template <> DD4hep::Geometry::Ref_t XMLElementFactory<DD4hep::Geometry::xml_element_##name>::create(DD4hep::Geometry::LCDD& l,DD4hep::XML::Handle_t e) {return func(l,e);} }}\ using DD4hep::Geometry::xml_element_##name;\ - PLUGINSVC_FACTORY_WITH_ID(xml_element_##name,std::string(#name),TNamed*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*)) + PLUGINSVC_FACTORY_WITH_ID(xml_element_##name,std::string(#name),DD4hep::NamedObject*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*)) #define DECLARE_XML_DOC_READER(name,func) \ namespace DD4hep { namespace Geometry { namespace { struct xml_document_##name {}; } \ @@ -237,7 +239,7 @@ namespace { namespace DD4hep { namespace Geometry { struct det_element_##name {}; \ template <> DD4hep::Geometry::Ref_t DetElementFactory< DD4hep::Geometry::det_element_##name >::create(DD4hep::Geometry::LCDD& l,DD4hep::XML::Handle_t e,DD4hep::Geometry::Ref_t h){return func(l,e,h);}}} \ using DD4hep::Geometry::det_element_##name;\ - PLUGINSVC_FACTORY_WITH_ID(det_element_##name,std::string(#name),TNamed*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*,DD4hep::Geometry::Ref_t*)) + PLUGINSVC_FACTORY_WITH_ID(det_element_##name,std::string(#name),DD4hep::NamedObject*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*,DD4hep::Geometry::Ref_t*)) #define DECLARE_SUBDETECTOR(name,func) DECLARE_XML_PROCESSOR(name,func) #define DECLARE_DETELEMENT(name,func) DECLARE_XML_PROCESSOR(name,func) diff --git a/DDCore/include/DD4hep/Fields.h b/DDCore/include/DD4hep/Fields.h index 3364a3f7fa5ffa2bb376257b4ecf85f1e79f3492..2223da916f7765dfd62e19fab3e1dc73e874fd01 100644 --- a/DDCore/include/DD4hep/Fields.h +++ b/DDCore/include/DD4hep/Fields.h @@ -11,6 +11,7 @@ #define DD4HEP_GEOMETRY_FIELDS_H // Framework include files +#include "DD4hep/NamedObject.h" #include "DD4hep/Objects.h" // C/C++ include files @@ -30,6 +31,7 @@ namespace DD4hep { // Forward declarations typedef Position Direction; + /** @class CartesianField Fields.h * * Generic structure describing any field type (electric or magnetic) @@ -41,7 +43,8 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct CartesianField: public Ref_t { + class CartesianField: public Ref_t { + public: enum FieldType { UNKNOWN = 0, ELECTRIC = 0x1, MAGNETIC = 0x2 }; @@ -49,7 +52,8 @@ namespace DD4hep { typedef std::map<std::string, PropertyValues> Properties; /// Internal data class shared by all handles of a given type - struct Object: public TNamed { + class Object: public NamedObject { + public: /// Field type int type; /// Field extensions @@ -121,19 +125,21 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct OverlayedField: public Ref_t { + class OverlayedField: public Ref_t { + public: enum FieldType { ELECTRIC = 0x1, MAGNETIC = 0x2 }; typedef std::map<std::string, std::string> PropertyValues; typedef std::map<std::string, PropertyValues> Properties; - struct Object: public TNamed { + class Object: public NamedObject { + public: int type; - CartesianField electric; - CartesianField magnetic; - std::vector<CartesianField> electric_components; - std::vector<CartesianField> magnetic_components; + DD4hep::Geometry::CartesianField electric; + DD4hep::Geometry::CartesianField magnetic; + std::vector<DD4hep::Geometry::CartesianField> electric_components; + std::vector<DD4hep::Geometry::CartesianField> magnetic_components; /// Field extensions Properties properties; /// Default constructor diff --git a/DDCore/include/DD4hep/GeoHandler.h b/DDCore/include/DD4hep/GeoHandler.h index 5e5ee4d7ed6edb5d1894e0c0656b74d18047fccf..ae2547fc99346391bad70ce1c8fefd2ca56ea46d 100644 --- a/DDCore/include/DD4hep/GeoHandler.h +++ b/DDCore/include/DD4hep/GeoHandler.h @@ -26,16 +26,19 @@ class TGeoNode; */ namespace DD4hep { + class NamedObject; + /* * Geometry namespace declaration */ namespace Geometry { - struct LCDD; - struct Volume; - struct PlacedVolume; - struct DetElement; - struct SensitiveDetector; + class LCDD; + class Volume; + class PlacedVolume; + class DetElement; + class SensitiveDetector; + class VisAttrObject; /** @class GeoHandlerTypes GeoHandler.h * @@ -44,21 +47,25 @@ namespace DD4hep { */ class GeoHandlerTypes { public: - typedef std::set<TGeoVolume*> VolumeSet; - typedef std::vector<TGeoVolume*> VolumeVector; + typedef std::set<Volume> VolumeSet; + typedef std::vector<Volume> VolumeVector; typedef std::set<const TGeoVolume*> ConstVolumeSet; typedef std::vector<std::pair<std::string, TGeoMatrix*> > TransformSet; typedef std::set<TGeoShape*> SolidSet; - typedef std::set<TGeoMedium*> MaterialSet; - typedef std::map<const TNamed*, ConstVolumeSet> SensitiveVolumes; - typedef std::map<const TNamed*, ConstVolumeSet> RegionVolumes; - typedef std::map<const TNamed*, ConstVolumeSet> LimitVolumes; + typedef std::set<Material> MaterialSet; + typedef std::map<SensitiveDetector, ConstVolumeSet> SensitiveVolumes; + typedef std::map<Region, ConstVolumeSet> RegionVolumes; + typedef std::map<LimitSet, ConstVolumeSet> LimitVolumes; typedef std::map<int, std::set<const TGeoNode*> > Data; - typedef std::set<const TNamed*> VisRefs; - typedef std::set<TNamed*> Fields; + typedef std::set<VisAttr> VisRefs; + typedef std::set<SensitiveDetector> SensitiveDetectorSet; + typedef std::set<Region> RegionSet; + typedef std::set<LimitSet> LimitSetSet; + typedef std::set<Ref_t> Fields; typedef std::set<TNamed*> ObjectSet; - typedef LCDD::HandleMap DefinitionSet; - struct GeometryInfo { + typedef LCDD::HandleMap DefinitionSet; + class GeometryInfo { + public: SolidSet solids; VolumeSet volumeSet; VolumeVector volumes; @@ -66,10 +73,7 @@ namespace DD4hep { VisRefs vis; Fields fields; MaterialSet materials; - // SensitiveVolumes sensitives; - // RegionVolumes regions; - // LimitVolumes limits; - std::set<TGeoMedium*> media; + std::set<TGeoMedium*> media; std::set<TGeoElement*> elements; }; }; diff --git a/DDCore/include/DD4hep/Handle.h b/DDCore/include/DD4hep/Handle.h index 8f12ffc28f058f8d0f2c742ee4c9085659b331fd..4ac2fd895c744ba8be5183c414d78eaff236bf2e 100644 --- a/DDCore/include/DD4hep/Handle.h +++ b/DDCore/include/DD4hep/Handle.h @@ -16,8 +16,6 @@ #include <typeinfo> #include <stdexcept> -class TNamed; - // Conversion factor from radians to degree: 360/(2*PI) #ifndef RAD_2_DEGREE #define RAD_2_DEGREE 57.295779513082320876798154814105 @@ -41,11 +39,14 @@ class TNamed; */ namespace DD4hep { + // Forward declarations + class NamedObject; + /* * Geometry sub-namespace declaration */ namespace Geometry { - struct LCDD; + class LCDD; std::string _toString(bool value); std::string _toString(int value); @@ -124,7 +125,8 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - template <typename T = TNamed> struct Handle { + template <typename T> class Handle { + public: typedef T Implementation; typedef Handle<Implementation> handle_t; T* m_element; @@ -145,18 +147,32 @@ namespace DD4hep { : m_element((T*) e.m_element) { verifyObject(); } + /// Assignment operator Handle<T>& operator=(const Handle<T>& e) { m_element = e.m_element; return *this; } + /// Boolean operator == used for RB tree insertions + bool operator==(const Handle<T>& e) const { + return m_element == e.m_element; + } + /// Boolean operator < used for RB tree insertions + bool operator<(const Handle<T>& e) const { + return m_element < e.m_element; + } + /// Boolean operator > used for RB tree insertions + bool operator>(const Handle<T>& e) const { + return m_element > e.m_element; + } bool isValid() const { return 0 != m_element; } bool operator!() const { return 0 == m_element; } - void clear() { + Handle<T>& clear() { m_element = 0; + return *this; } T* operator->() const { return m_element; @@ -186,7 +202,8 @@ namespace DD4hep { static void bad_assignment(const std::type_info& from, const std::type_info& to); void assign(Implementation* n, const std::string& nam, const std::string& title); }; - typedef Handle<TNamed> Ref_t; + + typedef Handle<NamedObject> Ref_t; /// Helper to delete objects from heap and reset the handle template <typename T> inline void destroyHandle(T& h) { diff --git a/DDCore/include/DD4hep/Handle.inl b/DDCore/include/DD4hep/Handle.inl index 692be8d8500f5bac8fc8c590f1c0e7ea99cb7df6..61208b4b80b22de4ef7bebac955b407bd1121937 100644 --- a/DDCore/include/DD4hep/Handle.inl +++ b/DDCore/include/DD4hep/Handle.inl @@ -53,7 +53,7 @@ namespace DD4hep { bad_assignment(typeid(*m_element), typeid(X)); \ } \ }}} \ - template struct DD4hep::Geometry::Handle<X> + template class DD4hep::Geometry::Handle<X> #define DD4HEP_INSTANTIATE_HANDLE_NAMED(X) \ namespace DD4hep { namespace Geometry { \ @@ -67,11 +67,11 @@ namespace DD4hep { } \ template <> void Handle<X>::verifyObject() const { \ increment_object_validations(); \ - if (m_element && dynamic_cast<X*>((TObject*)m_element) == 0) { \ + if (m_element && dynamic_cast<X*>((NamedObject*)m_element) == 0) { \ bad_assignment(typeid(*m_element), typeid(X)); \ } \ }}} \ - template struct DD4hep::Geometry::Handle<X> + template class DD4hep::Geometry::Handle<X> #define DD4HEP_INSTANTIATE_HANDLE_UNNAMED(X) \ namespace DD4hep { namespace Geometry { \ diff --git a/DDCore/include/DD4hep/IDDescriptor.h b/DDCore/include/DD4hep/IDDescriptor.h index 774ef2a875e81a868bb062f5a35ec668fd0b97c2..9be33e24dd76e6d5441be2b1c8300666393a2139 100644 --- a/DDCore/include/DD4hep/IDDescriptor.h +++ b/DDCore/include/DD4hep/IDDescriptor.h @@ -14,7 +14,6 @@ #include "DD4hep/Handle.h" #include "DD4hep/Primitives.h" #include "DDSegmentation/BitField64.h" -#include "TNamed.h" // C++ include files #include <string> @@ -31,48 +30,31 @@ namespace DD4hep { */ namespace Geometry { + class IDDescriptorObject; + /** @class IDDescriptor IDDescriptor.h DDCore/IDDescriptor.h * * @author M.Frank * @version 1.0 * @date 2012/07/31 */ - struct IDDescriptor: public Ref_t { + class IDDescriptor: public Handle<IDDescriptorObject> { public: - typedef std::pair<std::string, int> VolID; + typedef IDDescriptorObject Object; typedef DDSegmentation::BitFieldValue* Field; typedef std::vector<std::pair<std::string, Field> > FieldMap; typedef std::vector<std::pair<size_t, std::string> > FieldIDs; typedef std::pair<Field, VolumeID> VolIDField; typedef std::vector<VolIDField> VolIDFields; - /** @class IDDescriptor::Object IDDescriptor.h DDCore/IDDescriptor.h - * - * @author M.Frank - * @version 1.0 - * @date 2012/07/31 - */ - struct Object: public TNamed, public DDSegmentation::BitField64 { - FieldMap fieldMap; - FieldIDs fieldIDs; - std::string description; - /// Standard constructor - Object(const std::string& initString); - /// Default destructor - virtual ~Object(); - /// Access to the field container of the BitField64 - const std::vector<DDSegmentation::BitFieldValue*> fields() const { - return _fields; - } - }; public: /// Default constructor IDDescriptor() - : Ref_t() { + : Handle<Object>() { } /// Constructor to be used when reading the already parsed object template <typename Q> IDDescriptor(const Handle<Q>& e) - : Ref_t(e) { + : Handle<Object>(e) { } /// Initializing constructor IDDescriptor(const std::string& description); @@ -90,8 +72,11 @@ namespace DD4hep { size_t fieldID(const std::string& field_name) const; /// Get the field descriptor of one field by its identifier Field field(size_t identifier) const; +#ifndef __MAKECINT__ /// Encode a set of volume identifiers (corresponding to this description of course!) to a volumeID. + typedef std::pair<std::string, int> VolID; VolumeID encode(const std::vector<VolID>& ids) const; +#endif /// Decode volume IDs and return filled descriptor with all fields void decodeFields(VolumeID vid, VolIDFields& fields); /// Access string representation diff --git a/DDCore/include/DD4hep/LCDD.h b/DDCore/include/DD4hep/LCDD.h index 32c56fc562fe38f2f53091aa2f3533688887c69c..54a3eb1c7548b9c86c7ff98138fb834d3e81f587 100644 --- a/DDCore/include/DD4hep/LCDD.h +++ b/DDCore/include/DD4hep/LCDD.h @@ -20,6 +20,7 @@ #include "DD4hep/Detector.h" #include "DD4hep/Segmentations.h" #include "DD4hep/VolumeManager.h" +#include "DD4hep/NamedObject.h" // C/C++ include files #include <map> @@ -32,6 +33,9 @@ class TGeoManager; */ namespace DD4hep { + // Foward declarations + class NamedObject; + /* * Geometry namespace declaration */ @@ -54,7 +58,7 @@ namespace DD4hep { */ class LCDD { public: - typedef std::map<std::string, Handle<> > HandleMap; + typedef std::map<std::string, Handle<NamedObject> > HandleMap; typedef std::map<std::string, std::string> PropertyValues; typedef std::map<std::string, PropertyValues> Properties; @@ -119,6 +123,8 @@ namespace DD4hep { virtual const HandleMap& alignments() const = 0; /// Accessor to the map of field entries, which together form the global field virtual const HandleMap& fields() const = 0; + /// Accessor to the map of ID specifications + virtual const HandleMap& idSpecifications() const = 0; virtual Volume pickMotherVolume(const DetElement& sd) const = 0; @@ -167,6 +173,8 @@ namespace DD4hep { virtual LCDD& add(IDDescriptor spec) = 0; /// Add a new detector readout to the detector description virtual LCDD& add(Readout readout) = 0; + /// Add a new sensitive detector to the detector description + virtual LCDD& add(SensitiveDetector entry) = 0; /// Add a new subdetector to the detector description virtual LCDD& add(DetElement detector) = 0; /// Add alignment entry to the detector description diff --git a/DDCore/include/DD4hep/LCDDData.h b/DDCore/include/DD4hep/LCDDData.h new file mode 100644 index 0000000000000000000000000000000000000000..46c1ac27d19d168bcc08c038c9f130fd9120c560 --- /dev/null +++ b/DDCore/include/DD4hep/LCDDData.h @@ -0,0 +1,117 @@ +// $Id: LCDD.h 1117 2014-04-25 08:07:22Z markus.frank@cern.ch $ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== + +#ifndef DD4HEP_DDCORE_LCDDDATA_H +#define DD4HEP_DDCORE_LCDDDATA_H + +// Framework includes +#include "DD4hep/LCDD.h" +#include "DD4hep/ObjectExtensions.h" + +// C/C++ include files +#include <stdexcept> + +/* + * DD4hep namespace declaration + */ +namespace DD4hep { + + // Foward declarations + class NamedObject; + + /* + * Geometry namespace declaration + */ + namespace Geometry { + + /** @class LCDDData LCDDData.h DD4hep/LCDDData.h + * + * @author M.Frank + * @version 1.0 + */ + class LCDDData { + + public: + struct InvalidObjectError: public std::runtime_error { + InvalidObjectError(const std::string& msg) + : std::runtime_error("DD4hep: " + msg) { + } + }; + + protected: + struct ObjectHandleMap: public LCDD::HandleMap { + ObjectHandleMap() { + } + void append(const Ref_t& 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())); + if (!throw_on_doubles || r.second) + return; + throw InvalidObjectError("Attempt to add an already existing object:" + std::string(e.name()) + "."); + } + throw InvalidObjectError("Attempt to add an invalid object."); + } + + template <typename T> void append(const Ref_t& e, bool throw_on_doubles = true) { + T* obj = dynamic_cast<T*>(e.ptr()); + if (obj) { + this->append(e, throw_on_doubles); + return; + } + throw InvalidObjectError("Attempt to add an object, which is of the wrong type."); + } + }; + + TGeoManager* m_manager; + ObjectHandleMap m_readouts; + ObjectHandleMap m_idDict; + ObjectHandleMap m_limits; + ObjectHandleMap m_regions; + ObjectHandleMap m_detectors; + ObjectHandleMap m_alignments; + + ObjectHandleMap m_sensitive; + ObjectHandleMap m_display; + ObjectHandleMap m_fields; + + // GDML fields + ObjectHandleMap m_define; + + 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; + LCDD::Properties m_properties; + LCDDBuildType m_buildType; + + /// Definition of the extension type + ObjectExtensions m_extensions; + protected: + /// Default constructor + LCDDData(); + /// Default destructor + virtual ~LCDDData(); + /// Clear data content: releases all allocated resources + void destroyData(); + /// Clear data content: DOES NOT RELEASEW ALLOCATED RESOURCES! + void clearData(); + /// Adopt all data from source structure. + void adoptData(LCDDData& source); + }; + + } /* End namespace Geometry */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_DDCORE_LCDDDATA_H */ diff --git a/DDCore/include/DD4hep/MatrixHelpers.h b/DDCore/include/DD4hep/MatrixHelpers.h index da55647405e1193d1136be77e543ef69d2725181..d02b01e0457a311f8fb42d190e58729670b9b5e8 100644 --- a/DDCore/include/DD4hep/MatrixHelpers.h +++ b/DDCore/include/DD4hep/MatrixHelpers.h @@ -36,6 +36,7 @@ namespace DD4hep { TGeoHMatrix* _transform(const Transform3D& trans); TGeoHMatrix* _transform(const Position& pos); TGeoHMatrix* _transform(const RotationZYX& rot); + TGeoHMatrix* _transform(const Rotation3D& rot3D); TGeoHMatrix* _transform(const Position& pos, const RotationZYX& rot); Transform3D _transform(const TGeoMatrix* matrix); diff --git a/DDCore/include/DD4hep/objects/NamedObject.h b/DDCore/include/DD4hep/NamedObject.h similarity index 91% rename from DDCore/include/DD4hep/objects/NamedObject.h rename to DDCore/include/DD4hep/NamedObject.h index a6be3f36af6dc0ac83642407c0958ba24cb798c5..5caee6671c05e5db9f88e3607724117999d588d9 100644 --- a/DDCore/include/DD4hep/objects/NamedObject.h +++ b/DDCore/include/DD4hep/NamedObject.h @@ -17,11 +17,6 @@ */ namespace DD4hep { - /* - * Geometry namespace declaration - */ - namespace Geometry { - /** @class Container NamedObject.h DD4hep/NamedObject.h * * The data class behind a conditions container handle. @@ -50,22 +45,24 @@ namespace DD4hep { virtual ~NamedObject(); /// Assignment operator NamedObject& operator=(const NamedObject& c); + + /// Access name + const char* GetName() const { + return name.c_str(); + } /// Set name (used by Handle) void SetName(const char* nam) { name = nam; } -#if 0 - /// Get name (used by Handle) - const char* GetName() const { - return name.c_str(); - } -#endif /// Set Title (used by Handle) void SetTitle(const char* tit) { type = tit; } + /// Get name (used by Handle) + const char* GetTitle() const { + return type.c_str(); + } }; - } /* End namespace Geometry */ } /* End namespace DD4hep */ #endif /* DD4HEP_GEOMETRY_INTERNAL_NAMEDOBJECT_H */ diff --git a/DDCore/include/DD4hep/ObjectExtensions.h b/DDCore/include/DD4hep/ObjectExtensions.h index 9fdf56c66b47c69eb7c9ad8ab06d8a9677cbc12f..e15ed190d1f1dbc46ef0a87d8176c5d25fc7750d 100644 --- a/DDCore/include/DD4hep/ObjectExtensions.h +++ b/DDCore/include/DD4hep/ObjectExtensions.h @@ -39,9 +39,9 @@ namespace DD4hep { typedef std::map<const std::type_info*, Entry> ExtensionMap; /// The extensions object - Extensions extensions; + Extensions extensions; //! /// Pointer to the extension map - ExtensionMap* extensionMap; + ExtensionMap* extensionMap; //! public: /// Default constructor @@ -49,7 +49,7 @@ namespace DD4hep { /// Default destructor virtual ~ObjectExtensions(); /// Clear all extensions - void clear(); + void clear(bool destroy=true); /// Copy object extensions from another object. Hosting type must be identical! void copyFrom(const Extensions& ext, void* arg); /// Add an extension object to the detector element diff --git a/DDCore/include/DD4hep/Objects.h b/DDCore/include/DD4hep/Objects.h index 0463d8410967736ce3bcc48be889c7665f16de45..8968af9f33b31c768639e244904d9171f3caf93a 100644 --- a/DDCore/include/DD4hep/Objects.h +++ b/DDCore/include/DD4hep/Objects.h @@ -12,6 +12,8 @@ // Framework include files #include "DD4hep/Handle.h" +#include "DD4hep/NamedObject.h" + class TMap; class TGeoElement; class TGeoMaterial; @@ -55,8 +57,12 @@ namespace DD4hep { namespace Geometry { // Forward declarations - struct LCDD; + class LCDD; class IDDescriptor; + class VisAttrObject; + class HeaderObject; + class RegionObject; + class LimitSetObject; /** Access to identity transformation */ TGeoIdentity* identityTransform(); @@ -66,9 +72,10 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct Author: public Ref_t { + class Author: public Ref_t { + public: /// Definition of the implementation type - typedef TNamed Object; + typedef NamedObject Object; /// Default constructor Author() : Ref_t() { @@ -77,12 +84,12 @@ namespace DD4hep { Author(const Author& e) : Ref_t(e) { } - /// Constructor to be used when reading the already parsed DOM tree + /// Constructor to be used when assigning already valid handle template <typename Q> Author(const Handle<Q>& e) : Ref_t(e) { } - /// Constructor to be used when creating a new DOM tree + /// Constructor to be used when creating a new object Author(LCDD& doc); /// Assignment operator Author& operator=(const Author& e) { @@ -108,35 +115,20 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct Header: public Ref_t { - struct Object: public TNamed { - public: - std::string url; - std::string author; - std::string status; - std::string version; - std::string comment; - /// Standard constructor - Object(); - /// Default destructor - virtual ~Object(); - private: - /// Private copy constructor - Object(const Object&) : TNamed() {} - /// Private assignment operator - Object& operator=(const Object&) { return *this; } - }; + class Header: public Handle<HeaderObject> { + public: + typedef HeaderObject Object; /// Default constructor Header() - : Ref_t() { + : Handle<HeaderObject>() { } /// Constructorto be used for assignment from a handle Header(const Header& e) - : Ref_t(e) { + : Handle<HeaderObject>(e) { } /// Constructor to be used when reading the already parsed DOM tree template <typename Q> Header(const Handle<Q>& e) - : Ref_t(e) { + : Handle<HeaderObject>(e) { } /// Constructor to be used when creating a new DOM tree Header(const std::string& author, const std::string& url); @@ -182,9 +174,10 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct Constant: public Ref_t { + class Constant: public Ref_t { + public: /// Definition of the implementation type - typedef TNamed Object; + typedef NamedObject Object; /// Default constructor Constant() : Ref_t() { @@ -248,21 +241,24 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct Atom: public Handle<TGeoElement> { + class Atom: public Handle<TGeoElement> { + public: /// Definition of the implementation type typedef TGeoElement Object; /// Default constructor Atom() - : Handle<TGeoElement>() { + : Handle<Object>() { } +#ifndef __CINT__ /// Constructorto be used for assignment from a handle - Atom(const Handle<TGeoElement>& e) - : Handle<TGeoElement>(e) { + Atom(const Handle<Object>& e) + : Handle<Object>(e) { } +#endif /// Constructor to be used when creating from a object handle template <typename Q> Atom(const Handle<Q>& e) - : Handle<TGeoElement>(e) { + : Handle<Object>(e) { } /// Constructor to be used when reading the already parsed DOM tree Atom(const std::string& name, const std::string& formula, int Z, int N, double density); @@ -273,21 +269,25 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct Material: public Handle<TGeoMedium> { + class Material: public Handle<TGeoMedium> { + public: /// Definition of the implementation type typedef TGeoMedium Object; + /// Default constructor Material() - : Handle<TGeoMedium>() { + : Handle<Object>() { } +#ifndef __CINT__ /// Constructorto be used for assignment from material handle - Material(const Handle<TGeoMedium>& e) - : Handle<TGeoMedium>(e) { + Material(const Handle<Object>& e) + : Handle<Object>(e) { } +#endif /// Constructorto be used for assignment from object handle template <typename Q> Material(const Handle<Q>& e) - : Handle<TGeoMedium>(e) { + : Handle<Object>(e) { } /// proton number of the underlying material double Z() const ; @@ -308,36 +308,35 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct VisAttr: public Ref_t { + class VisAttr: public Handle<VisAttrObject> { + public: enum Style { SOLID = 0x1, WIREFRAME = 0x2, DASHED = 0x2, LAST_STYLE }; - struct Object: public TNamed { - unsigned long magic; - void* col; - int color; - float alpha; - unsigned char drawingStyle, lineStyle, showDaughters, visible; - /// Standard constructor - Object(); - /// Default destructor - virtual ~Object(); - }; + typedef VisAttrObject Object; /// Default constructor VisAttr() - : Ref_t() { + : Handle<Object>() { + } + /// Copy constructor for handle + VisAttr(const VisAttr& e) + : Handle<Object>(e) { + } +#ifndef __CINT__ + /// Copy constructor for handle + VisAttr(const Handle<Object>& e) + : Handle<Object>(e) { } +#endif /// Constructor to be used for assignment from object handle template <typename Q> VisAttr(const Handle<Q>& e) - : Ref_t(e) { - } - /// Copy constructor for handle - VisAttr(const VisAttr& e) - : Ref_t(e) { + : Handle<Object>(e) { } /// Constructor to be used when creating a new registered visualization object VisAttr(const std::string& name); + /// Constructor to be used when creating a new registered visualization object + VisAttr(const char* name); /// Assignment operator VisAttr& operator=(const VisAttr& attr) { m_element = attr.m_element; @@ -388,7 +387,8 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct AlignmentEntry: public Handle<TGeoPhysicalNode> { + class AlignmentEntry: public Handle<TGeoPhysicalNode> { + public: typedef Handle<TGeoPhysicalNode> Base; /// Constructor to be used when reading the already parsed DOM tree template <typename Q> @@ -411,7 +411,8 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct Limit { + class Limit { + public: std::string particles; std::string name; std::string unit; @@ -440,28 +441,34 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct LimitSet: public Ref_t { - struct Object: public TNamed, public std::set<Limit> { - /// Standard constructor - Object(); - /// Default destructor - virtual ~Object(); - }; + class LimitSet: public Handle<LimitSetObject> { + public: + typedef LimitSetObject Object; /// Constructor to be used when reading the already parsed DOM tree LimitSet() - : Ref_t() { + : Handle<LimitSetObject>() { + } + /// Copy constructor for handle + LimitSet(const LimitSet& e) + : Handle<LimitSetObject>(e) { + } +#ifndef __CINT__ + /// Copy constructor for handle + LimitSet(const Handle<LimitSetObject>& e) + : Handle<LimitSetObject>(e) { } +#endif /// Constructor to be used when reading the already parsed DOM tree template <typename Q> LimitSet(const Handle<Q>& e) - : Ref_t(e) { + : Handle<LimitSetObject>(e) { } /// Constructor to be used when creating a new object LimitSet(const std::string& name); /// Add new limit. Returns true if the new limit was added, false if it already existed. - bool addLimit(const Limit& limit); + bool addLimit(const DD4hep::Geometry::Limit& limit); /// Accessor to limits container - const std::set<Limit>& limits() const; + const std::set<DD4hep::Geometry::Limit>& limits() const; }; /** @class Region Objects.h @@ -469,27 +476,28 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct Region: public Ref_t { - struct Object: public TNamed { - unsigned long magic; - double threshold; - double cut; - bool store_secondaries; - std::string lunit, eunit; - std::vector<std::string> user_limits; - /// Standard constructor - Object(); - /// Default destructor - virtual ~Object(); - }; + class Region: public Handle<RegionObject> { + public: + /// Implemeting class + typedef RegionObject Object; /// Default constructor Region() - : Ref_t() { + : Handle<Object>() { } - /// Constructor to be used when reading the already parsed DOM tree + /// Copy Constructor + Region(const Region& e) + : Handle<Object>(e) { + } +#ifndef __CINT__ + /// Copy Constructor + Region(const Handle<RegionObject>& e) + : Handle<Object>(e) { + } +#endif + /// Constructor to be used when assigning handle template <typename Q> Region(const Handle<Q>& e) - : Ref_t(e) { + : Handle<Object>(e) { } /// Constructor to be used when creating a new object Region(const std::string& name); diff --git a/DDCore/include/DD4hep/Printout.h b/DDCore/include/DD4hep/Printout.h index b2f34875bd1edcdef38ad684709066d4386bc6aa..23484ad45ccdb9d1ab07bd3cf0502038a05548b9 100644 --- a/DDCore/include/DD4hep/Printout.h +++ b/DDCore/include/DD4hep/Printout.h @@ -29,19 +29,23 @@ class TNamed; */ namespace DD4hep { -/// Forward declarations + class NamedObject; + + /// Forward declarations namespace Geometry { - template <typename T> struct Handle; class LCDD; class VisAttr; class DetElement; class PlacedVolume; + template <typename T> struct Handle; + typedef Handle<NamedObject> Ref_t; } enum PrintLevel { NOLOG = 0, VERBOSE=1, DEBUG=2, INFO=3, WARNING=4, ERROR=5, FATAL=6, ALWAYS }; +#ifndef __CINT__ typedef size_t (*output_function_t)(void*, PrintLevel severity, const char*, const char*); /** Calls the display action @@ -127,15 +131,17 @@ namespace DD4hep { */ std::string format(const std::string& src, const std::string& fmt, va_list& args); -/// Set new print level. Returns the old print level + /// Customize printer function + void setPrinter(void* print_arg, output_function_t fcn); + +#endif // __CINT__ + + /// Set new print level. Returns the old print level PrintLevel setPrintLevel(PrintLevel new_level); /// Access the current printer level PrintLevel printLevel(); -/// Customize printer function - void setPrinter(void* print_arg, output_function_t fcn); - /** @class Printer Conversions.h DD4hep/compact/Conversions.h * * Small helper class to print objects @@ -173,7 +179,7 @@ namespace DD4hep { */ template <typename T> struct PrintMap { typedef T item_type; - typedef const std::map<std::string, Geometry::Handle<TNamed> > cont_type; + typedef const std::map<std::string, Geometry::Ref_t> cont_type; /// Reference to the detector description object const Geometry::LCDD* lcdd; diff --git a/DDCore/include/DD4hep/Readout.h b/DDCore/include/DD4hep/Readout.h index abefd8e0d9f557684fa6ae95baac10668c3b4179..d13af002905e6e6c297abc7c16206c218913b3fc 100644 --- a/DDCore/include/DD4hep/Readout.h +++ b/DDCore/include/DD4hep/Readout.h @@ -29,44 +29,46 @@ namespace DD4hep { */ namespace Geometry { + // Forward declarations class DetElement; + class ReadoutObject; /** @class Readout Readout.h DD4hep/Readout.h * * @author M.Frank * @version 1.0 */ - struct Readout: public Ref_t { + struct Readout: public Handle<ReadoutObject> { public: - - /** @class Readout::Object Readout.h DD4hep/Readout.h - * - * @author M.Frank - * @version 1.0 - */ - struct Object: public TNamed { - /// Handle to the readout segmentation - Segmentation segmentation; - /// Handle to the volume - Volume readoutWorld; - /// Handle to the field descriptor - IDDescriptor id; - /// Standard constructor - Object(); - /// Default destructor - virtual ~Object(); - }; + /// Implementation type + typedef ReadoutObject Object; public: /// Default constructor Readout() - : Ref_t() { + : Handle<Object>() { + } + /// Copy Constructor from object + Readout(const Readout& e) + : Handle<Object>(e) { } +#ifndef __CINT__ + /// Copy Constructor from handle + Readout(const Handle<ReadoutObject>& e) + : Handle<Object>(e) { + } +#endif /// Constructor to be used when reading the already parsed object template <typename Q> Readout(const Handle<Q>& e) - : Ref_t(e) { + : Handle<Object>(e) { } /// Initializing constructor Readout(const std::string& name); + /// Assignment operator + Readout& operator=(const Readout& ro) { + if ( &ro == this ) return *this; + m_element = ro.m_element; + return *this; + } /// Assign IDDescription to readout structure void setIDDescriptor(const Ref_t& spec) const; /// Access IDDescription structure diff --git a/DDCore/include/DD4hep/Segmentations.h b/DDCore/include/DD4hep/Segmentations.h index ecc7f3dd92e42f1ce0925745cc2d410cd1f84314..4590ba362bef0b312d2dba22628551f2831f281c 100644 --- a/DDCore/include/DD4hep/Segmentations.h +++ b/DDCore/include/DD4hep/Segmentations.h @@ -32,76 +32,97 @@ namespace DD4hep { typedef DDSegmentation::BitField64 BitField64; - /** @class Segmentation Segmentations.h DD4hep/Segmentations.h + /** @class Segmentation::Object Segmentations.h DD4hep/Segmentations.h * * @author M.Frank * @version 1.0 */ - struct Segmentation: public Handle<DDSegmentation::Segmentation> { + class SegmentationObject : public DDSegmentation::Segmentation { public: typedef DDSegmentation::Segmentation BaseSegmentation; typedef DDSegmentation::Parameter Parameter; typedef DDSegmentation::Parameters Parameters; + public: + /// Magic word to check object integrity + unsigned long magic; + /// Flag to use segmentation for hit positioning + unsigned char useForHitPosition; + /// determine the local position based on the cell ID + DDSegmentation::Vector3D position(const long64& cellID) const; + /// determine the cell ID based on the local position + long64 cellID(const DDSegmentation::Vector3D& localPosition, const DDSegmentation::Vector3D& globalPosition, const long64& volumeID) const; + /// Standard constructor + SegmentationObject(BaseSegmentation* s = 0); + /// Default destructor + virtual ~SegmentationObject(); + /// Access the encoding string + std::string fieldDescription() const; + /// Access the segmentation name + const std::string& name() const; + /// Set the segmentation name + void setName(const std::string& value); + /// Access the segmentation type + const std::string& type() const; + /// Access the description of the segmentation + const std::string& description() const; + /// Access the underlying decoder + BitField64* decoder(); + /// Set the underlying decoder + void setDecoder(BitField64* decoder); + /// Access to parameter by name + Parameter parameter(const std::string& parameterName) const; + /// Access to all parameters + Parameters parameters() const; + /// Set all parameters from an existing set of parameters + void setParameters(const Parameters& parameters); + /// Reference to base segmentation + BaseSegmentation* segmentation; + }; - /** @class Segmentation::Object Segmentations.h DD4hep/Segmentations.h - * - * @author M.Frank - * @version 1.0 - */ - struct Object : public BaseSegmentation { - /// Magic word to check object integrity - unsigned long magic; - /// Flag to use segmentation for hit positioning - unsigned char useForHitPosition; - /// determine the local position based on the cell ID - DDSegmentation::Vector3D position(const long64& cellID) const; - /// determine the cell ID based on the local position - long64 cellID(const DDSegmentation::Vector3D& localPosition, const DDSegmentation::Vector3D& globalPosition, const long64& volumeID) const; - /// Standard constructor - Object(BaseSegmentation* s = 0); - /// Default destructor - virtual ~Object(); - /// Access the encoding string - std::string fieldDescription() const; - /// Access the segmentation name - const std::string& name() const; - /// Set the segmentation name - void setName(const std::string& value); - /// Access the segmentation type - const std::string& type() const; - /// Access the description of the segmentation - const std::string& description() const; - /// Access the underlying decoder - BitField64* decoder(); - /// Set the underlying decoder - void setDecoder(BitField64* decoder); - /// Access to parameter by name - Parameter parameter(const std::string& parameterName) const; - /// Access to all parameters - Parameters parameters() const; - /// Set all parameters from an existing set of parameters - void setParameters(const Parameters& parameters); - /// Reference to base segmentation - BaseSegmentation* segmentation; - }; + /** @class Segmentation Segmentations.h DD4hep/Segmentations.h + * + * @author M.Frank + * @version 1.0 + */ + struct Segmentation: public Handle<SegmentationObject> { public: + typedef SegmentationObject Object; + typedef DDSegmentation::Segmentation BaseSegmentation; + typedef DDSegmentation::Parameter Parameter; + typedef DDSegmentation::Parameters Parameters; + + public: + /// Initializing constructor creating a new object of the given DDSegmentation type + Segmentation(const std::string& type, const std::string& name); /// Default constructor Segmentation() : Handle<Implementation>() { } - /// Initializing constructor creating a new object of the given DDSegmentation type - Segmentation(const std::string& type, const std::string& name); + /// Copy Constructor from object + Segmentation(const Segmentation& e) + : Handle<Object>(e) { + } +#ifndef __CINT__ + /// Copy Constructor from handle + Segmentation(const Handle<SegmentationObject>& e) + : Handle<Object>(e) { + } +#endif /// Constructor to be used when reading the already parsed object template <typename Q> Segmentation(const Handle<Q>& e) : Handle<Implementation>(e) { } + /// Assignment operator + Segmentation& operator=(const Segmentation& seg) { + if ( &seg == this ) return *this; + m_element = seg.m_element; + return *this; + } /// Access flag for hit positioning bool useForHitPosition() const; /// Accessor: Segmentation type std::string type() const; - /// Accessor: Set segmentation type - void setType(const std::string& new_type); /// Access segmentation object BaseSegmentation* segmentation() const; /// Access to the parameters diff --git a/DDCore/include/DD4hep/VolumeManager.h b/DDCore/include/DD4hep/VolumeManager.h index 86ff95afe874fcb50ef8e0bac9ed711db93a4102..e3f7f3c0593261b5f5fe60c278284037c0bb877b 100644 --- a/DDCore/include/DD4hep/VolumeManager.h +++ b/DDCore/include/DD4hep/VolumeManager.h @@ -12,6 +12,7 @@ // Framework include files #include "DD4hep/Volumes.h" #include "DD4hep/Detector.h" +#include "DD4hep/NamedObject.h" #include "DD4hep/IDDescriptor.h" // ROOT include files @@ -28,6 +29,8 @@ namespace DD4hep { // Forward declarations class LCDD; + class VolumeManagerContext; + class VolumeManagerObject; /** @class VolumeManager VolumeManager.h DD4hep/lcdd/VolumeManager.h * @@ -59,7 +62,7 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct VolumeManager: public Ref_t { + struct VolumeManager: public Handle<VolumeManagerObject> { public: typedef DD4hep::VolumeID VolumeID; typedef VolumeID VolIdentifier; @@ -72,96 +75,14 @@ namespace DD4hep { LAST }; - /** @class VolumeManager::Context VolumeManager.h DD4hep/lcdd/VolumeManager.h - * - * This structure describes the cached data for one placement - * - * @author M.Frank - * @version 1.0 - */ - struct Context { - public: - typedef std::vector<const TGeoNode*> Path; - typedef PlacedVolume::VolIDs::Base VolIDs; - - /// Placement identifier - VolumeID identifier; - /// Ignore mask of the placement identifier - VolumeID mask; - /// The placement - PlacedVolume placement; - /// Handle to the subdetector element handle - DetElement detector; - /// Handle to the closest Detector element - DetElement element; - /// The transformation of space-points to the corrdinate system of the closests detector element - TGeoHMatrix toDetector; - /// The transformation of space-points to the world corrdinate system - TGeoHMatrix toWorld; - /// Volume IDS corresponding to this element - VolIDs volID; - /// Path of placements to this sensitive volume - Path path; - public: - /// Default constructor - Context(); - /// Default destructor - virtual ~Context(); - }; /// Some useful Container abbreviations used by the VolumeManager + typedef VolumeManagerObject Object; + typedef VolumeManagerContext Context; typedef std::map<VolumeID, VolumeManager> Managers; typedef std::map<DetElement, VolumeManager> Detectors; - typedef std::map<TGeoNode*, Context*> PhysVolumes; - typedef std::map<VolumeID, Context*> Volumes; + typedef std::map<VolumeID, VolumeManagerContext*> Volumes; typedef PlacedVolume::VolIDs VolIDs; - - /** @class VolumeManager::Object VolumeManager.h DD4hep/lcdd/VolumeManager.h - * - * This structure describes the internal data of the volume manager object - * - * @author M.Frank - * @version 1.0 - */ - struct Object: public TNamed { - public: - typedef IDDescriptor::Field Field; - public: - /// Reference to the LCDD instance -#ifdef __CINT__ - LCDD* lcdd; -#else - LCDD& lcdd; -#endif - /// The container of subdetector elements - Detectors subdetectors; - /// The volume managers for the individual subdetector elements - Managers managers; - /// The container of placements managed by this instance - Volumes volumes; - /// The Detector element handle managed by this instance - DetElement detector; - /// The ID descriptor object - IDDescriptor id; - /// The reference to the TOP level VolumeManager - TNamed* top; - /// The system field descriptor - Field system; - /// System identifier - VolumeID sysID; - /// Sub-detector mask - VolumeID detMask; - /// Population flags - int flags; - public: - /// Default constructor - Object(LCDD& lcdd); - /// Default destructor - virtual ~Object(); - /// Search the locally cached volumes for a matching ID - Context* search(const VolumeID& id) const; - /// Update callback when alignment has changed (called only for subdetectors....) - void update(unsigned long tags, DetElement& det, void* param); - }; + typedef std::map<TGeoNode*, Context*> PhysVolumes; protected: /// Additional data accessor @@ -172,15 +93,21 @@ namespace DD4hep { public: /// Default constructor VolumeManager() - : Ref_t() { + : Handle<VolumeManagerObject>() { } /// Constructor to be used when reading the already parsed object VolumeManager(const VolumeManager& e) - : Ref_t(e) { + : Handle<VolumeManagerObject>(e) { } +#ifndef __CINT__ + /// Constructor to be used when reading the already parsed object + VolumeManager(const Handle<VolumeManagerObject>& e) + : Handle<VolumeManagerObject>(e) { + } +#endif /// Constructor to be used when reading the already parsed object template <typename Q> VolumeManager(const Handle<Q>& e) - : Ref_t(e) { + : Handle<VolumeManagerObject>(e) { } /** Initializing constructor. The tree will automatically be built if the detelement is valid * Please see enum PopulateFlags for further info. diff --git a/DDCore/include/DD4hep/Volumes.h b/DDCore/include/DD4hep/Volumes.h index 620bec3156263dffc5c62f17a16f2156aaf54750..35e00ea44ecb16a4216f71c82615e46996620816 100644 --- a/DDCore/include/DD4hep/Volumes.h +++ b/DDCore/include/DD4hep/Volumes.h @@ -50,58 +50,72 @@ namespace DD4hep { */ namespace Geometry { -// Forward declarations - struct LCDD; - struct Region; - struct LimitSet; - struct Material; - struct VisAttr; - struct Volume; - struct DetElement; - struct PlacedVolume; - struct SensitiveDetector; - - /** @class PlacedVolume Volume.h DD4hep/lcdd/Volume.h + // Forward declarations + class LCDD; + class Region; + class LimitSet; + class Material; + class VisAttr; + class Volume; + class DetElement; + class PlacedVolume; + class SensitiveDetector; + + /** @class PlacedVolumeExtension Volume.h DD4hep/lcdd/Volume.h * * @author M.Frank * @version 1.0 */ - struct PlacedVolume: Handle<TGeoNode> { + class PlacedVolumeExtension : public TGeoExtension { + public: typedef std::pair<std::string, int> VolID; - struct VolIDs: public std::vector<VolID> { + class VolIDs: public std::vector<VolID> { + public: typedef std::vector<VolID> Base; - VolIDs() - : Base() { + VolIDs() : std::vector<VolID>() { } ~VolIDs() { } - Base::const_iterator find(const std::string& name) const; - std::pair<Base::iterator, bool> insert(const std::string& name, int value); - }; - struct Object : public TGeoExtension { - /// Magic word to detect memory corruptions - unsigned long magic; - /// Reference count on object (used to implement Grab/Release) - long refCount; - /// ID container - VolIDs volIDs; - /// Default constructor - Object(); - /// Copy constructor - Object(const Object& c); - /// Default destructor - virtual ~Object(); - /// Assignment operator - Object& operator=(const Object& c) { - magic = c.magic; - volIDs = c.volIDs; - return *this; - } - /// TGeoExtension overload: Method called whenever requiring a pointer to the extension - virtual TGeoExtension *Grab(); - /// TGeoExtension overload: Method called always when the pointer to the extension is not needed anymore - virtual void Release() const; + std::vector<VolID>::const_iterator find(const std::string& name) const; + std::pair<std::vector<VolID>::iterator, bool> insert(const std::string& name, int value); }; + /// Magic word to detect memory corruptions + unsigned long magic; + /// Reference count on object (used to implement Grab/Release) + long refCount; + /// ID container + VolIDs volIDs; + /// Default constructor + PlacedVolumeExtension(); + /// Copy constructor + PlacedVolumeExtension(const PlacedVolumeExtension& c); + /// Default destructor + virtual ~PlacedVolumeExtension(); + /// Assignment operator + PlacedVolumeExtension& operator=(const PlacedVolumeExtension& c) { + magic = c.magic; + volIDs = c.volIDs; + return *this; + } + /// TGeoExtension overload: Method called whenever requiring a pointer to the extension + virtual TGeoExtension *Grab(); + /// TGeoExtension overload: Method called always when the pointer to the extension is not needed anymore + virtual void Release() const; + /// Enable ROOT persistency + ClassDef(PlacedVolumeExtension,1); + }; + + /** @class PlacedVolume Volume.h DD4hep/lcdd/Volume.h + * + * @author M.Frank + * @version 1.0 + */ + class PlacedVolume : public Handle<TGeoNode> { + public: + typedef PlacedVolumeExtension Object; + typedef Object::VolIDs VolIDs; + typedef Object::VolID VolID; + /// Constructor to be used when reading the already parsed DOM tree PlacedVolume(const TGeoNode* e) : Handle<TGeoNode>(e) { @@ -139,6 +153,45 @@ namespace DD4hep { std::string toString() const; }; + /** @class Volume::Object Volume.h DD4hep/Volume.h + * + * Internal data structure optional to TGeo data + * + * @author M.Frank + * @version 1.0 + */ + class VolumeExtension : public TGeoExtension { + public: + /// Magic word to detect memory corruptions + unsigned long magic; + /// Reference count on object (used to implement Grab/Release) + long refCount; + Region region; + LimitSet limits; + VisAttr vis; + Ref_t sens_det; + int referenced; + /// Default constructor + VolumeExtension(); + /// Default destructor + virtual ~VolumeExtension(); + /// Copy the object + void copy(const VolumeExtension& c) { + magic = c.magic; + region = c.region; + limits = c.limits; + vis = c.vis; + sens_det = c.sens_det; + referenced = c.referenced; + } + /// TGeoExtension overload: Method called whenever requiring a pointer to the extension + virtual TGeoExtension *Grab(); + /// TGeoExtension overload: Method called always when the pointer to the extension is not needed anymore + virtual void Release() const; + /// Enable ROOT persistency + ClassDef(VolumeExtension,1); + }; + /** @class Volume Volume.h DD4hep/Volume.h * * Handle describing a Volume @@ -146,46 +199,11 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct Volume: public Handle<TGeoVolume> { + class Volume: public Handle<TGeoVolume> { public: typedef Handle<TGeoVolume> Base; - - /** @class Volume::Object Volume.h DD4hep/Volume.h - * - * Internal data structure optional to TGeo data - * - * @author M.Frank - * @version 1.0 - */ - struct Object : public TGeoExtension { - /// Magic word to detect memory corruptions - unsigned long magic; - /// Reference count on object (used to implement Grab/Release) - long refCount; - Region region; - LimitSet limits; - VisAttr vis; - Ref_t sens_det; - int referenced; - /// Default constructor - Object(); - /// Default destructor - virtual ~Object(); - /// Copy the object - void copy(const Object& c) { - magic = c.magic; - region = c.region; - limits = c.limits; - vis = c.vis; - sens_det = c.sens_det; - referenced = c.referenced; - } - /// TGeoExtension overload: Method called whenever requiring a pointer to the extension - virtual TGeoExtension *Grab(); - /// TGeoExtension overload: Method called always when the pointer to the extension is not needed anymore - virtual void Release() const; - }; + typedef VolumeExtension Object; public: /// Default constructor @@ -193,6 +211,11 @@ namespace DD4hep { : Base(0) { } + /// Copy from handle + Volume(const TGeoVolume* v) + : Base(v) { + } + /// Copy from handle Volume(const Volume& v) : Base(v) { @@ -283,7 +306,8 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct Assembly: public Volume { + class Assembly: public Volume { + public: /// Default constructor Assembly() : Volume() { diff --git a/DDCore/include/DD4hep/objects/ConditionsInterna.h b/DDCore/include/DD4hep/objects/ConditionsInterna.h index e37d9274169169bb80e7c88b6583e2b232870e21..e8a6396aad28acc10df8268118f2c9ecc5b589e2 100644 --- a/DDCore/include/DD4hep/objects/ConditionsInterna.h +++ b/DDCore/include/DD4hep/objects/ConditionsInterna.h @@ -12,7 +12,10 @@ // Framework include files #include "DD4hep/Detector.h" #include "DD4hep/BasicGrammar.h" -#include "DD4hep/objects/NamedObject.h" +#include "DD4hep/NamedObject.h" + +#include <map> + /* * DD4hep namespace declaration */ @@ -34,8 +37,8 @@ namespace DD4hep { * */ namespace ConditionsInterna { - - class Object; + class ConditionContainer; + class ConditionObject; class Entry; class IOV; @@ -76,7 +79,7 @@ namespace DD4hep { * @version 1.0 */ class BlockData : public Block { - friend class ::DD4hep::Geometry::Condition; + friend class Condition; friend class Object; private: @@ -91,10 +94,10 @@ namespace DD4hep { void (*destruct)(void*); /// Constructor function -- only set if the object is valid void (*copy)(void*,const void*); - /// Data buffer type: Must be a bitmap! - int type; public: + /// Data buffer type: Must be a bitmap! + int type; /// Standard initializing constructor BlockData(); @@ -146,7 +149,7 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - class Object : public NamedObject { + class ConditionObject : public NamedObject { public: /// Condition value (in string form) std::string value; @@ -163,11 +166,11 @@ namespace DD4hep { /// Interval of validity IOV iov; /// Standard constructor - Object(); + ConditionObject(); /// Standard Destructor - virtual ~Object(); + virtual ~ConditionObject(); /// Move data content: 'from' will be reset to NULL - Object& move(Object& from); + ConditionObject& move(ConditionObject& from); }; /** @class Container ConditionsInterna.h DD4hep/ConditionsInterna.h @@ -177,16 +180,17 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - class Container : public NamedObject { + class ConditionContainer : public NamedObject { public: +#ifndef __CINT__ /// Container definition - typedef std::map<std::string, Condition> Entries; - - Entries entries; + typedef std::map<std::string, DD4hep::Geometry::Condition> Entries; +#endif + std::map<std::string,DD4hep::Geometry::Condition> entries; /// Standard constructor - Container(); + ConditionContainer(); /// Default destructor - virtual ~Container(); + virtual ~ConditionContainer(); /// Clear all conditions. Auto-delete of all existing entries void removeElements(); }; diff --git a/DDCore/include/DD4hep/objects/DetectorInterna.h b/DDCore/include/DD4hep/objects/DetectorInterna.h index 3c83abe19a1d391671fa988f3ba748c16e01d23a..0c17f371f2274edc47098f3f0414bacba876a0c6 100644 --- a/DDCore/include/DD4hep/objects/DetectorInterna.h +++ b/DDCore/include/DD4hep/objects/DetectorInterna.h @@ -11,6 +11,7 @@ // Framework include files #include "DD4hep/Callback.h" +#include "DD4hep/NamedObject.h" #include "DD4hep/Objects.h" #include "DD4hep/Detector.h" #include "DD4hep/Alignment.h" @@ -38,7 +39,7 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - class SensitiveDetectorObject: public TNamed, public ObjectExtensions { + class SensitiveDetectorObject: public NamedObject, public ObjectExtensions { public: unsigned int magic; int verbose; @@ -51,6 +52,8 @@ namespace DD4hep { /// Default constructor SensitiveDetectorObject(); + /// Initializing constructor + SensitiveDetectorObject(const std::string& nam); /// Internal object destructor: release extension object(s) virtual ~SensitiveDetectorObject(); }; @@ -60,7 +63,7 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - class DetElementObject: public TNamed, public ObjectExtensions { + class DetElementObject: public NamedObject, public ObjectExtensions { public: typedef DetElement::destruct_t destruct_t; typedef DetElement::copy_t copy_t; @@ -130,6 +133,8 @@ namespace DD4hep { TGeoHMatrix* referenceTrafo; /**@info: Public methods to ease the usage of the data. */ + /// Initializing constructor + DetElementObject(const std::string& nam, int ident); /// Default constructor DetElementObject(); /// Internal object destructor: release extension object(s) diff --git a/DDCore/include/DD4hep/objects/ObjectsInterna.h b/DDCore/include/DD4hep/objects/ObjectsInterna.h new file mode 100644 index 0000000000000000000000000000000000000000..ee8a59eb61828ee8fb5f338e1aa0ab201f08080d --- /dev/null +++ b/DDCore/include/DD4hep/objects/ObjectsInterna.h @@ -0,0 +1,164 @@ +// $Id: Detector.h 1087 2014-04-09 12:25:51Z markus.frank@cern.ch $ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== +#ifndef DD4HEP_GEOMETRY_OBJECTSINTERNA_H +#define DD4HEP_GEOMETRY_OBJECTSINTERNA_H + +// Framework include files +#include "DD4hep/Volumes.h" +#include "DD4hep/NamedObject.h" +#include "DD4hep/Segmentations.h" +#include "DDSegmentation/BitField64.h" + +// C/C++ include files +#include <set> + +// Forward declarations +class TColor; + +/* + * DD4hep namespace declaration + */ +namespace DD4hep { + + /* + * Geometry namespace declaration + */ + namespace Geometry { + + /** @class HeaderObject ObjectsInterna.h DD4hep/objects/ObjectsInterna.h + * + * + * + * @author M.Frank + * @version 1.0 + */ + class HeaderObject: public NamedObject { + public: + std::string url; + std::string author; + std::string status; + std::string version; + std::string comment; + /// Standard constructor + HeaderObject(); + /// Default destructor + virtual ~HeaderObject(); + private: + /// Private copy constructor + HeaderObject(const HeaderObject&) : NamedObject() {} + /// Private assignment operator + HeaderObject& operator=(const HeaderObject&) { return *this; } + }; + + /** @class VisAttrObject ObjectsInterna.h DD4hep/objects/ObjectsInterna.h + * + * + * + * @author M.Frank + * @version 1.0 + */ + class VisAttrObject: public NamedObject { + public: + unsigned long magic; + TColor* col; + int color; + float alpha; + unsigned char drawingStyle, lineStyle, showDaughters, visible; + /// Standard constructor + VisAttrObject(); + /// Default destructor + virtual ~VisAttrObject(); + }; + + /** @class RegionObject ObjectsInterna.h DD4hep/objects/ObjectsInterna.h + * + * + * + * @author M.Frank + * @version 1.0 + */ + class RegionObject: public NamedObject { + public: + unsigned long magic; + double threshold; + double cut; + bool store_secondaries; + std::string lunit, eunit; + std::vector<std::string> user_limits; + /// Standard constructor + RegionObject(); + /// Default destructor + virtual ~RegionObject(); + }; + + /** @class LimitSetObject ObjectsInterna.h DD4hep/objects/ObjectsInterna.h + * + * + * + * @author M.Frank + * @version 1.0 + */ + class LimitSetObject: public NamedObject, public std::set<Limit> { + public: + /// Standard constructor + LimitSetObject(); + /// Default destructor + virtual ~LimitSetObject(); + }; + + /** @class Readout::Object Readout.h DD4hep/Readout.h + * + * @author M.Frank + * @version 1.0 + */ + struct ReadoutObject: public NamedObject { + /// Handle to the readout segmentation + Segmentation segmentation; + /// Handle to the volume + Volume readoutWorld; + /// Handle to the field descriptor + IDDescriptor id; + /// Standard constructor + ReadoutObject(); + /// Default destructor + virtual ~ReadoutObject(); + }; + + /** @class IDDescriptor::Object IDDescriptor.h DDCore/IDDescriptor.h + * + * @author M.Frank + * @version 1.0 + * @date 2012/07/31 + */ + class IDDescriptorObject: public NamedObject, public DDSegmentation::BitField64 { + public: + typedef DDSegmentation::BitFieldValue* Field; + typedef std::vector<std::pair<std::string, Field> > FieldMap; + typedef std::vector<std::pair<size_t, std::string> > FieldIDs; + FieldMap fieldMap; //! not ROOT-persistent + FieldIDs fieldIDs; //! not ROOT-persistent + std::string description; + /// Default constructor + IDDescriptorObject(); + /// Standard constructor + IDDescriptorObject(const std::string& initString); + /// Default destructor + virtual ~IDDescriptorObject(); +#ifndef __CINT__ + /// Access to the field container of the BitField64 + const std::vector<DDSegmentation::BitFieldValue*> fields() const { + return _fields; + } +#endif + }; + + + } /* End namespace Geometry */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_GEOMETRY_OBJECTSINTERNA_H */ diff --git a/DDCore/include/DD4hep/objects/VolumeManagerInterna.h b/DDCore/include/DD4hep/objects/VolumeManagerInterna.h new file mode 100644 index 0000000000000000000000000000000000000000..e10f626d3c2590ce0195f2a07549b6a5fc2e73ea --- /dev/null +++ b/DDCore/include/DD4hep/objects/VolumeManagerInterna.h @@ -0,0 +1,126 @@ +// $Id: VolumeManager.h 513 2013-04-05 14:31:53Z gaede $ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== +#ifndef DD4HEP_GEOMETRY_VOLUMEMANAGERINTERNA_H +#define DD4HEP_GEOMETRY_VOLUMEMANAGERINTERNA_H + +// Framework include files +#include "DD4hep/Volumes.h" +#include "DD4hep/Detector.h" +#include "DD4hep/IDDescriptor.h" +#include "DD4hep/VolumeManager.h" + +// ROOT include files +#include "TGeoMatrix.h" +/* + * DD4hep namespace declaration + */ +namespace DD4hep { + + /* + * Geometry namespace declaration + */ + namespace Geometry { + + // Forward declarations + class LCDD; + class VolumeManagerContext; + class VolumeManagerObject; + + /** @class VolumeManagerContext VolumeManager.h DD4hep/lcdd/VolumeManager.h + * + * This structure describes the cached data for one placement + * + * @author M.Frank + * @version 1.0 + */ + class VolumeManagerContext { + public: + typedef std::vector<const TGeoNode*> Path; + typedef PlacedVolume::VolIDs::Base VolIDs; + + /// Placement identifier + VolumeID identifier; + /// Ignore mask of the placement identifier + VolumeID mask; + /// The placement + PlacedVolume placement; + /// Handle to the subdetector element handle + DetElement detector; + /// Handle to the closest Detector element + DetElement element; + /// The transformation of space-points to the corrdinate system of the closests detector element + TGeoHMatrix toDetector; + /// The transformation of space-points to the world corrdinate system + TGeoHMatrix toWorld; + /// Volume IDS corresponding to this element + VolIDs volID; + /// Path of placements to this sensitive volume + Path path; + public: + /// Default constructor + VolumeManagerContext(); + /// Default destructor + virtual ~VolumeManagerContext(); + }; + + /** @class VolumeManagerObject VolumeManager.h DD4hep/lcdd/VolumeManager.h + * + * This structure describes the internal data of the volume manager object + * + * @author M.Frank + * @version 1.0 + */ + struct VolumeManagerObject: public NamedObject { + public: + typedef IDDescriptor::Field Field; + typedef VolumeManager::Managers Managers; + typedef VolumeManager::Detectors Detectors; + typedef VolumeManager::Volumes Volumes; + typedef VolumeManager::Context Context; + + public: + /// Reference to the LCDD instance + LCDD* lcdd; + /// The container of subdetector elements + Detectors subdetectors; + /// The volume managers for the individual subdetector elements + Managers managers; + /// The container of placements managed by this instance + Volumes volumes; + /// The Detector element handle managed by this instance + DetElement detector; + /// The ID descriptor object + IDDescriptor id; + /// The reference to the TOP level VolumeManager + VolumeManagerObject* top; + /// The system field descriptor + Field system; + /// System identifier + VolumeID sysID; + /// Sub-detector mask + VolumeID detMask; + /// Population flags + int flags; + public: + /// Default constructor + VolumeManagerObject(LCDD& lcdd); + /// Default destructor + virtual ~VolumeManagerObject(); + /// Search the locally cached volumes for a matching ID + Context* search(const VolumeID& id) const; + /// Update callback when alignment has changed (called only for subdetectors....) + void update(unsigned long tags, DetElement& det, void* param); + }; + + /// Enable printouts for debugging + std::ostream& operator<<(std::ostream& os, const VolumeManager& m); + + } /* End namespace Geometry */ +} /* End namespace DD4hep */ +#endif /* DD4hep_GEOMETRY_VOLUMEMANAGERINTERNA_H */ diff --git a/DDCore/include/ROOT/LinkDef.h b/DDCore/include/ROOT/LinkDef.h index 50301fde445b62f5cfdd59897cb62aca86498de4..48b800afad4e3d8e3d15d4aab6737817a4bece4c 100644 --- a/DDCore/include/ROOT/LinkDef.h +++ b/DDCore/include/ROOT/LinkDef.h @@ -5,44 +5,6 @@ // Created by Pere Mato on 22/1/12. // Copyright 2012 __MyCompanyName__. All rights reserved. // +// Keep this file EMPTY. All CINT statements can be put in header files preceeding this one..... +// -#ifdef __CINT__ - -#pragma link off all globals; -#pragma link off all classes; -#pragma link off all functions; - -template class DD4hep::Geometry::Handle<TNamed>; - -#pragma link C++ class DD4hep::Geometry::LCDD; -#pragma link C++ class DD4hep::Geometry::Handle<TNamed>; -#pragma link C++ class DD4hep::Geometry::Constant; -#pragma link C++ class DD4hep::Geometry::Material; -#pragma link C++ class DD4hep::Geometry::Volume; -#pragma link C++ class DD4hep::Geometry::VisAttr; -#pragma link C++ class DD4hep::Geometry::Limit; -#pragma link C++ class DD4hep::Geometry::AlignmentEntry; -#pragma link C++ class DD4hep::Geometry::DetElement; -#pragma link C++ class DD4hep::Geometry::DetElement::Object; -#pragma link C++ class DD4hep::Geometry::Box; -#pragma link C++ class DD4hep::Geometry::Tube; -#pragma link C++ class DD4hep::Geometry::Trapezoid; -#pragma link C++ class DD4hep::Geometry::Volume; -#pragma link C++ class DD4hep::Geometry::PlacedVolume; -#pragma link C++ class DD4hep::Geometry::Position; -#pragma link C++ class DD4hep::Geometry::Rotation; -#pragma link C++ class DD4hep::Geometry::Readout; -#pragma link C++ class DD4hep::Geometry::Alignment; -#pragma link C++ class DD4hep::Geometry::Conditions; -#pragma link C++ class DD4hep::Geometry::ProjectiveCylinder; -#pragma link C++ class DD4hep::Geometry::NonProjectiveCylinder; -#pragma link C++ class DD4hep::Geometry::CartesianGridXY; -#pragma link C++ class DD4hep::Geometry::GridXYZ; -#pragma link C++ class DD4hep::Geometry::GlobalGridXY; -#pragma link C++ class DD4hep::Geometry::GridXY; -#pragma link C++ class DD4hep::Geometry::ProjectiveZPlane; -#pragma link C++ class DD4hep::Geometry::IDDescriptor; -#pragma link C++ namespace DD4hep::Geometry; -#pragma link C++ function DD4hep::Geometry::_toDictionary(const std::string&, const std::string&); - -#endif diff --git a/DDCore/src/Conditions.cpp b/DDCore/src/Conditions.cpp index 102550f977223d0bc13657538faa0da53937edeb..ed5f6e42b408559566206494b291b90db532eaa6 100644 --- a/DDCore/src/Conditions.cpp +++ b/DDCore/src/Conditions.cpp @@ -62,7 +62,7 @@ std::string Block::str() { /// Initializing constructor Condition::Condition(const string& nam) : Handle<Object>() { - assign(new ConditionsInterna::Object(),nam,"condition"); + assign(new ConditionsInterna::ConditionObject(),nam,"condition"); } /// Assignment operator @@ -202,7 +202,7 @@ int Conditions::set(Entry* cond) { } else { DetElement det(cond->detector); - assign(o=new ConditionsInterna::Container(),cond->name,cond->detector.name()); + assign(o=new ConditionsInterna::ConditionContainer(),cond->name,cond->detector.name()); det._data().conditions = *this; // Ugly. Need to fix this.... } if ( status == 1 ) { diff --git a/DDCore/src/ConditionsInterna.cpp b/DDCore/src/ConditionsInterna.cpp index 56ce287f56972dcf5ad822912e75a140683bc048..3561ed5c63cafeaeadb05c3f57c6cbe3e81097c4 100644 --- a/DDCore/src/ConditionsInterna.cpp +++ b/DDCore/src/ConditionsInterna.cpp @@ -19,7 +19,8 @@ using namespace DD4hep; using namespace DD4hep::Geometry; using namespace DD4hep::Geometry::ConditionsInterna; -DD4HEP_INSTANTIATE_HANDLE_NAMED(ConditionsInterna::Object); +DD4HEP_INSTANTIATE_HANDLE_NAMED(ConditionsInterna::ConditionObject); +DD4HEP_INSTANTIATE_HANDLE_NAMED(ConditionsInterna::ConditionContainer); /// Initializing constructor IOV::IOV(int t) : type(t) { @@ -97,17 +98,17 @@ void BlockData::assign(const void* ptr, const type_info& typ) { } /// Standard constructor -Object::Object() : NamedObject(), detector(), data(), iov() { +ConditionObject::ConditionObject() : NamedObject(), detector(), data(), iov() { InstanceCount::increment(this); } /// Standard Destructor -Object::~Object() { +ConditionObject::~ConditionObject() { InstanceCount::decrement(this); } /// Assignment operator -Object& Object::move(Object& c) { +ConditionObject& ConditionObject::move(ConditionObject& c) { if ( this != &c ) { name = c.name; type = c.type; @@ -153,18 +154,18 @@ Entry& Entry::operator=(const Entry& c) { } /// Standard constructor -Container::Container() : NamedObject() { +ConditionContainer::ConditionContainer() : NamedObject() { InstanceCount::increment(this); } /// Default destructor -Container::~Container() { +ConditionContainer::~ConditionContainer() { removeElements(); InstanceCount::decrement(this); } /// Clear all conditions. Auto-delete of all existing entries -void Container::removeElements() { +void ConditionContainer::removeElements() { for(Entries::iterator i=entries.begin(); i != entries.end(); ++i) delete (*i).second.ptr(); entries.clear(); diff --git a/DDCore/src/Detector.cpp b/DDCore/src/Detector.cpp index 4c75c94a4587f4e1c8cb8eaf5d7f076bcd5ecd73..bcf873abf98070f27413a3af424faa650a8e7ae6 100644 --- a/DDCore/src/Detector.cpp +++ b/DDCore/src/Detector.cpp @@ -23,19 +23,19 @@ DetElement::DetElement(Object* data, const string& name, const string& type) /// Constructor for a new subdetector element DetElement::DetElement(const string& name, const string& type, int id) { - assign(new Object(), name, type); + assign(new Object(name,id), name, type); ptr()->id = id; } /// Constructor for a new subdetector element DetElement::DetElement(const string& name, int id) { - assign(new Object(), name, ""); + assign(new Object(name,id), name, ""); ptr()->id = id; } /// Constructor for a new subdetector element DetElement::DetElement(DetElement parent, const string& name, int id) { - assign(new Object(), name, parent.type()); + assign(new Object(name,id), name, parent.type()); ptr()->id = id; parent.add(*this); } @@ -323,7 +323,7 @@ SensitiveDetector::SensitiveDetector(const string& name, const string& type) { <idspecref ref="EcalEndcapHits"/> </calorimeter> */ - assign(new Object(), name, type); + assign(new Object(name), name, type); object<Object>().ecut = 0e0; object<Object>().verbose = 0; } diff --git a/DDCore/src/DetectorInterna.cpp b/DDCore/src/DetectorInterna.cpp index 9b67e6eb7efa728b9f4b61bf5d92ff3948d59013..553270c27445ebccc74049898e29e42dd04718df 100644 --- a/DDCore/src/DetectorInterna.cpp +++ b/DDCore/src/DetectorInterna.cpp @@ -19,16 +19,26 @@ #include "DD4hep/objects/DetectorInterna.h" using namespace std; +using namespace DD4hep; using namespace DD4hep::Geometry; typedef DetectorTools::PlacementPath PlacementPath; typedef DetectorTools::ElementPath ElementPath; -DD4HEP_INSTANTIATE_HANDLE(DetElementObject); -DD4HEP_INSTANTIATE_HANDLE(SensitiveDetectorObject); +DD4HEP_INSTANTIATE_HANDLE_NAMED(DetElementObject); +DD4HEP_INSTANTIATE_HANDLE_NAMED(SensitiveDetectorObject); /// Default constructor SensitiveDetectorObject::SensitiveDetectorObject() - : TNamed(), ObjectExtensions(typeid(SensitiveDetectorObject)), magic(magic_word()), verbose(0), combineHits(0), ecut(0.0), readout(), region(), limits(), hitsCollection() { + : NamedObject(), ObjectExtensions(typeid(SensitiveDetectorObject)), magic(magic_word()), verbose(0), combineHits(0), ecut(0.0), readout(), region(), limits(), hitsCollection() { + printout(DEBUG,"SensitiveDetectorObject","+++ Created new anonymous SensitiveDetectorObject()"); + InstanceCount::increment(this); +} + +/// Initializing constructor +SensitiveDetectorObject::SensitiveDetectorObject(const std::string& nam) + : NamedObject(), ObjectExtensions(typeid(SensitiveDetectorObject)), magic(magic_word()), verbose(0), combineHits(0), ecut(0.0), readout(), region(), limits(), hitsCollection() { + SetName(nam.c_str()); + printout(DEBUG,"SensitiveDetectorObject","+++ Created new SensitiveDetectorObject('%s')",nam.c_str()); InstanceCount::increment(this); } @@ -43,10 +53,22 @@ SensitiveDetectorObject::~SensitiveDetectorObject() { /// Default constructor DetElementObject::DetElementObject() - : TNamed(), ObjectExtensions(typeid(DetElementObject)), magic(magic_word()), flag(0), id(0), combineHits(0), path(), placementPath(), + : NamedObject(), ObjectExtensions(typeid(DetElementObject)), magic(magic_word()), flag(0), id(0), combineHits(0), path(), placementPath(), + idealPlace(), placement(), volumeID(0), parent(), reference(), children(), + alignment(), volume_alignments(), conditions(), + worldTrafo(), parentTrafo(), referenceTrafo(0) { + printout(DEBUG,"DetElementObject","+++ Created new anonymous DetElementObject()"); + InstanceCount::increment(this); +} + +/// Initializing constructor +DetElementObject::DetElementObject(const std::string& nam, int ident) + : NamedObject(), ObjectExtensions(typeid(DetElementObject)), magic(magic_word()), flag(0), id(ident), combineHits(0), path(), placementPath(), idealPlace(), placement(), volumeID(0), parent(), reference(), children(), alignment(), volume_alignments(), conditions(), worldTrafo(), parentTrafo(), referenceTrafo(0) { + SetName(nam.c_str()); + printout(DEBUG,"DetElementObject","+++ Created new DetElementObject('%s', %d)",nam.c_str(),id); InstanceCount::increment(this); } @@ -84,7 +106,7 @@ DetElementObject* DetElementObject::clone(int new_id, int flag) const { obj->children.clear(); for (DetElement::Children::const_iterator i = children.begin(); i != children.end(); ++i) { - const TNamed* pc = (*i).second.ptr(); + const NamedObject* pc = (*i).second.ptr(); const DetElementObject& d = (*i).second._data(); DetElement child(d.clone(d.id, DetElement::COPY_PLACEMENT), pc->GetName(), pc->GetTitle()); pair<Children::iterator, bool> r = obj->children.insert(make_pair(child.name(), child)); diff --git a/DDCore/src/FieldTypes.cpp b/DDCore/src/FieldTypes.cpp index 4f03348795388fe52450e83f98feef7c4071d6ef..df631bc28565445ba6901be38044efc9100b7063 100644 --- a/DDCore/src/FieldTypes.cpp +++ b/DDCore/src/FieldTypes.cpp @@ -7,6 +7,7 @@ // //==================================================================== +#include "DD4hep/Handle.inl" #include "DD4hep/FieldTypes.h" #include <cmath> @@ -17,6 +18,10 @@ using namespace DD4hep::Geometry; #define INFINITY (numeric_limits<double>::max()) #endif +DD4HEP_INSTANTIATE_HANDLE(ConstantField); +DD4HEP_INSTANTIATE_HANDLE(SolenoidField); +DD4HEP_INSTANTIATE_HANDLE(DipoleField); + /// Call to access the field components at a given location void ConstantField::fieldComponents(const double* /* pos */, double* field) { field[0] += direction.X(); diff --git a/DDCore/src/Fields.cpp b/DDCore/src/Fields.cpp index 337639df9c9df31effbc3cb2bb5e7946ac6c5c7a..034516266edde03838fff10640adc021d4f38750 100644 --- a/DDCore/src/Fields.cpp +++ b/DDCore/src/Fields.cpp @@ -7,12 +7,19 @@ // //==================================================================== +#include "DD4hep/Handle.inl" #include "DD4hep/Fields.h" #include "DD4hep/InstanceCount.h" using namespace std; using namespace DD4hep::Geometry; +typedef CartesianField::Object CartesianFieldObject; +DD4HEP_INSTANTIATE_HANDLE(CartesianFieldObject); + +typedef OverlayedField::Object OverlayedFieldObject; +DD4HEP_INSTANTIATE_HANDLE(OverlayedFieldObject); + namespace { void calculate_combined_field(vector<CartesianField>& v, const double* pos, double* field) { for (vector<CartesianField>::iterator i = v.begin(); i != v.end(); ++i) @@ -22,7 +29,7 @@ namespace { /// Default constructor CartesianField::Object::Object() - : TNamed(), type(UNKNOWN) { + : NamedObject(), type(UNKNOWN) { InstanceCount::increment(this); } @@ -46,6 +53,16 @@ CartesianField::Properties& CartesianField::properties() const { return data<Object>()->properties; } +/// Returns the 3 field components (x, y, z). +void CartesianField::value(const Position& pos, Direction& field) const { + value(pos,(double*)&field); +} + +/// Returns the 3 field components (x, y, z). +void CartesianField::value(const Position& pos, double* val) const { + value((double*)&pos,val); +} + /// Returns the 3 field components (x, y, z). void CartesianField::value(const double* pos, double* val) const { data<Object>()->fieldComponents(pos, val); diff --git a/DDCore/src/GeoHandler.cpp b/DDCore/src/GeoHandler.cpp index d7f8d41465a7507cbb91beabb3fef0237bc26b91..83c7527e2bfac6d7ccf718ae972c61b8cfe20226 100644 --- a/DDCore/src/GeoHandler.cpp +++ b/DDCore/src/GeoHandler.cpp @@ -9,6 +9,7 @@ #include "DD4hep/LCDD.h" #include "DD4hep/GeoHandler.h" +#include "DD4hep/objects/ObjectsInterna.h" // ROOT includes #include "TGeoManager.h" @@ -77,14 +78,14 @@ GeoHandler& GeoHandler::collect(DetElement element, GeometryInfo& info) { const TGeoNode* n = *j; TGeoVolume* v = n->GetVolume(); if (v) { - TGeoMedium* m = v->GetMedium(); + Material m(v->GetMedium()); Volume vol = Ref_t(v); // Note : assemblies and the world do not have a real volume nor a material - if (info.volumeSet.find(v) == info.volumeSet.end()) { - info.volumeSet.insert(v); - info.volumes.push_back(v); + if (info.volumeSet.find(vol) == info.volumeSet.end()) { + info.volumeSet.insert(vol); + info.volumes.push_back(vol); } - if (m) + if (m.isValid()) info.materials.insert(m); if (dynamic_cast<Volume::Object*>(v)) { VisAttr vis = vol.visAttributes(); @@ -93,7 +94,7 @@ GeoHandler& GeoHandler::collect(DetElement element, GeometryInfo& info) { //SensitiveDetector det = vol.sensitiveDetector(); if (vis.isValid()) - info.vis.insert(vis.ptr()); + info.vis.insert(vis); //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); diff --git a/DDCore/src/GeometryTreeDump.cpp b/DDCore/src/GeometryTreeDump.cpp index 79a1607afc60b7f3e0c74eebe63fa286f9aaf712..b88916810dc273ec3fb2be7bb57ada0bb8792e4e 100644 --- a/DDCore/src/GeometryTreeDump.cpp +++ b/DDCore/src/GeometryTreeDump.cpp @@ -63,12 +63,11 @@ namespace { } /// Dump logical volume in GDML format to output stream -void* GeometryTreeDump::handleVolume(const string& name, const TGeoVolume* volume) const { - Volume vol = Handle<>(volume); +void* GeometryTreeDump::handleVolume(const string& name, Volume vol) const { VisAttr vis = vol.visAttributes(); - TGeoShape* shape = volume->GetShape(); - TGeoMedium* medium = volume->GetMedium(); - int num = volume->GetNdaughters(); + TGeoShape* shape = vol->GetShape(); + TGeoMedium* medium = vol->GetMedium(); + int num = vol->GetNdaughters(); m_output << "\t\t<volume name=\"" << name << "\">" << endl; m_output << "\t\t\t<solidref ref=\"" << shape->GetName() << "\"/>" << endl; @@ -78,7 +77,8 @@ void* GeometryTreeDump::handleVolume(const string& name, const TGeoVolume* volum } if (num > 0) { for (int i = 0; i < num; ++i) { - TGeoNode* n = volume->GetNode(i); + //TGeoNode* n = volume->GetNode(i); + TGeoNode* n = vol.ptr()->GetNode(vol->GetNode(i)->GetName()); TGeoVolume* v = n->GetVolume(); TGeoMatrix* m = n->GetMatrix(); m_output << "\t\t\t<physvol>" << endl; @@ -234,7 +234,7 @@ void GeometryTreeDump::handleSolids(const SolidSet& solids) const { void GeometryTreeDump::handleDefines(const LCDD::HandleMap& defs) const { m_output << "\t<define>" << endl; for (LCDD::HandleMap::const_iterator i = defs.begin(); i != defs.end(); ++i) - m_output << "\t\t<constant name=\"" << (*i).second->GetName() << "\" value=\"" << (*i).second->GetTitle() << "\" />" + m_output << "\t\t<constant name=\"" << (*i).second->name << "\" value=\"" << (*i).second->type << "\" />" << endl; m_output << "\t</define>" << endl; } diff --git a/DDCore/src/GeometryTreeDump.h b/DDCore/src/GeometryTreeDump.h index 0bf1c8f6c8ed1dda4b4899fbd16c171fab013cf8..dce23e7b2d5a28603578c0c242cfb23ace51a997 100644 --- a/DDCore/src/GeometryTreeDump.h +++ b/DDCore/src/GeometryTreeDump.h @@ -6,8 +6,8 @@ // Author : M.Frank // //==================================================================== -#ifndef DD4HEP_GeometryTreeDump_H -#define DD4HEP_GeometryTreeDump_H +#ifndef DD4HEP_GEOMETRYTREEDUMP_H +#define DD4HEP_GEOMETRYTREEDUMP_H #include "DD4hep/LCDD.h" #include "DD4hep/GeoHandler.h" @@ -42,7 +42,7 @@ namespace DD4hep { void create(DetElement top); /// Dump logical volume in GDML format to output stream - virtual void* handleVolume(const std::string& name, const TGeoVolume* volume) const; + virtual void* handleVolume(const std::string& name, Volume volume) const; /// Dump single volume transformation in GDML format to output stream virtual void* handleTransformation(const std::string& name, const TGeoMatrix* matrix) const; /// Dump solid in GDML format to output stream @@ -62,4 +62,4 @@ namespace DD4hep { } // End namespace Geometry } // End namespace DD4hep -#endif // DD4HEP_GeometryTreeDump_H +#endif // DD4HEP_GEOMETRYTREEDUMP_H diff --git a/DDCore/src/IDDescriptor.cpp b/DDCore/src/IDDescriptor.cpp index c07163bc3a78b70805866aca5768193c2a77a335..f27921ce63d2d5eabb25ccc14b319ae2e58d2af6 100644 --- a/DDCore/src/IDDescriptor.cpp +++ b/DDCore/src/IDDescriptor.cpp @@ -7,7 +7,9 @@ // //==================================================================== +#include "DD4hep/Handle.inl" #include "DD4hep/IDDescriptor.h" +#include "DD4hep/objects/ObjectsInterna.h" #include "DD4hep/InstanceCount.h" #include <stdexcept> #include <cstdlib> @@ -32,16 +34,6 @@ namespace { } } -/// Standard constructor -IDDescriptor::Object::Object(const std::string& desc) - : TNamed(), BitField64(desc) /*, maxBit(0) */{ - InstanceCount::increment(this); -} -/// Default destructor -IDDescriptor::Object::~Object() { - InstanceCount::decrement(this); -} - /// Initializing constructor IDDescriptor::IDDescriptor(const string& description) { Object* obj = new Object(description); @@ -124,7 +116,7 @@ VolumeID IDDescriptor::encode(const std::vector<VolID>& ids) const { void IDDescriptor::decodeFields(VolumeID vid, VolIDFields& fields) { fields.clear(); if (isValid()) { - const vector<BitFieldValue*>& v = data<Object>()->fields(); + const vector<BitFieldValue*>& v = ptr()->fields(); for (vector<BitFieldValue*>::const_iterator i = v.begin(); i != v.end(); ++i) fields.push_back(VolIDField(*i, (*i)->value(vid))); return; diff --git a/DDCore/src/LCDDData.cpp b/DDCore/src/LCDDData.cpp new file mode 100644 index 0000000000000000000000000000000000000000..74e2cdcf69c9996239e0de8899121ddf792205af --- /dev/null +++ b/DDCore/src/LCDDData.cpp @@ -0,0 +1,118 @@ +// $Id: LCDDImp.cpp 1117 2014-04-25 08:07:22Z markus.frank@cern.ch $ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== + +// Framework include files +#include "DD4hep/LCDDData.h" +#include "DD4hep/InstanceCount.h" +#include "DD4hep/objects/ObjectsInterna.h" +#include "DD4hep/objects/DetectorInterna.h" + +// ROOT include files +#include "TGeoManager.h" + +namespace DD4hep { namespace Geometry { class LCDDImp; }} + +using namespace DD4hep::Geometry; +using namespace DD4hep; +using namespace std; + +/// Default constructor +LCDDData::LCDDData() + : m_manager(0), m_world(), m_trackers(), m_worldVol(), + m_trackingVol(), m_field("global"), + m_extensions(typeid(LCDDData)) +{ + InstanceCount::increment(this); +} + +/// Standard destructor +LCDDData::~LCDDData() { + clearData(); + InstanceCount::decrement(this); +} + +/// Clear data content: releases all allocated resources +void LCDDData::destroyData() { + m_extensions.clear(); + destroyHandle(m_world); + destroyHandle(m_field); + destroyHandle(m_header); + for_each(m_readouts.begin(), m_readouts.end(), destroyHandles(m_readouts)); + for_each(m_idDict.begin(), m_idDict.end(), destroyHandles(m_idDict)); + for_each(m_limits.begin(), m_limits.end(), destroyHandles(m_limits)); + for_each(m_regions.begin(), m_regions.end(), destroyHandles(m_regions)); + for_each(m_alignments.begin(), m_alignments.end(), destroyHandles(m_alignments)); + for_each(m_sensitive.begin(), m_sensitive.end(), destroyHandles(m_sensitive)); + for_each(m_display.begin(), m_display.end(), destroyHandles(m_display)); + for_each(m_fields.begin(), m_fields.end(), destroyHandles(m_fields)); + for_each(m_define.begin(), m_define.end(), destroyHandles(m_define)); + + m_properties.clear(); + m_trackers.clear(); + m_worldVol.clear(); + m_trackingVol.clear(); + m_invisibleVis.clear(); + m_materialVacuum.clear(); + m_materialAir.clear(); + deletePtr(m_manager); +} + + +/// Clear data content: releases all allocated resources +void LCDDData::clearData() { + m_extensions.clear(false); + m_world.clear(); + m_field.clear(); + m_header.clear(); + m_properties.clear(); + m_readouts.clear(); + m_idDict.clear(); + m_limits.clear(); + m_regions.clear(); + m_alignments.clear(); + m_sensitive.clear(); + m_display.clear(); + m_fields.clear(); + m_define.clear(); + m_trackers.clear(); + m_worldVol.clear(); + m_trackingVol.clear(); + m_invisibleVis.clear(); + m_materialVacuum.clear(); + m_materialAir.clear(); + m_manager = 0; +} + +/// Adopt all data from source structure +void LCDDData::adoptData(LCDDData& source) { + m_extensions = source.m_extensions; + m_world = source.m_world; + m_field = source.m_field; + m_header = source.m_header; + m_properties = source.m_properties; + m_readouts = source.m_readouts; + m_idDict = source.m_idDict; + m_limits = source.m_limits; + m_regions = source.m_regions; + m_alignments = source.m_alignments; + m_sensitive = source.m_sensitive; + m_display = source.m_display; + m_fields = source.m_fields; + m_define = source.m_define; + m_trackers = source.m_trackers; + m_worldVol = source.m_worldVol; + m_trackingVol = source.m_trackingVol; + m_invisibleVis = source.m_invisibleVis; + m_materialVacuum = source.m_materialVacuum; + m_materialAir = source.m_materialAir; + m_manager = source.m_manager; + source.clearData(); +} + + diff --git a/DDCore/src/LCDDImp.cpp b/DDCore/src/LCDDImp.cpp index ebc5d4371bce31a450c3cf1299a0ec3a51081d10..e3e71bbb86a56c5a2d696210cf550f571a9a253d 100644 --- a/DDCore/src/LCDDImp.cpp +++ b/DDCore/src/LCDDImp.cpp @@ -11,7 +11,7 @@ #include "DD4hep/Printout.h" #include "DD4hep/GeoHandler.h" #include "DD4hep/InstanceCount.h" -#include "DD4hep/objects/DetectorInterna.h" +#include "DD4hep/objects/VolumeManagerInterna.h" #include "LCDDImp.h" // C/C++ include files @@ -76,6 +76,15 @@ void lcdd_unexpected(){ } } +/// Disable copy constructor +LCDDImp::LCDDImp(const LCDDImp&) : LCDDData(), m_volManager(), m_buildType(BUILD_NONE) { +} + +/// Disable assignment operator +LCDDImp& LCDDImp::operator=(const LCDDImp&) { + return *this; +} + LCDD& LCDD::getInstance() { if (!s_lcdd) s_lcdd = new LCDDImp(); @@ -91,15 +100,13 @@ void LCDD::destroyInstance() { /// Default constructor LCDDImp::LCDDImp() - : m_world(), m_trackers(), m_worldVol(), m_trackingVol(), m_field("global"), m_buildType(BUILD_NONE), - m_extensions(typeid(LCDDImp)) + : LCDDData(), m_volManager(), m_buildType(BUILD_NONE) { std::set_unexpected( lcdd_unexpected ) ; std::set_terminate( lcdd_unexpected ) ; InstanceCount::increment(this); - m_properties = new Properties(); if (0 == gGeoManager) { gGeoManager = new TGeoManager("world", "LCDD Geometry"); } @@ -126,29 +133,8 @@ LCDDImp::LCDDImp() /// Standard destructor LCDDImp::~LCDDImp() { - m_extensions.clear(); - destroyHandle(m_world); - destroyHandle(m_field); - destroyHandle(m_header); destroyHandle(m_volManager); - destroyObject(m_properties); - for_each(m_readouts.begin(), m_readouts.end(), destroyHandles(m_readouts)); - for_each(m_idDict.begin(), m_idDict.end(), destroyHandles(m_idDict)); - for_each(m_limits.begin(), m_limits.end(), destroyHandles(m_limits)); - for_each(m_regions.begin(), m_regions.end(), destroyHandles(m_regions)); - for_each(m_alignments.begin(), m_alignments.end(), destroyHandles(m_alignments)); - for_each(m_sensitive.begin(), m_sensitive.end(), destroyHandles(m_sensitive)); - for_each(m_display.begin(), m_display.end(), destroyHandles(m_display)); - for_each(m_fields.begin(), m_fields.end(), destroyHandles(m_fields)); - for_each(m_define.begin(), m_define.end(), destroyHandles(m_define)); - - m_trackers.clear(); - m_worldVol.clear(); - m_trackingVol.clear(); - m_invisibleVis.clear(); - m_materialVacuum.clear(); - m_materialAir.clear(); - delete m_manager; + destroyData(); InstanceCount::decrement(this); } diff --git a/DDCore/src/LCDDImp.h b/DDCore/src/LCDDImp.h index 515a006ca1a49ed4764d3dc6081d837944b1cde7..82ba49faab4918bbacdb941c586275beb6614642 100644 --- a/DDCore/src/LCDDImp.h +++ b/DDCore/src/LCDDImp.h @@ -11,8 +11,7 @@ #define DD4hep_LCDDGEOIMP_H // Framework include files -#include "DD4hep/LCDD.h" -#include "DD4hep/ObjectExtensions.h" +#include "DD4hep/LCDDData.h" // Forward declarations class TGeoManager; @@ -30,79 +29,24 @@ namespace DD4hep { */ namespace Geometry { - class LCDDImp: public LCDD { + /** @class LCDDImp LCDDImp.h src/LCDDImp.h + * + * @author M.Frank + * @version 1.0 + */ + class LCDDImp: public LCDD, public LCDDData { private: /// Disable copy constructor - LCDDImp(const LCDDImp&) : m_extensions(typeid(LCDDImp)) { - } + LCDDImp(const LCDDImp&); + /// Disable assignment operator - LCDDImp& operator=(const LCDDImp&) { - return *this; - } + LCDDImp& operator=(const LCDDImp&); public: - struct InvalidObjectError: public std::runtime_error { - InvalidObjectError(const std::string& msg) - : std::runtime_error("DD4hep: " + msg) { - } - }; - - struct ObjectHandleMap: public HandleMap { - ObjectHandleMap() { - } - void append(const Ref_t& 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())); - if (!throw_on_doubles || r.second) - return; - throw InvalidObjectError("Attempt to add an already existing object:" + std::string(e.name()) + "."); - } - throw InvalidObjectError("Attempt to add an invalid object."); - } - - template <typename T> void append(const Ref_t& e, bool throw_on_doubles = true) { - T* obj = dynamic_cast<T*>(e.ptr()); - if (obj) { - this->append(e, throw_on_doubles); - return; - } - throw InvalidObjectError("Attempt to add an object, which is of the wrong type."); - } - }; - - TGeoManager* m_manager; - ObjectHandleMap m_readouts; - ObjectHandleMap m_idDict; - ObjectHandleMap m_limits; - ObjectHandleMap m_regions; - ObjectHandleMap m_detectors; - ObjectHandleMap m_alignments; - ObjectHandleMap m_sensitive; - ObjectHandleMap m_display; - ObjectHandleMap m_fields; - - // GDML fields - ObjectHandleMap m_define; - - DetElement m_world; - DetElement m_trackers; - Volume m_worldVol; - Volume m_trackingVol; VolumeManager m_volManager; - - Material m_materialAir; - Material m_materialVacuum; - VisAttr m_invisibleVis; - OverlayedField m_field; - Ref_t m_header; - Properties* m_properties; LCDDBuildType m_buildType; - /// Definition of the extension type - ObjectExtensions m_extensions; - /// Default constructor LCDDImp(); @@ -146,7 +90,7 @@ namespace DD4hep { } /// Access to properties Properties& properties() const { - return *m_properties; + return *(Properties*)&m_properties; } /// Return handle to material describing air virtual Material air() const { @@ -279,6 +223,10 @@ namespace DD4hep { virtual const HandleMap& fields() const { return m_fields; } + /// Accessor to the map of ID specifications + virtual const HandleMap& idSpecifications() const { + return m_idDict; + } #define __R return *this /// Add a new constant to the detector description @@ -309,6 +257,10 @@ namespace DD4hep { virtual LCDD& add(Readout x) { return addReadout(x); } + /// Add a new sensitive detector to the detector description + virtual LCDD& add(SensitiveDetector x) { + return addSensitiveDetector(x); + } /// Add a new subdetector to the detector description virtual LCDD& add(DetElement x) { return addDetector(x); diff --git a/DDCore/src/MatrixHelpers.cpp b/DDCore/src/MatrixHelpers.cpp index e803c891f4d5d851181313e5d6a2ebf01c6728c9..7ffcea6057e0bdde5e55b36cc626a8edda3139a0 100644 --- a/DDCore/src/MatrixHelpers.cpp +++ b/DDCore/src/MatrixHelpers.cpp @@ -48,6 +48,13 @@ TGeoHMatrix* DD4hep::Geometry::_transform(const RotationZYX& rot) { return tr; } +TGeoHMatrix* DD4hep::Geometry::_transform(const Rotation3D& rot) { + TGeoHMatrix *tr = new TGeoHMatrix(); + Double_t* r = tr->GetRotationMatrix(); + rot.GetComponents(r); + return tr; +} + TGeoHMatrix* DD4hep::Geometry::_transform(const Transform3D& trans) { Position pos; RotationZYX rot; diff --git a/DDCore/src/NamedObject.cpp b/DDCore/src/NamedObject.cpp index 9a2ee0966261b99748aca607e911af2dd0a1856a..e32ea82ce69edc9fe5e72d9991079cc7a9dbdc8e 100644 --- a/DDCore/src/NamedObject.cpp +++ b/DDCore/src/NamedObject.cpp @@ -8,7 +8,7 @@ //==================================================================== // Framework includes -#include "DD4hep/objects/NamedObject.h" +#include "DD4hep/NamedObject.h" #include "DD4hep/Handle.inl" #include "TObject.h" diff --git a/DDCore/src/ObjectExtensions.cpp b/DDCore/src/ObjectExtensions.cpp index 1625aa92683a37bbcbb3e28a094c1c0e2cff70cd..c3a967269a504bbbda27f2ecb8fa1bb3754d1f92 100644 --- a/DDCore/src/ObjectExtensions.cpp +++ b/DDCore/src/ObjectExtensions.cpp @@ -39,14 +39,14 @@ ObjectExtensions::~ObjectExtensions() { } /// Internal object destructor: release extension object(s) -void ObjectExtensions::clear() { +void ObjectExtensions::clear(bool destroy) { for (Extensions::iterator i = extensions.begin(); i != extensions.end(); ++i) { void* ptr = (*i).second; if (ptr) { ExtensionMap::iterator j = extensionMap->find((*i).first); if (j != extensionMap->end()) { Entry& e = (*j).second; - if (e.destruct) + if (destroy && e.destruct) (*(e.destruct))(ptr); } } diff --git a/DDCore/src/Objects.cpp b/DDCore/src/Objects.cpp index 13d3f701b341d6a06689ecfb3309baace86e803c..520632ba006865f07a9215a4fbe61fc378bbfb26 100644 --- a/DDCore/src/Objects.cpp +++ b/DDCore/src/Objects.cpp @@ -7,10 +7,12 @@ // //==================================================================== +// Framework include files #include "DD4hep/LCDD.h" #include "DD4hep/Printout.h" #include "DD4hep/IDDescriptor.h" #include "DD4hep/InstanceCount.h" +#include "DD4hep/objects/ObjectsInterna.h" #include "TMap.h" #include "TROOT.h" @@ -20,6 +22,7 @@ #include "TGeoElement.h" #include "TGeoMaterial.h" +// C/C++ include files #include <cmath> #include <sstream> #include <iomanip> @@ -29,7 +32,7 @@ using namespace DD4hep::Geometry; /// Constructor to be used when creating a new DOM tree Author::Author(LCDD& /* lcdd */) { - m_element = new TNamed("", "author"); + m_element = new NamedObject("", "author"); } /// Access the auhor's name @@ -52,17 +55,6 @@ void Author::setAuthorEmail(const std::string& addr) { m_element->SetTitle(addr.c_str()); } -/// Standard constructor -Header::Object::Object() - : TNamed() { - InstanceCount::increment(this); -} - -/// Default destructor -Header::Object::~Object() { - InstanceCount::decrement(this); -} - /// Constructor to be used when creating a new DOM tree Header::Header(const string& author, const string& url) { Object* ptr = new Object(); @@ -141,12 +133,12 @@ void Header::setComment(const std::string& new_comment) { /// Constructor to be used when creating a new DOM tree Constant::Constant(const string& nam, const string& val) { - m_element = new TNamed(nam.c_str(), val.c_str()); + m_element = new NamedObject(nam.c_str(), val.c_str()); } /// Constructor to be used when creating a new DOM tree Constant::Constant(const string& name) { - m_element = new TNamed(name.c_str(), ""); + m_element = new NamedObject(name.c_str(), ""); } /// String representation of this object @@ -234,19 +226,19 @@ string Material::toString() const { return os.str(); } -/// Standard constructor -VisAttr::Object::Object() - : magic(magic_word()), col(0), color(0), alpha(0), drawingStyle(SOLID), lineStyle(SOLID), showDaughters(true), visible(true) { - InstanceCount::increment(this); -} - -/// Default destructor -VisAttr::Object::~Object() { - InstanceCount::decrement(this); +/// Constructor to be used when creating a new DOM tree +VisAttr::VisAttr(const string& name) { + Object* obj = new Object(); + assign(obj, name, "vis"); + obj->color = 2; + setLineStyle (SOLID); + setDrawingStyle(SOLID); + setShowDaughters(true); + setAlpha(0.1f); } /// Constructor to be used when creating a new DOM tree -VisAttr::VisAttr(const string& name) { +VisAttr::VisAttr(const char* name) { Object* obj = new Object(); assign(obj, name, "vis"); obj->color = 2; @@ -298,7 +290,7 @@ void VisAttr::setDrawingStyle(int value) { /// Get alpha value float VisAttr::alpha() const { - //TNamed* obj = first_value<TNamed>(*this); + //NamedObject* obj = first_value<NamedObject>(*this); //obj->SetAlpha(value); return object<Object>().alpha; } @@ -306,7 +298,7 @@ float VisAttr::alpha() const { /// Set alpha value void VisAttr::setAlpha(float value) { object<Object>().alpha = value; - //TNamed* obj = first_value<TNamed>(*this); + //NamedObject* obj = first_value<NamedObject>(*this); //obj->SetAlpha(value); } @@ -412,16 +404,6 @@ string Limit::toString() const { return res; } -/// Standard constructor -LimitSet::Object::Object() { - InstanceCount::increment(this); -} - -/// Default destructor -LimitSet::Object::~Object() { - InstanceCount::decrement(this); -} - /// Constructor to be used when creating a new DOM tree LimitSet::LimitSet(const string& name) { assign(new Object(), name, "limitset"); @@ -439,18 +421,6 @@ const set<Limit>& LimitSet::limits() const { return *o; } -/// Standard constructor -Region::Object::Object() - : magic(magic_word()), threshold(10.0), cut(10.0), store_secondaries(false) -{ - InstanceCount::increment(this); -} - -/// Default destructor -Region::Object::~Object() { - InstanceCount::decrement(this); -} - /// Constructor to be used when creating a new DOM tree Region::Region(const string& name) { Object* p = new Object(); diff --git a/DDCore/src/ObjectsInterna.cpp b/DDCore/src/ObjectsInterna.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3c10d405be04da23001056220a997d14c56f67e9 --- /dev/null +++ b/DDCore/src/ObjectsInterna.cpp @@ -0,0 +1,104 @@ +// $Id: Objects.cpp 1163 2014-05-19 12:26:55Z gaede $ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== +#include "DD4hep/Handle.inl" +#include "DD4hep/InstanceCount.h" +#include "DD4hep/Objects.h" +#include "DD4hep/objects/ObjectsInterna.h" + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::Geometry; + +DD4HEP_INSTANTIATE_HANDLE_NAMED(VisAttrObject); + +/// Standard constructor +VisAttrObject::VisAttrObject() +: magic(magic_word()), col(0), color(0), alpha(0), drawingStyle(VisAttr::SOLID), lineStyle(VisAttr::SOLID), showDaughters(true), visible(true) { + InstanceCount::increment(this); +} + +/// Default destructor +VisAttrObject::~VisAttrObject() { + InstanceCount::decrement(this); +} + +DD4HEP_INSTANTIATE_HANDLE_NAMED(HeaderObject); + +/// Standard constructor +HeaderObject::HeaderObject() + : NamedObject() { + InstanceCount::increment(this); +} + +/// Default destructor +HeaderObject::~HeaderObject() { + InstanceCount::decrement(this); +} + +DD4HEP_INSTANTIATE_HANDLE_NAMED(RegionObject); + +/// Standard constructor +RegionObject::RegionObject() + : magic(magic_word()), threshold(10.0), cut(10.0), store_secondaries(false) +{ + InstanceCount::increment(this); +} + +/// Default destructor +RegionObject::~RegionObject() { + InstanceCount::decrement(this); +} + +DD4HEP_INSTANTIATE_HANDLE_NAMED(LimitSetObject); + +/// Standard constructor +LimitSetObject::LimitSetObject() { + InstanceCount::increment(this); +} + +/// Default destructor +LimitSetObject::~LimitSetObject() { + InstanceCount::decrement(this); +} + +DD4HEP_INSTANTIATE_HANDLE_NAMED(ReadoutObject); + +/// Standard constructor +ReadoutObject::ReadoutObject() { + InstanceCount::increment(this); +} + +/// Default destructor +ReadoutObject::~ReadoutObject() { + //destroyHandle(segmentation); + InstanceCount::decrement(this); + if ( segmentation.isValid() ) { + delete segmentation.ptr(); + segmentation = Segmentation(); + } +} + +DD4HEP_INSTANTIATE_HANDLE_NAMED(IDDescriptorObject); + +/// Standard constructor +IDDescriptorObject::IDDescriptorObject() + : NamedObject(), BitField64() /*, maxBit(0) */{ + InstanceCount::increment(this); +} + +/// Standard constructor +IDDescriptorObject::IDDescriptorObject(const std::string& desc) + : NamedObject(), BitField64(desc) /*, maxBit(0) */{ + InstanceCount::increment(this); +} + +/// Default destructor +IDDescriptorObject::~IDDescriptorObject() { + InstanceCount::decrement(this); +} diff --git a/DDCore/src/Printout.cpp b/DDCore/src/Printout.cpp index 00ece2231fb352eb79224be82db085cf0b560432..7716cf0def9f92b832aad4edcb43da3a43610354 100644 --- a/DDCore/src/Printout.cpp +++ b/DDCore/src/Printout.cpp @@ -9,6 +9,7 @@ #include "DD4hep/LCDD.h" #include "DD4hep/Objects.h" +#include "DD4hep/objects/ObjectsInterna.h" #include "DD4hep/Printout.h" #include <cstdarg> #include <stdexcept> @@ -194,6 +195,9 @@ namespace DD4hep { p((*i).second); } + template <> void Printer<Handle<NamedObject> >::operator()(const Handle<NamedObject>& val) const { + printout(INFO, "Printer", "%s ++ Handle:%s %s", prefix.c_str(), val->GetName(), val->GetTitle()); + } template <> void Printer<Handle<TNamed> >::operator()(const Handle<TNamed>& val) const { printout(INFO, "Printer", "%s ++ Handle:%s %s", prefix.c_str(), val->GetName(), val->GetTitle()); } @@ -226,7 +230,7 @@ namespace DD4hep { template <> void Printer<Position>::operator()(const Position& val) const { printout(INFO, "Printer", "%s ++ Position: x: %9.3 mm y: %9.3 mm z: %9.3 mm", prefix.c_str(), val.X(), val.Y(), val.Z()); } - +#if 0 template <> void Printer<LimitSet>::operator()(const LimitSet& val) const { const set<Limit>& o = val.limits(); printout(INFO, "Printer", "%s ++ LimitSet: %s", prefix.c_str(), val.name()); @@ -277,13 +281,13 @@ namespace DD4hep { return; } } - +#endif template <> void Printer<const LCDD*>::operator()(const LCDD* const &) const { //Header(lcdd.header()).fromCompact(doc,compact.child(Tag_info),Strng_t("In memory")); PrintMap < Constant > (lcdd, os, lcdd->constants(), "List of Constants")(); - PrintMap < VisAttr > (lcdd, os, lcdd->visAttributes(), "List of Visualization attributes")(); - PrintMap < LimitSet > (lcdd, os, lcdd->readouts(), "List of Readouts")(); - PrintMap < Region > (lcdd, os, lcdd->regions(), "List of Regions")(); - PrintMap < DetElement > (lcdd, os, lcdd->detectors(), "List of DetElements")(); + //PrintMap < VisAttr > (lcdd, os, lcdd->visAttributes(), "List of Visualization attributes")(); + //PrintMap < LimitSet > (lcdd, os, lcdd->readouts(), "List of Readouts")(); + //PrintMap < Region > (lcdd, os, lcdd->regions(), "List of Regions")(); + //PrintMap < DetElement > (lcdd, os, lcdd->detectors(), "List of DetElements")(); } } diff --git a/DDCore/src/Readout.cpp b/DDCore/src/Readout.cpp index 0027ca29c818b671c6092af1a48019c29cb7f9c1..9c841504afdbfd5e1dbb3cb4d9aa25ad8a3ac8bf 100644 --- a/DDCore/src/Readout.cpp +++ b/DDCore/src/Readout.cpp @@ -8,33 +8,20 @@ //==================================================================== #include "DD4hep/Readout.h" +#include "DD4hep/objects/ObjectsInterna.h" #include "DD4hep/InstanceCount.h" #include "DD4hep/TGeoUnits.h" #include "DD4hep/LCDD.h" +#include "DD4hep/Handle.inl" using namespace std; using namespace DD4hep; using namespace DD4hep::Geometry; using tgeo::mm; -/// Standard constructor -Readout::Object::Object() { - InstanceCount::increment(this); -} - -/// Default destructor -Readout::Object::~Object() { - //destroyHandle(segmentation); - InstanceCount::decrement(this); - if ( segmentation.isValid() ) { - delete segmentation.ptr(); - segmentation = Segmentation(); - } -} - /// Initializing constructor to create a new object Readout::Readout(const string& nam) { - assign(new Object(), nam, "readout"); + assign(new ReadoutObject(), nam, "readout"); } /// Assign IDDescription to readout structure diff --git a/DDCore/src/Segmentations.cpp b/DDCore/src/Segmentations.cpp index 962e5c7cfc57e51aee6cd7568fb73403becbe144..0bfeed0eedc1df0010d68221d17bbf625cef4432 100644 --- a/DDCore/src/Segmentations.cpp +++ b/DDCore/src/Segmentations.cpp @@ -9,6 +9,7 @@ #include "DD4hep/Segmentations.h" #include "DD4hep/InstanceCount.h" +#include "DD4hep/Handle.inl" #include <iostream> #include <stdexcept> @@ -19,14 +20,16 @@ using DD4hep::DDSegmentation::Parameter; using DD4hep::DDSegmentation::Parameters; using DD4hep::DDSegmentation::SegmentationParameter; +DD4HEP_INSTANTIATE_HANDLE_UNNAMED(SegmentationObject); + /// Standard constructor -Segmentation::Object::Object(BaseSegmentation* s) +SegmentationObject::SegmentationObject(BaseSegmentation* s) : magic(magic_word()), useForHitPosition(0), segmentation(s) { InstanceCount::increment(this); } /// Default destructor -Segmentation::Object::~Object() { +SegmentationObject::~SegmentationObject() { InstanceCount::decrement(this); if (segmentation) { delete segmentation; @@ -34,53 +37,60 @@ Segmentation::Object::~Object() { } /// determine the local position based on the cell ID -DDSegmentation::Vector3D Segmentation::Object::position(const long64& cellID) const { +DDSegmentation::Vector3D SegmentationObject::position(const long64& cellID) const { return segmentation->position(cellID); } /// determine the cell ID based on the local position -long64 Segmentation::Object::cellID(const DDSegmentation::Vector3D& localPosition, const DDSegmentation::Vector3D& globalPosition, const long64& volumeID) const { +long64 SegmentationObject::cellID(const DDSegmentation::Vector3D& localPosition, const DDSegmentation::Vector3D& globalPosition, const long64& volumeID) const { return segmentation->cellID(localPosition, globalPosition, volumeID); } /// Access the encoding string -string Segmentation::Object::fieldDescription() const { +string SegmentationObject::fieldDescription() const { return segmentation->fieldDescription(); } /// Access the segmentation name -const string& Segmentation::Object::name() const { +const string& SegmentationObject::name() const { return segmentation->name(); } /// Set the segmentation name -void Segmentation::Object::setName(const string& value) { +void SegmentationObject::setName(const string& value) { segmentation->setName(value); } + /// Access the segmentation type -const string& Segmentation::Object::type() const { +const string& SegmentationObject::type() const { return segmentation->type(); } + /// Access the description of the segmentation -const string& Segmentation::Object::description() const { +const string& SegmentationObject::description() const { return segmentation->description(); } + /// Access the underlying decoder -BitField64* Segmentation::Object::decoder() { +BitField64* SegmentationObject::decoder() { return segmentation->decoder(); } + /// Set the underlying decoder -void Segmentation::Object::setDecoder(BitField64* decoder) { +void SegmentationObject::setDecoder(BitField64* decoder) { segmentation->setDecoder(decoder); } + /// Access to parameter by name -Parameter Segmentation::Object::parameter(const string& parameterName) const { +Parameter SegmentationObject::parameter(const string& parameterName) const { return segmentation->parameter(parameterName); } + /// Access to all parameters -Parameters Segmentation::Object::parameters() const { +Parameters SegmentationObject::parameters() const { return segmentation->parameters(); } + /// Set all parameters from an existing set of parameters -void Segmentation::Object::setParameters(const Parameters& parameters) { +void SegmentationObject::setParameters(const Parameters& parameters) { segmentation->setParameters(parameters); } diff --git a/DDCore/src/SimpleGDMLWriter.cpp b/DDCore/src/SimpleGDMLWriter.cpp index adb060f89c32fa0b8a515265522cba929d9d289f..cca0c80e00bd926098bd9c3a8ff4517c032aee7e 100644 --- a/DDCore/src/SimpleGDMLWriter.cpp +++ b/DDCore/src/SimpleGDMLWriter.cpp @@ -60,7 +60,7 @@ namespace { /// Dump logical volume in GDML format to output stream void* SimpleGDMLWriter::handleVolume(const string& name, const TGeoVolume* volume) const { - Volume vol = Handle<>(volume); + Volume vol(volume); VisAttr vis = vol.visAttributes(); TGeoShape* shape = volume->GetShape(); TGeoMedium* medium = volume->GetMedium(); @@ -68,13 +68,15 @@ void* SimpleGDMLWriter::handleVolume(const string& name, const TGeoVolume* volum m_output << "\t\t<volume name=\"" << name << "\">" << endl; m_output << "\t\t\t<solidref ref=\"" << shape->GetName() << "\"/>" << endl; - m_output << "\t\t\t<materialref ref=\"" << medium->GetName() << "\"/>" << endl; + m_output << "\t\t\t<materialref ref=\"" + << (medium ? medium->GetName() : "UnknownMaterial") << "\"/>" << endl; if (vis.isValid()) { m_output << "\t\t\t<visref ref=\"" << vis.name() << "\"/>" << endl; } if (num > 0) { for (int i = 0; i < num; ++i) { - TGeoNode* n = volume->GetNode(i); + //TGeoNode* n = volume->GetNode(i); + TGeoNode* n = volume->GetNode(volume->GetNode(i)->GetName()); TGeoVolume* v = n->GetVolume(); TGeoMatrix* m = n->GetMatrix(); m_output << "\t\t\t<physvol>" << endl; @@ -180,9 +182,9 @@ void* SimpleGDMLWriter::handleSolid(const string& name, const TGeoShape* shape) } /// Dump structure information in GDML format to output stream -void SimpleGDMLWriter::handleStructure(const VolumeSet& volset) const { +void SimpleGDMLWriter::handleStructure(const VolumeVector& volset) const { m_output << "\t<structure>" << endl; - for (VolumeSet::const_iterator i = volset.begin(); i != volset.end(); ++i) + for (VolumeVector::const_iterator i = volset.begin(); i != volset.end(); ++i) handleVolume((*i)->GetName(), (*i)); m_output << "\t</structure>" << endl; } @@ -282,9 +284,9 @@ void SimpleGDMLWriter::create(DetElement top) { GeometryInfo geo; collect(top, geo); //handleSetup(LCDD::getInstance().header()); - //handleDefines(LCDD::getInstance().constants()); + handleDefines(LCDD::getInstance().constants()); handleVisualisation(geo.vis); - //handleTransformations(geo.trafos); - //handleSolids(geo.solids); - //handleStructure(geo.volumes); + handleTransformations(geo.trafos); + handleSolids(geo.solids); + handleStructure(geo.volumes); } diff --git a/DDCore/src/SimpleGDMLWriter.h b/DDCore/src/SimpleGDMLWriter.h index f51fb0e2d650d1be331d03e3eddb10f3ef1128f7..92fcdbce58822696121aea79a97c7fad6c42e48a 100644 --- a/DDCore/src/SimpleGDMLWriter.h +++ b/DDCore/src/SimpleGDMLWriter.h @@ -62,7 +62,7 @@ namespace DD4hep { /// Dump Transformations in GDML format to output stream virtual void handleTransformations(const TransformSet& trafos) const; /// Dump structure information in GDML format to output stream - virtual void handleStructure(const VolumeSet& volset) const; + virtual void handleStructure(const VolumeVector& volset) const; }; } // End namespace Geometry } // End namespace DD4hep diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp index e9f59f7f114564d91a3bdce245125b6ce2e7cbee..ee346e77b897386e3f446807b27f3a99a17ce9da 100644 --- a/DDCore/src/VolumeManager.cpp +++ b/DDCore/src/VolumeManager.cpp @@ -7,10 +7,12 @@ // //==================================================================== // Framework include files -#include "DD4hep/VolumeManager.h" -#include "DD4hep/Printout.h" #include "DD4hep/LCDD.h" +#include "DD4hep/Handle.inl" +#include "DD4hep/Printout.h" +#include "DD4hep/VolumeManager.h" #include "DD4hep/objects/DetectorInterna.h" +#include "DD4hep/objects/VolumeManagerInterna.h" // C/C++ includes #include <set> @@ -18,10 +20,14 @@ #include <sstream> #include <iomanip> + using namespace std; using namespace DD4hep; using namespace DD4hep::Geometry; +DD4HEP_INSTANTIATE_HANDLE_NAMED(VolumeManagerObject); + + namespace { struct Populator { @@ -216,21 +222,21 @@ namespace { } /// Default constructor -VolumeManager::Context::Context() +VolumeManagerContext::VolumeManagerContext() : identifier(0), mask(~0x0ULL) { } /// Default destructor -VolumeManager::Context::~Context() { +VolumeManagerContext::~VolumeManagerContext() { } /// Default constructor -VolumeManager::Object::Object(LCDD& l) - : lcdd(l), top(0), system(0), sysID(0), detMask(~0x0ULL), flags(VolumeManager::NONE) { +VolumeManagerObject::VolumeManagerObject(LCDD& l) + : lcdd(&l), top(0), system(0), sysID(0), detMask(~0x0ULL), flags(VolumeManager::NONE) { } /// Default destructor -VolumeManager::Object::~Object() { +VolumeManagerObject::~VolumeManagerObject() { /// Cleanup volume tree for_each(volumes.begin(), volumes.end(), destroyObjects(volumes)); volumes.clear(); @@ -241,7 +247,7 @@ VolumeManager::Object::~Object() { } /// Update callback when alignment has changed (called only for subdetectors....) -void VolumeManager::Object::update(unsigned long tags, DetElement& det, void* param) { +void VolumeManagerObject::update(unsigned long tags, DetElement& det, void* param) { if ( DetElement::CONDITIONS_CHANGED == (tags&DetElement::CONDITIONS_CHANGED) ) printout(DEBUG,"VolumeManager","+++ Conditions update %s param:%p",det.path().c_str(),param); if ( DetElement::PLACEMENT_CHANGED == (tags&DetElement::PLACEMENT_CHANGED) ) @@ -255,7 +261,7 @@ void VolumeManager::Object::update(unsigned long tags, DetElement& det, void* pa } /// Search the locally cached volumes for a matching ID -VolumeManager::Context* VolumeManager::Object::search(const VolumeID& id) const { +VolumeManager::Context* VolumeManagerObject::search(const VolumeID& id) const { Context* context = 0; VolumeID volume_id(id); volume_id &= detMask; @@ -302,7 +308,7 @@ VolumeManager VolumeManager::addSubdetector(DetElement detector, Readout ro) { "valid placement VolIDs are allowed. [Invalid DetElement:" + det_name + "]"); } - i = o.subdetectors.insert(make_pair(detector, VolumeManager(o.lcdd, detector.name()))).first; + i = o.subdetectors.insert(make_pair(detector, VolumeManager(*o.lcdd, detector.name()))).first; const PlacedVolume::VolID& id = (*vit); VolumeManager m = (*i).second; IDDescriptor::Field field = ro.idSpec().field(id.first); diff --git a/DDCore/src/Volumes.cpp b/DDCore/src/Volumes.cpp index efc289fd269b23b9a412f1ea07b7f67a8da3f820..4e6bae9adfbf3a7fd2e210147b0a8e03a529fce4 100644 --- a/DDCore/src/Volumes.cpp +++ b/DDCore/src/Volumes.cpp @@ -11,6 +11,7 @@ #include "DD4hep/Printout.h" #include "DD4hep/InstanceCount.h" #include "DD4hep/MatrixHelpers.h" +#include "DD4hep/objects/ObjectsInterna.h" // ROOT include files #include "TColor.h" @@ -285,6 +286,7 @@ template <typename T> static typename T::Object* _userExtension(const T& v) { return o; } #endif +ClassImp(PlacedVolumeExtension) static TGeoVolume* _createTGeoVolume(const string& name, TGeoShape* s, TGeoMedium* m) { geo_volume_t* e = new geo_volume_t(name.c_str(),s,m); @@ -298,25 +300,25 @@ static TGeoVolume* _createTGeoVolumeAssembly(const string& name) { } /// Default constructor -PlacedVolume::Object::Object() +PlacedVolumeExtension::PlacedVolumeExtension() : TGeoExtension(), magic(0), refCount(0), volIDs() { magic = magic_word(); INCREMENT_COUNTER; } /// Copy constructor -PlacedVolume::Object::Object(const Object& c) +PlacedVolumeExtension::PlacedVolumeExtension(const PlacedVolumeExtension& c) : TGeoExtension(), magic(c.magic), refCount(0), volIDs(c.volIDs) { INCREMENT_COUNTER; } /// Default destructor -PlacedVolume::Object::~Object() { +PlacedVolumeExtension::~PlacedVolumeExtension() { DECREMENT_COUNTER; } /// TGeoExtension overload: Method called whenever requiring a pointer to the extension -TGeoExtension* PlacedVolume::Object::Grab() { +TGeoExtension* PlacedVolumeExtension::Grab() { ++this->refCount; #ifdef ___print_vols else cout << "Placement grabbed....." << endl; @@ -325,14 +327,15 @@ TGeoExtension* PlacedVolume::Object::Grab() { } /// TGeoExtension overload: Method called always when the pointer to the extension is not needed anymore -void PlacedVolume::Object::Release() const { - Object* ext = const_cast<Object*>(this); +void PlacedVolumeExtension::Release() const { + PlacedVolumeExtension* ext = const_cast<PlacedVolumeExtension*>(this); --ext->refCount; if ( 0 == ext->refCount ) delete ext; } /// Lookup volume ID -vector<PlacedVolume::VolID>::const_iterator PlacedVolume::VolIDs::find(const string& name) const { +vector<PlacedVolumeExtension::VolID>::const_iterator +PlacedVolumeExtension::VolIDs::find(const string& name) const { for (Base::const_iterator i = this->Base::begin(); i != this->Base::end(); ++i) if (name == (*i).first) return i; @@ -340,7 +343,8 @@ vector<PlacedVolume::VolID>::const_iterator PlacedVolume::VolIDs::find(const str } /// Insert a new value into the volume ID container -std::pair<vector<PlacedVolume::VolID>::iterator, bool> PlacedVolume::VolIDs::insert(const string& name, int value) { +std::pair<vector<PlacedVolumeExtension::VolID>::iterator, bool> +PlacedVolumeExtension::VolIDs::insert(const string& name, int value) { Base::iterator i = this->Base::begin(); for (; i != this->Base::end(); ++i) if (name == (*i).first) @@ -405,14 +409,17 @@ string PlacedVolume::toString() const { return s.str(); } +/// Enable ROOT persistency +ClassImp(VolumeExtension) + /// Default constructor -Volume::Object::Object() +VolumeExtension::VolumeExtension() : TGeoExtension(), magic(0), refCount(0), region(), limits(), vis(), sens_det(), referenced(0) { INCREMENT_COUNTER; } /// Default destructor -Volume::Object::~Object() { +VolumeExtension::~VolumeExtension() { region.clear(); limits.clear(); vis.clear(); @@ -421,8 +428,8 @@ Volume::Object::~Object() { } /// TGeoExtension overload: Method called whenever requiring a pointer to the extension -TGeoExtension* Volume::Object::Grab() { - Object* ext = const_cast<Object*>(this); +TGeoExtension* VolumeExtension::Grab() { + VolumeExtension* ext = const_cast<VolumeExtension*>(this); ++ext->refCount; #ifdef ___print_vols if ( ext->sens_det.isValid() ) @@ -434,8 +441,8 @@ TGeoExtension* Volume::Object::Grab() { } /// TGeoExtension overload: Method called always when the pointer to the extension is not needed anymore -void Volume::Object::Release() const { - Object* ext = const_cast<Object*>(this); +void VolumeExtension::Release() const { + VolumeExtension* ext = const_cast<VolumeExtension*>(this); --ext->refCount; if ( 0 == ext->refCount ) { #ifdef ___print_vols @@ -445,7 +452,7 @@ void Volume::Object::Release() const { } else { #ifdef ___print_vols - cout << "Volume::Object::Release::refCount:" << ext->refCount << endl; + cout << "VolumeExtension::Release::refCount:" << ext->refCount << endl; #endif } } @@ -556,7 +563,7 @@ const Volume& Volume::setVisAttributes(const VisAttr& attr) const { VisAttr::Object* vis = attr.data<VisAttr::Object>(); Color_t bright = vis->color;//kBlue;//TColor::GetColorBright(vis->color); Color_t dark = vis->color;//kRed;//TColor::GetColorDark(vis->color); - TColor* c = (TColor*)vis->col;//gROOT->GetColor(dark); + TColor* c = vis->col;//gROOT->GetColor(dark); int draw_style = vis->drawingStyle; int line_style = vis->lineStyle; diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index 28167f429aa658e679dffaec7fef25bff1e6d5e9..b16dc646040bd2e85eb66009ba9aa01ed3d861da 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -169,7 +169,7 @@ DECLARE_XML_DOC_READER(lccdd,create_Compact) */ template <> void Converter<Constant>::operator()(xml_h e) const { xml_ref_t constant(e); - TNamed* obj = new TNamed(constant.attr < string > (_U(name)).c_str(), constant.attr < string > (_U(value)).c_str()); + NamedObject* obj = new NamedObject(constant.attr < string > (_U(name)).c_str(), constant.attr < string > (_U(value)).c_str()); Ref_t cons(obj); _toDictionary(obj->GetName(), obj->GetTitle()); lcdd.addConstant(cons); @@ -555,10 +555,10 @@ template <> void Converter<CartesianField>::operator()(xml_h e) const { CartesianField field = lcdd.field(name); if (!field.isValid()) { // The field is not present: We create it and add it to LCDD - field = Ref_t(PluginService::Create<TNamed*>(type, &lcdd, &e)); + field = Ref_t(PluginService::Create<NamedObject*>(type, &lcdd, &e)); if (!field.isValid()) { PluginDebug dbg; - PluginService::Create<TNamed*>(type, &lcdd, &e); + PluginService::Create<NamedObject*>(type, &lcdd, &e); throw_print("Failed to create field object of type " + type + ". " + dbg.missingFactory(type)); } lcdd.addField(field); @@ -699,7 +699,7 @@ template <> void Converter<DetElement>::operator()(xml_h element) const { lcdd.addSensitiveDetector(sd); } Ref_t sens = sd; - DetElement det(Ref_t(PluginService::Create<TNamed*>(type, &lcdd, &element, &sens))); + DetElement det(Ref_t(PluginService::Create<NamedObject*>(type, &lcdd, &element, &sens))); if (det.isValid()) { setChildTitles(make_pair(name, det)); } @@ -709,7 +709,7 @@ template <> void Converter<DetElement>::operator()(xml_h element) const { if (!det.isValid()) { PluginDebug dbg; - PluginService::Create<TNamed*>(type, &lcdd, &element, &sens); + PluginService::Create<NamedObject*>(type, &lcdd, &element, &sens); throw runtime_error("Failed to execute subdetector creation plugin. " + dbg.missingFactory(type)); } lcdd.addDetector(det); diff --git a/DDCore/src/plugins/LCDDConverter.cpp b/DDCore/src/plugins/LCDDConverter.cpp index 44e07f40f36fe2e07389592c2d286ca5c14db61c..b96161768491dc4de5bd170eac4af7c4cf1a211b 100644 --- a/DDCore/src/plugins/LCDDConverter.cpp +++ b/DDCore/src/plugins/LCDDConverter.cpp @@ -12,6 +12,7 @@ #include "DD4hep/Volumes.h" #include "DD4hep/FieldTypes.h" #include "DD4hep/Segmentations.h" +#include "DD4hep/objects/ObjectsInterna.h" #include "DD4hep/objects/DetectorInterna.h" #include "XML/DocumentHandler.h" #include "LCDDConverter.h" @@ -87,7 +88,7 @@ namespace { Volume v = Ref_t(volume); return v.data() != 0; } - bool is_placement(const TGeoNode* node) { + bool is_placement(PlacedVolume node) { PlacedVolume v = Ref_t(node); return v.data() != 0; } @@ -114,7 +115,7 @@ LCDDConverter::~LCDDConverter() { } /// Dump element in GDML format to output stream -xml_h LCDDConverter::handleElement(const string& /* name */, const TGeoElement* element) const { +xml_h LCDDConverter::handleElement(const string& /* name */, Atom element) const { GeometryInfo& geo = data(); xml_h e = geo.xmlElements[element]; if (!e) { @@ -133,7 +134,7 @@ xml_h LCDDConverter::handleElement(const string& /* name */, const TGeoElement* } /// Dump material in GDML format to output stream -xml_h LCDDConverter::handleMaterial(const string& name, const TGeoMedium* medium) const { +xml_h LCDDConverter::handleMaterial(const string& name, Material medium) const { GeometryInfo& geo = data(); xml_h mat = geo.xmlMaterials[medium]; if (!mat) { @@ -160,7 +161,7 @@ xml_h LCDDConverter::handleMaterial(const string& name, const TGeoMedium* medium double sum = 0e0; for (int i = 0, n = mix->GetNelements(); i < n; i++) { TGeoElement *elt = mix->GetElement(i); - handleElement(elt->GetName(), elt); + handleElement(elt->GetName(), Atom(elt)); sum += wmix[i]; } for (int i = 0, n = mix->GetNelements(); i < n; i++) { @@ -181,7 +182,7 @@ xml_h LCDDConverter::handleMaterial(const string& name, const TGeoMedium* medium TGeoElement *elt = m->GetElement(0); cout << "Converting non mixing material:" << name << endl; xml_elt_t atom(geo.doc, _U(atom)); - handleElement(elt->GetName(), elt); + handleElement(elt->GetName(), Atom(elt)); mat.append(atom); mat.setAttr(_U(Z), m->GetZ()); atom.setAttr(_U(type), "A"); @@ -598,7 +599,7 @@ xml_h LCDDConverter::handleRotation(const std::string& name, const TGeoMatrix* t } /// Dump logical volume in GDML format to output stream -xml_h LCDDConverter::handleVolume(const string& name, const TGeoVolume* volume) const { +xml_h LCDDConverter::handleVolume(const string& name, Volume volume) const { GeometryInfo& geo = data(); xml_h vol = geo.xmlVolumes[volume]; if (!vol) { @@ -624,7 +625,7 @@ xml_h LCDDConverter::handleVolume(const string& name, const TGeoVolume* volume) vol.setAttr(_U(name), n); if (m) { string mat_name = m->GetName(); - xml_ref_t med = handleMaterial(mat_name, m); + xml_ref_t med = handleMaterial(mat_name, Material(m)); vol.setRef(_U(materialref), med.name()); } vol.setRef(_U(solidref), sol.name()); @@ -644,19 +645,19 @@ xml_h LCDDConverter::handleVolume(const string& name, const TGeoVolume* volume) VisAttr vis = _v.visAttributes(); SensitiveDetector det = _v.sensitiveDetector(); if (det.isValid()) { - xml_ref_t data = handleSensitive(det.name(), det.ptr()); + xml_ref_t data = handleSensitive(det.name(), det); vol.setRef(_U(sdref), data.name()); } if (reg.isValid()) { - xml_ref_t data = handleRegion(reg.name(), reg.ptr()); + xml_ref_t data = handleRegion(reg.name(), reg); vol.setRef(_U(regionref), data.name()); } if (lim.isValid()) { - xml_ref_t data = handleLimitSet(lim.name(), lim.ptr()); + xml_ref_t data = handleLimitSet(lim.name(), lim); vol.setRef(_U(limitsetref), data.name()); } if (vis.isValid()) { - xml_ref_t data = handleVis(vis.name(), vis.ptr()); + xml_ref_t data = handleVis(vis.name(), vis); vol.setRef(_U(visref), data.name()); } } @@ -676,7 +677,7 @@ xml_h LCDDConverter::handleVolumeVis(const string& /* name */, const TGeoVolume* if (vis.isValid()) { geo.doc_structure.append(vol = xml_elt_t(geo.doc, _U(volume))); vol.setAttr(_U(name), v->GetName()); - xml_ref_t data = handleVis(vis.name(), vis.ptr()); + xml_ref_t data = handleVis(vis.name(), vis); vol.setRef(_U(visref), data.name()); geo.xmlVolumes[v] = vol; } @@ -694,23 +695,22 @@ void LCDDConverter::collectVolume(const string& /* name */, const TGeoVolume* vo LimitSet lim = v.limitSet(); SensitiveDetector det = v.sensitiveDetector(); if (lim.isValid()) - geo.limits.insert(lim.ptr()); + geo.limits.insert(lim); if (reg.isValid()) - geo.regions.insert(reg.ptr()); + geo.regions.insert(reg); if (det.isValid()) - geo.sensitives.insert(det.ptr()); + geo.sensitives.insert(det); } else { cout << "LCDDConverter::collectVolume: Skip volume:" << volume->GetName() << endl; } } -void LCDDConverter::checkVolumes(const string& name, const TGeoVolume* volume) const { +void LCDDConverter::checkVolumes(const string& name, Volume v) const { NameSet::const_iterator i = m_checkNames.find(name); if (i != m_checkNames.end()) { - Volume v = Ref_t(volume); cout << "checkVolumes: Volume " << name << " "; - if (is_volume(volume)) { + if (is_volume(v.ptr())) { SensitiveDetector s = v.sensitiveDetector(); VisAttr vis = v.visAttributes(); if (s.isValid()) { @@ -727,7 +727,7 @@ void LCDDConverter::checkVolumes(const string& name, const TGeoVolume* volume) c } /// Dump volume placement in GDML format to output stream -xml_h LCDDConverter::handlePlacement(const string& name, const TGeoNode* node) const { +xml_h LCDDConverter::handlePlacement(const string& name,PlacedVolume node) const { GeometryInfo& geo = data(); xml_h place = geo.xmlPlacements[node]; if (!place) { @@ -743,9 +743,9 @@ xml_h LCDDConverter::handlePlacement(const string& name, const TGeoNode* node) c place.setRef(_U(volumeref), vol.name()); if (m) { char text[32]; - ::snprintf(text, sizeof(text), "_%p_pos", (void*)node); + ::snprintf(text, sizeof(text), "_%p_pos", (void*)node.ptr()); xml_ref_t pos = handlePosition(name + text, m); - ::snprintf(text, sizeof(text), "_%p_rot", (void*)node); + ::snprintf(text, sizeof(text), "_%p_rot", (void*)node.ptr()); place.setRef(_U(positionref), pos.name()); if ( m->IsRotation() ) { xml_ref_t rot = handleRotation(name + text, m); @@ -754,8 +754,7 @@ xml_h LCDDConverter::handlePlacement(const string& name, const TGeoNode* node) c } if (geo.doc_root.tag() != "gdml") { if (is_placement(node)) { - PlacedVolume p = Ref_t(node); - const PlacedVolume::VolIDs& ids = p.volIDs(); + const PlacedVolume::VolIDs& ids = node.volIDs(); for (PlacedVolume::VolIDs::const_iterator i = ids.begin(); i != ids.end(); ++i) { xml_h pvid = xml_elt_t(geo.doc, _U(physvolid)); pvid.setAttr(_U(field_name), (*i).first); @@ -773,28 +772,26 @@ xml_h LCDDConverter::handlePlacement(const string& name, const TGeoNode* node) c } /// Convert the geometry type region into the corresponding LCDD object(s). -xml_h LCDDConverter::handleRegion(const std::string& /* name */, const TNamed* region) const { +xml_h LCDDConverter::handleRegion(const std::string& /* name */, Region region) const { GeometryInfo& geo = data(); xml_h reg = geo.xmlRegions[region]; if (!reg) { - Region r = Ref_t(region); geo.doc_regions.append(reg = xml_elt_t(geo.doc, _U(region))); - reg.setAttr(_U(name), r.name()); - reg.setAttr(_U(cut), r.cut()); - reg.setAttr(_U(eunit), r.energyUnit()); - reg.setAttr(_U(lunit), r.lengthUnit()); - reg.setAttr(_U(store_secondaries), r.storeSecondaries()); + reg.setAttr(_U(name), region.name()); + reg.setAttr(_U(cut), region.cut()); + reg.setAttr(_U(eunit), region.energyUnit()); + reg.setAttr(_U(lunit), region.lengthUnit()); + reg.setAttr(_U(store_secondaries), region.storeSecondaries()); geo.xmlRegions[region] = reg; } return reg; } /// Convert the geometry type LimitSet into the corresponding LCDD object(s) -xml_h LCDDConverter::handleLimitSet(const std::string& /* name */, const TNamed* limitset) const { +xml_h LCDDConverter::handleLimitSet(const std::string& /* name */, LimitSet lim) const { GeometryInfo& geo = data(); - xml_h xml = geo.xmlLimits[limitset]; + xml_h xml = geo.xmlLimits[lim]; if (!xml) { - LimitSet lim = Ref_t(limitset); geo.doc_limits.append(xml = xml_elt_t(geo.doc, _U(limitset))); xml.setAttr(_U(name), lim.name()); const set<Limit>& obj = lim.limits(); @@ -807,7 +804,7 @@ xml_h LCDDConverter::handleLimitSet(const std::string& /* name */, const TNamed* x.setAttr(_U(value), l.value); x.setAttr(_U(particles), l.particles); } - geo.xmlLimits[limitset] = xml; + geo.xmlLimits[lim] = xml; } return xml; } @@ -845,11 +842,10 @@ xml_h LCDDConverter::handleSegmentation(Segmentation seg) const { } /// Convert the geometry type SensitiveDetector into the corresponding LCDD object(s). -xml_h LCDDConverter::handleSensitive(const string& /* name */, const TNamed* sens_det) const { +xml_h LCDDConverter::handleSensitive(const string& /* name */, SensitiveDetector sd) const { GeometryInfo& geo = data(); - xml_h sensdet = geo.xmlSensDets[sens_det]; + xml_h sensdet = geo.xmlSensDets[sd]; if (!sensdet) { - SensitiveDetector sd = Ref_t(sens_det); geo.doc_detectors.append(sensdet = xml_elt_t(geo.doc, Unicode(sd.type()))); sensdet.setAttr(_U(name), sd.name()); sensdet.setAttr(_U(ecut), sd.energyCutoff()); @@ -860,19 +856,19 @@ xml_h LCDDConverter::handleSensitive(const string& /* name */, const TNamed* sen sensdet.setAttr(_U(combine_hits), sd.combineHits()); Readout ro = sd.readout(); if (ro.isValid()) { - xml_ref_t ref = handleIdSpec(ro.idSpec().name(), ro.idSpec().ptr()); + xml_ref_t ref = handleIdSpec(ro.idSpec().name(), ro.idSpec()); sensdet.setRef(_U(idspecref), ref.name()); xml_h seg = handleSegmentation(ro.segmentation()); if (seg) sensdet.append(seg); } - geo.xmlSensDets[sens_det] = sensdet; + geo.xmlSensDets[sd] = sensdet; } return sensdet; } /// Convert the geometry id dictionary entry to the corresponding Xml object(s). -xml_h LCDDConverter::handleIdSpec(const std::string& name, const TNamed* id_spec) const { +xml_h LCDDConverter::handleIdSpec(const std::string& name, IDDescriptor id_spec) const { GeometryInfo& geo = data(); xml_h id = geo.xmlIdSpecs[id_spec]; if (!id) { @@ -907,12 +903,11 @@ xml_h LCDDConverter::handleIdSpec(const std::string& name, const TNamed* id_spec } /// Convert the geometry visualisation attributes to the corresponding LCDD object(s). -xml_h LCDDConverter::handleVis(const string& /* name */, const TNamed* v) const { +xml_h LCDDConverter::handleVis(const string& /* name */, VisAttr attr) const { GeometryInfo& geo = data(); - xml_h vis = geo.xmlVis[v]; + xml_h vis = geo.xmlVis[attr]; if (!vis) { float r = 0, g = 0, b = 0; - VisAttr attr = Ref_t(v); int style = attr.lineStyle(); int draw = attr.drawingStyle(); @@ -936,13 +931,13 @@ xml_h LCDDConverter::handleVis(const string& /* name */, const TNamed* v) const col.setAttr(_U(G), g); col.setAttr(_U(B), b); vis.append(col); - geo.xmlVis[v] = vis; + geo.xmlVis[attr] = vis; } return vis; } /// Convert the electric or magnetic fields into the corresponding Xml object(s). -xml_h LCDDConverter::handleField(const std::string& /* name */, const TNamed* f) const { +xml_h LCDDConverter::handleField(const std::string& /* name */, OverlayedField f) const { GeometryInfo& geo = data(); xml_h field = geo.xmlFields[f]; if (!field) { @@ -1195,7 +1190,7 @@ xml_doc_t LCDDConverter::createLCDD(DetElement top) { // Ensure that all required materials are present in the LCDD material table const LCDD::HandleMap& fld = lcdd.fields(); for (LCDD::HandleMap::const_iterator i = fld.begin(); i != fld.end(); ++i) - geo.fields.insert((*i).second.ptr()); + geo.fields.insert((*i).second); cout << "++ ==> Converting in memory detector description to LCDD format..." << endl; handleHeader(); diff --git a/DDCore/src/plugins/LCDDConverter.h b/DDCore/src/plugins/LCDDConverter.h index 2c0e5c980409e331b9c241575b379efa3bda63d2..d607749953b5999357373f2f39cc36108fa29a09 100644 --- a/DDCore/src/plugins/LCDDConverter.h +++ b/DDCore/src/plugins/LCDDConverter.h @@ -49,17 +49,17 @@ namespace DD4hep { */ struct LCDDConverter: public GeoHandler { typedef XML::XmlElement XmlElement; - typedef std::map<const TGeoElement*, XmlElement*> ElementMap; - typedef std::map<const TGeoMedium*, XmlElement*> MaterialMap; - typedef std::map<const TNamed*, XmlElement*> LimitMap; - typedef std::map<const TGeoNode*, XmlElement*> PlacementMap; - typedef std::map<const TNamed*, XmlElement*> RegionMap; - typedef std::map<const TNamed*, XmlElement*> SensDetMap; - typedef std::map<const TGeoVolume*, XmlElement*> VolumeMap; - typedef std::map<const TGeoShape*, XmlElement*> SolidMap; - typedef std::map<const TNamed*, XmlElement*> VisMap; - typedef std::map<const TNamed*, XmlElement*> FieldMap; - typedef std::map<const TNamed*, XmlElement*> IdSpecMap; + typedef std::map<Atom, XmlElement*> ElementMap; + typedef std::map<Material, XmlElement*> MaterialMap; + typedef std::map<LimitSet, XmlElement*> LimitMap; + typedef std::map<PlacedVolume, XmlElement*> PlacementMap; + typedef std::map<Region, XmlElement*> RegionMap; + typedef std::map<SensitiveDetector, XmlElement*> SensDetMap; + typedef std::map<Volume, XmlElement*> VolumeMap; + typedef std::map<IDDescriptor, XmlElement*> IdSpecMap; + typedef std::map<VisAttr, XmlElement*> VisMap; + typedef std::map<const TGeoShape*, XmlElement*> SolidMap; + typedef std::map<OverlayedField, XmlElement*> FieldMap; typedef std::map<const TGeoMatrix*, XmlElement*> TrafoMap; struct GeometryInfo: public GeoHandler::GeometryInfo { ElementMap xmlElements; @@ -75,9 +75,9 @@ namespace DD4hep { TrafoMap xmlPositions; TrafoMap xmlRotations; FieldMap xmlFields; - ObjectSet sensitives; - ObjectSet regions; - ObjectSet limits; + SensitiveDetectorSet sensitives; + RegionSet regions; + LimitSetSet limits; // These we need for redundancy and checking the data integrity typedef std::map<std::string, const TNamed*> CheckIter; struct _checks { @@ -97,8 +97,8 @@ namespace DD4hep { void checkShape(const std::string& name, const TNamed* n) const { check(name, n, checks.solids); } - void checkMaterial(const std::string& name, const TNamed* n) const { - check(name, n, checks.materials); + void checkMaterial(const std::string& name, Material n) const { + check(name, n.ptr(), checks.materials); } xml_doc_t doc; @@ -119,7 +119,7 @@ namespace DD4hep { } /// Data integrity checker - void checkVolumes(const std::string& name, const TGeoVolume* volume) const; + void checkVolumes(const std::string& name, Volume volume) const; /// Initializing Constructor LCDDConverter(LCDD& lcdd); @@ -140,39 +140,39 @@ namespace DD4hep { virtual void handleHeader() const; /// Convert the geometry type material into the corresponding Xml object(s). - virtual xml_h handleMaterial(const std::string& name, const TGeoMedium* medium) const; + virtual xml_h handleMaterial(const std::string& name, Material medium) const; /// Convert the geometry type element into the corresponding Xml object(s). - virtual xml_h handleElement(const std::string& name, const TGeoElement* element) const; + virtual xml_h handleElement(const std::string& name, Atom element) const; /// Convert the geometry type solid into the corresponding Xml object(s). virtual xml_h handleSolid(const std::string& name, const TGeoShape* volume) const; /// Convert the geometry type logical volume into the corresponding Xml object(s). - virtual xml_h handleVolume(const std::string& name, const TGeoVolume* volume) const; + virtual xml_h handleVolume(const std::string& name, Volume volume) const; virtual xml_h handleVolumeVis(const std::string& name, const TGeoVolume* volume) const; virtual void collectVolume(const std::string& name, const TGeoVolume* volume) const; /// Convert the geometry type volume placement into the corresponding Xml object(s). - virtual xml_h handlePlacement(const std::string& name, const TGeoNode* node) const; + virtual xml_h handlePlacement(const std::string& name, PlacedVolume node) const; /// Convert the geometry type field into the corresponding Xml object(s). ///virtual xml_h handleField(const std::string& name, Ref_t field) const; /// Convert the geometry type region into the corresponding Xml object(s). - virtual xml_h handleRegion(const std::string& name, const TNamed* region) const; + virtual xml_h handleRegion(const std::string& name, Region region) const; /// Convert the geometry visualisation attributes to the corresponding Xml object(s). - virtual xml_h handleVis(const std::string& name, const TNamed* vis) const; + virtual xml_h handleVis(const std::string& name, VisAttr vis) const; /// Convert the geometry id dictionary entry to the corresponding Xml object(s). - virtual xml_h handleIdSpec(const std::string& name, const TNamed* vis) const; + virtual xml_h handleIdSpec(const std::string& name, IDDescriptor idspec) const; /// Convert the geometry type LimitSet into the corresponding Xml object(s). - virtual xml_h handleLimitSet(const std::string& name, const TNamed* limitset) const; + virtual xml_h handleLimitSet(const std::string& name, LimitSet limitset) const; /// Convert the geometry type SensitiveDetector into the corresponding Xml object(s). - virtual xml_h handleSensitive(const std::string& name, const TNamed* sens_det) const; + virtual xml_h handleSensitive(const std::string& name, SensitiveDetector sens_det) const; /// Convert the segmentation of a SensitiveDetector into the corresponding LCDD object virtual xml_h handleSegmentation(Segmentation seg) const; @@ -184,7 +184,7 @@ namespace DD4hep { virtual xml_h handleRotation(const std::string& name, const TGeoMatrix* trafo) const; /// Convert the electric or magnetic fields into the corresponding Xml object(s). - virtual xml_h handleField(const std::string& name, const TNamed* field) const; + virtual xml_h handleField(const std::string& name, OverlayedField field) const; /// Handle the geant 4 specific properties void handleProperties(LCDD::Properties& prp) const; diff --git a/DDCore/src/plugins/StandardPlugins.cpp b/DDCore/src/plugins/StandardPlugins.cpp index 34df0d87fab3adae5418ec1324c4dbea412e808f..cbadfeb4091695d4d631c5672110b32d69d20367 100644 --- a/DDCore/src/plugins/StandardPlugins.cpp +++ b/DDCore/src/plugins/StandardPlugins.cpp @@ -19,6 +19,8 @@ #include "TGeoManager.h" #include "TGeoVolume.h" +#include <fstream> + using namespace std; using namespace DD4hep; using namespace DD4hep::Geometry; @@ -131,7 +133,7 @@ static long dump_geometry(LCDD& lcdd, int argc, char** argv) { return 0; } DECLARE_APPLY(DD4hepGeometry2Root,dump_geometry) - +#include "DD4hep/DetectorTools.h" /** Basic entry point to print out the volume hierarchy * * @author M.Frank @@ -139,15 +141,31 @@ DECLARE_APPLY(DD4hepGeometry2Root,dump_geometry) * @date 01/04/2014 */ static long dump_volume_tree(LCDD& lcdd, int , char** ) { - struct Actor { static long dump(TGeoNode* node,int level) { - char fmt[64]; - ::sprintf(fmt,"%03d %%-%ds %%s",level+1,2*level+1); - printout(INFO,"+++",fmt,"",node->GetName()); - for (Int_t idau = 0, ndau = node->GetNdaughters(); idau < ndau; ++idau) - Actor::dump(node->GetDaughter(idau),level+1); + struct Actor { static long dump(TGeoNode* ideal, TGeoNode* aligned,int level) { + char fmt[256]; + if ( ideal == aligned ) { + ::snprintf(fmt,sizeof(fmt),"%03d %%-%ds %%s \t\tNode:%p",level+1,2*level+1,(void*)ideal); + } + else { + ::snprintf(fmt,sizeof(fmt),"%03d %%-%ds %%s Ideal node:%p Aligned node:%p", + level+1,2*level+1,(void*)ideal,(void*)aligned); + } + printout(INFO,"+++",fmt,"",aligned->GetName()); + TGeoVolume* volume = ideal->GetVolume(); + for (Int_t idau = 0, ndau = aligned->GetNdaughters(); idau < ndau; ++idau) { + TGeoNode* ideal_daughter = ideal->GetDaughter(idau); + const char* daughter_name = ideal_daughter->GetName(); + TGeoNode* aligned_daughter = volume->GetNode(daughter_name); + Actor::dump(ideal_daughter,aligned_daughter,level+1); + } return 1; }}; - return Actor::dump(lcdd.world().placement().ptr(),0); + string place = lcdd.world().placementPath(); + DetectorTools::PlacementPath path; + DetectorTools::placementPath(lcdd.world(), path); + PlacedVolume pv = DetectorTools::findNode(lcdd.world().placement(),place); + return Actor::dump(lcdd.world().placement().ptr(),pv.ptr(),0); + //return Actor::dump(lcdd.manager().GetTopNode(),pv.ptr(),0); } DECLARE_APPLY(DD4hepVolumeDump,dump_volume_tree) @@ -197,3 +215,29 @@ static long detelement_cache(LCDD& lcdd, int , char** ) { return Actor::cache(lcdd.world()); } DECLARE_APPLY(DD4hepDetElementCache,detelement_cache) + +#include "../GeometryTreeDump.h" +static long exec_GeometryTreeDump(LCDD& lcdd, int, char** ) { + GeometryTreeDump dmp; + dmp.create(lcdd.world()); + return 1; +} +DECLARE_APPLY(DD4hepGeometryTreeDump,exec_GeometryTreeDump) + +#include "../SimpleGDMLWriter.h" +static long exec_SimpleGDMLWriter(LCDD& lcdd, int argc, char** argv) { + if ( argc > 1 ) { + string output = argv[1]; + ofstream out(output.c_str()+1,ios_base::out); + SimpleGDMLWriter dmp(out); + dmp.create(lcdd.world()); + } + else { + SimpleGDMLWriter dmp(cout); + dmp.create(lcdd.world()); + } + return 1; +} + +DECLARE_APPLY(DD4hepSimpleGDMLWriter,exec_SimpleGDMLWriter) + diff --git a/DDG4/CMakeLists.txt b/DDG4/CMakeLists.txt index 5ffa70d7cc4cb5cd6dfe8ba1ffa9234437f8994b..beacc10776579d3aa6c334ce9b3b6cfba1e5207e 100644 --- a/DDG4/CMakeLists.txt +++ b/DDG4/CMakeLists.txt @@ -38,6 +38,9 @@ endif() SET( CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Wno-long-long") #--------------------------- Main geant4 interface library (no plugins!)----------- +root_generate_dictionary( G__DDG4 ${CMAKE_CURRENT_SOURCE_DIR}/python/DDG4Dict.C LINKDEF ${CMAKE_SOURCE_DIR}/DDCore/include/ROOT/LinkDef.h) +list(APPEND sources G__DDG4.cxx) +# add_library(DD4hepG4 SHARED ${sources}) target_link_libraries(DD4hepG4 DD4hepCore ${ROOT_LIBRARIES} Reflex ${Geant4_LIBRARIES}) SET_TARGET_PROPERTIES( DD4hepG4 PROPERTIES VERSION ${DD4hep_VERSION} SOVERSION ${DD4hep_SOVERSION}) diff --git a/DDG4/examples/dictionaries.C b/DDG4/examples/dictionaries.C index 8be7edf5a70d2c3727c0e4db04ac1845e6a23dae..6a2afdd136269e91dc012e1a660d0c442c78a1a6 100644 --- a/DDG4/examples/dictionaries.C +++ b/DDG4/examples/dictionaries.C @@ -9,7 +9,7 @@ // Author : M.Frank // //==================================================================== -// FRamework include files +// Framework include files #include "DDG4/Geant4Data.h" #include <vector> diff --git a/DDG4/include/DDG4/Geant4Converter.h b/DDG4/include/DDG4/Geant4Converter.h index aff071739db5274a46dc3de8625a6f821426372f..14a309b15ef2400adb1785f79459753df0909e32 100644 --- a/DDG4/include/DDG4/Geant4Converter.h +++ b/DDG4/include/DDG4/Geant4Converter.h @@ -48,10 +48,10 @@ namespace DD4hep { Geant4Converter& create(DetElement top); /// Convert the geometry type material into the corresponding Geant4 object(s). - virtual void* handleMaterial(const std::string& name, const TGeoMedium* medium) const; + virtual void* handleMaterial(const std::string& name, Material medium) const; /// Convert the geometry type element into the corresponding Geant4 object(s). - virtual void* handleElement(const std::string& name, const TGeoElement* element) const; + virtual void* handleElement(const std::string& name, Atom element) const; /// Convert the geometry type solid into the corresponding Geant4 object(s). virtual void* handleSolid(const std::string& name, const TGeoShape* volume) const; @@ -68,22 +68,22 @@ namespace DD4hep { ///virtual void* handleField(const std::string& name, Ref_t field) const; /// Convert the geometry type region into the corresponding Geant4 object(s). - virtual void* handleRegion(const TNamed* region, const std::set<const TGeoVolume*>& volumes) const; + virtual void* handleRegion(Region region, const std::set<const TGeoVolume*>& volumes) const; /// Convert the geometry visualisation attributes to the corresponding Geant4 object(s). - virtual void* handleVis(const std::string& name, const TNamed* vis) const; + virtual void* handleVis(const std::string& name, VisAttr vis) const; /// Convert the geometry type LimitSet into the corresponding Geant4 object(s). - virtual void* handleLimitSet(const TNamed* limitset, const std::set<const TGeoVolume*>& volumes) const; + virtual void* handleLimitSet(LimitSet limitset, const std::set<const TGeoVolume*>& volumes) const; /// Convert the geometry type SensitiveDetector into the corresponding Geant4 object(s). - virtual void* handleSensitive(const TNamed* sens_det, const std::set<const TGeoVolume*>& volumes) const; + virtual void* handleSensitive(SensitiveDetector sens_det, const std::set<const TGeoVolume*>& volumes) const; /// Handle the geant 4 specific properties void handleProperties(LCDD::Properties& prp) const; /// Print the geometry type SensitiveDetector - virtual void* printSensitive(const TNamed* sens_det, const std::set<const TGeoVolume*>& volumes) const; + virtual void* printSensitive(SensitiveDetector sens_det, const std::set<const TGeoVolume*>& volumes) const; /// Print Geant4 placement virtual void* printPlacement(const std::string& name, const TGeoNode* node) const; }; diff --git a/DDG4/include/DDG4/Geant4GeometryInfo.h b/DDG4/include/DDG4/Geant4GeometryInfo.h index 7d31e27c912037dbf7b3a0084e3a2e004013f842..6c024e053de13298cabd62e4461719e0e6f31cd5 100644 --- a/DDG4/include/DDG4/Geant4GeometryInfo.h +++ b/DDG4/include/DDG4/Geant4GeometryInfo.h @@ -10,6 +10,7 @@ #define DD4HEP_DDG4_GEANT4GEOMETRYINFO_H // Framework include files +#include "DD4hep/Objects.h" #include "DD4hep/GeoHandler.h" #include "DDG4/Geant4Primitives.h" @@ -50,22 +51,31 @@ namespace DD4hep { class Geant4AssemblyVolume; namespace Geant4GeometryMaps { + typedef Geometry::Atom Atom; + typedef Geometry::Material Material; + typedef Geometry::VisAttr VisAttr; + typedef Geometry::Volume Volume; + typedef Geometry::PlacedVolume PlacedVolume; + typedef Geometry::Region Region; + typedef Geometry::LimitSet LimitSet; + typedef Geometry::SensitiveDetector SensitiveDetector; + typedef std::vector<const G4VPhysicalVolume*> Geant4PlacementPath; - typedef std::map<const TGeoElement*, G4Element*> ElementMap; - typedef std::map<const TGeoMedium*, G4Material*> MaterialMap; - typedef std::map<const TNamed*, G4UserLimits*> LimitMap; - typedef std::map<const TGeoNode*, G4VPhysicalVolume*> PlacementMap; - typedef std::map<const TNamed*, G4Region*> RegionMap; - typedef std::map<const TNamed*, G4VSensitiveDetector*> SensDetMap; - typedef std::map<const TGeoVolume*, G4LogicalVolume*> VolumeMap; - typedef std::map<const TGeoNode*, Geant4AssemblyVolume*> AssemblyMap; + typedef std::map<Atom, G4Element*> ElementMap; + typedef std::map<Material, G4Material*> MaterialMap; + typedef std::map<LimitSet, G4UserLimits*> LimitMap; + typedef std::map<PlacedVolume, G4VPhysicalVolume*> PlacementMap; + typedef std::map<Region, G4Region*> RegionMap; + typedef std::map<SensitiveDetector, G4VSensitiveDetector*> SensDetMap; + typedef std::map<Volume, G4LogicalVolume*> VolumeMap; + typedef std::map<PlacedVolume, Geant4AssemblyVolume*> AssemblyMap; typedef std::vector<const TGeoNode*> VolumeChain; typedef std::pair<VolumeChain,const G4VPhysicalVolume*> ImprintEntry; typedef std::vector<ImprintEntry> Imprints; - typedef std::map<const TGeoVolume*,Imprints> VolumeImprintMap; + typedef std::map<Volume,Imprints> VolumeImprintMap; typedef std::map<const TGeoShape*, G4VSolid*> SolidMap; - typedef std::map<const TNamed*, G4VisAttributes*> VisMap; + typedef std::map<VisAttr, G4VisAttributes*> VisMap; typedef std::map<Geant4PlacementPath, VolumeID> Geant4PathMap; typedef Geometry::GeoHandlerTypes::SensitiveVolumes SensitiveVolumes; diff --git a/DDG4/include/DDG4/Geant4Mapping.h b/DDG4/include/DDG4/Geant4Mapping.h index d14343c642e68ebdec0de7b1c0e4132b9ba955b0..46fdcf4df10b3a162eedf14626750248a0519586 100644 --- a/DDG4/include/DDG4/Geant4Mapping.h +++ b/DDG4/include/DDG4/Geant4Mapping.h @@ -40,8 +40,11 @@ namespace DD4hep { typedef Geometry::Solid Solid; typedef Geometry::Volume Volume; typedef Geometry::PlacedVolume PlacedVolume; + typedef Geometry::Atom Atom; typedef Geometry::Material Material; typedef Geometry::Region Region; + typedef Geometry::VisAttr VisAttr; + typedef Geometry::LimitSet LimitSet; protected: LCDD& m_lcdd; diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index e0e47ee7777e95c055943b42375d5e4b134e0793..6d33d1e878588a4dd8edd723f012dd50cf7961cc 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -26,6 +26,18 @@ def compileAClick(dictionary,g4=True): from ROOT import DD4hep as module return module +def loadDDG4(): + from ROOT import gSystem + import os.path + result = gSystem.Load("libDD4hepCore") + if 0 != result: + raise Exception('DDG4.py: Failed to load the Geant4 library libDD4hepCore: '+gSystem.GetErrorStr()) + result = gSystem.Load("libDD4hepG4") + if 0 != result: + raise Exception('DDG4.py: Failed to load the Geant4 library libDD4hepG4: '+gSystem.GetErrorStr()) + from ROOT import DD4hep as module + return module + # We are nearly there .... current = __import__(__name__) def _import_class(ns,nam): @@ -33,7 +45,17 @@ def _import_class(ns,nam): setattr(current,nam,getattr(scope,nam)) #--------------------------------------------------------------------------- -DD4hep = compileAClick(dictionary='DDG4Dict.C',g4=True) +# +try: + DD4hep = loadDDG4() +except Exception,X: + print '+--%-100s--+'%(100*'-',) + print '| %-100s |'%('Failed to load DDG4 library:',) + print '| %-100s |'%(str(X),) + print '| %-100s |'%('Try to compile AClick on the fly.',) + print '+--%-100s--+'%(100*'-',) + DD4hep = compileAClick(dictionary='DDG4Dict.C',g4=True) +Core = DD4hep Sim = DD4hep.Simulation Simulation = DD4hep.Simulation @@ -173,6 +195,10 @@ _props('PhysicsListActionSequenceHandle') _props('SensDetActionSequenceHandle') _props('Geant4PhysicsListActionSequence') + +#--------------------------------------------------------------------------- +_import_class('Core','NamedObject') + #--------------------------------------------------------------------------- Geo = DD4hep.Geometry Geometry = DD4hep.Geometry diff --git a/DDG4/python/DDG4Dict.C b/DDG4/python/DDG4Dict.C index 4caaba73558797bcae98050823e06c8912caf2e5..fff56b40bc3f93c8df0e44f475169f3619ddb84f 100644 --- a/DDG4/python/DDG4Dict.C +++ b/DDG4/python/DDG4Dict.C @@ -206,7 +206,6 @@ typedef DD4hep::Simulation::Geant4ActionCreation Geant4ActionCreation; #pragma link C++ class PhysicsListActionSequenceHandle; #pragma link C++ class SensDetActionSequenceHandle; - #pragma link C++ class Geant4ActionCreation; #pragma link C++ class Geant4Action; #pragma link C++ class Geant4Kernel; @@ -238,122 +237,9 @@ typedef DD4hep::Simulation::Geant4ActionCreation Geant4ActionCreation; #pragma link C++ class Geant4ActionSD; #pragma link C++ class Geant4Sensitive; #pragma link C++ class Geant4SensDetActionSequence; - #pragma link C++ class Geant4ActionPhase; - #endif - -using namespace DD4hep::Geometry; - -// CINT configuration for DD4hep -#if defined(__MAKECINT__) - -//#pragma link C++ class Handle<TObject>; -#pragma link C++ class ObjectExtensions; - -#pragma link C++ class Handle<TNamed>; -#pragma link C++ class LCDD::HandleMap; -#pragma link C++ class LCDD::HandleMap::iterator; -#pragma link C++ class LCDD::HandleMap::const_iterator; -#pragma link C++ class LCDD::HandleMap::key_type; -#pragma link C++ class LCDD::HandleMap::value_type; -#pragma link C++ class LCDD::PropertyValues; -#pragma link C++ class LCDD::Properties; -#pragma link C++ class LCDD; -#pragma link C++ class VolumeManager; -#pragma link C++ class OverlayedField; - -// Objects.h -#pragma link C++ class Author; -#pragma link C++ class Header; -#pragma link C++ class Constant; -#pragma link C++ class Atom; -#pragma link C++ class Material; -#pragma link C++ class VisAttr; -#pragma link C++ class AlignmentEntry; -#pragma link C++ class Limit; -#pragma link C++ class LimitSet; -#pragma link C++ class Region; - -// Readout.h -#pragma link C++ class Readout; -#pragma link C++ class Alignment; -#pragma link C++ class Condition; -#pragma link C++ class Conditions; - -// DetElement.h -#pragma link C++ class DetElement; -#pragma link C++ class DetElementObject; -#pragma link C++ class Handle<DetElementObject>; -#pragma link C++ class SensitiveDetectorObject; -#pragma link C++ class SensitiveDetector; -#pragma link C++ class Handle<SensitiveDetectorObject>; - -// Volume.h -#pragma link C++ class Volume; -#pragma link C++ class PlacedVolume; - -// Shapes.h -#pragma link C++ class Polycone; -#pragma link C++ class Solid_type<TGeoPcon>; -#pragma link C++ class Handle<TGeoPcon>; - -#pragma link C++ class ConeSegment; -#pragma link C++ class Solid_type<TGeoConeSeg>; -#pragma link C++ class Handle<TGeoConeSeg>; - -#pragma link C++ class Box; -#pragma link C++ class Solid_type<TGeoBBox>; -#pragma link C++ class Handle<TGeoBBox>; - -#pragma link C++ class Torus; -#pragma link C++ class Solid_type<TGeoTorus>; -#pragma link C++ class Handle<TGeoTorus>; - -#pragma link C++ class Cone; -#pragma link C++ class Solid_type<TGeoCone>; -#pragma link C++ class Handle<TGeoCone>; - -#pragma link C++ class Tube; -#pragma link C++ class Solid_type<TGeoTubeSeg>; -#pragma link C++ class Handle<TGeoTubeSeg>; - -#pragma link C++ class Trap; -#pragma link C++ class Solid_type<TGeoTrap>; -#pragma link C++ class Handle<TGeoTrap>; - -#pragma link C++ class Trapezoid; -#pragma link C++ class Solid_type<TGeoTrd2>; -#pragma link C++ class Handle<TGeoTrd2>; - -#pragma link C++ class Sphere; -#pragma link C++ class Solid_type<TGeoSphere>; -#pragma link C++ class Handle<TGeoSphere>; - -#pragma link C++ class Paraboloid; -#pragma link C++ class Solid_type<TGeoParaboloid>; -#pragma link C++ class Handle<TGeoParaboloid>; - -#pragma link C++ class PolyhedraRegular; -#pragma link C++ class Solid_type<TGeoPgon>; -#pragma link C++ class Handle<TGeoPgon>; - -#pragma link C++ class BooleanSolid; -#pragma link C++ class Solid_type<TGeoCompositeShape>; -#pragma link C++ class Handle<TGeoCompositeShape>; - -#pragma link C++ class SubtractionSolid; -#pragma link C++ class UnionSolid; -#pragma link C++ class IntersectionSolid; - - -//#pragma link C++ class Solid_type<>; -//#pragma link C++ class Handle<>; -#endif - - - int Geant4Dict() { return 0; } diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index fa3af011d2cf35da9662bd02cb1b31922ea8820b..500d2a110b7e4c46a39a24b88c065ad28b42569d 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -11,6 +11,7 @@ #include "DD4hep/Plugins.h" #include "DD4hep/Volumes.h" #include "DD4hep/Printout.h" +#include "DD4hep/objects/ObjectsInterna.h" #include "DD4hep/objects/DetectorInterna.h" #include "DDG4/Geant4Field.h" @@ -264,7 +265,7 @@ Geant4Converter::~Geant4Converter() { } /// Dump element in GDML format to output stream -void* Geant4Converter::handleElement(const string& name, const TGeoElement* element) const { +void* Geant4Converter::handleElement(const string& name, const Atom element) const { G4Element* g4e = data().g4Elements[element]; if (!g4e) { g4e = G4Element::GetElement(name, false); @@ -293,7 +294,7 @@ void* Geant4Converter::handleElement(const string& name, const TGeoElement* elem } /// Dump material in GDML format to output stream -void* Geant4Converter::handleMaterial(const string& name, const TGeoMedium* medium) const { +void* Geant4Converter::handleMaterial(const string& name, Material medium) const { G4Material* mat = data().g4Materials[medium]; if (!mat) { mat = G4Material::GetMaterial(name, false); @@ -327,7 +328,7 @@ void* Geant4Converter::handleMaterial(const string& name, const TGeoMedium* medi A_total += (mix->GetAmixt())[i]; for (int i = 0; i < nElements; ++i) { TGeoElement* e = mix->GetElement(i); - G4Element* g4e = (G4Element*) handleElement(e->GetName(), e); + G4Element* g4e = (G4Element*) handleElement(e->GetName(), Atom(e)); if (!g4e) { printout(ERROR, "Material", "Missing component %s for material %s.", e->GetName(), mix->GetName()); } @@ -498,7 +499,7 @@ void* Geant4Converter::handleVolume(const string& name, const TGeoVolume* volume LimitSet lim = _v.limitSet(); G4UserLimits* user_limits = 0; if (lim.isValid()) { - user_limits = info.g4Limits[lim.ptr()]; + user_limits = info.g4Limits[lim]; if (!user_limits) { throw runtime_error("G4Cnv::volume[" + name + "]: + FATAL Failed to " "access Geant4 user limits."); @@ -507,12 +508,12 @@ void* Geant4Converter::handleVolume(const string& name, const TGeoVolume* volume VisAttr vis = _v.visAttributes(); G4VisAttributes* vis_attr = 0; if (vis.isValid()) { - vis_attr = (G4VisAttributes*) handleVis(vis.name(), vis.ptr()); + vis_attr = (G4VisAttributes*)handleVis(vis.name(), vis); } Region reg = _v.region(); G4Region* region = 0; if (reg.isValid()) { - region = info.g4Regions[reg.ptr()]; + region = info.g4Regions[reg]; if (!region) { throw runtime_error("G4Cnv::volume[" + name + "]: + FATAL Failed to " "access Geant4 region."); @@ -526,7 +527,7 @@ void* Geant4Converter::handleVolume(const string& name, const TGeoVolume* volume //info.g4AssemblyVolumes[v] = new Geant4AssemblyVolume(); return 0; } - medium = (G4Material*) handleMaterial(m->GetName(), m); + medium = (G4Material*) handleMaterial(m->GetName(), Material(m)); if (!solid) { throw runtime_error("G4Converter: No Geant4 Solid present for volume:" + n); } @@ -565,11 +566,11 @@ void* Geant4Converter::collectVolume(const string& /* name */, const TGeoVolume* SensitiveDetector det = _v.sensitiveDetector(); if (lim.isValid()) - info.limits[lim.ptr()].insert(v); + info.limits[lim].insert(v); if (reg.isValid()) - info.regions[reg.ptr()].insert(v); + info.regions[reg].insert(v); if (det.isValid()) - info.sensitives[det.ptr()].insert(v); + info.sensitives[det].insert(v); return (void*) v; } @@ -696,7 +697,7 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) } /// Convert the geometry type region into the corresponding Geant4 object(s). -void* Geant4Converter::handleRegion(const TNamed* region, const set<const TGeoVolume*>& /* volumes */) const { +void* Geant4Converter::handleRegion(Region region, const set<const TGeoVolume*>& /* volumes */) const { G4Region* g4 = data().g4Regions[region]; if (!g4) { Region r = Ref_t(region); @@ -739,7 +740,7 @@ void* Geant4Converter::handleRegion(const TNamed* region, const set<const TGeoVo } /// Convert the geometry type LimitSet into the corresponding Geant4 object(s). -void* Geant4Converter::handleLimitSet(const TNamed* limitset, const set<const TGeoVolume*>& /* volumes */) const { +void* Geant4Converter::handleLimitSet(LimitSet limitset, const set<const TGeoVolume*>& /* volumes */) const { G4UserLimits* g4 = data().g4Limits[limitset]; if (!g4) { LimitSet ls = Ref_t(limitset); @@ -766,7 +767,7 @@ void* Geant4Converter::handleLimitSet(const TNamed* limitset, const set<const TG } /// Convert the geometry type SensitiveDetector into the corresponding Geant4 object(s). -void* Geant4Converter::handleSensitive(const TNamed* sens_det, const set<const TGeoVolume*>& /* volumes */) const { +void* Geant4Converter::handleSensitive(SensitiveDetector sens_det, const set<const TGeoVolume*>& /* volumes */) const { Geant4GeometryInfo& info = data(); G4VSensitiveDetector* g4 = info.g4SensDets[sens_det]; if (!g4) { @@ -795,12 +796,11 @@ void* Geant4Converter::handleSensitive(const TNamed* sens_det, const set<const T } /// Convert the geometry visualisation attributes to the corresponding Geant4 object(s). -void* Geant4Converter::handleVis(const string& /* name */, const TNamed* vis) const { +void* Geant4Converter::handleVis(const string& /* name */, VisAttr attr) const { Geant4GeometryInfo& info = data(); - G4VisAttributes* g4 = info.g4Vis[vis]; + G4VisAttributes* g4 = info.g4Vis[attr]; 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())); @@ -816,7 +816,7 @@ void* Geant4Converter::handleVis(const string& /* name */, const TNamed* vis) co g4->SetForceSolid(false); g4->SetForceWireframe(true); } - info.g4Vis[vis] = g4; + info.g4Vis[attr] = g4; } return g4; } @@ -862,7 +862,7 @@ void Geant4Converter::handleProperties(LCDD::Properties& prp) const { } /// Convert the geometry type SensitiveDetector into the corresponding Geant4 object(s). -void* Geant4Converter::printSensitive(const TNamed* sens_det, const set<const TGeoVolume*>& /* volumes */) const { +void* Geant4Converter::printSensitive(SensitiveDetector sens_det, const set<const TGeoVolume*>& /* volumes */) const { Geant4GeometryInfo& info = data(); G4VSensitiveDetector* g4 = info.g4SensDets[sens_det]; ConstVolumeSet& volset = info.sensitives[sens_det]; @@ -881,7 +881,7 @@ void* Geant4Converter::printSensitive(const TNamed* sens_det, const set<const TG 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); + map<Volume, G4LogicalVolume*>::iterator v = info.g4Volumes.find(*i); G4LogicalVolume* vol = (*v).second; str.str(""); str << " | " << "Volume:" << setw(24) << left << vol->GetName() << " " @@ -936,6 +936,12 @@ void* Geant4Converter::printPlacement(const string& name, const TGeoNode* node) return g4; } +template <typename O, typename C, typename F> void handleRefs(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); + (o->*pmf)("", *i); + } +} 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); @@ -965,16 +971,16 @@ Geant4Converter& Geant4Converter::create(DetElement top) { // All positions and the like are not really named. // Hence, start creating the G4 objects for materials, solids and log volumes. Material mat = m_lcdd.material("Argon"); - handleMaterial(mat.name(), mat.ptr()); + handleMaterial(mat.name(), mat); mat = m_lcdd.material("Silicon"); - handleMaterial(mat.name(), mat.ptr()); + handleMaterial(mat.name(), mat); //setPrintLevel(VERBOSE); handle(this, geo.volumes, &Geant4Converter::collectVolume); handle(this, geo.solids, &Geant4Converter::handleSolid); printout(m_outputLevel, "Geant4Converter", "++ Handled %ld solids.", geo.solids.size()); - handle(this, geo.vis, &Geant4Converter::handleVis); + handleRefs(this, geo.vis, &Geant4Converter::handleVis); printout(m_outputLevel, "Geant4Converter", "++ Handled %ld visualization attributes.", geo.vis.size()); handleMap(this, geo.sensitives, &Geant4Converter::handleSensitive); printout(m_outputLevel, "Geant4Converter", "++ Handled %ld sensitive detectors.", geo.sensitives.size()); diff --git a/DDG4/src/Geant4SensitiveDetector.cpp b/DDG4/src/Geant4SensitiveDetector.cpp index ec27d3b5b15581d987ca419ca46a1c1f3ab36730..1ef838978c7957f977150866ab5e25b40823d89e 100644 --- a/DDG4/src/Geant4SensitiveDetector.cpp +++ b/DDG4/src/Geant4SensitiveDetector.cpp @@ -166,7 +166,7 @@ void Geant4SensitiveDetector::dumpStep(G4Step* st, G4TouchableHistory* /* histor const G4VPhysicalVolume* qv = pl; if (qv == pv) { - const TGeoNode* tpv = (*i).first; + const TGeoNode* tpv = (*i).first.ptr(); printf(" Found TGeoNode:%s!\n", tpv->GetName()); } } diff --git a/DDG4/src/Geant4VolumeManager.cpp b/DDG4/src/Geant4VolumeManager.cpp index 19536172c7baa8f8e54f99c1c34e8669579ba45d..f5a350e49f43669b773e5f51930382d23e57f739 100644 --- a/DDG4/src/Geant4VolumeManager.cpp +++ b/DDG4/src/Geant4VolumeManager.cpp @@ -103,7 +103,7 @@ namespace { void add_entry(SensitiveDetector sd, const TGeoNode* /* n */, const PlacedVolume::VolIDs& ids, const Chain& nodes) { Chain control; const TGeoNode* node; - const TGeoVolume* vol; + Volume vol; Geant4PlacementPath path; Readout ro = sd.readout(); IDDescriptor iddesc = ro.idSpec(); @@ -128,7 +128,7 @@ namespace { continue; } control.insert(control.begin(),node); - vol = node->GetVolume(); + vol = Volume(node->GetVolume()); VolumeImprintMap::const_iterator iVolImp = m_geo.g4VolumeImprints.find(vol); if ( iVolImp != m_geo.g4VolumeImprints.end() ) { const Imprints& imprints = (*iVolImp).second; diff --git a/cmake/FindROOT.cmake b/cmake/FindROOT.cmake index 0711e1ba4b3365f2840fb0cd268263d9a6c70c68..b79b630b9c8248efe35ec69d77da853b96a255f8 100644 --- a/cmake/FindROOT.cmake +++ b/cmake/FindROOT.cmake @@ -9,7 +9,7 @@ find_program(ROOT_CONFIG_EXECUTABLE root-config - PATHS $ENV{ROOTSYS}/bin) + PATHS ${ROOTSYS}/bin $ENV{ROOTSYS}/bin) if(ROOT_CONFIG_EXECUTABLE) execute_process( @@ -56,7 +56,7 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(ROOT DEFAULT_MSG ROOTSYS ROOT_INCLUDE_DIR) mark_as_advanced(ROOT_FOUND ROOT_INCLUDE_DIR) include(CMakeParseArguments) -find_program(ROOTCINT_EXECUTABLE rootcint PATHS $ENV{ROOTSYS}/bin) +find_program(ROOTCINT_EXECUTABLE rootcint PATHS ${ROOTSYS}/bin $ENV{ROOTSYS}/bin) #---------------------------------------------------------------------------- # function root_generate_dictionary( dictionary @@ -100,8 +100,10 @@ function(root_generate_dictionary dictionary) endforeach() #---call rootcint------------------------------------------ add_custom_command(OUTPUT ${dictionary}.cxx ${dictionary}.h - COMMAND ${ROOTCINT_EXECUTABLE} -cint -f ${dictionary}.cxx + COMMAND echo ${ROOTCINT_EXECUTABLE} -cint -f ${dictionary}.cxx -c ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs} + COMMAND ${ROOTCINT_EXECUTABLE} -f ${dictionary}.cxx + -c -p ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs} DEPENDS ${headerfiles} ${linkdefs}) endfunction() diff --git a/doc/release.notes b/doc/release.notes index ddbee37aa5e529a599b6dbf571b9896a2f68fc36..f91e2824e981f5b64a2b9f8e3951625352206c3d 100644 --- a/doc/release.notes +++ b/doc/release.notes @@ -1,6 +1,28 @@ DD4hep ---- Release Notes ================================= +2014/06/03 Markus Frank +----------------------- + - Provision for ROOT persistency for DD4hep detector descriptions: + Create Cint dictionary for DD4hepCore by default when building the library. + For the time being the area of DDSegmentation is left out, since these + objects require changes due to the handling of references and template + specializations. Besides these, DD4hep detector descriptions can be + saved and read-back directly to/from ROOT files - which may improve + a lot the startup time of processes. + + - The DDG4 dictionary is created by default when building the library. + When importing DDG4 from python only the DD4hepCore DD4hepG4 libraries + must be present. It should no longer be necessary to compile the + necessary AClick on the fly. + + - Investigations on wirframe drawing: + Wireframes are a property of the scene graph. You can toggle to wireframe + using the 'w' key on the keyboard. Other representations are + 'r': Solid view + 't': Solid + wireframe view. + This information is accessible from the help menu of the ROOT OGL widget. + -------- 2014/05/28 Markus Frank | v00-07 | seventh beta release ... -------- diff --git a/examples/ClientTests/scripts/FCC_Hcal.py b/examples/ClientTests/scripts/FCC_Hcal.py new file mode 100644 index 0000000000000000000000000000000000000000..063aaf893a4a7b75004ea38f316393a282f7f47f --- /dev/null +++ b/examples/ClientTests/scripts/FCC_Hcal.py @@ -0,0 +1,151 @@ +# +# +import os, time, DDG4 +from DDG4 import OutputLevel as Output +from SystemOfUnits import * +# +# +""" + + DD4hep example setup using the python configuration + + @author M.Frank + @version 1.0 + +""" +def run(): + install_dir = os.environ['DD4hepINSTALL'] + example_dir = install_dir+'/examples/DDG4/examples'; + kernel = DDG4.Kernel() + kernel.setOutputLevel('Geant4Converter',Output.DEBUG) + kernel.setOutputLevel('RootOutput',Output.INFO) + kernel.setOutputLevel('LcioOutput',Output.INFO) + kernel.setOutputLevel('ShellHandler',Output.DEBUG) + kernel.setOutputLevel('Gun',Output.INFO) + kernel.UI = "UI" + kernel.loadGeometry("file:"+install_dir+"/examples/ClientTests/compact/FCC_HcalBarrel.xml") + kernel.loadXML("file:"+example_dir+"/DDG4_field.xml") + kernel.printProperties() + lcdd = kernel.lcdd() + print '+++ List of sensitive detectors:' + for i in lcdd.detectors(): + print i.second + o = DDG4.DetElement(i.second) + sd = lcdd.sensitiveDetector(o.name()) + if sd.isValid(): + print '+++ %-32s type:%s'%(o.name(), sd.type(), ) + + # Configure UI + ui = DDG4.Action(kernel,"Geant4UIManager/UI") + ui.HaveVIS = True + ui.HaveUI = True + ui.SessionType = 'csh' + kernel.registerGlobalAction(ui) + + + # Configure Run actions: example only! + """ + run1 = DDG4.RunAction(kernel,'Geant4TestRunAction/RunInit') + run1.Property_int = 12345 + run1.Property_double = -5e15*keV + run1.Property_string = 'Startrun: Hello_2' + print run1.Property_string, run1.Property_double, run1.Property_int + run1.enableUI() + kernel.registerGlobalAction(run1) + kernel.runAction().add(run1) + """ + # Configure Event actions + """ + trk = DDG4.Action(kernel,"Geant4TrackPersistency/MonteCarloTruthHandler") + mc = DDG4.Action(kernel,"Geant4MonteCarloRecordManager/MonteCarloRecordManager") + kernel.registerGlobalAction(trk) + kernel.registerGlobalAction(mc) + trk.release() + mc.release() + """ + + # Configure I/O + evt_root = DDG4.EventAction(kernel,'Geant4Output2ROOT/RootOutput') + evt_root.Control = True + evt_root.Output = "FCC_HCAL_"+time.strftime("%Y-%m-%d_%H-%M")+".root" + evt_root.enableUI() + kernel.eventAction().add(evt_root) + + #evt_lcio = DDG4.EventAction(kernel,'Geant4Output2LCIO/LcioOutput') + #evt_lcio.Output = "simple_lcio" + #evt_lcio.enableUI() + #kernel.eventAction().add(evt_lcio) + + # Setup particle gun + gun = DDG4.GeneratorAction(kernel,"Geant4ParticleGun/Gun") + gun.energy = 100*GeV + gun.particle = 'pi-' + gun.multiplicity = 1 + gun.position = (0*mm,0*mm,0*mm) + gun.isotrop = True + gun.enableUI() + kernel.generatorAction().add(gun) + """ + rdr = DDG4.GeneratorAction(kernel,"LcioGeneratorAction/Reader") + rdr.zSpread = 0.0 + rdr.lorentzAngle = 0.0 + rdr.OutputLevel = DDG4.OutputLevel.INFO + rdr.Input = "LcioEventReader|test.data" + rdr.enableUI() + kernel.generatorAction().add(rdr) + """ + + # Setup global filters fur use in sensntive detectors + f1 = DDG4.Filter(kernel,'GeantinoRejectFilter/GeantinoRejector') + f2 = DDG4.Filter(kernel,'EnergyDepositMinimumCut') + f2.Cut = 1e-14*keV + f2.enableUI() + kernel.registerGlobalFilter(f1) + kernel.registerGlobalFilter(f2) + + # Now the calorimeters + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/HcalBarrel') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalBarrelHandler','HcalBarrel') + seq.add(f1) # ignore geantinos + #seq.add(f2) # ignore particles below threshold + seq.add(act) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/ContainmentShell') + act = DDG4.SensitiveAction(kernel,'Geant4EscapeCounter/ShellHandler','ContainmentShell') + seq.add(act) + + # Now build the physics list: + phys = kernel.physicsList() + phys.extends = 'QGSP_BERT' + #phys.transportation = True + #phys.decays = True + phys.enableUI() + """ + ph = DDG4.PhysicsList(kernel,'Geant4PhysicsList/Myphysics') + ph.addParticleConstructor('G4BosonConstructor') + ph.addParticleConstructor('G4LeptonConstructor') + ph.addParticleConstructor('G4MesonConstructor') + ph.addParticleConstructor('G4BaryonConstructor') + ph.addParticleProcess('e[+-]','G4eMultipleScattering',-1,1,1) + #ph.addParticleProcess('e[+-]','G4eIonisation',-1,2,2) + ph.addParticleProcess('mu[+-]','G4MuMultipleScattering',-1,1,1) + #ph.addParticleProcess('mu[+-]','G4MuIonisation',-1,2,2) + ph.addParticleProcess('pi[+-]','G4hMultipleScattering',-1,2,2) + #ph.addParticleProcess('pi[+-]','G4hIonisation',-1,2,2) + ph.addParticleProcess('pi[+-]','G4hBremsstrahlung',-1,3,3) + ph.addParticleProcess('proton','G4hMultipleScattering',-1,2,2) + #ph.addParticleProcess('proton','G4hIonisation',-1,2,2) + ph.addParticleProcess('proton','G4hBremsstrahlung',-1,3,3) + ph.enableUI() + phys.add(ph) + """ + + phys.dump() + + kernel.configure() + kernel.initialize() + kernel.run() + kernel.terminate() + +if __name__ == "__main__": + run()