mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-19 08:17:13 +02:00
added missing files
This commit is contained in:
72
slsDetectorSoftware/src/CtbConfig.cpp
Normal file
72
slsDetectorSoftware/src/CtbConfig.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
|
||||
#include "CtbConfig.h"
|
||||
#include "SharedMemory.h"
|
||||
#include "sls/ToString.h"
|
||||
#include "sls/string_utils.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
namespace sls {
|
||||
|
||||
CtbConfig::CtbConfig(){
|
||||
for (size_t i=0; i!=num_dacs; ++i){
|
||||
setDacName(i, "dac"+ToString(i));
|
||||
}
|
||||
}
|
||||
|
||||
void CtbConfig::check_index(size_t i) const {
|
||||
if (!(i < num_dacs)) {
|
||||
std::ostringstream oss;
|
||||
oss << "DAC index is too large needs to be below " << num_dacs;
|
||||
throw RuntimeError(oss.str());
|
||||
}
|
||||
}
|
||||
|
||||
void CtbConfig::check_size(const std::string &name) const {
|
||||
|
||||
if (name.empty())
|
||||
throw RuntimeError("Name needs to be at least one character");
|
||||
|
||||
// dacname_length -1 to account for \0 termination
|
||||
if (!(name.size() < (name_length - 1))) {
|
||||
std::ostringstream oss;
|
||||
oss << "Length of name needs to be less than " << name_length - 1
|
||||
<< " chars";
|
||||
throw RuntimeError(oss.str());
|
||||
}
|
||||
}
|
||||
|
||||
void CtbConfig::setDacName(size_t index, const std::string &name) {
|
||||
|
||||
check_index(index);
|
||||
check_size(name);
|
||||
|
||||
char *dst = &dacnames[index * name_length];
|
||||
memset(dst, '\0', name_length);
|
||||
memcpy(dst, &name[0], name.size());
|
||||
}
|
||||
|
||||
void CtbConfig::setDacNames(const std::vector<std::string>& names){
|
||||
for (size_t i = 0; i!=num_dacs; ++i){
|
||||
setDacName(i, names[i]);
|
||||
}
|
||||
}
|
||||
|
||||
std::string CtbConfig::getDacName(size_t index) const {
|
||||
return dacnames + index * name_length;
|
||||
}
|
||||
|
||||
std::vector<std::string> CtbConfig::getDacNames() const {
|
||||
std::vector<std::string> names;
|
||||
for (size_t i = 0; i != num_dacs; ++i)
|
||||
names.push_back(getDacName(i));
|
||||
return names;
|
||||
}
|
||||
|
||||
const char* CtbConfig::shm_tag(){
|
||||
return shm_tag_;
|
||||
}
|
||||
|
||||
} // namespace sls
|
31
slsDetectorSoftware/src/CtbConfig.h
Normal file
31
slsDetectorSoftware/src/CtbConfig.h
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
namespace sls {
|
||||
|
||||
|
||||
class CtbConfig {
|
||||
static constexpr size_t name_length = 20;
|
||||
static constexpr size_t num_dacs = 18;
|
||||
static constexpr const char* shm_tag_ = "ctbdacs";
|
||||
char dacnames[name_length * num_dacs]{};
|
||||
|
||||
void check_index(size_t i) const;
|
||||
void check_size(const std::string &name) const;
|
||||
|
||||
public:
|
||||
CtbConfig();
|
||||
CtbConfig(const CtbConfig&) = default;
|
||||
CtbConfig(CtbConfig&&) = default;
|
||||
CtbConfig& operator=(const CtbConfig&) = default;
|
||||
~CtbConfig() = default;
|
||||
|
||||
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;
|
||||
static const char* shm_tag();
|
||||
};
|
||||
|
||||
|
||||
} // namespace sls
|
Reference in New Issue
Block a user