From 516c642cc4e5b5da90e3f66a1a67a26ea43cc088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Tue, 19 Mar 2013 09:08:37 +0100 Subject: [PATCH] Results Storage: Refined the output format. Think it is ok now p4#: 20956 --- .../RimReservoirCellResultsCacher.cpp | 15 +++++-- .../RimReservoirCellResultsCacher.h | 41 ++++++++++--------- .../ProjectDataModel/RimReservoirView.h | 1 - 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.cpp b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.cpp index 62d47c4369..7c8afe989f 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.cpp @@ -50,6 +50,10 @@ RimReservoirCellResultsCacher::~RimReservoirCellResultsCacher() } //-------------------------------------------------------------------------------------------------- +/// This override populates the metainfo regarding the cell results data in the RigReservoirCellResults +/// object. This metainfo will then be written to the project file when saving, and thus read on project file open. +/// This method then writes the actual double arrays to the data file in a simple format: +/// MagicNumber, Version, ResultVariables< Array < TimeStep< CellDataArraySize, CellData< Array > > > /// //-------------------------------------------------------------------------------------------------- void RimReservoirCellResultsCacher::setupBeforeSave() @@ -71,13 +75,15 @@ void RimReservoirCellResultsCacher::setupBeforeSave() QDataStream stream(&cacheFile); stream.setVersion(QDataStream::Qt_4_0); stream << (quint32)0xCEECAC4E; // magic number - stream << (qint32)1; // Version + stream << (quint32)1; // Version number. Increment if needing to extend the format in ways that can not be handled generically by the reader for (size_t rIdx = 0; rIdx < resInfo.size(); ++rIdx) { size_t timestepCount = m_cellResults->cellScalarResults(resInfo[rIdx].m_gridScalarResultIndex).size(); + if (timestepCount) { + // Create and setup the cache information for this result RimReservoirCellResultsCacheEntryInfo* cacheEntry = new RimReservoirCellResultsCacheEntryInfo; m_resultCacheMetaData.push_back(cacheEntry); @@ -85,8 +91,11 @@ void RimReservoirCellResultsCacher::setupBeforeSave() cacheEntry->m_resultName = resInfo[rIdx].m_resultName; cacheEntry->m_timeStepDates = resInfo[rIdx].m_timeStepDates; + // Take note of the file position for fast lookup later cacheEntry->m_filePosition = cacheFile.pos(); + // Write all the scalar values for each time step to the stream, + // starting with the number of values for (size_t tsIdx = 0; tsIdx < resInfo[rIdx].m_timeStepDates.size() ; ++tsIdx) { const std::vector* data = NULL; @@ -97,8 +106,8 @@ void RimReservoirCellResultsCacher::setupBeforeSave() if (data && data->size()) { - cacheEntry->m_timeStepHasData.v().push_back(1); + stream << (quint64)(data->size()); for (size_t cIdx = 0; cIdx < data->size(); ++cIdx) { stream << (*data)[cIdx]; @@ -106,7 +115,7 @@ void RimReservoirCellResultsCacher::setupBeforeSave() } else { - cacheEntry->m_timeStepHasData.v().push_back(0); + stream << (quint64)0; } } } diff --git a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.h b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.h index fcf703e02d..1051429769 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.h +++ b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.h @@ -37,36 +37,37 @@ public: virtual ~RimReservoirCellResultsCacher(); // Fields - caf::PdmField m_resultCacheFileName; + caf::PdmField m_resultCacheFileName; caf::PdmPointersField - m_resultCacheMetaData; + m_resultCacheMetaData; - RigReservoirCellResults* cellResults() { return m_cellResults; } - const RigReservoirCellResults* cellResults() const { return m_cellResults; } + RigReservoirCellResults* cellResults() { return m_cellResults; } + const RigReservoirCellResults* cellResults() const { return m_cellResults; } - void setCellResults(RigReservoirCellResults* cellResults); - void setMainGrid(RigMainGrid* mainGrid); + void setCellResults(RigReservoirCellResults* cellResults); + void setMainGrid(RigMainGrid* mainGrid); - void setReaderInterface(RifReaderInterface* readerInterface); - RifReaderInterface* readerInterface(); + void setReaderInterface(RifReaderInterface* readerInterface); + RifReaderInterface* readerInterface(); - void loadOrComputeSOIL(); - void loadOrComputeSOILForTimeStep(size_t timeStepIndex); - void computeDepthRelatedResults(); + void loadOrComputeSOIL(); + void loadOrComputeSOILForTimeStep(size_t timeStepIndex); + void computeDepthRelatedResults(); - size_t findOrLoadScalarResultForTimeStep(RimDefines::ResultCatType type, const QString& resultName, size_t timeStepIndex); - size_t findOrLoadScalarResult(RimDefines::ResultCatType type, const QString& resultName); - size_t findOrLoadScalarResult(const QString& resultName); ///< Simplified search. Assumes unique names across types. + size_t findOrLoadScalarResultForTimeStep(RimDefines::ResultCatType type, const QString& resultName, size_t timeStepIndex); + size_t findOrLoadScalarResult(RimDefines::ResultCatType type, const QString& resultName); + size_t findOrLoadScalarResult(const QString& resultName); ///< Simplified search. Assumes unique names across types. // Overridden methods from PdmObject - virtual void setupBeforeSave(); + virtual void setupBeforeSave(); private: - QString getValidCacheFileName(); - QString getCacheDirectoryPath(); - cvf::ref m_readerInterface; - RigReservoirCellResults* m_cellResults; - RigMainGrid* m_ownerMainGrid; + QString getValidCacheFileName(); + QString getCacheDirectoryPath(); + + cvf::ref m_readerInterface; + RigReservoirCellResults* m_cellResults; + RigMainGrid* m_ownerMainGrid; }; class RimReservoirCellResultsCacheEntryInfo : public caf::PdmObject diff --git a/ApplicationCode/ProjectDataModel/RimReservoirView.h b/ApplicationCode/ProjectDataModel/RimReservoirView.h index a0cb0126e4..24c75fdaae 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirView.h +++ b/ApplicationCode/ProjectDataModel/RimReservoirView.h @@ -51,7 +51,6 @@ namespace cvf class ModelBasicList; } - enum ViewState { GEOMETRY_ONLY,