70 Cerr(
"***** iDataFilePET::ReadSpecificInfoInHeader() -> Error while reading optional fields in the header data file !" << endl);
76 Cerr(
"***** iDataFilePET::ReadSpecificInfoInHeader() -> A problem occured while setting the isotope to oImageDimensionsAndQuantification !" << endl);
139 Cerr(
"***** iDataFilePET::ComputeSizeEvent() -> Unknown event mode !" << endl);
146 Cerr(
"***** iDataFilePET::ComputeSizeEvent() -> Error, the Event size in bytes should be >= 0 !" << endl;);
209 Cerr(
"*****iDataFilePET::PrepareDataFile() -> Error while trying to allocate memory for the Event object for thread " << th <<
" !" << endl;);
227 else Cout(
" --> Correct for attenuation" << endl);
239 else Cout(
" --> Correct for normalization" << endl);
251 else Cout(
" --> Correct for scatter events" << endl);
263 else Cout(
" --> Correct for random events" << endl);
281 char* file_position = ap_buffer;
289 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
290 file_position +=
sizeof(uint32_t);
300 event->SetKind(*reinterpret_cast<uint8_t*>(file_position));
301 file_position +=
sizeof(uint8_t);
324 if (!
m_ignoreTOFFlag)
event->SetTOFMeasurement(*reinterpret_cast<FLTNBDATA*>(file_position));
328 for (
int i=0; i<3; i++)
332 if (!
m_ignorePOIFlag)
event->SetPOI1(i,*reinterpret_cast<FLTNBDATA*>(file_position));
334 if (!
m_ignorePOIFlag)
event->SetPOI2(i,*reinterpret_cast<FLTNBDATA*>(file_position));
341 event->SetNbLines(*reinterpret_cast<uint16_t*>(file_position));
342 file_position +=
sizeof(uint16_t);
345 for (
int i=0 ; i<
event->GetNbLines() ; i++)
347 event->SetID1(i, *reinterpret_cast<uint32_t*>(file_position));
348 file_position +=
sizeof(uint32_t);
349 event->SetID2(i, *reinterpret_cast<uint32_t*>(file_position));
350 file_position +=
sizeof(uint32_t);
360 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
361 file_position +=
sizeof(uint32_t);
391 total_event_value += *
reinterpret_cast<FLTNBDATA*
>(file_position);
396 total_scatter_rate += *
reinterpret_cast<FLTNBDATA*
>(file_position);
401 event->SetEventValue(0,total_event_value);
410 event->SetEventValue(tb, *reinterpret_cast<FLTNBDATA*>(file_position));
423 event->SetNbLines(*reinterpret_cast<uint16_t*>(file_position));
424 file_position +=
sizeof(uint16_t);
427 for (
int i=0 ; i<
event->GetNbLines() ; i++)
429 event->SetID1(i, *reinterpret_cast<uint32_t*>(file_position));
430 file_position +=
sizeof(uint32_t);
431 event->SetID2(i, *reinterpret_cast<uint32_t*>(file_position));
432 file_position +=
sizeof(uint32_t);
456 event->SetNbLines(*reinterpret_cast<uint16_t*>(file_position));
457 file_position +=
sizeof(uint16_t);
460 for (
int i=0 ; i<
event->GetNbLines() ; i++)
462 event->SetID1(i, *reinterpret_cast<uint32_t*>(file_position));
463 file_position +=
sizeof(uint32_t);
464 event->SetID2(i, *reinterpret_cast<uint32_t*>(file_position));
465 file_position +=
sizeof(uint32_t);
484 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> Data type should be PET !'" << endl);
490 if (
m_verbose>
VERBOSE_DETAIL)
Cout(
"iDataFilePET::CheckSpecificParameters() -> Initialize maxRingDiff with the scanner default value" << endl);
500 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> POI correction flag is enabled while the data are histogrammed, no sense !" << endl);
512 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF correction is on while there is no TOF resolution specified in the datafile header !" << endl);
521 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF correction is on while there is only one TOF bin (specified in the datafile header) !" << endl);
527 Cerr(
"***** iDataFilePET::CheckSpecificParameters() -> TOF correction is on while there is no bin size specified in the datafile header !" << endl);
562 Cerr(
"--------------------------------------------------------------------------------------------------------------------------------------" << endl);
563 Cerr(
"***** iDataFilePET::CheckFileSizeConsistency() -> Datafile size is not consistent with the information provided by the user/datafile !" << endl);
565 Cerr(
" --> Actual size : "<< sizeInBytes << endl << endl);
566 Cerr(
" ADDITIONAL INFORMATION ABOUT THE DATAFILE INITIALIZATION : " << endl);
568 "LORs, or an equivalent number of LOR + garbage LORs" << endl);
569 else Cerr(
" --> No compression in the data" << endl);
571 else Cerr(
" --> No information about the kind of coincidences in the data" << endl);
573 else Cerr(
" --> No normalization correction term in the data" << endl);
575 else Cerr(
" --> No attenuation correction term in the data" << endl);
577 else Cerr(
" --> No scatter correction term in the data" << endl);
579 else Cerr(
" --> No random correction term in the data" << endl);
581 else Cerr(
" --> No TOF correction in the data" << endl);
589 Cerr(
"--------------------------------------------------------------------------------------------------------------------------------------" << endl);
596 Cout(
"------------------------------------------------- Datafile initialization -------------------------------------------------" << endl);
598 "LORs, or an equivalent number of LOR + garbage LORs" << endl);
599 else Cout(
" --> No compression in the data" << endl);
601 else Cout(
" --> No information about the kind of coincidences in the data" << endl);
603 else Cout(
" --> No normalization correction term in the data" << endl);
605 else Cout(
" --> No attenuation correction term in the data" << endl);
607 else Cout(
" --> No scatter correction term in the data" << endl);
609 else Cout(
" --> No random correction term in the data" << endl);
611 else Cout(
" --> No TOF correction in the data" << endl);
619 Cout(
"---------------------------------------------------------------------------------------------------------------------------" << endl);
639 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDatafile() -> Maximum numbers of lines by event are inconsistent !" << endl);
645 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDatafile() -> Maximum ring differences are inconsistent !" << endl);
651 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDatafile() -> Isotopes are inconsistent !" << endl);
657 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDatafile() -> Event kind flags are inconsistent !" << endl);
663 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDatafile() -> Attenuation correction flags are inconsistent !" << endl);
669 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDatafile() -> Normalization correction flags are inconsistent !" << endl);
675 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDatafile() -> Scatter correction flags are inconsistent !" << endl);
681 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDatafile() -> Random correction flags are inconsistent !" << endl);
687 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDatafile() -> TOF information flags are inconsistent !" << endl);
693 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDatafile() -> TOF resolutions are inconsistent !" << endl);
699 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDatafile() -> Numbers of TOF bins are inconsistent !" << endl);
705 Cerr(
"***** iDataFilePET::CheckSpecificConsistencyWithAnotherDatafile() -> TOF bin sizes are inconsistent !" << endl);
741 if(
m_verbose>=3)
Cout(
"iDataFilePET::PROJ_InitFile() ..."<< endl);
757 m_headerFileName = path_name.append(img_name).append(
"_CstrProj").append(
".Cdh");
767 datafile_name.append(
"_").append(ss.str());
769 m2p_dataFile[th] =
new fstream( datafile_name.c_str(), ios::binary | ios::out | ios::trunc);
780 system(dos_instruction.c_str());
809 #ifdef CASTOR_VERBOSE
811 if(
m_verbose>=4)
Cout(
"iDataFilePET::PROJ_WriteEvent() ..."<< endl);
818 Cerr(
"*****iDataFilePET::PROJ_WriteEvent() -> Error while trying to write projection datafile (list-mode)" << endl;);
827 Cerr(
"*****iDataFilePET::PROJ_WriteEvent() -> Error while trying to write projection datafile (histogram)" << endl;);
848 #ifdef CASTOR_VERBOSE
850 if(
m_verbose>=4)
Cout(
"iDataFilePET::PROJ_WriteHistoEvent() ..."<< endl);
857 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
862 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&atn_corr_factor),
sizeof(
FLTNB));
874 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&norm_corr_factor),
sizeof(
FLTNB));
892 for(
int i=0 ; i<nb_lines ; i++)
894 uint32_t id1 = ap_Event->
GetID1(i);
895 uint32_t id2 = ap_Event->
GetID2(i);
896 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
897 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
905 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
906 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
928 #ifdef CASTOR_VERBOSE
930 if(
m_verbose>=4)
Cout(
"iDataFilePET::PROJ_WriteListEvent() ..."<< endl);
937 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
943 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&atn_corr_factor),
sizeof(
FLTNB));
948 uint8_t event_kind = ap_Event->
GetKind();
949 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&event_kind),
sizeof(uint8_t));
967 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&norm_corr_factor),
sizeof(
FLTNB));
1003 for(
int i=0 ; i<nb_lines ; i++)
1005 uint32_t id1 = ap_Event->
GetID1(i);
1006 uint32_t id2 = ap_Event->
GetID2(i);
1007 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
1008 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
1016 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1017 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&gbg),
sizeof(uint32_t));
1051 headerFile <<
"Data mode:" <<
" " <<
m_dataMode << endl;
1053 headerFile <<
"Data type: " <<
" " <<
"PET" << endl;
1062 headerFile <<
"Scanner name:" <<
" " << p_scannermanager->
GetScannerName() << endl;
1064 headerFile <<
"Maximum ring difference:" <<
" " <<
m_maxRingDiff << endl;
1086 Cerr(
"***** iDataFilePET::PROJ_WriteHeader -> Error : TOF resolution (mm) for list-mode not initialized, while TOF correction flag is enabled!" << endl);
1096 Cerr(
"***** iDataFilePET::PROJ_WriteHeader -> Error : TOF bin size for histogram mode not initialized, while TOF correction flag is enabled!" << endl);
1101 headerFile <<
"Histo TOF number of bins:" <<
" " <<
m_nbBinsTOF << endl;
1102 headerFile <<
"Histo TOF bin size:" <<
" " <<
m_binSizeTOF << endl;
1107 Cerr(
"***** iDataFilePET::PROJ_WriteHeader -> Error : Datafile mode unknown (should be 0 (list-mode) or histogram (1))!" << endl);
1119 Cerr(
"***** iDataFilePET::PROJ_WriteHeader -> Request for writing POI resolution in histogram mode (this field is specific to list-mode) !" << endl);
1133 Cerr(
"***** iDataFilePET::PROJ_WriteHeader -> Request for writing event type in histogram mode (this field is specific to list-mode) !" << endl);
1137 headerFile <<
"Coincidence kind informations flag:" <<
" " <<
m_eventKindFlag << endl;
1174 if(
m_verbose>=3)
Cout(
"PROJ_GetScannerSpecificParameters() ..."<< endl);
1181 Cerr(
"***** iDataFilePET::PROJ_GetScannerSpecificParameters() -> An error occurred while trying to get PET geometric parameters from the scanner object !" << endl);
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]
int PROJ_GetScannerSpecificParameters()
Get PET specific parameters for projections from the scanner object, through the scannerManager.
#define MODE_NORMALIZATION
bool m_ignoreNormCorrectionFlag
FLTNB GetEventScatRate(int a_bin)
uint32_t GetID2(int a_line)
int PROJ_GetPETSpecificParameters(int *a_maxRingDiff)
Transfer addresses to each geometric parameter of the PET scanner objets to the corresponding pointer...
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.
int CheckSpecificConsistencyWithAnotherDatafile(vDataFile *ap_Datafile)
Check consistency between 'this' and the provided datafile, for specific characteristics.
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.
bool m_ignoreScatCorrectionFlag
int ComputeSizeEvent()
Computation of the size of each event according to the mandatory/optional correction fields...
Declaration of class iDataFilePET.
int PROJ_WriteHistoEvent(iEventHistoPET *ap_Event, int a_th)
Write a PET histogram event.
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.
int PROJ_WriteEvent(vEvent *ap_Event, int a_th)
Write event according to the chosen type of data.
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...
Singleton class that Instantiate and initialize the scanner object.
bool m_ignoreAttnCorrectionFlag
bool GetScatCorrectionFlag()
Simply return m_scatCorrectionFlag.
oImageDimensionsAndQuantification * mp_ID
uint16_t GetMaxNumberOfLinesPerEvent()
bool GetEventKindFlag()
Simply return m_eventKindFlag.
int PROJ_InitFile()
Initialize the fstream objets for output writing as well as some other variables specific to the Proj...
int PROJ_WriteHeader()
Generate a header file according to the projection and data output informations. Used by Projection...
vEvent * GetEventFromBuffer(char *ap_buffer, int a_th)
Read an event from the position pointed by 'ap_buffer', parse the generic or modality-specific inform...
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.
Mother class for the Event objects.
int PROJ_WriteListEvent(iEventListPET *ap_Event, int a_th)
Write a PET list-mode event.
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.
int GetScannerLayerNbRings(int a_layer)
Ask the number of rings to the scanner object for a specific layer. Returns an error if this inform...
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
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