Skip to content
Snippets Groups Projects

PrFTZoneHandler - Check array bounds before access

Merged Christopher Rob Jones requested to merge jonrob/Rec:PrZone-add-array-bounds-checks into master
All threads resolved!
2 files
+ 42
29
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -15,6 +15,8 @@
#include "FTDet/DeFTDetector.h"
#include "Kernel/DetectorSegment.h"
#include "PrKernel/PrHitZone.h"
#include <cassert>
#include <stdexcept>
namespace FTZoneCache {
@@ -31,32 +33,35 @@ namespace FTZoneCache {
PrFTZoneHandler( DeFT const& ftDet ) {
#ifdef USE_DD4HEP
auto func = [this]( const DeFTLayer& layer ) {
int id = layer.layerID();
const auto id = layer.layerID();
// fixme
DetectorSegment seg( 0, layer.globalZ(), layer.dxdy(), layer.dzdy(), 0., 0. );
float xmax = 0.5f * layer.sizeX();
float ymax = 0.5f * layer.sizeY();
const auto xmax = 0.5f * layer.sizeX();
const auto ymax = 0.5f * layer.sizeY();
// The setGeometry defines the z at y=0, the dxDy and the dzDy, as well as the isX properties of the zone.
// This is important, since these are used in the following.
// They are set once for each zone in this method.
this->MakeZone( 2 * id + 1, seg, -xmax, xmax, -25.f, ymax ); // Small overlap (25 mm) for stereo layers
this->MakeZone( 2 * id, seg, -xmax, xmax, -ymax, 25.f ); // Small overlap (25 mm) for stereo layers
const bool ok =
( this->MakeZone( 2 * id + 1, seg, -xmax, xmax, -25.f, ymax ) && // Small overlap (25 mm) for stereo layers
this->MakeZone( 2 * id, seg, -xmax, xmax, -ymax, 25.f ) ); // Small overlap (25 mm) for stereo layers
if ( !ok ) { throw std::runtime_error( "Failed to create DeFT Zones for ID = " + std::to_string( id ) ); }
};
ftDet.applyToAllLayers( func );
#else
for ( auto station : ftDet.stations() ) {
for ( auto layer : station->layers() ) {
int id = 4 * ( station->stationID() - 1 ) + layer->layerID();
const auto id = 4 * ( station->stationID() - 1 ) + layer->layerID();
DetectorSegment seg( 0, layer->globalZ(), layer->dxdy(), layer->dzdy(), 0., 0. );
float xmax = 0.5f * layer->sizeX();
float ymax = 0.5f * layer->sizeY();
const auto xmax = 0.5f * layer->sizeX();
const auto ymax = 0.5f * layer->sizeY();
// The setGeometry defines the z at y=0, the dxDy and the dzDy, as well as the isX properties of the zone.
// This is important, since these are used in the following.
// They are set once for each zone in this method.
this->MakeZone( 2 * id + 1, seg, -xmax, xmax, -25.f, ymax ); // Small overlap (25 mm) for stereo layers
this->MakeZone( 2 * id, seg, -xmax, xmax, -ymax, 25.f ); // Small overlap (25 mm) for stereo layers
const bool ok =
( this->MakeZone( 2 * id + 1, seg, -xmax, xmax, -25.f, ymax ) && // Small overlap (25 mm) for stereo
// layers
this->MakeZone( 2 * id, seg, -xmax, xmax, -ymax, 25.f ) ); // Small overlap (25 mm) for stereo layers
if ( !ok ) { throw std::runtime_error( "Failed to create DeFT Zones for ID = " + std::to_string( id ) ); }
}
}
#endif
@@ -64,10 +69,20 @@ namespace FTZoneCache {
/// Standard constructor
PrFTZoneHandler() = default;
void MakeZone( unsigned int n, DetectorSegment& seg, float xMin, float xMax, float yMin, float yMax ) {
m_zones[n].setZone( n, seg, xMin, xMax, yMin, yMax );
bool MakeZone( unsigned int n, DetectorSegment& seg, float xMin, float xMax, float yMin, float yMax ) {
if ( n < m_zones.size() ) {
m_zones[n].setZone( n, seg, xMin, xMax, yMin, yMax );
return true;
} else {
return false;
}
}
const PrHitZone& zone( unsigned int n ) const {
if ( n >= m_zones.size() ) {
throw std::runtime_error( "Zone index " + std::to_string( n ) + " is out-of-range" );
}
return m_zones[n];
}
const PrHitZone& zone( unsigned int n ) const { return m_zones[n]; }
template <PrHitZone::Side SIDE>
static int getXZone( int layer ) {
@@ -112,7 +127,6 @@ namespace FTZoneCache {
std::array<float, PrFTInfo::NFTZones> zoneDxDy{std::numeric_limits<float>::signaling_NaN()};
std::array<float, PrFTInfo::NFTZones> zoneDzDy{std::numeric_limits<float>::signaling_NaN()};
std::array<float, PrFTInfo::NFTZones> zoneZPos{std::numeric_limits<float>::signaling_NaN()};
ZoneCache() = default; // Needed by DD4hep even if unused !
ZoneCache( const DeFT& ftDet ) : handler( ftDet ) {
for ( int i{0}; i < PrFTInfo::NFTLayers; ++i ) {
zoneZPos[2 * i] = handler.zone( 2 * i ).z();
Loading