ChimeraTK-DeviceAccess  03.18.00
accessor2D_multiplexed.cpp

A special case: The 2D register might have multiplexed data on the backend side (backend specific implementation of the TwoDRegisterAccessor).

// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
// SPDX-License-Identifier: LGPL-3.0-or-later
#include <ChimeraTK/Device.h>
#include <ChimeraTK/Utilities.h>
#include <iostream>
int main() {
ChimeraTK::setDMapFilePath("example.dmap");
ChimeraTK::Device myDevice("MY_DEVICE");
myDevice.open();
/*
* We populate the memory region with multiple multiplexed sequences
* so that we can use this for demonstrating the demultiplexing of the
* TwoDRegisterAccessor (for some implementations depeding on the backend).
*
* In this example we only have 4 sequences with 4 samples each.
* We write numbers 0 to 15 as multiplexed data and expect the following
* result: sequence 0: 0 4 8 12 sequence 1: 1 5 9 13 sequence 2:
* 2 6 10 14 sequence 3: 3 7 11 15
*
* We use a register named AREA_DATA_RAW which provides plain access to the
* data region.
*/
auto dataRegion = myDevice.getOneDRegisterAccessor<double>("ADC/AREA_DATA_RAW");
int counter = 0;
for(auto& dataWord : dataRegion) {
dataWord = counter++;
}
dataRegion.write();
/*
* Now check how it looks using the TwoDRegisterAccessor. We just copy it from
* the accessor2D.cpp example.
*/
ChimeraTK::TwoDRegisterAccessor<double> twoDAccessor = myDevice.getTwoDRegisterAccessor<double>("ADC/DATA");
twoDAccessor.read();
for(size_t i = 0; i < twoDAccessor.getNChannels(); ++i) {
std::cout << "Channel " << i << ":";
std::vector<double>& channel = twoDAccessor[i];
for(double sample : channel) {
std::cout << " " << sample;
}
std::cout << std::endl;
}
myDevice.close();
return 0;
}
ChimeraTK::TwoDRegisterAccessor
Accessor class to read and write 2D registers.
Definition: ForwardDeclarations.h:20
ChimeraTK::Device::close
void close()
Close the device.
Definition: Device.cc:66
ChimeraTK::Device::getOneDRegisterAccessor
OneDRegisterAccessor< UserType > getOneDRegisterAccessor(const RegisterPath &registerPathName, size_t numberOfWords=0, size_t wordOffsetInRegister=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a OneDRegisterAccessor object for the given register.
Definition: Device.h:273
main
int main()
Definition: accessor2D_multiplexed.cpp:9
ChimeraTK::Device
Class allows to read/write registers from device.
Definition: Device.h:39
ChimeraTK::TwoDRegisterAccessor::getNChannels
size_t getNChannels() const
Return the number of channels (formerly called sequences)
Definition: TwoDRegisterAccessor.h:41
ChimeraTK::Device::open
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition: Device.cc:58
ChimeraTK::Device::getTwoDRegisterAccessor
TwoDRegisterAccessor< UserType > getTwoDRegisterAccessor(const RegisterPath &registerPathName, size_t numberOfElements=0, size_t elementsOffset=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a TwoDRegisterAccessor object for the given register.
Definition: Device.h:283
ChimeraTK::setDMapFilePath
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.
Definition: Utilities.cpp:327