diff --git a/DDCore/include/DD4hep/AlignmentsNominalMap.h b/DDCore/include/DD4hep/AlignmentsNominalMap.h index e2fdeb11a783dd2a9f68852092085aa820de891a..65afeb097eeefecfac811eb4a7509e0338171731 100644 --- a/DDCore/include/DD4hep/AlignmentsNominalMap.h +++ b/DDCore/include/DD4hep/AlignmentsNominalMap.h @@ -45,6 +45,9 @@ namespace dd4hep { public: /// Reference to the top detector element DetElement world; + /// Potential cache of real conditions + std::map<Condition::key_type,Condition> data; + public: /// Standard constructor AlignmentsNominalMap(DetElement wrld); @@ -85,5 +88,5 @@ namespace dd4hep { Condition::itemkey_type upper, const Condition::Processor& processor) const override; }; -} /* End namespace dd4hep */ +} /* End namespace dd4hep */ #endif /* DD4HEP_DDCORE_ALIGNMENTSNOMINALMAP_H */ diff --git a/DDCore/include/DD4hep/DD4hepRootPersistency.h b/DDCore/include/DD4hep/DD4hepRootPersistency.h index bfeee23a7e7025674cf4512466835e7c1f569dc1..db77918a6b83914cd7831c733cfe6c65c17ae10b 100644 --- a/DDCore/include/DD4hep/DD4hepRootPersistency.h +++ b/DDCore/include/DD4hep/DD4hepRootPersistency.h @@ -19,6 +19,10 @@ /// Helper class to support ROOT persistency of Detector objects class DD4hepRootPersistency : public TNamed, public dd4hep::DetectorData { public: + typedef std::map<std::string, dd4hep::Handle<dd4hep::NamedObject> > HandleMap; + typedef std::map<std::string, std::string> PropertyValues; + typedef std::map<std::string, PropertyValues> Properties; + /// Default constructor DD4hepRootPersistency() : TNamed() {} /// Default destructor @@ -26,9 +30,116 @@ public: static int save(dd4hep::Detector& description, const char* fname, const char* instance = "Geometry"); static int load(dd4hep::Detector& description, const char* fname, const char* instance = "Geometry"); + /// Access the geometry manager of this instance + TGeoManager& manager() const { + return *m_manager; + } + /// Access to properties + Properties& properties() const { + return *(Properties*)&m_properties; + } + /// Return handle to material describing air + dd4hep::Material air() const { + return m_materialAir; + } + /// Return handle to material describing vacuum + dd4hep::Material vacuum() const { + return m_materialVacuum; + } + /// Return handle to "invisible" visualization attributes + dd4hep::VisAttr invisible() const { + return m_invisibleVis; + } + /// Return reference to the top-most (world) detector element + dd4hep::DetElement world() const { + return m_world; + } + /// Return reference to detector element with all tracker devices. + dd4hep::DetElement trackers() const { + return m_trackers; + } + /// Return handle to the world volume containing everything + dd4hep::Volume worldVolume() const { + return m_worldVol; + } + /// Return handle to the world volume containing the volume with the tracking devices + dd4hep::Volume trackingVolume() const { + return m_trackingVol; + } + /// Return handle to the VolumeManager + dd4hep::VolumeManager volumeManager() const { + return m_volManager; + } + /// Return handle to the combined electromagentic field description. + dd4hep::OverlayedField field() const { + return m_field; + } + /// Accessor to the header entry + dd4hep::Header header() const { + return m_header; + } + /// Accessor to the map of constants + const HandleMap& constants() const { + return m_define; + } + /// Accessor to the map of visualisation attributes + const HandleMap& visAttributes() const { + return m_display; + } + /// Accessor to the map of limit settings + const HandleMap& limitsets() const { + return m_limits; + } + /// Accessor to the map of region settings + const HandleMap& regions() const { + return m_regions; + } + /// Accessor to the map of readout structures + const HandleMap& readouts() const { + return m_readouts; + } + /// Accessor to the map of sub-detectors + const HandleMap& detectors() const { + return m_detectors; + } + /// Retrieve a sensitive detector by it's name from the detector description + const HandleMap& sensitiveDetectors() const { + return m_sensitive; + } + /// Accessor to the map of field entries, which together form the global field + const HandleMap& fields() const { + return m_fields; + } + /// Accessor to the map of ID specifications + const HandleMap& idSpecifications() const { + return m_idDict; + } /// ROOT implementation macro ClassDef(DD4hepRootPersistency,1); }; +class DD4hepRootCheck { +public: + const DD4hepRootPersistency* object = 0; + DD4hepRootCheck() = default; + DD4hepRootCheck(const DD4hepRootCheck& copy) = default; + DD4hepRootCheck(const DD4hepRootPersistency* o) : object(o) {} + ~DD4hepRootCheck() = default; + DD4hepRootCheck& operator=(const DD4hepRootCheck& copy) = default; + const DD4hepRootCheck& checkDetectors() const; + const DD4hepRootCheck& checkMaterials() const; + const DD4hepRootCheck& checkReadouts() const; + const DD4hepRootCheck& checkFields() const; + const DD4hepRootCheck& checkRegions() const; + const DD4hepRootCheck& checkIdSpecs() const; + const DD4hepRootCheck& checkSensitives() const; + const DD4hepRootCheck& checkLimitSets() const; + const DD4hepRootCheck& checkVolManager() const; + const DD4hepRootCheck& checkDefines() const; + const DD4hepRootCheck& checkProperties() const; + const DD4hepRootCheck& checkAll() const; +}; + + #endif /* DD4HEP_DD4HEPROOTPERSISTENCY_H */ diff --git a/DDCore/include/DD4hep/Dictionary.h b/DDCore/include/DD4hep/Dictionary.h index ac46e37ff08501b38cf1e557f60169910d325479..9df5c5b83ffe6668178c23dbc207273d79840672 100644 --- a/DDCore/include/DD4hep/Dictionary.h +++ b/DDCore/include/DD4hep/Dictionary.h @@ -30,6 +30,7 @@ #include "DD4hep/Callback.h" #include "DD4hep/DetectorData.h" #include "DD4hep/Conditions.h" +#include "DD4hep/Alignments.h" #include "DD4hep/FieldTypes.h" // C/C++ include files @@ -98,6 +99,7 @@ template class pair<dd4hep::Callback,unsigned long>; #pragma link C++ function operator!=( const map<string, dd4hep::Handle<dd4hep::NamedObject> >::iterator&,const map<string, dd4hep::Handle<dd4hep::NamedObject> >::iterator& ); #endif +#pragma link C++ class dd4hep::BasicGrammar+; #pragma link C++ class dd4hep::ObjectExtensions+; template class dd4hep::Handle<TNamed>; #pragma link C++ class dd4hep::Handle<TNamed>+; @@ -113,6 +115,7 @@ template class dd4hep::Handle<TNamed>; #pragma link C++ class dd4hep::Detector::PropertyValues+; #pragma link C++ class dd4hep::Detector::Properties+; #pragma link C++ class DD4hepRootPersistency+; +#pragma link C++ class DD4hepRootCheck+; // These below are the Namedobject instances to be generated .... //#pragma link C++ class dd4hep::Detector::HandleMap+; @@ -122,9 +125,12 @@ template class dd4hep::Handle<TNamed>; //#pragma link C++ class dd4hep::Detector::HandleMap::value_type+; #pragma link C++ class dd4hep::VolumeManager+; -#pragma link C++ class dd4hep::VolumeManagerObject+; +#pragma link C++ class dd4hep::detail::VolumeManagerObject+; #pragma link C++ class dd4hep::VolumeManagerContext+; -#pragma link C++ class dd4hep::Handle<dd4hep::VolumeManagerObject>+; +#pragma link C++ class dd4hep::Handle<dd4hep::detail::VolumeManagerObject>+; +#pragma link C++ class map<dd4hep::DetElement,dd4hep::VolumeManager>+; +#pragma link C++ class map<dd4hep::VolumeID,dd4hep::VolumeManager>+; +#pragma link C++ class map<dd4hep::VolumeID,dd4hep::VolumeManagerContext*>+; #pragma link C++ class dd4hep::CartesianField+; #pragma link C++ class dd4hep::CartesianField::Object+; @@ -210,6 +216,10 @@ template class dd4hep::Handle<TNamed>; #pragma link C++ class dd4hep::Handle<dd4hep::AlignmentData>+; #pragma link C++ class dd4hep::Handle<TGeoPhysicalNode>+; +#pragma link C++ class dd4hep::AlignmentCondition+; +#pragma link C++ class dd4hep::detail::AlignmentObject+; +#pragma link C++ class dd4hep::Handle<dd4hep::detail::AlignmentObject>+; + #pragma link C++ class dd4hep::Condition+; @@ -218,10 +228,13 @@ template class dd4hep::Handle<TNamed>; #pragma link C++ class vector<dd4hep::ConditionKey>+; #pragma link C++ class dd4hep::detail::ConditionObject+; #pragma link C++ class dd4hep::Handle<dd4hep::detail::ConditionObject>+; +#pragma link C++ class dd4hep::OpaqueData+; +#pragma link C++ class dd4hep::OpaqueDataBlock+; // DetElement.h #pragma link C++ class dd4hep::World+; #pragma link C++ class dd4hep::WorldObject+; +#pragma link C++ class dd4hep::Handle<dd4hep::WorldObject>+; #pragma link C++ class dd4hep::DetElement+; #pragma link C++ class dd4hep::DetElementObject+; #pragma link C++ class dd4hep::Handle<dd4hep::DetElementObject>+; @@ -327,6 +340,8 @@ template vector<pair<string, int> >::iterator; #pragma link C++ class dd4hep::UnionSolid+; #pragma link C++ class dd4hep::IntersectionSolid+; + + #pragma link C++ class pair<string, string>+; #pragma link C++ class map<string, string>+; #pragma link C++ class map<string, string>::iterator; @@ -359,27 +374,36 @@ template vector<pair<string, int> >::iterator; #pragma link C++ class dd4hep::cond::AbstractMap+; #pragma link C++ class dd4hep::cond::AbstractMap::Params+; - #endif // __CINT__ // ------------------------------------------------------------------------- // DDSegmentation dictionaries +#define __HAVE_DDSEGMENTATION__ // ------------------------------------------------------------------------- #ifdef __HAVE_DDSEGMENTATION__ #include "DDSegmentation/Segmentation.h" #include "DDSegmentation/NoSegmentation.h" -#include "DDSegmentation/GridPhiEta.h" -#include "DDSegmentation/GridRPhiEta.h" #include "DDSegmentation/CartesianGrid.h" #include "DDSegmentation/CartesianGridXY.h" #include "DDSegmentation/CartesianGridXYZ.h" #include "DDSegmentation/CartesianGridXZ.h" #include "DDSegmentation/CartesianGridYZ.h" #include "DDSegmentation/CylindricalSegmentation.h" +#include "DDSegmentation/GridPhiEta.h" +#include "DDSegmentation/GridRPhiEta.h" +#include "DDSegmentation/MegatileLayerGridXY.h" +#include "DDSegmentation/MultiSegmentation.h" +#include "DDSegmentation/NoSegmentation.h" +#include "DDSegmentation/PolarGrid.h" +#include "DDSegmentation/PolarGridRPhi2.h" +#include "DDSegmentation/PolarGridRPhi.h" #include "DDSegmentation/ProjectiveCylinder.h" + #include "DDSegmentation/SegmentationParameter.h" +#include "DDSegmentation/TiledLayerGridXY.h" #include "DDSegmentation/TiledLayerSegmentation.h" +#include "DDSegmentation/WaferGridXY.h" typedef dd4hep::DDSegmentation::VolumeID VolumeID; typedef dd4hep::DDSegmentation::CellID CellID; @@ -390,26 +414,35 @@ typedef dd4hep::DDSegmentation::CellID CellID; #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 +#pragma link C++ class map<string,dd4hep::DDSegmentation::TypedSegmentationParameter<string>* >+; +#pragma link C++ class map<string,dd4hep::DDSegmentation::TypedSegmentationParameter<double>* >+; +#pragma link C++ class map<string,dd4hep::DDSegmentation::TypedSegmentationParameter<float>* >+; + /// Severe problem due to template specialization! #pragma link C++ class dd4hep::DDSegmentation::TypedSegmentationParameter<vector<int> >+; #pragma link C++ class dd4hep::DDSegmentation::TypedSegmentationParameter<vector<float> >+; #pragma link C++ class dd4hep::DDSegmentation::TypedSegmentationParameter<vector<double> >+; #pragma link C++ class dd4hep::DDSegmentation::TypedSegmentationParameter<vector<string> >+; -#endif #pragma link C++ class dd4hep::DDSegmentation::Segmentation+; -#pragma link C++ class dd4hep::DDSegmentation::NoSegmentation+; -#pragma link C++ class dd4hep::DDSegmentation::GridPhiEta+; -#pragma link C++ class dd4hep::DDSegmentation::GridRPhiEta+; #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::CartesianGridYZ+; #pragma link C++ class dd4hep::DDSegmentation::CylindricalSegmentation+; +#pragma link C++ class dd4hep::DDSegmentation::GridPhiEta+; +#pragma link C++ class dd4hep::DDSegmentation::GridRPhiEta+; +#pragma link C++ class dd4hep::DDSegmentation::MegatileLayerGridXY+; +#pragma link C++ class dd4hep::DDSegmentation::MultiSegmentation+; +#pragma link C++ class dd4hep::DDSegmentation::NoSegmentation+; +#pragma link C++ class dd4hep::DDSegmentation::PolarGrid+; +#pragma link C++ class dd4hep::DDSegmentation::PolarGridRPhi2+; +#pragma link C++ class dd4hep::DDSegmentation::PolarGridRPhi+; #pragma link C++ class dd4hep::DDSegmentation::ProjectiveCylinder+; +#pragma link C++ class dd4hep::DDSegmentation::TiledLayerGridXY+; #pragma link C++ class dd4hep::DDSegmentation::TiledLayerSegmentation+; +#pragma link C++ class dd4hep::DDSegmentation::WaferGridXY+; #pragma link C++ class dd4hep::DDSegmentation::BitFieldValue+; #pragma link C++ class dd4hep::DDSegmentation::BitField64+; diff --git a/DDCore/include/DD4hep/IDDescriptor.h b/DDCore/include/DD4hep/IDDescriptor.h index c82709423a2359ac04f051b3e21824a48a336946..79425cc9d6bc4903d0eaf08254a29d3c0b9a9e84 100644 --- a/DDCore/include/DD4hep/IDDescriptor.h +++ b/DDCore/include/DD4hep/IDDescriptor.h @@ -74,6 +74,8 @@ namespace dd4hep { std::string toString() const; /// Access the BitField64 object BitField64* decoder(); + /// Re-build object in place + void rebuild(const std::string& description); }; } /* End namespace dd4hep */ #endif /* DD4HEP_DDCORE_IDDESCRIPTOR_H */ diff --git a/DDCore/include/DD4hep/detail/DetectorInterna.h b/DDCore/include/DD4hep/detail/DetectorInterna.h index d15a39a9da3491e1d757e3153751871a28c2e194..8cdf5509f8bb3f4349ae08006dcea7841a1b4cd5 100644 --- a/DDCore/include/DD4hep/detail/DetectorInterna.h +++ b/DDCore/include/DD4hep/detail/DetectorInterna.h @@ -130,7 +130,7 @@ namespace dd4hep { /// The array of children DetElement::Children children; /// Placeholder for structure with update callbacks - UpdateCallbacks updateCalls; + UpdateCallbacks updateCalls; //! Not ROOT persistent //@{ Additional information set externally to facilitate the processing of event data */ /// Basic ideal/nominal detector element alignment entry @@ -191,7 +191,7 @@ namespace dd4hep { class WorldObject: public DetElementObject { public: /// Reference to the Detector instance object - Detector* description; + Detector* description; //! Not persistent in ROOT public: //@{ Public methods to ease the usage of the data. */ diff --git a/DDCore/include/DD4hep/detail/ObjectsInterna.h b/DDCore/include/DD4hep/detail/ObjectsInterna.h index 05d93d589c49a13d6a94775d8fbc650197aceb5a..1e65730175d71c718d798806064cde333b1dd7b0 100644 --- a/DDCore/include/DD4hep/detail/ObjectsInterna.h +++ b/DDCore/include/DD4hep/detail/ObjectsInterna.h @@ -65,6 +65,8 @@ namespace dd4hep { public: /// Constant type std::string dataType; + /// Default constructor for ROOT persistency + ConstantObject(); /// Standard constructor ConstantObject(const std::string& nam, const std::string& val, const std::string& typ); /// Default destructor @@ -167,7 +169,7 @@ namespace dd4hep { class ReadoutObject: public NamedObject { public: /// Handle to the readout segmentation - Segmentation segmentation; + Segmentation segmentation; //! No ROOT persistency /// Handle to the volume Volume readoutWorld; /// Handle to the field descriptor @@ -194,6 +196,7 @@ namespace dd4hep { typedef std::vector<std::pair<size_t, std::string> > FieldIDs; FieldMap fieldMap; //! not ROOT-persistent FieldIDs fieldIDs; //! not ROOT-persistent + /// The description string to build the bit-field descriptors. std::string description; /// Default constructor IDDescriptorObject(); diff --git a/DDCore/include/DD4hep/detail/SegmentationsInterna.h b/DDCore/include/DD4hep/detail/SegmentationsInterna.h index da5b6d90c0516f13f7082674986e5a016b7b9117..59d684d02bb0308267239775d72806765d4238e0 100644 --- a/DDCore/include/DD4hep/detail/SegmentationsInterna.h +++ b/DDCore/include/DD4hep/detail/SegmentationsInterna.h @@ -101,12 +101,16 @@ namespace dd4hep { /// DDSegmentation aggregate IMP* implementation; public: +#if defined(G__ROOT) || defined(__CLANG__) || defined(__ROOTCLING__) + /// Empty constructor for ROOT persistency + SegmentationWrapper() : SegmentationObject(implementation=new IMP(0)) { } +#endif /// Standard constructor SegmentationWrapper(BitField64* decoder); /// Default destructor virtual ~SegmentationWrapper(); }; - + /// Standard constructor template <typename IMP> inline SegmentationWrapper<IMP>::SegmentationWrapper(BitField64* decode) diff --git a/DDCore/src/AlignmentNominalMap.cpp b/DDCore/src/AlignmentNominalMap.cpp index 092a7f2f9353e906dbe4e5657f03c09d5243e5ca..46b055f43c2243925494b487fd5682faedb01f0e 100644 --- a/DDCore/src/AlignmentNominalMap.cpp +++ b/DDCore/src/AlignmentNominalMap.cpp @@ -26,35 +26,51 @@ AlignmentsNominalMap::AlignmentsNominalMap(DetElement wrld) : world(wrld) { } /// Insert a new entry to the map -bool AlignmentsNominalMap::insert(DetElement /* detector */, - Condition::itemkey_type /* key */, - Condition /* condition */) { - return false; +bool AlignmentsNominalMap::insert(DetElement detector, + Condition::itemkey_type key, + Condition condition) { + auto res = data.insert(std::make_pair(ConditionKey(detector,key).hash,condition)); + return res.second; } /// Interface to access conditions by hash value Condition AlignmentsNominalMap::get(DetElement detector, Condition::itemkey_type key) const { - if ( key == Keys::alignmentKey ) { - return Condition(detector.nominal().ptr()); + auto res = data.find(ConditionKey(detector,key).hash); + if ( res == data.end() ) { + if ( key == Keys::alignmentKey ) { + return Condition(detector.nominal().ptr()); + } + return Condition(); } - return Condition(); + return res->second; } /// Interface to scan data content of the conditions mapping void AlignmentsNominalMap::scan(const Condition::Processor& processor) const { - /// Heklper to implement partial scans. + + /// Helper to implement partial scans. + /* + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ struct Scanner { const Condition::Processor& proc; /// Constructor - Scanner(const Condition::Processor& p) : proc(p){} + Scanner(const Condition::Processor& p) : proc(p) { } /// Conditions callback for object processing int operator()(DetElement de, int /* level */) const { Condition c = de.nominal(); return proc(c); } } scanner(processor); + + // First scan the local conditions + for( const auto& i : data ) + processor(i); + // We emulate here a full detector scan, access the nominal alignments and process them by the processor. - if ( world.isValid() ) { + if ( world.isValid() ) { DetectorScanner().scan(scanner,world,0,true); return; } @@ -67,10 +83,27 @@ void AlignmentsNominalMap::scan(DetElement detector, Condition::itemkey_type lower, Condition::itemkey_type upper, const Condition::Processor& processor) const { + if ( detector.isValid() ) { - if ( lower <= Keys::alignmentKey && upper >= Keys::alignmentKey ) { - Condition c(detector.nominal().ptr()); - processor(c); + Condition::detkey_type det_key = detector.key(); + Condition::key_type low = ConditionKey::KeyMaker(det_key,lower).hash; + Condition::key_type up = ConditionKey::KeyMaker(det_key,upper).hash; + ConditionKey::KeyMaker align_key(detector.key(),Keys::alignmentKey); + + for(auto i=data.lower_bound(low); i != data.end() && (*i).first <= up; ++i) { + ConditionKey::KeyMaker k((*i).first); + if ( low <= k.hash && up >= k.hash ) { + processor((*i).second); + if ( k.hash == align_key.hash ) { + align_key.hash = 0; + } + } + } + if ( align_key.hash ) { + if ( lower <= Keys::alignmentKey && upper >= Keys::alignmentKey ) { + Condition c(detector.nominal().ptr()); + processor(c); + } } return; } diff --git a/DDCore/src/ConditionsMap.cpp b/DDCore/src/ConditionsMap.cpp index ee8ee7253f5fab402afb9a5483fa29bd81b70412..5c7fc5789afeab48ca8a2000f4ec25be903a81bf 100644 --- a/DDCore/src/ConditionsMap.cpp +++ b/DDCore/src/ConditionsMap.cpp @@ -24,7 +24,12 @@ void ConditionsMap::scan(DetElement detector, Condition::itemkey_type upper, const Condition::Processor& processor) const { - /// Heklper to implement partial scans. + /// Helper to implement partial scans. + /* + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ struct Scanner : public Condition::Processor { Condition::key_type lower, upper; const Condition::Processor& processor; @@ -54,7 +59,12 @@ void ConditionsMap::scan(DetElement detector, std::vector<Condition> ConditionsMap::get(DetElement detector, Condition::itemkey_type lower, Condition::itemkey_type upper) const { - /// Heklper to implement partial scans. + /// Helper to implement partial scans. + /* + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ struct Scanner : public Condition::Processor { Condition::key_type lower, upper; std::vector<Condition>& result; diff --git a/DDCore/src/DD4hepRootPersistency.cpp b/DDCore/src/DD4hepRootPersistency.cpp index 69077c50d87e94c7ec74b2e3e3458a9d1619c930..f8e5b096b3e040769ed0c76bd0e712517d0264f1 100644 --- a/DDCore/src/DD4hepRootPersistency.cpp +++ b/DDCore/src/DD4hepRootPersistency.cpp @@ -20,25 +20,31 @@ ClassImp(DD4hepRootPersistency) -int DD4hepRootPersistency::save(dd4hep::Detector& description, const char* fname, const char* instance) { +using namespace dd4hep; + +int DD4hepRootPersistency::save(Detector& description, const char* fname, const char* instance) { TFile* f = TFile::Open(fname,"RECREATE"); if ( f && !f->IsZombie()) { DD4hepRootPersistency* persist = new DD4hepRootPersistency(); persist->adoptData(dynamic_cast<DetectorData&>(description)); int nBytes = persist->Write(instance); f->Close(); - dd4hep::printout(dd4hep::ALWAYS,"DD4hepRootPersistency", + printout(ALWAYS,"DD4hepRootPersistency", "+++ Wrote %d Bytes of geometry data '%s' to '%s'.", nBytes, instance, fname); + if ( nBytes > 0 ) { + printout(ALWAYS,"DD4hepRootPersistency", + "+++ Successfully saved geometry data to file."); + } delete f; delete persist; return nBytes; } - dd4hep::printout(dd4hep::ERROR,"DD4hepRootPersistency","+++ Cannot open file '%s'.",fname); + printout(ERROR,"DD4hepRootPersistency","+++ Cannot open file '%s'.",fname); return 0; } -int DD4hepRootPersistency::load(dd4hep::Detector& description, const char* fname, const char* instance) { +int DD4hepRootPersistency::load(Detector& description, const char* fname, const char* instance) { TFile* f = TFile::Open(fname); if ( f && !f->IsZombie()) { DD4hepRootPersistency* persist = (DD4hepRootPersistency*)f->Get(instance); @@ -49,13 +55,81 @@ int DD4hepRootPersistency::load(dd4hep::Detector& description, const char* fname delete persist; return 1; } - dd4hep::printout(dd4hep::ERROR,"DD4hepRootPersistency", + printout(ERROR,"DD4hepRootPersistency", "+++ Cannot Cannot load instance '%s' from file '%s'.", instance, fname); f->ls(); delete f; return 0; } - dd4hep::printout(dd4hep::ERROR,"DD4hepRootPersistency","+++ Cannot open file '%s'.",fname); + printout(ERROR,"DD4hepRootPersistency","+++ Cannot open file '%s'.",fname); return 0; } + +namespace { + int printDetElement(DetElement d) { + const DetElement::Children& children = d.children(); + int count = 1; + printout(INFO,"checkDetector","+++ %-40s Level:%3d Key:%08X VolID:%016llX", + d.name(), d.level(), d.key(), d.volumeID()); + for( const auto& c : children ) + count += printDetElement(c.second); + return count; + } + void checkDetector(DetElement d) { + printout(INFO,"checkDetector","+++ Checking Sub-Detector: %-40s Key:%08X VolID:%016llX", + d.name(), d.key(), d.volumeID()); + int count = printDetElement(d); + } +} + +const DD4hepRootCheck& DD4hepRootCheck::checkDetectors() const { + const auto& dets = object->detectors(); + for( const auto& d : dets ) + checkDetector(d.second); + return *this; +} + +const DD4hepRootCheck& DD4hepRootCheck::checkMaterials() const { + return *this; +} + +const DD4hepRootCheck& DD4hepRootCheck::checkReadouts() const { + return *this; +} + +const DD4hepRootCheck& DD4hepRootCheck::checkFields() const { + return *this; +} + +const DD4hepRootCheck& DD4hepRootCheck::checkRegions() const { + return *this; +} + +const DD4hepRootCheck& DD4hepRootCheck::checkIdSpecs() const { + return *this; +} + +const DD4hepRootCheck& DD4hepRootCheck::checkSensitives() const { + return *this; +} + +const DD4hepRootCheck& DD4hepRootCheck::checkLimitSets() const { + return *this; +} + +const DD4hepRootCheck& DD4hepRootCheck::checkVolManager() const { + return *this; +} + +const DD4hepRootCheck& DD4hepRootCheck::checkDefines() const { + return *this; +} + +const DD4hepRootCheck& DD4hepRootCheck::checkProperties() const { + return *this; +} + +const DD4hepRootCheck& DD4hepRootCheck::checkAll() const { + return *this; +} diff --git a/DDCore/src/DetectorData.cpp b/DDCore/src/DetectorData.cpp index 1f86f20ede9526688e342a8c2ec9849084063d90..9a25348761d90b9027d03a83c9bc3c219986a4ad 100644 --- a/DDCore/src/DetectorData.cpp +++ b/DDCore/src/DetectorData.cpp @@ -107,26 +107,29 @@ void DetectorData::clearData() { void DetectorData::adoptData(DetectorData& source) { m_inhibitConstants = source.m_inhibitConstants; m_extensions.move(source.m_extensions); - m_motherVolumes = source.m_motherVolumes; - m_world = source.m_world; - m_field = source.m_field; - m_header = source.m_header; - m_properties = source.m_properties; + m_manager = source.m_manager; m_readouts = source.m_readouts; m_idDict = source.m_idDict; m_limits = source.m_limits; m_regions = source.m_regions; + m_detectors = source.m_detectors; m_sensitive = source.m_sensitive; m_display = source.m_display; m_fields = source.m_fields; m_define = source.m_define; + + m_motherVolumes = source.m_motherVolumes; + m_world = source.m_world; 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; + m_materialVacuum = source.m_materialVacuum; + m_invisibleVis = source.m_invisibleVis; + m_field = source.m_field; + m_header = source.m_header; + m_properties = source.m_properties; + //m_extensions = source.m_extensions; m_volManager = source.m_volManager; source.clearData(); } diff --git a/DDCore/src/IDDescriptor.cpp b/DDCore/src/IDDescriptor.cpp index 380d9d06c05fb2de09497fdef4be1ce822995bdb..9cf0aa5400de0d2da3ee7af572fb8acdffb6162c 100644 --- a/DDCore/src/IDDescriptor.cpp +++ b/DDCore/src/IDDescriptor.cpp @@ -45,6 +45,13 @@ IDDescriptor::IDDescriptor(const string& description) { _construct(obj, description); } +/// Re-build object in place +void IDDescriptor::rebuild(const string& description) { + Object* p = ptr(); + p->~Object(); + new(p) Object(description); +} + /// Acces string representation string IDDescriptor::toString() const { if ( isValid() ) { diff --git a/DDCore/src/ObjectsInterna.cpp b/DDCore/src/ObjectsInterna.cpp index 724fdf70037f1f20ef0e23980fab12636c5fcec4..e116552c49b596156101e5432f2778fe7aa3f498 100644 --- a/DDCore/src/ObjectsInterna.cpp +++ b/DDCore/src/ObjectsInterna.cpp @@ -25,7 +25,8 @@ 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) { + : magic(magic_word()), col(0), color(0), alpha(0), + drawingStyle(VisAttr::SOLID), lineStyle(VisAttr::SOLID), showDaughters(true), visible(true) { InstanceCount::increment(this); } @@ -49,6 +50,11 @@ HeaderObject::~HeaderObject() { DD4HEP_INSTANTIATE_HANDLE_NAMED(ConstantObject); +/// Default constructor +ConstantObject::ConstantObject() { + InstanceCount::increment(this); +} + /// Standard constructor ConstantObject::ConstantObject(const string& nam, const string& val, const string& typ) : NamedObject(nam.c_str(), val.c_str()) { @@ -109,13 +115,13 @@ DD4HEP_INSTANTIATE_HANDLE_NAMED(IDDescriptorObject); /// Standard constructor IDDescriptorObject::IDDescriptorObject() - : NamedObject(), BitField64() /*, maxBit(0) */{ + : NamedObject(), BitField64() { InstanceCount::increment(this); } /// Standard constructor IDDescriptorObject::IDDescriptorObject(const std::string& desc) - : NamedObject(), BitField64(desc) /*, maxBit(0) */{ + : NamedObject(), BitField64(desc) { InstanceCount::increment(this); } @@ -123,3 +129,4 @@ IDDescriptorObject::IDDescriptorObject(const std::string& desc) IDDescriptorObject::~IDDescriptorObject() { InstanceCount::decrement(this); } + diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp index 9cbf7229649e5e18fc15df605843f80a5acbf134..3cd04b450cac07b971e014f800cc68aac5492b91 100644 --- a/DDCore/src/VolumeManager.cpp +++ b/DDCore/src/VolumeManager.cpp @@ -15,6 +15,8 @@ #include "DD4hep/Detector.h" #include "DD4hep/Printout.h" #include "DD4hep/MatrixHelpers.h" +#include "DD4hep/detail/Handle.inl" +#include "DD4hep/detail/ObjectsInterna.h" #include "DD4hep/detail/DetectorInterna.h" #include "DD4hep/detail/VolumeManagerInterna.h" @@ -28,7 +30,13 @@ using namespace std; using namespace dd4hep; using namespace dd4hep::detail; +DD4HEP_INSTANTIATE_HANDLE_NAMED(VolumeManagerObject); + + namespace { + + static bool s_useAllocator = false; + class ContextExtension { public: /// The placement of the (sensitive) volume @@ -41,24 +49,18 @@ namespace { ~ContextExtension() = default; }; - inline ContextExtension* _getExtension(const VolumeManagerContext* ctxt) { - char* p = (char*)ctxt; - return (ContextExtension*)(p + sizeof(VolumeManagerContext)); - } - -#if 0 static size_t ALLOCATE_SIZE = 1000; - class ContextAllocator { + class VolumeContextAllocator { public: - struct Small { + struct Small { + unsigned char context[sizeof(VolumeManagerContext)]; unsigned int chunk = 0; unsigned short slot = 0; unsigned char type = 0; unsigned char used = 0; - unsigned char ctxt[sizeof(VolumeManagerContext)]; /// Default constructor - Small() : type(1) {} + Small() : type(1) {} /// Default destructor virtual ~Small() = default; /// Inhibit copy constructor @@ -80,21 +82,33 @@ namespace { std::vector<std::pair<size_t,Small*> > small; std::vector<std::pair<size_t,Large*> > large; - std::pair<size_t, Small*> curr_small{0,0}; - std::pair<size_t, Large*> curr_large{0,0}; - size_t num_total = 0; - size_t num_free = 0; - ContextAllocator() {} + std::list<Small*> free_small; + std::list<Large*> free_large; + + VolumeContextAllocator() {} + static VolumeContextAllocator* instance() { + static VolumeContextAllocator _s; + return &_s; + } + void clear() { + free_small.clear(); + for( auto& i : small ) delete i.second; + small.clear(); + + free_large.clear(); + for( auto& i : large ) delete i.second; + large.clear(); + } void freeBlock(void* ctxt) { - unsigned char* p = (unsigned char*)ctxt; - p -= (sizeof(Small) - sizeof(VolumeManagerContext)); - Small* s = (Small*)p; + Small* s = (Small*)ctxt; switch(s->type) { case 1: - freeSlot(small,s); + s->used = 0; + free_small.push_back(s); return; case 2: - freeSlot(large,s); + s->used = 0; + free_large.push_back((Large*)s); return; default: printout(ERROR,"VolumeManager", @@ -103,26 +117,41 @@ namespace { return; } } - void freeSlot(std::vector<std::pair<size_t,Large*> >& cont, Small* s) { - } - void freeSlot(std::vector<std::pair<size_t,Small*> >& cont, Small* s) { - } void* alloc_large() { - if ( curr_large.first > 0 ) { - Large* cont = (Large*)curr_large.second; - --curr_large.first; - --num_free; - cont[curr_large.first].used = 1; - return &cont[curr_large.first].ctxt; + if ( s_useAllocator ) { + if ( !free_large.empty() ) { + Large* entry = free_large.back(); + free_large.pop_back(); + entry->used = 1; + return entry->context; + } + Large* blk = new Large[ALLOCATE_SIZE]; + for(size_t i=0; i<ALLOCATE_SIZE;++i) free_large.push_back(&blk[i]); + large.push_back(make_pair(ALLOCATE_SIZE,blk)); + return alloc_large(); + } + return new VolumeContextAllocator::Large(); + } + void* alloc_small() { + if ( s_useAllocator ) { + if ( !free_small.empty() ) { + Small* entry = free_small.back(); + free_small.pop_back(); + entry->used = 1; + return entry->context; + } + Small* blk = new Small[ALLOCATE_SIZE]; + for(size_t i=0; i<ALLOCATE_SIZE;++i) free_small.push_back(&blk[i]); + small.push_back(make_pair(ALLOCATE_SIZE,blk)); + return alloc_small(); } - curr_large = make_pair(ALLOCATE_SIZE,new Large[ALLOCATE_SIZE]); - large.push_back(curr_large); - num_total += ALLOCATE_SIZE; - num_free += ALLOCATE_SIZE; - return alloc_large(); + return new VolumeContextAllocator::Small(); } }; -#endif + inline ContextExtension* _getExtension(const VolumeManagerContext* ctxt) { + VolumeContextAllocator::Large* p = (VolumeContextAllocator::Large*)ctxt; + return (ContextExtension*)p->extension; + } } /// Namespace for the AIDA detector description toolkit @@ -336,17 +365,16 @@ namespace dd4hep { VolumeManager section = m_volManager.addSubdetector(sub_detector, ro); // This is the block, we effectively have to save for each physical volume with a VolID - size_t len = nodes.empty() - ? sizeof(VolumeManagerContext) - : sizeof(VolumeManagerContext) + sizeof(ContextExtension); - void* ptr = ::operator new(len); - VolumeManagerContext* context = new(ptr) VolumeManagerContext; + void* mem = nodes.empty() + ? VolumeContextAllocator::instance()->alloc_small() + : VolumeContextAllocator::instance()->alloc_large(); + VolumeManagerContext* context = new(mem) VolumeManagerContext; context->identifier = code.first; context->mask = code.second; context->element = e; - if ( nodes.size() > 0 ) { + context->flag = nodes.empty() ? 0 : 1; + if ( context->flag ) { ContextExtension* ext = new(_getExtension(context)) ContextExtension(); - context->flag = 1; ext->placement = PlacedVolume(n); for (size_t i = nodes.size(); i > 1; --i) { // Omit the placement of the parent DetElement TGeoMatrix* m = nodes[i-1]->GetMatrix(); @@ -726,3 +754,36 @@ std::ostream& dd4hep::operator<<(std::ostream& os, const VolumeManager& m) { os << prefix << i.second << endl; return os; } + +/// Default destructor +VolumeManagerObject::~VolumeManagerObject() { + /// Cleanup volume tree + if ( s_useAllocator ) { + VolumeContextAllocator::instance()->clear(); + } + else { + destroyObjects(volumes); + } + /// Cleanup dependent managers + destroyHandles(managers); + managers.clear(); + subdetectors.clear(); +} + +/// Update callback when alignment has changed (called only for subdetectors....) +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) ) + printout(DEBUG,"VolumeManager","+++ Alignment update %s param:%p",det.path().c_str(),param); + + for(const auto& i : volumes ) + printout(DEBUG,"VolumeManager","+++ Alignment update %s",i.second->elementPlacement().name()); +} + +/// Search the locally cached volumes for a matching ID +VolumeManagerContext* VolumeManagerObject::search(const VolumeID& vol_id) const { + auto i = volumes.find(vol_id&detMask); + return (i == volumes.end()) ? 0 : (*i).second; +} + diff --git a/DDCore/src/VolumeManagerInterna.cpp b/DDCore/src/VolumeManagerInterna.cpp deleted file mode 100644 index a01d1ef31b3446f2bdf80a93bc2e361dac700a36..0000000000000000000000000000000000000000 --- a/DDCore/src/VolumeManagerInterna.cpp +++ /dev/null @@ -1,49 +0,0 @@ -//========================================================================== -// AIDA Detector description implementation -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see $DD4hepINSTALL/LICENSE. -// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. -// -// Author : M.Frank -// -//========================================================================== - -// Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/detail/Handle.inl" -#include "DD4hep/detail/VolumeManagerInterna.h" - -using namespace dd4hep; -using namespace dd4hep::detail; - -DD4HEP_INSTANTIATE_HANDLE_NAMED(VolumeManagerObject); - -/// Default destructor -VolumeManagerObject::~VolumeManagerObject() { - /// Cleanup volume tree - destroyObjects(volumes); - /// Cleanup dependent managers - destroyHandles(managers); - managers.clear(); - subdetectors.clear(); -} - -/// Update callback when alignment has changed (called only for subdetectors....) -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) ) - printout(DEBUG,"VolumeManager","+++ Alignment update %s param:%p",det.path().c_str(),param); - - for(const auto& i : volumes ) - printout(DEBUG,"VolumeManager","+++ Alignment update %s",i.second->elementPlacement().name()); -} - -/// Search the locally cached volumes for a matching ID -VolumeManagerContext* VolumeManagerObject::search(const VolumeID& vol_id) const { - auto i = volumes.find(vol_id&detMask); - return (i == volumes.end()) ? 0 : (*i).second; -} diff --git a/DDCore/src/plugins/StandardPlugins.cpp b/DDCore/src/plugins/StandardPlugins.cpp index b3131cf9ce7d40fc5a36627279ca1a2363fade24..9046a3885c7093c6e4989bd946e6d4683576966b 100644 --- a/DDCore/src/plugins/StandardPlugins.cpp +++ b/DDCore/src/plugins/StandardPlugins.cpp @@ -487,7 +487,19 @@ DECLARE_APPLY(DD4hepVolumeManager,load_volmgr) */ static long dump_geometry2root(Detector& description, int argc, char** argv) { if ( argc > 0 ) { - string output = argv[0]; + string output; + for(int i = 0; i < argc && argv[i]; ++i) { + if ( 0 == ::strncmp("-output",argv[i],4) ) + output = argv[++i]; + } + if ( output.empty() ) { + cout << + "Usage: -plugin <name> -arg [-arg] \n" + " name: factory name DD4hepGeometry2ROOT \n" + " -output <string> Output file name. \n" + "\tArguments given: " << arguments(argc,argv) << endl << flush; + ::exit(EINVAL); + } printout(INFO,"Geometry2ROOT","+++ Dump geometry to root file:%s",output.c_str()); //description.manager().Export(output.c_str()+1); if ( DD4hepRootPersistency::save(description,output.c_str(),"Geometry") > 1 ) { diff --git a/DDSegmentation/include/DDSegmentation/BitField64.h b/DDSegmentation/include/DDSegmentation/BitField64.h index 60a1704277312459d6ee56be72444485901e6d47..6b8708bcbf4770a99af82c3a2a3ac9310fbd0c82 100644 --- a/DDSegmentation/include/DDSegmentation/BitField64.h +++ b/DDSegmentation/include/DDSegmentation/BitField64.h @@ -162,7 +162,7 @@ namespace DDSegmentation { // -------------- data members:-------------- - std::vector<BitFieldValue*> _fields ; + std::vector<BitFieldValue*> _fields; //! Not ROOT persistent long64 _value ; IndexMap _map ; long64 _joined ; diff --git a/DDSegmentation/include/DDSegmentation/MegatileLayerGridXY.h b/DDSegmentation/include/DDSegmentation/MegatileLayerGridXY.h index 1c4da110a5e907407c09a6bb6191bdd957f16e95..6ef055dd6a353dffd8d472501512bd7a6c0fc375 100644 --- a/DDSegmentation/include/DDSegmentation/MegatileLayerGridXY.h +++ b/DDSegmentation/include/DDSegmentation/MegatileLayerGridXY.h @@ -96,9 +96,6 @@ namespace dd4hep { virtual std::vector<double> cellDimensions(const CellID& cellID) const; virtual std::vector<double> cellDimensions(const unsigned int ilayer, const unsigned int iwafer) const; - - protected: - struct segInfo { double megaTileSizeX = 0; double megaTileSizeY = 0; @@ -109,6 +106,9 @@ namespace dd4hep { segInfo() = default; }; + + protected: + mutable segInfo _currentSegInfo; void getSegInfo( unsigned int layerIndex, unsigned int waferIndex) const; diff --git a/DDSegmentation/include/DDSegmentation/Segmentation.h b/DDSegmentation/include/DDSegmentation/Segmentation.h index 6743678c626c2c2af81f30526afd94c4be320388..b3d0c727728ff9cf0fab7994526338d145caeb2b 100644 --- a/DDSegmentation/include/DDSegmentation/Segmentation.h +++ b/DDSegmentation/include/DDSegmentation/Segmentation.h @@ -158,9 +158,9 @@ protected: /// The indices used for the encoding std::map<std::string, StringParameter> _indexIdentifiers; /// The cell ID encoder and decoder - mutable BitField64* _decoder; + mutable BitField64* _decoder = 0; //! Not ROOT persistent /// Keeps track of the decoder ownership - bool _ownsDecoder; + bool _ownsDecoder = false; private: /// No copy constructor allowed Segmentation(const Segmentation&); diff --git a/DDSegmentation/include/DDSegmentation/SegmentationParameter.h b/DDSegmentation/include/DDSegmentation/SegmentationParameter.h index d4180205658862a026aa1895c207a9b18efb9abe..bcde988522fbe513df49802adc37d96bf44c9c7b 100644 --- a/DDSegmentation/include/DDSegmentation/SegmentationParameter.h +++ b/DDSegmentation/include/DDSegmentation/SegmentationParameter.h @@ -100,7 +100,7 @@ public: enum UnitType { NoUnit, LengthUnit, AngleUnit }; - /// Destructor + /// Default destructor virtual ~SegmentationParameter() { } /// Access to the parameter name @@ -154,22 +154,29 @@ protected: template<typename TYPE> class TypedSegmentationParameter: public SegmentationParameter { public: +#if defined(G__ROOT) || defined(__CLANG__) || defined(__ROOTCLING__) + /// Empty constructor for ROOT persistency + TypedSegmentationParameter() + : SegmentationParameter("","",SegmentationParameter::NoUnit,false), _value(0), _defaultValue() {} +#endif /// Default constructor TypedSegmentationParameter(const std::string& nam, const std::string& desc, TYPE& val, const TYPE& default_Value, SegmentationParameter::UnitType unitTyp = SegmentationParameter::NoUnit, bool isOpt = false) : - SegmentationParameter(nam, desc, unitTyp, isOpt), _value(val), _defaultValue(default_Value) { - _value = default_Value; + SegmentationParameter(nam, desc, unitTyp, isOpt), _value(&val), _defaultValue(default_Value) { + *_value = default_Value; } + /// Default destructor + virtual ~TypedSegmentationParameter() { } /// Access to the parameter value const TYPE& typedValue() const { - return _value; + return *_value; } /// Set the parameter value void setTypedValue(const TYPE& val) { - _value = val; + *_value = val; } /// Access to the parameter default value @@ -185,7 +192,7 @@ public: /// Access to the parameter value in string representation std::string value() const { std::stringstream s; - s << _value; + s << *_value; return s.str(); } @@ -193,7 +200,7 @@ public: void setValue(const std::string& val) { std::stringstream s; s << val; - s >> _value; + s >> *_value; } /// Access to the parameter default value in string representation @@ -204,28 +211,35 @@ public: } protected: - TYPE& _value; - TYPE _defaultValue; + TYPE* _value = 0; //! + TYPE _defaultValue; }; template<typename TYPE> class TypedSegmentationParameter<std::vector<TYPE> > : public SegmentationParameter { public: +#if defined(G__ROOT) || defined(__CLANG__) || defined(__ROOTCLING__) + /// Empty constructor for ROOT persistency + TypedSegmentationParameter() + : SegmentationParameter("","",SegmentationParameter::NoUnit,false), _value(0), _defaultValue() {} +#endif /// Default constructor TypedSegmentationParameter(const std::string& nam, const std::string& desc, std::vector<TYPE>& val, const std::vector<TYPE>& defaultVal, SegmentationParameter::UnitType unitTyp = SegmentationParameter::NoUnit, bool isOpt = false) : - SegmentationParameter(nam, desc, unitTyp, isOpt), _value(val), _defaultValue(defaultVal) { - _value = defaultVal; + SegmentationParameter(nam, desc, unitTyp, isOpt), _value(&val), _defaultValue(defaultVal) { + *_value = defaultVal; } + /// Default destructor + virtual ~TypedSegmentationParameter() { } /// Access to the parameter value const std::vector<TYPE>& typedValue() const { - return _value; + return *_value; } /// Set the parameter value void setTypedValue(const std::vector<TYPE>& val) { - _value = val; + *_value = val; } /// Access to the parameter default value @@ -243,9 +257,8 @@ public: /// Access to the parameter value in string representation std::string value() const { std::stringstream s; - typename std::vector<TYPE>::const_iterator it = _value.begin(); - for (; it != _value.end(); ++it) { - s << *it; + for (const auto& it : *_value ) { + s << it; s << " "; } return s.str(); @@ -254,14 +267,14 @@ public: /// Set the parameter value in string representation void setValue(const std::string& val) { std::vector<std::string> elements = splitString(val); - _value.clear(); + _value->clear(); for (std::vector<std::string>::const_iterator it = elements.begin(); it != elements.end(); ++it) { if (not it->empty()) { TYPE entry; std::stringstream s; s << *it; s >> entry; - _value.push_back(entry); + _value->push_back(entry); } } } @@ -278,8 +291,8 @@ public: } protected: - std::vector<TYPE>& _value; - std::vector<TYPE> _defaultValue; + std::vector<TYPE>* _value = 0; //! + std::vector<TYPE> _defaultValue; }; diff --git a/DDSegmentation/src/Segmentation.cpp b/DDSegmentation/src/Segmentation.cpp index cc15e929d32e478c03ab7664c0d289aca780373c..daf6a66cbe591f75c2cb1119047a01e16e228cd3 100644 --- a/DDSegmentation/src/Segmentation.cpp +++ b/DDSegmentation/src/Segmentation.cpp @@ -40,14 +40,10 @@ namespace dd4hep { if (_ownsDecoder and _decoder != 0) { delete _decoder; } - map<std::string, SegmentationParameter*>::iterator it; - for (it = _parameters.begin(); it != _parameters.end(); ++it) { - SegmentationParameter* p = it->second; - if (p) { - delete p; - p = 0; - } + for (auto& p : _parameters) { + if ( p.second ) delete p.second; } + _parameters.clear(); } /// Add subsegmentation. Call only valid for Multi-segmentations. Default implementation throws an exception diff --git a/examples/CLICSiD/CMakeLists.txt b/examples/CLICSiD/CMakeLists.txt index ba6d2fbb5706c5cf30f9e5ab0c038a599261a406..05fea071ad02094038050985856a4e1165085be3 100644 --- a/examples/CLICSiD/CMakeLists.txt +++ b/examples/CLICSiD/CMakeLists.txt @@ -58,6 +58,14 @@ dd4hep_add_test_reg( CLICSiD_check_overlaps_LONGTEST --tolerance=0.1 REGEX_PASS " Execution finished..." ) # +# Test saving geometry to file +dd4hep_add_test_reg( ClientTests_CLICSiD_Save_ROOT_LONGTEST + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh" + EXEC_ARGS geoPluginRun + -volmgr -destroy -input file:${CMAKE_CURRENT_SOURCE_DIR}/compact/compact.xml + -plugin DD4hepGeometry2ROOT -output CLICSiD_geometry.root + REGEX_PASS "\\+\\+\\+ Successfully saved geometry data to file.") +# #---Geant4 Testsing----------------------------------------------------------------- # if (DD4HEP_USE_GEANT4) diff --git a/examples/ClientTests/CMakeLists.txt b/examples/ClientTests/CMakeLists.txt index 24186cc85bfcd510c6ab24be66caf0bae9f4659c..5153c4b6b7e88b17bce6d7ad94900d37c240c7f4 100644 --- a/examples/ClientTests/CMakeLists.txt +++ b/examples/ClientTests/CMakeLists.txt @@ -107,6 +107,14 @@ dd4hep_add_test_reg( ClientTests_Check_Handle_Casts -plugin DD4hepDetectorVolumeDump REGEX_PASS "| PASSED casts: 86 FAILED casts: 86 |") # +# Test saving geometry to file +dd4hep_add_test_reg( ClientTests_MiniTel_Save_ROOT_LONGTEST + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh" + EXEC_ARGS geoPluginRun + -volmgr -destroy -input file:${CMAKE_CURRENT_SOURCE_DIR}/compact/MiniTel.xml + -plugin DD4hepGeometry2ROOT -output MiniTel_geometry.root + REGEX_PASS "\\+\\+\\+ Successfully saved geometry data to file.") +# # foreach (test Assemblies BoxTrafos IronCylinder LheD_tracker MagnetFields MaterialTester MiniTel SectorBarrelCalorimeter SiliconBlock NestedSimple NestedDetectors