117 if (a_affectQuantificationFlag &&
mp_ID==NULL)
119 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Image dimensions and quantification object has not been set while it is asked to affect" << endl);
120 Cerr(
" its parameters from information read into the header !" << endl);
127 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read number of events in the header data file !" << endl);
132 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read scanner name in the header data file !" << endl);
139 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read data filename in the header data file !" << endl);
154 string data_mode =
"";
157 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read data mode in the header data file !" << endl);
160 if ( data_mode==
"LIST" || data_mode==
"LISTMODE" || data_mode==
"LIST-MODE" ||
161 data_mode==
"list" || data_mode==
"listmode" || data_mode==
"list-mode" || data_mode==
"0" )
m_dataMode =
MODE_LIST;
162 else if ( data_mode==
"HISTOGRAM" || data_mode==
"histogram" || data_mode==
"Histogram" ||
164 else if ( data_mode==
"NORMALIZATION" || data_mode==
"normalization" || data_mode==
"Normalization" ||
168 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Unknown data mode '" << data_mode <<
"' found in header file !" << endl);
173 string data_type =
"";
176 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read data type in the header data file !" << endl);
179 if ( data_type==
"PET" || data_type==
"pet" || data_type==
"0" )
184 else if ( data_type==
"SPECT" || data_type==
"spect" || data_type==
"1" )
189 else if ( data_type==
"CT" || data_type==
"ct" || data_type==
"2" )
196 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Unknown data type '" << data_type <<
"' found in header file !" << endl);
205 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read acquisition start time in the header data file !" << endl);
210 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read acquisition stop time in the header data file !" << endl);
218 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading acquisition start time in the header data file !" << endl);
223 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading acquisition stop time in the header data file !" << endl);
231 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while passing acquisition start and stop time to the ImageDimensionsAndQuantification !" << endl);
240 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading the 'Bed relative position (mm)' field in the data file header !" << endl);
249 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading optional field in the header data file !" << endl);
256 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read modality-specific informations from the header data file !" << endl);
263 Cerr(
"***** vDataFile::ReadSpecificInfoInHeader() -> A problem occured while setting the calibration factor to oImageDimensionsAndQuantification !" << endl);
303 Cerr(
"***** vDataFile::SetParametersFrom() -> An error occured while setting specific parameters fro mthe provided datafile !" << endl);
323 Cerr(
"***** vDataFile::CheckParameters() -> ImageDimensionsAndQuantification object not initialized !" << endl);
328 Cerr(
"***** vDataFile::CheckParameters() -> String containing path to header file not initialized !" << endl);
333 Cerr(
"***** vDataFile::CheckParameters() -> String containing path to raw data file not initialized !" << endl);
338 Cerr(
"***** vDataFile::CheckParameters() -> Number of events incorrectly initialized !" << endl);
343 Cerr(
"***** vDataFile::CheckParameters() -> Data mode incorrectly initialized !" << endl);
348 Cerr(
"***** vDataFile::CheckParameters() -> Acquisition duration (s) incorrectly initialized !" << endl);
353 Cerr(
"***** vDataFile::CheckParameters() -> Data type incorrectly initialized !" << endl);
358 Cerr(
"***** vDataFile::CheckParameters() -> Data physical property incorrectly initialized !" << endl);
363 Cerr(
"***** vDataFile::CheckParameters() -> Bed position index incorrectly initialized !" << endl);
368 Cerr(
"***** vDataFile::CheckParameters() -> Verbosity incorrectly initialized !" << endl);
374 Cerr(
"***** vDataFile::CheckParameters() -> Error while checking specific parameters !" << endl);
390 if (
m_verbose>=
VERBOSE_DETAIL)
Cout(
"vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Check consistency between this and the provided datafiles" << endl);
394 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Data types are inconsistent !" << endl);
400 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Data modes are inconsistent !" << endl);
406 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Total number of events are inconsistent !" << endl);
412 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Scanner names are inconsistent !" << endl);
418 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Calibration factors are inconsistent !" << endl);
424 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Events sizes are inconsistent !" << endl);
430 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> POI flags are inconsistent !" << endl);
438 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> POI resolutions are inconsistent !" << endl);
444 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Bed relative positions must be provided for all beds or not at all !" << endl);
450 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Inconsistency detected for specific characteristics !" << endl);
471 Cerr(
"***** vDataFile::InitializeMappedFile() -> A problem occured while checking file size consistency !" << endl);
480 Cerr(
"***** vDataFile::InitializeMappedFile() -> Failed to open data file '" <<
m_dataFileName <<
"' !" << endl);
515 Cout(
"vDataFile::Describe() -> Here is some generic content of the datafile" << endl);
542 Cerr(
"***** vDataFile::OpenFileForWriting() -> Output data file is already open !" << endl);
565 Cerr(
"***** vDataFile::OpenFileForWriting() -> Failed to create output file '" <<
m_dataFileName <<
"' !" << endl);
584 if (
m_verbose>=2)
Cout(
"vDataFile::CloseFile() -> Closing output binary data file" << endl);
626 if (
m_verbose >=2)
Cout(
"vDataFile::Shuffle() : Everyday I shuffle in... " << endl);
628 int64_t *rndmIdx =
new int64_t[ nb_events_to_load ];
629 std::iota( rndmIdx, rndmIdx + nb_events_to_load, 0 );
632 std::random_device rd;
633 std::mt19937 rndm( rd() );
634 rndm.seed( 1100001001 );
637 std::shuffle( rndmIdx, rndmIdx + nb_events_to_load, rndm );
640 char *mp_arrayEvents_tmp =
new char[ nb_events_to_load*
m_sizeEvent ];
643 for( int64_t i = 0; i < nb_events_to_load; ++i )
648 mp_arrayEvents_tmp[ i * m_sizeEvent + j ] =
mp_mappedMemory[ rndmIdx[ i ] * m_sizeEvent + j ];
690 else *ap_indexStart =
m_mpi1stEvent + (a_nbSubsets - modulo);
705 Cerr(
"*****vDataFile::GetMaxRingDiff() -> This function is not implemented for the used system" << endl);
706 Cerr(
" (this error may be prompted if the present function is erroneously called for a SPECT system)" << endl);
744 ofstream merged_file(
m_dataFileName.c_str(), ios::out | ios::binary | ios::app);
750 stringstream ss; ss << th;
752 file_name.append(
"_").append(ss.str());
757 ifstream data_file(file_name.c_str(), ios::binary | ios::in);
762 Cerr(
"***** vDataFile::PROJ_WriteData() -> Input temporary thread file '" << file_name <<
"' is missing or corrupted !" << endl);
767 merged_file << data_file.rdbuf();
772 m2p_dataFile[th]->open( file_name.c_str(), ios::binary | ios::out | ios::trunc);
795 stringstream ss; ss << th;
800 file_name.append(
"_").append(ss.str());
803 ifstream fcheck(file_name.c_str());
808 string dos_instruction =
"del " + file_name;
809 system(dos_instruction.c_str());
811 remove(file_name.c_str());
843 string data_type =
"";
847 else data_type =
"unknown";
859 string data_mode =
"";
863 else data_mode =
"unknown";
875 string data_spec =
"";
878 else data_spec =
"unknown";
#define KEYWORD_OPTIONAL_SUCCESS
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)
Compute the index start and stop of the events loop with respect to the current subset and MPI size a...
#define VERBOSE_DEBUG_EVENT
void SetNbLines(uint16_t a_value)
Set the number of lines of the Event.
bool mp_POIDirectionFlag[3]
virtual vEvent * GetEventSpecific(char *ap_buffer, int a_th)=0
This function is implemented in child classes Read an event from the position pointed by 'ap_buffer...
#define MODE_NORMALIZATION
int CheckParameters()
Check the initialization of member variables Call the CheckSpecificParameters() function implemente...
FLTNB GetCalibrationFactor()
int GetNb1stMotImgsForLMS(int a_fr)
call the eponym function from the oDynamicDataManager object
virtual int CheckFileSizeConsistency()=0
int SetParametersFrom(vDataFile *ap_DataFile)
Initialize all parameters from the provided datafile.
oMemoryMapped * mp_MappedFile
int ReadInfoInHeader(bool a_affectQuantificationFlag=true)
Read and check general information from the header datafile Call the ReadSpecificInformationInHeade...
int SetCalibrationFactor(int a_bed, FLTNB a_calibrationFactor)
Set the calibration factor for the provided bed.
virtual int CheckSpecificConsistencyWithAnotherDataFile(vDataFile *ap_DataFile)=0
Check consistency between 'this' and the provided datafile, for specific characteristics.
int CheckConsistencyWithAnotherBedDataFile(vDataFile *ap_DataFile)
Check consistency between 'this' and the provided datafile as two bed positions.
string GetDataSpecToString()
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
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 Open(const std::string &filename, size_t mappedBytes=WholeFile, CacheHint hint=Normal)
open file, mappedBytes = 0 maps the whole file
int InitializeMappedFile()
Check the datafile existency, map it to memory and get the raw char* pointer. .
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.
const string & GetPathName()
#define VERBOSE_DEBUG_LIGHT
virtual int CheckSpecificParameters()=0
This function is implemented in child classes Check specific parameters of child classes...
bool * GetPOIDirectionFlag()
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
vDataFile()
vDataFile constructor.
Declaration of class vDataFile.
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...
int GetMPISize()
Get the MPI size (the number of MPI instances)
everything ... be careful when file is larger than memory
bool GetBedPositionFlag()
oImageDimensionsAndQuantification * mp_ID
virtual int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag=true)=0
This function is implemented in child classes Read and check modality-specific information from the...
FLTNB m_relativeBedPosition
FLTNB * GetPOIResolution()
int OpenFileForWriting(string a_suffix="")
Open a binary file stream for writing, with eventually the suffix appended to the file name...
vEvent * PROJ_GenerateEvent(int idx_elt1, int idx_elt2, int a_th)
Generate a standard event and set up its ID Used by the projection, list-mode sensitivity generatio...
virtual void DescribeSpecific()=0
A pure virtual function used to describe the specific parts of the datafile.
#define KEYWORD_MANDATORY
#define SPEC_TRANSMISSION
const unsigned char * GetData() const
raw access
FLTNB mp_POIResolution[3]
void SetID2(int a_line, uint32_t a_value)
Set the indice associated with the line index for the 2nd ID of the Event.
const string & GetBaseName()
Mother class for the Event objects.
int GetNbTimeFrames()
Get the number of time frames.
vEvent ** m2p_BufferEvent
FLTNB GetRelativeBedPosition()
int GetNb2ndMotImgsForLMS()
call the eponym function from the oDynamicDataManager object
void Describe()
A function used to describe the generic parts of the datafile.
int SetAcquisitionTime(int a_bed, FLTNB a_timeStartInSec, FLTNB a_durationInSec)
Set the acquisition time if not already set by the SetTimeFrames()
int GetNbThreadsForProjection()
Get the number of threads used for projections.
string GetDataTypeToString()
#define DEBUG_VERBOSE(IGNORED1, IGNORED2)
virtual int SetSpecificParametersFrom(vDataFile *ap_DataFile)=0
This function is implemented in child classes Initialize all specific parameters from the provided ...
Portable read-only memory mapping (Windows and Linux)
FLTNB m_calibrationFactor
int PROJ_DeleteTmpDataFile()
Delete temporary datafile used for multithreaded output writing if needed.
int GetVerbose()
Get the verbose level.
virtual int Shuffle(int64_t)
!!!\ This function has been modified to be used specifically with a
int GetMPIRank()
Get the MPI instance number (the rank)
string GetDataModeToString()
#define VERBOSE_DEBUG_NORMAL
void SetID1(int a_line, uint32_t a_value)
Set the indice associated with the line index for the 1st ID of the Event.