IAP GITLAB
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
corsika
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
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
Pranav Sampathkumar
corsika
Commits
4751b8c4
Commit
4751b8c4
authored
5 years ago
by
ralfulrich
Committed by
Maximilian Reininghaus
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fixed bug in SecondaryView::Delete
parent
1d3ef7f6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Framework/StackInterface/SecondaryView.h
+29
-10
29 additions, 10 deletions
Framework/StackInterface/SecondaryView.h
Framework/StackInterface/testSecondaryView.cc
+5
-15
5 additions, 15 deletions
Framework/StackInterface/testSecondaryView.cc
with
34 additions
and
25 deletions
Framework/StackInterface/SecondaryView.h
+
29
−
10
View file @
4751b8c4
...
@@ -43,14 +43,18 @@ namespace corsika::stack {
...
@@ -43,14 +43,18 @@ namespace corsika::stack {
All operations possible on a Stack object are also possible on a
All operations possible on a Stack object are also possible on a
SecondaryView object. This means you can add, delete, copy, swap,
SecondaryView object. This means you can add, delete, copy, swap,
iterate, etc.
iterate, etc.
*/
/* INTERNAL NOTE FOR DEVELOPERS The secondary particle indices are
*Further information about implementation (for developers):* All
stored in a std::vector fIndices, the index of the primary projectle
data is stored in the original stack privided at construction
particle is explicitly stored in fProjectileIndex. StackIterator
time. The secondary particle (view) indices are stored in an
indices are refering to those numbers, where
extra std::vector of SecondaryView class 'fIndices' referring to
StackIterator::GetIndex()==0 refers to the fProjectileIndex and
the original stack slot indices. The index of the primary
StackIterator::GetIndex()>0 to fIndices[i+1], see function GetIndexFromIterator.
projectle particle is also explicitly stored in
'fProjectileIndex'. StackIterator indices
'i = StackIterator::GetIndex()' are referring to those numbers,
where 'i==0' refers to the 'fProjectileIndex', and
'StackIterator::GetIndex()>0' to 'fIndices[i-1]', see function
GetIndexFromIterator.
*/
*/
template
<
typename
StackDataType
,
template
<
typename
>
typename
ParticleInterface
>
template
<
typename
StackDataType
,
template
<
typename
>
typename
ParticleInterface
>
...
@@ -125,8 +129,11 @@ namespace corsika::stack {
...
@@ -125,8 +129,11 @@ namespace corsika::stack {
template
<
typename
...
Args
>
template
<
typename
...
Args
>
auto
AddSecondary
(
StackIterator
&
proj
,
const
Args
...
v
)
{
auto
AddSecondary
(
StackIterator
&
proj
,
const
Args
...
v
)
{
// make space on stack
InnerStackType
::
GetStackData
().
IncrementSize
();
InnerStackType
::
GetStackData
().
IncrementSize
();
// get current number of secondaries on stack
const
unsigned
int
idSec
=
GetSize
();
const
unsigned
int
idSec
=
GetSize
();
// determine index on (inner) stack where new particle will be located
const
unsigned
int
index
=
InnerStackType
::
GetStackData
().
GetSize
()
-
1
;
const
unsigned
int
index
=
InnerStackType
::
GetStackData
().
GetSize
()
-
1
;
fIndices
.
push_back
(
index
);
fIndices
.
push_back
(
index
);
// NOTE: "+1" is since "0" is special marker here for PROJECTILE, see
// NOTE: "+1" is since "0" is special marker here for PROJECTILE, see
...
@@ -161,14 +168,26 @@ namespace corsika::stack {
...
@@ -161,14 +168,26 @@ namespace corsika::stack {
/// @}
/// @}
/**
/**
* need overwrite Stack::Delete, since we want to call SecondaryView::DeleteLast
* need overwrite Stack::Delete, since we want to call
* SecondaryView::DeleteLast
*
* The particle is deleted on the underlying (internal) stack. The
* local references in SecondaryView in fIndices must be fixed,
* too. The approach is to a) check if the particle 'p' is at the
* very end of the internal stack, b) if not: move it there by
* copying the last particle to the current particle location, c)
* remove the last particle.
*
*/
*/
void
Delete
(
StackIterator
p
)
{
void
Delete
(
StackIterator
p
)
{
if
(
IsEmpty
())
{
/* error */
if
(
IsEmpty
())
{
/* error */
throw
std
::
runtime_error
(
"Stack, cannot delete entry since size is zero"
);
throw
std
::
runtime_error
(
"Stack, cannot delete entry since size is zero"
);
}
}
if
(
p
.
GetIndex
()
<
GetSize
()
-
1
)
const
int
innerSize
=
InnerStackType
::
GetSize
();
InnerStackType
::
GetStackData
().
Copy
(
GetSize
()
-
1
,
p
.
GetIndex
());
const
int
innerIndex
=
GetIndexFromIterator
(
p
.
GetIndex
());
if
(
innerIndex
<
innerSize
-
1
)
InnerStackType
::
GetStackData
().
Copy
(
innerSize
-
1
,
GetIndexFromIterator
(
p
.
GetIndex
()));
DeleteLast
();
DeleteLast
();
}
}
...
...
This diff is collapsed.
Click to expand it.
Framework/StackInterface/testSecondaryView.cc
+
5
−
15
View file @
4751b8c4
...
@@ -137,6 +137,7 @@ TEST_CASE("SecondaryStack", "[stack]") {
...
@@ -137,6 +137,7 @@ TEST_CASE("SecondaryStack", "[stack]") {
SECTION
(
"deletion"
)
{
SECTION
(
"deletion"
)
{
StackTest
stack
;
StackTest
stack
;
stack
.
AddParticle
(
std
::
tuple
{
-
99.
});
stack
.
AddParticle
(
std
::
tuple
{
0.
});
stack
.
AddParticle
(
std
::
tuple
{
0.
});
{
{
...
@@ -149,27 +150,21 @@ TEST_CASE("SecondaryStack", "[stack]") {
...
@@ -149,27 +150,21 @@ TEST_CASE("SecondaryStack", "[stack]") {
proj
.
AddSecondary
(
std
::
tuple
{
1.
});
proj
.
AddSecondary
(
std
::
tuple
{
1.
});
proj
.
AddSecondary
(
std
::
tuple
{
2.
});
proj
.
AddSecondary
(
std
::
tuple
{
2.
});
CHECK
(
stack
.
GetSize
()
==
5
);
CHECK
(
stack
.
GetSize
()
==
6
);
// -99, 0, -2, -1, 1, 2
CHECK
(
view
.
GetSize
()
==
4
);
// -2, -1, 1, 2
// now delete all negative entries, i.e. -1 and -2
// now delete all negative entries, i.e. -1 and -2
auto
p
=
view
.
begin
();
auto
p
=
view
.
begin
();
while
(
p
!=
view
.
end
())
{
while
(
p
!=
view
.
end
())
{
auto
data
=
p
.
GetData
();
auto
data
=
p
.
GetData
();
if
(
data
<
0
)
{
if
(
data
<
0
)
{
std
::
cout
<<
"deleting "
<<
data
<<
", "
;
p
.
Delete
();
p
.
Delete
();
}
else
{
}
else
{
++
p
;
++
p
;
}
}
}
}
CHECK
(
stack
.
GetSize
()
==
4
);
// -99, 0, 2, 1
// stack should contain 0, 1, 2 now
CHECK
(
view
.
GetSize
()
==
2
);
// 2, 1
CHECK
(
stack
.
GetSize
()
==
3
);
std
::
cout
<<
std
::
endl
;
for
(
auto
&
p
:
stack
)
{
std
::
cout
<<
p
.
GetData
()
<<
" | "
;
}
std
::
cout
<<
std
::
endl
;
}
}
// repeat
// repeat
...
@@ -190,7 +185,6 @@ TEST_CASE("SecondaryStack", "[stack]") {
...
@@ -190,7 +185,6 @@ TEST_CASE("SecondaryStack", "[stack]") {
while
(
p
!=
view
.
end
())
{
while
(
p
!=
view
.
end
())
{
auto
data
=
p
.
GetData
();
auto
data
=
p
.
GetData
();
if
(
data
<
0
)
{
if
(
data
<
0
)
{
std
::
cout
<<
"deleting "
<<
data
<<
", "
;
p
.
Delete
();
p
.
Delete
();
}
else
{
}
else
{
++
p
;
++
p
;
...
@@ -201,10 +195,6 @@ TEST_CASE("SecondaryStack", "[stack]") {
...
@@ -201,10 +195,6 @@ TEST_CASE("SecondaryStack", "[stack]") {
// view should contain 1, 2
// view should contain 1, 2
CHECK
(
stack
.
GetSize
()
==
6
);
CHECK
(
stack
.
GetSize
()
==
6
);
std
::
cout
<<
std
::
endl
;
for
(
auto
&
p
:
stack
)
{
std
::
cout
<<
p
.
GetData
()
<<
" | "
;
}
std
::
cout
<<
std
::
endl
;
}
}
}
}
}
}
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