9 #include "iDataFilePET.hh" 77 Cerr(
"***** iDataFilePET::ReadSpecificInfoInHeader() -> Error while reading optional fields in the header data file !" << endl);
83 Cerr(
"***** iDataFilePET::ReadSpecificInfoInHeader() -> A problem occurred while setting the isotope to oImageDimensionsAndQuantification !" << endl);
174 Cerr(
"***** iDataFilePET::ComputeSizeEvent() -> Unknown event mode !" << endl);
185 Cerr(
"***** iDataFilePET::ComputeSizeEvent() -> Error, the Event size in bytes should be >= 0 !" << endl;);
254 Cerr(
"*****iDataFilePET::PrepareDataFile() -> Error while trying to allocate memory for the Event object for thread " << th <<
" !" << endl;);
266 Cerr(
"*****iDataFilePET::PrepareDataFile() -> Error while trying to allocate memory for the custom Event INT fields for thread " << th <<
" !" << endl;);
274 Cerr(
"*****iDataFilePET::PrepareDataFile() -> Error while trying to allocate memory for the custom Event FLT fields for thread " << th <<
" !" << endl;);
293 else Cout(
" --> Correct for attenuation" << endl);
305 else Cout(
" --> Correct for normalization" << endl);
317 else Cout(
" --> Correct for scatter events" << endl);
329 else Cout(
" --> Correct for random events" << endl);
344 Cerr(
"***** iDataFilePET::PrepareDataFile() -> Scatter correction for list-mode TOF data will be erroneous if TOF information is ignored in the projections !" << endl);
351 else Cout(
" --> Use TOF information" << endl);
369 char* file_position = ap_buffer;
377 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
378 file_position +=
sizeof(uint32_t);
388 event->SetKind(*reinterpret_cast<uint8_t*>(file_position));
389 file_position +=
sizeof(uint8_t);
412 if (!
m_ignoreTOFFlag)
event->SetTOFMeasurementInPs(*reinterpret_cast<FLTNBDATA*>(file_position));
419 if (!
m_ignoreTOFFlag)
event->SetTOFEventResolutionInPs(*reinterpret_cast<FLTNBDATA*>(file_position));
424 for (
int i=0; i<3; i++)
428 if (!
m_ignorePOIFlag)
event->SetPOI1(i,*reinterpret_cast<FLTNBDATA*>(file_position));
430 if (!
m_ignorePOIFlag)
event->SetPOI2(i,*reinterpret_cast<FLTNBDATA*>(file_position));
437 event->SetNbLines(*reinterpret_cast<uint16_t*>(file_position));
438 file_position +=
sizeof(uint16_t);
441 for (
int i=0 ; i<
event->GetNbLines() ; i++)
443 event->SetID1(i, *reinterpret_cast<uint32_t*>(file_position));
444 file_position +=
sizeof(uint32_t);
445 event->SetID2(i, *reinterpret_cast<uint32_t*>(file_position));
446 file_position +=
sizeof(uint32_t);
454 event->SetCustomFLTData(i, *reinterpret_cast<EVTFLTDATA*>(file_position));
463 event->SetCustomINTData(i, *reinterpret_cast<EVTINTDATA*>(file_position));
475 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
476 file_position +=
sizeof(uint32_t);
506 total_event_value += *
reinterpret_cast<FLTNBDATA*
>(file_position);
511 total_scatter_rate += *
reinterpret_cast<FLTNBDATA*
>(file_position);
516 event->SetEventValue(0,total_event_value);
525 event->SetEventValue(tb, *reinterpret_cast<FLTNBDATA*>(file_position));
538 event->SetNbLines(*reinterpret_cast<uint16_t*>(file_position));
539 file_position +=
sizeof(uint16_t);
542 for (
int i=0 ; i<
event->GetNbLines() ; i++)
544 event->SetID1(i, *reinterpret_cast<uint32_t*>(file_position));
545 file_position +=
sizeof(uint32_t);
546 event->SetID2(i, *reinterpret_cast<uint32_t*>(file_position));
547 file_position +=
sizeof(uint32_t);
551 if(m_nbCustomFLTData>0)
555 event->SetCustomFLTData(i, *reinterpret_cast<EVTFLTDATA*>(file_position));
560 if(m_nbCustomINTData>0)
564 event->SetCustomINTData(i, *reinterpret_cast<EVTINTDATA*>(file_position));
590 event->SetNbLines(*reinterpret_cast<uint16_t*>(file_position));
591 file_position +=
sizeof(uint16_t);
594 for (
int i=0 ; i<
event->GetNbLines() ; i++)
596 event->SetID1(i, *reinterpret_cast<uint32_t*>(file_position));
597 file_position +=
sizeof(uint32_t);
598 event->SetID2(i, *reinterpret_cast<uint32_t*>(file_position));
599 file_position +=
sizeof(uint32_t);
602 if(m_nbCustomFLTData>0)
606 event->SetCustomFLTData(i, *reinterpret_cast<EVTFLTDATA*>(file_position));
611 if(m_nbCustomINTData>0)
615 event->SetCustomINTData(i, *reinterpret_cast<EVTINTDATA*>(file_position));
635 Cout(
"iDataFilePET::DescribeSpecific() -> Here is some specific content of the PET datafile" << endl);
646 Cout(
" --> TOF quantization bin size (for list-mode data) not set " << endl);
649 Cout(
" --> Using per event TOF resolution data");
653 Cout(
" --> Number of TOF bins: " << m_nbTOFBins << endl);
677 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> Data type should be PET !'" << endl);
691 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> POI correction flag is enabled while the data are histogrammed, no sense !" << endl);
703 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF information is used while there is no TOF resolution specified in the datafile header !" << endl);
712 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF information is used while there is only one TOF bin (specified in the datafile header) !" << endl);
718 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF information is used while there is no bin size specified in the datafile header !" << endl);
723 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> Per event TOF resolution data only works in list mode !" << endl);
733 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF measurement range not set !" << endl);
738 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> Both per event and global TOF resolution are set. Remove global value !" << endl);
766 fstream* p_file =
new fstream(
m_dataFileName.c_str(), ios::binary| ios::in );
768 if (!p_file->is_open())
770 Cerr(
"***** iDataFilePET::CheckFileSizeConsistency() -> Failed to open input file '" <<
m_dataFileName.c_str() <<
"' !" << endl);
775 p_file->seekg(0, ios::end);
776 int64_t sizeInBytes = p_file->tellg();
783 Cerr(
"--------------------------------------------------------------------------------------------------------------------------------------" << endl);
784 Cerr(
"***** iDataFilePET::CheckFileSizeConsistency() -> DataFile size is not consistent with the information provided by the user/datafile !" << endl);
786 Cerr(
" --> Actual size : "<< sizeInBytes << endl << endl);
787 Cerr(
" ADDITIONAL INFORMATION ABOUT THE DATAFILE INITIALIZATION : " << endl);
789 "LORs, or an equivalent number of LOR + garbage LORs" << endl);
790 else Cerr(
" --> No compression in the data" << endl);
792 else Cerr(
" --> No information about the kind of coincidences in the data" << endl);
794 else Cerr(
" --> No normalization correction term in the data" << endl);
796 else Cerr(
" --> No attenuation correction term in the data" << endl);
798 else Cerr(
" --> No scatter correction term in the data" << endl);
800 else Cerr(
" --> No random correction term in the data" << endl);
802 else Cerr(
" --> No TOF information in the data" << endl);
811 else Cerr(
" --> No per event TOF standard deviation in the data" << endl);
812 Cerr(
"--------------------------------------------------------------------------------------------------------------------------------------" << endl);
832 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Maximum numbers of lines by event are inconsistent !" << endl);
838 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Maximum ring differences are inconsistent !" << endl);
844 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Isotopes are inconsistent !" << endl);
850 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Event kind flags are inconsistent !" << endl);
856 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Attenuation correction flags are inconsistent !" << endl);
862 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Normalization correction flags are inconsistent !" << endl);
868 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Scatter correction flags are inconsistent !" << endl);
874 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Random correction flags are inconsistent !" << endl);
880 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF information flags are inconsistent !" << endl);
886 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF resolutions are inconsistent !" << endl);
892 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Numbers of TOF bins are inconsistent !" << endl);
898 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF bin sizes are inconsistent !" << endl);
904 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF measurement ranges are inconsistent !" << endl);
910 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF quantization bin sizes are inconsistent !" << endl);
916 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Per event TOF resolution flags are inconsistent (list-mode or histogram) !" << endl);
922 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Data modes are inconsistent (list-mode or histogram) !" << endl);
978 datafile_name.append(
"_").append(ss.str());
980 m2p_dataFile[th] =
new fstream( datafile_name.c_str(), ios::binary | ios::out | ios::trunc);
991 system(dos_instruction.c_str());
1015 Cerr(
"*****iDataFilePET::WriteEvent() -> Error while trying to write projection datafile (list-mode)" << endl;);
1024 Cerr(
"*****iDataFilePET::WriteEvent() -> Error while trying to write projection datafile (histogram)" << endl;);
1033 Cerr(
"*****iDataFilePET::WriteEvent() -> Error while trying to write projection datafile (histogram)" << endl;);
1054 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
1089 for(
int i=0 ; i<nb_lines ; i++)
1091 uint32_t id1 = ap_Event->
GetID1(i);
1092 uint32_t id2 = ap_Event->
GetID2(i);
1093 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
1094 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
1098 if(m_nbCustomINTData>0)
1107 if(m_nbCustomFLTData>0)
1121 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1122 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1141 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
1152 uint8_t event_kind = ap_Event->
GetKind();
1153 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&event_kind),
sizeof(uint8_t));
1212 for(
int i=0 ; i<nb_lines ; i++)
1214 uint32_t id1 = ap_Event->
GetID1(i);
1215 uint32_t id2 = ap_Event->
GetID2(i);
1216 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
1217 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
1221 if(m_nbCustomINTData>0)
1230 if(m_nbCustomFLTData>0)
1244 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1245 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1284 for(
int i=0 ; i<nb_lines ; i++)
1286 uint32_t id1 = ap_Event->
GetID1(i);
1287 uint32_t id2 = ap_Event->
GetID2(i);
1288 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
1289 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
1293 if(m_nbCustomINTData>0)
1302 if(m_nbCustomFLTData>0)
1316 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1317 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1340 if (!headerFile.is_open())
1342 Cerr(
"***** iDataFilePET::WriteHeader() -> Failed to open output header file '" <<
m_headerFileName <<
"' !" << endl);
1349 headerFile <<
"Number of events: " <<
m_nbEvents << endl;
1355 headerFile <<
"Data type: PET" << endl;
1371 headerFile <<
"Isotope: " <<
m_isotope << endl;
1376 headerFile <<
"TOF information flag: 1" << endl;
1380 headerFile <<
"Per event TOF resolution flag: 1" << endl;
1396 headerFile <<
"Histo TOF number of bins: " << m_nbTOFBins << endl;
1407 Cerr(
"***** iDataFilePET::WriteHeader -> Request for writing event type in histogram mode (this field is specific to list-mode) !" << endl);
1410 else headerFile <<
"Coincidence kind flag: " <<
m_eventKindFlag << endl;
1440 Cerr(
"***** iDataFilePET::PROJ_GetScannerSpecificParameters() -> An error occurred while trying to get PET geometric parameters from the scanner object !" << endl);
int WriteEvent(vEvent *ap_Event, int a_th)
bool m_randCorrectionFlag
virtual EVTFLTDATA * GetCustomFLTData()
uint32_t GetID2(int a_line)
This class is designed to be a mother virtual class for DataFile.
bool GetNormCorrectionFlag()
Simply return m_normCorrectionFlag.
int SetPETIsotope(int a_bed, const string &a_isotope)
static sScannerManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
FLTNB GetTOFMeasurementRangeInPs()
void SetNbLines(uint16_t a_value)
FLTNB m_TOFMeasurementRangeInPs
int PROJ_GetScannerSpecificParameters()
Get PET specific parameters for projections from the scanner object, through the scannerManager.
FLTNB GetFrameDurationInSec(int a_bed, int a_frame)
#define MODE_NORMALIZATION
FLTNB GetAttenuationCorrectionFactor()
bool m_ignoreNormCorrectionFlag
void DescribeSpecific()
Implementation of the pure virtual eponym function that simply prints info about the datafile...
FLTNB GetEventScatRate(int a_bin)
int WriteNormEvent(iEventNorm *ap_Event, int a_th)
int CheckSpecificConsistencyWithAnotherDataFile(vDataFile *ap_DataFile)
iDataFilePET()
iDataFilePET constructor. Initialize the member variables to their default values.
bool GetIgnoreAttnCorrectionFlag()
Get the boolean that says if the attenuation correction is ignored or not.
FLTNB GetTOFEventResolutionInPs() const
Get TOF resolution in ps.
int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag)
bool IsInitialized()
Returns true if the object has been initialized.
int CheckSpecificParameters()
Check parameters specific to PET data.
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
vEvent * GetEventSpecific(char *ap_buffer, int a_th)
bool m_ignoreScatCorrectionFlag
FLTNB GetFrameTimeStartInSec(int a_bed, int a_frame)
int ComputeSizeEvent()
Computation of the size of each event according to the mandatory/optional correction fields...
FLTNB mp_POIResolution[3]
bool GetIgnoreNormCorrectionFlag()
Get the boolean that says if the normalization correction is ignored or not.
bool GetIgnoreRandCorrectionFlag()
Get the boolean that says if the random correction is ignored or not.
void SetAttenuationCorrectionFactor(FLTNBDATA a_value)
Cast the FLTNBDATA value passed as parameter in FLTNB, and set it to the attenuation correction facto...
Inherit from iEventPET. Class for PET list-mode events.
FLTNB GetEventValue(int a_bin)
const string & GetPathName()
Inherit from iEventPET. Class for PET histogram mode events.
bool GetPerEventTOFResolutionFlag() const
Simply return m_perEventTOFResolutionFlag.
~iDataFilePET()
iDataFilePET destructor.
#define DEBUG_VERBOSE(IGNORED1, IGNORED2)
virtual void SetNbCustomFLTData(int a_value)
initialize the number of custom INT data with a_value
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
bool m_ignoreAttnCorrectionFlag
FLTNB GetTOFQuantizationBinSizeInPs()
bool GetScatCorrectionFlag()
Simply return m_scatCorrectionFlag.
int SetSpecificParametersFrom(vDataFile *ap_DataFile)
bool m_perEventTOFResolutionFlag
vEvent ** m2p_BufferEvent
uint16_t GetMaxNumberOfLinesPerEvent()
bool GetEventKindFlag()
Simply return m_eventKindFlag.
int WriteHistoEvent(iEventHistoPET *ap_Event, int a_th)
int WriteHeader()
Generate a header file according to the data output information.
int PROJ_InitFile()
Initialize the fstream objets for output writing as well as some other variables specific to the Proj...
FLTNB m_TOFResolutionInPs
FLTNB m_TOFQuantizationBinSizeInPs
Inherit from vEvent. Used for normalization events for sensitivity computation.
FLTNB GetTOFBinSizeInPs()
int PrepareDataFile()
Store different kind of information inside arrays (data relative to specific correction as well as ba...
const string & GetBaseName()
void SetTimeInMs(uint32_t a_value)
FLTNB GetMaxAxialDiffmm()
virtual void SetNbCustomINTData(int a_value)
initialize the number of custom INT data with a_value
bool mp_POIDirectionFlag[3]
Mother class for the Event objects.
int GetNbTimeFrames()
Get the number of time frames.
FLTNB GetTOFResolutionInPs(int a_reso)
bool GetRandCorrectionFlag()
Simply return m_randCorrectionFlag.
int GetNbThreadsForProjection()
Get the number of threads used for projections.
bool GetIgnoreScatCorrectionFlag()
Get the boolean that says if the scatter correction is ignored or not.
int CheckFileSizeConsistency()
This function is implemented in child classes Check if file size is consistent. ...
FLTNB m_calibrationFactor
uint32_t GetID1(int a_line)
string GetFileFromPath(const string &a_pathToFile)
Simply return the file from a path string passed in parameter.
#define VERBOSE_DEBUG_LIGHT
virtual EVTINTDATA * GetCustomINTData()
int ReadDataASCIIFile(const string &a_file, const string &a_keyword, T *ap_return, int a_nbElts, bool a_mandatoryFlag)
Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter a...
bool m_normCorrectionFlag
uint16_t m_maxNumberOfLinesPerEvent
bool GetAtnCorrectionFlag()
Simply return m_atnCorrectionFlag.
Inherit from vDataFile. Class that manages the reading of a PET input file (header + data)...
bool m_scatCorrectionFlag
FLTNB GetEventScatRate(int a_bin)
FLTNB GetTOFMeasurementInPs()
bool m_ignoreRandCorrectionFlag
int WriteListEvent(iEventListPET *ap_Event, int a_th=0)
FLTNB GetNormalizationFactor()
#define VERBOSE_DEBUG_EVENT
oImageDimensionsAndQuantification * mp_ID