Skip to content

Commit

Permalink
Fix error setting source date from Source.lib entry, and add parsing …
Browse files Browse the repository at this point in the history
…optional distance and activity uncertainty to Source.lib comment field.
  • Loading branch information
wcjohns committed May 17, 2024
1 parent 36a658f commit 588e51b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
27 changes: 26 additions & 1 deletion InterSpec/MakeDrfSrcDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,44 @@ namespace SandiaDecay
*/
struct SrcLibLineInfo
{
/** Activity of source (in units of PhysicalUnits), on date specified. */
double m_activity;
/** Nuclide of this source. */
const SandiaDecay::Nuclide *m_nuclide;
/** The date the activity was specified for.
For sources that grow in, this is also assumed to be their T=0 date.
*/
boost::posix_time::ptime m_activity_date;

/** The first field specified. */
std::string m_source_name;

/** Everything past activity field. */
std::string m_comments;

/** The entire line all the information was extracted from. */
std::string m_line;

/** Optional activity uncertainty (in units of PhysicalUnits activity - i.e., bq)
Will be zero or negative if not specified.
*/
double m_activity_uncert;

/** Optional distance used for the source.
Will be zero or negative if not specified.
*/
double m_distance;

SrcLibLineInfo();

/** Source lines should be in the format:
"[nuclide]_[serial num] [activity in bq] [activity reference date] [comment]"
for example:
"22NA_01551910 5.107E+04 25-Aug-2022 West Rad Lab"
"22NA_01551910 5.107E+04 25-Aug-2022 West Rad Lab, Distance=50cm, ActivityUncertainty=5.107E+03"
The comment field can optionally contain both the distance, and activity uncertainty, for example:
- "Distance=50cm"
- "ActivityUncertainty=5.107E+03", where activity uncertainty is in Bq
If any field is not valid (except comment can be blank), the line wont be included in the results.
*/
Expand Down
57 changes: 55 additions & 2 deletions src/MakeDrfSrcDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "InterSpec_config.h"

#include <regex>

#include <Wt/WDate>
#include <Wt/WTable>
#include <Wt/WLabel>
Expand Down Expand Up @@ -84,7 +86,9 @@ SrcLibLineInfo::SrcLibLineInfo()
m_activity_date{},
m_source_name{},
m_comments{},
m_line{}
m_line{},
m_activity_uncert( -1.0 ),
m_distance( -1.0 )
{
}

Expand Down Expand Up @@ -145,6 +149,40 @@ vector<SrcLibLineInfo> SrcLibLineInfo::sources_in_lib( const string &filename )
for( size_t i = 3; i < fields.size(); ++i )
src_info.m_comments += ((i==3) ? "" : " ") + fields[i];


// By default PhysicalUnits::sm_distanceRegex has a "^" character at beginning, and "$"
// character at end - lets get rid of these
string dist_regex = PhysicalUnits::sm_distanceRegex;
SpecUtils::ireplace_all( dist_regex, "^", "" );
SpecUtils::ireplace_all( dist_regex, "$", "" );

std::smatch dist_mtch;
std::regex dist_expr( string(".+([dist|distance]\\s*\\=\\s*(")
+ dist_regex
+ ")).*?", std::regex::icase );
if( std::regex_match( src_info.m_comments, dist_mtch, dist_expr ) )
{
try
{
src_info.m_distance = PhysicalUnits::stringToDistance( dist_mtch[2].str() );
}catch( std::exception & )
{
src_info.m_distance = -1.0;
}
}//if( std::regex_match( remark, dist_mtch, dist_expr ) )

std::smatch act_uncert_mtch;
std::regex act_uncert_expr( string(".+([ActivityUncertainty|ActivityUncert]\\s*\\=\\s*(")
+ PhysicalUnits::sm_positiveDecimalRegex
+ ")).*?", std::regex::icase );
if( std::regex_match( src_info.m_comments, act_uncert_mtch, act_uncert_expr ) )
{
string strval = act_uncert_mtch[2].str();
if( !SpecUtils::parse_double( strval.c_str(), strval.size(), src_info.m_activity_uncert ) )
src_info.m_activity_uncert = -1.0;
}//if( std::regex_match( remark, dist_mtch, dist_expr ) )


src_info.m_line = std::move(line);

answer.push_back( std::move(src_info) );
Expand Down Expand Up @@ -244,6 +282,12 @@ Wt::Signal<> &MakeDrfSrcDef::updated()

void MakeDrfSrcDef::setSrcInfo( const SrcLibLineInfo &info )
{
if( info.m_distance > 0.0 )
m_distanceEdit->setText( PhysicalUnits::printToBestLengthUnits(info.m_distance, 5) );

if( info.m_activity_uncert > 0.0 )
m_activityUncertainty->setValue( 100 * info.m_activity_uncert / info.m_activity );

setAssayInfo( info.m_activity, info.m_activity_date );
}//void setSrcInfo( const SrcLibLineInfo &info )

Expand Down Expand Up @@ -866,9 +910,15 @@ void MakeDrfSrcDef::setActivity( const double act )
void MakeDrfSrcDef::setAssayInfo( const double activity,
const boost::posix_time::ptime &assay_date )
{
// We only want to update the UI at the end of this function - so block emitting updates until
// then (and actually we'll possible get an error in calculation if we dont wait until
// everything is updated)
const bool updateBlocked = m_updated.isBlocked();
m_updated.setBlocked( true );

m_useAgeInfo->setChecked( !assay_date.is_special() );
useAgeInfoUserToggled();
m_assayDate->setDate( WDateTime::fromPosixTime(assay_date).date() );
useAgeInfoUserToggled();

if( activity > 0.0 )
{
Expand All @@ -879,6 +929,9 @@ void MakeDrfSrcDef::setAssayInfo( const double activity,

validateDateFields();
updateAgedText();

m_updated.setBlocked( updateBlocked );
m_updated.emit();
}//void setAssayInfo(..);


Expand Down

0 comments on commit 588e51b

Please sign in to comment.