9 #include "iDataFileCT.hh" 53 FLTNB* p_angles = NULL;
65 Cerr(
"***** iDataFileCT::ReadSpecificInfoInHeader() -> Number of projections should be strictly positive !" << endl);
78 Cout(
" --> Provided projection angles" << endl);
87 Cerr(
"***** iDataFileCT::ReadSpecificInfoInHeader() -> Error while reading optional fields in the header data file !" << endl);
128 m_sizeEvent =
sizeof(uint32_t) + 2*
sizeof(uint32_t);
146 Cerr(
"***** iDataFileCT::ComputeSizeEvent() -> Unknown event mode !" << endl);
157 Cerr(
"***** iDataFileCT::ComputeSizeEvent() -> Error, the Event size in bytes should be >= 0 !" << endl;);
208 Cerr(
"*****iDataFileCT::PrepareDataFile() -> Error while trying to allocate memory for the Event object!" << endl);
220 Cerr(
"*****iDataFilePET::PrepareDataFile() -> Error while trying to allocate memory for the custom Event fields for thread " << th <<
" !" << endl;);
228 Cerr(
"*****iDataFilePET::PrepareDataFile() -> Error while trying to allocate memory for the custom Event fields for thread " << th <<
" !" << endl;);
248 else Cout(
" --> Correct for blank" << endl);
260 else Cout(
" --> Correct for scatter events" << endl);
278 char* file_position = ap_buffer;
286 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
287 file_position +=
sizeof(uint32_t);
291 event->SetKind(*reinterpret_cast<uint8_t*>(file_position));
292 file_position +=
sizeof(uint8_t);
307 event->SetID1(0, *reinterpret_cast<uint32_t*>(file_position));
308 file_position +=
sizeof(uint32_t);
310 event->SetID2(0, *reinterpret_cast<uint32_t*>(file_position));
311 file_position +=
sizeof(uint32_t);
318 event->SetCustomFLTData(i, *reinterpret_cast<EVTFLTDATA*>(file_position));
327 event->SetCustomINTData(i, *reinterpret_cast<EVTINTDATA*>(file_position));
339 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
340 file_position +=
sizeof(uint32_t);
342 event->SetEventValue(0, *reinterpret_cast<FLTNBDATA*>(file_position));
357 event->SetID1(0, *reinterpret_cast<uint32_t*>(file_position));
358 file_position +=
sizeof(uint32_t);
360 event->SetID2(0, *reinterpret_cast<uint32_t*>(file_position));
361 file_position +=
sizeof(uint32_t);
364 if(m_nbCustomINTData>0)
368 event->SetCustomINTData(i, *reinterpret_cast<EVTINTDATA*>(file_position));
372 if(m_nbCustomFLTData>0)
376 event->SetCustomFLTData(i, *reinterpret_cast<EVTFLTDATA*>(file_position));
396 Cout(
"iDataFileCT::DescribeSpecific() -> Here is some specific content of the CT datafile" << endl);
402 else Cout(
" --> Detector rotation is undefined !!!" << endl);
403 Cout(
" --> Number of acquisition projections: " << m_nbOfProjections << endl);
418 Cerr(
"***** iDataFileCT::CheckSpecificParameters() -> Data type should be CT !'" << endl);
422 if (m_nbOfProjections == 0)
424 Cerr(
"***** iDataFileCT::CheckSpecificParameters() -> Number of projections not initialized (should be >0) !" << endl);
430 Cerr(
"***** iDataFileCT::CheckSpecificParameters() -> Projection angles not initialized !" << endl);
447 fstream* p_file =
new fstream(
m_dataFileName.c_str(), ios::binary| ios::in );
449 if (!p_file->is_open())
451 Cerr(
"***** iDataFilePET::CheckFileSizeConsistency() -> Failed to open input file '" <<
m_dataFileName.c_str() <<
"' !" << endl);
456 p_file->seekg(0, ios::end);
457 int64_t sizeInBytes = p_file->tellg();
464 Cerr(
"-------------------------------------------------------------------------------------------------------------------------------------" << endl);
465 Cerr(
"***** iDataFileCT::CheckFileSizeConsistency() -> DataFile size is not consistent with the information provided by the user/datafile !" << endl);
467 Cerr(
" --> Actual size: "<< sizeInBytes << endl << endl);
468 Cerr(
" ADDITIONAL INFORMATION ABOUT THE DATAFILE INITIALIZATION" << endl);
470 else Cerr(
" --> No information about the kind of events in the data" << endl);
472 else Cerr(
" --> No blank correction term in the data" << endl);
474 else Cerr(
" --> No scatter correction term in the data" << endl);
476 Cerr(
"----------------------------------------------------------------------------------------------------------------------------------------" << endl);
496 Cerr(
"***** iDataFileCT::CheckSpecificConsistencyWithAnotherDataFile() -> Event kind flags are inconsistent !" << endl);
502 Cerr(
"***** iDataFileCT::CheckSpecificConsistencyWithAnotherDataFile() -> Blank correction flags are inconsistent !" << endl);
508 Cerr(
"***** iDataFileCT::CheckSpecificConsistencyWithAnotherDataFile() -> Scatter correction flags are inconsistent !" << endl);
514 Cerr(
"***** iDataFileCT::CheckSpecificConsistencyWithAnotherDataFile() -> Data modes are inconsistent (list-mode or histogram) !" << endl);
530 if (m_nbOfProjections == 0)
532 Cerr(
"***** iDataFileCT::InitAngles() -> Number of projection angles not initialized !'" << endl);
580 datafile_name.append(
"_").append(ss.str());
582 m2p_dataFile[th] =
new fstream( datafile_name.c_str(), ios::binary | ios::out | ios::trunc);
587 ofstream output_file(
m_dataFileName.c_str(), ios::out | ios::trunc);
609 Cerr(
"*****iDataFileCT::WriteEvent() -> Error while trying to write projection datafile (list-mode)" << endl);
618 Cerr(
"*****iDataFileCT::WriteEvent() -> Error while trying to write projection datafile (histogram)" << endl);
639 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
656 uint32_t id1 = ap_Event->
GetID1(0);
657 uint32_t id2 = ap_Event->
GetID2(0);
658 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
659 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
662 if(m_nbCustomINTData>0)
671 if(m_nbCustomFLTData>0)
696 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
700 uint8_t event_kind = ap_Event->
GetKind();
701 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&event_kind),
sizeof(uint8_t));
716 uint32_t id1 = ap_Event->
GetID1(0);
717 uint32_t id2 = ap_Event->
GetID2(0);
718 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
719 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
722 if(m_nbCustomINTData>0)
731 if(m_nbCustomFLTData>0)
756 if (!headerFile.is_open())
758 Cerr(
"***** iDataFileCT::WriteHeader() -> Failed to open output header file '" <<
m_headerFileName <<
"' !" << endl);
764 headerFile <<
"Number of events: " <<
m_nbEvents << endl;
770 headerFile <<
"Data type: CT" << endl;
778 headerFile <<
"Number of projections: " << m_nbOfProjections << endl;
780 headerFile <<
"Projection angles: " <<
mp_angles[0];
789 headerFile <<
"Scanner rotation direction: " << rot_direction << endl;
807 FLTNB* p_angles = NULL;
811 Cerr(
"*****iDataFileCT::PROJ_GetScannerSpecificParameters() -> An error occurred while trying to get CT geometric parameters from the scanner object !" << endl);
817 mp_angles[a] = p_angles[a];
virtual EVTFLTDATA * GetCustomFLTData()
uint32_t GetID2(int a_line)
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.
bool GetScatCorrectionFlag()
Simply return m_scatCorrectionFlag.
#define MODE_NORMALIZATION
int GetDetectorRotDirection()
Simply return m_detectorRotDirection.
int InitAngles(FLTNB *ap_angles)
int SetSpecificParametersFrom(vDataFile *ap_DataFile)
bool m_blankCorrectionFlag
Inherit from iEventCT. Class for CT list-mode events.
iDataFileCT()
iDataFileCT constructor. Initialize the member variables to their default values. ...
bool m_ignoreScatCorrectionFlag
uint16_t m_nbOfProjections
int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag)
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
bool m_ignoreBlankCorrectionFlag
bool m_scatCorrectionFlag
int WriteHeader()
Generate a header file according to the data output information.
bool GetIgnoreNormCorrectionFlag()
Get the boolean that says if the normalization correction is ignored or not.
int WriteListEvent(iEventListCT *ap_Event, int a_th)
const string & GetPathName()
int ComputeSizeEvent()
Computation of the size of each event according to the mandatory/optional correction fields...
#define DEBUG_VERBOSE(IGNORED1, IGNORED2)
virtual void SetNbCustomFLTData(int a_value)
initialize the number of custom INT data with a_value
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
vEvent * GetEventSpecific(char *ap_buffer, int a_th)
Singleton class that Instantiate and initialize the scanner object.
vEvent ** m2p_BufferEvent
int PROJ_GetScannerSpecificParameters()
Get SPECT specific parameters for projections from the scanner object, through the scannerManager...
int CheckSpecificParameters()
Check parameters specific to CT data.
void DescribeSpecific()
Implementation of the pure virtual eponym function that simply prints info about the datafile...
Inherit from iEventCT. Class for CT histogram mode events.
int PROJ_InitFile()
Initialize the fstream objets for output writing as well as some other variables specific to the Proj...
bool GetBlankCorrectionFlag()
Simply return m_blankCorrectionFlag.
#define SPEC_TRANSMISSION
bool GetEventKindFlag()
Simply return m_eventKindFlag.
int m_detectorRotDirection
int CheckSpecificConsistencyWithAnotherDataFile(vDataFile *ap_DataFile)
uint16_t GetNbProjections()
const string & GetBaseName()
void SetTimeInMs(uint32_t a_value)
virtual void SetNbCustomINTData(int a_value)
initialize the number of custom INT data with a_value
int WriteEvent(vEvent *ap_Event, int a_th=0)
Mother class for the Event objects.
Inherit from vDataFile. Class that manages the reading of a CT input file (header + data)...
int GetNbThreadsForProjection()
Get the number of threads used for projections.
bool GetIgnoreScatCorrectionFlag()
Get the boolean that says if the scatter correction is ignored or not.
FLTNB m_calibrationFactor
uint32_t GetID1(int a_line)
string GetFileFromPath(const string &a_pathToFile)
Simply return the file from a path string passed in parameter.
#define VERBOSE_DEBUG_LIGHT
~iDataFileCT()
iDataFileCT destructor.
virtual EVTINTDATA * GetCustomINTData()
int GetCTSpecificParameters(uint16_t *ap_nbOfProjections, FLTNB *&ap_angles, int *ap_headRotDirection)
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 WriteHistoEvent(iEventHistoCT *ap_Event, int a_th)
int PrepareDataFile()
Store different kind of information inside arrays (data relative to specific correction as well as ba...
int CheckFileSizeConsistency()
This function is implemented in child classes Check if file size is consistent. ...
FLTNB GetEventValue(int a_bin)
#define VERBOSE_DEBUG_EVENT
oImageDimensionsAndQuantification * mp_ID