STIR 6.4.0
CListRecordECAT8_32bit.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2003-2011 Hammersmith Imanet Ltd
3 Copyright (C) 2013-2014 University College London
4 This file is part of STIR.
5
6 SPDX-License-Identifier: Apache-2.0
7
8 See STIR/LICENSE.txt for details
9*/
17
18#ifndef __stir_listmode_CListRecordECAT8_32bit_H__
19#define __stir_listmode_CListRecordECAT8_32bit_H__
20
24#include "stir/Succeeded.h"
25#include "stir/ByteOrder.h"
27#include "stir/round.h"
28#include "boost/static_assert.hpp"
29#include "boost/cstdint.hpp"
31
32START_NAMESPACE_STIR
33namespace ecat
34{
35
37
48{
49public:
50 /* 'delayed' bit:
51 0 if event is delayed (it fell in delayed time window) */
52
53#if STIRIsNativeByteOrderBigEndian
54 unsigned type : 1; /* 0-coincidence event, 1-time tick */
55 unsigned delayed : 1;
56 unsigned offset : 30;
57#else
58 // Do byteswapping first before using this bit field.
59 unsigned offset : 30;
60 unsigned delayed : 1;
61 unsigned type : 1; /* 0-coincidence event, 1-time tick */
62
63#endif
64}; /*-coincidence event*/
65
67
72class CListEventECAT8_32bit : public CListEventCylindricalScannerWithDiscreteDetectors
73{
74private:
75public:
76 typedef CListEventDataECAT8_32bit DataType;
77 DataType get_data() const { return this->data; }
78
79public:
80 CListEventECAT8_32bit(const shared_ptr<const ProjDataInfo>& proj_data_info_sptr);
81
84
87
88 Succeeded init_from_data_ptr(const void* const ptr)
89 {
90 const char* const data_ptr = reinterpret_cast<const char* const>(ptr);
91 std::copy(data_ptr, data_ptr + sizeof(this->raw), reinterpret_cast<char*>(&this->raw));
92 return Succeeded::yes;
93 }
94 inline bool is_prompt() const override { return this->data.delayed == 1; }
95 inline Succeeded set_prompt(const bool prompt = true) override
96 {
97 if (prompt)
98 this->data.delayed = 1;
99 else
100 this->data.delayed = 0;
101 return Succeeded::yes;
102 }
103
104private:
105 BOOST_STATIC_ASSERT(sizeof(CListEventDataECAT8_32bit) == 4);
106 union
107 {
109 boost::int32_t raw;
110 };
111 std::vector<int> segment_sequence;
112 std::vector<int> timing_poss_sequence;
113 std::vector<int> sizes;
114};
115
117
120{
121public:
122#if STIRIsNativeByteOrderBigEndian
123 unsigned type : 1; /* 0-coincidence event, 1-time tick */
124 unsigned deadtimeetc : 2; /* extra bits differentiating between timing or other stuff, zero if timing event */
125 unsigned time : 29; /* since scan start */
126#else
127 // Do byteswapping first before using this bit field.
128 unsigned time : 29; /* since scan start */
129 unsigned deadtimeetc : 2; /* extra bits differentiating between timing or other stuff, zero if timing event */
130 unsigned type : 1; /* 0-coincidence event, 1-time tick */
131#endif
132};
133
134class CListDataAnyECAT8_32bit
135{
136public:
137 Succeeded init_from_data_ptr(const void* const ptr)
138 {
139 const char* const data_ptr = reinterpret_cast<const char* const>(ptr);
140 std::copy(data_ptr, data_ptr + sizeof(this->raw), reinterpret_cast<char*>(&this->raw));
141 return Succeeded::yes;
142 }
143 bool is_time() const { return this->data.type == 1U && this->data.deadtimeetc == 0U; }
144 bool is_other() const { return this->data.type == 1U && this->data.deadtimeetc != 0U; }
145 bool is_event() const { return this->data.type == 0U; }
146
147private:
148 BOOST_STATIC_ASSERT(sizeof(CListTimeDataECAT8_32bit) == 4);
149 union
150 {
151 CListTimeDataECAT8_32bit data;
152 boost::int32_t raw;
153 };
154};
155
157
160{
161public:
162 Succeeded init_from_data_ptr(const void* const ptr)
163 {
164 const char* const data_ptr = reinterpret_cast<const char* const>(ptr);
165 std::copy(data_ptr, data_ptr + sizeof(this->raw), reinterpret_cast<char*>(&this->raw));
166 return Succeeded::yes;
167 }
168 bool is_time() const { return this->data.type == 1U && this->data.deadtimeetc == 0U; }
169 inline unsigned long get_time_in_millisecs() const override { return static_cast<unsigned long>(this->data.time); }
170 inline Succeeded set_time_in_millisecs(const unsigned long time_in_millisecs) override
171 {
172 this->data.time = ((1U << 30) - 1) & static_cast<unsigned>(time_in_millisecs);
173 // TODO return more useful value
174 return Succeeded::yes;
175 }
176
177private:
178 BOOST_STATIC_ASSERT(sizeof(CListTimeDataECAT8_32bit) == 4);
179 union
180 {
182 boost::int32_t raw;
183 };
184};
185
187
195class CListRecordECAT8_32bit : public CListRecord // currently no gating yet
196{
197
198 // public:
199
200 bool is_time() const override { return this->any_data.is_time(); }
201 /*
202 bool is_gating_input() const
203 { return this->is_time(); }
204 */
205 bool is_event() const override { return this->any_data.is_event(); }
206 CListEventECAT8_32bit& event() override { return this->event_data; }
207 const CListEventECAT8_32bit& event() const override { return this->event_data; }
208 CListTimeECAT8_32bit& time() override { return this->time_data; }
209 const CListTimeECAT8_32bit& time() const override { return this->time_data; }
210
211 bool operator==(const CListRecord& e2) const
212 {
213 return dynamic_cast<CListRecordECAT8_32bit const*>(&e2) != 0 && raw == dynamic_cast<CListRecordECAT8_32bit const&>(e2).raw;
214 }
215
216public:
217 CListRecordECAT8_32bit(const shared_ptr<const ProjDataInfo>& proj_data_info_sptr)
218 : event_data(proj_data_info_sptr)
219 {}
220
221 virtual Succeeded init_from_data_ptr(const char* const data_ptr,
222 const std::size_t
223#ifndef NDEBUG
224 size // only used within assert, so commented-out otherwise to avoid compiler warnings
225#endif
226 ,
227 const bool do_byte_swap)
228 {
229 assert(size >= 4);
230 std::copy(data_ptr, data_ptr + 4, reinterpret_cast<char*>(&raw));
231 if (do_byte_swap)
233 this->any_data.init_from_data_ptr(&raw);
234 // should in principle check return value, but it's always Succeeded::yes anyway
235 if (this->any_data.is_time())
236 return this->time_data.init_from_data_ptr(&raw);
237 else if (this->any_data.is_event())
238 return this->event_data.init_from_data_ptr(&raw);
239 else
240 return Succeeded::yes;
241 }
242
243 virtual std::size_t
244 size_of_record_at_ptr(const char* const /*data_ptr*/, const std::size_t /*size*/, const bool /*do_byte_swap*/) const
245 {
246 return 4;
247 }
248
249private:
250 CListEventECAT8_32bit event_data;
251 CListTimeECAT8_32bit time_data;
252 CListDataAnyECAT8_32bit any_data;
253 boost::int32_t raw; // this raw field isn't strictly necessary, get rid of it?
254};
255
256} // namespace ecat
257END_NAMESPACE_STIR
258
259#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::DetectionPositionPair.
Declaration of class stir::ProjDataInfoCylindrical.
Declaration of class stir::Succeeded.
static void swap_order(NUMBER &value)
swap the byteorder of the argument
Definition ByteOrder.h:122
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:67
A class for storing 2 coordinates-sets of a detection, together with a timing-position index (for TOF...
Definition DetectionPositionPair.h:41
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
Class for decoding storing and using a raw coincidence event from a listmode file from the ECAT 966 s...
Definition CListRecordECAT8_32bit.h:48
Class for storing and using a coincidence event from a listmode file from Siemens scanners using the ...
Definition CListRecordECAT8_32bit.h:73
void get_detection_position(DetectionPositionPair<> &) const override
This routine returns the corresponding detector pair.
Definition CListRecordECAT8_32bit.cxx:48
void set_detection_position(const DetectionPositionPair<> &) override
This routine sets in a coincidence event from detector "indices".
Definition CListRecordECAT8_32bit.cxx:83
Succeeded set_prompt(const bool prompt=true) override
Changes the event from prompt to delayed or vice versa.
Definition CListRecordECAT8_32bit.h:95
A class for decoding a raw events that is neither time or coincidence in a listmode file from the ECA...
Definition CListRecordECAT8_32bit.h:120
A class for storing and using a timing 'event' from a listmode file from the ECAT 8_32bit scanner.
Definition CListRecordECAT8_32bit.h:160
Declaration of the stir::round functions.