#include <ReportReader.h>
Public Member Functions | |
void | close () |
QString | fileName () |
qint64 | lastBlockOffset () |
double | misfit (int index) |
void | modelBlock (int index) |
int | nModels () |
bool | open () |
ReportReader () | |
ReportReader (QString fileName) | |
void | setFileName (QString fileName) |
QDataStream & | stream () |
void | synchronize () |
int | userBlockVersion (const char *tag) |
int | userBlockVersion (int index, const char *tag) |
int | version () const |
~ReportReader () | |
Static Public Member Functions | |
static bool | isReportFormat (QString fileName) |
Reports partially inherits the ".report" format used by na_viewer and qtbsurfacewave before 2005.
It is a generic class for report file management. Report files contain records of variable lengths.
Contrary to its ancestor, the maximum number models inside a report is not fixed at the creation of the file, and it does not contain the "goal" curves any longer, nor the parameterization. We prefer using XML text files for the description of goal curves and the parameterization.
These files, contrary to what would be expected, are not for random access. Originally, this was one of the requirements. However, for huge files, random access may generate lots of swap between buffered data and disk, takes a long long time. Nevertheless this object can offer a random access by constructing an offset table (see synchronize()).
Description of the file format:
8 Tag, 'DINVER05', for automatic file recognition 4 Version number: current=1 ... Model blocks of variable lengths pointed by offsets
Each model block starts with the raw parameters (stored by dinvercore in all situations)
4 Block tag: "MBLK" for model blocks 8 Offset of the next model block (0 for the last block under construction) 8 Misfit in double precision (64 bits) 4 Number of parameters (nd) 4 Unique parameterization checksum (32 bits, unsigned int) nd*8 Parameter values for model in double precision (64 bits) 4 User specific data tag, e.g. "DISP" for all blocks produced by dinverdc 4 Version of user specific data (introduced in version 1 20071121) ... Any user specific data of any length
ReportWriter can be used to create/add models to a report.
ReportReader is a SharedObject to be deleted automatically when no longer referenced. This feature is use by DCModelInfo
DinverCore::ReportReader::ReportReader | ( | ) | [inline] |
{}
DinverCore::ReportReader::ReportReader | ( | QString | fileName | ) |
DinverCore::ReportReader::~ReportReader | ( | ) | [inline] |
{}
void DinverCore::ReportReader::close | ( | ) | [inline] |
{_f.close();}
QString DinverCore::ReportReader::fileName | ( | ) | [inline] |
Referenced by DinverCore::ModelSet::importModelsFromReport().
{return _f.fileName();}
bool DinverCore::ReportReader::isReportFormat | ( | QString | fileName | ) | [static] |
References REPORT_CURRENT_VERSION, REPORT_FILE_TAG, TRACE, and version().
Referenced by DinverCore::ModelSet::importModels(), DinverCore::ModelRepository::importModels(), and DinverCore::ReportWriter::initReport().
{ TRACE; QFile f(fileName); if(f.open(QIODevice::ReadOnly)) { QDataStream s(&f); char buf[8]; s.readRawData(buf, 8); if(strncmp(buf, REPORT_FILE_TAG, 8)==0) { int version; s >> version; if(version>REPORT_CURRENT_VERSION) { return false; } else { return true; } } else { return false; } } else { return false; } }
qint64 DinverCore::ReportReader::lastBlockOffset | ( | ) |
References TRACE.
Referenced by synchronize().
{ TRACE; if(_offsets.isEmpty()) return 0; else return _offsets.last(); }
double DinverCore::ReportReader::misfit | ( | int | index | ) |
References TRACE.
Referenced by main(), reportMode(), DinverDCGui::GroundModelViewer::saveAsReport(), and DinverDCGui::DCModelViewer::selectModels().
{ TRACE; _f.seek(_offsets.at(index)); double m; _s >> m; return m; }
void DinverCore::ReportReader::modelBlock | ( | int | index | ) | [inline] |
Referenced by DinverCore::ModelSet::importModelsFromReport().
{_f.seek(_offsets.at(index));}
int DinverCore::ReportReader::nModels | ( | ) | [inline] |
Referenced by DinverCore::ModelRepository::importModels(), DinverCore::ModelSet::importModelsFromReport(), and DinverDCGui::DCModelViewer::selectModels().
{return _offsets.count();}
bool DinverCore::ReportReader::open | ( | ) |
Opens the report file, checks initial tag and general version. The offset table is not loaded into memory for random access (
References QGpCoreTools::endl(), REPORT_CURRENT_VERSION, REPORT_FILE_TAG, stream(), QGpCoreTools::tr(), and TRACE.
Referenced by DinverCore::ModelSet::importModels(), DinverCore::ModelRepository::importModels(), reportMode(), and DinverDCGui::DCModelViewer::selectModels().
{ TRACE; if(_f.open(QIODevice::ReadOnly)) { _s.setDevice(&_f); char buf[8]; _s.readRawData(buf, 8); if(strncmp(buf, REPORT_FILE_TAG, 8)==0) { _s >> _version; if(_version>REPORT_CURRENT_VERSION) { App::stream() << tr("This inversion report has been generated with a more recent version") << endl; return false; } else { // file is now ready for reading return true; } } else { App::stream() << tr("Bad file tag for inversion report, corrupted file") << endl; return false; } } else { App::stream() << tr("Cannot open file %1 for reading").arg(_f.fileName()) << endl; return false; } }
void DinverCore::ReportReader::setFileName | ( | QString | fileName | ) | [inline] |
{_f.setFileName(fileName);}
QDataStream& DinverCore::ReportReader::stream | ( | ) | [inline] |
Referenced by DinverDCGui::GroundModelViewer::exportModels(), DinverCore::ModelSet::importModelsFromReport(), DinverDCGui::DCModelViewer::loadModels(), main(), DinverDCGui::GroundModelViewer::minMaxProfiles(), open(), DinverDCGui::DCModelViewer::rejectModels(), reportMode(), DinverDCGui::GroundModelViewer::saveAsReport(), DinverDCGui::DCModelViewer::selectModels(), userBlockVersion(), DinverDCCore::DCReportBlock::write(), and DinverDCCore::DCReportBlock::writeBeta().
{return _s;}
Synchronizes offset table with file contents. This is mandatory for random access. Offsets points right after tag and offset to next block (12-byte shift).
References lastBlockOffset(), REPORT_BLOCK_TAG, and TRACE.
Referenced by DinverCore::ModelSet::importModels(), DinverCore::ModelRepository::importModels(), DinverCore::ReportWriter::open(), reportMode(), and DinverDCGui::DCModelViewer::selectModels().
{ TRACE; char buf[4]; qint64 offset; if(_offsets.isEmpty()) { offset=12; } else { offset=lastBlockOffset()-12; _offsets.removeLast(); } _f.seek(offset); while(true) { _s.readRawData(buf, 4); if(strncmp(buf, REPORT_BLOCK_TAG, 4)==0) { _offsets << (offset+12); // store offset where header is skipped _s >> offset; if(offset==0) break; _f.seek(offset); } else break; } }
int DinverCore::ReportReader::userBlockVersion | ( | const char * | tag | ) |
Must be called just after a call to misfit(int index). Returns the version number of the user block or -1 if a bad tag is encountered. 0 is returned for all reports with general version 0.
References QGpCoreTools::endl(), stream(), QGpCoreTools::tr(), and TRACE.
Referenced by DinverDCGui::GroundModelViewer::exportModels(), DinverDCGui::DCModelViewer::loadModels(), DinverDCGui::GroundModelViewer::minMaxProfiles(), outputDCModel(), DinverDCGui::DCModelViewer::rejectModels(), DinverDCGui::DCModelViewer::selectModels(), userBlockVersion(), DinverDCCore::DCReportBlock::write(), and DinverDCCore::DCReportBlock::writeBeta().
{ TRACE; int nd; _s >> nd; _f.seek(_f.pos()+nd*8+4); char buf[4]; _s.readRawData(buf,4); if(strncmp(buf, tag, 4)==0) { int userVersion; if(_version>=1) { // version 0 had no version number for user blocks _s >> userVersion; } else { userVersion=0; } return userVersion; } else { App::stream() << tr("Bad tag for user block") << endl; } return -1; }
int DinverCore::ReportReader::userBlockVersion | ( | int | index, |
const char * | tag | ||
) | [inline] |
References TRACE, and userBlockVersion().
{ TRACE; _f.seek(_offsets.at(index)+8); return userBlockVersion(tag); }
int DinverCore::ReportReader::version | ( | ) | const [inline] |
Referenced by isReportFormat().
{return _version;}