mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-12-29 15:41:18 +01:00
badchannels done
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user