diff --git a/DDCond/include/DDCond/ConditionsRootPersistency.h b/DDCond/include/DDCond/ConditionsRootPersistency.h index 15a5df11d184df9dbffd23f486220811f0c95def..37547b07add3aec05759bdf87677c846a674110e 100644 --- a/DDCond/include/DDCond/ConditionsRootPersistency.h +++ b/DDCond/include/DDCond/ConditionsRootPersistency.h @@ -55,10 +55,10 @@ namespace dd4hep { typedef std::pair<std::string,std::pair<std::pair<std::string,int>,IOV::Key> > iov_key_type; typedef std::list<std::pair<iov_key_type, pool_type> > persistent_type; - persistent_type conditionPools; - persistent_type userPools; - persistent_type iovPools; - float duration; + persistent_type conditionPools {}; + persistent_type userPools {}; + persistent_type iovPools {}; + float duration = 0; enum ImportStrategy { IMPORT_ALL = 1<<0, IMPORT_EXACT = 1<<1, diff --git a/DDCond/include/DDCond/ConditionsTreePersistency.h b/DDCond/include/DDCond/ConditionsTreePersistency.h index bed2520ed6f876c2fd5db75aae42f1bd96d577c7..959e5c887f217aa5daa625a0038e2fb503ff97b2 100644 --- a/DDCond/include/DDCond/ConditionsTreePersistency.h +++ b/DDCond/include/DDCond/ConditionsTreePersistency.h @@ -131,9 +131,9 @@ namespace dd4hep { typedef std::pair<std::string,std::pair<std::pair<std::string,int>,IOV::Key> > iov_key_type; typedef std::list<std::pair<iov_key_type, pool_type> > persistent_type; - persistent_type conditionPools; - persistent_type iovPools; - float duration; + persistent_type conditionPools {}; + persistent_type iovPools {}; + float duration {0}; enum ImportStrategy { IMPORT_ALL = 1<<0, IMPORT_EXACT = 1<<1, diff --git a/DDCond/src/ConditionsIOVPool.cpp b/DDCond/src/ConditionsIOVPool.cpp index ecb5558744cd91d75077a697848e249895f26295..823a94ed571e22eb6a60c953f2bbdb601904314e 100644 --- a/DDCond/src/ConditionsIOVPool.cpp +++ b/DDCond/src/ConditionsIOVPool.cpp @@ -30,7 +30,12 @@ ConditionsIOVPool::ConditionsIOVPool(const IOVType* typ) : type(typ) { /// Default destructor ConditionsIOVPool::~ConditionsIOVPool() { - clean(-1); + try { + clean(-1); + } + catch(const std::exception& e) { + printout(ERROR,"ConditionsIOVPool","+++ Unexpected exception in destructor(ConditionsIOVPool): %s",e.what()); + } InstanceCount::decrement(this); } diff --git a/DDCore/include/DD4hep/PluginTester.h b/DDCore/include/DD4hep/PluginTester.h index 33f39d0859bcd5803a3a050a8238ce673ab2fa39..f1c83f91e9ddd83886176907beadd3f933273d29 100644 --- a/DDCore/include/DD4hep/PluginTester.h +++ b/DDCore/include/DD4hep/PluginTester.h @@ -46,7 +46,7 @@ namespace dd4hep { /// The extensions object Extensions extensions; //! /// Pointer to the extension map - ExtensionMap* extensionMap; //! + ExtensionMap* extensionMap = 0; //! /// Function to be passed as dtor if object should NOT be deleted! static void _noDelete(void*) {} diff --git a/DDCore/include/XML/XMLElements.h b/DDCore/include/XML/XMLElements.h index e8ed1587cb8630b9e6d1f8754837f04d5217a930..cd12d614f086261a1f79c579716c5cc519a0cec9 100644 --- a/DDCore/include/XML/XMLElements.h +++ b/DDCore/include/XML/XMLElements.h @@ -137,8 +137,12 @@ namespace dd4hep { bool _toBool(const XmlChar* value); /// Conversion function from raw unicode string to int \ingroup DD4HEP_XML int _toInt(const XmlChar* value); + /// Conversion function from raw unicode string to unsigned int \ingroup DD4HEP_XML + unsigned int _toUInt(const XmlChar* value); /// Conversion function from raw unicode string to long \ingroup DD4HEP_XML long _toLong(const XmlChar* value); + /// Conversion function from raw unicode string to unsigned long \ingroup DD4HEP_XML + unsigned long _toULong(const XmlChar* value); /// Conversion function from raw unicode string to float \ingroup DD4HEP_XML float _toFloat(const XmlChar* value); /// Conversion function from raw unicode string to double \ingroup DD4HEP_XML @@ -532,10 +536,18 @@ namespace dd4hep { return _toInt(attr_value(tag_value)); } + template <> INLINE unsigned int Handle_t::attr<unsigned int>(const XmlChar* tag_value) const { + return _toUInt(attr_value(tag_value)); + } + template <> INLINE long Handle_t::attr<long>(const XmlChar* tag_value) const { return _toLong(attr_value(tag_value)); } + template <> INLINE unsigned long Handle_t::attr<unsigned long>(const XmlChar* tag_value) const { + return _toULong(attr_value(tag_value)); + } + template <> INLINE float Handle_t::attr<float>(const XmlChar* tag_value) const { return _toFloat(attr_value(tag_value)); } @@ -558,11 +570,21 @@ namespace dd4hep { return a ? _toInt(attr_value(a)) : default_value; } + template <> INLINE unsigned int Handle_t::attr<unsigned int>(const XmlChar* tag_value, unsigned int default_value) const { + Attribute a = attr_nothrow(tag_value); + return a ? _toUInt(attr_value(a)) : default_value; + } + template <> INLINE long Handle_t::attr<long>(const XmlChar* tag_value, long default_value) const { Attribute a = attr_nothrow(tag_value); return a ? _toLong(attr_value(a)) : default_value; } + template <> INLINE unsigned long Handle_t::attr<unsigned long>(const XmlChar* tag_value, unsigned long default_value) const { + Attribute a = attr_nothrow(tag_value); + return a ? _toULong(attr_value(a)) : default_value; + } + template <> INLINE float Handle_t::attr<float>(const XmlChar* tag_value, float default_value) const { Attribute a = attr_nothrow(tag_value); return a ? _toFloat(attr_value(a)) : default_value; diff --git a/DDCore/src/DetectorImp.cpp b/DDCore/src/DetectorImp.cpp index 6b9f98b57c7094215bc8995559e23f1f174ffa04..75851c04526d6828580433c1eb814e2a188f1831 100644 --- a/DDCore/src/DetectorImp.cpp +++ b/DDCore/src/DetectorImp.cpp @@ -90,8 +90,9 @@ namespace { Detector* remove(const string& name) { auto i = detectors.find(name); if ( i==detectors.end() ) { + Detector* det = (*i).second; detectors.erase(i); - return (*i).second; + return det; } return 0; } diff --git a/DDCore/src/SurfaceInstaller.cpp b/DDCore/src/SurfaceInstaller.cpp index 6227c81d7d36b088fbdb49dc7d044ac53fa3260e..29f778cda7ca737a715cca19508a7699263ac29d 100644 --- a/DDCore/src/SurfaceInstaller.cpp +++ b/DDCore/src/SurfaceInstaller.cpp @@ -51,11 +51,11 @@ SurfaceInstaller::SurfaceInstaller(Detector& description, int argc, char** argv) /// Indicate error message and throw exception void SurfaceInstaller::invalidInstaller(const std::string& msg) const { const char* det = m_det.isValid() ? m_det.name() : "<UNKNOWN>"; - const char* typ = m_det.isValid() ? m_det.type().c_str() : "<UNKNOWN>"; + string typ = m_det.isValid() ? m_det.type() : string("<UNKNOWN>"); printout(FATAL,"SurfaceInstaller","+++ Surfaces for: %s",det); printout(FATAL,"SurfaceInstaller","+++ %s.",msg.c_str()); printout(FATAL,"SurfaceInstaller","+++ You sure you apply the correct plugin to generate"); - printout(FATAL,"SurfaceInstaller","+++ surfaces for a detector of type %s",typ); + printout(FATAL,"SurfaceInstaller","+++ surfaces for a detector of type %s",typ.c_str()); throw std::runtime_error("+++ Failed to install Surfaces to detector "+string(det)); } diff --git a/DDCore/src/XML/XMLElements.cpp b/DDCore/src/XML/XMLElements.cpp index f9b996140c04b4de186e2928b00ea72c7c6cedc2..251c5aa20b1c2b43697ff2f7ed8e6205f9bde965 100644 --- a/DDCore/src/XML/XMLElements.cpp +++ b/DDCore/src/XML/XMLElements.cpp @@ -309,23 +309,19 @@ long dd4hep::xml::_toLong(const XmlChar* value) { return -1; } -int dd4hep::xml::_toInt(const XmlChar* value) { - if (value) { - string s = _toString(value); - size_t idx = s.find("(int)"); - if (idx != string::npos) - s.erase(idx, 5); - while (s[0] == ' ') - s.erase(0, 1); - double result = eval.evaluate(s.c_str()); - if (eval.status() != tools::Evaluator::OK) { - cerr << s << ": "; - eval.print_error(); - throw runtime_error("dd4hep: Severe error during expression evaluation of " + s); - } - return (int) result; - } - return -1; +unsigned long dd4hep::xml::_toULong(const XmlChar* value) { + long val = _toLong(value); + if ( val > 0 ) return (unsigned long) val; + string s = _toString(value); + throw runtime_error("dd4hep: Severe error during expression evaluation of " + s); +} + +int dd4hep::xml::_toInt(const XmlChar* value) { + return (int)_toLong(value); +} + +unsigned int dd4hep::xml::_toUInt(const XmlChar* value) { + return (unsigned int)_toULong(value); } bool dd4hep::xml::_toBool(const XmlChar* value) { diff --git a/DDCore/src/gdml/DetElementCreator.cpp b/DDCore/src/gdml/DetElementCreator.cpp index 8223c2079bf5b024d18a8d4cd23564daf3705bdd..ffdbe144fd0e3a2c6ddead84d9bcd23f4fba2cd4 100644 --- a/DDCore/src/gdml/DetElementCreator.cpp +++ b/DDCore/src/gdml/DetElementCreator.cpp @@ -202,17 +202,24 @@ DetElementCreator::~DetElementCreator() { << idspec << "</id> <!-- Number of bits: " << num_bits << " -->" << endl << "</readout>" << endl; + /// Create ID Descriptors and readout configurations - IDDescriptor dsc(ro_name,idspec); - description.addIDSpecification(dsc); - Readout ro(ro_name); - ro.setIDDescriptor(dsc); - description.addReadout(ro); - SensitiveDetector sd = description.sensitiveDetector(f.first.name()); - sd.setHitsCollection(ro.name()); - sd.setReadout(ro); - printout(INFO,pref,"DetElementCreator: ++ Setting up readout for subdetector:%-24s id:%04X", - f.first.name(), f.first.id()); + try { + IDDescriptor dsc(ro_name,idspec); + description.addIDSpecification(dsc); + Readout ro(ro_name); + ro.setIDDescriptor(dsc); + description.addReadout(ro); + SensitiveDetector sd = description.sensitiveDetector(f.first.name()); + sd.setHitsCollection(ro.name()); + sd.setReadout(ro); + printout(INFO,pref,"DetElementCreator: ++ Setting up readout for subdetector:%-24s id:%04X", + f.first.name(), f.first.id()); + } + catch(std::exception& e) { + printout(ERROR,pref,"DetElementCreator: ++ FAILED to setup readout for subdetector:%-24s id:%04X [%s]", + f.first.name(), f.first.id(), e.what()); + } } printout(INFO,pref,"DetElementCreator: " "+++++++++++++++ ID Descriptor generation ++++++++++++++++++++++++++++"); diff --git a/DDCore/src/gdml/GdmlPlugins.cpp b/DDCore/src/gdml/GdmlPlugins.cpp index 183d93526ac2bb8b472603a308fb7fb9ba82c759..80cac0b42ff87c247f801062aacaef7834dd61ec 100644 --- a/DDCore/src/gdml/GdmlPlugins.cpp +++ b/DDCore/src/gdml/GdmlPlugins.cpp @@ -140,7 +140,7 @@ DECLARE_APPLY(DD4hep_ROOTGDMLParse,gdml_parse) */ static long gdml_extract(Detector& description, int argc, char** argv) { if ( argc > 0 ) { - bool detector = true, volpath = false, volname = false; + bool detector = true, volpath = false; string output, path; for(int i = 0; i < argc && argv[i]; ++i) { if ( 0 == ::strncmp("-output",argv[i],2) ) @@ -148,11 +148,11 @@ static long gdml_extract(Detector& description, int argc, char** argv) { else if ( 0 == ::strncmp("-path", argv[i],2) ) path = argv[++i]; else if ( 0 == ::strncmp("-volpath", argv[i],7) ) - volpath = true, volname = false, detector = false; + volpath = true, detector = false; else if ( 0 == ::strncmp("-volname", argv[i],7) ) - volpath = false, volname = true, detector = false; + volpath = false, detector = false; else if ( 0 == ::strncmp("-detector", argv[i],8) ) - volpath = false, volname = false, detector = true; + volpath = false, detector = true; } if ( output.empty() || path.empty() ) { cout << @@ -210,7 +210,7 @@ static long gdml_extract(Detector& description, int argc, char** argv) { }; Volume top = description.worldVolume(); TObjArray* ents = top->GetNodes(); - Actor a(path, volpath ? true : volname ? false : true); + Actor a(path, volpath ? true : false); for (Int_t i = 0, n = ents->GetEntries(); i < n && a._volume == 0; ++i) { TGeoNode* node = (TGeoNode*)ents->At(i); a.scan(node, node->GetName()); diff --git a/DDCore/src/gdml/ImportPlainRoot.cpp b/DDCore/src/gdml/ImportPlainRoot.cpp index 5d4d70e80145a04dc530813829b6b9258361746a..fe2480a20c6873b9193de0ba4dcf50ff94540e50 100644 --- a/DDCore/src/gdml/ImportPlainRoot.cpp +++ b/DDCore/src/gdml/ImportPlainRoot.cpp @@ -160,22 +160,24 @@ static long plain_root_dump(Detector& description, int argc, char** argv) { if ( f && !f->IsZombie() ) { DetectorData* det = dynamic_cast<DetectorData*>(&description); TGeoManager* mgr = (TGeoManager*)f->Get(in_obj.c_str()); - TGeoManip manip(det, level, do_import, prt); - DetectorData::patchRootStreamer(TGeoVolume::Class()); - DetectorData::patchRootStreamer(TGeoNode::Class()); - det->m_manager = mgr; - manip(0, mgr->GetTopNode()); - det->m_worldVol = mgr->GetTopNode()->GetVolume(); - if ( !air.empty() ) { - description.addConstant(Constant("Air",air)); - } - if ( !vacuum.empty() ) { - description.addConstant(Constant("Vacuum",vacuum)); + if ( det && mgr ) { + TGeoManip manip(det, level, do_import, prt); + DetectorData::patchRootStreamer(TGeoVolume::Class()); + DetectorData::patchRootStreamer(TGeoNode::Class()); + det->m_manager = mgr; + manip(0, mgr->GetTopNode()); + det->m_worldVol = mgr->GetTopNode()->GetVolume(); + if ( !air.empty() ) { + description.addConstant(Constant("Air",air)); + } + if ( !vacuum.empty() ) { + description.addConstant(Constant("Vacuum",vacuum)); + } + description.init(); + description.endDocument(); + detail::deleteObject(f); + return 1; } - description.init(); - description.endDocument(); - detail::deleteObject(f); - return 1; } detail::deleteObject(f); } diff --git a/DDCore/src/plugins/CodeGenerator.cpp b/DDCore/src/plugins/CodeGenerator.cpp index adb222d07bf6fedd7ea4caf842ef10897a726286..456fdaa68050d3efb67fd12de8bdab4dcae68399 100644 --- a/DDCore/src/plugins/CodeGenerator.cpp +++ b/DDCore/src/plugins/CodeGenerator.cpp @@ -416,7 +416,7 @@ namespace { if ( mat->IsTranslation() ) { log << "\t Double_t trans[] = {"; for(size_t i=0; tra && i<3; ++i) { - log << (tra[i]); + log << tra[i]; log << ((i<2) ? sep : "};"); } log << newline << "\t mat->SetTranslation(trans);" << newline; @@ -425,7 +425,7 @@ namespace { if ( rot[0] != 1e0 || rot[4] != 1e0 || rot[8] != 1e0) { log << "\t Double_t rot[] = {"; for(size_t i=0; rot && i<9; ++i) { - log << (rot ? rot[i] : 0e0); + log << rot[i]; log << ((i<8) ? sep : "};"); } log << newline << "\t mat->SetRotation(rot);" << newline; @@ -434,7 +434,7 @@ namespace { if ( mat->IsScale() ) { log << "\t Double_t scale[] = {"; for(size_t i=0; sca && i<3; ++i) { - log << (sca ? sca[i] : 0e0); + log << sca[i]; log << ((i<2) ? sep : "};"); } log << newline << "\t mat->SetScale(scale);" << newline; diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index 9c3010d2a7eef96cf8ffbc91a62abca6a3cb2242..6089bec21d6cd74ba5ece650e43931d62ca7791b 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -725,7 +725,7 @@ template <> void Converter<PropertyConstant>::operator()(xml_h e) const { template <> void Converter<PropertyTable>::operator()(xml_h e) const { string val; vector<double> values; - size_t cols = e.attr<long>(_U(coldim)); + size_t cols = e.attr<unsigned long>(_U(coldim)); stringstream str(e.attr<string>(_U(values))); if ( s_debug.matrix ) { diff --git a/DDCore/src/plugins/TGeoCodeGenerator.cpp b/DDCore/src/plugins/TGeoCodeGenerator.cpp index 516f0ba55f190179432a5abe5d31a0a316ddb8aa..da87aa452cbb16a5a4835323d888f7888b710a51 100644 --- a/DDCore/src/plugins/TGeoCodeGenerator.cpp +++ b/DDCore/src/plugins/TGeoCodeGenerator.cpp @@ -255,7 +255,7 @@ namespace { if ( mat->IsTranslation() ) { log << "\t Double_t trans[] = {"; for(size_t i=0; tra && i<3; ++i) { - log << (tra ? tra[i] : 0e0); + log << tra[i]; log << ((i<2) ? ", " : "};"); } log << newline << "\t matrix_" << pvoid_t(mat) << "->SetTranslation(trans);" << newline; @@ -263,7 +263,7 @@ namespace { if ( mat->IsRotation() ) { log << "\t Double_t rot[] = {"; for(size_t i=0; rot && i<9; ++i) { - log << (rot[i]); + log << rot[i]; log << ((i<8) ? ", " : "};"); } log << newline << "\t matrix_" << pvoid_t(mat) << "->SetRotation(rot);" << newline; @@ -271,7 +271,7 @@ namespace { if ( mat->IsScale() ) { log << "\t Double_t scale[] = {"; for(size_t i=0; sca && i<3; ++i) { - log << (sca[i]); + log << sca[i]; log << ((i<2) ? ", " : "};"); } log << newline << "\t matrix_" << pvoid_t(mat) << "->SetScale(scale);" << newline; diff --git a/DDRec/include/DDRec/Surface.h b/DDRec/include/DDRec/Surface.h index 0b010d9072b53bba4bdc87aad9c1662dc21a63aa..2df066b7e2980e9cbc75276e30bb3b51dbcda6af 100644 --- a/DDRec/include/DDRec/Surface.h +++ b/DDRec/include/DDRec/Surface.h @@ -45,18 +45,18 @@ namespace dd4hep { friend class VolSurface ; protected: - SurfaceType _type ; - Vector3D _u ; - Vector3D _v ; - Vector3D _n ; - Vector3D _o ; - double _th_i ; - double _th_o ; - MaterialData _innerMat ; - MaterialData _outerMat ; - Volume _vol ; - long64 _id ; - unsigned _refCount ; + SurfaceType _type {}; + Vector3D _u {}; + Vector3D _v {}; + Vector3D _n {}; + Vector3D _o {}; + double _th_i {0}; + double _th_o {0}; + MaterialData _innerMat {}; + MaterialData _outerMat {}; + Volume _vol {}; + long64 _id {0}; + unsigned _refCount {0}; /// setter for daughter classes virtual void setU(const Vector3D& u) ; @@ -69,60 +69,36 @@ namespace dd4hep { public: - virtual ~VolSurfaceBase() {} + virtual ~VolSurfaceBase() = default; ///default c'tor - VolSurfaceBase() : - _type( SurfaceType() ) , - _u( Vector3D() ) , - _v( Vector3D() ) , - _n( Vector3D() ) , - _o( Vector3D() ) , - _th_i( 0. ), - _th_o( 0. ), - _innerMat( MaterialData() ), - _outerMat( MaterialData() ), - _vol(), - _id(0),_refCount(0) { - } - + VolSurfaceBase() = default; VolSurfaceBase( SurfaceType typ, - double thickness_inner ,double thickness_outer, - Vector3D u_val ,Vector3D v_val , - Vector3D n ,Vector3D o, Volume vol,int identifier ) : - _type(typ ) , - _u( u_val ) , - _v( v_val ) , - _n( n ) , - _o( o ), - _th_i( thickness_inner ), - _th_o( thickness_outer ), - _innerMat( MaterialData() ), - _outerMat( MaterialData() ), - _vol(vol) , - _id( identifier ), _refCount(0) { + double thickness_inner ,double thickness_outer, + Vector3D u_val ,Vector3D v_val , + Vector3D n ,Vector3D o, Volume vol,int identifier ) : + _type(typ ) , + _u( u_val ) , + _v( v_val ) , + _n( n ) , + _o( o ), + _th_i( thickness_inner ), + _th_o( thickness_outer ), + _vol(vol) , + _id( identifier ) { } /// Copy the from object - VolSurfaceBase(const VolSurfaceBase& c) { - _type = c._type ; - _u = c._u ; - _v = c._v ; - _n = c._n ; - _o = c._o; - _th_i = c._th_i ; - _th_o = c._th_o ; - _innerMat = c._innerMat ; - _outerMat = c._innerMat ; - _vol = c._vol; - _id = c._id ; - _refCount = 0 ; // new instance + VolSurfaceBase(const VolSurfaceBase& c) + : _type(c._type), _u(c._u), _v(c._v), _n(c._n), _o(c._o), + _th_i(c._th_i), _th_o(c._th_o), _innerMat(c._innerMat), + _outerMat(c._innerMat), _vol(c._vol), _id(c._id) + { } - /// the volume to which this surface is attached. Volume volume() const { return _vol ; } @@ -211,10 +187,10 @@ namespace dd4hep { public: virtual ~VolSurface(){ - if( _surf ) { - -- _surf->_refCount ; - if( _surf->_refCount == 0 ) delete _surf ; - } + if( _surf ) { + -- _surf->_refCount ; + if( _surf->_refCount == 0 ) delete _surf ; + } } ///default c'tor VolSurface() : _surf(0) { } @@ -224,13 +200,13 @@ namespace dd4hep { /// Constructor to be used with an existing object VolSurface(const VolSurface& vsurf) : _surf( vsurf._surf ) { - ++ _surf->_refCount ; + ++ _surf->_refCount ; } VolSurface& operator=(const VolSurface& vsurf) { - _surf = vsurf._surf ; - ++ _surf->_refCount ; - return *this ; + _surf = vsurf._surf ; + ++ _surf->_refCount ; + return *this ; } @@ -361,9 +337,9 @@ namespace dd4hep { /// standard c'tor with all necessary arguments - origin is (0,0,0) if not given. VolPlaneImpl( SurfaceType typ, double thickness_inner ,double thickness_outer, - Vector3D u_val ,Vector3D v_val ,Vector3D n_val , Vector3D o_val, Volume vol, int id_val ) : + Vector3D u_val ,Vector3D v_val ,Vector3D n_val , Vector3D o_val, Volume vol, int id_val ) : - VolSurfaceBase( typ, thickness_inner, thickness_outer, u_val,v_val, n_val, o_val, vol, id_val ) { + VolSurfaceBase( typ, thickness_inner, thickness_outer, u_val,v_val, n_val, o_val, vol, id_val ) { _type.setProperty( SurfaceType::Plane , true ) ; _type.setProperty( SurfaceType::Cylinder , false ) ; @@ -442,7 +418,7 @@ namespace dd4hep { * the normal is chosen to be orthogonal to v. NB: the cone is always parallel to the local z axis. */ VolConeImpl( Volume vol, SurfaceType type, double thickness_inner ,double thickness_outer, - Vector3D v, Vector3D origin ) ; + Vector3D v, Vector3D origin ) ; /** First direction of measurement U - rotated to point projected onto the cone. * No check is done whether the point actually is on the cone surface @@ -469,7 +445,7 @@ namespace dd4hep { virtual Vector3D localToGlobal( const Vector2D& point) const ; virtual std::vector< std::pair<Vector3D, Vector3D> > getLines(unsigned nMax=100) ; - } ; + } ; @@ -486,9 +462,9 @@ namespace dd4hep { public: VolSurfaceHandle( Volume vol, SurfaceType typ, double thickness_inner ,double thickness_outer, - Vector3D u_val ,Vector3D v_val ,Vector3D n_val , Vector3D o_val = Vector3D(0.,0.,0.) ) : + Vector3D u_val ,Vector3D v_val ,Vector3D n_val , Vector3D o_val = Vector3D(0.,0.,0.) ) : - VolSurface( new T( typ, thickness_inner, thickness_outer, u_val, v_val, n_val, o_val, vol , 0 ) ){ + VolSurface( new T( typ, thickness_inner, thickness_outer, u_val, v_val, n_val, o_val, vol , 0 ) ){ } T* operator->() { return static_cast<T*>( _surf ) ; } @@ -527,13 +503,13 @@ namespace dd4hep { mutable VolSurface _volSurf ; std::unique_ptr<TGeoMatrix> _wtM ; // matrix for world transformation of surface - long64 _id ; + long64 _id {0}; - SurfaceType _type ; - Vector3D _u ; - Vector3D _v ; - Vector3D _n ; - Vector3D _o ; + SurfaceType _type {}; + Vector3D _u {}; + Vector3D _v {}; + Vector3D _n {}; + Vector3D _o {}; /// default c'tor etc. removed Surface() = delete; @@ -642,7 +618,7 @@ namespace dd4hep { ///Standard c'tor. CylinderSurface( DetElement det, VolSurface volSurf ) : Surface( det, volSurf ) { } - /** First direction of measurement U - rotated to point projected onto the cylinder. + /** First direction of measurement U - rotated to point projected onto the cylinder. * No check is done whether the point actually is on the cylinder surface */ virtual Vector3D u( const Vector3D& point = Vector3D() ) const ; @@ -705,28 +681,22 @@ namespace dd4hep { class SurfaceList : public std::list< ISurface* > { protected: - bool _isOwner ; + bool _isOwner {false}; public: /// defaul c'tor - allow to set ownership for surfaces - SurfaceList(bool isOwner=false ) : _isOwner( isOwner ) {} - + SurfaceList() = default; + /// defaul c'tor - allow to set ownership for surfaces + SurfaceList(bool isOwner ) : _isOwner( isOwner ) {} /// copy c'tor - SurfaceList(const SurfaceList& other ) : std::list< ISurface* >( other ), _isOwner( false ){} - + SurfaceList(const SurfaceList& other ) = default; /// required c'tor for extension mechanism - SurfaceList(const DetElement& ) : _isOwner( false ) { - // anything to do here ? - } + SurfaceList(const DetElement& ) {} /// required c'tor for extension mechanism - SurfaceList(const SurfaceList& ,const DetElement& ) : _isOwner( false ) { - // anything to do here ? - } - + SurfaceList(const SurfaceList& ,const DetElement& ) {} /// d'tor deletes all owned surfaces - virtual ~SurfaceList() ; - - } ; + virtual ~SurfaceList(); + }; // SurfaceList* surfaceList( DetElement& det ) ; diff --git a/DDRec/src/Surface.cpp b/DDRec/src/Surface.cpp index 144e2b09a7cc149d2846d476c5c336438a8702e9..0936cf00042e885605012699953f5361c59a8c62 100644 --- a/DDRec/src/Surface.cpp +++ b/DDRec/src/Surface.cpp @@ -32,7 +32,7 @@ namespace dd4hep { using namespace detail ; - //====================================================================================================== + //====================================================================================================== void VolSurfaceBase::setU(const Vector3D& u_val) { _u = u_val ; } void VolSurfaceBase::setV(const Vector3D& v_val) { _v = v_val ; } @@ -92,46 +92,46 @@ namespace dd4hep { if( volume()->GetShape()->Contains( o.const_array() ) ){ - dist_p = volume()->GetShape()->DistFromInside( const_cast<double*> ( o.const_array() ) , - const_cast<double*> ( u_val.const_array() ) ) ; - dist_m = volume()->GetShape()->DistFromInside( const_cast<double*> ( o.const_array() ) , - const_cast<double*> ( um.array() ) ) ; + dist_p = volume()->GetShape()->DistFromInside( const_cast<double*> ( o.const_array() ) , + const_cast<double*> ( u_val.const_array() ) ) ; + dist_m = volume()->GetShape()->DistFromInside( const_cast<double*> ( o.const_array() ) , + const_cast<double*> ( um.array() ) ) ; - // std::cout << " VolSurfaceBase::length_along_u() : shape contains(o) = " << volume()->GetShape()->Contains( o.const_array() ) - // << " dist_p " << dist_p - // << " dist_m " << dist_m - // << std::endl ; + // std::cout << " VolSurfaceBase::length_along_u() : shape contains(o) = " << volume()->GetShape()->Contains( o.const_array() ) + // << " dist_p " << dist_p + // << " dist_m " << dist_m + // << std::endl ; } else{ - dist_p = volume()->GetShape()->DistFromOutside( const_cast<double*> ( o.const_array() ) , - const_cast<double*> ( u_val.const_array() ) ) ; - dist_m = volume()->GetShape()->DistFromOutside( const_cast<double*> ( o.const_array() ) , - const_cast<double*> ( um.array() ) ) ; + dist_p = volume()->GetShape()->DistFromOutside( const_cast<double*> ( o.const_array() ) , + const_cast<double*> ( u_val.const_array() ) ) ; + dist_m = volume()->GetShape()->DistFromOutside( const_cast<double*> ( o.const_array() ) , + const_cast<double*> ( um.array() ) ) ; - dist_p *= 1.0001 ; - dist_m *= 1.0001 ; + dist_p *= 1.0001 ; + dist_m *= 1.0001 ; - // std::cout << " VolSurfaceBase::length_along_u() : shape contains(o) = " << volume()->GetShape()->Contains( o.const_array() ) - // << " dist_p " << dist_p - // << " dist_m " << dist_m - // << std::endl ; + // std::cout << " VolSurfaceBase::length_along_u() : shape contains(o) = " << volume()->GetShape()->Contains( o.const_array() ) + // << " dist_p " << dist_p + // << " dist_m " << dist_m + // << std::endl ; - Vector3D o_1 = this->origin() + dist_p * u_val ; - Vector3D o_2 = this->origin() + dist_m * um ; + Vector3D o_1 = this->origin() + dist_p * u_val ; + Vector3D o_2 = this->origin() + dist_m * um ; - dist_p += volume()->GetShape()->DistFromInside( const_cast<double*> ( o_1.const_array() ) , - const_cast<double*> ( u_val.const_array() ) ) ; + dist_p += volume()->GetShape()->DistFromInside( const_cast<double*> ( o_1.const_array() ) , + const_cast<double*> ( u_val.const_array() ) ) ; - dist_m += volume()->GetShape()->DistFromInside( const_cast<double*> ( o_2.const_array() ) , - const_cast<double*> ( um.array() ) ) ; + dist_m += volume()->GetShape()->DistFromInside( const_cast<double*> ( o_2.const_array() ) , + const_cast<double*> ( um.array() ) ) ; - // std::cout << " VolSurfaceBase::length_along_u() : shape contains(o) = " << volume()->GetShape()->Contains( o.const_array() ) - // << " dist_p " << dist_p - // << " dist_m " << dist_m - // << std::endl ; + // std::cout << " VolSurfaceBase::length_along_u() : shape contains(o) = " << volume()->GetShape()->Contains( o.const_array() ) + // << " dist_p " << dist_p + // << " dist_m " << dist_m + // << std::endl ; } return dist_p + dist_m ; @@ -155,46 +155,46 @@ namespace dd4hep { if( volume()->GetShape()->Contains( o.const_array() ) ){ - dist_p = volume()->GetShape()->DistFromInside( const_cast<double*> ( o.const_array() ) , - const_cast<double*> ( v_val.const_array() ) ) ; - dist_m = volume()->GetShape()->DistFromInside( const_cast<double*> ( o.const_array() ) , - const_cast<double*> ( vm.array() ) ) ; + dist_p = volume()->GetShape()->DistFromInside( const_cast<double*> ( o.const_array() ) , + const_cast<double*> ( v_val.const_array() ) ) ; + dist_m = volume()->GetShape()->DistFromInside( const_cast<double*> ( o.const_array() ) , + const_cast<double*> ( vm.array() ) ) ; - // std::cout << " VolSurfaceBase::length_along_u() : shape contains(o) = " << volume()->GetShape()->Contains( o.const_array() ) - // << " dist_p " << dist_p - // << " dist_m " << dist_m - // << std::endl ; + // std::cout << " VolSurfaceBase::length_along_u() : shape contains(o) = " << volume()->GetShape()->Contains( o.const_array() ) + // << " dist_p " << dist_p + // << " dist_m " << dist_m + // << std::endl ; } else{ - dist_p = volume()->GetShape()->DistFromOutside( const_cast<double*> ( o.const_array() ) , - const_cast<double*> ( v_val.const_array() ) ) ; - dist_m = volume()->GetShape()->DistFromOutside( const_cast<double*> ( o.const_array() ) , - const_cast<double*> ( vm.array() ) ) ; + dist_p = volume()->GetShape()->DistFromOutside( const_cast<double*> ( o.const_array() ) , + const_cast<double*> ( v_val.const_array() ) ) ; + dist_m = volume()->GetShape()->DistFromOutside( const_cast<double*> ( o.const_array() ) , + const_cast<double*> ( vm.array() ) ) ; - dist_p *= 1.0001 ; - dist_m *= 1.0001 ; + dist_p *= 1.0001 ; + dist_m *= 1.0001 ; - // std::cout << " VolSurfaceBase::length_along_u() : shape contains(o) = " << volume()->GetShape()->Contains( o.const_array() ) - // << " dist_p " << dist_p - // << " dist_m " << dist_m - // << std::endl ; + // std::cout << " VolSurfaceBase::length_along_u() : shape contains(o) = " << volume()->GetShape()->Contains( o.const_array() ) + // << " dist_p " << dist_p + // << " dist_m " << dist_m + // << std::endl ; - Vector3D o_1 = this->origin() + dist_p * v_val ; - Vector3D o_2 = this->origin() + dist_m * vm ; + Vector3D o_1 = this->origin() + dist_p * v_val ; + Vector3D o_2 = this->origin() + dist_m * vm ; - dist_p += volume()->GetShape()->DistFromInside( const_cast<double*> ( o_1.const_array() ) , - const_cast<double*> ( v_val.const_array() ) ) ; + dist_p += volume()->GetShape()->DistFromInside( const_cast<double*> ( o_1.const_array() ) , + const_cast<double*> ( v_val.const_array() ) ) ; - dist_m += volume()->GetShape()->DistFromInside( const_cast<double*> ( o_2.const_array() ) , - const_cast<double*> ( vm.array() ) ) ; + dist_m += volume()->GetShape()->DistFromInside( const_cast<double*> ( o_2.const_array() ) , + const_cast<double*> ( vm.array() ) ) ; - // std::cout << " VolSurfaceBase::length_along_u() : shape contains(o) = " << volume()->GetShape()->Contains( o.const_array() ) - // << " dist_p " << dist_p - // << " dist_m " << dist_m - // << std::endl ; + // std::cout << " VolSurfaceBase::length_along_u() : shape contains(o) = " << volume()->GetShape()->Contains( o.const_array() ) + // << " dist_p " << dist_p + // << " dist_m " << dist_m + // << std::endl ; } return dist_p + dist_m ; @@ -223,11 +223,11 @@ namespace dd4hep { if( type().isUnbounded() ){ - return std::abs ( distance( point ) ) < epsilon ; + return std::abs ( distance( point ) ) < epsilon ; } else { - return ( std::abs ( distance( point ) ) < epsilon && volume()->GetShape()->Contains( point.const_array() ) ) ; + return ( std::abs ( distance( point ) ) < epsilon && volume()->GetShape()->Contains( point.const_array() ) ) ; } #endif @@ -272,10 +272,10 @@ namespace dd4hep { double VolPlaneImpl::distance(const Vector3D& point ) const { return ( point - origin() ) * normal() ; } - //====================================================================================================== + //====================================================================================================== VolCylinderImpl::VolCylinderImpl( Volume vol, SurfaceType typ, - double thickness_inner ,double thickness_outer, Vector3D o ) : + double thickness_inner ,double thickness_outer, Vector3D o ) : VolSurfaceBase(typ, thickness_inner, thickness_outer, Vector3D() , Vector3D() , Vector3D() , o , vol, 0) { Vector3D v_val( 0., 0., 1. ) ; @@ -371,10 +371,10 @@ namespace dd4hep { _ztip = o_val.z() - tipoffset ; double dist_p = vol->GetShape()->DistFromInside( const_cast<double*> ( o_val.const_array() ) , - const_cast<double*> ( v_val.const_array() ) ) ; + const_cast<double*> ( v_val.const_array() ) ) ; Vector3D vm = -1. * v_val ; double dist_m = vol->GetShape()->DistFromInside( const_cast<double*> ( o_val.const_array() ) , - const_cast<double*> ( vm.array() ) ) ; + const_cast<double*> ( vm.array() ) ) ; double costh = std::cos( theta) ; _zt0 = tipoffset - dist_m * costh ; @@ -457,9 +457,9 @@ namespace dd4hep { //return dz * normal( point ) ; - double zp = point.z() - _ztip ; - double r = point.rho() - zp * _tanTheta ; - return r * std::cos( _v.theta() ) ; + double zp = point.z() - _ztip ; + double r = point.rho() - zp * _tanTheta ; + return r * std::cos( _v.theta() ) ; } @@ -486,21 +486,21 @@ namespace dd4hep { for( unsigned i = 0 ; i < n ; ++i ) { - Vector3D r0v0( r0*sin( i *dPhi ) , r0*cos( i *dPhi ) , 0. ) ; - Vector3D r0v1( r0*sin( (i+1)*dPhi ) , r0*cos( (i+1)*dPhi ) , 0. ) ; + Vector3D r0v0( r0*sin( i *dPhi ) , r0*cos( i *dPhi ) , 0. ) ; + Vector3D r0v1( r0*sin( (i+1)*dPhi ) , r0*cos( (i+1)*dPhi ) , 0. ) ; - Vector3D r1v0( r1*sin( i *dPhi ) , r1*cos( i *dPhi ) , 0. ) ; - Vector3D r1v1( r1*sin( (i+1)*dPhi ) , r1*cos( (i+1)*dPhi ) , 0. ) ; + Vector3D r1v0( r1*sin( i *dPhi ) , r1*cos( i *dPhi ) , 0. ) ; + Vector3D r1v1( r1*sin( (i+1)*dPhi ) , r1*cos( (i+1)*dPhi ) , 0. ) ; - Vector3D pl0 = zv + r1v0 ; - Vector3D pl1 = zv + r1v1 ; - Vector3D pl2 = -zv + r0v1 ; - Vector3D pl3 = -zv + r0v0 ; + Vector3D pl0 = zv + r1v0 ; + Vector3D pl1 = zv + r1v1 ; + Vector3D pl2 = -zv + r0v1 ; + Vector3D pl3 = -zv + r0v0 ; - lines.emplace_back( pl0, pl1 ); - lines.emplace_back( pl1, pl2 ); - lines.emplace_back( pl2, pl3 ); - lines.emplace_back( pl3, pl0 ); + lines.emplace_back( pl0, pl1 ); + lines.emplace_back( pl1, pl2 ); + lines.emplace_back( pl2, pl3 ); + lines.emplace_back( pl3, pl0 ); } return lines; } @@ -517,12 +517,9 @@ namespace dd4hep { //======================================================= SurfaceList::~SurfaceList(){ - if( _isOwner ) { // delete all surfaces attached to this volume - for( SurfaceList::iterator i=begin(), n=end() ; i !=n ; ++i ) { - delete (*i) ; - } + std::for_each(begin(), end(), detail::deleteObject<ISurface>); } } @@ -583,7 +580,7 @@ namespace dd4hep { +" [Internal error -- bad detector constructor]"); } - PlacedVolume pv_dau( daughter ); + PlacedVolume pv_dau( daughter ); if( findVolume( pv_dau , theVol , volList ) ) { @@ -606,7 +603,7 @@ namespace dd4hep { //====================================================================================================================== Surface::Surface( DetElement det, VolSurface volSurf ) : _det( det) , _volSurf( volSurf ), - _wtM() , _id( 0) , _type( _volSurf.type() ) { + _wtM() , _id( 0) , _type( _volSurf.type() ) { initialize() ; } @@ -634,13 +631,13 @@ namespace dd4hep { MaterialManager matMgr( _det.placement().volume() ) ; - Vector3D p = _o - innerThickness() * _n ; + Vector3D p = _o - innerThickness() * _n ; const MaterialVec& materials = matMgr.materialsBetween( _o , p ) ; - _volSurf.setInnerMaterial( materials.size() > 1 ? - matMgr.createAveragedMaterial( materials ) : - materials[0].first ) ; + _volSurf.setInnerMaterial( materials.size() > 1 ? + matMgr.createAveragedMaterial( materials ) : + materials[0].first ) ; } return mat ; } @@ -653,13 +650,13 @@ namespace dd4hep { MaterialManager matMgr( _det.placement().volume() ) ; - Vector3D p = _o + outerThickness() * _n ; + Vector3D p = _o + outerThickness() * _n ; const MaterialVec& materials = matMgr.materialsBetween( _o , p ) ; - _volSurf.setOuterMaterial( materials.size() > 1 ? - matMgr.createAveragedMaterial( materials ) : - materials[0].first ) ; + _volSurf.setOuterMaterial( materials.size() > 1 ? + matMgr.createAveragedMaterial( materials ) : + materials[0].first ) ; } return mat ; } @@ -802,12 +799,12 @@ namespace dd4hep { // =========== check parallel and orthogonal to Z =================== if( ! _type.isCone() ) { - //fixme: workaround for conical surfaces that should always be parallel to z - // however the check with the normal does not work here ... + //fixme: workaround for conical surfaces that should always be parallel to z + // however the check with the normal does not work here ... - _type.checkParallelToZ( *this ) ; + _type.checkParallelToZ( *this ) ; - _type.checkOrthogonalToZ( *this ) ; + _type.checkOrthogonalToZ( *this ) ; } //======== set the unique surface ID from the DetElement ( and placements below ? ) @@ -845,19 +842,19 @@ namespace dd4hep { const std::vector< std::pair<Vector3D, Vector3D> >& local_lines = _volSurf.getLines() ; if( local_lines.size() > 0 ) { - unsigned n=local_lines.size() ; - lines.reserve( n ) ; + unsigned n=local_lines.size() ; + lines.reserve( n ) ; - for( unsigned i=0;i<n;++i){ + for( unsigned i=0;i<n;++i){ - Vector3D av,bv; - _wtM->LocalToMaster( local_lines[i].first , av.array() ) ; - _wtM->LocalToMaster( local_lines[i].second , bv.array() ) ; + Vector3D av,bv; + _wtM->LocalToMaster( local_lines[i].first , av.array() ) ; + _wtM->LocalToMaster( local_lines[i].second , bv.array() ) ; - lines.emplace_back( av, bv ); - } + lines.emplace_back( av, bv ); + } - return lines ; + return lines ; } //-------------------------------------------- @@ -931,32 +928,32 @@ namespace dd4hep { // can only deal with special case of z-disk and origin in center of cone if( type().isZDisk() ) { // && lo.rho() < epsilon ) { - if( lo.rho() > epsilon ) { - // move origin to z-axis - lo.x() = 0. ; - lo.y() = 0. ; - } - - double zhalf = 0 ; - double rmax1 = 0 ; - double rmax2 = 0 ; - double rmin1 = 0 ; - double rmin2 = 0 ; - if( shape->InheritsFrom("TGeoTube") ) { - TGeoTube* tube = ( TGeoTube* ) shape ; - zhalf = tube->GetDZ() ; - rmax1 = tube->GetRmax() ; - rmax2 = tube->GetRmax() ; - rmin1 = tube->GetRmin() ; - rmin2 = tube->GetRmin() ; - } else { // shape->InheritsFrom("TGeoCone") ) - TGeoCone* cone = ( TGeoCone* ) shape ; - zhalf = cone->GetDZ() ; - rmax1 = cone->GetRmax1() ; - rmax2 = cone->GetRmax2() ; - rmin1 = cone->GetRmin1() ; - rmin2 = cone->GetRmin2() ; - } + if( lo.rho() > epsilon ) { + // move origin to z-axis + lo.x() = 0. ; + lo.y() = 0. ; + } + + double zhalf = 0 ; + double rmax1 = 0 ; + double rmax2 = 0 ; + double rmin1 = 0 ; + double rmin2 = 0 ; + if( shape->InheritsFrom("TGeoTube") ) { + TGeoTube* tube = ( TGeoTube* ) shape ; + zhalf = tube->GetDZ() ; + rmax1 = tube->GetRmax() ; + rmax2 = tube->GetRmax() ; + rmin1 = tube->GetRmin() ; + rmin2 = tube->GetRmin() ; + } else { // shape->InheritsFrom("TGeoCone") ) + TGeoCone* cone = ( TGeoCone* ) shape ; + zhalf = cone->GetDZ() ; + rmax1 = cone->GetRmax1() ; + rmax2 = cone->GetRmax2() ; + rmin1 = cone->GetRmin1() ; + rmin2 = cone->GetRmin2() ; + } // two circles around origin // get radii at position of plane @@ -1171,7 +1168,7 @@ namespace dd4hep { } else if( type().isCylinder() ) { - if( shape->InheritsFrom("TGeoTube") || shape->InheritsFrom("TGeoCone") ) { + if( shape->InheritsFrom("TGeoTube") || shape->InheritsFrom("TGeoCone") ) { lines.reserve( nMax ) ;