ChimeraTK-DeviceAccess  03.18.00
accessor2D.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 
9 int main() {
10  ChimeraTK::setDMapFilePath("example.dmap");
11 
12  ChimeraTK::Device myDevice("MY_DEVICE");
13  myDevice.open();
14 
15  /*
16  * In this example there is a data region called "DATA" in
17  * a module called "ADC".
18  */
19  ChimeraTK::TwoDRegisterAccessor<double> twoDAccessor = myDevice.getTwoDRegisterAccessor<double>("ADC/DATA");
20 
21  /*
22  * Read data for all channels from the hardware
23  */
24  twoDAccessor.read();
25 
26  /*
27  * You can access each sequence/channel individually. They are std::vectors.
28  * You get a reference to the vector inside the accessor. No data copying.
29  */
30  for(size_t i = 0; i < twoDAccessor.getNChannels(); ++i) {
31  std::cout << "Channel " << i << ":";
32  std::vector<double>& channel = twoDAccessor[i];
33  for(double sample : channel) {
34  std::cout << " " << sample;
35  }
36  std::cout << std::endl;
37  }
38 
39  /*
40  * You can modify the stuff at will in the accessors internal buffer.
41  * In this example we use two [] operators like a 2D array.
42  */
43  for(size_t i = 0; i < twoDAccessor.getNChannels(); ++i) {
44  for(size_t j = 0; j < twoDAccessor.getNElementsPerChannel(); ++j) {
45  twoDAccessor[i][j] = i * 100 + j;
46  }
47  }
48 
49  /*
50  * Finally write to the hardware.
51  */
52  twoDAccessor.write();
53 
54  myDevice.close();
55 
56  return 0;
57 }
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
main
int main()
Definition: accessor2D.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::TwoDRegisterAccessor::getNElementsPerChannel
size_t getNElementsPerChannel() const
Return number of elements/samples per channel.
Definition: TwoDRegisterAccessor.h:44
ChimeraTK::setDMapFilePath
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.
Definition: Utilities.cpp:327