Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
athena
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Sherwood
athena
Commits
5e55f1ac
Commit
5e55f1ac
authored
4 years ago
by
Shaun Roe
Browse files
Options
Downloads
Patches
Plain Diff
Catch possibility of running offf the end of the eta bounds array
parent
a5b04f0f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tracking/TrkTools/TrkAmbiguityProcessor/src/AmbiCounter.icc
+18
-13
18 additions, 13 deletions
Tracking/TrkTools/TrkAmbiguityProcessor/src/AmbiCounter.icc
with
18 additions
and
13 deletions
Tracking/TrkTools/TrkAmbiguityProcessor/src/AmbiCounter.icc
+
18
−
13
View file @
5e55f1ac
...
...
@@ -10,6 +10,7 @@
#include
"TrkTrack/Track.h"
#include
<stdexcept>
#include
<algorithm>
#include
<optional>
template
<
class
EnumType
>
class
AmbiCounter
{
...
...
@@ -24,8 +25,11 @@ public:
};
//
AmbiCounter
(
const
std
::
vector
<
float
>
&
eta_bounds
)
:
m_etaBounds
(
eta_bounds
){
const
std
::
string
errMsg
=
"eta_bounds size must be "
+
std
::
to_string
(
nRegions
);
if
(
m_etaBounds
.
size
()
!=
nRegions
)
throw
std
::
out_of_range
(
errMsg
);
const
std
::
string
errMsgPrefix
=
"In AmbiCounter.icc, eta_bounds size must be "
;
if
(
m_etaBounds
.
size
()
!=
nRegions
)
throw
std
::
runtime_error
(
errMsgPrefix
+
std
::
to_string
(
nRegions
)
+
" elements long."
);
if
(
not
std
::
is_sorted
(
m_etaBounds
.
begin
(),
m_etaBounds
.
end
())){
throw
std
::
runtime_error
(
errMsgPrefix
+
"in ascending order."
);
}
}
//convert Category to array index
...
...
@@ -52,8 +56,11 @@ public:
}
// increment one bin
void
increment
(
Categories
categoryIdx
,
unsigned
int
etaBinIdx
)
{
++
m_counter
.
at
(
idx
(
categoryIdx
)).
at
(
etaBinIdx
);
increment
(
Categories
category
,
unsigned
int
etaBinIdx
)
{
if
((
category
>=
Categories
::
kNCounter
)
or
(
etaBinIdx
>=
nRegions
)){
throw
std
::
out_of_range
(
"in AmbiCounter.icc::increment()"
);
}
++
m_counter
[
idx
(
category
)][
etaBinIdx
];
}
//
AmbiCounter
<
EnumType
>
&
operator
+=
(
const
AmbiCounter
<
EnumType
>
&
a
)
{
...
...
@@ -81,7 +88,9 @@ public:
std
::
array
<
int
,
nRegions
>
&
nTracks
=
m_counter
.
at
(
idx
(
categoryIdx
));
// @TODO make sure that list of track parameters is not empty
const
double
absEta
=
std
::
abs
(
track
->
trackParameters
()
->
front
()
->
eta
());
++
nTracks
.
at
(
etaBin
(
absEta
));
if
(
const
auto
&
possibleIdx
{
etaBin
(
absEta
)}){
//i.e. if it's within bounds
++
nTracks
[
possibleIdx
.
value
()];
}
}
}
//
...
...
@@ -94,7 +103,6 @@ public:
const
auto
allRegionCounts
=
std
::
accumulate
(
displayedArray
.
begin
(),
displayedArray
.
end
(),
0
);
out
<<
std
::
setiosflags
(
std
::
ios
::
dec
)
<<
std
::
setw
(
iw
)
<<
allRegionCounts
;
for
(
unsigned
int
etaBinIdx
=
0
;
etaBinIdx
<
nRegions
;
++
etaBinIdx
)
{
assert
(
etaBinIdx
<
m_counter
[
idx
(
categoryIdx
)].
size
()
);
out
<<
std
::
setiosflags
(
std
::
ios
::
dec
)
<<
std
::
setw
(
iw
)
<<
m_counter
[
idx
(
categoryIdx
)][
etaBinIdx
];
}
out
<<
"
\n
"
;
...
...
@@ -110,14 +118,11 @@ private:
std
::
array
<
std
::
array
<
int
,
nRegions
>
,
static_cast
<
size_t
>
(
Categories
::
kNCounter
)
>
m_counter
{};
std
::
array
<
int
,
nGlobalCounters
>
m_globalCounter
{};
const
std
::
vector
<
float
>
&
m_etaBounds
;
//!< eta intervals for internal monitoring
size_t
std
::
optional
<
size_t
>
etaBin
(
const
double
val
){
size_t
regionIdx
{};
//eta *must be* in ascending order in the m_etaBounds vector
for
(;
regionIdx
<
nRegions
;
++
regionIdx
){
if
(
val
<
m_etaBounds
[
regionIdx
])
break
;
}
return
regionIdx
;
auto
pVal
=
std
::
lower_bound
(
m_etaBounds
.
begin
(),
m_etaBounds
.
end
(),
val
);
//if it's in bounds, return the value, otherwise return a nullopt
return
(
pVal
!=
m_etaBounds
.
end
())
?
std
::
optional
<
size_t
>
(
std
::
distance
(
m_etaBounds
.
begin
(),
pVal
))
:
std
::
nullopt
;
}
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment