ChimeraTK-DeviceAccess-TangoBackend 00.01.02
Loading...
Searching...
No Matches
OfflineCache.cc
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 "OfflineCache.h"
5
6namespace ChimeraTK {
7
9 std::ifstream f(_cacheFilePath);
10 nlohmann::json data;
11 try {
12 data = nlohmann::json::parse(f);
13 }
14 catch(nlohmann::json::exception& ex) {
15 throw ChimeraTK::logic_error("Failed to parse " + _cacheFilePath + ": " + ex.what());
16 }
17
18 auto registers = data["catalogue"];
19
20 if(!data["catalogue"].is_array()) {
21 throw ChimeraTK::logic_error("malformed cache file, missing \"catalogue\" " + _cacheFilePath);
22 }
23
24 auto catalogue = TangoRegisterCatalogue();
25 for(auto& reg : registers) {
26 Tango::AttributeInfoEx info;
27 info.name = reg["name"].get<std::string>();
28 info.max_dim_x = reg["length"].get<int>();
29 info.max_dim_y = reg["channels"].get<int>();
30 info.data_type = reg["tangoTypeId"].get<int>();
31 info.writable = static_cast<Tango::AttrWriteType>(reg["writable"].get<int>());
32 if(info.max_dim_x == 1 && info.max_dim_y == 0) {
33 info.data_format = Tango::AttrDataFormat::SCALAR;
34 }
35 else if(info.max_dim_x > 1 && info.max_dim_y == 0) {
36 info.data_format = Tango::AttrDataFormat::SPECTRUM;
37 }
38 else if(info.max_dim_x > 1 && info.max_dim_y > 0) {
39 info.data_format = Tango::AttrDataFormat::IMAGE;
40 }
41 catalogue.addRegister(TangoRegisterInfo(info));
42 }
43
44 return catalogue;
45 }
46} // namespace ChimeraTK
TangoRegisterCatalogue read()