96 Cerr(
"***** iDataFilePET::ReadSpecificInfoInHeader() -> Error while reading optional fields in the header data file !" << endl);
102 Cerr(
"***** iDataFilePET::ReadSpecificInfoInHeader() -> A problem occured while setting the isotope to oImageDimensionsAndQuantification !" << endl);
190 Cerr(
"***** iDataFilePET::ComputeSizeEvent() -> Unknown event mode !" << endl);
197 Cerr(
"***** iDataFilePET::ComputeSizeEvent() -> Error, the Event size in bytes should be >= 0 !" << endl;);
266 Cerr(
"*****iDataFilePET::PrepareDataFile() -> Error while trying to allocate memory for the Event object for thread " << th <<
" !" << endl;);
284 else Cout(
" --> Correct for attenuation" << endl);
296 else Cout(
" --> Correct for normalization" << endl);
308 else Cout(
" --> Correct for scatter events" << endl);
320 else Cout(
" --> Correct for random events" << endl);
335 Cerr(
"***** iDataFilePET::PrepareDataFile() -> Scatter correction for list-mode TOF data will be erroneous if TOF information is ignored in the projections !" << endl);
342 else Cout(
" --> Use TOF information" << endl);
360 char* file_position = ap_buffer;
368 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
369 file_position +=
sizeof(uint32_t);
379 event->SetKind(*reinterpret_cast<uint8_t*>(file_position));
380 file_position +=
sizeof(uint8_t);
403 if (!
m_ignoreTOFFlag)
event->SetTOFMeasurement(*reinterpret_cast<FLTNBDATA*>(file_position));
407 for (
int i=0; i<3; i++)
411 if (!
m_ignorePOIFlag)
event->SetPOI1(i,*reinterpret_cast<FLTNBDATA*>(file_position));
413 if (!
m_ignorePOIFlag)
event->SetPOI2(i,*reinterpret_cast<FLTNBDATA*>(file_position));
420 event->SetNbLines(*reinterpret_cast<uint16_t*>(file_position));
421 file_position +=
sizeof(uint16_t);
424 for (
int i=0 ; i<
event->GetNbLines() ; i++)
426 event->SetID1(i, *reinterpret_cast<uint32_t*>(file_position));
427 file_position +=
sizeof(uint32_t);
428 event->SetID2(i, *reinterpret_cast<uint32_t*>(file_position));
429 file_position +=
sizeof(uint32_t);
439 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
440 file_position +=
sizeof(uint32_t);
470 total_event_value += *
reinterpret_cast<FLTNBDATA*
>(file_position);
475 total_scatter_rate += *
reinterpret_cast<FLTNBDATA*
>(file_position);
480 event->SetEventValue(0,total_event_value);
489 event->SetEventValue(tb, *reinterpret_cast<FLTNBDATA*>(file_position));
502 event->SetNbLines(*reinterpret_cast<uint16_t*>(file_position));
503 file_position +=
sizeof(uint16_t);
506 for (
int i=0 ; i<
event->GetNbLines() ; i++)
508 event->SetID1(i, *reinterpret_cast<uint32_t*>(file_position));
509 file_position +=
sizeof(uint32_t);
510 event->SetID2(i, *reinterpret_cast<uint32_t*>(file_position));
511 file_position +=
sizeof(uint32_t);
535 event->SetNbLines(*reinterpret_cast<uint16_t*>(file_position));
536 file_position +=
sizeof(uint16_t);
539 for (
int i=0 ; i<
event->GetNbLines() ; i++)
541 event->SetID1(i, *reinterpret_cast<uint32_t*>(file_position));
542 file_position +=
sizeof(uint32_t);
543 event->SetID2(i, *reinterpret_cast<uint32_t*>(file_position));
544 file_position +=
sizeof(uint32_t);
562 Cout(
"iDataFilePET::DescribeSpecific() -> Here is some specific content of the PET datafile" << endl);
596 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> Data type should be PET !'" << endl);
610 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> POI correction flag is enabled while the data are histogrammed, no sense !" << endl);
622 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF information is used while there is no TOF resolution specified in the datafile header !" << endl);
631 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF information is used while there is only one TOF bin (specified in the datafile header) !" << endl);
637 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF information is used while there is no bin size specified in the datafile header !" << endl);
668 fstream* p_file =
new fstream(
m_dataFileName.c_str(), ios::binary| ios::in );
670 if (!p_file->is_open())
672 Cerr(
"***** iDataFilePET::CheckFileSizeConsistency() -> Failed to open input file '" <<
m_dataFileName.c_str() <<
"' !" << endl);
677 p_file->seekg(0, ios::end);
678 int64_t sizeInBytes = p_file->tellg();
685 Cerr(
"--------------------------------------------------------------------------------------------------------------------------------------" << endl);
686 Cerr(
"***** iDataFilePET::CheckFileSizeConsistency() -> DataFile size is not consistent with the information provided by the user/datafile !" << endl);
688 Cerr(
" --> Actual size : "<< sizeInBytes << endl << endl);
689 Cerr(
" ADDITIONAL INFORMATION ABOUT THE DATAFILE INITIALIZATION : " << endl);
691 "LORs, or an equivalent number of LOR + garbage LORs" << endl);
692 else Cerr(
" --> No compression in the data" << endl);
694 else Cerr(
" --> No information about the kind of coincidences in the data" << endl);
696 else Cerr(
" --> No normalization correction term in the data" << endl);
698 else Cerr(
" --> No attenuation correction term in the data" << endl);
700 else Cerr(
" --> No scatter correction term in the data" << endl);
702 else Cerr(
" --> No random correction term in the data" << endl);
704 else Cerr(
" --> No TOF information in the data" << endl);
712 Cerr(
"--------------------------------------------------------------------------------------------------------------------------------------" << endl);
732 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Maximum numbers of lines by event are inconsistent !" << endl);
738 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Maximum ring differences are inconsistent !" << endl);
744 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Isotopes are inconsistent !" << endl);
750 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Event kind flags are inconsistent !" << endl);
756 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Attenuation correction flags are inconsistent !" << endl);
762 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Normalization correction flags are inconsistent !" << endl);
768 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Scatter correction flags are inconsistent !" << endl);
774 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Random correction flags are inconsistent !" << endl);
780 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF information flags are inconsistent !" << endl);
786 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF resolutions are inconsistent !" << endl);
792 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Numbers of TOF bins are inconsistent !" << endl);
798 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> TOF bin sizes are inconsistent !" << endl);
804 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDataFile() -> Data modes are inconsistent (list-mode or histogram) !" << endl);
851 m_headerFileName = path_name.append(img_name).append(
"_CstrProj").append(
".Cdh");
861 datafile_name.append(
"_").append(ss.str());
863 m2p_dataFile[th] =
new fstream( datafile_name.c_str(), ios::binary | ios::out | ios::trunc);
874 system(dos_instruction.c_str());
898 Cerr(
"*****iDataFilePET::WriteEvent() -> Error while trying to write projection datafile (list-mode)" << endl;);
907 Cerr(
"*****iDataFilePET::WriteEvent() -> Error while trying to write projection datafile (histogram)" << endl;);
928 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
933 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&atn_corr_factor),
sizeof(
FLTNB));
945 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&norm_corr_factor),
sizeof(
FLTNB));
963 for(
int i=0 ; i<nb_lines ; i++)
965 uint32_t id1 = ap_Event->
GetID1(i);
966 uint32_t id2 = ap_Event->
GetID2(i);
967 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
968 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
976 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
977 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
996 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
1002 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&atn_corr_factor),
sizeof(
FLTNB));
1007 uint8_t event_kind = ap_Event->
GetKind();
1008 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&event_kind),
sizeof(uint8_t));
1026 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&norm_corr_factor),
sizeof(
FLTNB));
1062 for(
int i=0 ; i<nb_lines ; i++)
1064 uint32_t id1 = ap_Event->
GetID1(i);
1065 uint32_t id2 = ap_Event->
GetID2(i);
1066 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
1067 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
1075 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1076 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1096 if (!headerFile.is_open())
1098 Cerr(
"***** iDataFilePET::WriteHeader() -> Failed to open output header file '" <<
m_headerFileName <<
"' !" << endl);
1105 headerFile <<
"Number of events: " <<
m_nbEvents << endl;
1111 headerFile <<
"Data type: PET" << endl;
1127 headerFile <<
"Isotope: " <<
m_isotope << endl;
1132 headerFile <<
"TOF information flag: 1" << endl;
1141 headerFile <<
"Histo TOF number of bins: " <<
m_nbBinsTOF << endl;
1143 headerFile <<
"Histo TOF bin size (ps): " <<
m_binSizeTOF << endl;
1152 Cerr(
"***** iDataFilePET::WriteHeader -> Request for writing event type in histogram mode (this field is specific to list-mode) !" << endl);
1155 else headerFile <<
"Coincidence kind flag: " <<
m_eventKindFlag << endl;
1185 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
void SetNbLines(uint16_t a_value)
Set the number of lines of the Event.
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.
FLTNB GetTOFMeasurement()
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...
FLTNB m_TOFMeasurementRange
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
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...
Inherit from vEvent. Used for normalization events for sensitivity computation.
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.
FLTNB GetTOFMeasurementRange()
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)
bool m_ignoreRandCorrectionFlag
int WriteListEvent(iEventListPET *ap_Event, int a_th=0)
Write a PET list-mode event.