31#ifndef __stir_IO_SAFIRCListmodeInputFileFormat_H__
32#define __stir_IO_SAFIRCListmodeInputFileFormat_H__
39#include "boost/algorithm/string.hpp"
79template <
class EventDataType>
80class SAFIRCListmodeInputFileFormat :
public InputFileFormat<ListModeData>,
public ParsingObject
83 SAFIRCListmodeInputFileFormat() {}
84 const std::string get_name()
const override {
return "SAFIR Coincidence Listmode File Format"; }
97 std::ifstream par_file(filename.c_str());
99 std::getline(par_file, key,
':');
101 if (key != std::string(
"clistmodedatasafir parameters"))
105 if (!actual_do_parsing(filename))
107 std::ifstream data_file(listmode_filename.c_str(), std::ios::binary);
108 char* buffer =
new char[32];
109 data_file.read(buffer, 32);
112 if (std::is_same<EventDataType, CListEventDataSAFIR>::value)
114 cr = (!strncmp(buffer,
"MUPET CListModeData\0", 20) || !strncmp(buffer,
"SAFIR CListModeData\0", 20));
116 else if (std::is_same<EventDataType, CListEventDataNeuroLF>::value)
118 cr = !strncmp(buffer,
"NeuroLF CListModeData\0", 20);
122 warning(
"SAFIRCListModeInputFileFormat was initialised with an unexpected template.");
127 warning(
"SAFIRCListModeInputFileFormat tried to read file " + listmode_filename
128 +
" but it seems to have the wrong signature.");
137 error(
"read_from_file for SAFIRCListmodeData with istream not implemented %s:%d. Sorry", __FILE__, __LINE__);
138 return unique_ptr<data_type>();
141 std::unique_ptr<data_type>
read_from_file(
const std::string& filename)
const override
143 info(
"SAFIRCListmodeInputFileFormat: read_from_file(" + std::string(filename) +
")");
144 actual_do_parsing(filename);
146 listmode_filename, crystal_map_filename, template_proj_data_filename, lor_randomization_sigma));
151 mutable std::string listmode_filename;
152 mutable std::string crystal_map_filename;
153 mutable std::string template_proj_data_filename;
154 mutable double lor_randomization_sigma;
156 bool actual_can_read(
const FileSignature& signature, std::istream& input)
const override
164 this->parser.add_start_key(
"CListModeDataSAFIR Parameters");
165 this->parser.add_key(
"listmode data filename", &listmode_filename);
166 this->parser.add_key(
"crystal map filename", &crystal_map_filename);
167 this->parser.add_key(
"template projection data filename", &template_proj_data_filename);
168 this->parser.add_key(
"LOR randomization (Gaussian) sigma", &lor_randomization_sigma);
169 this->parser.add_stop_key(
"END CListModeDataSAFIR Parameters");
175 crystal_map_filename =
"";
176 template_proj_data_filename =
"";
177 lor_randomization_sigma = 0.0;
180 bool actual_do_parsing(
const std::string& filename)
const
194 if (!file_exists(listmode_filename))
196 else if (!file_exists(template_proj_data_filename))
206 bool file_exists(
const std::string& filename)
208 std::ifstream infile(filename.c_str());
209 return infile.good();
Declaration of class stir::CListModeDataSAFIR.
Declaration of class stir::CListEventSAFIR and stir::CListRecordSAFIR with supporting classes.
Declaration of class stir::ParsingObject.
Class for reading SAFIR listmode data with variable geometry.
Definition CListModeDataSAFIR.h:61
Class for general SAFIR record, containing a union of data, time and raw record and providing access ...
Definition CListRecordSAFIR.h:228
A class to read/store the file signature.
Definition FileSignature.h:35
A base class for objects that want to be able to parse parameter files.
Definition ParsingObject.h:45
virtual void initialise_keymap()
Initialise all keywords.
Definition ParsingObject.cxx:52
virtual void set_defaults()
Set defaults before parsing.
Definition ParsingObject.cxx:48
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
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 standardise_interfile_keyword(const string &keyword)
Put a (Interfile) keyword into a standard form.
Definition interfile_keyword_functions.cxx:28
This file declares various utility functions.