STIR  6.2.0
ROOTListmodeInputFileFormat.h
1 /*
2  Copyright (C) 2015-2016 University of Leeds
3  Copyright (C) 2016 UCL
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_ROOTListmodeInputFileFormat_h__
11 #define __stir_IO_ROOTListmodeInputFileFormat_h__
12 
16 #include "stir/error.h"
17 #include "stir/utilities.h"
18 #include <string>
19 
20 START_NAMESPACE_STIR
21 
27 class ROOTListmodeInputFileFormat : public InputFileFormat<ListModeData>
28 {
29 public:
30  const std::string get_name() const override { return "ROOT"; }
31 
32 protected:
33  bool actual_can_read(const FileSignature& signature, std::istream& input) const override
34  {
35  return this->is_root_signature(signature.get_signature());
36  }
37 
38  bool is_root_signature(const char* const signature) const
39  {
40  // checking for "interfile :"
41  const char* pos_of_colon = strchr(signature, ':');
42  if (pos_of_colon == NULL)
43  return false;
44  std::string keyword(signature, pos_of_colon - signature);
45  return (standardise_interfile_keyword(keyword) == standardise_interfile_keyword("ROOT header"));
46  }
47 
48 public:
49  unique_ptr<data_type> read_from_file(std::istream& input) const override
50  {
51  error("read_from_file for ROOT listmode data with istream not implemented %s:%s. Sorry", __FILE__, __LINE__);
52  return unique_ptr<data_type>();
53  }
54 
55  unique_ptr<data_type> read_from_file(const std::string& filename) const override
56  {
57  return unique_ptr<data_type>(new CListModeDataROOT(filename));
58  }
59 };
60 
61 END_NAMESPACE_STIR
62 
63 #endif
A class to read/store the file signature.
Definition: FileSignature.h:34
This file declares various utility functions.
Declaration of class stir::InputFileFormat.
unique_ptr< data_type > read_from_file(const std::string &filename) const override
read data from a filename
Definition: ROOTListmodeInputFileFormat.h:55
Declaration of class stir::CListModeDataROOT.
Declaration of stir::error()
unique_ptr< data_type > read_from_file(std::istream &input) const override
read data from a stream
Definition: ROOTListmodeInputFileFormat.h:49
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
The ROOTListmodeInputFileFormat class.
Definition: ROOTListmodeInputFileFormat.h:27
string standardise_interfile_keyword(const string &keyword)
Put a (Interfile) keyword into a standard form.
Definition: interfile_keyword_functions.cxx:28
Functions useful for manipulating Interfile keywords.
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition: error.cxx:42
class that reads ROOT files, generated by GATE, as listmode data.
Definition: CListModeDataROOT.h:106