ChimeraTK-DeviceAccess  03.18.00
LogicalNameMappingBackend.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 
6 #include "DeviceBackendImpl.h"
8 #include "LNMVariable.h"
9 #include <unordered_set>
10 
11 #include <mutex>
12 #include <utility>
13 
14 namespace ChimeraTK {
15 
20  public:
21  explicit LogicalNameMappingBackend(std::string lmapFileName = "");
22 
23  void open() override;
24 
25  void close() override;
26 
27  std::string readDeviceInfo() override { return std::string("Logical name mapping file: ") + _lmapFileName; }
28 
29  static boost::shared_ptr<DeviceBackend> createInstance(
30  std::string address, std::map<std::string, std::string> parameters);
31 
32  RegisterCatalogue getRegisterCatalogue() const override;
33 
34  void setExceptionImpl() noexcept override;
35 
36  void activateAsyncRead() noexcept override;
37 
38  template<typename UserType>
39  boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_impl(const RegisterPath& registerPathName,
40  size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags, size_t omitPlugins = 0);
41 
42  template<typename UserType>
43  boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_internal(
44  const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
45 
47  void parse() const;
48 
50  mutable bool hasParsed;
51 
53  std::string _lmapFileName;
54 
56  mutable std::map<std::string, boost::shared_ptr<DeviceBackend>> _devices;
57 
59  std::map<std::string, std::string> _parameters;
60 
64  // mutable LNMRegisterCatalogue _catalogue_mutable;
67  mutable bool catalogueCompleted{false};
68 
70  template<typename UserType>
71  struct SharedAccessor {
72  boost::weak_ptr<NDRegisterAccessor<UserType>> accessor;
73  std::recursive_mutex mutex;
74 
75  // Must only be modified while holding mutex
76  int useCount{0};
77  };
78 
82  using AccessorKey = std::pair<DeviceBackend*, RegisterPath>;
83  template<typename UserType>
84  using SharedAccessorMap = std::map<AccessorKey, SharedAccessor<UserType>>;
88 
92  mutable std::map<std::string /*name*/, LNMVariable> _variables;
93 
94  template<typename T>
96 
97  template<typename T>
99 
100  template<typename T>
101  friend class LNMBackendBitAccessor;
102 
103  template<typename T>
105 
107  std::atomic<bool> _asyncReadActive{false};
108 
110  std::unordered_set<std::string> getTargetDevices() const;
111 
112  private:
113  // A version number created when opening the backend. All variables will report this version number until they are
114  // changed for the first time after opening the device.
115  std::atomic<ChimeraTK::VersionNumber> _versionOnOpen{ChimeraTK::VersionNumber{nullptr}};
116 
117  public:
119  };
120 
121 } // namespace ChimeraTK
ChimeraTK::LogicalNameMappingBackend::AccessorKey
std::pair< DeviceBackend *, RegisterPath > AccessorKey
Map of target accessors which are potentially shared across our accessors.
Definition: LogicalNameMappingBackend.h:82
ChimeraTK::LogicalNameMappingBackend::SharedAccessorMap
std::map< AccessorKey, SharedAccessor< UserType > > SharedAccessorMap
Definition: LogicalNameMappingBackend.h:84
ChimeraTK::LogicalNameMappingBackend::LNMBackendRegisterAccessor
friend class LNMBackendRegisterAccessor
Definition: LogicalNameMappingBackend.h:95
ChimeraTK::LogicalNameMappingBackend::activateAsyncRead
void activateAsyncRead() noexcept override
Activate asyncronous read for all transfer elements where AccessMode::wait_for_new_data is set.
Definition: LogicalNameMappingBackend.cc:344
ChimeraTK::TemplateUserTypeMap< SharedAccessorMap >
ChimeraTK::LogicalNameMappingBackend::getRegisterAccessor_impl
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_impl(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags, size_t omitPlugins=0)
Definition: LogicalNameMappingBackend.cc:123
ChimeraTK::LogicalNameMappingBackend::SharedAccessor::mutex
std::recursive_mutex mutex
Definition: LogicalNameMappingBackend.h:73
ChimeraTK::LogicalNameMappingBackend::_lmapFileName
std::string _lmapFileName
name of the logical map file
Definition: LogicalNameMappingBackend.h:53
ChimeraTK::LogicalNameMappingBackend::LogicalNameMappingBackend
LogicalNameMappingBackend(std::string lmapFileName="")
Definition: LogicalNameMappingBackend.cc:15
ChimeraTK::LogicalNameMappingBackend::SharedAccessor::useCount
int useCount
Definition: LogicalNameMappingBackend.h:76
LNMVariable.h
ChimeraTK::LogicalNameMappingBackend::_asyncReadActive
std::atomic< bool > _asyncReadActive
Flag storing whether asynchronous read has been activated.
Definition: LogicalNameMappingBackend.h:107
BackendRegisterCatalogue.h
ChimeraTK::LogicalNameMappingBackend::readDeviceInfo
std::string readDeviceInfo() override
Return a device information string containing hardware details like the firmware version number or th...
Definition: LogicalNameMappingBackend.h:27
ChimeraTK::LogicalNameMappingBackend::SharedAccessor::accessor
boost::weak_ptr< NDRegisterAccessor< UserType > > accessor
Definition: LogicalNameMappingBackend.h:72
ChimeraTK::LogicalNameMappingBackend::catalogueCompleted
bool catalogueCompleted
Flag whether the catalogue has already been filled with extra information from the target backends.
Definition: LogicalNameMappingBackend.h:67
DeviceBackendImpl.h
ChimeraTK::LogicalNameMappingBackend::getRegisterAccessor_internal
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_internal(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
Definition: LogicalNameMappingBackend.cc:149
ChimeraTK::LogicalNameMappingBackend::setExceptionImpl
void setExceptionImpl() noexcept override
Function to be (optionally) implemented by backends if additional actions are needed when switching t...
Definition: LogicalNameMappingBackend.cc:303
ChimeraTK::LogicalNameMappingBackend::getRegisterCatalogue
RegisterCatalogue getRegisterCatalogue() const override
Return the register catalogue with detailed information on all registers.
Definition: LogicalNameMappingBackend.cc:215
ChimeraTK::RegisterCatalogue
Catalogue of register information.
Definition: RegisterCatalogue.h:20
ChimeraTK::LNMVariable
Definition: LNMVariable.h:17
ChimeraTK::DeviceBackend
The base class for backends providing IO functionality for the Device class.
Definition: DeviceBackend.h:28
ChimeraTK::BackendRegisterCatalogue
Interface for backends to the register catalogue.
Definition: BackendRegisterCatalogue.h:70
ChimeraTK::LogicalNameMappingBackend::parse
void parse() const
parse the logical map file, if not yet done
Definition: LogicalNameMappingBackend.cc:22
ChimeraTK::LogicalNameMappingBackend::_variables
std::map< std::string, LNMVariable > _variables
Map of variables and constants.
Definition: LogicalNameMappingBackend.h:92
ChimeraTK::LogicalNameMappingBackend::_devices
std::map< std::string, boost::shared_ptr< DeviceBackend > > _devices
map of target devices
Definition: LogicalNameMappingBackend.h:56
ChimeraTK::LogicalNameMappingBackend::_catalogue_mutable
BackendRegisterCatalogue< LNMBackendRegisterInfo > _catalogue_mutable
We need to make the catalogue mutable, since we fill it within getRegisterCatalogue()
Definition: LogicalNameMappingBackend.h:63
ChimeraTK::LNMBackendRegisterInfo
RegisterInfo structure for the LogicalNameMappingBackend.
Definition: LNMBackendRegisterInfo.h:22
ChimeraTK::LogicalNameMappingBackend::open
void open() override
Open the device.
Definition: LogicalNameMappingBackend.cc:46
ChimeraTK::LNMBackendChannelAccessor
Definition: LNMBackendChannelAccessor.h:17
ChimeraTK::LogicalNameMappingBackend::getVersionOnOpen
ChimeraTK::VersionNumber getVersionOnOpen() const
Definition: LogicalNameMappingBackend.cc:401
ChimeraTK::LogicalNameMappingBackend::sharedAccessorMap
TemplateUserTypeMap< SharedAccessorMap > sharedAccessorMap
Definition: LogicalNameMappingBackend.h:85
ChimeraTK::LogicalNameMappingBackend
Backend to map logical register names onto real hardware registers.
Definition: LogicalNameMappingBackend.h:19
ChimeraTK::LogicalNameMappingBackend::getTargetDevices
std::unordered_set< std::string > getTargetDevices() const
Obtain list of all target devices referenced in the catalogue.
Definition: LogicalNameMappingBackend.cc:391
ChimeraTK::DeviceBackendImpl
DeviceBackendImpl implements some basic functionality which should be available for all backends.
Definition: DeviceBackendImpl.h:25
ChimeraTK::LogicalNameMappingBackend::hasParsed
bool hasParsed
flag if already parsed
Definition: LogicalNameMappingBackend.h:50
ChimeraTK::LogicalNameMappingBackend::sharedAccessorMap_mutex
std::mutex sharedAccessorMap_mutex
a mutex to be locked when sharedAccessorMap (the container) is changed
Definition: LogicalNameMappingBackend.h:87
ChimeraTK::RegisterPath
Class to store a register path name.
Definition: RegisterPath.h:16
ChimeraTK::LogicalNameMappingBackend::createInstance
static boost::shared_ptr< DeviceBackend > createInstance(std::string address, std::map< std::string, std::string > parameters)
Definition: LogicalNameMappingBackend.cc:108
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition: VersionNumber.h:23
ChimeraTK::LogicalNameMappingBackend::SharedAccessor
Struct holding shared accessors together with a mutex for thread safety.
Definition: LogicalNameMappingBackend.h:71
ChimeraTK::LogicalNameMappingBackend::close
void close() override
Close the device.
Definition: LogicalNameMappingBackend.cc:85
ChimeraTK::AccessModeFlags
Set of AccessMode flags with additional functionality for an easier handling.
Definition: AccessMode.h:48
LNMBackendRegisterInfo.h
ChimeraTK::LogicalNameMappingBackend::_parameters
std::map< std::string, std::string > _parameters
map of parameters passed through the CDD
Definition: LogicalNameMappingBackend.h:59
ChimeraTK::LNMBackendVariableAccessor
Definition: LNMBackendVariableAccessor.h:21
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::NDRegisterAccessor
N-dimensional register accessor.
Definition: ForwardDeclarations.h:17
ChimeraTK::LNMBackendBitAccessor
Definition: LNMBackendBitAccessor.h:21