CASToR  2.0
Tomographic Reconstruction (PET/SPECT/CT)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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-2018 all CASToR contributors listed below:
18 
19  --> current contributors: Thibaut MERLIN, Simon STUTE, Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Mael MILLARDET
20  --> past contributors: Valentin VIELZEUF
21 
22 This is CASToR version 2.0.
23 */
24 
31 #ifndef VDATAFILE_HH
32 #define VDATAFILE_HH 1
33 
34 #include "gVariables.hh"
35 #include "vEvent.hh"
36 #include "iEventPET.hh"
37 #include "iEventListPET.hh"
38 #include "iEventHistoPET.hh"
39 #include "iEventSPECT.hh"
40 #include "iEventCT.hh"
41 #include "iEventNorm.hh"
42 #include "sOutputManager.hh"
43 #include "sScannerManager.hh"
45 #include "oMemoryMapped.hh"
46 
55 #define MODE_UNKNOWN -1
56 
57 #define MODE_LIST 0
58 
59 #define MODE_HISTOGRAM 1
60 
61 #define MODE_NORMALIZATION 2
62 
72 #define TYPE_UNKNOWN -1
73 
74 #define TYPE_PET 0
75 
76 #define TYPE_SPECT 1
77 
78 #define TYPE_CT 2
79 
89 #define SPEC_UNKNOWN -1
90 
91 #define SPEC_EMISSION 0
92 
93 #define SPEC_TRANSMISSION 1
94 
104 {
105  // -------------------------------------------------------------------
106  // Constructor & Destructor
107  public:
112  vDataFile ();
116  virtual ~vDataFile();
117 
118  // -------------------------------------------------------------------
119  // Public member functions
120  public:
130  int ReadInfoInHeader(bool a_affectQuantificationFlag = true);
137  int SetParametersFrom(vDataFile* ap_DataFile);
144  int CheckParameters();
150  int InitializeMappedFile();
157  virtual int ComputeSizeEvent() = 0;
165  virtual int PrepareDataFile() = 0;
173  int OpenFileForWriting(string a_suffix="");
180  int CloseFile();
187  virtual int WriteHeader() = 0;
196  virtual int WriteEvent(vEvent* ap_Event, int a_th=0) = 0;
204  vEvent* GetEvent(int64_t a_eventIndex, int a_th = 0);
213  virtual vEvent* GetEventSpecific(char* ap_buffer, int a_th) = 0;
222  void GetEventIndexStartAndStop(int64_t* ap_indexStart, int64_t* ap_indexStop, int a_subsetNum = 0, int a_NbSubsets = 1);
237  void Describe();
242  virtual void DescribeSpecific() = 0;
243 
244  // -------------------------------------------------------------------
245  // Functions dedicated to analytical projections
246  public:
253  virtual int PROJ_InitFile() = 0;
261  virtual int PROJ_GetScannerSpecificParameters() = 0;
268  int PROJ_WriteData();
285  vEvent* PROJ_GenerateEvent(int idx_elt1, int idx_elt2, int a_th);
286 
287  // -------------------------------------------------------------------
288  // Public Get & Set FUNCTIONS
289  public:
294  inline int GetBedIndex()
295  {return m_bedIndex;}
300  inline int GetDataMode()
301  {return m_dataMode;}
306  string GetDataModeToString();
311  inline int GetDataType()
312  {return m_dataType;}
317  string GetDataTypeToString();
322  inline int GetDataSpec()
323  {return m_dataSpec;}
328  string GetDataSpecToString();
333  int64_t GetSize()
334  {return m_nbEvents;}
339  int64_t GetEventSize() {return m_sizeEvent;}
344  inline string GetHeaderDataFileName()
345  {return m_headerFileName;};
350  inline string GetDataFileName()
351  {return m_dataFileName;};
356  inline int64_t GetStartTime()
357  {return m_startTimeInSec;};
362  inline int64_t GetDuration()
363  {return m_durationInSec;};
369  {return m_calibrationFactor;}
375  {return mp_POIResolution;}
380  inline bool* GetPOIDirectionFlag()
381  {return mp_POIDirectionFlag;}
386  inline bool GetPOIInfoFlag()
387  {return m_POIInfoFlag;}
392  inline bool GetIgnorePOIFlag()
393  {return m_ignorePOIFlag;}
400  virtual int GetMaxRingDiff();
406  inline void SetDataMode(int a_dataMode)
407  {m_dataMode = a_dataMode;}
413  inline void SetDataType(int a_dataType)
414  {m_dataType = a_dataType;}
420  inline void SetBedIndex(int a_bedIndex)
421  {m_bedIndex = a_bedIndex;}
426  inline bool GetBedPositionFlag()
427  {return m_bedPositionFlag;}
433  {return m_relativeBedPosition;}
439  inline void SetVerbose(int a_verboseLevel)
440  {m_verbose = a_verboseLevel;}
446  inline int GetVerbose()
447  {return m_verbose;}
453  inline void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification* ap_ImageDimensionsAndQuantification)
454  {mp_ID = ap_ImageDimensionsAndQuantification;}
461  inline void SetPOIResolution(FLTNB ap_value[3])
462  {for (int i=0 ; i<3 ; i++) mp_POIResolution[i] = ap_value[i];}
468  inline void SetIgnorePOIFlag(bool a_ignorePOIFlag)
469  {m_ignorePOIFlag = a_ignorePOIFlag;}
476  inline void SetHeaderDataFileName(const string& a_headerFileName)
477  {m_headerFileName = a_headerFileName;}
484  inline void SetBinaryDataFileName(const string& a_dataFileName)
485  {m_dataFileName = a_dataFileName;}
492  inline void SetCalibrationFactor(FLTNB a_value)
493  {m_calibrationFactor = a_value;}
500  inline void SetNbEvents(int64_t a_value)
501  {m_nbEvents = a_value;}
508  inline void SetStartTime(FLTNB a_value)
509  {m_startTimeInSec = a_value;}
516  inline void SetDuration(FLTNB a_value)
517  {m_durationInSec = a_value;}
522  inline string GetScannerName()
523  {return m_scannerName;}
524 
525  virtual int Shuffle( int64_t );
526 
527  // -------------------------------------------------------------------
528  // Private member functions
529  private:
536  virtual int SetSpecificParametersFrom(vDataFile* ap_DataFile) = 0;
543  virtual int CheckSpecificParameters() = 0;
550  virtual int CheckFileSizeConsistency() = 0;
560  virtual int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag = true) = 0;
568  virtual int CheckSpecificConsistencyWithAnotherDataFile(vDataFile* ap_DataFile) = 0;
569 
570  // -------------------------------------------------------------------
571  // Data members
572  protected:
574  int m_verbose;
576  // Variables related to the acquisition
578  string m_dataFileName;
579  int64_t m_nbEvents;
589  string m_scannerName;
591  // POI: Position Of Interaction
597  // Members for I/O actions
598  int64_t m_sizeEvent;
599  fstream** m2p_dataFile;
601  int64_t m_mpi1stEvent;
602  int64_t m_mpiLastEvent;
603  int64_t m_mpiNbEvents;
606 };
607 
608 #endif
void SetDataMode(int a_dataMode)
set the data mode
Definition: vDataFile.hh:406
int64_t GetEventSize()
Definition: vDataFile.hh:339
void SetIgnorePOIFlag(bool a_ignorePOIFlag)
Set a boolean that that if we ignore POI information or not.
Definition: vDataFile.hh:468
This class is designed to be a mother virtual class for DataFile.
Definition: vDataFile.hh:103
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:671
Declaration of class oImageDimensionsAndQuantification.
int64_t m_sizeEvent
Definition: vDataFile.hh:598
bool mp_POIDirectionFlag[3]
Definition: vDataFile.hh:594
string m_dataFileName
Definition: vDataFile.hh:578
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 'ap_buffer...
#define FLTNB
Definition: gVariables.hh:81
int CheckParameters()
Check the initialization of member variables Call the CheckSpecificParameters() function implemente...
Definition: vDataFile.cc:315
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:368
bool GetPOIInfoFlag()
Definition: vDataFile.hh:386
virtual int CheckFileSizeConsistency()=0
int SetParametersFrom(vDataFile *ap_DataFile)
Initialize all parameters from the provided datafile.
Definition: vDataFile.cc:275
oMemoryMapped * mp_MappedFile
Definition: vDataFile.hh:604
int ReadInfoInHeader(bool a_affectQuantificationFlag=true)
Read and check general information from the header datafile Call the ReadSpecificInformationInHeade...
Definition: vDataFile.cc:110
FLTNB m_durationInSec
Definition: vDataFile.hh:584
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:439
virtual int CheckSpecificConsistencyWithAnotherDataFile(vDataFile *ap_DataFile)=0
Check consistency between 'this' and the provided datafile, for specific characteristics.
int64_t GetSize()
Definition: vDataFile.hh:333
string m_headerFileName
Definition: vDataFile.hh:577
void SetDuration(FLTNB a_value)
Definition: vDataFile.hh:516
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 'this' and the provided datafile as two bed positions.
Definition: vDataFile.cc:386
string GetDataSpecToString()
Definition: vDataFile.cc:872
int m_dataMode
Definition: vDataFile.hh:580
virtual ~vDataFile()
vDataFile destructor.
Definition: vDataFile.cc:85
virtual int GetMaxRingDiff()
Return an error by default. This function is surcharged by the PET (and CT) scanner daughter class...
Definition: vDataFile.cc:702
int m_dataSpec
Definition: vDataFile.hh:582
FLTNB m_startTimeInSec
Definition: vDataFile.hh:583
int64_t m_mpi1stEvent
Definition: vDataFile.hh:601
int InitializeMappedFile()
Check the datafile existency, map it to memory and get the raw char* pointer. .
Definition: vDataFile.cc:462
Declaration of class iEventSPECT.
void SetPOIResolution(FLTNB ap_value[3])
initialize the POI resolution (for list-mode)
Definition: vDataFile.hh:461
Declaration of class iEventHistoPET.
int PROJ_WriteData()
Write/Merge chunk of data in a general data file.
Definition: vDataFile.cc:715
vEvent * GetEvent(int64_t a_eventIndex, int a_th=0)
Definition: vDataFile.cc:598
string GetHeaderDataFileName()
Definition: vDataFile.hh:344
int CloseFile()
Close as many binary file stream for writing.
Definition: vDataFile.cc:578
int64_t m_mpiLastEvent
Definition: vDataFile.hh:602
bool GetIgnorePOIFlag()
Definition: vDataFile.hh:392
void SetBinaryDataFileName(const string &a_dataFileName)
set the data binary file name
Definition: vDataFile.hh:484
bool m_ignorePOIFlag
Definition: vDataFile.hh:593
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:508
bool * GetPOIDirectionFlag()
Definition: vDataFile.hh:380
char * mp_mappedMemory
Definition: vDataFile.hh:605
vDataFile()
vDataFile constructor.
Definition: vDataFile.cc:39
void SetDataType(int a_dataType)
set the data type
Definition: vDataFile.hh:413
void SetCalibrationFactor(FLTNB a_value)
initialize the global calibration factor with a FLTNB value
Definition: vDataFile.hh:492
int m_dataType
Definition: vDataFile.hh:581
bool GetBedPositionFlag()
Definition: vDataFile.hh:426
int64_t m_nbEvents
Definition: vDataFile.hh:579
oImageDimensionsAndQuantification * mp_ID
Definition: vDataFile.hh:573
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:599
FLTNB m_relativeBedPosition
Definition: vDataFile.hh:587
FLTNB * GetPOIResolution()
Definition: vDataFile.hh:374
int GetDataType()
Definition: vDataFile.hh:311
int GetBedIndex()
Definition: vDataFile.hh:294
void SetHeaderDataFileName(const string &a_headerFileName)
set the data header file name
Definition: vDataFile.hh:476
int OpenFileForWriting(string a_suffix="")
Open a binary file stream for writing, with eventually the suffix appended to the file name...
Definition: vDataFile.cc:537
string GetScannerName()
Definition: vDataFile.hh:522
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:824
int m_bedIndex
Definition: vDataFile.hh:586
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:500
FLTNB mp_POIResolution[3]
Definition: vDataFile.hh:595
Implementation of file to memory mapping.
bool m_bedPositionFlag
Definition: vDataFile.hh:588
int GetDataSpec()
Definition: vDataFile.hh:322
Declaration of class iEventListPET.
void SetBedIndex(int a_bedIndex)
set the bed index corresponding to this data file
Definition: vDataFile.hh:420
Declaration of class sOutputManager.
Mother class for the Event objects.
Definition: vEvent.hh:43
Declaration of class iEventPET.
int GetDataMode()
Definition: vDataFile.hh:300
vEvent ** m2p_BufferEvent
Definition: vDataFile.hh:600
FLTNB GetRelativeBedPosition()
Definition: vDataFile.hh:432
string GetDataFileName()
Definition: vDataFile.hh:350
bool m_POIInfoFlag
Definition: vDataFile.hh:592
void Describe()
A function used to describe the generic parts of the datafile.
Definition: vDataFile.cc:510
This class is designed to manage all dimensions and quantification related stuff. ...
string GetDataTypeToString()
Definition: vDataFile.cc:840
int64_t m_mpiNbEvents
Definition: vDataFile.hh:603
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:589
Portable read-only memory mapping (Windows and Linux)
FLTNB m_calibrationFactor
Definition: vDataFile.hh:585
int PROJ_DeleteTmpDataFile()
Delete temporary datafile used for multithreaded output writing if needed.
Definition: vDataFile.cc:786
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:446
virtual int Shuffle(int64_t)
!!!\ This function has been modified to be used specifically with a
Definition: vDataFile.cc:623
void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification *ap_ImageDimensionsAndQuantification)
set the pointer to the oImageDimensionsAndQuantification object
Definition: vDataFile.hh:453
int64_t GetDuration()
Definition: vDataFile.hh:362
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:574
string GetDataModeToString()
Definition: vDataFile.cc:856
Declaration of class iEventCT.
int64_t GetStartTime()
Definition: vDataFile.hh:356