CASToR  3.2
Tomographic Reconstruction (PET/SPECT/CT)
include/datafile/vDataFile.hh
Go to the documentation of this file.
1 
8 #ifndef VDATAFILE_HH
9 #define VDATAFILE_HH 1
10 
11 #include "gVariables.hh"
12 #include "vEvent.hh"
13 #include "iEventPET.hh"
14 #include "iEventListPET.hh"
15 #include "iEventHistoPET.hh"
16 #include "iEventSPECT.hh"
17 #include "iEventCT.hh"
18 #include "iEventNorm.hh"
19 #include "sOutputManager.hh"
20 #include "sScannerManager.hh"
21 #include "oImageDimensionsAndQuantification.hh"
22 #include "oMemoryMapped.hh"
23 #include "oInterfileIO.hh"
24 
33 #define MODE_UNKNOWN -1
34 
35 #define MODE_LIST 0
36 
37 #define MODE_HISTOGRAM 1
38 
39 #define MODE_NORMALIZATION 2
40 
50 #define TYPE_UNKNOWN -1
51 
52 #define TYPE_PET 0
53 
54 #define TYPE_SPECT 1
55 
56 #define TYPE_CT 2
57 
67 #define SPEC_UNKNOWN -1
68 
69 #define SPEC_EMISSION 0
70 
71 #define SPEC_TRANSMISSION 1
72 
81 class vDataFile
82 {
83  // -------------------------------------------------------------------
84  // Constructor & Destructor
85  public:
90  vDataFile ();
94  virtual ~vDataFile();
95 
96  // -------------------------------------------------------------------
97  // Public member functions
98  public:
108  int ReadInfoInHeader(bool a_affectQuantificationFlag = true);
115  int SetParametersFrom(vDataFile* ap_DataFile);
122  int CheckParameters();
128  int InitializeMappedFile();
136  int InitializeAdditionalData(const string& a_pathToAdditionalData);
144  FLTNB* GetNewAdditionalDataMatrix(INTNB a_nbDataPerEvent);
151  virtual int ComputeSizeEvent() = 0;
159  virtual int PrepareDataFile() = 0;
167  int OpenFileForWriting(string a_suffix="");
174  int CloseFile();
181  virtual int WriteHeader() = 0;
190  virtual int WriteEvent(vEvent* ap_Event, int a_th=0) = 0;
198  vEvent* GetEvent(int64_t a_eventIndex, int a_th = 0);
207  virtual vEvent* GetEventSpecific(char* ap_buffer, int a_th) = 0;
216  void GetEventIndexStartAndStop(int64_t* ap_indexStart, int64_t* ap_indexStop, int a_subsetNum = 0, int a_NbSubsets = 1);
231  void Describe();
236  virtual void DescribeSpecific() = 0;
237 
238  // -------------------------------------------------------------------
239  // Functions dedicated to analytical projections
240  public:
247  virtual int PROJ_InitFile() = 0;
255  virtual int PROJ_GetScannerSpecificParameters() = 0;
262  int PROJ_WriteData();
279  vEvent* PROJ_GenerateEvent(int idx_elt1, int idx_elt2, int a_th);
280 
281  // -------------------------------------------------------------------
282  // Public Get & Set FUNCTIONS
283  public:
288  inline int GetBedIndex()
289  {return m_bedIndex;}
294  inline int GetDataMode()
295  {return m_dataMode;}
300  string GetDataModeToString();
305  inline int GetDataType()
306  {return m_dataType;}
311  string GetDataTypeToString();
316  inline int GetDataSpec()
317  {return m_dataSpec;}
322  string GetDataSpecToString();
327  int64_t GetSize()
328  {return m_nbEvents;}
333  int64_t GetEventSize() {return m_sizeEvent;}
338  inline string GetHeaderDataFileName()
339  {return m_headerFileName;};
344  inline string GetDataFileName()
345  {return m_dataFileName;};
351  {return m_startTimeInSec;};
357  {return m_durationInSec;};
363  {return m_calibrationFactor;}
369  {return mp_POIResolution;}
374  inline bool* GetPOIDirectionFlag()
375  {return mp_POIDirectionFlag;}
380  inline bool GetPOIInfoFlag()
381  {return m_POIInfoFlag;}
386  inline bool GetIgnorePOIFlag()
387  {return m_ignorePOIFlag;}
394  virtual int GetMaxRingDiff();
400  inline void SetDataMode(int a_dataMode)
401  {m_dataMode = a_dataMode;}
407  inline void SetDataType(int a_dataType)
408  {m_dataType = a_dataType;}
414  inline void SetBedIndex(int a_bedIndex)
415  {m_bedIndex = a_bedIndex;}
420  inline bool GetBedPositionFlag()
421  {return m_bedPositionFlag;}
427  {return m_relativeBedPosition;}
433  inline void SetVerbose(int a_verboseLevel)
434  {m_verbose = a_verboseLevel;}
440  inline int GetVerbose()
441  {return m_verbose;}
447  inline void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification* ap_ImageDimensionsAndQuantification)
448  {mp_ID = ap_ImageDimensionsAndQuantification;}
455  inline void SetPOIResolution(FLTNB ap_value[3])
456  {for (int i=0 ; i<3 ; i++) mp_POIResolution[i] = ap_value[i];}
462  inline void SetIgnorePOIFlag(bool a_ignorePOIFlag)
463  {m_ignorePOIFlag = a_ignorePOIFlag;}
470  inline void SetHeaderDataFileName(const string& a_headerFileName)
471  {m_headerFileName = a_headerFileName;}
478  inline void SetBinaryDataFileName(const string& a_dataFileName)
479  {m_dataFileName = a_dataFileName;}
486  inline void SetCalibrationFactor(FLTNB a_value)
487  {m_calibrationFactor = a_value;}
493  inline int64_t GetNbEvents()
494  {return m_nbEvents;}
501  inline void SetNbEvents(int64_t a_value)
502  {m_nbEvents = a_value;}
509  inline void SetStartTime(FLTNB a_value)
510  {m_startTimeInSec = a_value;}
517  inline void SetDuration(FLTNB a_value)
518  {m_durationInSec = a_value;}
523  inline string GetScannerName()
524  {return m_scannerName;}
530  inline int GetNbAdditionalData()
531  {return m_nbAdditionalData;}
532 
533 
534  virtual int Shuffle( int64_t );
535 
536  // -------------------------------------------------------------------
537  // Private member functions
538  private:
545  virtual int SetSpecificParametersFrom(vDataFile* ap_DataFile) = 0;
552  virtual int CheckSpecificParameters() = 0;
559  virtual int CheckFileSizeConsistency() = 0;
569  virtual int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag = true) = 0;
577  virtual int CheckSpecificConsistencyWithAnotherDataFile(vDataFile* ap_DataFile) = 0;
578 
579  // -------------------------------------------------------------------
580  // Data members
581  public:
582  // Additional data
586  protected:
588  int m_verbose;
590  // Variables related to the acquisition
591  string m_headerFileName;
592  string m_dataFileName;
593  int64_t m_nbEvents;
594  int m_dataMode;
595  int m_dataType;
596  int m_dataSpec;
600  int m_bedIndex;
602  bool m_bedPositionFlag;
603  string m_scannerName;
605  // POI: Position Of Interaction
606  bool m_POIInfoFlag;
607  bool m_ignorePOIFlag;
608  bool mp_POIDirectionFlag[3];
611  // Members for I/O actions
612  int64_t m_sizeEvent;
613  fstream** m2p_dataFile;
615  int64_t m_mpi1stEvent;
616  int64_t m_mpiLastEvent;
617  int64_t m_mpiNbEvents;
619  char* mp_mappedMemory;
621  // Additional data
626  // Custom data info
630 };
631 
632 #endif
void SetDataMode(int a_dataMode)
void SetIgnorePOIFlag(bool a_ignorePOIFlag)
This class is designed to be a mother virtual class for DataFile.
void GetEventIndexStartAndStop(int64_t *ap_indexStart, int64_t *ap_indexStop, int a_subsetNum=0, int a_NbSubsets=1)
int64_t GetNbEvents()
Get the total number of events in the datafile.
Declaration of class iEventListPET.
int CheckParameters()
Check the initialization of member variables Call the CheckSpecificParameters() function implemente...
virtual int WriteHeader()=0
This function is implemented in child classes. Generate a header file according to the data output ...
virtual int CheckFileSizeConsistency()=0
int SetParametersFrom(vDataFile *ap_DataFile)
virtual int WriteEvent(vEvent *ap_Event, int a_th=0)=0
int ReadInfoInHeader(bool a_affectQuantificationFlag=true)
void SetVerbose(int a_verboseLevel)
Declaration of class iEventNorm.
virtual int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag=true)=0
void SetDuration(FLTNB a_value)
Declaration of class iEventHistoPET.
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)
virtual ~vDataFile()
vDataFile destructor.
virtual int GetMaxRingDiff()
Return an error by default. This function is surcharged by the PET (and CT) scanner daughter class...
int InitializeMappedFile()
Check the datafile existency, map it to memory and get the raw char* pointer. .
virtual int CheckSpecificConsistencyWithAnotherDataFile(vDataFile *ap_DataFile)=0
void SetPOIResolution(FLTNB ap_value[3])
FLTNB * GetNewAdditionalDataMatrix(INTNB a_nbDataPerEvent)
Allocate the memory for this additional data matrix and return the pointer to the matrix...
int PROJ_WriteData()
Write/Merge chunk of data in a general data file.
vEvent * GetEvent(int64_t a_eventIndex, int a_th=0)
int CloseFile()
Close as many binary file stream for writing.
void SetBinaryDataFileName(const string &a_dataFileName)
virtual int CheckSpecificParameters()=0
This function is implemented in child classes Check specific parameters of child classes...
void SetStartTime(FLTNB a_value)
vDataFile()
vDataFile constructor.
void SetDataType(int a_dataType)
void SetCalibrationFactor(FLTNB a_value)
virtual int PrepareDataFile()=0
This function is implemented in child classes Store different kind of information inside arrays (da...
Declaration of class iEventSPECT.
void SetHeaderDataFileName(const string &a_headerFileName)
int OpenFileForWriting(string a_suffix="")
vEvent * PROJ_GenerateEvent(int idx_elt1, int idx_elt2, int a_th)
virtual void DescribeSpecific()=0
A pure virtual function used to describe the specific parts of the datafile.
int GetNbAdditionalData()
Get the number of additional data.
void SetNbEvents(int64_t a_value)
int InitializeAdditionalData(const string &a_pathToAdditionalData)
Memory allocation and initialization for the additional data matrices.
Implementation of file to memory mapping.
void SetBedIndex(int a_bedIndex)
Mother class for the Event objects.
Declaration of class iEventCT.
void Describe()
A function used to describe the generic parts of the datafile.
This class is designed to manage all dimensions and quantification related stuff. ...
Declaration of class vEvent.
virtual vEvent * GetEventSpecific(char *ap_buffer, int a_th)=0
Portable read-only memory mapping (Windows and Linux)
int PROJ_DeleteTmpDataFile()
Delete temporary datafile used for multithreaded output writing if needed.
virtual int PROJ_GetScannerSpecificParameters()=0
This function is implemented in child classes It is used to set several variables of the datafile w...
Declaration of class iEventPET.
virtual int Shuffle(int64_t)
!!!\ This function has been modified to be used specifically with a
void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification *ap_ImageDimensionsAndQuantification)
virtual int SetSpecificParametersFrom(vDataFile *ap_DataFile)=0
virtual int PROJ_InitFile()=0
This function is implemented in child classes Initialize the fstream objets for output writing as w...
oImageDimensionsAndQuantification * mp_ID