97 Cerr(
"***** iDataFilePET::ReadSpecificInfoInHeader() -> Error while reading optional fields in the header data file !" << endl);
103 Cerr(
"***** iDataFilePET::ReadSpecificInfoInHeader() -> A problem occurred while setting the isotope to oImageDimensionsAndQuantification !" << endl);
192 Cerr(
"***** iDataFilePET::ComputeSizeEvent() -> Unknown event mode !" << endl);
199 Cerr(
"***** iDataFilePET::ComputeSizeEvent() -> Error, the Event size in bytes should be >= 0 !" << endl;);
268 Cerr(
"*****iDataFilePET::PrepareDataFile() -> Error while trying to allocate memory for the Event object for thread " << th <<
" !" << endl;);
286 else Cout(
" --> Correct for attenuation" << endl);
298 else Cout(
" --> Correct for normalization" << endl);
310 else Cout(
" --> Correct for scatter events" << endl);
322 else Cout(
" --> Correct for random events" << endl);
337 Cerr(
"***** iDataFilePET::PrepareDataFile() -> Scatter correction for list-mode TOF data will be erroneous if TOF information is ignored in the projections !" << endl);
344 else Cout(
" --> Use TOF information" << endl);
362 char* file_position = ap_buffer;
370 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
371 file_position +=
sizeof(uint32_t);
381 event->SetKind(*reinterpret_cast<uint8_t*>(file_position));
382 file_position +=
sizeof(uint8_t);
405 if (!
m_ignoreTOFFlag)
event->SetTOFMeasurementInPs(*reinterpret_cast<FLTNBDATA*>(file_position));
409 for (
int i=0; i<3; i++)
413 if (!
m_ignorePOIFlag)
event->SetPOI1(i,*reinterpret_cast<FLTNBDATA*>(file_position));
415 if (!
m_ignorePOIFlag)
event->SetPOI2(i,*reinterpret_cast<FLTNBDATA*>(file_position));
422 event->SetNbLines(*reinterpret_cast<uint16_t*>(file_position));
423 file_position +=
sizeof(uint16_t);
426 for (
int i=0 ; i<
event->GetNbLines() ; i++)
428 event->SetID1(i, *reinterpret_cast<uint32_t*>(file_position));
429 file_position +=
sizeof(uint32_t);
430 event->SetID2(i, *reinterpret_cast<uint32_t*>(file_position));
431 file_position +=
sizeof(uint32_t);
441 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
442 file_position +=
sizeof(uint32_t);
472 total_event_value += *
reinterpret_cast<FLTNBDATA*
>(file_position);
477 total_scatter_rate += *
reinterpret_cast<FLTNBDATA*
>(file_position);
482 event->SetEventValue(0,total_event_value);
491 event->SetEventValue(tb, *reinterpret_cast<FLTNBDATA*>(file_position));
504 event->SetNbLines(*reinterpret_cast<uint16_t*>(file_position));
505 file_position +=
sizeof(uint16_t);
508 for (
int i=0 ; i<
event->GetNbLines() ; i++)
510 event->SetID1(i, *reinterpret_cast<uint32_t*>(file_position));
511 file_position +=
sizeof(uint32_t);
512 event->SetID2(i, *reinterpret_cast<uint32_t*>(file_position));
513 file_position +=
sizeof(uint32_t);
537 event->SetNbLines(*reinterpret_cast<uint16_t*>(file_position));
538 file_position +=
sizeof(uint16_t);
541 for (
int i=0 ; i<
event->GetNbLines() ; i++)
543 event->SetID1(i, *reinterpret_cast<uint32_t*>(file_position));
544 file_position +=
sizeof(uint32_t);
545 event->SetID2(i, *reinterpret_cast<uint32_t*>(file_position));
546 file_position +=
sizeof(uint32_t);
564 Cout(
"iDataFilePET::DescribeSpecific() -> Here is some specific content of the PET datafile" << endl);
575 Cout(
" --> TOF quantization bin size (for list-mode data) not set " << endl);
602 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> Data type should be PET !'" << endl);
616 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> POI correction flag is enabled while the data are histogrammed, no sense !" << endl);
628 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF information is used while there is no TOF resolution specified in the datafile header !" << endl);
637 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF information is used while there is only one TOF bin (specified in the datafile header) !" << endl);
643 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF information is used while there is no bin size specified in the datafile header !" << endl);
653 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF measurement range not set !" << endl);
680 fstream* p_file =
new fstream(
m_dataFileName.c_str(), ios::binary| ios::in );
682 if (!p_file->is_open())
684 Cerr(
"***** iDataFilePET::CheckFileSizeConsistency() -> Failed to open input file '" <<
m_dataFileName.c_str() <<
"' !" << endl);
689 p_file->seekg(0, ios::end);
690 int64_t sizeInBytes = p_file->tellg();
697 Cerr(
"--------------------------------------------------------------------------------------------------------------------------------------" << endl);
698 Cerr(
"***** iDataFilePET::CheckFileSizeConsistency() -> DataFile size is not consistent with the information provided by the user/datafile !" << endl);
700 Cerr(
" --> Actual size : "<< sizeInBytes << endl << endl);
701 Cerr(
" ADDITIONAL INFORMATION ABOUT THE DATAFILE INITIALIZATION : " << endl);
703 "LORs, or an equivalent number of LOR + garbage LORs" << endl);
704 else Cerr(
" --> No compression in the data" << endl);
706 else Cerr(
" --> No information about the kind of coincidences in the data" << endl);
708 else Cerr(
" --> No normalization correction term in the data" << endl);
710 else Cerr(
" --> No attenuation correction term in the data" << endl);
712 else Cerr(
" --> No scatter correction term in the data" << endl);
714 else Cerr(
" --> No random correction term in the data" << endl);
716 else Cerr(
" --> No TOF information in the data" << endl);
724 Cerr(
"--------------------------------------------------------------------------------------------------------------------------------------" << endl);
744 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Maximum numbers of lines by event are inconsistent !" << endl);
750 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Maximum ring differences are inconsistent !" << endl);
756 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Isotopes are inconsistent !" << endl);
762 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Event kind flags are inconsistent !" << endl);
768 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Attenuation correction flags are inconsistent !" << endl);
774 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Normalization correction flags are inconsistent !" << endl);
780 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Scatter correction flags are inconsistent !" << endl);
786 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Random correction flags are inconsistent !" << endl);
792 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF information flags are inconsistent !" << endl);
798 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF resolutions are inconsistent !" << endl);
804 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Numbers of TOF bins are inconsistent !" << endl);
810 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF bin sizes are inconsistent !" << endl);
816 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF measurement ranges are inconsistent !" << endl);
822 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF quantization bin sizes are inconsistent !" << endl);
828 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Data modes are inconsistent (list-mode or histogram) !" << endl);
883 datafile_name.append(
"_").append(ss.str());
885 m2p_dataFile[th] =
new fstream( datafile_name.c_str(), ios::binary | ios::out | ios::trunc);
896 system(dos_instruction.c_str());
920 Cerr(
"*****iDataFilePET::WriteEvent() -> Error while trying to write projection datafile (list-mode)" << endl;);
929 Cerr(
"*****iDataFilePET::WriteEvent() -> Error while trying to write projection datafile (histogram)" << endl;);
950 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
985 for(
int i=0 ; i<nb_lines ; i++)
987 uint32_t id1 = ap_Event->
GetID1(i);
988 uint32_t id2 = ap_Event->
GetID2(i);
989 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
990 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
998 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
999 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1018 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
1029 uint8_t event_kind = ap_Event->
GetKind();
1030 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&event_kind),
sizeof(uint8_t));
1084 for(
int i=0 ; i<nb_lines ; i++)
1086 uint32_t id1 = ap_Event->
GetID1(i);
1087 uint32_t id2 = ap_Event->
GetID2(i);
1088 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
1089 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
1097 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1098 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1118 if (!headerFile.is_open())
1120 Cerr(
"***** iDataFilePET::WriteHeader() -> Failed to open output header file '" <<
m_headerFileName <<
"' !" << endl);
1127 headerFile <<
"Number of events: " <<
m_nbEvents << endl;
1133 headerFile <<
"Data type: PET" << endl;
1149 headerFile <<
"Isotope: " <<
m_isotope << endl;
1154 headerFile <<
"TOF information flag: 1" << endl;
1167 headerFile <<
"Histo TOF number of bins: " <<
m_nbTOFBins << endl;
1178 Cerr(
"***** iDataFilePET::WriteHeader -> Request for writing event type in histogram mode (this field is specific to list-mode) !" << endl);
1181 else headerFile <<
"Coincidence kind flag: " <<
m_eventKindFlag << endl;
1211 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)
Write event according to the chosen type of data.
bool m_randCorrectionFlag
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)
Set the PET isotope for the provided bed.
static sScannerManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
#define VERBOSE_DEBUG_EVENT
FLTNB GetTOFMeasurementRangeInPs()
void SetNbLines(uint16_t a_value)
Set the number of lines of the Event.
FLTNB m_TOFMeasurementRangeInPs
bool mp_POIDirectionFlag[3]
FLTNB GetFrameTimeStartInSec(int a_bed, int a_frame)
Get the frame time start for the given bed, in seconds as a FLTNB.
int PROJ_GetScannerSpecificParameters()
Get PET specific parameters for projections from the scanner object, through the scannerManager.
#define MODE_NORMALIZATION
bool m_ignoreNormCorrectionFlag
void DescribeSpecific()
Implementation of the pure virtual eponym function that simply prints info about the datafile...
FLTNB GetEventScatRate(int a_bin)
uint32_t GetID2(int a_line)
int CheckSpecificConsistencyWithAnotherDataFile(vDataFile *ap_DataFile)
Check consistency between 'this' and the provided datafile, for specific characteristics.
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.
int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag)
Read through the header file and gather specific PET information.
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)
Read an event from the position pointed by 'ap_buffer', parse the generic or modality-specific inform...
bool m_ignoreScatCorrectionFlag
int ComputeSizeEvent()
Computation of the size of each event according to the mandatory/optional correction fields...
Declaration of class iDataFilePET.
string GetFileFromPath(const string &a_pathToFile)
Simply return the file from a path string passed in parameter.
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.
#define VERBOSE_DEBUG_LIGHT
~iDataFilePET()
iDataFilePET destructor.
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
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_ignoreAttnCorrectionFlag
FLTNB GetTOFQuantizationBinSizeInPs()
bool GetScatCorrectionFlag()
Simply return m_scatCorrectionFlag.
int SetSpecificParametersFrom(vDataFile *ap_DataFile)
Initialize all parameters specific to PET from the provided datafile.
oImageDimensionsAndQuantification * mp_ID
uint16_t GetMaxNumberOfLinesPerEvent()
bool GetEventKindFlag()
Simply return m_eventKindFlag.
int WriteHistoEvent(iEventHistoPET *ap_Event, int a_th)
Write a PET histogram event.
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()
FLTNB GetTOFResolutionInPs()
int PrepareDataFile()
Store different kind of information inside arrays (data relative to specific correction as well as ba...
FLTNB mp_POIResolution[3]
const string & GetBaseName()
void SetTimeInMs(uint32_t a_value)
Set the timestamp of the Event.
FLTNB GetMaxAxialDiffmm()
Mother class for the Event objects.
int GetNbTimeFrames()
Get the number of time frames.
vEvent ** m2p_BufferEvent
bool GetRandCorrectionFlag()
Simply return m_randCorrectionFlag.
uint32_t GetID1(int a_line)
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.
#define DEBUG_VERBOSE(IGNORED1, IGNORED2)
int CheckFileSizeConsistency()
This function is implemented in child classes Check if file size is consistent. ...
FLTNB m_calibrationFactor
FLTNB GetFrameDurationInSec(int a_bed, int a_frame)
Get the frame duration for the given bed, in seconds as a FLTNB.
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)
Write a PET list-mode event.