CASToR  3.0
Tomographic Reconstruction (PET/SPECT/CT)
vDataFile.hh
Go to the documentation of this file.
1 /*
2 This file is part of CASToR.
3 
4  CASToR is free software: you can redistribute it and/or modify it under the
5  terms of the GNU General Public License as published by the Free Software
6  Foundation, either version 3 of the License, or (at your option) any later
7  version.
8 
9  CASToR is distributed in the hope that it will be useful, but WITHOUT ANY
10  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  details.
13 
14  You should have received a copy of the GNU General Public License along with
15  CASToR (in file GNU_GPL.TXT). If not, see <http://www.gnu.org/licenses/>.
16 
17 Copyright 2017-2019 all CASToR contributors listed below:
18 
19  --> Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Thibaut MERLIN, Mael MILLARDET, Simon STUTE, Valentin VIELZEUF
20 
21 This is CASToR version 3.0.
22 */
23 
30 #ifndef VDATAFILE_HH
31 #define VDATAFILE_HH 1
32 
33 #include "gVariables.hh"
34 #include "vEvent.hh"
35 #include "iEventPET.hh"
36 #include "iEventListPET.hh"
37 #include "iEventHistoPET.hh"
38 #include "iEventSPECT.hh"
39 #include "iEventCT.hh"
40 #include "iEventNorm.hh"
41 #include "sOutputManager.hh"
42 #include "sScannerManager.hh"
44 #include "oMemoryMapped.hh"
45 
54 #define MODE_UNKNOWN -1
55 
56 #define MODE_LIST 0
57 
58 #define MODE_HISTOGRAM 1
59 
60 #define MODE_NORMALIZATION 2
61 
71 #define TYPE_UNKNOWN -1
72 
73 #define TYPE_PET 0
74 
75 #define TYPE_SPECT 1
76 
77 #define TYPE_CT 2
78 
88 #define SPEC_UNKNOWN -1
89 
90 #define SPEC_EMISSION 0
91 
92 #define SPEC_TRANSMISSION 1
93 
103 {
104  // -------------------------------------------------------------------
105  // Constructor & Destructor
106  public:
111  vDataFile ();
115  virtual ~vDataFile();
116 
117  // -------------------------------------------------------------------
118  // Public member functions
119  public:
129  int ReadInfoInHeader(bool a_affectQuantificationFlag = true);
136  int SetParametersFrom(vDataFile* ap_DataFile);
143  int CheckParameters();
149  int InitializeMappedFile();
156  virtual int ComputeSizeEvent() = 0;
164  virtual int PrepareDataFile() = 0;
172  int OpenFileForWriting(string a_suffix="");
179  int CloseFile();
186  virtual int WriteHeader() = 0;
195  virtual int WriteEvent(vEvent* ap_Event, int a_th=0) = 0;
203  vEvent* GetEvent(int64_t a_eventIndex, int a_th = 0);
212  virtual vEvent* GetEventSpecific(char* ap_buffer, int a_th) = 0;
221  void GetEventIndexStartAndStop(int64_t* ap_indexStart, int64_t* ap_indexStop, int a_subsetNum = 0, int a_NbSubsets = 1);
236  void Describe();
241  virtual void DescribeSpecific() = 0;
242 
243  // -------------------------------------------------------------------
244  // Functions dedicated to analytical projections
245  public:
252  virtual int PROJ_InitFile() = 0;
260  virtual int PROJ_GetScannerSpecificParameters() = 0;
267  int PROJ_WriteData();
284  vEvent* PROJ_GenerateEvent(int idx_elt1, int idx_elt2, int a_th);
285 
286  // -------------------------------------------------------------------
287  // Public Get & Set FUNCTIONS
288  public:
293  inline int GetBedIndex()
294  {return m_bedIndex;}
299  inline int GetDataMode()
300  {return m_dataMode;}
305  string GetDataModeToString();
310  inline int GetDataType()
311  {return m_dataType;}
316  string GetDataTypeToString();
321  inline int GetDataSpec()
322  {return m_dataSpec;}
327  string GetDataSpecToString();
332  int64_t GetSize()
333  {return m_nbEvents;}
338  int64_t GetEventSize() {return m_sizeEvent;}
343  inline string GetHeaderDataFileName()
344  {return m_headerFileName;};
349  inline string GetDataFileName()
350  {return m_dataFileName;};
355  inline int64_t GetStartTime()
356  {return m_startTimeInSec;};
361  inline int64_t GetDuration()
362  {return m_durationInSec;};
368  {return m_calibrationFactor;}
374  {return mp_POIResolution;}
379  inline bool* GetPOIDirectionFlag()
380  {return mp_POIDirectionFlag;}
385  inline bool GetPOIInfoFlag()
386  {return m_POIInfoFlag;}
391  inline bool GetIgnorePOIFlag()
392  {return m_ignorePOIFlag;}
399  virtual int GetMaxRingDiff();
405  inline void SetDataMode(int a_dataMode)
406  {m_dataMode = a_dataMode;}
412  inline void SetDataType(int a_dataType)
413  {m_dataType = a_dataType;}
419  inline void SetBedIndex(int a_bedIndex)
420  {m_bedIndex = a_bedIndex;}
425  inline bool GetBedPositionFlag()
426  {return m_bedPositionFlag;}
432  {return m_relativeBedPosition;}
438  inline void SetVerbose(int a_verboseLevel)
439  {m_verbose = a_verboseLevel;}
445  inline int GetVerbose()
446  {return m_verbose;}
452  inline void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification* ap_ImageDimensionsAndQuantification)
453  {mp_ID = ap_ImageDimensionsAndQuantification;}
460  inline void SetPOIResolution(FLTNB ap_value[3])
461  {for (int i=0 ; i<3 ; i++) mp_POIResolution[i] = ap_value[i];}
467  inline void SetIgnorePOIFlag(bool a_ignorePOIFlag)
468  {m_ignorePOIFlag = a_ignorePOIFlag;}
475  inline void SetHeaderDataFileName(const string& a_headerFileName)
476  {m_headerFileName = a_headerFileName;}
483  inline void SetBinaryDataFileName(const string& a_dataFileName)
484  {m_dataFileName = a_dataFileName;}
491  inline void SetCalibrationFactor(FLTNB a_value)
492  {m_calibrationFactor = a_value;}
499  inline void SetNbEvents(int64_t a_value)
500  {m_nbEvents = a_value;}
507  inline void SetStartTime(FLTNB a_value)
508  {m_startTimeInSec = a_value;}
515  inline void SetDuration(FLTNB a_value)
516  {m_durationInSec = a_value;}
521  inline string GetScannerName()
522  {return m_scannerName;}
523 
524  virtual int Shuffle( int64_t );
525 
526  // -------------------------------------------------------------------
527  // Private member functions
528  private:
535  virtual int SetSpecificParametersFrom(vDataFile* ap_DataFile) = 0;
542  virtual int CheckSpecificParameters() = 0;
549  virtual int CheckFileSizeConsistency() = 0;
559  virtual int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag = true) = 0;
567  virtual int CheckSpecificConsistencyWithAnotherDataFile(vDataFile* ap_DataFile) = 0;
568 
569  // -------------------------------------------------------------------
570  // Data members
571  protected:
573  int m_verbose;
575  // Variables related to the acquisition
577  string m_dataFileName;
578  int64_t m_nbEvents;
588  string m_scannerName;
590  // POI: Position Of Interaction
596  // Members for I/O actions
597  int64_t m_sizeEvent;
598  fstream** m2p_dataFile;
600  int64_t m_mpi1stEvent;
601  int64_t m_mpiLastEvent;
602  int64_t m_mpiNbEvents;
605 };
606 
607 #endif
void SetDataMode(int a_dataMode)
set the data mode
Definition: vDataFile.hh:405
int64_t GetEventSize()
Definition: vDataFile.hh:338
void SetIgnorePOIFlag(bool a_ignorePOIFlag)
Set a boolean that that if we ignore POI information or not.
Definition: vDataFile.hh:467
This class is designed to be a mother virtual class for DataFile.
Definition: vDataFile.hh:102
This header file is mainly used to declare some macro definitions and all includes needed from the st...
void GetEventIndexStartAndStop(int64_t *ap_indexStart, int64_t *ap_indexStop, int a_subsetNum=0, int a_NbSubsets=1)
Compute the index start and stop of the events loop with respect to the current subset and MPI size a...
Definition: vDataFile.cc:678
Declaration of class oImageDimensionsAndQuantification.
int64_t m_sizeEvent
Definition: vDataFile.hh:597
bool mp_POIDirectionFlag[3]
Definition: vDataFile.hh:593
string m_dataFileName
Definition: vDataFile.hh:577
virtual vEvent * GetEventSpecific(char *ap_buffer, int a_th)=0
This function is implemented in child classes Read an event from the position pointed by &#39;ap_buffer...
#define FLTNB
Definition: gVariables.hh:81
int CheckParameters()
Check the initialization of member variables Call the CheckSpecificParameters() function implemente...
Definition: vDataFile.cc:322
virtual int WriteHeader()=0
This function is implemented in child classes. Generate a header file according to the data output ...
FLTNB GetCalibrationFactor()
Definition: vDataFile.hh:367
bool GetPOIInfoFlag()
Definition: vDataFile.hh:385
virtual int CheckFileSizeConsistency()=0
int SetParametersFrom(vDataFile *ap_DataFile)
Initialize all parameters from the provided datafile.
Definition: vDataFile.cc:282
oMemoryMapped * mp_MappedFile
Definition: vDataFile.hh:603
int ReadInfoInHeader(bool a_affectQuantificationFlag=true)
Read and check general information from the header datafile Call the ReadSpecificInformationInHeade...
Definition: vDataFile.cc:109
FLTNB m_durationInSec
Definition: vDataFile.hh:583
virtual int WriteEvent(vEvent *ap_Event, int a_th=0)=0
This function is implemented in child classes Write event according to the chosen type of data...
void SetVerbose(int a_verboseLevel)
set verbosity
Definition: vDataFile.hh:438
virtual int CheckSpecificConsistencyWithAnotherDataFile(vDataFile *ap_DataFile)=0
Check consistency between &#39;this&#39; and the provided datafile, for specific characteristics.
int64_t GetSize()
Definition: vDataFile.hh:332
string m_headerFileName
Definition: vDataFile.hh:576
void SetDuration(FLTNB a_value)
Definition: vDataFile.hh:515
virtual int ComputeSizeEvent()=0
This function is implemented in child classes Computation of the size of each event according to th...
int CheckConsistencyWithAnotherBedDataFile(vDataFile *ap_DataFile)
Check consistency between &#39;this&#39; and the provided datafile as two bed positions.
Definition: vDataFile.cc:393
string GetDataSpecToString()
Definition: vDataFile.cc:879
int m_dataMode
Definition: vDataFile.hh:579
virtual ~vDataFile()
vDataFile destructor.
Definition: vDataFile.cc:84
virtual int GetMaxRingDiff()
Return an error by default. This function is surcharged by the PET (and CT) scanner daughter class...
Definition: vDataFile.cc:709
int m_dataSpec
Definition: vDataFile.hh:581
FLTNB m_startTimeInSec
Definition: vDataFile.hh:582
int64_t m_mpi1stEvent
Definition: vDataFile.hh:600
int InitializeMappedFile()
Check the datafile existency, map it to memory and get the raw char* pointer. .
Definition: vDataFile.cc:469
Declaration of class iEventSPECT.
void SetPOIResolution(FLTNB ap_value[3])
initialize the POI resolution (for list-mode)
Definition: vDataFile.hh:460
Declaration of class iEventHistoPET.
int PROJ_WriteData()
Write/Merge chunk of data in a general data file.
Definition: vDataFile.cc:722
vEvent * GetEvent(int64_t a_eventIndex, int a_th=0)
Definition: vDataFile.cc:605
string GetHeaderDataFileName()
Definition: vDataFile.hh:343
int CloseFile()
Close as many binary file stream for writing.
Definition: vDataFile.cc:585
int64_t m_mpiLastEvent
Definition: vDataFile.hh:601
bool GetIgnorePOIFlag()
Definition: vDataFile.hh:391
void SetBinaryDataFileName(const string &a_dataFileName)
set the data binary file name
Definition: vDataFile.hh:483
bool m_ignorePOIFlag
Definition: vDataFile.hh:592
virtual int CheckSpecificParameters()=0
This function is implemented in child classes Check specific parameters of child classes...
void SetStartTime(FLTNB a_value)
Definition: vDataFile.hh:507
bool * GetPOIDirectionFlag()
Definition: vDataFile.hh:379
char * mp_mappedMemory
Definition: vDataFile.hh:604
vDataFile()
vDataFile constructor.
Definition: vDataFile.cc:38
void SetDataType(int a_dataType)
set the data type
Definition: vDataFile.hh:412
void SetCalibrationFactor(FLTNB a_value)
initialize the global calibration factor with a FLTNB value
Definition: vDataFile.hh:491
int m_dataType
Definition: vDataFile.hh:580
bool GetBedPositionFlag()
Definition: vDataFile.hh:425
int64_t m_nbEvents
Definition: vDataFile.hh:578
oImageDimensionsAndQuantification * mp_ID
Definition: vDataFile.hh:572
Declaration of class sScannerManager.
virtual int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag=true)=0
This function is implemented in child classes Read and check modality-specific information from the...
Declaration of class vEvent.
virtual int PrepareDataFile()=0
This function is implemented in child classes Store different kind of information inside arrays (da...
fstream ** m2p_dataFile
Definition: vDataFile.hh:598
FLTNB m_relativeBedPosition
Definition: vDataFile.hh:586
FLTNB * GetPOIResolution()
Definition: vDataFile.hh:373
int GetDataType()
Definition: vDataFile.hh:310
int GetBedIndex()
Definition: vDataFile.hh:293
void SetHeaderDataFileName(const string &a_headerFileName)
set the data header file name
Definition: vDataFile.hh:475
int OpenFileForWriting(string a_suffix="")
Open a binary file stream for writing, with eventually the suffix appended to the file name...
Definition: vDataFile.cc:544
string GetScannerName()
Definition: vDataFile.hh:521
vEvent * PROJ_GenerateEvent(int idx_elt1, int idx_elt2, int a_th)
Generate a standard event and set up its ID Used by the projection, list-mode sensitivity generatio...
Definition: vDataFile.cc:831
int m_bedIndex
Definition: vDataFile.hh:585
virtual void DescribeSpecific()=0
A pure virtual function used to describe the specific parts of the datafile.
void SetNbEvents(int64_t a_value)
initialize the number of events with a int64_t value
Definition: vDataFile.hh:499
FLTNB mp_POIResolution[3]
Definition: vDataFile.hh:594
Implementation of file to memory mapping.
bool m_bedPositionFlag
Definition: vDataFile.hh:587
int GetDataSpec()
Definition: vDataFile.hh:321
Declaration of class iEventListPET.
void SetBedIndex(int a_bedIndex)
set the bed index corresponding to this data file
Definition: vDataFile.hh:419
Declaration of class sOutputManager.
Mother class for the Event objects.
Definition: vEvent.hh:42
Declaration of class iEventPET.
int GetDataMode()
Definition: vDataFile.hh:299
vEvent ** m2p_BufferEvent
Definition: vDataFile.hh:599
FLTNB GetRelativeBedPosition()
Definition: vDataFile.hh:431
string GetDataFileName()
Definition: vDataFile.hh:349
bool m_POIInfoFlag
Definition: vDataFile.hh:591
void Describe()
A function used to describe the generic parts of the datafile.
Definition: vDataFile.cc:517
This class is designed to manage all dimensions and quantification related stuff. ...
string GetDataTypeToString()
Definition: vDataFile.cc:847
int64_t m_mpiNbEvents
Definition: vDataFile.hh:602
Declaration of class iEventNorm.
virtual int SetSpecificParametersFrom(vDataFile *ap_DataFile)=0
This function is implemented in child classes Initialize all specific parameters from the provided ...
string m_scannerName
Definition: vDataFile.hh:588
Portable read-only memory mapping (Windows and Linux)
FLTNB m_calibrationFactor
Definition: vDataFile.hh:584
int PROJ_DeleteTmpDataFile()
Delete temporary datafile used for multithreaded output writing if needed.
Definition: vDataFile.cc:793
virtual int PROJ_GetScannerSpecificParameters()=0
This function is implemented in child classes It is used to set several variables of the datafile w...
int GetVerbose()
Get the verbose level.
Definition: vDataFile.hh:445
virtual int Shuffle(int64_t)
!!!\ This function has been modified to be used specifically with a
Definition: vDataFile.cc:630
void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification *ap_ImageDimensionsAndQuantification)
set the pointer to the oImageDimensionsAndQuantification object
Definition: vDataFile.hh:452
int64_t GetDuration()
Definition: vDataFile.hh:361
virtual int PROJ_InitFile()=0
This function is implemented in child classes Initialize the fstream objets for output writing as w...
int m_verbose
Definition: vDataFile.hh:573
string GetDataModeToString()
Definition: vDataFile.cc:863
Declaration of class iEventCT.
int64_t GetStartTime()
Definition: vDataFile.hh:355