STIR 6.5.0
CListRecordGEHDF5.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2003-2011 Hammersmith Imanet Ltd (CListRecordECAT.h)
3 Copyright (C) 2013, 2016, 2020 University College London
4 Copyright (C) 2017-2018 University of Leeds
5*/
17
18#ifndef __stir_listmode_CListRecordGEHDF5_H__
19#define __stir_listmode_CListRecordGEHDF5_H__
20
23#include "stir/Succeeded.h"
24#include "stir/ByteOrder.h"
26#include <boost/static_assert.hpp>
27#include "stir/error.h"
28#include <cstdint>
29#include <iostream>
30
31START_NAMESPACE_STIR
32
33namespace GE
34{
35namespace RDF_HDF5
36{
37
38namespace detail
39{
40/***********************************
41 * Supported Event Length Modes
42 ***********************************/
43enum EventLength
44{
45 /* RESERVED = 0x0, */
46 LENGTH_6_EVT = 0x1,
47 LENGTH_8_EVT = 0x2,
48 LENGTH_16_EVT = 0x3
49};
50
51/***********************************
52 * Supported Event Types
53 ***********************************/
54enum EventType
55{
56 EXTENDED_EVT = 0x0,
57 COINC_EVT = 0x1
58};
59
60/***********************************
61 * Supported Extended Event Types
62 ***********************************/
63enum ExtendedEvtType
64{
65 TIME_MARKER_EVT = 0x0,
66 COINC_COUNT_EVT = 0x1,
67 EXTERN_TRIG_EVT = 0x2,
68 TABLE_POS_EVT = 0x3,
69 /* RESERVED = 0x4 to 0xE */
70 /* 0xE is temporary taken here to mark end of it. */
71 END_LIST_EVT = 0xE,
72 SINGLE_EVT = 0xF
73};
74
76
80{
81public:
82#if STIRIsNativeByteOrderBigEndian
83 // Do byteswapping first before using this bit field.
84 TODO;
85#else
86 std::uint16_t eventLength : 2; /* Event Length : Enum for the number of bytes in the event */
87 std::uint16_t eventType : 1; /* Event Type : Coin or Extended types */
88 std::uint16_t eventTypeExt : 4; /* If not a coincidence, Extended Event Type : Time Marker, Trigger, Single..etc */
89 std::uint16_t dummy : 9;
90#endif
91}; /*any record */
92
94
99{
100public:
101 inline bool is_prompt() const { return true; } // TODO
102 inline Succeeded set_prompt(const bool prompt = true)
103 {
104 // if (prompt) random=1; else random=0; return Succeeded::yes;
105 return Succeeded::no;
106 }
107 inline bool is_event() const
108 {
109 return (eventType == COINC_EVT) /* && eventTypeExt==COINC_COUNT_EVT)*/;
110 } // TODO need to find out how to see if it's a coincidence event
111
112 inline int get_tof_bin() const { return static_cast<int>(-deltaTime); }
113#if STIRIsNativeByteOrderBigEndian
114 // Do byteswapping first before using this bit field.
115 TODO
116#else
117 std::uint16_t eventLength : 2; /* Event Length : Enum for the number of bytes in the event */
118 std::uint16_t eventType : 1; /* Event Type : Coin or Extended types */
119 std::uint16_t hiXtalShortInteg : 1; /* High Crystal Short Integration on / off */
120 std::uint16_t loXtalShortInteg : 1; /* Low Crystal Short Integration on / off */
121 std::uint16_t hiXtalScatterRec : 1; /* High Crystal Scatter Recovered on / off */
122 std::uint16_t loXtalScatterRec : 1; /* Low Crystal Scatter Recovered on / off */
123 std::int16_t deltaTime : 9; /* TOF 'signed' delta time (units defined by electronics */
124 std::uint16_t hiXtalAxialID : 6; /* High Crystal Axial Id */
125 std::uint16_t hiXtalTransAxID : 10; /* High Crystal Trans-Axial Id */
126 std::uint16_t loXtalAxialID : 6; /* Low Crystal Axial Id */
127 std::uint16_t loXtalTransAxID : 10; /* Low Crystal Trans-Axial Id */
128#endif
129}; /*-coincidence event*/
130
132
137{
138public:
139 inline unsigned long get_time_in_millisecs() const { return (time_hi() << 16) | time_lo(); }
140 inline Succeeded set_time_in_millisecs(const unsigned long time_in_millisecs)
141 {
142 data.timeMarkerLS = ((1UL << 16) - 1) & (time_in_millisecs);
143 data.timeMarkerMS = (time_in_millisecs) >> 16;
144 // TODO return more useful value
145 return Succeeded::yes;
146 }
147 inline bool is_time() const
148 { // TODO need to find out how to see if it's a timing event
149 return (data.eventType == EXTENDED_EVT) && (data.eventTypeExt == TIME_MARKER_EVT);
150 } // TODO
151
152private:
153 struct data_t
154 {
155#if STIRIsNativeByteOrderBigEndian
156 TODO
157#else
158 std::uint16_t eventLength : 2; /* Event Length : Enum for the number of bytes in the event */
159 std::uint16_t eventType : 1; /* Event Type : Coin or Extended types */
160 std::uint16_t eventTypeExt : 4; /* Extended Event Type : Time Marker, Trigger, Single..etc */
161 std::uint16_t unused1 : 5; /* Unused */
162 std::uint16_t externEvt3 : 1; /* External Event Input 3 Level */
163 std::uint16_t externEvt2 : 1; /* External Event Input 2 Level */
164 std::uint16_t externEvt1 : 1; /* External Event Input 1 Level */
165 std::uint16_t externEvt0 : 1; /* External Event Input 0 Level */
166 std::uint16_t timeMarkerLS : 16; /* Least Significant 16 bits of 32-bit Time Marker */
167 std::uint16_t timeMarkerMS : 16; /* Most Significant 16 bits of 32-bitTime Marker */
168#endif
169 };
170
171 data_t data;
172
173 unsigned long time_lo() const
174 {
175 return data.timeMarkerLS;
176 }
177 unsigned long time_hi() const
178 {
179 return data.timeMarkerMS;
180 }
181};
182
183} // namespace detail
184
186
192 public ListTime, // public CListGatingInput,
194{
195 typedef detail::CListEventDataGEHDF5 DataType;
196 typedef detail::ListTimeDataGEHDF5 TimeType;
197 // typedef CListGatingDataGEHDF5 GatingType;
198
199public:
201
206 CListRecordGEHDF5(const shared_ptr<const ProjDataInfo>& proj_data_info_sptr, const unsigned long first_time_stamp)
208 first_time_stamp(first_time_stamp)
209 {}
210
211 bool is_time() const override { return this->time_data.is_time(); }
212#if 0
213 bool is_gating_input() const
214 {
215 return this->gating_data.is_gating_input();
216 }
217#endif
218
219 bool is_event() const override
220 {
221 return this->event_data.is_event();
222 }
223 CListEvent& event() override
224 {
225 return *this;
226 }
227 const CListEvent& event() const override
228 {
229 return *this;
230 }
231 ListTime& time() override
232 {
233 return *this;
234 }
235 const ListTime& time() const override
236 {
237 return *this;
238 }
239#if 0
240 virtual CListGatingInput& gating_input()
241 { return *this; }
242 virtual const CListGatingInput& gating_input() const
243 { return *this; }
244#endif
245 bool operator==(const CListRecord& e2) const
246 {
247 return false;
248#if 0
249// TODO
250dynamic_cast<CListRecordGEHDF5 const *>(&e2) != 0 &&
251 raw[0] == static_cast<CListRecordGEHDF5 const &>(e2).raw[0] &&
252 (this->is_event() || (raw[1] == static_cast<CListRecordGEHDF5 const &>(e2).raw[1]));
253#endif
254 }
255
256 // time
257 inline unsigned long get_time_in_millisecs() const override
258 {
259 return time_data.get_time_in_millisecs() - first_time_stamp;
260 }
261
262 inline Succeeded set_time_in_millisecs(const unsigned long time_in_millisecs) override
263 {
264 return time_data.set_time_in_millisecs(time_in_millisecs);
265 }
266#if 0
267 inline unsigned int get_gating() const
268 { return gating_data.get_gating(); }
269 inline Succeeded set_gating(unsigned int g)
270 { return gating_data.set_gating(g); }
271#endif
272 // event
273 inline bool is_prompt() const override
274 {
275 return event_data.is_prompt();
276 }
277 inline Succeeded set_prompt(const bool prompt = true) override
278 {
279 return event_data.set_prompt(prompt);
280 }
281
283 {
284 det_pos.pos1().tangential_coord()
285 = this->get_uncompressed_proj_data_info_sptr()->get_scanner_sptr()->get_num_detectors_per_ring() - 1
286 - event_data.loXtalTransAxID;
287 det_pos.pos1().axial_coord() = event_data.loXtalAxialID;
288 det_pos.pos2().tangential_coord()
289 = this->get_uncompressed_proj_data_info_sptr()->get_scanner_sptr()->get_num_detectors_per_ring() - 1
290 - event_data.hiXtalTransAxID;
291 det_pos.pos2().axial_coord() = event_data.hiXtalAxialID;
292 det_pos.timing_pos() = event_data.get_tof_bin();
293 }
294
297 {
298 error("TODO");
299 }
300
301 virtual std::size_t size_of_record_at_ptr(const char* const data_ptr, const std::size_t, const bool do_byte_swap) const
302 {
303 // TODO don't know what to do with byteswap.
304 assert(do_byte_swap == false);
305
306 // Figure out the actual size from the eventLength bits.
307 union
308 {
310 std::uint16_t raw[4];
311 };
312 std::copy(data_ptr, data_ptr + 2, &raw[0]);
313 switch (rec.eventLength)
314 {
315 case detail::LENGTH_6_EVT:
316 return std::size_t(6);
317 case detail::LENGTH_8_EVT:
318 return std::size_t(8);
319 case detail::LENGTH_16_EVT:
320 return std::size_t(16);
321 default:
322 error("ClistRecordGEHDF5: error decoding event (eventLength bits are incorrect)");
323 return std::size_t(0); // avoid compiler warnings
324 }
325 }
326
327 virtual Succeeded init_from_data_ptr(const char* const data_ptr, const std::size_t size, const bool do_byte_swap)
328 {
329 assert(size >= 6);
330 assert(size <= 16);
331 std::copy(data_ptr, data_ptr + size, reinterpret_cast<char*>(&this->raw[0]));
332
333 if (do_byte_swap)
334 {
335 error("ClistRecordGEHDF5: byte-swapping not supported yet. sorry");
336 // ByteOrder::swap_order(this->raw[0]);
337 }
338
339 return Succeeded::yes;
340 }
341
342private:
343 unsigned long first_time_stamp;
344 union
345 {
346 DataType event_data;
347 TimeType time_data;
348 // GatingType gating_data;
349 std::int32_t raw[16 / 4];
350 };
351 BOOST_STATIC_ASSERT(sizeof(std::int32_t) == 4);
352 BOOST_STATIC_ASSERT(sizeof(DataType) == 6);
353 BOOST_STATIC_ASSERT(sizeof(TimeType) == 6);
354 // BOOST_STATIC_ASSERT(sizeof(GatingType)==8);
355};
356
357} // namespace RDF_HDF5
358} // namespace GE
359
360END_NAMESPACE_STIR
361
362#endif
Definition of STIRIsNativeByteOrderBigEndian and STIRIsNativeByteOrderLittleEndian preprocessor symbo...
This file declares the stir::ByteOrder class.
Declarations of class stir::CListEventCylindricalScannerWithDiscreteDetectors.
Declarations of classes stir::CListRecord, and stir::CListEvent which are used for list mode data.
Declaration of class stir::Succeeded.
Class for storing and using a coincidence event from a list mode file for a cylindrical scanner.
Definition CListEventCylindricalScannerWithDiscreteDetectors.h:33
Class for records in a PET list mode file.
Definition CListRecord.h:68
A class for storing 2 coordinates-sets of a detection, together with a timing-position index (for TOF...
Definition DetectionPositionPair.h:41
CListRecordGEHDF5(const shared_ptr< const ProjDataInfo > &proj_data_info_sptr, const unsigned long first_time_stamp)
constructor
Definition CListRecordGEHDF5.h:206
void set_detection_position(const DetectionPositionPair<> &) override
This routine sets in a coincidence event from detector "indices".
Definition CListRecordGEHDF5.h:296
void get_detection_position(DetectionPositionPair<> &det_pos) const override
This routine returns the corresponding detector pair.
Definition CListRecordGEHDF5.h:282
Succeeded set_prompt(const bool prompt=true) override
Changes the event from prompt to delayed or vice versa.
Definition CListRecordGEHDF5.h:277
Class for finding out what the event/size-type is in a GE RDF9 listmode file.
Definition CListRecordGEHDF5.h:80
Class for storing and using a coincidence event from a GE RDF9 listmode file.
Definition CListRecordGEHDF5.h:99
A class for storing and using a timing 'event' from a GE RDF9 listmode file.
Definition CListRecordGEHDF5.h:137
A class for storing and using a timing record from a listmode file.
Definition ListTime.h:47
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition Succeeded.h:44
Declaration of stir::error().
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition error.cxx:42