114 Cout(
"vDataFile::~vDataFile() -> Number of events directly read from file for each thread" << endl);
121 Cout(
" --> Total number of events read from file: " << total << endl);
141 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read number of events in the header data file !" << endl);
146 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read scanner name in the header data file !" << endl);
153 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read data filename in the header data file !" << endl);
168 string data_mode =
"";
171 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read data mode in the header data file !" << endl);
174 if ( data_mode==
"LIST" || data_mode==
"LISTMODE" || data_mode==
"LIST-MODE" ||
175 data_mode==
"list" || data_mode==
"listmode" || data_mode==
"list-mode" || data_mode==
"0" )
m_dataMode =
MODE_LIST;
176 else if ( data_mode==
"HISTOGRAM" || data_mode==
"histogram" || data_mode==
"Histogram" ||
178 else if ( data_mode==
"NORMALIZATION" || data_mode==
"normalization" || data_mode==
"Normalization" ||
182 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Unknown data mode '" << data_mode <<
"' found in header file !" << endl);
187 string data_type =
"";
190 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read data type in the header data file !" << endl);
195 else if ( data_type==
"TRANSMISSION" || data_type==
"transmission" || data_type==
"Transmission" ||
199 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Unknown data type '" << data_type <<
"' found in header file !" << endl);
208 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read acquisition start time in the header data file !" << endl);
213 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read acquisition stop time in the header data file !" << endl);
221 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading acquisition start time in the header data file !" << endl);
226 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading acquisition stop time in the header data file !" << endl);
234 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while passing acquisition start and stop time to the ImageDimensionsAndQuantification !" << endl);
243 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading optional field in the header data file !" << endl);
250 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read modality-specific informations from the header data file !" << endl);
257 Cerr(
"***** vDataFile::ReadSpecificInfoInHeader() -> A problem occured while setting the calibration factor to oImageDimensionsAndQuantification !" << endl);
272 if(
m_verbose >=3)
Cout(
"vDataFile::CheckParameters() ..." << endl);
276 Cerr(
"***** vDataFile::CheckParameters() -> Error : ImageDimensionsAndQuantification object not initialized !" << endl);
281 Cerr(
"***** vDataFile::CheckParameters() -> Error : string containing path to header file not initialized !" << endl);
286 Cerr(
"***** vDataFile::CheckParameters() -> Error : string containing path to raw data file not initialized !" << endl);
289 if (m_percentageLoad<0 || m_percentageLoad>100)
291 Cerr(
"***** vDataFile::CheckParameters() -> Percentage load of the data file incorrectly set !" << endl);
296 Cerr(
"***** vDataFile::CheckParameters() -> Number of events incorrectly initialized !" << endl);
301 Cerr(
"***** vDataFile::CheckParameters() -> Data mode incorrectly initialized !" << endl);
306 Cerr(
"***** vDataFile::CheckParameters() -> Acquisition duration (s) incorrectly initialized !" << endl);
311 Cerr(
"***** vDataFile::CheckParameters() -> Data type incorrectly initialized !" << endl);
316 Cerr(
"***** vDataFile::CheckParameters() -> Bed position index incorrectly initialized !" << endl);
321 Cerr(
"***** vDataFile::CheckParameters() -> Verbosity incorrectly initialized !" << endl);
327 Cerr(
"***** vDataFile::CheckParameters() -> Error while checking specific parameters !" << endl);
344 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDatafile() -> Data types are inconsistent !" << endl);
350 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDatafile() -> Data modes are inconsistent !" << endl);
356 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDatafile() -> Total number of events are inconsistent !" << endl);
362 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDatafile() -> Scanner names are inconsistent !" << endl);
368 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDatafile() -> Bed displacement between two successive bed positions must be strictly positive !" << endl);
374 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDatafile() -> Calibration factors are inconsistent !" << endl);
380 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDatafile() -> Events sizes are inconsistent !" << endl);
386 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDatafile() -> POI flags are inconsistent !" << endl);
394 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDatafile() -> POI resolutions are inconsistent !" << endl);
400 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDatafile() -> Inconsistency detected for specific characteristics !" << endl);
414 if (
m_verbose>=3)
Cout(
"vDataFile::InitializeFile() ..." << endl);
424 Cerr(
"***** vDataFile::InitializeFile() -> Error reading the input data file at the path: '" <<
m_dataFileName.c_str() <<
"'" << endl);
432 Cerr(
"***** vDataFile::InitializeFile() -> A problem occured while checking file size consistency !" << endl);
468 Cout(
" --> Allocating memory for the datafile" << endl);
469 Cout(
" --> Number of events in memory: " << m_mpiNbEvents << endl);
515 #ifdef CASTOR_VERBOSE
516 if (
m_verbose >=4)
Cout(
"vDataFile::FillBuffer() ..." << endl);
528 int64_t last_included_event_that_can_be_loaded = a_eventIndex +
m_sizeArrayEvents - 1;
531 int64_t nb_events_to_load = 0;
546 Cerr(
"***** vDataFile::FillBuffer() -> Failed to read " << nb_events_to_load <<
" events in datafile (only read " <<
m2p_dataFile[thread_0]->gcount() <<
" events) !" << endl);
555 #ifdef CASTOR_VERBOSE
556 if (
m_verbose >=4)
Cout(
"vDataFile::FillBuffer() completed" << endl);
619 #ifdef CASTOR_VERBOSE
620 if (
m_verbose >=4)
Cout(
"vDataFile::GetEventWithAscendingOrderAssumption() ..." << endl);
632 Cerr(
"***** vDataFile::GetEventWithAscendingOrderAssumption() -> The requested event index is below the current range of indices loaded in memory !" << endl);
633 Cerr(
" --> Note that this situation should never happen if this function is being called within an ascending ordered loop on event indices, AND if" << endl);
634 Cerr(
" the vDataFile::ResetBufferRange() function has been called before performing the loop. So if this is really the case, then please report" << endl);
635 Cerr(
" the bug." << endl);
642 bool all_threads_over_range =
true;
645 while (!all_threads_over_range)
647 all_threads_over_range =
true;
657 Cerr(
"***** vDataFile::GetEventWithAscendingOrderAssumption() -> An error occured while filling the buffer from datafile !" << endl);
760 #ifdef CASTOR_VERBOSE
761 if (
m_verbose >=4)
Cout(
"vDataFile::GetEventWithoutOrderAssumption() ..." << endl);
778 bool all_threads_not_reading_buffer =
true;
781 while (!all_threads_not_reading_buffer)
783 all_threads_not_reading_buffer =
true;
793 Cerr(
"***** vDataFile::GetEventWithoutOrderAssumption() -> An error occured while filling the buffer from datafile !" << endl);
851 #ifdef CASTOR_VERBOSE
852 if (
m_verbose >=4)
Cout(
"vDataFile::GetEventFromFile() ..." << endl);
861 Cerr(
"***** vDataFile::GetEventFromFile() -> Failed to read one event in datafile !" << endl);
875 #ifdef CASTOR_VERBOSE
876 if (
m_verbose >=4)
Cout(
"vDataFile::GetEventIndexStartAndStop() ..." << endl);
894 else *ap_indexStart =
m_mpi1stEvent + (a_nbSubsets - modulo);
908 Cerr(
"*****vDataFile::GetMaxRingDiff() ->This function is not implemented for the used system" << endl);
909 Cerr(
" (this error may be prompted if the present function is erroneously called for a SPECT system)" << endl);
930 if (
m_verbose >=2)
Cout(
"vDataFile::PROJ_WriteData() ..." << endl);
957 ofstream merged_file(
m_dataFileName.c_str(), ios::out | ios::binary | ios::app);
963 stringstream ss; ss << th;
965 file_name.append(
"_").append(ss.str());
970 ifstream data_file(file_name.c_str(), ios::binary | ios::in);
975 Cerr(
"***** vDataFile::PROJ_ConcatenateMthDatafile() -> Input temporary thread file '" << file_name <<
"' is missing or corrupted !" << endl);
980 merged_file << data_file.rdbuf();
985 m2p_dataFile[th]->open( file_name.c_str(), ios::binary | ios::out | ios::trunc);
1010 if (
m_verbose >=3)
Cout(
"vDataFile::PROJ_DeleteTmpDatafile() ..." << endl);
1016 stringstream ss; ss << th;
1021 file_name.append(
"_").append(ss.str());
1024 ifstream fcheck(file_name.c_str());
1029 string dos_instruction =
"del " + file_name;
1030 system(dos_instruction.c_str());
1032 remove(file_name.c_str());
1058 #ifdef CASTOR_VERBOSE
1059 if (
m_verbose >=4)
Cout(
"vDataFile::PROJ_GenerateEvent() ..." << endl);
This class is designed to be a mother virtual class for Datafile.
static sScannerManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
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...
void SetNbLines(uint16_t a_value)
Set the number of lines of the Event.
bool mp_POIDirectionFlag[3]
vEvent * GetEventWithoutOrderAssumption(int64_t a_eventIndex, int a_th)
According to the current part of the datafile loaded in memory, either read from this buffer or direc...
#define MODE_NORMALIZATION
int CheckParameters()
Check the initialization of member variables Call the CheckSpecificParameters() function implemente...
virtual vEvent * GetEventFromBuffer(char *ap_buffer, int a_th)=0
This function is implemented in child classes Read an event from the position pointed by 'ap_buffer...
FLTNB GetCalibrationFactor()
bool * mp_overBufferRange
int64_t m_1stIdxArrayEvents
virtual int CheckFileSizeConsistency()=0
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.
#define TYPE_TRANSMISSION
bool m_requestBufferFilling
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 PROJ_WriteData()
Write/Merge chunk of data in a general data file.
int64_t m_sizeArrayEvents
virtual int CheckSpecificParameters()=0
This function is implemented in child classes Check specific parameters of child classes...
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...
void ResetBufferRange()
Simply set the m_1stIdxArrayEvents and m_lastIdxArrayEvents to -1 only if the percentage load is stri...
int GetMPISize()
Get the MPI size (the number of MPI instances)
oImageDimensionsAndQuantification * mp_ID
int GetSensNbRespGates()
call the eponym function from the oDynamicDataManager object
int CheckConsistencyWithAnotherBedDatafile(vDataFile *ap_Datafile)
Check consistency between 'this' and the provided datafile as two bed positions.
virtual int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag=true)=0
This function is implemented in child classes Read and check modality-specific information from the...
FLTNB * GetPOIResolution()
int64_t * mp_nbEventsReadFromFile
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...
int PROJ_DeleteTmpDatafile()
Delete temporary datafile used for multithreaded output writing if needed.
vEvent * GetEventWithAscendingOrderAssumption(int64_t a_eventIndex, int64_t a_eventIndexLimit, int a_th)
According to the current part of the datafile loaded in memory, either read from this buffer or direc...
#define KEYWORD_MANDATORY
vEvent * GetEventFromFile(int64_t a_eventIndex, int a_th)
Return the a_eventIndex event from the datafile.
bool m_currentlyFillingBuffer
virtual int CheckSpecificConsistencyWithAnotherDatafile(vDataFile *ap_Datafile)=0
Check consistency between 'this' and the provided datafile, for specific characteristics.
int FillBuffer(int64_t a_eventIndex)
Fill 'mp_arrayEvents' from the 'a_eventIndex' position in the data file. The filling process stops ...
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.
bool * mp_currentlyReadingBuffer
Mother class for the Event objects.
int GetNbTimeFrames()
Get the number of time frames.
vEvent ** m2p_BufferEvent
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.
int InitializeFile()
Instantiate the fstream objets for input reading and check if the related datafile's existence and co...
char ** m2p_bufferEventFromFile
FLTNB m_calibrationFactor
int64_t m_lastIdxArrayEvents
virtual int Shuffle(int64_t)
int GetMPIRank()
Get the MPI instance number (the rank)
void SetID1(int a_line, uint32_t a_value)
Set the indice associated with the line index for the 1st ID of the Event.