ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
TriggerFanOut.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include "Application.h"
6#include "DeviceModule.h"
7#include "FeedingFanOut.h"
8#include "InternalModule.h"
9
10#include <ChimeraTK/NDRegisterAccessor.h>
11#include <ChimeraTK/SupportedUserTypes.h>
12#include <ChimeraTK/TransferGroup.h>
13
14constexpr useconds_t DeviceOpenTimeout = 500;
15
16namespace ChimeraTK {
17
18 /********************************************************************************************************************/
19
23 public:
24 TriggerFanOut(boost::shared_ptr<ChimeraTK::TransferElement> externalTriggerImpl, DeviceManager& deviceModule);
25
26 ~TriggerFanOut() override;
27
28 void activate() override;
29
30 void deactivate() final;
31
33 template<typename UserType>
34 void addNetwork(boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> feedingNode,
35 ConsumerImplementationPairs<UserType> const& consumerImplementationPairs);
36
39 void run();
40
41 protected:
43 boost::shared_ptr<ChimeraTK::TransferElement> _externalTrigger;
44
47 template<typename UserType>
48 using FanOutMap = std::map<boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>>,
49 boost::shared_ptr<FeedingFanOut<UserType>>>;
50 TemplateUserTypeMap<FanOutMap> _fanOutMap;
51
53 ChimeraTK::TransferGroup _transferGroup;
54
56 boost::thread _thread;
57
60 };
61
62 /********************************************************************************************************************/
63 /********************************************************************************************************************/
64
65 template<typename UserType>
66 void TriggerFanOut::addNetwork(boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> feedingNode,
67 ConsumerImplementationPairs<UserType> const& consumerImplementationPairs) {
68 assert(feedingNode.get() != nullptr);
69
70 // if no consumers present, ignore this network. This primarily might happen if the only consumer was a control
71 // system variable which was optimised out.
72 if(consumerImplementationPairs.empty()) {
73 return;
74 }
75
76 // add feeder to TransferGroup
77 _transferGroup.addAccessor(feedingNode);
78
79 // create FeedingFanOut to distribute the read value to all consumers (even if just one)
80 auto feedingFanOut = boost::make_shared<FeedingFanOut<UserType>>(feedingNode->getName(), feedingNode->getUnit(),
81 feedingNode->getDescription(), feedingNode->getNumberOfSamples(),
82 false, // in TriggerFanOuts we cannot have return channels
83 consumerImplementationPairs);
84 boost::fusion::at_key<UserType>(_fanOutMap.table)[feedingNode] = feedingFanOut;
85 }
86
87 /********************************************************************************************************************/
88
89} /* namespace ChimeraTK */
constexpr useconds_t DeviceOpenTimeout
Implements access to a ChimeraTK::Device.
Base class for internal modules which are created by the variable connection code (e....
InternalModule which waits for a trigger, then reads a number of variables and distributes each of th...
boost::shared_ptr< ChimeraTK::TransferElement > _externalTrigger
TransferElement acting as our trigger.
DeviceManager & _deviceModule
The DeviceModule of the feeder.
boost::thread _thread
Thread handling the synchronisation, if needed.
void activate() override
Activate synchronisation thread if needed.
TemplateUserTypeMap< FanOutMap > _fanOutMap
void addNetwork(boost::shared_ptr< ChimeraTK::NDRegisterAccessor< UserType > > feedingNode, ConsumerImplementationPairs< UserType > const &consumerImplementationPairs)
Add a new network the TriggerFanOut.
std::map< boost::shared_ptr< ChimeraTK::NDRegisterAccessor< UserType > >, boost::shared_ptr< FeedingFanOut< UserType > > > FanOutMap
Map of the feeding NDRegisterAccessor to the corresponding FeedingFanOut for each UserType.
void deactivate() final
Deactivate synchronisation thread if running.
ChimeraTK::TransferGroup _transferGroup
TransferGroup containing all feeders NDRegisterAccessors.
void run()
Synchronise feeder and the consumers.
InvalidityTracer application module.
std::list< std::pair< boost::shared_ptr< ChimeraTK::NDRegisterAccessor< UserType > >, VariableNetworkNode > > ConsumerImplementationPairs
Definition FanOut.h:18