veto file in

This commit is contained in:
2020-07-14 18:51:47 +02:00
parent 35dbc3813d
commit 7752b86d97
12 changed files with 255 additions and 22 deletions

View File

@ -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 << ' ';

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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();