mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-22 03:40:04 +02:00
WIP
This commit is contained in:
parent
fa25340e5c
commit
01c785271f
Binary file not shown.
@ -35,32 +35,6 @@ int getChipStatusRegister(){
|
|||||||
return chipStatusRegister;
|
return chipStatusRegister;
|
||||||
}
|
}
|
||||||
|
|
||||||
// int setGainCaps(int caps){
|
|
||||||
// int csr = getChipStatusRegister();
|
|
||||||
|
|
||||||
// int gain_mask = 0;
|
|
||||||
// gain_mask |= 1 << CSR_C10pre;
|
|
||||||
// gain_mask |= 1 << CSR_C15sh;
|
|
||||||
// gain_mask |= 1 << CSR_C30sh;
|
|
||||||
// gain_mask |= 1 << CSR_C50sh;
|
|
||||||
// gain_mask |= 1 << CSR_C225ACsh;
|
|
||||||
// gain_mask |= 1 << CSR_C15pre;
|
|
||||||
|
|
||||||
// LOG(logINFO, ("gain_mask: 0x%x\n", gain_mask));
|
|
||||||
// LOG(logINFO, ("csr: 0x%x\n", csr));
|
|
||||||
// csr &= ~gain_mask; //zero out the bits in the gain mask
|
|
||||||
// LOG(logINFO, ("csr: 0x%x\n", csr));
|
|
||||||
// caps &= gain_mask;
|
|
||||||
// csr |= caps;
|
|
||||||
|
|
||||||
// LOG(logINFO, ("csr: 0x%x\n", csr));
|
|
||||||
|
|
||||||
// //now comes the actual setting
|
|
||||||
|
|
||||||
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
patternParameters *setChipStatusRegister(int csr) {
|
patternParameters *setChipStatusRegister(int csr) {
|
||||||
int iaddr=0;
|
int iaddr=0;
|
||||||
int nbits=18;
|
int nbits=18;
|
||||||
|
@ -1061,30 +1061,13 @@ int64_t getMeasurementTime() {
|
|||||||
/* parameters - module, speed, readout */
|
/* parameters - module, speed, readout */
|
||||||
|
|
||||||
int setModule(sls_detector_module myMod, char *mess) {
|
int setModule(sls_detector_module myMod, char *mess) {
|
||||||
|
|
||||||
LOG(logINFO, ("Setting module\n"));
|
LOG(logINFO, ("Setting module\n"));
|
||||||
|
|
||||||
// settings
|
|
||||||
if (myMod.reg >= 0) {
|
if (setGainCaps(myMod.reg)){
|
||||||
setSettings((enum detectorSettings)myMod.reg);
|
sprintf(mess, "Could not set module gain caps\n");
|
||||||
if (getSettings() != (enum detectorSettings)myMod.reg) {
|
LOG(logERROR, (mess));
|
||||||
sprintf(
|
return FAIL;
|
||||||
mess,
|
|
||||||
"Could not set module. Could not set settings to %d, read %d\n",
|
|
||||||
myMod.reg, (int)getSettings());
|
|
||||||
LOG(logERROR, (mess));
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
detectorModules->reg = myMod.reg;
|
|
||||||
}
|
|
||||||
// custom trimbit file
|
|
||||||
else {
|
|
||||||
// changed for setsettings (direct),
|
|
||||||
// custom trimbit file (setmodule with myMod.reg as -1),
|
|
||||||
// change of dac (direct)
|
|
||||||
for (int i = 0; i < NCOUNTERS; ++i) {
|
|
||||||
setThresholdEnergy(i, -1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// dacs
|
// dacs
|
||||||
@ -1108,24 +1091,12 @@ int setModule(sls_detector_module myMod, char *mess) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if settings given and cannot be validated (after setting dacs), return
|
|
||||||
// error
|
|
||||||
if (myMod.reg >= 0) {
|
|
||||||
if (getSettings() != (enum detectorSettings)myMod.reg) {
|
|
||||||
sprintf(
|
|
||||||
mess,
|
|
||||||
"Could not set module. The dacs in file do not correspond to "
|
|
||||||
"settings %d\n",
|
|
||||||
myMod.reg);
|
|
||||||
LOG(logERROR, (mess));
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// threshold
|
// threshold
|
||||||
for (int i = 0; i < NCOUNTERS; ++i) {
|
for (int i = 0; i < NCOUNTERS; ++i) {
|
||||||
if (myMod.eV[i] >= 0) {
|
if (myMod.eV[i] >= 0) {
|
||||||
setThresholdEnergy(i, myMod.eV[i]);
|
setThresholdEnergy(i, myMod.eV[i]);
|
||||||
|
}else{
|
||||||
|
setThresholdEnergy(i, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1549,18 +1549,11 @@ int set_module(int file_des) {
|
|||||||
// only set
|
// only set
|
||||||
else if (Server_VerifyLock() == OK) {
|
else if (Server_VerifyLock() == OK) {
|
||||||
// check index
|
// check index
|
||||||
|
|
||||||
|
#if !(defined(EIGERD) || defined(MYTHEN3D))
|
||||||
|
//TODO! Check if this is used for any detector
|
||||||
switch (module.reg) {
|
switch (module.reg) {
|
||||||
#ifdef EIGERD
|
#ifdef JUNGFRAUD
|
||||||
case STANDARD:
|
|
||||||
case HIGHGAIN:
|
|
||||||
case LOWGAIN:
|
|
||||||
case VERYHIGHGAIN:
|
|
||||||
case VERYLOWGAIN:
|
|
||||||
#elif MYTHEN3D
|
|
||||||
case STANDARD:
|
|
||||||
case FAST:
|
|
||||||
case HIGHGAIN:
|
|
||||||
#elif JUNGFRAUD
|
|
||||||
case DYNAMICGAIN:
|
case DYNAMICGAIN:
|
||||||
case DYNAMICHG0:
|
case DYNAMICHG0:
|
||||||
case FIXGAIN1:
|
case FIXGAIN1:
|
||||||
@ -1579,10 +1572,12 @@ int set_module(int file_des) {
|
|||||||
modeNotImplemented("Settings", (int)module.reg);
|
modeNotImplemented("Settings", (int)module.reg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
ret = setModule(module, mess);
|
ret = setModule(module, mess);
|
||||||
enum detectorSettings retval = getSettings();
|
enum detectorSettings retval = getSettings();
|
||||||
|
#if !(defined(EIGERD) || defined(MYTHEN3D))
|
||||||
validate(module.reg, (int)retval, "set module (settings)", DEC);
|
validate(module.reg, (int)retval, "set module (settings)", DEC);
|
||||||
|
#endif
|
||||||
LOG(logDEBUG1, ("Settings: %d\n", retval));
|
LOG(logDEBUG1, ("Settings: %d\n", retval));
|
||||||
}
|
}
|
||||||
free(myChan);
|
free(myChan);
|
||||||
|
@ -3203,6 +3203,9 @@ sls_detector_module Module::readSettingsFile(const std::string &fname,
|
|||||||
throw RuntimeError("Could not open settings file: " + fname);
|
throw RuntimeError("Could not open settings file: " + fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto file_size = getFileSize(infile);
|
||||||
|
|
||||||
|
|
||||||
// eiger
|
// eiger
|
||||||
if (shm()->myDetectorType == EIGER) {
|
if (shm()->myDetectorType == EIGER) {
|
||||||
infile.read(reinterpret_cast<char *>(myMod.dacs),
|
infile.read(reinterpret_cast<char *>(myMod.dacs),
|
||||||
@ -3228,6 +3231,16 @@ sls_detector_module Module::readSettingsFile(const std::string &fname,
|
|||||||
|
|
||||||
// mythen3 (dacs, trimbits)
|
// mythen3 (dacs, trimbits)
|
||||||
else if (shm()->myDetectorType == MYTHEN3) {
|
else if (shm()->myDetectorType == MYTHEN3) {
|
||||||
|
int expected_size =
|
||||||
|
sizeof(int) * myMod.ndac + sizeof(int) * myMod.nchan + sizeof(myMod.reg);
|
||||||
|
if (file_size != expected_size) {
|
||||||
|
throw RuntimeError("The size of the settings file: " + fname +
|
||||||
|
" differs from the expected size, " +
|
||||||
|
std::to_string(file_size) + " instead of " +
|
||||||
|
std::to_string(expected_size) + " bytes");
|
||||||
|
}
|
||||||
|
infile.read(reinterpret_cast<char *>(&myMod.reg),
|
||||||
|
sizeof(myMod.reg));
|
||||||
infile.read(reinterpret_cast<char *>(myMod.dacs),
|
infile.read(reinterpret_cast<char *>(myMod.dacs),
|
||||||
sizeof(int) * (myMod.ndac));
|
sizeof(int) * (myMod.ndac));
|
||||||
for (int i = 0; i < myMod.ndac; ++i) {
|
for (int i = 0; i < myMod.ndac; ++i) {
|
||||||
|
@ -48,3 +48,7 @@ int writeDataFile(std::string fname, int nch, short int *data);
|
|||||||
|
|
||||||
// mkdir -p path implemented by recursive calls
|
// mkdir -p path implemented by recursive calls
|
||||||
void mkdir_p(const std::string &path, std::string dir = "");
|
void mkdir_p(const std::string &path, std::string dir = "");
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
int getFileSize(std::ifstream &ifs);
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "sls/sls_detector_exceptions.h"
|
#include "sls/sls_detector_exceptions.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <ios>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -92,3 +93,13 @@ void mkdir_p(const std::string &path, std::string dir) {
|
|||||||
if (i + 1 < path.length())
|
if (i + 1 < path.length())
|
||||||
mkdir_p(path.substr(i + 1), dir);
|
mkdir_p(path.substr(i + 1), dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
int getFileSize(std::ifstream &ifs) {
|
||||||
|
auto current_pos = ifs.tellg();
|
||||||
|
ifs.seekg(0, std::ios::end);
|
||||||
|
int file_size = ifs.tellg();
|
||||||
|
ifs.seekg(current_pos);
|
||||||
|
return file_size;
|
||||||
|
}
|
||||||
|
} // namespace sls
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
target_sources(tests PRIVATE
|
target_sources(tests PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test-bit_utils.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/test-bit_utils.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/test-file_utils.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test-container_utils.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/test-container_utils.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test-network_utils.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/test-network_utils.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test-string_utils.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/test-string_utils.cpp
|
||||||
|
28
slsSupportLib/tests/test-file_utils.cpp
Normal file
28
slsSupportLib/tests/test-file_utils.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "catch.hpp"
|
||||||
|
#include "sls/file_utils.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
TEST_CASE("Get size of empty file") {
|
||||||
|
char fname[] = "temfile_XXXXXX";
|
||||||
|
int fh = mkstemp(fname);
|
||||||
|
std::ifstream ifs(fname);
|
||||||
|
auto size = sls::getFileSize(ifs);
|
||||||
|
REQUIRE(size == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Get size of file with data") {
|
||||||
|
constexpr size_t n_bytes = 137;
|
||||||
|
std::vector<char> data(n_bytes);
|
||||||
|
char fname[] = "temfile_XXXXXX";
|
||||||
|
int fh = mkstemp(fname);
|
||||||
|
write(fh, data.data(), n_bytes);
|
||||||
|
|
||||||
|
std::ifstream ifs(fname);
|
||||||
|
auto size = sls::getFileSize(ifs);
|
||||||
|
REQUIRE(size == n_bytes);
|
||||||
|
REQUIRE(ifs.tellg() == 0); //getting size resets pos!
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user