Files
slsDetectorPackage/slsDetectorSoftware/src/CtbConfig.h
T
maliakal_d 3dd07bf2be
Build on local RHEL9 / build (push) Successful in 1m25s
Build on RHEL9 / build (push) Successful in 3m15s
Build on local RHEL8 / build (push) Successful in 3m31s
Build on RHEL8 / build (push) Successful in 4m44s
Dev/define cmd (#1312)
* basic ctb config api for register and bit names

* tests for define and definelist pass. yet to implement using them for reg, setbit, clearbit and getbit

* improved autocomplete for getbit,setbit, clearbit

* validate autocomplete

* definelist has no put

* updating help

* converting char array+int in runtimeerror compiles but throws at runtime.Fixed.Tested for it. Also check if string or int before using getregisterdefinitonbyvalue to see if it threw to call the other function. because both of it can throw and we should differentiate the issues for both

* removed std::vector<std::pair<string,int> to std::map<string, int> for defiitions list

* Dev/define cmd tie bit to reg (#1328)

* strong type

* moved everythign to bit_utils class

* pybindings

* added tests for python

* removed duplicates

* removed bit names in reg

* changed BitPosition to BitAddress

* Using define reg/bit from python (#1344)

* define_bit, define_addr in python. 
* setBit/clearBit takes int or addr

* added example using bits

* split define into 2 commands define_reg and define_bit, definelist into 2: definelist_reg and definelist_bit

* allow string for register and bit names in c++ api

* refactor from github comments

* naming refactoring (getRegisterDefnition to retunr name and address specifically

* added marker for 8 cmd tests connected to define, changed macro to static constexpr

* changed bitPosition from int to uint32_t

* got rid of setbitposition and setaddress, instead overloaded constructor to take in strings so that the conversion from string to bit address members, takes place within the class for easy maintainance in case type changes

* Removing implicit conversions:
RegisterAddresss and RegisterValue: Removed the implicit conversions.
RegisterAddress: Changed member name from address_ to value_ and method as well to value().
RegisterValue: Also added | operator to be able to concatenate with uint32_t. Same in python bindings (but could not find the tests to modify

* Allowed concatenation with other RegisterValue, made them all constexpr

* fix a ctbConfig test

* Maponstack works with integration tests, but need unit tests

* tests on mapstack

* fixed ctb tests and FixedString being initialized with gibberish

* removing parsing from string inside the class RegisterAddress, BitAddress and RegisterValue

* updated python bindings

* fixed bit utils test

* renaming getRegisterDefintiionAddress/Name=>getRegisterAddress/Name and similary for getBitDefinitionAddress/Name

* updated python bindings

* fix tests (format)

* a few python tests added and python bindings corrected

* replaceing str with __str__ for bit.cpp

* repr reimplemented for bit.cpp

* removed make with registerAddress etc

* starting server for tests per session and nor module

* killprocess throws if no process found-> github runs fails, changed to pkill and not throw

* clean shm shouldnt raise, in ci binary not found

* ignoring these tests for CI, which fail on CI because simulators are not generated in CI. This is in another PR, where it should work

---------

Co-authored-by: Erik Fröjdh <erik.frojdh@gmail.com>
Co-authored-by: froejdh_e <erik.frojdh@psi.ch>
2026-01-05 15:10:46 +01:00

104 lines
4.0 KiB
C++

#pragma once
#include "MapOnStack.h"
#include "sls/bit_utils.h"
#include "sls/sls_detector_defs.h"
#include "sls/string_utils.h"
#include <vector>
namespace sls {
class CtbConfig {
public:
/** fixed pattern */
static constexpr int SHM_VERSION = 0x251215;
int shmversion{SHM_VERSION};
bool isValid{true}; // false if freed to block access from python or c++ api
/** end of fixed pattern */
private:
static constexpr const char *shm_tag_ = "ctbdacs";
static constexpr size_t name_length = 32;
static constexpr size_t num_dacs = 18;
static constexpr size_t num_adcs = 32;
static constexpr size_t num_signals = 64;
static constexpr size_t num_powers = 5;
static constexpr size_t num_slowADCs = 8;
char dacnames[num_dacs][name_length]{};
char adcnames[num_adcs][name_length]{};
char signalnames[num_signals][name_length]{};
char powernames[num_powers][name_length]{};
char slowADCnames[num_slowADCs][name_length]{};
void check_index(size_t index, size_t max, const std::string &name,
const std::string &suffix = "") const;
void set_name(const std::string &name, char dst[][name_length],
size_t index);
void setNames(const std::vector<std::string> &names, size_t expected_size,
void (CtbConfig::*setNameFunc)(size_t, const std::string &));
std::vector<std::string>
getNames(size_t expected_size,
std::string (CtbConfig::*getNameFunc)(size_t) const) const;
static constexpr size_t Max_Named_Regs = 1024;
static constexpr size_t Max_Named_Bits = 32 * 1024;
MapOnStack<FixedString<name_length>, RegisterAddress, Max_Named_Regs, true>
registers;
MapOnStack<FixedString<name_length>, BitAddress, Max_Named_Bits, true> bits;
public:
CtbConfig();
static const char *shm_tag();
void setDacNames(const std::vector<std::string> &names);
void setDacName(size_t index, const std::string &name);
std::string getDacName(size_t index) const;
std::vector<std::string> getDacNames() const;
void setAdcNames(const std::vector<std::string> &names);
void setAdcName(size_t index, const std::string &name);
std::string getAdcName(size_t index) const;
std::vector<std::string> getAdcNames() const;
void setSignalNames(const std::vector<std::string> &names);
void setSignalName(size_t index, const std::string &name);
std::string getSignalName(size_t index) const;
std::vector<std::string> getSignalNames() const;
void setPowerNames(const std::vector<std::string> &names);
void setPowerName(size_t index, const std::string &name);
std::string getPowerName(size_t index) const;
std::vector<std::string> getPowerNames() const;
void setSlowADCNames(const std::vector<std::string> &names);
void setSlowADCName(size_t index, const std::string &name);
std::string getSlowADCName(size_t index) const;
std::vector<std::string> getSlowADCNames() const;
int getRegisterNamesCount() const;
bool hasRegisterName(const std::string &name) const;
bool hasRegisterAddress(RegisterAddress addr) const;
void clearRegisterNames();
void setRegisterName(const std::string &name, RegisterAddress addr);
RegisterAddress getRegisterAddress(const std::string &name) const;
std::string getRegisterName(RegisterAddress addr) const;
void setRegisterNames(const std::map<std::string, RegisterAddress> &list);
std::map<std::string, RegisterAddress> getRegisterNames() const;
int getBitNamesCount() const;
void clearBitNames();
bool hasBitName(const std::string &name) const;
bool hasBitAddress(BitAddress addr) const;
std::string toRegisterNameBitString(BitAddress addr) const;
void setBitName(const std::string &name, BitAddress addr);
BitAddress getBitAddress(const std::string &name) const;
std::string getBitName(BitAddress addr) const;
void setBitNames(const std::map<std::string, BitAddress> &list);
std::map<std::string, BitAddress> getBitNames() const;
};
} // namespace sls