STIR 6.5.0
CListRecordSAFIR.h
Go to the documentation of this file.
1/* CListRecordSAFIR.h
2
3 Coincidence Event Class for SAFIR: Header File
4
5 Copyright 2015 ETH Zurich, Institute of Particle Physics
6 Copyright 2017 ETH Zurich, Institute of Particle Physics and Astrophysics
7 Copyright 2020, 2022 Positrigo AG, Zurich
8
9 Licensed under the Apache License, Version 2.0 (the "License");
10 you may not use this file except in compliance with the License.
11 You may obtain a copy of the License at
12
13 http://www.apache.org/licenses/LICENSE-2.0
14
15 Unless required by applicable law or agreed to in writing, software
16 distributed under the License is distributed on an "AS IS" BASIS,
17 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 See the License for the specific language governing permissions and
19 limitations under the License.
20
21 */
22
33
34#ifndef __stir_listmode_CListRecordSAFIR_H__
35#define __stir_listmode_CListRecordSAFIR_H__
36
37#include <random>
38
41#include "stir/Succeeded.h"
42#include "stir/ByteOrder.h"
44
45#include "boost/static_assert.hpp"
46#include "boost/cstdint.hpp"
47
49#include "boost/make_shared.hpp"
50
51START_NAMESPACE_STIR
52
71template <class Derived>
73{
74public:
78 inline CListEventSAFIR() {}
79
81 inline LORAs2Points<float> get_LOR() const override;
82
84 inline void get_bin(Bin& bin, const ProjDataInfo& proj_data_info) const override;
85
87
91 inline bool is_valid_template(const ProjDataInfo&) const override { return true; }
92
94 inline bool is_prompt() const override { return !(static_cast<const Derived*>(this)->is_prompt()); }
96
97 inline void set_map_sptr(shared_ptr<const DetectorCoordinateMap> new_map_sptr) { map_sptr = new_map_sptr; }
100 inline void set_scanner_sptr(shared_ptr<const Scanner> new_scanner_sptr) { scanner_sptr = new_scanner_sptr; }
101
102private:
103 shared_ptr<const DetectorCoordinateMap> map_sptr;
104 shared_ptr<const Scanner> scanner_sptr;
105
106 const DetectorCoordinateMap& map_to_use() const
107 {
108 return map_sptr ? *map_sptr : *this->scanner_sptr->get_detector_coordinate_map_sptr();
109 }
110};
111
113
115{
116public:
118 inline void get_detection_position_pair(DetectionPositionPair<>& det_pos_pair);
119
121 inline bool is_prompt() const { return !isDelayed; }
122
124 inline bool is_time() const { return type; }
125
127 inline Succeeded set_prompt(const bool prompt = true)
128 {
129 isDelayed = !prompt;
130 return Succeeded::yes;
131 }
132
133private:
134#if STIRIsNativeByteOrderBigEndian
135 unsigned type : 1;
136 unsigned isDelayed : 1;
137 unsigned reserved : 6;
138 unsigned layerB : 4;
139 unsigned layerA : 4;
140 unsigned detB : 16;
141 unsigned detA : 16;
142 unsigned ringB : 8;
143 unsigned ringA : 8;
144#else
145 unsigned ringA : 8;
146 unsigned ringB : 8;
147 unsigned detA : 16;
148 unsigned detB : 16;
149 unsigned layerA : 4;
150 unsigned layerB : 4;
151 unsigned reserved : 6;
152 unsigned isDelayed : 1;
153 unsigned type : 1;
154#endif
155};
156
158
160{
161public:
163 inline void get_detection_position_pair(DetectionPositionPair<>& det_pos_pair);
164
166 inline bool is_prompt() const { return !isDelayed; }
167
169 inline bool is_time() const { return type; }
170
172 inline Succeeded set_prompt(const bool prompt = true)
173 {
174 isDelayed = !prompt;
175 return Succeeded::yes;
176 }
177
178private:
179#if STIRIsNativeByteOrderBigEndian
180 unsigned type : 1;
181 unsigned isDelayed : 1;
182 unsigned reserved : 8;
183 unsigned layerB : 3;
184 unsigned layerA : 3;
185 unsigned detB : 16;
186 unsigned detA : 16;
187 unsigned ringB : 8;
188 unsigned ringA : 8;
189#else
190 unsigned ringA : 8;
191 unsigned ringB : 8;
192 unsigned detA : 16;
193 unsigned detB : 16;
194 unsigned layerA : 3;
195 unsigned layerB : 3;
196 unsigned reserved : 8;
197 unsigned isDelayed : 1;
198 unsigned type : 1;
199#endif
200};
201
203
205{
206public:
207 inline unsigned long get_time_in_millisecs() const { return static_cast<unsigned long>(time); }
208 inline Succeeded set_time_in_millisecs(const unsigned long time_in_millisecs)
209 {
210 time = ((boost::uint64_t(1) << 49) - 1) & static_cast<boost::uint64_t>(time_in_millisecs);
211 return Succeeded::yes;
212 }
213 inline bool is_time() const { return type; }
214
215private:
216#if STIRIsNativeByteOrderBigEndian
217 boost::uint64_t type : 1;
218 boost::uint64_t reserved : 15;
219 boost::uint64_t time : 48;
220#else
221 boost::uint64_t time : 48;
222 boost::uint64_t reserved : 15;
223 boost::uint64_t type : 1;
224#endif
225};
226
228
229template <class DataType>
230class CListRecordSAFIR : public CListRecord, public ListTime, public CListEventSAFIR<CListRecordSAFIR<DataType>>
231{
232public:
234 DataType get_data() const { return this->event_data; }
235
237 : CListEventSAFIR<CListRecordSAFIR<DataType>>()
238 {}
239
240 ~CListRecordSAFIR() override {}
241
242 bool is_time() const override { return time_data.is_time(); }
243
244 bool is_event() const override { return !time_data.is_time(); }
245
246 CListEvent& event() override { return *this; }
247
248 const CListEvent& event() const override { return *this; }
249
250 virtual CListEventSAFIR<CListRecordSAFIR<DataType>>& event_SAFIR() { return *this; }
251
252 virtual const CListEventSAFIR<CListRecordSAFIR<DataType>>& event_SAFIR() const { return *this; }
253
254 ListTime& time() override { return *this; }
255
256 const ListTime& time() const override { return *this; }
257
258 virtual bool operator==(const CListRecord& e2) const
259 {
260 return dynamic_cast<CListRecordSAFIR<DataType> const*>(&e2) != 0
261 && raw == static_cast<CListRecordSAFIR<DataType> const&>(e2).raw;
262 }
263
264 inline unsigned long get_time_in_millisecs() const override { return time_data.get_time_in_millisecs(); }
265
266 inline Succeeded set_time_in_millisecs(const unsigned long time_in_millisecs) override
267 {
268 return time_data.set_time_in_millisecs(time_in_millisecs);
269 }
270
271 inline bool is_prompt() const override { return event_data.is_prompt(); }
272
273 Succeeded init_from_data_ptr(const char* const data_ptr, const std::size_t size_of_record, const bool do_byte_swap)
274 {
275 assert(size_of_record >= 8);
276 std::copy(data_ptr, data_ptr + 8, reinterpret_cast<char*>(&raw)); // TODO necessary for operator==
277 if (do_byte_swap)
279 return Succeeded::yes;
280 }
281
282 std::size_t size_of_record_at_ptr(const char* const /*data_ptr*/, const std::size_t /*size*/, const bool /*do_byte_swap*/) const
283 {
284 return 8;
285 }
286
287private:
288 // use C++ union to save data, you can only use one at a time,
289 // but compiler will not check which one was used!
290 // Be careful not to read event data from time record and vice versa!!
291 // However, this is used as a feature if comparing events over the 'raw' type.
292 union
293 {
294 DataType event_data;
295 CListTimeDataSAFIR time_data;
296 boost::int64_t raw;
297 };
298 BOOST_STATIC_ASSERT(sizeof(boost::uint64_t) == 8);
299 BOOST_STATIC_ASSERT(sizeof(DataType) == 8);
300 BOOST_STATIC_ASSERT(sizeof(CListTimeDataSAFIR) == 8);
301};
302
303END_NAMESPACE_STIR
304
305#include "CListRecordSAFIR.inl"
306
307#endif
Definition of STIRIsNativeByteOrderBigEndian and STIRIsNativeByteOrderLittleEndian preprocessor symbo...
This file declares the stir::ByteOrder class.
Inline implementation of class stir::CListEventSAFIR and stir::CListRecordSAFIR with supporting class...
Declarations of classes stir::CListRecord, and stir::CListEvent which are used for list mode data.
Declaration of class stir::DetectionPositionPair.
Declaration of class stir::DetectorCoordinateMap.
Declaration of class stir::Succeeded.
A class for storing coordinates and value of a single projection bin.
Definition Bin.h:49
static void swap_order(NUMBER &value)
swap the byteorder of the argument
Definition ByteOrder.h:122
Class for record with coincidence data using NeuroLF bitfield definition.
Definition CListRecordSAFIR.h:160
Succeeded set_prompt(const bool prompt=true)
Can be used to set "promptness" of event.
Definition CListRecordSAFIR.h:172
bool is_prompt() const
Returns 0 if event is prompt and 1 if delayed.
Definition CListRecordSAFIR.h:166
void get_detection_position_pair(DetectionPositionPair<> &det_pos_pair)
Writes detection position pair to reference given as argument.
Definition CListRecordSAFIR.inl:134
bool is_time() const
Returns 1 if if event is time and 0 if it is prompt.
Definition CListRecordSAFIR.h:169
Class for record with coincidence data using SAFIR bitfield definition.
Definition CListRecordSAFIR.h:115
Succeeded set_prompt(const bool prompt=true)
Can be used to set "promptness" of event.
Definition CListRecordSAFIR.h:127
void get_detection_position_pair(DetectionPositionPair<> &det_pos_pair)
Writes detection position pair to reference given as argument.
Definition CListRecordSAFIR.inl:121
bool is_prompt() const
Returns 0 if event is prompt and 1 if delayed.
Definition CListRecordSAFIR.h:121
bool is_time() const
Returns 1 if if event is time and 0 if it is prompt.
Definition CListRecordSAFIR.h:124
Definition CListRecordSAFIR.h:73
CListEventSAFIR()
Definition CListRecordSAFIR.h:78
bool is_prompt() const override
Returns 0 if event is prompt and 1 if delayed.
Definition CListRecordSAFIR.h:94
void set_scanner_sptr(shared_ptr< const Scanner > new_scanner_sptr)
Definition CListRecordSAFIR.h:100
void set_map_sptr(shared_ptr< const DetectorCoordinateMap > new_map_sptr)
Function to set map for detector indices to coordinates.
Definition CListRecordSAFIR.h:97
bool is_valid_template(const ProjDataInfo &) const override
This method checks if the template is valid for LmToProjData.
Definition CListRecordSAFIR.h:91
Class for storing and using a coincidence event from a list mode file.
Definition CListRecord.h:54
Class for general SAFIR record, containing a union of data, time and raw record and providing access ...
Definition CListRecordSAFIR.h:231
bool is_prompt() const override
Returns 0 if event is prompt and 1 if delayed.
Definition CListRecordSAFIR.h:271
DataType get_data() const
Returns event_data (without checking if the type is really event and not time).
Definition CListRecordSAFIR.h:234
Class for records in a PET list mode file.
Definition CListRecord.h:68
Class for record with time data using SAFIR bitfield definition.
Definition CListRecordSAFIR.h:205
A class for storing 2 coordinates-sets of a detection, together with a timing-position index (for TOF...
Definition DetectionPositionPair.h:41
Definition DetectorCoordinateMap.h:51
A class for LORs.
Definition LORCoordinates.h:296
A class for storing and using a timing record from a listmode file.
Definition ListTime.h:47
An (abstract base) class that contains information on the projection data.
Definition ProjDataInfo.h:70
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition Succeeded.h:44