ChimeraTK-DeviceAccess  03.18.00
MapFileParser.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 "Exception.h"
6 #include "MetadataCatalogue.h"
8 
9 #include <cstdint>
10 #include <fstream>
11 #include <iomanip>
12 #include <list>
13 #include <string>
14 
15 namespace ChimeraTK {
16 
21  class MapFileParser {
22  public:
36  std::pair<NumericAddressedRegisterCatalogue, MetadataCatalogue> parse(const std::string& file_name);
37 
38  private:
40  struct ParsedLine {
41  RegisterPath pathName;
42  uint32_t nElements{0};
43  uint64_t address{0};
44  uint32_t nBytes{0};
45  uint64_t bar{0};
46  uint32_t width{32};
47  int32_t nFractionalBits{0};
48  bool signedFlag{true};
51  std::vector<size_t> interruptID;
52  };
53 
61  static std::pair<RegisterPath, std::string> splitStringAtLastDot(RegisterPath moduleDotName);
62 
63  static std::pair<NumericAddressedRegisterInfo::Type, int> getTypeAndNFractionalBits(
64  const std::string& bitInterpretation, uint32_t width);
65 
66  // returns an empty vector if the type is not INTERRUPT
67  static std::vector<size_t> getInterruptId(std::string accessType);
68 
69  static void checkFileConsitencyAndThrowIfError(NumericAddressedRegisterInfo::Access registerAccessMode,
70  NumericAddressedRegisterInfo::Type registerType, uint32_t nElements, uint64_t address, uint32_t nBytes,
71  uint64_t bar, uint32_t width, int32_t nFractionalBits, bool signedFlag);
72 
73  void parseMetaData(std::string line);
74 
75  ParsedLine parseLine(const std::string& line);
76 
81  void handle2D(const ParsedLine& pl);
82 
87  void handle2DNewStyle(const ParsedLine& pl);
88 
93  static bool isScalarOr1D(const RegisterPath& pathName);
94 
99  static bool is2D(const RegisterPath& pathName);
100 
105  static bool is2DNewStyle(RegisterPath pathName);
106 
110  static RegisterPath makeSequenceName(const RegisterPath& pathName, size_t index);
111 
115  static RegisterPath make2DName(const RegisterPath& pathName, const std::string& prefix);
116 
121  void make2DRegisterInfos(const ParsedLine& pl, std::list<ParsedLine>& channelLines, const std::string& prefix);
122 
124  MetadataCatalogue metadataCatalogue;
125 
126  std::string file_name;
127  uint32_t line_nr = 0;
128 
129  std::vector<ParsedLine> parsedLines;
130  std::map<RegisterPath, const ParsedLine&> parsedLinesMap;
131  };
132 
133 } // namespace ChimeraTK
ChimeraTK::MetadataCatalogue
Container for backend metadata.
Definition: MetadataCatalogue.h:17
ChimeraTK::MapFileParser
Provides method to parse MAP file.
Definition: MapFileParser.h:21
ChimeraTK::NumericAddressedRegisterInfo::Type::FIXED_POINT
@ FIXED_POINT
NumericAddressedRegisterCatalogue.h
MetadataCatalogue.h
ChimeraTK::NumericAddressedRegisterInfo::Type
Type
Enum descibing the data interpretation:
Definition: NumericAddressedRegisterCatalogue.h:36
ChimeraTK::NumericAddressedRegisterInfo::Access
Access
Enum describing the access mode of the register:
Definition: NumericAddressedRegisterCatalogue.h:24
ChimeraTK::RegisterPath
Class to store a register path name.
Definition: RegisterPath.h:16
ChimeraTK::NumericAddressedRegisterCatalogue
Definition: NumericAddressedRegisterCatalogue.h:136
ChimeraTK::NumericAddressedRegisterInfo::Access::READ_WRITE
@ READ_WRITE
Exception.h
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::MapFileParser::parse
std::pair< NumericAddressedRegisterCatalogue, MetadataCatalogue > parse(const std::string &file_name)
Performs parsing of specified MAP file.
Definition: MapFileParser.cpp:19