9 #include "vDataFile.hh" 111 if (a_affectQuantificationFlag &&
mp_ID==NULL)
113 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Image dimensions and quantification object has not been set while it is asked to affect" << endl);
114 Cerr(
" its parameters from information read into the header !" << endl);
121 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read number of events in the header data file !" << endl);
126 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read scanner name in the header data file !" << endl);
133 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read data filename in the header data file !" << endl);
148 string data_mode =
"";
151 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read data mode in the header data file !" << endl);
154 if ( data_mode==
"LIST" || data_mode==
"LISTMODE" || data_mode==
"LIST-MODE" ||
155 data_mode==
"list" || data_mode==
"listmode" || data_mode==
"list-mode" || data_mode==
"0" )
m_dataMode =
MODE_LIST;
156 else if ( data_mode==
"HISTOGRAM" || data_mode==
"histogram" || data_mode==
"Histogram" ||
158 else if ( data_mode==
"NORMALIZATION" || data_mode==
"normalization" || data_mode==
"Normalization" ||
162 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Unknown data mode '" << data_mode <<
"' found in header file !" << endl);
167 string data_type =
"";
170 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read data type in the header data file !" << endl);
173 if ( data_type==
"PET" || data_type==
"pet" || data_type==
"0" )
178 else if ( data_type==
"SPECT" || data_type==
"spect" || data_type==
"1" )
183 else if ( data_type==
"CT" || data_type==
"ct" || data_type==
"2" )
190 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Unknown data type '" << data_type <<
"' found in header file !" << endl);
199 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read acquisition start time in the header data file !" << endl);
204 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read acquisition stop time in the header data file !" << endl);
212 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading acquisition start time in the header data file !" << endl);
217 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading acquisition stop time in the header data file !" << endl);
222 string gate_list_durations_in_sec =
"";
225 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading acquisition gate duration in the header data file !" << endl);
233 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while passing acquisition start and stop time to the ImageDimensionsAndQuantification !" << endl);
242 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading the 'Bed relative position (mm)' field in the data file header !" << endl);
251 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading optional field in the header data file !" << endl);
258 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read modality-specific informations from the header data file !" << endl);
265 Cerr(
"***** vDataFile::ReadSpecificInfoInHeader() -> A problem occurred while setting the calibration factor to oImageDimensionsAndQuantification !" << endl);
271 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading 'Custom INT data' field in the header data file !" << endl);
277 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading 'Custom FLT data' field in the header data file !" << endl);
294 Cerr(
"!!!!! vDataFile::InitializeAdditionalData() -> Additional data already loaded; do nothing." << endl);
300 if (a_pathToAdditionalData!=
"")
303 int already_existing_additional_data = 0;
306 vector<string> p_file_names;
307 string list_of_names = a_pathToAdditionalData;
308 size_t comma = list_of_names.find_first_of(
",");
310 while (comma!=string::npos)
313 p_file_names.push_back(list_of_names.substr(0,comma));
315 list_of_names = list_of_names.substr(comma+1);
317 comma = list_of_names.find_first_of(
",");
320 p_file_names.push_back(list_of_names);
322 int nb_additional_data_to_read = p_file_names.size();
326 if (already_existing_additional_data>1)
338 for (
int nb=0; nb<nb_additional_data_to_read; nb++)
341 if (
m_verbose>=3)
Cout(
"vDataFile::InitializeAdditionalData() -> From file '" << p_file_names.at(nb) <<
"'"<< endl);
343 INTNB nb_tof_bins_in_additional_data = 1;
344 string tof_bin_key_word =
"Histo TOF number of bins";
347 Cerr(
"***** vDataFile::InitializeAdditionalData() -> An error occured while searching for the optional '" << tof_bin_key_word <<
"' keyword !" << endl);
357 Cerr(
"***** vDataFile::InitializeAdditionalData() -> Error reading interfile additional data '" << p_file_names.at(nb) <<
"' !" << endl);
377 if (
m_verbose>=
VERBOSE_DETAIL)
Cout(
"vDataFile::GetNewAdditionalDataMatrix() -> Create a new additional data matrix with " << a_nbDataPerEvent <<
" data per event" << endl);
434 Cerr(
"***** vDataFile::SetParametersFrom() -> An error occurred while setting specific parameters fro mthe provided datafile !" << endl);
454 Cerr(
"***** vDataFile::CheckParameters() -> ImageDimensionsAndQuantification object not initialized !" << endl);
459 Cerr(
"***** vDataFile::CheckParameters() -> String containing path to header file not initialized !" << endl);
464 Cerr(
"***** vDataFile::CheckParameters() -> String containing path to raw data file not initialized !" << endl);
469 Cerr(
"***** vDataFile::CheckParameters() -> Number of events incorrectly initialized !" << endl);
474 Cerr(
"***** vDataFile::CheckParameters() -> Data mode incorrectly initialized !" << endl);
479 Cerr(
"***** vDataFile::CheckParameters() -> Acquisition duration (s) incorrectly initialized !" << endl);
484 Cerr(
"***** vDataFile::CheckParameters() -> Data type incorrectly initialized !" << endl);
489 Cerr(
"***** vDataFile::CheckParameters() -> Data physical property incorrectly initialized !" << endl);
494 Cerr(
"***** vDataFile::CheckParameters() -> Bed position index incorrectly initialized !" << endl);
499 Cerr(
"***** vDataFile::CheckParameters() -> Verbosity incorrectly initialized !" << endl);
505 Cerr(
"***** vDataFile::CheckParameters() -> Error while checking specific parameters !" << endl);
521 if (
m_verbose>=
VERBOSE_DETAIL)
Cout(
"vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Check consistency between this and the provided datafiles" << endl);
525 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Data types are inconsistent !" << endl);
531 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Data modes are inconsistent !" << endl);
537 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Total number of events are inconsistent !" << endl);
543 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Scanner names are inconsistent !" << endl);
549 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Calibration factors are inconsistent !" << endl);
555 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Events sizes are inconsistent !" << endl);
561 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> POI flags are inconsistent !" << endl);
569 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> POI resolutions are inconsistent !" << endl);
575 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Bed relative positions must be provided for all beds or not at all !" << endl);
581 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Number of additional data files are inconsistent !" << endl);
587 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Inconsistency detected for specific characteristics !" << endl);
608 Cerr(
"***** vDataFile::InitializeMappedFile() -> A problem occurred while checking file size consistency !" << endl);
617 Cerr(
"***** vDataFile::InitializeMappedFile() -> Failed to open data file '" <<
m_dataFileName <<
"' !" << endl);
652 Cout(
"vDataFile::Describe() -> Here is some generic content of the datafile" << endl);
679 Cerr(
"***** vDataFile::OpenFileForWriting() -> Output data file is already open !" << endl);
702 Cerr(
"***** vDataFile::OpenFileForWriting() -> Failed to create output file '" <<
m_dataFileName <<
"' !" << endl);
721 if (
m_verbose>=2)
Cout(
"vDataFile::CloseFile() -> Closing output binary data file" << endl);
765 if (
m_verbose >=2)
Cout(
"vDataFile::Shuffle() : Everyday I shuffle in... " << endl);
767 int64_t *rndmIdx =
new int64_t[ nb_events_to_load ];
768 std::iota( rndmIdx, rndmIdx + nb_events_to_load, 0 );
771 std::random_device rd;
772 std::mt19937 rndm( rd() );
773 rndm.seed( 1100001001 );
776 std::shuffle( rndmIdx, rndmIdx + nb_events_to_load, rndm );
779 char *mp_arrayEvents_tmp =
new char[ nb_events_to_load*
m_sizeEvent ];
782 for( int64_t i = 0; i < nb_events_to_load; ++i )
787 mp_arrayEvents_tmp[ i * m_sizeEvent + j ] =
mp_mappedMemory[ rndmIdx[ i ] * m_sizeEvent + j ];
829 else *ap_indexStart =
m_mpi1stEvent + (a_nbSubsets - modulo);
844 Cerr(
"*****vDataFile::GetMaxRingDiff() -> This function is not implemented for the used system" << endl);
845 Cerr(
" (this error may be prompted if the present function is erroneously called for a SPECT system)" << endl);
883 ofstream merged_file(
m_dataFileName.c_str(), ios::out | ios::binary | ios::app);
889 stringstream ss; ss << th;
891 file_name.append(
"_").append(ss.str());
896 ifstream data_file(file_name.c_str(), ios::binary | ios::in);
901 Cerr(
"***** vDataFile::PROJ_WriteData() -> Input temporary thread file '" << file_name <<
"' is missing or corrupted !" << endl);
906 merged_file << data_file.rdbuf();
911 m2p_dataFile[th]->open( file_name.c_str(), ios::binary | ios::out | ios::trunc);
934 stringstream ss; ss << th;
939 file_name.append(
"_").append(ss.str());
942 ifstream fcheck(file_name.c_str());
947 string dos_instruction =
"del " + file_name;
948 system(dos_instruction.c_str());
950 remove(file_name.c_str());
982 string data_type =
"";
986 else data_type =
"unknown";
998 string data_mode =
"";
1002 else data_mode =
"unknown";
1014 string data_spec =
"";
1017 else data_spec =
"unknown";
everything ... be careful when file is larger than memory
#define KEYWORD_OPTIONAL_SUCCESS
This class is designed to be a mother virtual class for DataFile.
INTNB * mp_additionalDataSize
void GetEventIndexStartAndStop(int64_t *ap_indexStart, int64_t *ap_indexStop, int a_subsetNum=0, int a_NbSubsets=1)
void SetNbLines(uint16_t a_value)
void SetEventIndex(int a_eventIndex)
Set current index associated to the event.
#define MODE_NORMALIZATION
int IntfReadAdditionalData(const string &a_pathToHeaderFile, FLTNB *ap_DataMatrix, int64_t a_matrixSize, int vb)
Main function dedicated to Interfile 3D additional data loading.
int CheckParameters()
Check the initialization of member variables Call the CheckSpecificParameters() function implemente...
oMemoryMapped * mp_MappedFile
FLTNB GetCalibrationFactor()
FLTNB ** m2p_additionalData
virtual int CheckFileSizeConsistency()=0
int SetParametersFrom(vDataFile *ap_DataFile)
int ReadInfoInHeader(bool a_affectQuantificationFlag=true)
int SetCalibrationFactor(int a_bed, FLTNB a_calibrationFactor)
virtual int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag=true)=0
int CheckConsistencyWithAnotherBedDataFile(vDataFile *ap_DataFile)
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
FLTNB mp_POIResolution[3]
int InitializeMappedFile()
Check the datafile existency, map it to memory and get the raw char* pointer. .
virtual int CheckSpecificConsistencyWithAnotherDataFile(vDataFile *ap_DataFile)=0
FLTNB * GetNewAdditionalDataMatrix(INTNB a_nbDataPerEvent)
Allocate the memory for this additional data matrix and return the pointer to the matrix...
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 DEBUG_VERBOSE(IGNORED1, IGNORED2)
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.
int GetMPISize()
Get the MPI size (the number of MPI instances)
bool GetBedPositionFlag()
vEvent ** m2p_BufferEvent
FLTNB m_relativeBedPosition
FLTNB * GetPOIResolution()
int OpenFileForWriting(string a_suffix="")
vEvent * PROJ_GenerateEvent(int idx_elt1, int idx_elt2, int a_th)
virtual void DescribeSpecific()=0
A pure virtual function used to describe the specific parts of the datafile.
#define KEYWORD_MANDATORY
int GetNbAdditionalData()
Get the number of additional data.
#define VERBOSE_DEBUG_NORMAL
#define SPEC_TRANSMISSION
void SetID2(int a_line, uint32_t a_value)
int GetNb1stMotImgsForLMS(int a_fr)
const string & GetBaseName()
int InitializeAdditionalData(const string &a_pathToAdditionalData)
Memory allocation and initialization for the additional data matrices.
bool mp_POIDirectionFlag[3]
Mother class for the Event objects.
int GetNbTimeFrames()
Get the number of time frames.
FLTNB GetRelativeBedPosition()
int GetNb2ndMotImgsForLMS()
call the eponym function from the oDynamicDataManager object
const unsigned char * GetData() const
raw access
void Describe()
A function used to describe the generic parts of the datafile.
int GetNbThreadsForProjection()
Get the number of threads used for projections.
string GetDataTypeToString()
virtual vEvent * GetEventSpecific(char *ap_buffer, int a_th)=0
Portable read-only memory mapping (Windows and Linux)
FLTNB m_calibrationFactor
int PROJ_DeleteTmpDataFile()
Delete temporary datafile used for multithreaded output writing if needed.
#define VERBOSE_DEBUG_LIGHT
int GetVerbose()
Get the verbose level.
virtual int Shuffle(int64_t)
!!!\ This function has been modified to be used specifically with a
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 SetAcquisitionTime(int a_bed, FLTNB a_timeStartInSec, FLTNB a_durationInSec, string a_GateListDurationsInSec)
virtual int SetSpecificParametersFrom(vDataFile *ap_DataFile)=0
int GetMPIRank()
Get the MPI instance number (the rank)
string GetDataModeToString()
#define KEYWORD_OPTIONAL_ERROR
#define VERBOSE_DEBUG_EVENT
oImageDimensionsAndQuantification * mp_ID
void SetID1(int a_line, uint32_t a_value)