ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
accessor2D_multiplexed.cpp
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
4#include <ChimeraTK/Device.h>
5#include <ChimeraTK/Utilities.h>
6
7#include <iostream>
8
9int main() {
10 ChimeraTK::setDMapFilePath("example.dmap");
11
12 ChimeraTK::Device myDevice("MY_DEVICE");
13 myDevice.open();
14
15 /*
16 * We populate the memory region with multiple multiplexed sequences
17 * so that we can use this for demonstrating the demultiplexing of the
18 * TwoDRegisterAccessor (for some implementations depeding on the backend).
19 *
20 * In this example we only have 4 sequences with 4 samples each.
21 * We write numbers 0 to 15 as multiplexed data and expect the following
22 * result: sequence 0: 0 4 8 12 sequence 1: 1 5 9 13 sequence 2:
23 * 2 6 10 14 sequence 3: 3 7 11 15
24 *
25 * We use a register named AREA_DATA_RAW which provides plain access to the
26 * data region.
27 */
28 auto dataRegion = myDevice.getOneDRegisterAccessor<double>("ADC/AREA_DATA_RAW");
29 int counter = 0;
30 for(auto& dataWord : dataRegion) {
31 dataWord = counter++;
32 }
33 dataRegion.write();
34
35 /*
36 * Now check how it looks using the TwoDRegisterAccessor. We just copy it from
37 * the accessor2D.cpp example.
38 */
39 ChimeraTK::TwoDRegisterAccessor<double> twoDAccessor = myDevice.getTwoDRegisterAccessor<double>("ADC/DATA");
40 twoDAccessor.read();
41
42 for(size_t i = 0; i < twoDAccessor.getNChannels(); ++i) {
43 std::cout << "Channel " << i << ":";
44 std::vector<double>& channel = twoDAccessor[i];
45 for(double sample : channel) {
46 std::cout << " " << sample;
47 }
48 std::cout << std::endl;
49 }
50
51 myDevice.close();
52
53 return 0;
54}
int main()
Class allows to read/write registers from device.
Definition Device.h:39
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:286
void close()
Close the device.
Definition Device.cc:66
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:276
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition Device.cc:58
void read()
Read the data from the device.
Accessor class to read and write 2D registers.
size_t getNChannels() const
Return the number of channels (formerly called sequences)
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.