badchannels done

This commit is contained in:
2020-07-15 18:24:17 +02:00
parent d7f490701b
commit ca298580f3
13 changed files with 362 additions and 24 deletions

View File

@ -1752,7 +1752,7 @@ std::string CmdProxy::ConfigureADC(int action) {
WrongNumberOfParameters(2);
}
auto t = det->getADCConfiguration(StringTo<int>(args[0]),
StringTo<int>(args[1]));
StringTo<int>(args[1]), {det_id});
os << OutStringHex(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 3) {
@ -1769,6 +1769,31 @@ std::string CmdProxy::ConfigureADC(int action) {
return os.str();
}
std::string CmdProxy::BadChannels(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[fname]\n\t[Gotthard2] Sets the bad channels (from file of bad "
"channel numbers) to be masked out."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->getBadChannels(args[0], {det_id});
os << "successfully retrieved" << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->setBadChannels(args[0], {det_id});
os << "successfully loaded" << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/* Mythen3 Specific */
std::string CmdProxy::Counters(int action) {

View File

@ -372,6 +372,27 @@
return os.str(); \
}
/** set only, 1 argument */
#define EXECUTE_SET_COMMAND_1ARG(CMDNAME, SETFCN, HLPSTR) \
std::string CMDNAME(const int action) { \
std::ostringstream os; \
os << cmd << ' '; \
if (action == slsDetectorDefs::HELP_ACTION) \
os << HLPSTR << '\n'; \
else if (action == slsDetectorDefs::GET_ACTION) { \
throw sls::RuntimeError("Cannot get"); \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (args.size() != 1) { \
WrongNumberOfParameters(1); \
} \
det->SETFCN(args[0]); \
os << args.front() << '\n'; \
} else { \
throw sls::RuntimeError("Unknown action"); \
} \
return os.str(); \
}
/** get only */
#define GET_COMMAND(CMDNAME, GETFCN, HLPSTR) \
std::string CMDNAME(const int action) { \
@ -842,6 +863,7 @@ class CmdProxy {
{"timingsource", &CmdProxy::timingsource},
{"veto", &CmdProxy::veto},
{"confadc", &CmdProxy::ConfigureADC},
{"badchannels", &CmdProxy::BadChannels},
/* Mythen3 Specific */
{"counters", &CmdProxy::Counters},
@ -1020,6 +1042,7 @@ class CmdProxy {
std::string VetoFile(int action);
std::string BurstMode(int action);
std::string ConfigureADC(int action);
std::string BadChannels(int action);
/* Mythen3 Specific */
std::string Counters(int action);
std::string GateDelay(int action);
@ -1093,7 +1116,7 @@ class CmdProxy {
"g2_lc_hg | g2_lc_lg | g4_hg | g4_lg]"
"\n\t[Eiger] Use threshold or thresholdnotb.");
EXECUTE_SET_COMMAND_NOID_1ARG(
EXECUTE_SET_COMMAND_1ARG(
trimbits, loadTrimbits,
"[fname]\n\t[Eiger][Mythen3] Loads the trimbit file to detector. If no "
"extension specified, serial number of each module is attached.");

View File

@ -1363,6 +1363,14 @@ void Detector::setADCConfiguration(const int chipIndex, const int adcIndex,
value);
}
void Detector::getBadChannels(const std::string &fname, Positions pos) const {
pimpl->Parallel(&Module::getBadChannels, pos, fname);
}
void Detector::setBadChannels(const std::string &fname, Positions pos) {
pimpl->Parallel(&Module::setBadChannels, pos, fname);
}
// Mythen3 Specific
Result<uint32_t> Detector::getCounterMask(Positions pos) const {

View File

@ -1400,18 +1400,17 @@ std::vector<int> Module::getVetoPhoton(const int chipIndex) {
client.Receive(mess, MAX_STR_LENGTH);
throw RuntimeError("Detector " + std::to_string(moduleId) +
" returned error: " + std::string(mess));
} else {
int nch = -1;
client.Receive(&nch, sizeof(nch));
int adus[nch];
memset(adus, 0, sizeof(adus));
client.Receive(adus, sizeof(adus));
std::vector<int> retvals(adus, adus + nch);
LOG(logDEBUG1) << "Getting veto photon [" << chipIndex << "]: " << nch
<< " channels\n";
return retvals;
}
int nch = -1;
client.Receive(&nch, sizeof(nch));
int adus[nch];
memset(adus, 0, sizeof(adus));
client.Receive(adus, sizeof(adus));
std::vector<int> retvals(adus, adus + nch);
LOG(logDEBUG1) << "Getting veto photon [" << chipIndex << "]: " << nch
<< " channels\n";
return retvals;
}
void Module::setVetoPhoton(const int chipIndex, const int numPhotons,
@ -1460,7 +1459,8 @@ void Module::setVetoPhoton(const int chipIndex, const int numPhotons,
// first line: caluclate gain index from gain thresholds from file
if (firstLine) {
int g0 = -1, g1 = -1;
if (!(ss >> g0 >> g1)) {
ss >> g0 >> g1;
if (ss.fail()) {
throw RuntimeError(
"Could not set veto photon. Invalid gain thresholds");
}
@ -1477,7 +1477,8 @@ void Module::setVetoPhoton(const int chipIndex, const int numPhotons,
// read pedestal and gain values
else {
double p[3] = {-1, -1, -1}, g[3] = {-1, -1, -1};
if (!(ss >> p[0] >> p[1] >> p[2] >> g[0] >> g[1] >> g[2])) {
ss >> p[0] >> p[1] >> p[2] >> g[0] >> g[1] >> g[2];
if (ss.fail()) {
throw RuntimeError("Could not set veto photon. Invalid "
"pedestal or gain values for channel " +
std::to_string(nRead));
@ -1559,7 +1560,8 @@ void Module::setVetoFile(const int chipIndex, const std::string &fname) {
// convert command and string to a vector
std::istringstream iss(line);
std::string val;
if (!(iss >> gainIndices[nRead] >> val)) {
iss >> gainIndices[nRead] >> val;
if (iss.fail()) {
throw RuntimeError("Could not set veto file. Invalid gain "
"or reference value for channel " +
std::to_string(nRead));
@ -1656,6 +1658,90 @@ void Module::setADCConfiguration(const int chipIndex, const int adcIndex,
sendToDetector(F_SET_ADC_CONFIGURATION, args, nullptr);
}
void Module::getBadChannels(const std::string &fname) {
LOG(logDEBUG1) << "Getting bad channels to " << fname;
int fnum = F_GET_BAD_CHANNELS;
int ret = FAIL;
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(&fnum, sizeof(fnum));
client.Receive(&ret, sizeof(ret));
if (ret == FAIL) {
char mess[MAX_STR_LENGTH]{};
client.Receive(mess, MAX_STR_LENGTH);
throw RuntimeError("Detector " + std::to_string(moduleId) +
" returned error: " + std::string(mess));
}
// receive badchannels
int nch = -1;
std::vector<int> badchannels;
client.Receive(&nch, sizeof(nch));
if (nch > 0) {
int temp[nch];
memset(temp, 0, sizeof(temp));
client.Receive(temp, sizeof(temp));
badchannels.insert(badchannels.end(), &temp[0], &temp[nch]);
for (int i = 0; i < (int)badchannels.size(); ++i) {
LOG(logDEBUG1) << i << ":" << badchannels[i];
}
}
// save to file
std::ofstream outfile;
outfile.open(fname.c_str(), std::ios_base::out);
if (!outfile.is_open()) {
throw RuntimeError("Could not create file to save pattern");
}
for (int i = 0; i < nch; ++i) {
outfile << badchannels[i] << '\n';
}
LOG(logDEBUG1) << nch << " bad channels saved to file";
}
void Module::setBadChannels(const std::string &fname) {
// read bad channels file
std::ifstream input_file(fname);
if (!input_file.is_open()) {
throw RuntimeError("Could not open bad channels file " + fname +
" for reading");
}
std::vector<int> badchannels;
for (std::string line; std::getline(input_file, line);) {
if (line.find(' ') != std::string::npos) {
line.erase(line.find(' '));
}
if (line.length() >= 1) {
std::istringstream iss(line);
int ival = 0;
iss >> ival;
if (iss.fail()) {
throw RuntimeError("Could not load bad channels file. Invalid "
"channel number at position " +
std::to_string(badchannels.size()));
}
badchannels.push_back(ival);
}
}
// send bad channels to module
int fnum = F_SET_BAD_CHANNELS;
int ret = FAIL;
int nch = badchannels.size();
LOG(logDEBUG1) << "Sending bad channels to detector, nch:" << nch;
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(&fnum, sizeof(fnum));
client.Send(&nch, sizeof(nch));
if (nch > 0) {
client.Send(badchannels.data(), sizeof(int) * nch);
}
client.Receive(&ret, sizeof(ret));
if (ret == FAIL) {
char mess[MAX_STR_LENGTH]{};
client.Receive(mess, MAX_STR_LENGTH);
throw RuntimeError("Detector " + std::to_string(moduleId) +
" returned error: " + std::string(mess));
}
}
// Mythen3 Specific
uint32_t Module::getCounterMask() {

View File

@ -389,6 +389,8 @@ class Module : public virtual slsDetectorDefs {
int getADCConfiguration(const int chipIndex, const int adcIndex);
void setADCConfiguration(const int chipIndex, const int adcIndex,
int value);
void getBadChannels(const std::string &fname);
void setBadChannels(const std::string &fname);
/**************************************************
* *