8 #include "gVariables.hh" 10 #include "oImageDimensionsAndQuantification.hh" 11 #include "iDataFilePET.hh" 12 #include "iDataFileSPECT.hh" 13 #include "iDataFileCT.hh" 14 #include "sOutputManager.hh" 15 #include "sScannerManager.hh" 16 #include "sRandomNumberGenerator.hh" 17 #include "iScannerPET.hh" 18 #include "sAddonManager.hh" 37 cout <<
"Usage: castor-datafileExplorer -df datafile.cdh [settings]" << endl;
39 cout <<
"This program can be used to explore a datafile and get some info about it. By default, it simply prints general information recovered" << endl;
40 cout <<
"from the reader. If the '-e' option is supply, an event-by-event exploration will be performed: information about each event will be" << endl;
41 cout <<
"displayed." << endl;
43 cout <<
"[Mandatory parameters]:" << endl;
44 cout <<
" -df datafile.cdh : Give the path to a single datafile." << endl;
46 cout <<
"[Options]:" << endl;
47 cout <<
" -e : Flag for event by event exploration (will list the content of each event)." << endl;
48 cout <<
" -i : Flag for interactive one by one event exploration when -e option is supplied." << endl;
49 cout <<
" -g : Flag for global exploration (will not list the content of each event but will supply a summary)." << endl;
50 cout <<
" -vb value : Give the verbosity level, from 0 (no verbose) to 2 (default: 1)" << endl;
51 cout <<
" --help,-h,-help : Print out this help page." << endl;
54 cout <<
" Build date: " << BUILD_DATE << endl;
58 cout <<
" This program is part of the CASToR release version " <<
CASTOR_VERSION <<
"." << endl;
71 int main(
int argc,
char** argv)
79 MPI_Init(&argc, &argv);
80 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
81 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
82 if (mpi_rank!=0)
return 0;
97 string path_to_data_filename;
101 bool event_by_event_flag =
false;
103 bool interactive_flag =
false;
105 bool global_flag =
false;
112 for (
int i=1; i<argc; i++)
115 string option = (string)argv[i];
117 if (option==
"-h" || option==
"--help" || option==
"-help")
123 else if (option==
"-vb")
127 Cerr(
"***** castor-datafileExplorer() -> Argument missing for option: " << option << endl);
132 Cerr(
"***** castor-datafileExplorer() -> Exception when trying to read provided verbosity level '" << verbose <<
" for option: " << option << endl);
138 else if (option==
"-df")
142 Cerr(
"***** castor-datafileExplorer() -> Argument missing for option: " << option << endl);
145 path_to_data_filename = (string)argv[i+1];
149 else if (option==
"-e")
151 event_by_event_flag =
true;
154 else if (option==
"-i")
156 interactive_flag =
true;
159 else if (option==
"-g")
166 Cerr(
"***** castor-datafileExplorer() -> Unknown option '" << option <<
"' !" << endl);
176 if (path_to_data_filename==
"")
178 Cerr(
"***** castor-datafileExplorer() -> Please provide a datafile name !" << endl);
184 Cerr(
"***** castor-datafileExplorer() -> Verbose less than 1 has no sense for a program used to solely print out information on screen !" << endl);
188 if (verbose>2) verbose = 2;
190 if (global_flag && event_by_event_flag)
192 Cerr(
"***** castor-datafileExplorer() -> Cannot use global and event-by-event mode at the same time !" << endl);
201 Cout(
"==============================================================" << endl);
202 Cout(
"castor-datafileExplorer() -> Initialization starts" << endl);
216 string scanner_name =
"";
219 Cerr(
"***** castor-datafileExplorer() -> A problem occurred while trying to find the system name in the datafile header !" << endl);
224 Cerr(
"***** castor-datafileExplorer() -> A problem occurred while searching for scanner system !" << endl);
229 Cerr(
"***** castor-datafileExplorer() -> A problem occurred during scanner object construction ! !" << endl);
234 Cerr(
"***** castor-datafileExplorer() -> A problem occurred while creating Scanner object !" << endl);
239 Cerr(
"***** castor-datafileExplorer() -> A problem occurred while retrieving scanner fields from the datafile header !" << endl);
244 Cerr(
"***** castor-datafileExplorer() -> A problem occurred while generating/reading the LUT !" << endl);
249 Cerr(
"***** castor-datafileExplorer() -> A problem occurred while checking scanner manager parameters !" << endl);
254 Cerr(
"***** castor-datafileExplorer() -> A problem occurred while initializing scanner !" << endl);
275 Cerr(
"***** castor-datafileExplorer() -> Unknown scanner type (" << p_ScannerManager->
GetScannerType() <<
") for datafile construction ! Abort." << endl);
285 bool do_not_affect_quantification =
false;
288 Cerr(
"***** castor-datafileExplorer() -> A problem occurred during datafile header reading ! Abort." << endl);
293 Cerr(
"***** castor-datafileExplorer() -> A problem occurred while checking datafile parameters ! Abort." << endl);
298 Cerr(
"***** castor-datafileExplorer() -> A problem occurred in datafile initialization ! Abort." << endl);
303 Cerr(
"***** castor-datafileExplorer() -> A problem occurred in datafile initialization ! Abort." << endl);
308 Cerr(
"***** castor-datafileExplorer() -> A problem occurred in datafile preparation ! Abort." << endl);
313 Cout(
"castor-datafileExplorer() -> End of initialization" << endl);
314 Cout(
"==============================================================" << endl);
324 Cout(
"==============================================================" << endl);
330 if (event_by_event_flag)
332 Cout(
"castor-datafileExplorer() -> Start exploration of all events" << endl);
334 int64_t index_start = 0; int64_t index_stop = 0;
337 int64_t index = index_start;
338 while (index>=index_start && index<index_stop)
341 Cout(
"------------------------- Event index " << index <<
" -------------------------" << endl);
346 Cerr(
"***** castor-datafileExplorer() -> An error occurred while getting the event from index " << index <<
" !" << endl);
352 if (interactive_flag)
355 cout <<
"--------> Give an event index or simply press enter for next event: " << flush;
357 string answer =
""; getline(cin,answer);
360 if (answer==
"") index++;
365 int64_t next_index = stoll(answer);
366 if (next_index<index_start || next_index>=index_stop)
368 Cerr(
"***** castor-datafileExplorer() -> The provided event index (" << next_index <<
") is out of datafile range" 369 <<
" [" << index_start <<
":" << index_stop <<
"[ !" << endl);
372 else index = next_index;
377 Cout(
"==============================================================" << endl);
384 else if (global_flag)
387 Cout(
"castor-datafileExplorer() -> Start global exploration of all events" << endl);
389 cout <<
"0 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%" << endl;
390 cout <<
"|----|----|----|----|----|----|----|----|----|----|" << endl;
391 cout <<
"|" << flush;
392 int progression_percentage_old = 0;
393 int progression_nb_bars = 0;
394 uint64_t progression_printing_index = 0;
396 int64_t index_start = 0; int64_t index_stop = 0;
401 for (int64_t index=index_start ; index<index_stop ; index++)
404 if (progression_printing_index%1000==0)
406 int progression_percentage_new = ((int)( (((
float)(index-index_start+1))/((
float)(index_stop-index_start)) ) * 100.));
407 if (progression_percentage_new>=progression_percentage_old+2)
409 int nb_steps = (progression_percentage_new-progression_percentage_old)/2;
410 for (
int i=0; i<nb_steps; i++)
412 cout <<
"-" << flush;
413 progression_nb_bars++;
415 progression_percentage_old += nb_steps*2;
418 progression_printing_index++;
423 Cerr(
"***** castor-datafileExplorer() -> An error occurred while getting the event from index " << index <<
" !" << endl);
430 int progression_total_bars = 49;
431 for (
int i=0; i<progression_total_bars-progression_nb_bars; i++) cout <<
"-";
433 Cout(
" --> Total number of data: " << total_nb_data << endl);
434 Cout(
"==============================================================" << 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)
int CheckParameters()
Check the initialization of member variables Call the CheckSpecificParameters() function implemente...
int FindScannerSystem(string a_scannerName)
int BuildScannerObject()
Instantiate the specific scanner object related to the modality, and set verbosity of scanner object...
int ReadInfoInHeader(bool a_affectQuantificationFlag=true)
void SetVerbose(int a_verboseLevel)
virtual int ComputeSizeEvent()=0
This function is implemented in child classes Computation of the size of each event according to th...
int CheckParameters()
Check if all parameters have been correctly initialized, and call the CheckParameters function of the...
int InitializeMappedFile()
Check the datafile existency, map it to memory and get the raw char* pointer. .
int InstantiateScanner()
Instantiate scanner using the related function in the scanner classes.
vEvent * GetEvent(int64_t a_eventIndex, int a_th=0)
#define SCANNER_SPECT_CONVERGENT
int BuildLUT()
Call the eponym function of the scanner class.
Singleton class that Instantiate and initialize the scanner object.
virtual int PrepareDataFile()=0
This function is implemented in child classes Store different kind of information inside arrays (da...
Inherit from vDataFile. Class that manages the reading of a SPECT input file (header + data)...
void SetHeaderDataFileName(const string &a_headerFileName)
#define KEYWORD_MANDATORY
virtual FLTNB GetEventValue(int a_bin)=0
int Initialize()
Initialization : .
void SetBedIndex(int a_bedIndex)
virtual void Describe()=0
This function can be used to get a description of the event printed out.
void GetUserEndianness()
Check user/host computer endianness and write it to the global variable User_Endianness.
Mother class for the Event objects.
int ConvertFromString(const string &a_str, string *a_result)
Copy the 'a_str' string in the position pointed by 'a_result'.
Inherit from vDataFile. Class that manages the reading of a CT input file (header + data)...
void Describe()
A function used to describe the generic parts of the datafile.
This class is designed to manage all dimensions and quantification related stuff. ...
virtual INTNB GetNbValueBins()=0
Get the number of event value bins.
void SetVerbose(int a_verboseLevel)
void SetDefault()
A function used to set number of threads and MPI instances to 1 and bypass the CheckParameters() func...
void SetVerbose(int a_verbose)
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 SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification *ap_ImageDimensionsAndQuantification)
Inherit from vDataFile. Class that manages the reading of a PET input file (header + data)...
int GetGeometricInfoFromDataFile(string a_pathToDataFilename)