9 #include "vDataFile.hh" 94 if (a_affectQuantificationFlag &&
mp_ID==NULL)
96 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Image dimensions and quantification object has not been set while it is asked to affect" << endl);
97 Cerr(
" its parameters from information read into the header !" << endl);
104 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read number of events in the header data file !" << endl);
109 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read scanner name in the header data file !" << endl);
116 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read data filename in the header data file !" << endl);
131 string data_mode =
"";
134 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read data mode in the header data file !" << endl);
137 if ( data_mode==
"LIST" || data_mode==
"LISTMODE" || data_mode==
"LIST-MODE" ||
138 data_mode==
"list" || data_mode==
"listmode" || data_mode==
"list-mode" || data_mode==
"0" )
m_dataMode =
MODE_LIST;
139 else if ( data_mode==
"HISTOGRAM" || data_mode==
"histogram" || data_mode==
"Histogram" ||
141 else if ( data_mode==
"NORMALIZATION" || data_mode==
"normalization" || data_mode==
"Normalization" ||
145 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Unknown data mode '" << data_mode <<
"' found in header file !" << endl);
150 string data_type =
"";
153 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read data type in the header data file !" << endl);
156 if ( data_type==
"PET" || data_type==
"pet" || data_type==
"0" )
161 else if ( data_type==
"SPECT" || data_type==
"spect" || data_type==
"1" )
166 else if ( data_type==
"CT" || data_type==
"ct" || data_type==
"2" )
173 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Unknown data type '" << data_type <<
"' found in header file !" << endl);
182 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read acquisition start time in the header data file !" << endl);
187 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read acquisition stop time in the header data file !" << endl);
195 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading acquisition start time in the header data file !" << endl);
200 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading acquisition stop time in the header data file !" << endl);
205 string gate_list_durations_in_sec =
"";
208 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading acquisition gate duration in the header data file !" << endl);
216 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while passing acquisition start and stop time to the ImageDimensionsAndQuantification !" << endl);
225 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading the 'Bed relative position (mm)' field in the data file header !" << endl);
234 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while reading optional field in the header data file !" << endl);
241 Cerr(
"***** vDataFile::ReadInfoInHeader() -> Error while trying to read modality-specific informations from the header data file !" << endl);
248 Cerr(
"***** vDataFile::ReadSpecificInfoInHeader() -> A problem occurred while setting the calibration factor to oImageDimensionsAndQuantification !" << endl);
288 Cerr(
"***** vDataFile::SetParametersFrom() -> An error occurred while setting specific parameters fro mthe provided datafile !" << endl);
308 Cerr(
"***** vDataFile::CheckParameters() -> ImageDimensionsAndQuantification object not initialized !" << endl);
313 Cerr(
"***** vDataFile::CheckParameters() -> String containing path to header file not initialized !" << endl);
318 Cerr(
"***** vDataFile::CheckParameters() -> String containing path to raw data file not initialized !" << endl);
323 Cerr(
"***** vDataFile::CheckParameters() -> Number of events incorrectly initialized !" << endl);
328 Cerr(
"***** vDataFile::CheckParameters() -> Data mode incorrectly initialized !" << endl);
333 Cerr(
"***** vDataFile::CheckParameters() -> Acquisition duration (s) incorrectly initialized !" << endl);
338 Cerr(
"***** vDataFile::CheckParameters() -> Data type incorrectly initialized !" << endl);
343 Cerr(
"***** vDataFile::CheckParameters() -> Data physical property incorrectly initialized !" << endl);
348 Cerr(
"***** vDataFile::CheckParameters() -> Bed position index incorrectly initialized !" << endl);
353 Cerr(
"***** vDataFile::CheckParameters() -> Verbosity incorrectly initialized !" << endl);
359 Cerr(
"***** vDataFile::CheckParameters() -> Error while checking specific parameters !" << endl);
375 if (
m_verbose>=
VERBOSE_DETAIL)
Cout(
"vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Check consistency between this and the provided datafiles" << endl);
379 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Data types are inconsistent !" << endl);
385 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Data modes are inconsistent !" << endl);
391 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Total number of events are inconsistent !" << endl);
397 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Scanner names are inconsistent !" << endl);
403 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Calibration factors are inconsistent !" << endl);
409 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Events sizes are inconsistent !" << endl);
415 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> POI flags are inconsistent !" << endl);
423 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> POI resolutions are inconsistent !" << endl);
429 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Bed relative positions must be provided for all beds or not at all !" << endl);
435 Cerr(
"***** vDataFile::CheckConsistencyWithAnotherBedDataFile() -> Inconsistency detected for specific characteristics !" << endl);
456 Cerr(
"***** vDataFile::InitializeMappedFile() -> A problem occurred while checking file size consistency !" << endl);
465 Cerr(
"***** vDataFile::InitializeMappedFile() -> Failed to open data file '" <<
m_dataFileName <<
"' !" << endl);
500 Cout(
"vDataFile::Describe() -> Here is some generic content of the datafile" << endl);
527 Cerr(
"***** vDataFile::OpenFileForWriting() -> Output data file is already open !" << endl);
550 Cerr(
"***** vDataFile::OpenFileForWriting() -> Failed to create output file '" <<
m_dataFileName <<
"' !" << endl);
569 if (
m_verbose>=2)
Cout(
"vDataFile::CloseFile() -> Closing output binary data file" << endl);
611 if (
m_verbose >=2)
Cout(
"vDataFile::Shuffle() : Everyday I shuffle in... " << endl);
613 int64_t *rndmIdx =
new int64_t[ nb_events_to_load ];
614 std::iota( rndmIdx, rndmIdx + nb_events_to_load, 0 );
617 std::random_device rd;
618 std::mt19937 rndm( rd() );
619 rndm.seed( 1100001001 );
622 std::shuffle( rndmIdx, rndmIdx + nb_events_to_load, rndm );
625 char *mp_arrayEvents_tmp =
new char[ nb_events_to_load*
m_sizeEvent ];
628 for( int64_t i = 0; i < nb_events_to_load; ++i )
633 mp_arrayEvents_tmp[ i * m_sizeEvent + j ] =
mp_mappedMemory[ rndmIdx[ i ] * m_sizeEvent + j ];
675 else *ap_indexStart =
m_mpi1stEvent + (a_nbSubsets - modulo);
690 Cerr(
"*****vDataFile::GetMaxRingDiff() -> This function is not implemented for the used system" << endl);
691 Cerr(
" (this error may be prompted if the present function is erroneously called for a SPECT system)" << endl);
729 ofstream merged_file(
m_dataFileName.c_str(), ios::out | ios::binary | ios::app);
735 stringstream ss; ss << th;
737 file_name.append(
"_").append(ss.str());
742 ifstream data_file(file_name.c_str(), ios::binary | ios::in);
747 Cerr(
"***** vDataFile::PROJ_WriteData() -> Input temporary thread file '" << file_name <<
"' is missing or corrupted !" << endl);
752 merged_file << data_file.rdbuf();
757 m2p_dataFile[th]->open( file_name.c_str(), ios::binary | ios::out | ios::trunc);
780 stringstream ss; ss << th;
785 file_name.append(
"_").append(ss.str());
788 ifstream fcheck(file_name.c_str());
793 string dos_instruction =
"del " + file_name;
794 system(dos_instruction.c_str());
796 remove(file_name.c_str());
828 string data_type =
"";
832 else data_type =
"unknown";
844 string data_mode =
"";
848 else data_mode =
"unknown";
860 string data_spec =
"";
863 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.
void GetEventIndexStartAndStop(int64_t *ap_indexStart, int64_t *ap_indexStop, int a_subsetNum=0, int a_NbSubsets=1)
void SetNbLines(uint16_t a_value)
#define MODE_NORMALIZATION
int CheckParameters()
Check the initialization of member variables Call the CheckSpecificParameters() function implemente...
oMemoryMapped * mp_MappedFile
FLTNB GetCalibrationFactor()
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
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
#define VERBOSE_DEBUG_NORMAL
#define SPEC_TRANSMISSION
void SetID2(int a_line, uint32_t a_value)
int GetNb1stMotImgsForLMS(int a_fr)
const string & GetBaseName()
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 VERBOSE_DEBUG_EVENT
oImageDimensionsAndQuantification * mp_ID
void SetID1(int a_line, uint32_t a_value)