Commit 43d07bb2 authored by Sarka Todorova's avatar Sarka Todorova Committed by Graeme Stewart
Browse files

memory leak fix (TrkGeometry-02-02-05)

        * fix of memeory leak in the AlignableTV
        * tagged as TrkGeometry-02-02-05

2014-12-15 Goetz Gaycken
	* Fix coverity issue 11266 (copy without assign).
	* Fix coverity issue 11442 (possible memory leak).
	* Fix coverity issue 11443 (copy without assign).
	* Fix coverity issue 13986 (possible memory leak).

2014-12-11 Goetz Gaycken
	* Fix coverity issue 12074 (uninitialized pointer member).
	* Fix coverity issue 24932 (missing assignment in copy constructor).
	* Fix coverity issue 24907 (wrong end indicator to ostream).
	* Fix coverity issue 11565 and 11566 (misleading indention).
	* Fix coverity issue 11877 (uninitialised pointer member).
	* Fix coverity issue 24939-24945, 24948 (uninitialised member).
	* Fix coverity issue 24946 (uninitialised pointer member).
	* Fix coverity issue 24947 (uninitialised members).
	* Fix assignment operator (child object not cloned).
	* Fix coverity issues 24908 (pointless expression) and 11495
...
(Long ChangeLog diff - truncated)
parent 03f8be33
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// ApproachDescriptor.h, (c) ATLAS Detector software
///////////////////////////////////////////////////////////////////
#ifndef TRKGEOMETRY_APPROPACHDESCRIPTOR_H
#define TRKGEOMETRY_APPROPACHDESCRIPTOR_H
// Trk
#include "GeoPrimitives/GeoPrimitives.h"
#include "TrkSurfaces/Surface.h"
#include "TrkDetDescrUtils/BinnedArray.h"
namespace Trk {
/**
@class ApproachSurfaces
just implement the delete on the objects
*/
class ApproachSurfaces : public std::vector<const Surface*> {
public :
//* Default constructor */
ApproachSurfaces() :
std::vector<const Surface*>()
{}
//* Desctructur with cleanup*/
~ApproachSurfaces()
{
for (auto& sf : (*this))
delete sf;
}
};
/**
@class ApproachDescriptor
Class to decide and return which approaching surface to be taken,
it either has a
@author Andreas.Salzburger@cern.ch
*/
class ApproachDescriptor {
public:
/**Default constructor*/
ApproachDescriptor(ApproachSurfaces* aSurfaces, bool rebuild=true) :
m_approachSurfaces(aSurfaces),
m_approachSurfaceArraySurface(0),
m_approachSurfaceArray(0),
m_rebuild(rebuild)
{}
/**Default constructor*/
ApproachDescriptor(BinnedArray<ApproachSurfaces>* aSurfaceArray, Surface* aSurfaceArraySurface = 0):
m_approachSurfaces(0),
m_approachSurfaceArraySurface(aSurfaceArraySurface),
m_approachSurfaceArray(aSurfaceArray),
m_rebuild(false)
{}
/** register Layer */
void registerLayer(const Layer& lay);
/**Virtual destructor*/
virtual ~ApproachDescriptor(){}
/** Telling you if it needs to be rebuilt */
bool rebuild() const;
/** get the compatible surfaces
- return : a boolean indicating if an actual intersection had been tried
- fill vector of intersections
- primary bin surface : sf
- position & direction : pos, dir
*/
const ApproachSurfaces* approachSurfaces(const Amg::Vector3D& pos, const Amg::Vector3D& dir) const;
private :
/** register the Layer */
void registerLayerToSurfaces(const Layer& lay, const ApproachSurfaces& aSurfaces);
/** Copy constructor - private */
ApproachDescriptor(const ApproachDescriptor&):
m_approachSurfaces(0),
m_approachSurfaceArraySurface(0),
m_approachSurfaceArray(0)
{}
ApproachSurfaces* m_approachSurfaces;
Surface* m_approachSurfaceArraySurface;
BinnedArray<ApproachSurfaces>* m_approachSurfaceArray;
bool m_rebuild;
};
inline const ApproachSurfaces* ApproachDescriptor::approachSurfaces(const Amg::Vector3D& pos, const Amg::Vector3D& dir) const {
// return the single approach surfaces
if (m_approachSurfaces)
return (m_approachSurfaces);
// there's new surface given
if (m_approachSurfaceArraySurface){
Trk::Intersection asInter = m_approachSurfaceArraySurface->straightLineIntersection(pos,dir);
if (asInter.valid)
return (m_approachSurfaceArray->object(asInter.position));
}
// get the bin
return (m_approachSurfaceArray->object(pos));
}
inline bool ApproachDescriptor::rebuild() const { return m_rebuild; }
inline void ApproachDescriptor::registerLayer(const Layer& lay) {
if (m_approachSurfaces)
registerLayerToSurfaces(lay, *m_approachSurfaces);
if (m_approachSurfaceArraySurface){
m_approachSurfaceArraySurface->associateLayer(lay);
m_approachSurfaceArraySurface->setOwner(Trk::TGOwn);
}
if (m_approachSurfaceArray){
const std::vector<const ApproachSurfaces*>& aSurfaceObjects = m_approachSurfaceArray->arrayObjects();
for (auto& aSurfaces : aSurfaceObjects)
registerLayerToSurfaces(lay, *aSurfaces);
}
}
inline void ApproachDescriptor::registerLayerToSurfaces(const Layer& lay, const ApproachSurfaces& aSurfaces) {
for (auto& aSurface : aSurfaces){
aSurface->associateLayer(lay);
aSurface->setOwner(Trk::TGOwn);
}
}
}
#endif
......@@ -48,6 +48,14 @@ namespace Trk {
float correctionFactor,
const Trk::TrackingVolume* tvol,
const Trk::Layer* lay);
/** Constructor with Material */
AssociatedMaterial(const Amg::Vector3D& hitpos,
float steplength,
const Trk::Material&,
float correctionFactor,
const Trk::TrackingVolume* tvol,
const Trk::Layer* lay);
/** Constructor with Material Properties - ownership stays with holder*/
AssociatedMaterial(const Amg::Vector3D& hitpos,
......
......@@ -70,7 +70,7 @@ namespace Trk {
virtual ~BinnedLayerMaterial();
/**Pseudo-Constructor clone()*/
BinnedLayerMaterial* clone() const;
BinnedLayerMaterial* clone() const override;
/** Assignment operator */
BinnedLayerMaterial& operator=(const BinnedLayerMaterial& lmp);
......@@ -79,7 +79,7 @@ namespace Trk {
BinnedLayerMaterial& operator*=(double scale);
/** Return the BinUtility */
const BinUtility* binUtility() const;
const BinUtility* binUtility() const override;
/** Update the BinUtility if necessary - passing ownership of the utility class*/
void updateBinning(BinUtility* bu) const;
......@@ -91,12 +91,13 @@ namespace Trk {
const MaterialProperties* fullMaterial(const Amg::Vector3D& gp) const;
/** Access the single bin */
const MaterialProperties* material(size_t bin0, size_t bin1 ) const;
const MaterialProperties* material(size_t bin0, size_t bin1 ) const override;
/** Output Method for MsgStream, to be overloaded by child classes */
MsgStream& dump(MsgStream& sl) const;
MsgStream& dump(MsgStream& sl) const override;
/** Output Method for std::ostream, to be overloaded by child classes */
std::ostream& dump(std::ostream& sl) const;
std::ostream& dump(std::ostream& sl) const override;
private:
......
......@@ -65,8 +65,9 @@ namespace Trk {
virtual ~CompoundLayer();
virtual const Layer& layerRepresentation() const = 0;
//virtual const Surface& surfaceRepresentation() = 0;
const std::vector<const Surface*> constituentSurfaces() const;
virtual const std::vector<const Surface*> closestSurfaces(const Amg::Vector3D& gp, const Amg::Vector3D& dir, bool alsoBackward = false) const;
/// Searches through the surfaces with Layer specific tolerance to
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// CompoundLayerMaterial.h, (c) ATLAS Detector software
///////////////////////////////////////////////////////////////////
#ifndef TRKGEOMETRY_COMPOUNDLAYERMATERIAL_H
#define TRKGEOMETRY_COMPOUNDLAYERMATERIAL_H
//Trk
#include "TrkGeometry/ElementTable.h"
#include "TrkGeometry/Material.h"
#include "TrkGeometry/MaterialProperties.h"
#include "TrkGeometry/LayerMaterialProperties.h"
#include "TrkDetDescrUtils/BinUtility.h"
#include "TrkDetDescrUtils/SharedObject.h"
// Amg
#include "GeoPrimitives/GeoPrimitives.h"
//Gaudi
#include "GaudiKernel/MsgStream.h"
namespace Trk {
typedef std::vector<unsigned char> ValueVector;
typedef std::vector< ValueVector > ValueMatrix;
struct ValueStore {
float valueMin;
float valueStep;
ValueMatrix valueBinMatrix;
double value(unsigned char ibin0, unsigned char ibin1) {
// get the entry from the matrix
unsigned int ibin = static_cast<unsigned int>(valueBinMatrix[static_cast<unsigned int>(ibin1)][static_cast<unsigned int>(ibin0)]);
if (!ibin) return 0.;
double value = valueMin + (double(ibin)-0.5)*valueStep;
return value;
}
};
/**
@class CompoundLayerMaterial
It extends the LayerMaterialProperties base class,
and has a intrinsic accuracy of about 0.5 % on the dynamic range from using unsigned char
@author Andreas.Salzburger@cern.ch
*/
class CompoundLayerMaterial : public LayerMaterialProperties {
public:
/** Default Constructor - needed by POOL*/
CompoundLayerMaterial();
/**Explizit constructor */
CompoundLayerMaterial(const Trk::BinUtility& binutility,
const ValueStore& thicknessBins,
const ValueStore& x0Bins,
const ValueStore& l0Bins,
const ValueStore& aBins,
const ValueStore& zBins,
const ValueStore& rhoBins,
const std::vector< std::vector< MaterialComposition > >& composition,
bool fComposition = false);
/**Copy Constructor */
CompoundLayerMaterial(const CompoundLayerMaterial& mprop);
/**Destructor*/
virtual ~CompoundLayerMaterial();
/**Pseudo-Constructor clone()*/
CompoundLayerMaterial* clone() const;
/** Assignment operator */
CompoundLayerMaterial& operator=(const CompoundLayerMaterial& lmp);
/** Scale operator */
CompoundLayerMaterial& operator*=(double scale);
/** Return the BinUtility */
const BinUtility* binUtility() const override;
/** Update the BinUtility if necessary - passing ownership of the utility class*/
void updateBinning(BinUtility* bu) const;
/**Return method for full material description of the Layer */
const MaterialProperties* fullMaterial(const Amg::Vector3D& gp) const;
/** Access the single bin */
const MaterialProperties* material(size_t bin0, size_t bin1) const override;
/** Update the ElementTable */
void updateElementTable(const SharedObject<const ElementTable>& set) const;
/** Get the ElementTable */
const ElementTable* elementTable() const;
/** Output Method for MsgStream, to be overloaded by child classes */
MsgStream& dump(MsgStream& sl) const override;
/** Output Method for std::ostream, to be overloaded by child classes */
std::ostream& dump(std::ostream& sl) const override;
private:
mutable MaterialProperties* m_materialProperties; //!< the ones you return
mutable BinUtility* m_binUtility; //!< the helper for the bin finding
mutable ValueStore m_thicknessBins; //!< thickness parameter
mutable ValueStore m_x0Bins; //!< x0 parameter
mutable ValueStore m_l0Bins; //!< l0 parameter
mutable ValueStore m_aBins; //!< A parameters (averaged)
mutable ValueStore m_zBins; //!< Z parameter (averaged)
mutable ValueStore m_rhoBins; //!< rho parameter (averaged)
mutable std::vector< std::vector< MaterialComposition > > m_composition; //!< composition matrix
bool m_fullComposition; //!< full composition calculation
mutable SharedObject<const ElementTable> m_elementTable; // the ElementTable (filled/synchronised)
};
inline const BinUtility* CompoundLayerMaterial::binUtility() const
{ return m_binUtility; }
inline void CompoundLayerMaterial::updateElementTable(const SharedObject<const ElementTable>& set) const
{ m_elementTable = set; }
inline void CompoundLayerMaterial::updateBinning(BinUtility* bu) const
{
if (bu){
delete m_binUtility;
m_binUtility = bu;
}
}
inline const ElementTable* CompoundLayerMaterial::elementTable() const
{ return m_elementTable.getPtr(); }
}
#endif
......@@ -59,7 +59,7 @@ namespace Trk {
virtual ~CompressedLayerMaterial();
/**Pseudo-Constructor clone()*/
CompressedLayerMaterial* clone() const;
CompressedLayerMaterial* clone() const override;
/** Assignment operator */
CompressedLayerMaterial& operator=(const CompressedLayerMaterial& lmp);
......@@ -68,7 +68,7 @@ namespace Trk {
CompressedLayerMaterial& operator*=(double scale);
/** Return the BinUtility */
const BinUtility* binUtility() const;
const BinUtility* binUtility() const override;
/** Update the BinUtility if necessary - passing ownership of the utility class*/
void updateBinning(BinUtility* bu) const;
......@@ -80,15 +80,15 @@ namespace Trk {
const std::vector<unsigned short int>& materialBins() const;
/**Return method for full material description of the Layer */
const MaterialProperties* fullMaterial(const Amg::Vector3D& gp) const;
const MaterialProperties* fullMaterial(const Amg::Vector3D& gp) const override;
/** Access the single bin */
const MaterialProperties* material(size_t bin0, size_t bin1) const;
const MaterialProperties* material(size_t bin0, size_t bin1) const override;
/** Output Method for MsgStream, to be overloaded by child classes */
MsgStream& dump(MsgStream& sl) const;
MsgStream& dump(MsgStream& sl) const override;
/** Output Method for std::ostream, to be overloaded by child classes */
std::ostream& dump(std::ostream& sl) const;
std::ostream& dump(std::ostream& sl) const override;
private:
mutable BinUtility* m_binUtility; //!< the helper for the bin finding
......
......@@ -42,9 +42,9 @@ namespace Trk {
virtual const ConeCylinderConeLayer& layerRepresentation() const {return (*this);}
virtual const CylinderSurface& surfaceRepresentation() const {return (*this);}
virtual const CylinderSurface& surfaceRepresentation() const override {return (*this);}
virtual bool isOnLayer(const Amg::Vector3D& gp) const {return isOnCompoundLayer(gp,0.5*thickness());}
virtual bool isOnLayer(const Amg::Vector3D& gp, const BoundaryCheck&) const {return isOnCompoundLayer(gp,0.5*thickness());}
double radius(const Amg::Vector3D& gp) const
{
......
......@@ -88,28 +88,23 @@ namespace Trk {
virtual ~ConeLayer(){}
/** Transforms the layer into a Surface representation for extrapolation */
const ConeSurface& surfaceRepresentation() const;
const ConeSurface& surfaceRepresentation() const override;
/** getting the MaterialProperties back - for pre-update*/
double preUpdateMaterialFactor(const Trk::TrackParameters& par,
Trk::PropDirection dir) const;
double preUpdateMaterialFactor(const Trk::TrackParameters& par, Trk::PropDirection dir) const override;
/** getting the MaterialProperties back - for post-update*/
double postUpdateMaterialFactor(const Trk::TrackParameters& par,
Trk::PropDirection dir) const;
/** Return the path correction */
double pathCorrection(const TrackParameters& par) const;
double postUpdateMaterialFactor(const Trk::TrackParameters& par, Trk::PropDirection dir) const override;
/** move the Layer */
void moveLayer(Amg::Transform3D& shift) const;
void moveLayer(Amg::Transform3D& shift) const override;
private:
/** Resize the layer to the tracking volume - not (yet) supported for ConeLayer */
void resize(const VolumeBounds&, double) const {}
/** Resize the layer to the tracking volume - not supported since this an entry layer method*/
void resizeAndRepositionLayer(const VolumeBounds&, const Amg::Vector3D&, double) const {}
void resizeAndRepositionLayer(const VolumeBounds&, const Amg::Vector3D&, double) const override {}
};
......
......@@ -26,6 +26,7 @@ namespace Trk {
class CylinderBounds;
class LayerMaterialProperties;
class OverlapDescriptor;
class ApproachDescriptor;
/**
@class CylinderLayer
......@@ -57,12 +58,15 @@ class OverlapDescriptor;
OverlapDescriptor* od = 0,
int laytyp=int(Trk::active));
/**Constructor with CylinderSurface components and pointer to SurfaceArray (passing ownership) */
/**Constructor with CylinderSurface components and pointer to SurfaceArray (passing ownership)
- has optionally an OverlapDescriptor and ApproachDescriptor for the surfaceArray
*/
CylinderLayer(Amg::Transform3D* transform,
CylinderBounds* cbounds,
SurfaceArray* surfaceArray,
double thickness = 0.,
OverlapDescriptor* od = 0,
ApproachDescriptor* ad = 0,
int laytyp=int(Trk::active));
/**Constructor with CylinderSurface components,
......@@ -73,6 +77,7 @@ class OverlapDescriptor;
const LayerMaterialProperties& laymatprop,
double thickness = 0.,
OverlapDescriptor* od = 0,
ApproachDescriptor* ad = 0,
int laytyp=int(Trk::active));
/**Concentric Layer: Constructor with CylinderSurface components and MaterialProperties */
......@@ -87,6 +92,7 @@ class OverlapDescriptor;
SurfaceArray* surfaceArray,
double thickness = 0.,
OverlapDescriptor* od = 0,
ApproachDescriptor* ad = 0,
int laytyp=int(Trk::active));
/**Concentric Layer: Constructor with CylinderSurface components,
......@@ -96,6 +102,7 @@ class OverlapDescriptor;
const LayerMaterialProperties& laymatprop,
double thickness = 0.,
OverlapDescriptor* od = 0,
ApproachDescriptor* ad = 0,
int laytyp=int(Trk::active));
/**Copy constructor of CylinderLayer*/
......@@ -108,31 +115,50 @@ class OverlapDescriptor;
CylinderLayer& operator=(const CylinderLayer&);
/**Destructor*/
virtual ~CylinderLayer(){}
virtual ~CylinderLayer();
/** Transforms the layer into a Surface representation for extrapolation */
const CylinderSurface& surfaceRepresentation() const;
const CylinderSurface& surfaceRepresentation() const override;
/** getting the MaterialProperties back - for pre-update*/
double preUpdateMaterialFactor(const Trk::TrackParameters& par,
Trk::PropDirection dir) const;
Trk::PropDirection dir) const override;
/** getting the MaterialProperties back - for post-update*/
double postUpdateMaterialFactor(const Trk::TrackParameters& par,
Trk::PropDirection dir) const;
/** Return the path correction */
double pathCorrection(const TrackParameters& par) const;
Trk::PropDirection dir) const override;
/** Surface seen on approach - if not defined differently, it is the surfaceRepresentation() */
const Surface& surfaceOnApproach(const Amg::Vector3D& pos,
const Amg::Vector3D& dir,
PropDirection pdir,
BoundaryCheck& bcheck,
bool resolveSubSurfaces = 0,
const ICompatibilityEstimator* ice = 0) const override;
/** move the Layer */
void moveLayer( Amg::Transform3D& shift ) const;
void moveLayer( Amg::Transform3D& shift ) const override;
private:
/** Resize the layer to the tracking volume - only works for CylinderVolumeBouns */
void resizeLayer(const VolumeBounds& vBounds, double envelope) const;
void resizeLayer(const VolumeBounds& vBounds, double envelope) const override;
/** Resize the layer to the tracking volume */
void resizeAndRepositionLayer(const VolumeBounds& vBounds, const Amg::Vector3D& cCenter, double envelope) const;
void resizeAndRepositionLayer(const VolumeBounds& vBounds, const Amg::Vector3D& cCenter, double envelope) const override;
/** build approach surfaces */
void buildApproachDescriptor() const;
/** Surface seen on approach - if not defined differently, it is the surfaceRepresentation() */
const Surface& approachSurface(const Amg::Vector3D& pos,
const Amg::Vector3D& dir,
BoundaryCheck& bcheck) const;
/** surfaces on approach to the layer */
mutable ApproachDescriptor* m_approachDescriptor;
};
/** @class CylinderLayerSorterR
......
......@@ -78,11 +78,14 @@ namespace Trk {
const std::vector<const Layer*>* multilayerRepresentation() const;
/** sign the volume - the geometry builder has to do that */
void sign(GeometrySignature signat) const;
void sign(GeometrySignature signat, GeometryType geotype) const;
/** return the Signature */
GeometrySignature geometrySignature() const;
/** return the Type */
GeometryType geometryType() const;
/** set the simplified calculable components */
void saveConstituents(std::vector<std::pair<const Trk::Volume*,float> >* ) const;
......
......@@ -26,6 +26,8 @@ namespace Trk {
class VolumeBounds;
class LayerMaterialProperties;
class OverlapDescriptor;
class ApproachDescriptor;
/**
@class DiscLayer
......@@ -65,6 +67,7 @@ namespace Trk {
SurfaceArray* surfaceArray,
double isontolerance = 0.,
OverlapDescriptor* od = 0,
ApproachDescriptor* ad = 0,
int laytyp=int(Trk::active));
/**Constructor with DiscSurface components,
......@@ -75,6 +78,7 @@ namespace Trk {
const LayerMaterialProperties& laymatprop,
double thickness = 0.,