Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ApplicationCore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
ChimeraTK Mirror
ApplicationCore
Commits
3693cade
Commit
3693cade
authored
4 years ago
by
Jens Georg
Browse files
Options
Downloads
Patches
Plain Diff
Modify doPost[Read|Write] for new behavior
Fixes #153
parent
dd11913a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/ConsumingFanOut.h
+2
-0
2 additions, 0 deletions
include/ConsumingFanOut.h
include/FeedingFanOut.h
+56
-11
56 additions, 11 deletions
include/FeedingFanOut.h
with
58 additions
and
11 deletions
include/ConsumingFanOut.h
+
2
−
0
View file @
3693cade
...
...
@@ -28,6 +28,8 @@ namespace ChimeraTK {
void
doPostRead
(
TransferType
type
,
bool
hasNewData
)
override
{
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doPostRead
(
type
,
hasNewData
);
if
(
!
hasNewData
)
return
;
for
(
auto
&
slave
:
FanOut
<
UserType
>::
slaves
)
{
// send out copies to slaves
// do not send copy if no data is expected (e.g. trigger)
if
(
slave
->
getNumberOfSamples
()
!=
0
)
{
...
...
This diff is collapsed.
Click to expand it.
include/FeedingFanOut.h
+
56
−
11
View file @
3693cade
...
...
@@ -11,9 +11,43 @@
#include
<ChimeraTK/NDRegisterAccessor.h>
#include
"FanOut.h"
#include
<functional>
#include
<sstream>
namespace
ChimeraTK
{
/**
* @brief The RuntimeErrorCollector struct
* Helper class to be used in loops which catches exceptions
* stores the reasons and can then throw an exception with a combined reson
* afterwards
*/
struct
RuntimeErrorCollector
{
std
::
stringstream
ss
;
bool
hasException
{
false
};
// Ideally, this would happen in the destructor
void
unwrap
()
{
if
(
not
hasException
)
return
;
auto
s
=
ss
.
str
();
s
.
pop_back
();
throw
runtime_error
(
s
);
}
bool
wrap
(
std
::
function
<
void
(
void
)
>
f
)
{
try
{
f
();
return
true
;
}
catch
(
runtime_error
&
ex
)
{
ss
<<
ex
.
what
()
<<
"
\n
"
;
return
false
;
}
}
};
/**
* NDRegisterAccessor implementation which distributes values written to this
* accessor out to any number of slaves.
...
...
@@ -92,16 +126,20 @@ namespace ChimeraTK {
void
doPostRead
(
TransferType
type
,
bool
hasNewData
)
override
{
if
(
!
_withReturn
)
throw
ChimeraTK
::
logic_error
(
"Read operation called on write-only variable."
);
assert
(
_hasReturnSlave
);
_returnSlave
->
postRead
(
type
,
hasNewData
);
_returnSlave
->
accessChannel
(
0
).
swap
(
ChimeraTK
::
NDRegisterAccessor
<
UserType
>::
buffer_2D
[
0
]);
// distribute return-channel update to the other slaves
for
(
auto
&
slave
:
FanOut
<
UserType
>::
slaves
)
{
// send out copies to slaves
if
(
slave
==
_returnSlave
)
continue
;
if
(
slave
->
getNumberOfSamples
()
!=
0
)
{
// do not send copy if no data is expected (e.g. trigger)
slave
->
accessChannel
(
0
)
=
ChimeraTK
::
NDRegisterAccessor
<
UserType
>::
buffer_2D
[
0
];
auto
_
=
cppext
::
finally
([
&
]{
_returnSlave
->
accessChannel
(
0
).
swap
(
ChimeraTK
::
NDRegisterAccessor
<
UserType
>::
buffer_2D
[
0
]);
// distribute return-channel update to the other slaves
for
(
auto
&
slave
:
FanOut
<
UserType
>::
slaves
)
{
// send out copies to slaves
if
(
slave
==
_returnSlave
)
continue
;
if
(
slave
->
getNumberOfSamples
()
!=
0
)
{
// do not send copy if no data is expected (e.g. trigger)
slave
->
accessChannel
(
0
)
=
ChimeraTK
::
NDRegisterAccessor
<
UserType
>::
buffer_2D
[
0
];
}
slave
->
writeDestructively
(
_returnSlave
->
getVersionNumber
());
}
slave
->
writeDestructively
(
_returnSlave
->
getVersionNumber
());
}
});
_returnSlave
->
postRead
(
type
,
hasNewData
);
}
ChimeraTK
::
TransferFuture
doReadTransferAsync
()
override
{
...
...
@@ -121,11 +159,15 @@ namespace ChimeraTK {
}
slave
->
setDataValidity
(
this
->
dataValidity
());
}
// pre write may only be called on the target accessors after we have filled
// them all, otherwise the first accessor might take us the data away...
RuntimeErrorCollector
ec
;
for
(
auto
&
slave
:
FanOut
<
UserType
>::
slaves
)
{
slave
->
preWrite
(
type
);
ec
.
wrap
([
&
]
{
slave
->
preWrite
(
type
);
})
}
ec
.
unwrap
();
}
bool
doWriteTransfer
(
ChimeraTK
::
VersionNumber
versionNumber
=
{})
override
{
...
...
@@ -155,10 +197,13 @@ namespace ChimeraTK {
}
void
doPostWrite
(
TransferType
type
,
bool
dataLost
)
override
{
RuntimeErrorCollector
ec
;
for
(
auto
&
slave
:
FanOut
<
UserType
>::
slaves
)
{
slave
->
postWrite
(
type
,
dataLost
);
ec
.
wrap
([
&
]
{
slave
->
postWrite
(
type
,
dataLost
);
});
}
FanOut
<
UserType
>::
slaves
.
front
()
->
accessChannel
(
0
).
swap
(
ChimeraTK
::
NDRegisterAccessor
<
UserType
>::
buffer_2D
[
0
]);
ec
.
unwrap
();
}
bool
mayReplaceOther
(
const
boost
::
shared_ptr
<
const
ChimeraTK
::
TransferElement
>&
)
const
override
{
...
...
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