STIR  6.2.0
PENNListmodeInputFileFormat.h
1 /*
2 /*
3  * Copyright (C) 2020-2022 University of Pennsylvania
4  This file is part of STIR.
5 
6  SPDX-License-Identifier: Apache-2.0
7 
8  See STIR/LICENSE.txt for details
9 */
10 #ifndef __stir_IO_PENNListmodeInputFileFormat_h__
11 #define __stir_IO_PENNListmodeInputFileFormat_h__
12 
15 #include "stir/error.h"
16 #include "stir/utilities.h"
17 #include <string>
18 
19 START_NAMESPACE_STIR
20 
25 class PENNListmodeInputFileFormat : public InputFileFormat<ListModeData>
26 {
27 public:
28  virtual const std::string get_name() const { return "PENN"; }
29 
30 protected:
31  virtual bool actual_can_read(const FileSignature& signature, std::istream& input) const
32  {
33  return this->is_penn_signature(signature.get_signature());
34  }
35 
36  bool is_penn_signature(const char* const signature) const
37  {
38  // checking for txt file
39  const char* pos_of_colon = strchr(signature, ':');
40  if (pos_of_colon == NULL)
41  return false;
42  std::string keyword(signature, pos_of_colon - signature);
43  return (standardise_interfile_keyword(keyword) == standardise_interfile_keyword("PENN header"));
44  }
45 
46 public:
47  virtual unique_ptr<data_type> read_from_file(std::istream& input) const
48  {
49  error("read_from_file for PENN listmode data with istream not implemented %s:%s. Sorry", __FILE__, __LINE__);
50  return unique_ptr<data_type>();
51  }
52 
53  virtual unique_ptr<data_type> read_from_file(const std::string& filename) const
54  {
55  return unique_ptr<data_type>(new CListModeDataPENN(filename));
56  }
57 };
58 
59 END_NAMESPACE_STIR
60 
61 #endif
A class to read/store the file signature.
Definition: FileSignature.h:34
This file declares various utility functions.
Declaration of class stir::InputFileFormat.
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
Base class for PENN listmode file format support.
Definition: PENNListmodeInputFileFormat.h:25
virtual unique_ptr< data_type > read_from_file(std::istream &input) const
read data from a stream
Definition: PENNListmodeInputFileFormat.h:47
string standardise_interfile_keyword(const string &keyword)
Put a (Interfile) keyword into a standard form.
Definition: interfile_keyword_functions.cxx:28
virtual unique_ptr< data_type > read_from_file(const std::string &filename) const
read data from a filename
Definition: PENNListmodeInputFileFormat.h:53
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition: error.cxx:42
Declaration of class stir::CListModeDataPENN.
Base class for listmode data for PENNPET Explorer scanner.
Definition: CListModeDataPENN.h:27