@@ -2586,28 +2586,50 @@ const map<set<int>,long long int> &SpecMeas::dbUserStateIndexes() const
25862586
25872587void SpecMeas::cleanup_after_load ( const unsigned int flags )
25882588{
2589- bool has_any_peaks = false ;
2590- if ( m_peaks )
2589+ // I *think*, m_peaks, m_autoSearchPeaks, and m_dbUserStateIndexes are the only
2590+ // SpecMeas specific things that use the sample numbers
2591+ bool has_specific_info = !m_dbUserStateIndexes.empty ();
2592+ if ( !has_specific_info && m_peaks )
25912593 {
2592- for ( const auto &samples_peaks : *m_peaks )
2593- {
2594- has_any_peaks = (samples_peaks.second && !samples_peaks.second ->empty ());
2595- if ( has_any_peaks )
2596- break ;
2597- }
2594+ for ( auto iter = begin (*m_peaks); !has_specific_info && (iter != end (*m_peaks)); ++iter )
2595+ has_specific_info = (iter->second && !iter->second ->empty ());
25982596 }// if( m_peaks )
25992597
2600- if ( m_fileWasFromInterSpec || has_any_peaks )
2598+ if ( !has_specific_info && !m_autoSearchPeaks.empty () )
2599+ {
2600+ for ( auto iter = begin (m_autoSearchPeaks); !has_specific_info && (iter != end (m_autoSearchPeaks)); ++iter )
2601+ has_specific_info = (iter->second && !iter->second ->empty ());
2602+ }// if( !has_specific_info && m_autoSearchPeaks )
2603+
2604+
2605+ if ( m_fileWasFromInterSpec && !(flags & SpecFile::ReorderSamplesByTime) )
26012606 {
26022607 SpecFile::cleanup_after_load ( (flags | SpecFile::DontChangeOrReorderSamples) );
2608+ }if ( has_specific_info )
2609+ {
2610+ // Grab a mapping from Measurement* to sample numbers.
2611+ vector<pair<int ,shared_ptr<const SpecUtils::Measurement>>> orig_sample_nums;
2612+ orig_sample_nums.reserve ( measurements_.size () );
2613+ for ( const std::shared_ptr<SpecUtils::Measurement> &m : measurements_ )
2614+ orig_sample_nums.emplace_back ( m->sample_number_ , m );
2615+
2616+ // Do cleanup - which _could_ change some of the Measurements sample numbers
2617+ SpecFile::cleanup_after_load ( flags );
2618+
2619+ // Now fixup m_peaks, m_autoSearchPeaks, and m_dbUserStateIndexes to use the newly assigned sample numbers
2620+ vector<pair<int ,int >> from_to_sample_nums;
2621+ for ( const pair<int ,shared_ptr<const SpecUtils::Measurement>> &samplenum_meas : orig_sample_nums )
2622+ {
2623+ if ( samplenum_meas.first != samplenum_meas.second ->sample_number () )
2624+ from_to_sample_nums.emplace_back ( samplenum_meas.first , samplenum_meas.second ->sample_number () );
2625+ }
2626+
2627+ if ( !from_to_sample_nums.empty () )
2628+ change_sample_numbers_spec_meas_stuff ( from_to_sample_nums );
26032629 }else
26042630 {
26052631 SpecFile::cleanup_after_load ( flags );
26062632 }
2607-
2608- // should detect if the detector was loaded, and if not, if we know the type,
2609- // we could then load it.
2610- // -instead for right now lets do this in InterSpec...
26112633}// void SpecMeas::cleanup_after_load()
26122634
26132635
@@ -2670,7 +2692,12 @@ void SpecMeas::cleanup_orphaned_info()
26702692void SpecMeas::change_sample_numbers ( const vector<pair<int ,int >> &from_to_sample_nums )
26712693{
26722694 SpecFile::change_sample_numbers ( from_to_sample_nums );
2673-
2695+ change_sample_numbers_spec_meas_stuff ( from_to_sample_nums );
2696+ }
2697+
2698+
2699+ void SpecMeas::change_sample_numbers_spec_meas_stuff ( const std::vector<std::pair<int ,int >> &from_to_sample_nums )
2700+ {
26742701 // I *think*, m_peaks, m_autoSearchPeaks, and m_dbUserStateIndexes are the only
26752702 // SpecMeas specific things that use the sample numbers
26762703
0 commit comments