mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
veto file in
This commit is contained in:
@ -983,6 +983,10 @@ class Detector {
|
||||
void setVetoReference(const int gainIndex, const int value,
|
||||
Positions pos = {});
|
||||
|
||||
/** [Gotthard2] */
|
||||
void setVetoFile(const int chipIndex, const std::string &fname,
|
||||
Positions pos = {});
|
||||
|
||||
/** [Gotthard2] */
|
||||
Result<defs::burstMode> getBurstMode(Positions pos = {});
|
||||
|
||||
|
@ -1669,6 +1669,29 @@ std::string CmdProxy::VetoReference(int action) {
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string CmdProxy::VetoFile(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[chip index 0-10, -1 for all] [file name] \n\t[Gotthard2] Set "
|
||||
"veto reference for each 128 channels for specific chip. The "
|
||||
"file should have 128 rows of gain index and 12 bit value in hex"
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
throw sls::RuntimeError(
|
||||
"cannot get vetofile. Did you mean vetophoton?");
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
if (args.size() != 2) {
|
||||
WrongNumberOfParameters(2);
|
||||
}
|
||||
det->setVetoFile(StringTo<int>(args[0]), args[1], {det_id});
|
||||
os << sls::ToString(args) << '\n';
|
||||
} else {
|
||||
throw sls::RuntimeError("Unknown action");
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string CmdProxy::BurstMode(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
|
@ -834,6 +834,7 @@ class CmdProxy {
|
||||
{"inj_ch", &CmdProxy::InjectChannel},
|
||||
{"vetophoton", &CmdProxy::VetoPhoton},
|
||||
{"vetoref", &CmdProxy::VetoReference},
|
||||
{"vetofile", &CmdProxy::VetoFile},
|
||||
{"burstmode", &CmdProxy::BurstMode},
|
||||
{"cdsgain", &CmdProxy::cdsgain},
|
||||
{"filter", &CmdProxy::filter},
|
||||
@ -1015,6 +1016,7 @@ class CmdProxy {
|
||||
std::string InjectChannel(int action);
|
||||
std::string VetoPhoton(int action);
|
||||
std::string VetoReference(int action);
|
||||
std::string VetoFile(int action);
|
||||
std::string BurstMode(int action);
|
||||
/* Mythen3 Specific */
|
||||
std::string Counters(int action);
|
||||
|
@ -1297,6 +1297,11 @@ void Detector::setVetoReference(const int gainIndex, const int value,
|
||||
pimpl->Parallel(&Module::setVetoReference, pos, gainIndex, value);
|
||||
}
|
||||
|
||||
void Detector::setVetoFile(const int chipIndex, const std::string &fname,
|
||||
Positions pos) {
|
||||
pimpl->Parallel(&Module::setVetoFile, pos, chipIndex, fname);
|
||||
}
|
||||
|
||||
Result<defs::burstMode> Detector::getBurstMode(Positions pos) {
|
||||
return pimpl->Parallel(&Module::getBurstMode, pos);
|
||||
}
|
||||
|
@ -1521,6 +1521,82 @@ void Module::setVetoReference(const int gainIndex, const int value) {
|
||||
sendToDetector(F_SET_VETO_REFERENCE, args, nullptr);
|
||||
}
|
||||
|
||||
void Module::setVetoFile(const int chipIndex, const std::string &fname) {
|
||||
if (shm()->myDetectorType != GOTTHARD2) {
|
||||
throw RuntimeError(
|
||||
"Set Veto file is not implemented for this detector");
|
||||
}
|
||||
if (chipIndex < -1 || chipIndex >= shm()->nChip.x) {
|
||||
throw RuntimeError("Could not set veto file. Invalid chip index: " +
|
||||
std::to_string(chipIndex));
|
||||
}
|
||||
std::ifstream infile(fname.c_str());
|
||||
if (!infile.is_open()) {
|
||||
throw RuntimeError("Could not set veto file for chip " +
|
||||
std::to_string(chipIndex) +
|
||||
". Could not open file: " + fname);
|
||||
}
|
||||
|
||||
std::ifstream input_file(fname);
|
||||
if (!input_file.is_open()) {
|
||||
throw RuntimeError("Could not open veto file " + fname +
|
||||
" for reading");
|
||||
}
|
||||
|
||||
int ch = shm()->nChan.x;
|
||||
int nRead = 0;
|
||||
int gainIndices[ch];
|
||||
memset(gainIndices, 0, sizeof(gainIndices));
|
||||
int values[ch];
|
||||
memset(values, 0, sizeof(values));
|
||||
|
||||
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);
|
||||
std::string val;
|
||||
if (!(iss >> gainIndices[nRead] >> val)) {
|
||||
throw RuntimeError("Could not set veto file. Invalid gain "
|
||||
"or reference value for channel " +
|
||||
std::to_string(nRead));
|
||||
}
|
||||
try {
|
||||
values[nRead] = StringTo<int>(val);
|
||||
} catch (...) {
|
||||
throw RuntimeError("Could not set veto file. Invalid value " +
|
||||
val + " for channel " +
|
||||
std::to_string(nRead));
|
||||
}
|
||||
++nRead;
|
||||
if (nRead >= ch) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int fnum = F_SET_VETO_FILE;
|
||||
int ret = FAIL;
|
||||
int args[]{chipIndex, ch};
|
||||
LOG(logDEBUG) << "Sending veto file value to detector [chip:" << chipIndex
|
||||
<< "]: " << args;
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(&fnum, sizeof(fnum));
|
||||
client.Send(args, sizeof(args));
|
||||
client.Send(gainIndices, sizeof(gainIndices));
|
||||
client.Send(values, sizeof(values));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
slsDetectorDefs::burstMode Module::getBurstMode() {
|
||||
auto r = sendToDetector<int>(F_GET_BURST_MODE);
|
||||
return static_cast<slsDetectorDefs::burstMode>(r);
|
||||
|
@ -373,6 +373,7 @@ class Module : public virtual slsDetectorDefs {
|
||||
void setVetoPhoton(const int chipIndex, const int numPhotons,
|
||||
const int energy, const std::string &fname);
|
||||
void setVetoReference(const int gainIndex, const int value);
|
||||
void setVetoFile(const int chipIndex, const std::string &fname);
|
||||
burstMode getBurstMode();
|
||||
void setBurstMode(burstMode value);
|
||||
bool getCDSGain();
|
||||
|
@ -343,6 +343,20 @@ TEST_CASE("vetoref", "[.cmd][.new]") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("vetofile", "[.cmd][.new]") {
|
||||
Detector det;
|
||||
CmdProxy proxy(&det);
|
||||
auto det_type = det.getDetectorType().squash();
|
||||
|
||||
if (det_type == defs::GOTTHARD2) {
|
||||
REQUIRE_THROWS(proxy.Call("vetofile", {}, -1, GET));
|
||||
REQUIRE_THROWS(proxy.Call("vetofile", {"12", "/tmp/bla.txt"}, -1,
|
||||
PUT)); // invalid chip index
|
||||
} else {
|
||||
REQUIRE_THROWS(proxy.Call("vetofile", {"-1"}, -1, GET));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("burstmode", "[.cmd][.new]") {
|
||||
Detector det;
|
||||
CmdProxy proxy(&det);
|
||||
|
Reference in New Issue
Block a user