mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 15:20:02 +02:00
WIP
This commit is contained in:
parent
fd3108a61b
commit
d4518b2ca3
@ -18,25 +18,24 @@ typedef struct __attribute__((packed)) {
|
||||
uint64_t waittime[3];
|
||||
} patternParameters;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
class Pattern{
|
||||
patternParameters* pat = new patternParameters{};
|
||||
class Pattern {
|
||||
patternParameters *pat = new patternParameters{};
|
||||
|
||||
public:
|
||||
Pattern();
|
||||
~Pattern();
|
||||
Pattern(const Pattern& other);
|
||||
bool operator==(const Pattern& other) const;
|
||||
bool operator!=(const Pattern& other) const;
|
||||
patternParameters* data();
|
||||
patternParameters* data() const;
|
||||
constexpr size_t size() const noexcept{ return sizeof(patternParameters);}
|
||||
Pattern(const Pattern &other);
|
||||
bool operator==(const Pattern &other) const;
|
||||
bool operator!=(const Pattern &other) const;
|
||||
patternParameters *data();
|
||||
patternParameters *data() const;
|
||||
constexpr size_t size() const noexcept { return sizeof(patternParameters); }
|
||||
void validate() const;
|
||||
void load(const std::string &fname);
|
||||
void save(const std::string &fname);
|
||||
std::string str() const { return {}; }
|
||||
|
||||
};
|
||||
|
||||
} //namespace sls
|
||||
} // namespace sls
|
||||
#endif
|
@ -1758,7 +1758,8 @@ void Detector::savePattern(const std::string &fname) {
|
||||
auto t = pimpl->Parallel(&Module::getPattern, {});
|
||||
auto pat = t.tsquash("Inconsistent pattern parameters between modules");
|
||||
pat.validate();
|
||||
// pat.save(fname);
|
||||
std::cout << ToString(pat) << std::endl;
|
||||
pat.save(fname);
|
||||
}
|
||||
|
||||
void Detector::setPattern(const std::string &fname, Positions pos) {
|
||||
|
@ -1913,7 +1913,7 @@ void Module::setLEDEnable(bool enable) {
|
||||
|
||||
// Pattern
|
||||
|
||||
void Module::setPattern(const Pattern& pat) {
|
||||
void Module::setPattern(const Pattern &pat) {
|
||||
sendToDetector(F_SET_PATTERN, pat.data(), pat.size(), nullptr, 0);
|
||||
}
|
||||
|
||||
|
@ -15,38 +15,40 @@ Pattern::Pattern(const Pattern &other) {
|
||||
}
|
||||
|
||||
bool Pattern::operator==(const Pattern &other) const {
|
||||
for (size_t i = 0; i<(sizeof(pat->word)/sizeof(pat->word[0])); ++i){
|
||||
for (size_t i = 0; i < (sizeof(pat->word) / sizeof(pat->word[0])); ++i) {
|
||||
if (pat->word[i] != other.pat->word[i])
|
||||
return false;
|
||||
}
|
||||
if (pat->ioctrl != other.pat->ioctrl)
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i<(sizeof(pat->limits)/sizeof(pat->limits[0])); ++i){
|
||||
for (size_t i = 0; i < (sizeof(pat->limits) / sizeof(pat->limits[0]));
|
||||
++i) {
|
||||
if (pat->limits[i] != other.pat->limits[i])
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i<(sizeof(pat->loop)/sizeof(pat->loop[0])); ++i){
|
||||
for (size_t i = 0; i < (sizeof(pat->loop) / sizeof(pat->loop[0])); ++i) {
|
||||
if (pat->loop[i] != other.pat->loop[i])
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i<(sizeof(pat->nloop)/sizeof(pat->nloop[0])); ++i){
|
||||
for (size_t i = 0; i < (sizeof(pat->nloop) / sizeof(pat->nloop[0])); ++i) {
|
||||
if (pat->nloop[i] != other.pat->nloop[i])
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i<(sizeof(pat->wait)/sizeof(pat->wait[0])); ++i){
|
||||
for (size_t i = 0; i < (sizeof(pat->wait) / sizeof(pat->wait[0])); ++i) {
|
||||
if (pat->wait[i] != other.pat->wait[i])
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i<(sizeof(pat->waittime)/sizeof(pat->waittime[0])); ++i){
|
||||
for (size_t i = 0; i < (sizeof(pat->waittime) / sizeof(pat->waittime[0]));
|
||||
++i) {
|
||||
if (pat->waittime[i] != other.pat->waittime[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Pattern::operator!=(const Pattern& other) const{
|
||||
return !(*this==other);
|
||||
bool Pattern::operator!=(const Pattern &other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
patternParameters *Pattern::data() { return pat; }
|
||||
@ -163,4 +165,43 @@ void Pattern::load(const std::string &fname) {
|
||||
}
|
||||
}
|
||||
|
||||
void Pattern::save(const std::string &fname) {
|
||||
std::ofstream output_file(fname);
|
||||
if (!output_file) {
|
||||
throw RuntimeError("Could not open pattern file " + fname +
|
||||
" for writing");
|
||||
}
|
||||
std::ostringstream os;
|
||||
// pattern word
|
||||
for (uint32_t i = pat->limits[0]; i <= pat->limits[1]; ++i) {
|
||||
output_file << "patword [" << ToStringHex(i, 4) << ", "
|
||||
<< ToStringHex(pat->word[i], 16) << "]" << std::endl;
|
||||
}
|
||||
|
||||
// patioctrl
|
||||
output_file << "patioctrl " << ToStringHex(pat->ioctrl, 16) << std::endl;
|
||||
|
||||
// patlimits
|
||||
output_file << "patlimits " << ToStringHex(pat->limits[0], 4) << " "
|
||||
<< ToStringHex(pat->limits[1], 4) << std::endl;
|
||||
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
// patloop
|
||||
output_file << "patloop" << i << " "
|
||||
<< ToStringHex(pat->loop[i * 2 + 0], 4) << " "
|
||||
<< ToStringHex(pat->loop[i * 2 + 1], 4) << std::endl;
|
||||
// patnloop
|
||||
output_file << "patnloop" << i << " " << pat->nloop[i] << std::endl;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
// patwait
|
||||
output_file << "patwait" << i << " " << ToStringHex(pat->wait[i], 4)
|
||||
<< std::endl;
|
||||
// patwaittime
|
||||
output_file << "patwaittime" << i << " " << pat->waittime[i]
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sls
|
@ -475,35 +475,6 @@ typedef struct {
|
||||
} __attribute__((packed));
|
||||
#endif
|
||||
|
||||
// /** pattern structure */
|
||||
// #ifdef __cplusplus
|
||||
// struct patternParameters {
|
||||
// #else
|
||||
// typedef struct __attribute__((packed)) {
|
||||
// #endif
|
||||
// uint64_t word[MAX_PATTERN_LENGTH];
|
||||
// uint64_t ioctrl;
|
||||
// uint32_t limits[2];
|
||||
// // loop0 start, loop0 stop .. loop2 start, loop2 stop
|
||||
// uint32_t loop[6];
|
||||
// uint32_t nloop[3];
|
||||
// uint32_t wait[3];
|
||||
// uint64_t waittime[3];
|
||||
// #ifdef __cplusplus
|
||||
// public:
|
||||
// patternParameters() {
|
||||
// // Since the def has to be c compatible we can't use {} for the
|
||||
// // members
|
||||
// memset(this, 0, sizeof(patternParameters));
|
||||
// }
|
||||
// void load(const std::string &fname);
|
||||
// void save(const std::string &fname);
|
||||
// void validate() const;
|
||||
// } __attribute__((packed));
|
||||
// #else
|
||||
// } patternParameters;
|
||||
// #endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
protected:
|
||||
#endif
|
||||
|
@ -1,217 +0,0 @@
|
||||
#include "sls/sls_detector_defs.h"
|
||||
#include "sls/ToString.h"
|
||||
#include "sls/logger.h"
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
using sls::RuntimeError;
|
||||
using sls::StringTo;
|
||||
using sls::ToString;
|
||||
|
||||
void slsDetectorDefs::patternParameters::load(const std::string &fname) {
|
||||
std::ifstream input_file(fname);
|
||||
if (!input_file) {
|
||||
throw RuntimeError("Could not open pattern file " + fname +
|
||||
" for reading");
|
||||
}
|
||||
for (std::string line; std::getline(input_file, line);) {
|
||||
if (line.find('#') != std::string::npos) {
|
||||
line.erase(line.find('#'));
|
||||
}
|
||||
LOG(logDEBUG1) << "line after removing comments:\n\t" << line;
|
||||
if (line.length() > 1) {
|
||||
|
||||
// convert command and string to a vector
|
||||
std::istringstream iss(line);
|
||||
auto it = std::istream_iterator<std::string>(iss);
|
||||
std::vector<std::string> args = std::vector<std::string>(
|
||||
it, std::istream_iterator<std::string>());
|
||||
|
||||
std::string cmd = args[0];
|
||||
int nargs = args.size() - 1;
|
||||
|
||||
if (cmd == "patword") {
|
||||
if (nargs != 2) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
uint32_t addr = StringTo<uint32_t>(args[1]);
|
||||
if (addr >= MAX_PATTERN_LENGTH) {
|
||||
throw RuntimeError("Invalid address for " + ToString(args));
|
||||
}
|
||||
word[addr] = StringTo<uint64_t>(args[2]);
|
||||
} else if (cmd == "patioctrl") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
ioctrl = StringTo<uint64_t>(args[1]);
|
||||
} else if (cmd == "patlimits") {
|
||||
if (nargs != 2) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
limits[0] = StringTo<uint32_t>(args[1]);
|
||||
limits[1] = StringTo<uint32_t>(args[2]);
|
||||
} else if (cmd == "patloop0" || cmd == "patloop1" ||
|
||||
cmd == "patloop2") {
|
||||
if (nargs != 2) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
int level = cmd[cmd.find_first_of("012")] - '0';
|
||||
int loop1 = StringTo<uint32_t>(args[1]);
|
||||
int loop2 = StringTo<uint32_t>(args[2]);
|
||||
loop[level * 2 + 0] = loop1;
|
||||
loop[level * 2 + 1] = loop2;
|
||||
} else if (cmd == "patnloop0" || cmd == "patnloop1" ||
|
||||
cmd == "patnloop2") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
int level = cmd[cmd.find_first_of("012")] - '0';
|
||||
nloop[level] = StringTo<uint32_t>(args[1]);
|
||||
} else if (cmd == "patwait0" || cmd == "patwait1" ||
|
||||
cmd == "patwait2") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
int level = cmd[cmd.find_first_of("012")] - '0';
|
||||
wait[level] = StringTo<uint32_t>(args[1]);
|
||||
} else if (cmd == "patwaittime0" || cmd == "patwaittime1" ||
|
||||
cmd == "patwaittime2") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
int level = cmd[cmd.find_first_of("012")] - '0';
|
||||
waittime[level] = StringTo<uint64_t>(args[1]);
|
||||
} else {
|
||||
throw RuntimeError("Unknown command in pattern file " + cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void slsDetectorDefs::patternParameters::save(const std::string &fname) {
|
||||
std::ofstream output_file(fname);
|
||||
if (!output_file) {
|
||||
throw RuntimeError("Could not open pattern file " + fname +
|
||||
" for writing");
|
||||
}
|
||||
std::cout << "is it really going here??" << std : endl;
|
||||
std::ostringstream os;
|
||||
// pattern word
|
||||
for (uint32_t i = limits[0]; i <= limits[1]; ++i) {
|
||||
output_file << "patword [" << sls::ToStringHex(i, 4) << ", "
|
||||
<< sls::ToStringHex(word[i], 16) << "]" << std::endl;
|
||||
}
|
||||
|
||||
/*
|
||||
for (std::string line; std::getline(output_file, line);) {
|
||||
if (line.find('#') != std::string::npos) {
|
||||
line.erase(line.find('#'));
|
||||
}
|
||||
LOG(logDEBUG1) << "line after removing comments:\n\t" << line;
|
||||
if (line.length() > 1) {
|
||||
|
||||
// convert command and string to a vector
|
||||
std::istringstream iss(line);
|
||||
auto it = std::istream_iterator<std::string>(iss);
|
||||
std::vector<std::string> args = std::vector<std::string>(
|
||||
it, std::istream_iterator<std::string>());
|
||||
|
||||
std::string cmd = args[0];
|
||||
int nargs = args.size() - 1;
|
||||
|
||||
if (cmd == "patword") {
|
||||
if (nargs != 2) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
uint32_t addr = StringTo<uint32_t>(args[1]);
|
||||
if (addr >= MAX_PATTERN_LENGTH) {
|
||||
throw RuntimeError("Invalid address for " +
|
||||
ToString(args));
|
||||
}
|
||||
word[addr] = StringTo<uint64_t>(args[2]);
|
||||
} else if (cmd == "patioctrl") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
patioctrl = StringTo<uint64_t>(args[1]);
|
||||
} else if (cmd == "patlimits") {
|
||||
if (nargs != 2) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
patlimits[0] = StringTo<uint32_t>(args[1]);
|
||||
patlimits[1] = StringTo<uint32_t>(args[2]);
|
||||
} else if (cmd == "patloop0" || cmd == "patloop1" ||
|
||||
cmd == "patloop2") {
|
||||
if (nargs != 2) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
int level = cmd[cmd.find_first_of("012")] - '0';
|
||||
int patloop1 = StringTo<uint32_t>(args[1]);
|
||||
int patloop2 = StringTo<uint32_t>(args[2]);
|
||||
patloop[level * 2 + 0] = patloop1;
|
||||
patloop[level * 2 + 1] = patloop2;
|
||||
} else if (cmd == "patnloop0" || cmd == "patnloop1" ||
|
||||
cmd == "patnloop2") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
int level = cmd[cmd.find_first_of("012")] - '0';
|
||||
patnloop[level] = StringTo<uint32_t>(args[1]);
|
||||
} else if (cmd == "patwait0" || cmd == "patwait1" ||
|
||||
cmd == "patwait2") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
int level = cmd[cmd.find_first_of("012")] - '0';
|
||||
patwait[level] = StringTo<uint32_t>(args[1]);
|
||||
} else if (cmd == "patwaittime0" || cmd == "patwaittime1" ||
|
||||
cmd == "patwaittime2") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
int level = cmd[cmd.find_first_of("012")] - '0';
|
||||
patwaittime[level] = StringTo<uint64_t>(args[1]);
|
||||
} else {
|
||||
throw RuntimeError("Unknown command in pattern file " +
|
||||
cmd);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void slsDetectorDefs::patternParameters::validate() const {
|
||||
if (limits[0] >= MAX_PATTERN_LENGTH || limits[1] >= MAX_PATTERN_LENGTH) {
|
||||
throw RuntimeError("Invalid Pattern limits address [" +
|
||||
ToString(limits[0]) + std::string(", ") +
|
||||
ToString(limits[1]) + std::string("]"));
|
||||
}
|
||||
for (int i = 0; i != 3; ++i) {
|
||||
if (loop[i * 2 + 0] >= MAX_PATTERN_LENGTH ||
|
||||
loop[i * 2 + 1] >= MAX_PATTERN_LENGTH) {
|
||||
throw RuntimeError("Invalid Pattern loop address for level " +
|
||||
ToString(i) + std::string(" [") +
|
||||
ToString(loop[i * 2 + 0]) + std::string(", ") +
|
||||
ToString(loop[i * 2 + 1]) + std::string("]"));
|
||||
}
|
||||
if (wait[i] >= MAX_PATTERN_LENGTH) {
|
||||
throw RuntimeError("Invalid Pattern wait address for level " +
|
||||
ToString(i) + std::string(" ") +
|
||||
ToString(wait[i]));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user