Skip to content

Commit 814963d

Browse files
committed
Make so the concatinated batch peak fit output file is sorted by time.
This also required fixing a potentiaal issue where SpecFile cleanup_after_load could change a Measurements sample number - which would throw off how all the peaks are tracked (by sample number) - so now the tracking of those peaks is also updated.
1 parent 2c35ff6 commit 814963d

File tree

3 files changed

+53
-20
lines changed

3 files changed

+53
-20
lines changed

InterSpec/SpecMeas.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,12 @@ class SpecMeas : public SpecUtils::SpecFile
197197
This function is primarily useful if you remove some sample numbers.
198198
*/
199199
void cleanup_orphaned_info();
200-
200+
201+
/** overrides the `SpecFile::change_sample_numbers` by first calling that function, and then fixing the SpecMeas
202+
specific stuff up for any chnages, by calling `SpecMeas::change_sample_numbers_spec_meas_stuff(...)`.
203+
*/
201204
virtual void change_sample_numbers( const std::vector<std::pair<int,int>> &from_to_sample_nums );
202-
205+
203206
std::shared_ptr< std::deque< std::shared_ptr<const PeakDef> > >
204207
peaks( const std::set<int> &samplenums );
205208
/** CAUTION: the returned deque may be modified elsewhere in the app, if for
@@ -379,6 +382,12 @@ class SpecMeas : public SpecUtils::SpecFile
379382
#endif //#if( USE_LLM_INTERFACE )
380383

381384
protected:
385+
/** Changes all instances of the first sample number, to the second sample number in `m_peaks`, `m_autoSearchPeaks`, and
386+
`m_dbUserStateIndexes`. DOES NOT change the sample numbers of `SpecUtils::Measurement` - see `change_sample_numbers`
387+
for that.
388+
*/
389+
void change_sample_numbers_spec_meas_stuff( const std::vector<std::pair<int,int>> &from_to_sample_nums );
390+
382391
//m_peaks: is only accessed by the PeakModel class for the foreground spectrum - it shouldnt be set or
383392
// modified anywhere else. When a new primary spectrum is loaded in
384393
// InterSpec::setSpectrum(...), the m_peaks variable is passed

src/BatchPeak.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,8 @@ void fit_peaks_in_files( const std::string &exemplar_filename,
711711
}
712712
}
713713

714-
// TODO: Sort sample numbers according to start time, and call:
715-
//concatenated_spec->change_sample_numbers(<#const std::vector<std::pair<int, int>> &from_to_sample_nums#>);
716-
717714
// Clean up the SpecMeas after adding all measurements
718-
concatenated_spec->cleanup_after_load( SpecUtils::SpecFile::DontChangeOrReorderSamples );
715+
concatenated_spec->cleanup_after_load( SpecUtils::SpecFile::ReorderSamplesByTime );
719716

720717
// Save the concatenated file
721718
const string concatenated_file = SpecUtils::append_path( options.output_dir, "concatenated.n42" );

src/SpecMeas.cpp

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,28 +2586,50 @@ const map<set<int>,long long int> &SpecMeas::dbUserStateIndexes() const
25862586

25872587
void 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()
26702692
void 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

Comments
 (0)