ChimeraTK-DeviceAccess 03.20.00
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TraditionalMapFileParser.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
5#include "MetadataCatalogue.h"
7
8#include <cstdint>
9#include <fstream>
10#include <list>
11#include <string>
12
13namespace ChimeraTK::detail {
14
19 class TraditionalMapFileParser {
20 public:
21 explicit TraditionalMapFileParser(std::string fileName);
22
30 std::pair<NumericAddressedRegisterCatalogue, MetadataCatalogue> parse(std::ifstream& stream);
31
32 private:
34 struct ParsedLine {
35 RegisterPath pathName;
36 uint32_t nElements{0};
37 uint64_t address{0};
38 uint32_t nBytes{0};
39 uint64_t bar{0};
40 uint32_t width{32};
41 int32_t nFractionalBits{0};
42 bool signedFlag{true};
45 std::vector<size_t> interruptID;
46 };
47
55 static std::pair<RegisterPath, std::string> splitStringAtLastDot(RegisterPath moduleDotName);
56
57 static std::pair<NumericAddressedRegisterInfo::Type, int> getTypeAndNFractionalBits(
58 const std::string& bitInterpretation, uint32_t width);
59
60 // returns an empty vector if the type is not INTERRUPT
61 static std::vector<size_t> getInterruptId(std::string accessType);
62
63 static void checkFileConsitencyAndThrowIfError(NumericAddressedRegisterInfo::Access registerAccessMode,
64 NumericAddressedRegisterInfo::Type registerType, uint32_t nElements, uint64_t address, uint32_t nBytes,
65 uint64_t bar, uint32_t width, int32_t nFractionalBits, bool signedFlag);
66
67 void parseMetaData(std::string line);
68
69 ParsedLine parseLine(const std::string& line);
70
75 void handle2D(const ParsedLine& pl);
76
81 void handle2DNewStyle(const ParsedLine& pl);
82
87 static bool isScalarOr1D(const RegisterPath& pathName);
88
93 static bool is2D(const RegisterPath& pathName);
94
99 static bool is2DNewStyle(RegisterPath pathName);
100
104 static RegisterPath makeSequenceName(const RegisterPath& pathName, size_t index);
105
109 static RegisterPath make2DName(const RegisterPath& pathName, const std::string& prefix);
110
115 void make2DRegisterInfos(const ParsedLine& pl, std::list<ParsedLine>& channelLines, const std::string& prefix);
116
117 NumericAddressedRegisterCatalogue _pmap;
118 MetadataCatalogue _metadataCatalogue;
119
120 std::string _fileName;
121 uint32_t _lineNo = 0;
122
123 std::vector<ParsedLine> _parsedLines;
124 std::map<RegisterPath, const ParsedLine&> _parsedLinesMap;
125 };
126
127} // namespace ChimeraTK::detail
Access
Enum describing the access mode of the register: