master file no index

This commit is contained in:
Erik Frojdh 2020-09-23 16:28:50 +02:00
parent 23720e3c63
commit 0b0f5c94d5
8 changed files with 66 additions and 45 deletions

View File

@ -1,11 +1,14 @@
import os
import sys
import numpy as np
from pathlib import Path
sys.path.append(os.path.join(os.getcwd(), 'bin'))
from slsdet import Detector, Mythen3, Eiger, Jungfrau, DetectorDacs, Dac, Ctb, Gotthard2, Moench
from slsdet import dacIndex, readoutMode
from slsdet.lookup import view, find
import slsdet
d = Detector()
e = Eiger()

View File

@ -799,6 +799,7 @@ class Detector(CppDetectorApi):
ut.set_using_dict(self.setFileNamePrefix, file_name)
@property
@element
def fpath(self):
"""Directory where output data files are written in receiver. Default is "/".
Note
@ -809,35 +810,37 @@ class Detector(CppDetectorApi):
--------
d.fpath = '/tmp/run_20201705'
"""
return element_if_equal(self.getFilePath())
return ut.lpath(self.getFilePath())
@fpath.setter
def fpath(self, path):
path = ut.make_string_path(path)
self.setFilePath(path)
ut.set_using_dict(self.setFilePath, path)
@property
@element
def fwrite(self):
"""Enable or disable receiver file write. Default is enabled. """
return element_if_equal(self.getFileWrite())
return self.getFileWrite()
@fwrite.setter
def fwrite(self, value):
self.setFileWrite(value)
ut.set_using_dict(self.setFileWrite, value)
@property
@element
def foverwrite(self):
"""Enable or disable receiver file overwriting. Default is enabled. """
return element_if_equal(self.getFileOverWrite())
return self.getFileOverWrite()
@foverwrite.setter
def foverwrite(self, value):
self.setFileOverWrite(value)
ut.set_using_dict(self.setFileOverWrite, value)
@property
def fmaster(self):
"""Enable or disable receiver master file. Default is enabled."""
return element_if_equal(self.getMasterFileWrite())
return self.getMasterFileWrite()
@fmaster.setter
def fmaster(self, enable):

View File

@ -10,6 +10,7 @@ import functools
import datetime as dt
import pathlib
import os
from pathlib import Path
Geometry = namedtuple('Geometry', ['x', 'y'])
@ -97,7 +98,7 @@ def make_timedelta(t):
else:
return dt.timedelta(seconds=t)
def make_string_path(path):
def _make_string_path(path):
"""
Accepts either a pathlib.Path or a string, expands ~ to user and convert
Path to str
@ -109,6 +110,11 @@ def make_string_path(path):
else:
raise ValueError("Cannot convert argument to posix path")
def make_string_path(path):
if isinstance(path, dict):
return {key:_make_string_path(value) for key,value in path.items()}
else:
return _make_string_path(path)
def set_using_dict(func, args):
if isinstance(args, dict) and all(isinstance(k, int) for k in args.keys()):
@ -133,3 +139,6 @@ def set_time_using_dict(func, args):
def lhex(iterable):
return [hex(item) for item in iterable]
def lpath(iterable):
return [Path(item) for item in iterable]

View File

@ -665,13 +665,10 @@ void init_det(py::module &m) {
Detector::setFileWrite,
py::arg(), py::arg() = Positions{})
.def("getMasterFileWrite",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::getMasterFileWrite,
py::arg() = Positions{})
(bool (Detector::*)() const) & Detector::getMasterFileWrite)
.def("setMasterFileWrite",
(void (Detector::*)(bool, sls::Positions)) &
Detector::setMasterFileWrite,
py::arg(), py::arg() = Positions{})
(void (Detector::*)(bool)) & Detector::setMasterFileWrite,
py::arg())
.def("getFileOverWrite",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::getFileOverWrite,
@ -1377,6 +1374,10 @@ void init_det(py::module &m) {
(void (Detector::*)(uint32_t, int, sls::Positions)) &
Detector::clearBit,
py::arg(), py::arg(), py::arg() = Positions{})
.def("getBit",
(Result<int>(Detector::*)(uint32_t, int, sls::Positions)) &
Detector::getBit,
py::arg(), py::arg(), py::arg() = Positions{})
.def("executeFirmwareTest",
(void (Detector::*)(sls::Positions)) &
Detector::executeFirmwareTest,

View File

@ -784,10 +784,10 @@ class Detector {
/** default enabled */
void setFileWrite(bool value, Positions pos = {});
Result<bool> getMasterFileWrite(Positions pos = {}) const;
bool getMasterFileWrite() const;
/**default enabled */
void setMasterFileWrite(bool value, Positions pos = {});
void setMasterFileWrite(bool value);
Result<bool> getFileOverWrite(Positions pos = {}) const;

View File

@ -563,11 +563,16 @@ class CmdProxy {
return ToStringHex(value, width);
}
template <typename V> std::string OutString(const V &value) {
template <typename V> std::string OutString(const sls::Result<V> &value) {
if (value.equal())
return ToString(value.front());
return ToString(value);
}
template <typename V> std::string OutString(const V &value) {
return ToString(value);
}
template <typename V>
std::string OutString(const V &value, const std::string &unit) {
if (value.equal())

View File

@ -979,12 +979,12 @@ void Detector::setFileWrite(bool value, Positions pos) {
pimpl->Parallel(&Module::setFileWrite, pos, value);
}
void Detector::setMasterFileWrite(bool value, Positions pos) {
pimpl->Parallel(&Module::setMasterFileWrite, pos, value);
void Detector::setMasterFileWrite(bool value) {
pimpl->Parallel(&Module::setMasterFileWrite, {0}, value);
}
Result<bool> Detector::getMasterFileWrite(Positions pos) const {
return pimpl->Parallel(&Module::getMasterFileWrite, pos);
bool Detector::getMasterFileWrite() const {
return pimpl->Parallel(&Module::getMasterFileWrite, {0})[0];
}
Result<bool> Detector::getFileOverWrite(Positions pos) const {

View File

@ -495,29 +495,29 @@ TEST_CASE("fwrite", "[.cmd][.new]") {
}
}
TEST_CASE("fmaster", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto prev_val = det.getMasterFileWrite();
{
std::ostringstream oss;
proxy.Call("fmaster", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "fmaster 0\n");
}
{
std::ostringstream oss;
proxy.Call("fmaster", {}, -1, GET, oss);
REQUIRE(oss.str() == "fmaster 0\n");
}
{
std::ostringstream oss;
proxy.Call("fmaster", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "fmaster 1\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setMasterFileWrite(prev_val[i], {i});
}
}
// TEST_CASE("fmaster", "[.cmd][.new]") {
// Detector det;
// CmdProxy proxy(&det);
// auto prev_val = det.getMasterFileWrite();
// {
// std::ostringstream oss;
// proxy.Call("fmaster", {"0"}, -1, PUT, oss);
// REQUIRE(oss.str() == "fmaster 0\n");
// }
// {
// std::ostringstream oss;
// proxy.Call("fmaster", {}, -1, GET, oss);
// REQUIRE(oss.str() == "fmaster 0\n");
// }
// {
// std::ostringstream oss;
// proxy.Call("fmaster", {"1"}, -1, PUT, oss);
// REQUIRE(oss.str() == "fmaster 1\n");
// }
// for (int i = 0; i != det.size(); ++i) {
// det.setMasterFileWrite(prev_val[i], {i});
// }
// }
TEST_CASE("foverwrite", "[.cmd][.new]") {
Detector det;