STIR  6.2.0
ECAT962ListmodeInputFileFormat.h
Go to the documentation of this file.
1 //
2 //
3 #ifndef __stir_IO_ECAT962ListmodeInputFileFormat_h__
4 #define __stir_IO_ECAT962ListmodeInputFileFormat_h__
5 /*
6  Copyright (C) 2006- 2013, Hammersmith Imanet Ltd
7  This file is part of STIR.
8  SPDX-License-Identifier: Apache-2.0
9 
10  See STIR/LICENSE.txt for details
11 */
24 
25 #include "stir/error.h"
26 #include "stir/utilities.h"
27 #include <string>
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"
34 START_NAMESPACE_STIR
35 START_NAMESPACE_ECAT
36 START_NAMESPACE_ECAT7
37 
39 
42 class ECAT962ListmodeInputFileFormat : public InputFileFormat<ListModeData>
43 {
44 public:
45  virtual const std::string get_name() const { return "ECAT962"; }
46 
47  virtual bool can_read(const FileSignature& signature, std::istream& input) const
48  {
49  return this->actual_can_read(signature, input);
50  }
51  virtual bool can_read(const FileSignature& signature, const std::string& listmode_filename_prefix) const
52  {
53  const std::string singles_filename = listmode_filename_prefix + "_1.sgl";
54  std::ifstream singles_file(singles_filename.c_str(), std::ios::binary);
55  char buffer[sizeof(Main_header)];
56  Main_header singles_main_header;
57  singles_file.read(buffer, sizeof(singles_main_header));
58  if (!singles_file)
59  return false;
60  unmap_main_header(buffer, &singles_main_header);
61  shared_ptr<Scanner> scanner_sptr;
62  ecat::ecat7::find_scanner(scanner_sptr, singles_main_header);
63  if (scanner_sptr->get_type() == Scanner::E962)
64  return false;
65 
66  return true;
67  }
68 
69 protected:
70  virtual bool actual_can_read(const FileSignature& signature, std::istream& input) const
71  {
72  warning("can_read for ECAT962 listmode data with istream not implemented %s:%d. Sorry", __FILE__, __LINE__);
73  return false;
74 
75  if (strncmp(signature.get_signature(), "MATRIX", 6) != 0)
76  return false;
77 
78  // TODO
79  // return (is_ECAT7_image_file(filename))
80  return true;
81  }
82 
83 public:
84  virtual unique_ptr<data_type> read_from_file(std::istream& input) const
85  {
86  // cannot do this as need both .sgl and .lm
87  error("read_from_file for ECAT962 listmode data with istream not implemented %s:%d. Sorry", __FILE__, __LINE__);
88  return unique_ptr<data_type>();
89  }
90  virtual unique_ptr<data_type> read_from_file(const std::string& filename) const
91  {
92  return unique_ptr<data_type>(new ecat::ecat7::CListModeDataECAT<ecat::ecat7::CListRecordECAT962>(filename));
93  }
94 };
95 
96 END_NAMESPACE_ECAT
97 END_NAMESPACE_ECAT7
98 END_NAMESPACE_STIR
99 
100 #endif
Classes for listmode events for the ECAT 962 (aka Exact HR+)
virtual unique_ptr< data_type > read_from_file(std::istream &input) const
read data from a stream
Definition: ECAT962ListmodeInputFileFormat.h:84
Class for reading list mode data from the ECAT 962 scanner.
Definition: ECAT962ListmodeInputFileFormat.h:42
A class to read/store the file signature.
Definition: FileSignature.h:34
Declaration of class stir::CListModeDataECAT.
This file declares various utility functions.
Declaration of class stir::InputFileFormat.
Declaration of routines which convert CTI things into our building blocks and vice versa...
A class that reads the listmode data for ECAT scanners.
Definition: CListModeDataECAT.h:48
Declaration of stir::error()
const char * get_signature() const
get access to the signature
Definition: FileSignature.h:52
Base-class for file-formats for reading.
Definition: InputFileFormat.h:39
void warning(const char *const s,...)
Print warning with format string a la printf.
Definition: warning.cxx:41
virtual unique_ptr< data_type > read_from_file(const std::string &filename) const
read data from a filename
Definition: ECAT962ListmodeInputFileFormat.h:90
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition: error.cxx:42
void find_scanner(shared_ptr< Scanner > &scanner_ptr, const Main_header &mhead)
determine scanner type from the main_header
Definition: stir_ecat7.cxx:184