Merge branch 'developer' into rxacqIndices

This commit is contained in:
Dhanya Thattil 2022-03-17 11:30:01 +01:00 committed by GitHub
commit 95f9da9d70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 870 additions and 706 deletions

View File

@ -51,6 +51,9 @@ This document describes the differences between v7.0.0 and v6.x.x
- progress looks at activated or enabled ports, so progress does not stagnate
- (eiger) disable datastreaming also for virtual servers only for 10g
- missing packets also takes care of disabled ports
- added geometry to metadata
- 10g eiger nextframenumber get fixed.
- stop, able to set nextframenumber to a consistent (max + 1) for all modules if different (eiger/ctb/jungfrau/moench)
2. Resolved Issues

View File

@ -6,57 +6,57 @@ sls::Detector class. The tool needs the libclang bindings
to be installed.
When the Detector API is updated this file should be run
manually
manually.
"""
from clang import cindex
import subprocess
import argparse
import sys
import time
from pathlib import Path
from parse import system_include_paths, clang_format_version
required_version = 12
RED = '\033[91m'
REDC = '\033[91m'
GREENC = '\033[92m'
ENDC = '\033[0m'
if (ver := clang_format_version()) != required_version:
print(f'{RED}Clang format version {required_version} required, detected: {ver}. Bye!{ENDC}')
sys.exit(1)
def red(msg):
return f'{REDC}{msg}{ENDC}'
def green(msg):
return f'{GREENC}{msg}{ENDC}'
def check_clang_format_version(required_version):
if (ver := clang_format_version()) != required_version:
msg = red(f'Clang format version {required_version} required, detected: {ver}. Bye!')
print(msg)
sys.exit(1)
else:
msg = green(f'Found clang-format version {ver}')
print(msg)
def check_for_compile_commands_json(path):
# print(f"Looking for compile data base in: {path}")
compile_data_base_file = path/'compile_commands.json'
if not compile_data_base_file.exists():
msg = red(f"No compile_commands.json file found in {path}. Bye!")
print(msg)
sys.exit(1)
else:
msg = green(f'Found: {compile_data_base_file}')
print(msg)
default_build_path = "/home/l_frojdh/sls/build/"
fpath = "../../slsDetectorSoftware/src/Detector.cpp"
parser = argparse.ArgumentParser()
parser.add_argument(
"-p",
"--build_path",
help="Path to the build database",
type=str,
default=default_build_path,
)
cargs = parser.parse_args()
db = cindex.CompilationDatabase.fromDirectory(cargs.build_path)
index = cindex.Index.create()
args = db.getCompileCommands(fpath)
args = list(iter(args).__next__().arguments)[0:-1]
args = args + "-x c++ --std=c++11".split()
syspath = system_include_paths("clang++")
incargs = ["-I" + inc for inc in syspath]
args = args + incargs
tu = index.parse(fpath, args=args)
m = []
ag = []
lines = []
ag2 = []
cn = []
def get_arguments(node):
@ -119,25 +119,67 @@ def visit(node):
lines.append(
f'.def("{child.spelling}",{fs} &Detector::{child.spelling}{args})'
)
print(f'&Detector::{child.spelling}{args})')
if cargs.verbose:
print(f'&Detector::{child.spelling}{args})')
cn.append(child)
for child in node.get_children():
visit(child)
visit(tu.cursor)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-p",
"--build_path",
help="Path to the build database",
type=Path,
default=default_build_path,
)
parser.add_argument(
"-v",
"--verbose",
help="more output",
action='store_true',
)
cargs = parser.parse_args()
check_clang_format_version(12)
check_for_compile_commands_json(cargs.build_path)
with open("../src/detector_in.cpp") as f:
data = f.read()
s = "".join(lines)
s += ";"
text = data.replace("[[FUNCTIONS]]", s)
warning = "/* WARINING This file is auto generated any edits might be overwritten without warning */\n\n"
with open("../src/detector.cpp", "w") as f:
f.write(warning)
f.write(text)
print("Parsing functions in Detector.h - ", end = "", flush = True)
t0 = time.perf_counter()
#parse functions
db = cindex.CompilationDatabase.fromDirectory(cargs.build_path)
index = cindex.Index.create()
args = db.getCompileCommands(fpath)
args = list(iter(args).__next__().arguments)[0:-1]
args = args + "-x c++ --std=c++11".split()
syspath = system_include_paths("clang++")
incargs = ["-I" + inc for inc in syspath]
args = args + incargs
tu = index.parse(fpath, args=args)
visit(tu.cursor)
print(green('OK'))
print(f'Parsing took {time.perf_counter()-t0:.3f}s')
# run clang format on the output
subprocess.run(["clang-format", "../src/detector.cpp", "-i"])
print("Read detector_in.cpp - ", end = "")
with open("../src/detector_in.cpp") as f:
data = f.read()
s = "".join(lines)
s += ";"
text = data.replace("[[FUNCTIONS]]", s)
warning = "/* WARINING This file is auto generated any edits might be overwritten without warning */\n\n"
print(green("OK"))
print("Writing to detector.cpp - ", end = "")
with open("../src/detector.cpp", "w") as f:
f.write(warning)
f.write(text)
print(green('OK'))
# run clang format on the output
print('Running clang format on generated source -', end = "")
subprocess.run(["clang-format", "../src/detector.cpp", "-i"])
print(green(" OK"))
print("Changes since last commit:")
subprocess.run(['git', 'diff', '../src/detector.cpp'])

View File

@ -1259,20 +1259,20 @@ int Beb_GetNextFrameNumber(uint64_t *retval, int tengigaEnable) {
else {
uint64_t left10g =
Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_1G_LEFT_MSB_OFST);
temp = Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_1G_LEFT_LSB_OFST);
Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_10G_LEFT_MSB_OFST);
temp = Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_10G_LEFT_LSB_OFST);
left10g = ((left10g << 32) | temp) >> 16;
++left10g; // increment for firmware
uint64_t right10g =
Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_1G_LEFT_MSB_OFST);
temp = Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_1G_LEFT_LSB_OFST);
Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_10G_LEFT_MSB_OFST);
temp = Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_10G_LEFT_LSB_OFST);
right10g = ((right10g << 32) | temp) >> 16;
Beb_close(fd, csp0base);
++right10g; // increment for firmware
if (left10g != right10g) {
LOG(logERROR, ("Retrieved inconsistent frame numbers from `0g left "
LOG(logERROR, ("Retrieved inconsistent frame numbers from 10g left "
"%llu and right %llu\n",
(long long int)left10g, (long long int)right10g));
*retval = (left10g > right10g)

View File

@ -800,6 +800,25 @@ void Detector::startDetectorReadout() {
void Detector::stopDetector(Positions pos) {
pimpl->Parallel(&Module::stopAcquisition, pos);
// validate consistent frame numbers
switch (getDetectorType().squash()) {
case defs::EIGER:
case defs::JUNGFRAU:
case defs::MOENCH:
case defs::CHIPTESTBOARD: {
auto res = getNextFrameNumber(pos);
if (!res.equal()) {
uint64_t maxVal = 0;
for (auto it : res) {
maxVal = std::max(maxVal, it);
}
setNextFrameNumber(maxVal + 1);
}
} break;
default:
break;
}
}
Result<defs::runStatus> Detector::getDetectorStatus(Positions pos) const {
@ -1593,7 +1612,6 @@ std::vector<defs::gainMode> Detector::getGainModeList() const {
return std::vector<defs::gainMode>{
defs::DYNAMIC, defs::FORCE_SWITCH_G1, defs::FORCE_SWITCH_G2,
defs::FIX_G1, defs::FIX_G2, defs::FIX_G0};
break;
default:
throw RuntimeError("Gain mode is not implemented for this detector.");
}

View File

@ -2166,6 +2166,41 @@ TEST_CASE("nextframenumber", "[.cmd]") {
proxy.Call("nextframenumber", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "nextframenumber 1\n");
}
auto prev_timing =
det.getTimingMode().tsquash("inconsistent timing mode in test");
auto prev_frames =
det.getNumberOfFrames().tsquash("inconsistent #frames in test");
auto prev_exptime =
det.getExptime().tsquash("inconsistent exptime in test");
auto prev_period =
det.getPeriod().tsquash("inconsistent period in test");
det.setTimingMode(defs::AUTO_TIMING);
det.setNumberOfFrames(1);
det.setExptime(std::chrono::microseconds(200));
det.setPeriod(std::chrono::milliseconds(1));
det.startDetector();
std::this_thread::sleep_for(std::chrono::seconds(2));
auto currentfnum =
det.getNextFrameNumber().tsquash("inconsistent frame nr in test");
REQUIRE(currentfnum == 2);
if (det_type == defs::EIGER) {
auto prev_tengiga =
det.getTenGiga().tsquash("inconsistent ten giga enable");
det.setTenGiga(true);
det.setNextFrameNumber(1);
det.startDetector();
std::this_thread::sleep_for(std::chrono::seconds(2));
auto currentfnum = det.getNextFrameNumber().tsquash(
"inconsistent frame nr in test");
REQUIRE(currentfnum == 2);
det.setTenGiga(prev_tengiga);
}
det.setTimingMode(prev_timing);
det.setNumberOfFrames(prev_frames);
det.setExptime(prev_exptime);
det.setPeriod(prev_period);
for (int i = 0; i != det.size(); ++i) {
det.setNextFrameNumber(prev_sfnum[i], {i});
}

View File

@ -13,6 +13,7 @@ set(SOURCES
src/DataStreamer.cpp
src/Fifo.cpp
src/Arping.cpp
src/MasterAttributes.cpp
)
set(PUBLICHEADERS

View File

@ -784,6 +784,12 @@ void Implementation::SetupWriter() {
}
masterAttributes->detType = detType;
masterAttributes->timingMode = timingMode;
xy nm{numModules.x, numModules.y};
if (quadEnable) {
nm.x = 1;
nm.y = 2;
}
masterAttributes->geometry = xy(nm.x, nm.y);
masterAttributes->imageSize = generalData->imageSize;
masterAttributes->nPixels =
xy(generalData->nPixelsX, generalData->nPixelsY);

View File

@ -0,0 +1,676 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "MasterAttributes.h"
void MasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
LOG(logERROR) << "WriteMasterBinaryAttributes should have been called "
"by a child class";
}
std::string MasterAttributes::GetBinaryMasterAttributes() {
time_t t = time(nullptr);
std::ostringstream oss;
oss << "Version : " << std::setprecision(2)
<< BINARY_WRITER_VERSION << '\n'
<< "TimeStamp : " << ctime(&t) << '\n'
<< "Detector Type : " << sls::ToString(detType) << '\n'
<< "Timing Mode : " << sls::ToString(timingMode) << '\n'
<< "Geometry : " << sls::ToString(geometry) << '\n'
<< "Image Size : " << imageSize << " bytes" << '\n'
<< "Pixels : " << sls::ToString(nPixels) << '\n'
<< "Max Frames Per File : " << maxFramesPerFile << '\n'
<< "Frame Discard Policy : " << sls::ToString(frameDiscardMode)
<< '\n'
<< "Frame Padding : " << framePadding << '\n'
<< "Scan Parameters : " << sls::ToString(scanParams) << '\n'
<< "Total Frames : " << totalFrames << '\n';
return oss.str();
};
void MasterAttributes::WriteBinaryAttributes(FILE *fd, std::string message) {
if (fwrite((void *)message.c_str(), 1, message.length(), fd) !=
message.length()) {
throw sls::RuntimeError(
"Master binary file incorrect number of bytes written to file");
}
};
void MasterAttributes::WriteFinalBinaryAttributes(FILE *fd) {
// adding few common parameters to the end
std::ostringstream oss;
if (!additionalJsonHeader.empty()) {
oss << "Additional Json Header : "
<< sls::ToString(additionalJsonHeader) << '\n';
}
oss << "Frames in File : " << framesInFile << '\n';
// adding sls_receiver header format
oss << '\n'
<< "#Frame Header" << '\n'
<< "Frame Number : 8 bytes" << '\n'
<< "SubFrame Number/ExpLength : 4 bytes" << '\n'
<< "Packet Number : 4 bytes" << '\n'
<< "Bunch ID : 8 bytes" << '\n'
<< "Timestamp : 8 bytes" << '\n'
<< "Module Id : 2 bytes" << '\n'
<< "Row : 2 bytes" << '\n'
<< "Column : 2 bytes" << '\n'
<< "Reserved : 2 bytes" << '\n'
<< "Debug : 4 bytes" << '\n'
<< "Round Robin Number : 2 bytes" << '\n'
<< "Detector Type : 1 byte" << '\n'
<< "Header Version : 1 byte" << '\n'
<< "Packets Caught Mask : 64 bytes" << '\n';
std::string message = oss.str();
// writing to file
if (fwrite((void *)message.c_str(), 1, message.length(), fd) !=
message.length()) {
throw sls::RuntimeError(
"Master binary file incorrect number of bytes written to file");
}
};
#ifdef HDF5C
void MasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
LOG(logERROR) << "WriteMasterHdf5Attributes should have been called "
"by a child class";
};
void MasterAttributes::WriteHDF5Attributes(H5File *fd, Group *group) {
char c[1024];
memset(c, 0, sizeof(c));
// clang-format off
// version
{
double version = BINARY_WRITER_VERSION;
DataSpace dataspace = DataSpace(H5S_SCALAR);
Attribute attribute = fd->createAttribute(
"Version", PredType::NATIVE_DOUBLE, dataspace);
attribute.write(PredType::NATIVE_DOUBLE, &version);
}
// timestamp
{
time_t t = time(nullptr);
StrType strdatatype(PredType::C_S1, 256);
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Timestamp", strdatatype, dataspace);
sls::strcpy_safe(c, std::string(ctime(&t)));
dataset.write(c, strdatatype);
}
// detector type
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Detector Type", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(detType));
dataset.write(c, strdatatype);
}
// timing mode
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Timing Mode", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(timingMode));
dataset.write(c, strdatatype);
}
//TODO: make this into an array?
// geometry x
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Geometry in x axis", PredType::NATIVE_INT, dataspace);
dataset.write(&geometry.x, PredType::NATIVE_INT);
}
// geometry y
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Geometry in y axis", PredType::NATIVE_INT, dataspace);
dataset.write(&geometry.y, PredType::NATIVE_INT);
}
// Image Size
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Image Size", PredType::NATIVE_INT, dataspace);
dataset.write(&imageSize, PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
sls::strcpy_safe(c, "bytes");
attribute.write(strdatatype, c);
}
//TODO: make this into an array?
// npixels x
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of pixels in x axis", PredType::NATIVE_INT, dataspace);
dataset.write(&nPixels.x, PredType::NATIVE_INT);
}
// npixels y
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of pixels in y axis", PredType::NATIVE_INT, dataspace);
dataset.write(&nPixels.y, PredType::NATIVE_INT);
}
// Maximum frames per file
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Maximum frames per file", PredType::NATIVE_INT, dataspace);
dataset.write(&maxFramesPerFile, PredType::NATIVE_INT);
}
// Frame Discard Policy
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Frame Discard Policy", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(frameDiscardMode));
dataset.write(c, strdatatype);
}
// Frame Padding
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Frame Padding", PredType::NATIVE_INT, dataspace);
dataset.write(&framePadding, PredType::NATIVE_INT);
}
// Scan Parameters
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Scan Parameters", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(scanParams));
dataset.write(c, strdatatype);
}
// Total Frames
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Total Frames", PredType::STD_U64LE, dataspace);
dataset.write(&totalFrames, PredType::STD_U64LE);
}
};
void MasterAttributes::WriteFinalHDF5Attributes(H5File *fd, Group *group) {
char c[1024];
memset(c, 0, sizeof(c));
// Total Frames in file
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Frames in File", PredType::STD_U64LE, dataspace);
dataset.write(&framesInFile, PredType::STD_U64LE);
}
// additional json header
if (!additionalJsonHeader.empty()) {
std::string json = sls::ToString(additionalJsonHeader);
StrType strdatatype(PredType::C_S1, json.length());
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Additional JSON Header", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(additionalJsonHeader));
dataset.write(c, strdatatype);
}
};
void MasterAttributes::WriteHDF5Exptime(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time", strdatatype, dataspace);
char c[1024];
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(exptime));
dataset.write(c, strdatatype);
};
void MasterAttributes::WriteHDF5Period(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Acquisition Period", strdatatype, dataspace);
char c[1024];
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(period));
dataset.write(c, strdatatype);
};
void MasterAttributes::WriteHDF5DynamicRange(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Dynamic Range", PredType::NATIVE_INT, dataspace);
dataset.write(&dynamicRange, PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
char c[1024] = "bits";
attribute.write( strdatatype, c);
};
void MasterAttributes::WriteHDF5TenGiga(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Ten Giga Enable", PredType::NATIVE_INT, dataspace);
dataset.write(&tenGiga, PredType::NATIVE_INT);
};
#endif
void GotthardMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void GotthardMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
// Roi xmin
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"roi xmin", PredType::NATIVE_INT, dataspace);
dataset.write(&roi.xmin, PredType::NATIVE_INT);
}
// Roi xmax
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"roi xmax", PredType::NATIVE_INT, dataspace);
dataset.write(&roi.xmax, PredType::NATIVE_INT);
}
};
#endif
void JungfrauMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Number of UDP Interfaces : " << numUDPInterfaces << '\n'
<< "Number of rows : " << readNRows << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void JungfrauMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of UDP Interfaces", PredType::NATIVE_INT, dataspace);
dataset.write(&numUDPInterfaces, PredType::NATIVE_INT);
}
// readNRows
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of rows", PredType::NATIVE_INT, dataspace);
dataset.write(&readNRows, PredType::NATIVE_INT);
}
};
#endif
void EigerMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Dynamic Range : " << dynamicRange << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Threshold Energy : " << thresholdEnergyeV << '\n'
<< "SubExptime : " << sls::ToString(subExptime)
<< '\n'
<< "SubPeriod : " << sls::ToString(subPeriod)
<< '\n'
<< "Quad : " << quad << '\n'
<< "Number of rows : " << readNRows << '\n'
<< "Rate Corrections : " << sls::ToString(ratecorr)
<< '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void EigerMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5DynamicRange(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
char c[1024];
memset(c, 0, sizeof(c));
// threshold
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Threshold Energy", PredType::NATIVE_INT, dataspace);
dataset.write(&thresholdEnergyeV, PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
sls::strcpy_safe(c, "eV");
attribute.write(strdatatype, c);
}
// SubExptime
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset = group->createDataSet("Sub Exposure Time",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(subExptime));
dataset.write(c, strdatatype);
}
// SubPeriod
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Sub Period", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(subPeriod));
dataset.write(c, strdatatype);
}
// Quad
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Quad", PredType::NATIVE_INT, dataspace);
dataset.write(&quad, PredType::NATIVE_INT);
}
// readNRows
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of rows", PredType::NATIVE_INT, dataspace);
dataset.write(&readNRows, PredType::NATIVE_INT);
}
// Rate corrections
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 1024);
DataSet dataset = group->createDataSet("Rate Corrections",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(ratecorr));
dataset.write(c, strdatatype);
}
};
#endif
void Mythen3MasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Dynamic Range : " << dynamicRange << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Counter Mask : " << sls::ToStringHex(counterMask)
<< '\n'
<< "Exptime1 : " << sls::ToString(exptime1)
<< '\n'
<< "Exptime2 : " << sls::ToString(exptime2)
<< '\n'
<< "Exptime3 : " << sls::ToString(exptime3)
<< '\n'
<< "GateDelay1 : " << sls::ToString(gateDelay1)
<< '\n'
<< "GateDelay2 : " << sls::ToString(gateDelay2)
<< '\n'
<< "GateDelay3 : " << sls::ToString(gateDelay3)
<< '\n'
<< "Gates : " << gates << '\n'
<< "Threshold Energies : "
<< sls::ToString(thresholdAllEnergyeV) << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void Mythen3MasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5DynamicRange(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
char c[1024];
memset(c, 0, sizeof(c));
// Counter Mask
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Counter Mask", PredType::STD_U32LE, dataspace);
dataset.write(&counterMask, PredType::STD_U32LE);
}
// Exptime1
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time1", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptime1));
dataset.write(c, strdatatype);
}
// Exptime2
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time2", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptime2));
dataset.write(c, strdatatype);
}
// Exptime3
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time3", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptime3));
dataset.write(c, strdatatype);
}
// GateDelay1
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay1", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelay1));
dataset.write(c, strdatatype);
}
// GateDelay2
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay2", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelay2));
dataset.write(c, strdatatype);
}
// GateDelay3
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay3", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelay3));
dataset.write(c, strdatatype);
}
// Gates
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Gates", PredType::STD_U32LE, dataspace);
dataset.write(&gates, PredType::STD_U32LE);
}
// Threshold Energies
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 1024);
DataSet dataset = group->createDataSet("Threshold Energies",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(thresholdAllEnergyeV));
dataset.write(c, strdatatype);
}
};
#endif
void Gotthard2MasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Burst Mode : " << sls::ToString(burstMode)
<< '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void Gotthard2MasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
// burst mode
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Burst Mode", strdatatype, dataspace);
char c[1024];
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(burstMode));
dataset.write(c, strdatatype);
}
};
#endif
void MoenchMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "ADC Mask : " << sls::ToStringHex(adcmask)
<< '\n'
<< "Analog Samples : " << analogSamples << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void MoenchMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
// ADC Mask
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"ADC Mask", PredType::NATIVE_INT, dataspace);
dataset.write(&adcmask, PredType::NATIVE_INT);
}
// Analog Samples
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Analog Samples", PredType::NATIVE_INT, dataspace);
dataset.write(&analogSamples, PredType::NATIVE_INT);
}
};
#endif
void CtbMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "ADC Mask : " << sls::ToStringHex(adcmask)
<< '\n'
<< "Analog Flag : " << analog << '\n'
<< "Analog Samples : " << analogSamples << '\n'
<< "Digital Flag : " << digital << '\n'
<< "Digital Samples : " << digitalSamples << '\n'
<< "Dbit Offset : " << dbitoffset << '\n'
<< "Dbit Bitset : " << dbitlist << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void CtbMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
// ADC Mask
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"ADC mMsk", PredType::NATIVE_INT, dataspace);
dataset.write(&adcmask, PredType::NATIVE_INT);
}
// Analog Flag
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Analog Flag", PredType::NATIVE_INT, dataspace);
dataset.write(&analog, PredType::NATIVE_INT);
}
// Analog Samples
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Analog Samples", PredType::NATIVE_INT, dataspace);
dataset.write(&analogSamples, PredType::NATIVE_INT);
}
// Digital Flag
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Digital Flag", PredType::NATIVE_INT, dataspace);
dataset.write(&digital, PredType::NATIVE_INT);
}
// Digital Samples
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Digital Samples", PredType::NATIVE_INT, dataspace);
dataset.write(&digitalSamples, PredType::NATIVE_INT);
}
// Dbit Offset
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Dbit Offset", PredType::NATIVE_INT, dataspace);
dataset.write(&dbitoffset, PredType::NATIVE_INT);
}
// Dbit List
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Dbit Bitset List", PredType::STD_U64LE, dataspace);
dataset.write(&dbitlist, PredType::STD_U64LE);
}
};
#endif

View File

@ -17,10 +17,12 @@ using namespace H5;
#include <chrono>
using ns = std::chrono::nanoseconds;
struct MasterAttributes {
class MasterAttributes {
public:
// (before acquisition)
slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC};
slsDetectorDefs::timingMode timingMode{slsDetectorDefs::AUTO_TIMING};
slsDetectorDefs::xy geometry{};
uint32_t imageSize{0};
slsDetectorDefs::xy nPixels{};
uint32_t maxFramesPerFile{0};
@ -63,701 +65,82 @@ struct MasterAttributes {
// Final Attributes (after acquisition)
uint64_t framesInFile{0};
MasterAttributes(){};
virtual ~MasterAttributes(){};
virtual void WriteMasterBinaryAttributes(FILE *fd) {
LOG(logERROR) << "WriteMasterBinaryAttributes should have been called "
"by a child class";
}
std::string GetBinaryMasterAttributes() {
time_t t = time(nullptr);
std::ostringstream oss;
oss << "Version : " << std::setprecision(2)
<< BINARY_WRITER_VERSION << '\n'
<< "TimeStamp : " << ctime(&t) << '\n'
<< "Detector Type : " << sls::ToString(detType) << '\n'
<< "Timing Mode : " << sls::ToString(timingMode)
<< '\n'
<< "Image Size : " << imageSize << " bytes" << '\n'
<< "Pixels : " << sls::ToString(nPixels) << '\n'
<< "Max Frames Per File : " << maxFramesPerFile << '\n'
<< "Frame Discard Policy : "
<< sls::ToString(frameDiscardMode) << '\n'
<< "Frame Padding : " << framePadding << '\n'
<< "Scan Parameters : " << sls::ToString(scanParams)
<< '\n'
<< "Total Frames : " << totalFrames << '\n';
return oss.str();
};
void WriteBinaryAttributes(FILE *fd, std::string message) {
if (fwrite((void *)message.c_str(), 1, message.length(), fd) !=
message.length()) {
throw sls::RuntimeError(
"Master binary file incorrect number of bytes written to file");
}
};
void WriteFinalBinaryAttributes(FILE *fd) {
// adding few common parameters to the end
std::ostringstream oss;
if (!additionalJsonHeader.empty()) {
oss << "Additional Json Header : "
<< sls::ToString(additionalJsonHeader) << '\n';
}
oss << "Frames in File : " << framesInFile << '\n';
// adding sls_receiver header format
oss << '\n'
<< "#Frame Header" << '\n'
<< "Frame Number : 8 bytes" << '\n'
<< "SubFrame Number/ExpLength : 4 bytes" << '\n'
<< "Packet Number : 4 bytes" << '\n'
<< "Bunch ID : 8 bytes" << '\n'
<< "Timestamp : 8 bytes" << '\n'
<< "Module Id : 2 bytes" << '\n'
<< "Row : 2 bytes" << '\n'
<< "Column : 2 bytes" << '\n'
<< "Reserved : 2 bytes" << '\n'
<< "Debug : 4 bytes" << '\n'
<< "Round Robin Number : 2 bytes" << '\n'
<< "Detector Type : 1 byte" << '\n'
<< "Header Version : 1 byte" << '\n'
<< "Packets Caught Mask : 64 bytes" << '\n';
std::string message = oss.str();
// writing to file
if (fwrite((void *)message.c_str(), 1, message.length(), fd) !=
message.length()) {
throw sls::RuntimeError(
"Master binary file incorrect number of bytes written to file");
}
};
MasterAttributes() = default;
virtual ~MasterAttributes() = default;
virtual void WriteMasterBinaryAttributes(FILE *fd);
std::string GetBinaryMasterAttributes();
void WriteBinaryAttributes(FILE *fd, std::string message);
void WriteFinalBinaryAttributes(FILE *fd);
#ifdef HDF5C
virtual void WriteMasterHDF5Attributes(H5File *fd, Group *group) {
LOG(logERROR) << "WriteMasterHdf5Attributes should have been called "
"by a child class";
};
void WriteHDF5Attributes(H5File *fd, Group *group) {
char c[1024];
memset(c, 0, sizeof(c));
// clang-format off
// version
{
double version = BINARY_WRITER_VERSION;
DataSpace dataspace = DataSpace(H5S_SCALAR);
Attribute attribute = fd->createAttribute(
"Version", PredType::NATIVE_DOUBLE, dataspace);
attribute.write(PredType::NATIVE_DOUBLE, &version);
}
// timestamp
{
time_t t = time(nullptr);
StrType strdatatype(PredType::C_S1, 256);
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Timestamp", strdatatype, dataspace);
sls::strcpy_safe(c, std::string(ctime(&t)));
dataset.write(c, strdatatype);
}
// detector type
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Detector Type", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(detType));
dataset.write(c, strdatatype);
}
// timing mode
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Timing Mode", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(timingMode));
dataset.write(c, strdatatype);
}
// Image Size
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Image Size", PredType::NATIVE_INT, dataspace);
dataset.write(&imageSize, PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
sls::strcpy_safe(c, "bytes");
attribute.write(strdatatype, c);
}
//TODO: make this into an array?
// x
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of pixels in x axis", PredType::NATIVE_INT, dataspace);
dataset.write(&nPixels.x, PredType::NATIVE_INT);
}
// y
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of pixels in y axis", PredType::NATIVE_INT, dataspace);
dataset.write(&nPixels.y, PredType::NATIVE_INT);
}
// Maximum frames per file
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Maximum frames per file", PredType::NATIVE_INT, dataspace);
dataset.write(&maxFramesPerFile, PredType::NATIVE_INT);
}
// Frame Discard Policy
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Frame Discard Policy", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(frameDiscardMode));
dataset.write(c, strdatatype);
}
// Frame Padding
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Frame Padding", PredType::NATIVE_INT, dataspace);
dataset.write(&framePadding, PredType::NATIVE_INT);
}
// Scan Parameters
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Scan Parameters", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(scanParams));
dataset.write(c, strdatatype);
}
// Total Frames
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Total Frames", PredType::STD_U64LE, dataspace);
dataset.write(&totalFrames, PredType::STD_U64LE);
}
};
void WriteFinalHDF5Attributes(H5File *fd, Group *group) {
char c[1024];
memset(c, 0, sizeof(c));
// Total Frames in file
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Frames in File", PredType::STD_U64LE, dataspace);
dataset.write(&framesInFile, PredType::STD_U64LE);
}
// additional json header
if (!additionalJsonHeader.empty()) {
std::string json = sls::ToString(additionalJsonHeader);
StrType strdatatype(PredType::C_S1, json.length());
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Additional JSON Header", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(additionalJsonHeader));
dataset.write(c, strdatatype);
}
};
void WriteHDF5Exptime(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time", strdatatype, dataspace);
char c[1024];
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(exptime));
dataset.write(c, strdatatype);
};
void WriteHDF5Period(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Acquisition Period", strdatatype, dataspace);
char c[1024];
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(period));
dataset.write(c, strdatatype);
};
void WriteHDF5DynamicRange(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Dynamic Range", PredType::NATIVE_INT, dataspace);
dataset.write(&dynamicRange, PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
char c[1024] = "bits";
attribute.write( strdatatype, c);
};
void WriteHDF5TenGiga(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Ten Giga Enable", PredType::NATIVE_INT, dataspace);
dataset.write(&tenGiga, PredType::NATIVE_INT);
};
virtual void WriteMasterHDF5Attributes(H5File *fd, Group *group);
void WriteHDF5Attributes(H5File *fd, Group *group);
void WriteFinalHDF5Attributes(H5File *fd, Group *group);
void WriteHDF5Exptime(H5File *fd, Group *group);
void WriteHDF5Period(H5File *fd, Group *group);
void WriteHDF5DynamicRange(H5File *fd, Group *group);
void WriteHDF5TenGiga(H5File *fd, Group *group);
#endif
};
// clang-format on
class GotthardMasterAttributes : public MasterAttributes {
public:
GotthardMasterAttributes(){};
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
GotthardMasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
#ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
// Roi xmin
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"roi xmin", PredType::NATIVE_INT, dataspace);
dataset.write(&roi.xmin, PredType::NATIVE_INT);
}
// Roi xmax
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"roi xmax", PredType::NATIVE_INT, dataspace);
dataset.write(&roi.xmax, PredType::NATIVE_INT);
}
};
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
#endif
};
class JungfrauMasterAttributes : public MasterAttributes {
public:
JungfrauMasterAttributes(){};
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Number of UDP Interfaces : " << numUDPInterfaces << '\n'
<< "Number of rows : " << readNRows << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
JungfrauMasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
#ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of UDP Interfaces", PredType::NATIVE_INT, dataspace);
dataset.write(&numUDPInterfaces, PredType::NATIVE_INT);
}
// readNRows
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of rows", PredType::NATIVE_INT, dataspace);
dataset.write(&readNRows, PredType::NATIVE_INT);
}
};
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
#endif
};
class EigerMasterAttributes : public MasterAttributes {
public:
EigerMasterAttributes(){};
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Dynamic Range : " << dynamicRange << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Threshold Energy : " << thresholdEnergyeV << '\n'
<< "SubExptime : " << sls::ToString(subExptime)
<< '\n'
<< "SubPeriod : " << sls::ToString(subPeriod)
<< '\n'
<< "Quad : " << quad << '\n'
<< "Number of rows : " << readNRows << '\n'
<< "Rate Corrections : " << sls::ToString(ratecorr)
<< '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
EigerMasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
#ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5DynamicRange(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
char c[1024];
memset(c, 0, sizeof(c));
// threshold
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Threshold Energy", PredType::NATIVE_INT, dataspace);
dataset.write(&thresholdEnergyeV, PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
sls::strcpy_safe(c, "eV");
attribute.write(strdatatype, c);
}
// SubExptime
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset = group->createDataSet("Sub Exposure Time",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(subExptime));
dataset.write(c, strdatatype);
}
// SubPeriod
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Sub Period", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(subPeriod));
dataset.write(c, strdatatype);
}
// Quad
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Quad", PredType::NATIVE_INT, dataspace);
dataset.write(&quad, PredType::NATIVE_INT);
}
// readNRows
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of rows", PredType::NATIVE_INT, dataspace);
dataset.write(&readNRows, PredType::NATIVE_INT);
}
// Rate corrections
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 1024);
DataSet dataset = group->createDataSet("Rate Corrections",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(ratecorr));
dataset.write(c, strdatatype);
}
};
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
#endif
};
class Mythen3MasterAttributes : public MasterAttributes {
public:
Mythen3MasterAttributes(){};
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Dynamic Range : " << dynamicRange << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Counter Mask : " << sls::ToStringHex(counterMask)
<< '\n'
<< "Exptime1 : " << sls::ToString(exptime1)
<< '\n'
<< "Exptime2 : " << sls::ToString(exptime2)
<< '\n'
<< "Exptime3 : " << sls::ToString(exptime3)
<< '\n'
<< "GateDelay1 : " << sls::ToString(gateDelay1)
<< '\n'
<< "GateDelay2 : " << sls::ToString(gateDelay2)
<< '\n'
<< "GateDelay3 : " << sls::ToString(gateDelay3)
<< '\n'
<< "Gates : " << gates << '\n'
<< "Threshold Energies : "
<< sls::ToString(thresholdAllEnergyeV) << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
Mythen3MasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
#ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5DynamicRange(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
char c[1024];
memset(c, 0, sizeof(c));
// Counter Mask
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Counter Mask", PredType::STD_U32LE, dataspace);
dataset.write(&counterMask, PredType::STD_U32LE);
}
// Exptime1
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time1", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptime1));
dataset.write(c, strdatatype);
}
// Exptime2
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time2", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptime2));
dataset.write(c, strdatatype);
}
// Exptime3
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time3", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptime3));
dataset.write(c, strdatatype);
}
// GateDelay1
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay1", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelay1));
dataset.write(c, strdatatype);
}
// GateDelay2
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay2", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelay2));
dataset.write(c, strdatatype);
}
// GateDelay3
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay3", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelay3));
dataset.write(c, strdatatype);
}
// Gates
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Gates", PredType::STD_U32LE, dataspace);
dataset.write(&gates, PredType::STD_U32LE);
}
// Threshold Energies
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 1024);
DataSet dataset = group->createDataSet("Threshold Energies",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(thresholdAllEnergyeV));
dataset.write(c, strdatatype);
}
};
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
#endif
};
class Gotthard2MasterAttributes : public MasterAttributes {
public:
Gotthard2MasterAttributes(){};
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Burst Mode : " << sls::ToString(burstMode)
<< '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
Gotthard2MasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
#ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
// burst mode
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Burst Mode", strdatatype, dataspace);
char c[1024];
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(burstMode));
dataset.write(c, strdatatype);
}
};
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
#endif
};
class MoenchMasterAttributes : public MasterAttributes {
public:
MoenchMasterAttributes(){};
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "ADC Mask : " << sls::ToStringHex(adcmask)
<< '\n'
<< "Analog Samples : " << analogSamples << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
MoenchMasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
#ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
// ADC Mask
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"ADC Mask", PredType::NATIVE_INT, dataspace);
dataset.write(&adcmask, PredType::NATIVE_INT);
}
// Analog Samples
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Analog Samples", PredType::NATIVE_INT, dataspace);
dataset.write(&analogSamples, PredType::NATIVE_INT);
}
};
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
#endif
};
class CtbMasterAttributes : public MasterAttributes {
public:
CtbMasterAttributes(){};
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "ADC Mask : " << sls::ToStringHex(adcmask)
<< '\n'
<< "Analog Flag : " << analog << '\n'
<< "Analog Samples : " << analogSamples << '\n'
<< "Digital Flag : " << digital << '\n'
<< "Digital Samples : " << digitalSamples << '\n'
<< "Dbit Offset : " << dbitoffset << '\n'
<< "Dbit Bitset : " << dbitlist << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
CtbMasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
#ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
// ADC Mask
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"ADC mMsk", PredType::NATIVE_INT, dataspace);
dataset.write(&adcmask, PredType::NATIVE_INT);
}
// Analog Flag
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Analog Flag", PredType::NATIVE_INT, dataspace);
dataset.write(&analog, PredType::NATIVE_INT);
}
// Analog Samples
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Analog Samples", PredType::NATIVE_INT, dataspace);
dataset.write(&analogSamples, PredType::NATIVE_INT);
}
// Digital Flag
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Digital Flag", PredType::NATIVE_INT, dataspace);
dataset.write(&digital, PredType::NATIVE_INT);
}
// Digital Samples
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Digital Samples", PredType::NATIVE_INT, dataspace);
dataset.write(&digitalSamples, PredType::NATIVE_INT);
}
// Dbit Offset
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Dbit Offset", PredType::NATIVE_INT, dataspace);
dataset.write(&dbitoffset, PredType::NATIVE_INT);
}
// Dbit List
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Dbit Bitset List", PredType::STD_U64LE, dataspace);
dataset.write(&dbitlist, PredType::STD_U64LE);
}
};
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
#endif
};

View File

@ -17,8 +17,8 @@
// files
// versions
#define HDF5_WRITER_VERSION (6.3) // 1 decimal places
#define BINARY_WRITER_VERSION (6.3) // 1 decimal places
#define HDF5_WRITER_VERSION (6.4) // 1 decimal places
#define BINARY_WRITER_VERSION (6.4) // 1 decimal places
#define MAX_FRAMES_PER_FILE 20000
#define SHORT_MAX_FRAMES_PER_FILE 100000

View File

@ -5,11 +5,11 @@
#define APILIB 0x211125
#define APIRECEIVER 0x211124
#define APIGUI 0x211124
#define APICTB 0x220317
#define APIGOTTHARD 0x220317
#define APIGOTTHARD2 0x220317
#define APIJUNGFRAU 0x220317
#define APIMYTHEN3 0x220317
#define APIMOENCH 0x220317
#define APIEIGER 0x220317