Skip to content
Snippets Groups Projects
Commit c9724a45 authored by Christopher Rob Jones's avatar Christopher Rob Jones
Browse files

Merge branch 'PrZone-add-array-bounds-checks' into 'master'

PrFTZoneHandler - Check array bounds before access

See merge request !3052
parents fa60652b 5faf43fc
No related branches found
No related tags found
1 merge request!3052PrFTZoneHandler - Check array bounds before access
Pipeline #4309782 passed
......@@ -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();
......
......@@ -8,8 +8,8 @@
* granted to it by virtue of its status as an Intergovernmental Organization *
* or submit itself to any jurisdiction. *
\*****************************************************************************/
#ifndef PRKERNEL_PRHITZONE_H
#define PRKERNEL_PRHITZONE_H 1
#pragma once
// Include files
#include "Kernel/DetectorSegment.h"
......@@ -58,15 +58,14 @@ public:
float dxOnAFibre() const { return ( m_yMax - m_yMin ) * m_dxDy; }
private:
unsigned int m_number;
unsigned int m_planeCode;
float m_z;
float m_dxDy;
float m_dzDy;
bool m_isX;
float m_xMin;
float m_xMax;
float m_yMin;
float m_yMax;
unsigned int m_number{};
unsigned int m_planeCode{};
float m_z{};
float m_dxDy{};
float m_dzDy{};
bool m_isX{};
float m_xMin{};
float m_xMax{};
float m_yMin{};
float m_yMax{};
};
#endif // PRKERNEL_PRHITZONE_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment