STIR 6.4.0
ECAT966ListmodeInputFileFormat.h
Go to the documentation of this file.
1#ifndef __stir_IO_ECAT966ListmodeInputFileFormat_h__
2#define __stir_IO_ECAT966ListmodeInputFileFormat_h__
3/*
4 Copyright (C) 2011, Hammersmith Imanet Ltd
5 Copyright (C) 2013-2014, University College London
6 This file is part of STIR.
7 SPDX-License-Identifier: Apache-2.0
8
9 See STIR/LICENSE.txt for details
10*/
22
23#include "stir/utilities.h"
24#include "stir/info.h"
25#include "stir/error.h"
26#include <string>
27#include "stir/format.h"
28
29#ifndef HAVE_LLN_MATRIX
30# error HAVE_LLN_MATRIX not define: you need the lln ecat library.
31#endif
32
33#include "stir/IO/stir_ecat7.h"
34START_NAMESPACE_STIR
35START_NAMESPACE_ECAT
36START_NAMESPACE_ECAT7
37
39
51{
52public:
53 virtual const std::string get_name() const { return "ECAT966"; }
54
56 virtual bool can_read(const FileSignature& signature, std::istream& input) const
57 {
58 return this->actual_can_read(signature, input);
59 }
60
62 virtual bool can_read(const FileSignature& signature, const std::string& singles_filename) const
63 {
64 if (strncmp(signature.get_signature(), "MATRIX", 6) != 0)
65 return false;
66
67 // const string singles_filename = listmode_filename_prefix + "_1.sgl";
68 std::ifstream singles_file(singles_filename.c_str(), std::ios::binary);
69 char buffer[sizeof(Main_header)];
70 Main_header singles_main_header;
71 singles_file.read(buffer, sizeof(singles_main_header));
72 if (!singles_file)
73 return false;
74 unmap_main_header(buffer, &singles_main_header);
75 shared_ptr<Scanner> scanner_sptr;
76 ecat::ecat7::find_scanner(scanner_sptr, singles_main_header);
77 if (scanner_sptr->get_type() == Scanner::E966)
78 return true;
79
80 return false;
81 }
82
83protected:
85 virtual bool actual_can_read(const FileSignature& signature, std::istream& input) const
86 {
87 warning("can_read for ECAT966 listmode data with istream not implemented %s:%d. Sorry", __FILE__, __LINE__);
88 return false;
89
90 if (strncmp(signature.get_signature(), "MATRIX", 6) != 0)
91 return false;
92
93 // TODO
94 // return (is_ECAT7_image_file(filename))
95 return true;
96 }
97
98public:
99 virtual unique_ptr<data_type> read_from_file(std::istream& input) const
100 {
101 // cannot do this as need both .sgl and .lm
102 error("read_from_file for ECAT966 listmode data with istream not implemented %s:%d. Sorry", __FILE__, __LINE__);
103 return unique_ptr<data_type>();
104 }
105
106
109 virtual unique_ptr<data_type> read_from_file(const std::string& filename) const
110 {
111 // filename points to the .sgl file, but we need the prefix
112 std::string::size_type pos = find_pos_of_extension(filename);
113 // also remove _1 at the end (if present)
114 if (pos != std::string::npos && pos > 2 && filename.substr(pos - 2, 2) == "_1")
115 {
116 pos -= 2;
117 }
118 const std::string filename_prefix = filename.substr(0, pos);
119 info("Reading ECAT listmode file with prefix " + filename_prefix);
120
121 return unique_ptr<data_type>(new ecat::ecat7::CListModeDataECAT<ecat::ecat7::CListRecordECAT966>(filename_prefix));
122 }
123};
124
125END_NAMESPACE_ECAT
126END_NAMESPACE_ECAT7
127END_NAMESPACE_STIR
128
129#endif
Declaration of class stir::CListModeDataECAT.
Classes for listmode events for the ECAT 966 (aka Exact 3d)
Declaration of class stir::InputFileFormat.
A class to read/store the file signature.
Definition FileSignature.h:35
const char * get_signature() const
get access to the signature
Definition FileSignature.h:52
Base-class for file-formats for reading.
Definition InputFileFormat.h:40
A class that reads the listmode data for ECAT scanners.
Definition CListModeDataECAT.h:49
Class for reading list mode data from the ECAT 966 scanner.
Definition ECAT966ListmodeInputFileFormat.h:51
virtual unique_ptr< data_type > read_from_file(std::istream &input) const
read data from a stream
Definition ECAT966ListmodeInputFileFormat.h:99
virtual bool can_read(const FileSignature &signature, const std::string &singles_filename) const
Checks if it's an ECAT7 file by reading the main header and if the scanner is supported....
Definition ECAT966ListmodeInputFileFormat.h:62
virtual unique_ptr< data_type > read_from_file(const std::string &filename) const
read the data via the .sgl file
Definition ECAT966ListmodeInputFileFormat.h:109
virtual bool can_read(const FileSignature &signature, std::istream &input) const
Always return false as ECAT7 IO cannot read from stream.
Definition ECAT966ListmodeInputFileFormat.h:56
virtual bool actual_can_read(const FileSignature &signature, std::istream &input) const
Always return false as ECAT7 IO cannot read from stream.
Definition ECAT966ListmodeInputFileFormat.h:85
Declaration of stir::error()
Include for formatting function. Use standard library version if available (C++20 and newer)....
void find_scanner(shared_ptr< Scanner > &scanner_ptr, const Main_header &mhead)
determine scanner type from the main_header
Definition stir_ecat7.cxx:184
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition error.cxx:42
void warning(const char *const s,...)
Print warning with format string a la printf.
Definition warning.cxx:41
void info(const STRING &string, const int verbosity_level=1)
Use this function for writing informational messages.
Definition info.h:51
Declaration of stir::info()
string::size_type find_pos_of_extension(const string &file_in_directory_name)
find the position of the '.' of the extension
Definition utilities.cxx:185
Declaration of routines which convert CTI things into our building blocks and vice versa.
This file declares various utility functions.