Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ControlSystemAdapter-DoocsAdapter
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
ControlSystemAdapter-DoocsAdapter
Commits
1b99bd31
Commit
1b99bd31
authored
4 years ago
by
Martin Christoph Hierholzer
Browse files
Options
Downloads
Patches
Plain Diff
Slight optimisation: merge the 3 maps used in the updateLoop() into a single map with a struct.
This avoids multiple map lookups.
parent
817aeb58
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/DoocsUpdater.h
+9
-5
9 additions, 5 deletions
include/DoocsUpdater.h
src/DoocsUpdater.cc
+23
-14
23 additions, 14 deletions
src/DoocsUpdater.cc
with
32 additions
and
19 deletions
include/DoocsUpdater.h
+
9
−
5
View file @
1b99bd31
...
...
@@ -40,11 +40,15 @@ namespace ChimeraTK {
protected:
std
::
list
<
ChimeraTK
::
TransferElementAbstractor
>
_elementsToRead
;
boost
::
thread
_syncThread
;
// we have to use boost thread to use interruption points
// FIXME: make this an unordered map
std
::
map
<
ChimeraTK
::
TransferElementID
,
std
::
vector
<
std
::
function
<
void
()
>>>
_toDoocsUpdateMap
;
std
::
map
<
ChimeraTK
::
TransferElementID
,
std
::
vector
<
EqFct
*>>
_toDoocsEqFctMap
;
std
::
map
<
ChimeraTK
::
TransferElementID
,
std
::
set
<
boost
::
shared_ptr
<
ChimeraTK
::
TransferElement
>>>
_toDoocsAdditionalTransferElementsMap
;
// Struct used to aggregate the information needed in the updateLoop when an update is received from the
// application.
struct
ToDoocsUpdateDescriptor
{
std
::
vector
<
std
::
function
<
void
()
>>
updateFunctions
;
std
::
vector
<
EqFct
*>
locations
;
std
::
set
<
boost
::
shared_ptr
<
ChimeraTK
::
TransferElement
>>
additionalTransferElements
;
};
std
::
map
<
ChimeraTK
::
TransferElementID
,
ToDoocsUpdateDescriptor
>
_toDoocsDescriptorMap
;
};
}
// namespace ChimeraTK
...
...
This diff is collapsed.
Click to expand it.
src/DoocsUpdater.cc
+
23
−
14
View file @
1b99bd31
...
...
@@ -7,25 +7,25 @@ namespace ChimeraTK {
void
DoocsUpdater
::
addVariable
(
TransferElementAbstractor
variable
,
EqFct
*
eq_fct
,
std
::
function
<
void
()
>
updaterFunction
)
{
// Don't add the transfer element twice into the list of elements to read.
// Don't add the transfer element twice into the list of elements to read
(i.e. later into the ReadAnyGroup)
.
// To check if there is such an element we use the map with the lookup table
// which has a search function, instead of manually looking at the elements in
// the list and compare the ID.
if
(
_toDoocs
Update
Map
.
find
(
variable
.
getId
())
==
_toDoocs
Update
Map
.
end
())
{
if
(
_toDoocs
Descriptor
Map
.
find
(
variable
.
getId
())
==
_toDoocs
Descriptor
Map
.
end
())
{
_elementsToRead
.
push_back
(
variable
);
}
else
{
_toDoocs
A
dditionalTransferElements
Map
[
variable
.
getId
()]
.
insert
(
variable
.
getHighLevelImplElement
());
_toDoocs
DescriptorMap
[
variable
.
getId
()].
a
dditionalTransferElements
.
insert
(
variable
.
getHighLevelImplElement
());
}
_toDoocs
Update
Map
[
variable
.
getId
()].
push_back
(
updaterFunction
);
_toDoocs
EqFct
Map
[
variable
.
getId
()].
push_back
(
eq_fct
);
_toDoocs
Descriptor
Map
[
variable
.
getId
()].
updateFunctions
.
push_back
(
updaterFunction
);
_toDoocs
Descriptor
Map
[
variable
.
getId
()].
locations
.
push_back
(
eq_fct
);
}
void
DoocsUpdater
::
update
()
{
for
(
auto
&
transferElem
:
_elementsToRead
)
{
if
(
transferElem
.
readLatest
())
{
for
(
auto
&
updaterFunction
:
_toDoocs
Update
Map
[
transferElem
.
getId
()])
{
for
(
auto
&
updaterFunction
:
_toDoocs
Descriptor
Map
[
transferElem
.
getId
()]
.
updateFunctions
)
{
updaterFunction
();
}
}
...
...
@@ -37,16 +37,21 @@ namespace ChimeraTK {
return
;
}
// Worst-case: We need to lock all locations, so pre-allocate this here
std
::
unordered_set
<
EqFct
*>
locationsToLock
;
locationsToLock
.
reserve
(
_toDoocsEqFctMap
.
size
());
// preallocate locationsToLock to avoid breaking "realtime" behaivour
size_t
nMaxLocationsToLock
=
0
;
for
(
auto
&
pair
:
_toDoocsDescriptorMap
)
{
nMaxLocationsToLock
=
std
::
max
(
nMaxLocationsToLock
,
pair
.
second
.
locations
.
size
());
}
locationsToLock
.
reserve
(
nMaxLocationsToLock
);
ReadAnyGroup
group
(
_elementsToRead
.
begin
(),
_elementsToRead
.
end
());
while
(
true
)
{
// Call preRead for all TEs on
_toDoocsA
dditional
T
ransfer
E
lements
Map
. waitAny() is doing this for all
// Call preRead for all TEs on
a
dditional
t
ransfer
e
lements. waitAny() is doing this for all
// elements in the ReadAnyGroup. Unnecessary calls to preRead are ignored anyway.
for
(
auto
&
pair
:
_toDoocs
AdditionalTransferElements
Map
)
{
for
(
auto
&
elem
:
pair
.
second
)
{
for
(
auto
&
pair
:
_toDoocs
Descriptor
Map
)
{
for
(
auto
&
elem
:
pair
.
second
.
additionalTransferElements
)
{
elem
->
preRead
(
ChimeraTK
::
TransferType
::
read
);
}
}
...
...
@@ -54,23 +59,27 @@ namespace ChimeraTK {
// Wait until any variable got an update
auto
notification
=
group
.
waitAny
();
auto
updatedElement
=
notification
.
getId
();
auto
&
descriptor
=
_toDoocsDescriptorMap
[
updatedElement
];
// Gather all involved locations in a unique set
for
(
auto
&
location
:
_toDoocsEqFctMap
[
updatedElement
]
)
{
for
(
auto
&
location
:
descriptor
.
locations
)
{
if
(
locationsToLock
.
insert
(
location
).
second
)
location
->
lock
();
}
// Complete the read transfer of the process variable
notification
.
accept
();
// Call postRead for all TEs on _toDoocsAdditionalTransferElementsMap for the updated ID
for
(
auto
&
elem
:
_toDoocsA
dditionalTransferElements
Map
[
updatedElement
]
)
{
for
(
auto
&
elem
:
descriptor
.
a
dditionalTransferElements
)
{
elem
->
postRead
(
ChimeraTK
::
TransferType
::
read
,
true
);
}
// Call all updater functions
for
(
auto
&
updaterFunction
:
_toDoocsUpdateMap
[
updatedElement
])
updaterFunction
();
for
(
auto
&
updaterFunction
:
descriptor
.
updateFunctions
)
updaterFunction
();
// Unlock all involved locations
for
(
auto
&
location
:
locationsToLock
)
location
->
unlock
();
locationsToLock
.
clear
();
// Allow shutting down this thread...
boost
::
this_thread
::
interruption_point
();
}
...
...
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