tttrlib
A library for time-tagged time resolved data
Loading...
Searching...
No Matches
include
TTTRHeader.h
Go to the documentation of this file.
1
#ifndef TTTRLIB_READHEADER_H
2
#define TTTRLIB_READHEADER_H
3
4
#include <stdlib.h>
/* malloc, calloc, realloc, exit, free */
5
#include <cstdint>
6
#include <cstdio>
7
#include <iostream>
8
#include <map>
9
#include <cmath>
/* floor, ceil */
10
#include <string>
11
#include <string.h>
/* strcmp */
12
#include <algorithm>
13
#include <vector>
14
#include <array>
15
#include <memory>
16
#include <numeric>
17
#include <iostream>
18
#include <sstream>
// std::stringstream
19
#include <iomanip>
/* std::setfill */
20
#include <fstream>
/* ifstream */
21
22
#include <any>
23
// #include <boost/any.hpp>
24
//#include <boost/filesystem.hpp>
25
//#include <boost/locale.hpp>
26
27
#include "json.hpp"
28
29
#include "
Histogram.h
"
30
#include "
TTTRRecordReader.h
"
31
#include "
TTTRRecordTypes.h
"
32
#include "
TTTRHeaderTypes.h
"
33
34
// some important Tag Idents (TTagHead.Ident) that we will need to read the most common content of a PTU file
35
// check the output of this program and consult the tag dictionary if you need more
36
const
std::string
TTTRTagRes
=
"MeasDesc_Resolution"
;
// Resolution for the Dtime (T3 Only) - in seconds
37
const
std::string
TTTRTagGlobRes
=
"MeasDesc_GlobalResolution"
;
// Global Resolution of TimeTag(T2) /NSync (T3) - in seconds
38
const
std::string
TTTRSyncRate
=
"SyncRate"
;
// SyncRate - in Hz
39
const
std::string
TTTRNMicroTimes
=
"MeasDesc_NumberMicrotimes"
;
// The number of micro time channels
40
const
std::string
TTTRRecordType
=
"MeasDesc_RecordType"
;
// Internal record type (see tttrlib record type identifier definitions)
41
const
std::string
TTTRContainerType
=
"MeasDesc_ContainerType"
;
// Internal container type (see tttrlib record type identifier definitions)
42
const
std::string
TTTRTagTTTRRecType
=
"TTResultFormat_TTTRRecType"
;
43
const
std::string
TTTRTagBits
=
"TTResultFormat_BitsPerRecord"
;
// Bits per TTTR record
44
const
std::string
FileTagEnd
=
"Header_End"
;
// Always appended as last tag (BLOCKEND)
45
46
47
class
TTTRHeader
{
48
49
friend
class
TTTR
;
50
51
protected
:
52
53
// JSON object used to store all the header information
54
nlohmann::json
json_data
;
55
59
size_t
header_end
= 0;
60
61
public
:
62
66
int
get_tttr_record_type
(){
67
return
(
int
)
json_data
[
TTTRRecordType
];
68
}
69
74
void
set_tttr_record_type
(
int
v){
75
json_data
[
TTTRRecordType
] = v;
76
}
77
82
int
get_tttr_container_type
(){
83
return
(
int
)
json_data
[
TTTRContainerType
];
84
}
85
90
void
set_tttr_container_type
(
int
v){
91
json_data
[
TTTRContainerType
] = v;
92
}
93
102
static
nlohmann::json
get_tag
(
103
nlohmann::json
json_data
,
104
const
std::string &name,
105
int
idx = -1
106
);
107
116
static
int
find_tag
(
117
nlohmann::json &
json_data
,
118
const
std::string &name,
119
int
idx = -1
120
);
121
132
static
void
add_tag
(
133
nlohmann::json &
json_data
,
134
const
std::string &name,
135
std::any value,
136
// boost::any value,
137
unsigned
int
type =
tyAnsiString
,
138
int
idx = -1
139
);
140
145
size_t
get_bytes_per_record
(){
146
return
(
size_t
)
get_tag
(
json_data
,
TTTRTagBits
)[
"value"
] / 8;
147
}
148
149
size_t
end
()
const
{
150
return
header_end
;
151
}
152
156
size_t
size
(){
157
return
json_data
[
"tags"
].size();
158
}
159
160
nlohmann::json&
operator[]
(std::size_t idx){
161
return
json_data
[
"tags"
][idx];
162
}
163
164
const
nlohmann::json&
operator[]
(std::size_t idx)
const
{
165
return
json_data
[
"tags"
][idx];
166
}
167
174
unsigned
int
get_number_of_micro_time_channels
(){
175
return
(
unsigned
int
)
get_tag
(
json_data
,
TTTRNMicroTimes
)[
"value"
];
176
}
177
179
double
get_macro_time_resolution
();
180
182
double
get_micro_time_resolution
(){
183
return
get_tag
(
json_data
,
TTTRTagRes
)[
"value"
];
184
}
185
187
int
get_pixel_duration
(){
188
double
pixel_duration_d =
TTTRHeader::get_tag
(
189
json_data
,
"$TimePerPixel"
)[
"value"
];
190
double
global_res =
TTTRHeader::get_tag
(
191
json_data
,
"MeasDesc_GlobalResolution"
)[
"value"
];
192
long
pixel_duration = std::round(pixel_duration_d / global_res);
193
return
pixel_duration;
194
}
195
197
int
get_line_duration
(){
198
double
pixel_duration_d =
TTTRHeader::get_tag
(
199
json_data
,
"$TimePerPixel"
)[
"value"
];
200
double
global_res_d =
TTTRHeader::get_tag
(
201
json_data
,
"MeasDesc_GlobalResolution"
)[
"value"
];
202
double
n_pixel =
TTTRHeader::get_tag
(
json_data
,
"ImgHdr_PixX"
)[
"value"
];
203
return
std::ceil((pixel_duration_d * n_pixel) / global_res_d);
204
}
205
217
unsigned
int
get_effective_number_of_micro_time_channels
(){
218
double
macro_time_resolution =
get_macro_time_resolution
();
219
double
micro_time_resolution =
get_micro_time_resolution
();
220
return
(
unsigned
int
) std::floor(macro_time_resolution / micro_time_resolution);
221
}
222
226
TTTRHeader
();
227
TTTRHeader
(
int
tttr_container_type);
228
230
TTTRHeader
(
const
TTTRHeader
&p2);
231
244
TTTRHeader
(std::FILE *fpin,
int
tttr_container_type=0,
bool
close_file=
false
);
245
TTTRHeader
(std::string fn,
int
tttr_container_type=0);
246
~TTTRHeader
() =
default
;
247
257
static
size_t
read_ptu_header
(
258
std::FILE *fpin,
259
int
&tttr_record_type,
260
nlohmann::json &
json_data
,
261
bool
rewind =
true
262
);
263
272
static
size_t
read_ht3_header
(
273
std::FILE *fpin,
274
nlohmann::json &data,
275
bool
rewind =
true
276
);
277
286
static
size_t
read_bh132_header
(
287
std::FILE *fpin,
288
nlohmann::json &data,
289
bool
rewind =
true
290
);
291
300
static
size_t
read_cz_confocor3_header
(
301
std::FILE *fpin,
302
nlohmann::json &data,
303
bool
rewind =
true
304
);
305
315
static
void
write_spc132_header
(
316
std::string fn,
317
TTTRHeader
* header,
318
std::string modes =
"w"
319
);
320
330
static
void
write_ptu_header
(
331
std::string fn,
332
TTTRHeader
* header,
333
std::string modes =
"wb"
334
);
335
345
static
void
write_ht3_header
(
346
std::string fn,
347
TTTRHeader
* header,
348
std::string modes =
"wb"
349
);
350
361
std::string
get_json
(std::string tag_name=
""
,
int
idx=-1,
int
indent=1);
362
368
void
set_json
(std::string json_string){
369
json_data
= nlohmann::json::parse(json_string);
370
}
371
372
};
373
374
375
#endif
//TTTRLIB_READHEADER_H
Histogram.h
TTTRTagRes
const std::string TTTRTagRes
Definition
TTTRHeader.h:36
TTTRContainerType
const std::string TTTRContainerType
Definition
TTTRHeader.h:41
TTTRTagGlobRes
const std::string TTTRTagGlobRes
Definition
TTTRHeader.h:37
TTTRTagTTTRRecType
const std::string TTTRTagTTTRRecType
Definition
TTTRHeader.h:42
TTTRNMicroTimes
const std::string TTTRNMicroTimes
Definition
TTTRHeader.h:39
FileTagEnd
const std::string FileTagEnd
Definition
TTTRHeader.h:44
TTTRSyncRate
const std::string TTTRSyncRate
Definition
TTTRHeader.h:38
TTTRTagBits
const std::string TTTRTagBits
Definition
TTTRHeader.h:43
TTTRRecordType
const std::string TTTRRecordType
Definition
TTTRHeader.h:40
TTTRHeaderTypes.h
tyAnsiString
#define tyAnsiString
Definition
TTTRHeaderTypes.h:16
TTTRRecordReader.h
TTTRRecordTypes.h
TTTRHeader
Definition
TTTRHeader.h:47
TTTRHeader::set_tttr_record_type
void set_tttr_record_type(int v)
Definition
TTTRHeader.h:74
TTTRHeader::get_tttr_container_type
int get_tttr_container_type()
Definition
TTTRHeader.h:82
TTTRHeader::TTTRHeader
TTTRHeader(std::FILE *fpin, int tttr_container_type=0, bool close_file=false)
TTTRHeader::end
size_t end() const
Definition
TTTRHeader.h:149
TTTRHeader::operator[]
const nlohmann::json & operator[](std::size_t idx) const
Definition
TTTRHeader.h:164
TTTRHeader::add_tag
static void add_tag(nlohmann::json &json_data, const std::string &name, std::any value, unsigned int type=tyAnsiString, int idx=-1)
TTTRHeader::get_tag
static nlohmann::json get_tag(nlohmann::json json_data, const std::string &name, int idx=-1)
TTTRHeader::read_bh132_header
static size_t read_bh132_header(std::FILE *fpin, nlohmann::json &data, bool rewind=true)
Reads the header of a Becker & Hickel SPC132 file and sets the reading routing.
TTTRHeader::set_tttr_container_type
void set_tttr_container_type(int v)
Definition
TTTRHeader.h:90
TTTRHeader::get_micro_time_resolution
double get_micro_time_resolution()
Resolution for the micro time in nanoseconds.
Definition
TTTRHeader.h:182
TTTRHeader::~TTTRHeader
~TTTRHeader()=default
TTTRHeader::get_number_of_micro_time_channels
unsigned int get_number_of_micro_time_channels()
Definition
TTTRHeader.h:174
TTTRHeader::TTTRHeader
TTTRHeader(const TTTRHeader &p2)
Copy constructor.
TTTRHeader::get_line_duration
int get_line_duration()
Duration of a line in LSM in units of macro time clock.
Definition
TTTRHeader.h:197
TTTRHeader::TTTRHeader
TTTRHeader(int tttr_container_type)
TTTRHeader::operator[]
nlohmann::json & operator[](std::size_t idx)
Definition
TTTRHeader.h:160
TTTRHeader::get_effective_number_of_micro_time_channels
unsigned int get_effective_number_of_micro_time_channels()
Definition
TTTRHeader.h:217
TTTRHeader::read_ptu_header
static size_t read_ptu_header(std::FILE *fpin, int &tttr_record_type, nlohmann::json &json_data, bool rewind=true)
Reads the header of a PTU file and sets the reading routing.
TTTRHeader::get_pixel_duration
int get_pixel_duration()
Duration of a pixel in LSM in units of macro time clock.
Definition
TTTRHeader.h:187
TTTRHeader::read_ht3_header
static size_t read_ht3_header(std::FILE *fpin, nlohmann::json &data, bool rewind=true)
Reads the header of an HT3 file and sets the reading routing.
TTTRHeader::write_ht3_header
static void write_ht3_header(std::string fn, TTTRHeader *header, std::string modes="wb")
TTTRHeader::TTTRHeader
TTTRHeader(std::string fn, int tttr_container_type=0)
TTTRHeader::write_spc132_header
static void write_spc132_header(std::string fn, TTTRHeader *header, std::string modes="w")
TTTRHeader::read_cz_confocor3_header
static size_t read_cz_confocor3_header(std::FILE *fpin, nlohmann::json &data, bool rewind=true)
Reads the header of a Carl Zeiss (CZ) Confocor3 file and sets the reading routing.
TTTRHeader::get_tttr_record_type
int get_tttr_record_type()
Definition
TTTRHeader.h:66
TTTRHeader::json_data
nlohmann::json json_data
Definition
TTTRHeader.h:54
TTTRHeader::size
size_t size()
Definition
TTTRHeader.h:156
TTTRHeader::TTTRHeader
TTTRHeader()
TTTRHeader::write_ptu_header
static void write_ptu_header(std::string fn, TTTRHeader *header, std::string modes="wb")
TTTRHeader::find_tag
static int find_tag(nlohmann::json &json_data, const std::string &name, int idx=-1)
TTTRHeader::set_json
void set_json(std::string json_string)
Definition
TTTRHeader.h:368
TTTRHeader::header_end
size_t header_end
Definition
TTTRHeader.h:59
TTTRHeader::get_bytes_per_record
size_t get_bytes_per_record()
Definition
TTTRHeader.h:145
TTTRHeader::get_json
std::string get_json(std::string tag_name="", int idx=-1, int indent=1)
TTTRHeader::get_macro_time_resolution
double get_macro_time_resolution()
Resolution for the macro time in nanoseconds.
TTTR
Time-Tagged Time-Resolved (TTTR) data class.
Definition
TTTR.h:195
Generated by
1.10.0