diff --git a/ApplicationLibCode/FileInterface/RifMultipleSummaryReaders.cpp b/ApplicationLibCode/FileInterface/RifMultipleSummaryReaders.cpp index c27492520b..1dd204ef1d 100644 --- a/ApplicationLibCode/FileInterface/RifMultipleSummaryReaders.cpp +++ b/ApplicationLibCode/FileInterface/RifMultipleSummaryReaders.cpp @@ -33,6 +33,19 @@ void RifMultipleSummaryReaders::addReader( std::unique_ptrserialNumber() ) != nullptr ) return; m_readers.push_back( std::move( reader ) ); + + // Reorder readers so the calculated reader is at the front of the vector. This ensures that calculated data is used before other data. + // https://github.com/OPM/ResInsight/issues/12989 + std::sort( m_readers.begin(), + m_readers.end(), + []( const auto& first, const auto& second ) + { + bool isFirstCalc = dynamic_cast( first.get() ) != nullptr; + bool isSecondCalc = dynamic_cast( second.get() ) != nullptr; + if ( isFirstCalc && !isSecondCalc ) return true; + if ( !isFirstCalc && isSecondCalc ) return false; + return first->serialNumber() < second->serialNumber(); + } ); } //--------------------------------------------------------------------------------------------------