DiffractionExperiment: Adjust storage cell delay as a parameter

This commit is contained in:
2023-07-04 20:58:48 +02:00
parent 3067604e2a
commit 4ce2fcf98f
13 changed files with 205 additions and 118 deletions

View File

@@ -23,7 +23,7 @@
#define MIN_FRAME_TIME_FULL_SPEED_IN_US 470
#define MAX_FRAME_TIME 2000
#define MAX_SUMMATION 5000
#define MIN_STORAGE_CELL_DELAY_IN_NS 2100
#define READOUT_TIME_IN_US 20
#define GRPC_MAX_MESSAGE_SIZE (1000L*1000L*1000L)

View File

@@ -78,7 +78,7 @@ DiffractionExperiment::DiffractionExperiment(const DetectorSetup& det_setup) {
internal.set_storage_cells(1);
internal.set_storage_cell_start(15);
internal.set_storage_cell_delay_ns(10*1000);
Detector(det_setup);
Mode(DetectorMode::Conversion);
}
@@ -854,7 +854,7 @@ DiffractionExperiment::operator JFJochProtoBuf::DetectorInput() const {
}
ret.set_storage_cell_start(GetStorageCellStart());
ret.set_storage_cell_number(GetStorageCellNumber());
ret.set_storage_cell_delay(7.5);
ret.set_storage_cell_delay_ns(GetStorageCellDelay().count());
if (GetStorageCellNumber() > 1) {
ret.set_period_us((GetFrameTime().count() +10) * GetStorageCellNumber());
@@ -955,7 +955,8 @@ void DiffractionExperiment::LoadDetectorSettings(const JFJochProtoBuf::DetectorS
if (settings.has_pedestal_g2_frames())
PedestalG2Frames(settings.pedestal_g2_frames());
if (settings.has_storage_cell_delay_ns())
StorageCellDelay(std::chrono::nanoseconds(settings.storage_cell_delay_ns()));
ConversionOnCPU(settings.conversion_on_cpu());
} catch (...) {
internal = tmp;
@@ -973,6 +974,7 @@ JFJochProtoBuf::DetectorSettings DiffractionExperiment::GetDetectorSettings() co
ret.set_pedestal_g0_frames(GetPedestalG0Frames());
ret.set_pedestal_g1_frames(GetPedestalG1Frames());
ret.set_pedestal_g2_frames(GetPedestalG2Frames());
ret.set_storage_cell_delay_ns(GetStorageCellDelay().count());
return ret;
}
@@ -1052,6 +1054,7 @@ void DiffractionExperiment::FillMessage(StartMessage &message) const {
message.compression_block_size = JFJochBitShuffleCompressor::DefaultBlockSize;
message.pixel_bit_depth = GetPixelDepth() * 8;
message.storage_cell_number = GetStorageCellNumber();
message.storage_cell_delay_ns = GetStorageCellDelay().count();
message.file_prefix = GetFilePrefix();
message.pixel_signed = IsPixelSigned();
message.sample_name = GetSampleName();
@@ -1241,3 +1244,13 @@ bool DiffractionExperiment::GetSaveCalibration() const {
return dataset.save_calibration();
}
DiffractionExperiment &DiffractionExperiment::StorageCellDelay(std::chrono::nanoseconds input) {
check_min("Storage cell delay [ns]", input.count(), MIN_STORAGE_CELL_DELAY_IN_NS);
internal.set_storage_cell_delay_ns(input.count());
return *this;
}
std::chrono::nanoseconds DiffractionExperiment::GetStorageCellDelay() const {
return std::chrono::nanoseconds(internal.storage_cell_delay_ns());
}

View File

@@ -132,6 +132,9 @@ public:
std::chrono::microseconds GetImageCountTime() const;
std::chrono::microseconds GetFrameCountTime() const;
DiffractionExperiment& StorageCellDelay(std::chrono::nanoseconds input);
std::chrono::nanoseconds GetStorageCellDelay() const;
float GetPhotonEnergy_keV() const;
float GetWavelength_A() const;
float GetBeamX_pxl() const;

View File

@@ -105,7 +105,7 @@ void DetectorWrapper::Start(const JFJochProtoBuf::DetectorInput &request) {
det.setNumberOfTriggers(request.num_triggers());
det.setStorageCellStart(request.storage_cell_start());
det.setNumberOfAdditionalStorageCells(request.storage_cell_number() - 1);
det.setStorageCellDelay(std::chrono::nanoseconds(static_cast<uint64_t>(request.storage_cell_delay() * 1000)));
det.setStorageCellDelay(std::chrono::nanoseconds(request.storage_cell_delay_ns() - MIN_STORAGE_CELL_DELAY_IN_NS));
if (request.period_us() < MIN_FRAME_TIME_HALF_SPEED_IN_US)
det.setReadoutSpeed(slsDetectorDefs::speedLevel::FULL_SPEED);

View File

@@ -540,6 +540,8 @@ void JFJochFrameDeserializer::ProcessStartMessageUserDataElement(CborValue &valu
start_message.summation = GetCBORUInt(map_value);
else if (key == "storage_cell_number")
start_message.storage_cell_number = GetCBORUInt(map_value);
else if (key == "storage_cell_delay")
start_message.storage_cell_delay_ns = GetRational(map_value).first;
else if (key == "compression_algorithm") {
auto tmp = GetCBORString(map_value);
if (tmp == "bslz4")

View File

@@ -255,7 +255,7 @@ inline void CBOR_ENC_USER_DATA(CborEncoder &encoder, const StartMessage& message
CborEncoder mapEncoder;
cborErr(cbor_encode_text_stringz(&encoder, "user_data"));
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, 21));
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, 22));
CBOR_ENC(mapEncoder, "file_prefix", message.file_prefix);
CBOR_ENC(mapEncoder, "sample_name", message.sample_name);
@@ -263,6 +263,8 @@ inline void CBOR_ENC_USER_DATA(CborEncoder &encoder, const StartMessage& message
CBOR_ENC(mapEncoder, "max_spot_count", message.max_spot_count);
CBOR_ENC(mapEncoder, "data_file_count", message.data_file_count);
CBOR_ENC(mapEncoder, "storage_cell_number", message.storage_cell_number);
CBOR_ENC_RATIONAL(mapEncoder, "storage_cell_delay", message.storage_cell_delay_ns, 1000*1000*1000UL);
CBOR_ENC(mapEncoder, "pixel_bit_depth", message.pixel_bit_depth);
CBOR_ENC(mapEncoder, "pixel_signed", message.pixel_signed);
CBOR_ENC(mapEncoder, "min_value", message.min_value);

View File

@@ -52,6 +52,7 @@ struct StartMessage {
uint64_t max_spot_count; // user data
uint64_t storage_cell_number; // user data
uint64_t storage_cell_delay_ns;
bool pixel_mask_enabled;

View File

@@ -22,11 +22,13 @@ type MyState = {
countTimeUs: number | string,
pedestalG0Frames: number | string,
pedestalG1Frames: number | string,
pedestalG2Frames: number | string
pedestalG2Frames: number | string,
storageCellDelayNs: number | string
},
storage_cell_list_value: string,
frame_time_error: boolean,
count_time_error: boolean,
storage_cell_delay_error: boolean,
connection_error: boolean
}
@@ -46,11 +48,13 @@ class DetectorSettings extends Component<MyProps, MyState> {
countTimeUs: 980,
pedestalG0Frames: 2000,
pedestalG1Frames: 300,
pedestalG2Frames: 300
pedestalG2Frames: 300,
storageCellDelayNs: 10000
},
storage_cell_list_value: "1",
frame_time_error: false,
count_time_error: false,
storage_cell_delay_error: false,
connection_error: true
}
@@ -88,6 +92,22 @@ class DetectorSettings extends Component<MyProps, MyState> {
));
}
updateStorageCellDelay = (event: React.ChangeEvent<HTMLInputElement>) => {
let num_val = Number(event.target.value);
let err = !Number.isInteger(num_val);
if (!err) {
if (num_val < 2100) err = true;
}
this.setState(prevState => (
{
storage_cell_delay_error: err,
s : {...prevState.s,
storageCellDelayNs: event.target.value
}
}
));
}
updateFrameTime = (event: React.ChangeEvent<HTMLInputElement>) => {
this.updateCollectionTime(event.target.value, this.state.s.countTimeUs);
@@ -183,10 +203,14 @@ class DetectorSettings extends Component<MyProps, MyState> {
}}/>
<br/><br/>
</Grid>
<Grid item xs={1}/>
<Grid item xs={1}/>
<Grid item xs={2}>
<FormControl>
<InputLabel id="demo-simple-select-label">Storage cell count</InputLabel>
<Select
sx={{width: 120}}
labelId="demo-simple-select-label"
id="demo-simple-select"
value={this.state.storage_cell_list_value}
@@ -202,7 +226,26 @@ class DetectorSettings extends Component<MyProps, MyState> {
</Select>
</FormControl>
<br/><br/>
</Grid>
<Grid item xs={8}>
<TextField id="storage_cell_delay" label="Storage cell delay" variant="outlined"
style={{ minWidth: "100px" }}
error={this.state.storage_cell_delay_error}
onChange={this.updateStorageCellDelay}
value={this.state.s.storageCellDelayNs}
disabled={this.state.connection_error || (this.state.storage_cell_list_value === "1")}
InputProps = {{
inputProps: {
style: {textAlign: 'right'}
},
endAdornment: <InputAdornment position="end">ns</InputAdornment>
}}/>
<br/><br/>
</Grid>
<Grid item xs={1}/>
<Grid item xs={1}/>
<Grid item xs={10}>
<Switch onChange={this.rawDataToggle} checked={this.state.s.collectRawData}
disabled={this.state.connection_error}/>
Collect raw data <br/><br/>
@@ -210,7 +253,9 @@ class DetectorSettings extends Component<MyProps, MyState> {
<Button color="secondary" onClick={this.downloadButton} variant="contained" disableElevation>
Reload</Button>&nbsp;&nbsp;
<Button color="secondary" onClick={this.uploadButton} variant="contained" disableElevation
disabled={this.state.count_time_error || this.state.frame_time_error}>Upload</Button>
disabled={this.state.count_time_error
|| this.state.frame_time_error
|| this.state.storage_cell_delay_error}>Upload</Button>
<br/><br/>
<Button color="secondary" onClick={this.deactivate} variant="contained" disableElevation>
Deactivate to turn off</Button>

View File

@@ -128,6 +128,7 @@ message DetectorSettings {
optional int64 pedestal_g2_frames = 8;
bool conversion_on_cpu = 9;
optional int64 storage_cell_delay_ns = 10;
}
message DetectorModuleGeometry {
@@ -164,7 +165,7 @@ message InternalSettings {
bool internal_fpga_packet_generator = 9;
int64 storage_cells = 10;
int64 storage_cell_start = 11;
int64 storage_cell_delay_ns = 39;
int64 pedestal_g0_frames = 12;
int64 pedestal_g1_frames = 13;
int64 pedestal_g2_frames = 14;
@@ -196,6 +197,7 @@ message InternalSettings {
bool roi_apply = 37;
bool debug_pixel_mask = 38;
}
@@ -345,7 +347,7 @@ message DetectorInput {
int64 num_triggers = 4;
int64 storage_cell_number = 5;
int64 storage_cell_start = 6;
double storage_cell_delay = 7;
int64 storage_cell_delay_ns = 7;
int64 period_us = 9;
int64 count_time_us = 10;
}

File diff suppressed because one or more lines are too long

View File

@@ -39,6 +39,7 @@ TEST_CASE("CBORSerialize_Start", "[CBOR]") {
.space_group_number = 154,
.max_spot_count = 250,
.storage_cell_number = 16,
.storage_cell_delay_ns = 15345,
.pixel_mask_enabled = true,
.arm_date = "abc",
.sample_name = "lyso",
@@ -95,6 +96,7 @@ TEST_CASE("CBORSerialize_Start", "[CBOR]") {
CHECK(output_message.space_group_number == message.space_group_number);
CHECK(output_message.arm_date == message.arm_date);
CHECK(output_message.storage_cell_number == message.storage_cell_number);
CHECK(output_message.storage_cell_delay_ns == message.storage_cell_delay_ns);
CHECK(output_message.pixel_signed == message.pixel_signed);
CHECK(output_message.sample_name == message.sample_name);
CHECK(output_message.file_prefix == message.file_prefix);

View File

@@ -709,7 +709,7 @@ TEST_CASE("DiffractionExperiment_DetectorInput_PedestalG2","[DiffractionExperime
TEST_CASE("DiffractionExperiment_DetectorInput_StorageCell","[DiffractionExperiment]") {
DiffractionExperiment x(DetectorGeometry(8, 2, 8, 36));
x.FrameTime(1200us).Summation(1).NumTriggers(4560).StorageCells(8);
x.FrameTime(1200us).Summation(1).NumTriggers(4560).StorageCells(8).StorageCellDelay(7000ns);
JFJochProtoBuf::DetectorInput ret = x;
REQUIRE(ret.modules_num() == 8);
REQUIRE(ret.period_us() == 8 * (x.GetFrameTime().count() + 10));
@@ -717,7 +717,7 @@ TEST_CASE("DiffractionExperiment_DetectorInput_StorageCell","[DiffractionExperim
REQUIRE(ret.num_triggers() == 4560 + 1);
REQUIRE(ret.num_frames() == 1);
REQUIRE(ret.storage_cell_number() == 8);
REQUIRE(ret.storage_cell_delay() == 7.5);
REQUIRE(ret.storage_cell_delay_ns() == 7000);
REQUIRE(ret.storage_cell_start() == x.GetStorageCellStart());
}
@@ -808,7 +808,7 @@ TEST_CASE("DiffractionExperiment_LoadDatasetSettings_Invalid", "[DiffractionExpe
TEST_CASE("DiffractionExperiment_LoadDetectorSettings", "[DiffractionExperiment]") {
DiffractionExperiment x;
x.PedestalG0Frames(456).PedestalG1Frames(1234).PedestalG2Frames(123);
x.PedestalG0Frames(456).PedestalG1Frames(1234).PedestalG2Frames(123).StorageCellDelay(2500ns);
JFJochProtoBuf::DetectorSettings settings;
settings.set_frame_time_us(600);
@@ -829,6 +829,22 @@ TEST_CASE("DiffractionExperiment_LoadDetectorSettings", "[DiffractionExperiment]
REQUIRE(x.GetPedestalG0Frames() == 5000);
REQUIRE(x.GetPedestalG1Frames() == 100);
REQUIRE(x.GetPedestalG2Frames() == 150);
REQUIRE(x.GetStorageCellDelay().count() == 2500);
}
TEST_CASE("DiffractionExperiment_LoadDetectorSettings_StorageCellDelay", "[DiffractionExperiment]") {
DiffractionExperiment x;
x.PedestalG0Frames(456).PedestalG1Frames(1234).PedestalG2Frames(123).StorageCellDelay(5000ns);
JFJochProtoBuf::DetectorSettings settings;
settings.set_frame_time_us(600);
settings.set_count_time_us(400);
settings.set_storage_cell_count(8);
settings.set_use_internal_packet_generator(true);
settings.set_collect_raw_data(true);
settings.set_storage_cell_delay_ns(7000);
REQUIRE_NOTHROW(x.LoadDetectorSettings(settings));
REQUIRE(x.GetStorageCellDelay().count() == 7000);
}
TEST_CASE("DiffractionExperiment_LoadDetectorSettings_invalid", "[DiffractionExperiment]") {

View File

@@ -93,7 +93,8 @@ void HDF5Metadata::Detector(HDF5File *hdf5_file, const StartMessage &start, cons
SaveScalar(det_specific, "software_git_commit", jfjoch_git_sha1());
SaveScalar(det_specific, "software_git_date", jfjoch_git_date());
SaveScalar(det_specific, "storage_cell_number", static_cast<uint32_t>(start.storage_cell_number));
if (start.storage_cell_number > 1)
SaveScalar(det_specific, "storage_cell_delay", static_cast<uint32_t>(start.storage_cell_delay_ns))->Units("ns");
SaveScalar(det_specific, "data_collection_efficiency", end.efficiency);
SaveScalar(det_specific, "max_receiver_delay", end.max_receiver_delay);
}