[med-svn] [SCM] aghermann branch, master, updated. 3603e7ef1289f9ec79a3eb415b6d141166e9498a
Andrei Zavada
johnhommer at gmail.com
Sun Jul 14 22:28:23 UTC 2013
The following commit has been merged in the master branch:
commit 8fdfabfb4a8ed8c893e186c0ad29c651fa1d876f
Author: Andrei Zavada <johnhommer at gmail.com>
Date: Mon Jul 15 01:11:09 2013 +0300
sink some common code in libsigfile
diff --git a/src/common/subject_id.cc b/src/common/subject_id.cc
index 93518d3..cacede8 100644
--- a/src/common/subject_id.cc
+++ b/src/common/subject_id.cc
@@ -14,6 +14,7 @@
#include <string>
#include <cstring>
#include "string.hh"
+#include "libsigfile/source-base.hh" // for CEDFFile::TStatus flags
#include "subject_id.hh"
#if HAVE_CONFIG_H && !defined(VERSION)
@@ -181,6 +182,31 @@ update_from( const SSubjectId& j)
}
+int
+SSubjectId::
+parse_recording_id_edf_style( const string& s)
+{
+ using namespace agh::str;
+ int_least32_t status = 0;
+ auto subfields = tokens( s, " ");
+ if ( subfields.size() < 4 ) {
+ id = subfields.front();
+ status |= sigfile::CSource::nonconforming_patient_id;
+ } else {
+ if ( subfields.size() > 4 )
+ status |= sigfile::CSource::extra_patientid_subfields;
+ auto i = subfields.begin();
+ id = *i++;
+ gender = agh::SSubjectId::char_to_gender((*i++)[0]);
+ dob = agh::SSubjectId::str_to_dob(*i++);
+ name = join( tokens(*i++, "_"), " ");
+ if ( not valid() )
+ status |= sigfile::CSource::invalid_subject_details;
+ }
+ return status;
+}
+
+
// Local Variables:
// Mode: c++
// indent-tabs-mode: 8
diff --git a/src/common/subject_id.hh b/src/common/subject_id.hh
index ff1442a..b9ee48e 100644
--- a/src/common/subject_id.hh
+++ b/src/common/subject_id.hh
@@ -82,7 +82,7 @@ struct SSubjectId {
}
int update_from( const SSubjectId&);
- string make_recording_id() const
+ string make_recording_id_edf_style() const
{
return agh::str::sasprintf(
"%s %c %s %s",
@@ -90,6 +90,9 @@ struct SSubjectId {
name.c_str());
}
+ // flag bits as in CEDFFile::TStatus
+ int parse_recording_id_edf_style( const string&);
+
static char gender_sign( TGender);
static TGender char_to_gender( char);
static time_t str_to_dob( const string&);
diff --git a/src/libsigfile/edf-io.cc b/src/libsigfile/edf-io.cc
index 2e369b7..b4170c1 100644
--- a/src/libsigfile/edf-io.cc
+++ b/src/libsigfile/edf-io.cc
@@ -20,7 +20,7 @@ CEDFFile::
get_region_original_smpl( const int h,
const size_t sa, const size_t sz) const
{
- if ( unlikely (_status & (TStatus::bad_header | TStatus::bad_version)) )
+ if ( unlikely (_status & (CSource::TStatus::bad_header | TStatus::bad_version)) )
throw invalid_argument ("CEDFFile::get_region_original(): broken source");
if ( unlikely (_mmapping == NULL) )
throw invalid_argument ("CEDFFile::get_region_original(): no data");
@@ -71,7 +71,7 @@ put_region_smpl( const int h,
const valarray<TFloat>& src,
const size_t offset)
{
- if ( unlikely (_status & (TStatus::bad_header | TStatus::bad_version)) )
+ if ( unlikely (_status & (CSource::TStatus::bad_header | TStatus::bad_version)) )
throw invalid_argument("CEDFFile::put_region_(): broken source");
if ( unlikely (_mmapping == NULL) )
throw invalid_argument("CEDFFile::put_region_(): no data");
diff --git a/src/libsigfile/edf.cc b/src/libsigfile/edf.cc
index 827c7ab..5428814 100644
--- a/src/libsigfile/edf.cc
+++ b/src/libsigfile/edf.cc
@@ -124,12 +124,12 @@ CEDFFile (const string& fname_, const int flags_)
struct stat stat0;
int stst = stat( fname_.c_str(), &stat0);
if ( stst == -1 )
- throw invalid_argument (explain_status(_status |= TStatus::sysfail));
+ throw invalid_argument (explain_status(_status |= CSource::TStatus::sysfail));
_fsize = stat0.st_size;
}
_fd = open( fname_.c_str(), O_RDWR);
if ( _fd == -1 )
- throw invalid_argument (explain_status(_status |= TStatus::sysfail));
+ throw invalid_argument (explain_status(_status |= sysfail));
// mmap
_mmapping =
@@ -195,7 +195,7 @@ CEDFFile (const string& fname_, const TSubtype subtype_, const int flags_,
{
_fd = open( fname_.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP);
if ( _fd == -1 )
- throw invalid_argument (explain_status(_status |= TStatus::sysfail));
+ throw invalid_argument (explain_status(_status |= CSource::TStatus::sysfail));
header_length = 256 + (channels_.size() * 256);
size_t total_samplerate = 0;
@@ -205,7 +205,7 @@ CEDFFile (const string& fname_, const TSubtype subtype_, const int flags_,
_fsize = header_length + 2 * total_samplerate * data_record_size * n_data_records;
// extend
if ( lseek( _fd, _fsize-1, SEEK_SET) == -1 || write( _fd, "\0", 1) != 1 )
- throw invalid_argument (explain_status(_status |= TStatus::sysfail));
+ throw invalid_argument (explain_status(_status |= sysfail));
// size_t sys_page_size = (size_t) sysconf( _SC_PAGESIZE);
_mmapping =
@@ -226,7 +226,7 @@ CEDFFile (const string& fname_, const TSubtype subtype_, const int flags_,
strncpy( header.version_number, version_string, 8);
_subject = {"Fafa_1", "Mr. Fafa"};
- set_patient_id( _subject.make_recording_id());
+ set_patient_id( _subject.make_recording_id_edf_style());
set_recording_id( "Zzz");
set_comment( fname_);
@@ -494,25 +494,10 @@ _parse_header()
_recording_id = trim( string (header.patient_id, 80));
// sub-parse patient_id into SSubjectId struct
- {
- auto subfields = tokens( _patient_id, " ");
- if ( unlikely (_patient_id.empty()) ) {
- _status |= missing_patient_id;
- } else if ( subfields.size() < 4 ) {
- _subject.id = subfields.front();
- _status |= nonconforming_patient_id;
- } else {
- if ( subfields.size() > 4 )
- _status |= extra_patientid_subfields;
- auto i = subfields.begin();
- _subject.id = *i++;
- _subject.gender = agh::SSubjectId::char_to_gender((*i++)[0]);
- _subject.dob = agh::SSubjectId::str_to_dob(*i++);
- _subject.name = join( tokens(*i++, "_"), " ");
- if ( not _subject.valid() )
- _status |= invalid_subject_details;
- }
- }
+ if ( unlikely (_patient_id.empty()) )
+ _status |= missing_patient_id;
+ _status |=
+ _subject.parse_recording_id_edf_style( _patient_id);
// deal with episode and session
int parsed_status;
diff --git a/src/libsigfile/edf.hh b/src/libsigfile/edf.hh
index a223b2e..04f0358 100644
--- a/src/libsigfile/edf.hh
+++ b/src/libsigfile/edf.hh
@@ -358,34 +358,16 @@ class CEDFFile
enum TStatus : int_least32_t {
- ok = 0,
- bad_header = (1 << 0),
- bad_version = (1 << 1),
- bad_numfld = (1 << 2),
- bad_recording = (1 << 3),
- date_unparsable = (1 << 4),
- time_unparsable = (1 << 5),
- nosession = (1 << 6),
- noepisode = (1 << 7),
- nonkemp_signaltype = (1 << 8),
- non1020_channel = (1 << 9),
- dup_channels = (1 << 10),
- nogain = (1 << 11),
- sysfail = (1 << 12),
- too_many_channels = (1 << 13),
- nonconforming_patient_id = (1 << 14),
- missing_patient_id = (1 << 15),
- invalid_subject_details = (1 << 16),
- file_truncated = (1 << 17),
- trailing_junk = (1 << 18),
- extra_patientid_subfields = (1 << 19),
- recognised_channel_conflicting_type = (1 << 20),
- mmap_error = (1 << 21),
+ bad_version = (1 << (COMMON_STATUS_BITS + 1)),
+ file_truncated = (1 << (COMMON_STATUS_BITS + 2)),
+ trailing_junk = (1 << (COMMON_STATUS_BITS + 3)),
+ mmap_error = (1 << (COMMON_STATUS_BITS + 4)),
+ nogain = (1 << (COMMON_STATUS_BITS + 5)),
+ recognised_channel_conflicting_type = (1 << (COMMON_STATUS_BITS + 6)),
inoperable = (bad_header
| bad_version
| bad_numfld
- | bad_recording
| date_unparsable | time_unparsable
| dup_channels
| nogain
diff --git a/src/libsigfile/source-base.hh b/src/libsigfile/source-base.hh
index b39c513..bea96f8 100644
--- a/src/libsigfile/source-base.hh
+++ b/src/libsigfile/source-base.hh
@@ -221,12 +221,31 @@ class CSource {
no_ancillary_files = 1<<1,
no_field_consistency_check = 1<<2,
};
+ enum TStatus : int_least32_t {
+ ok = 0,
+ bad_header = (1 << 0),
+ bad_numfld = (1 << 1),
+ date_unparsable = (1 << 2),
+ time_unparsable = (1 << 3),
+ nosession = (1 << 4),
+ noepisode = (1 << 5),
+ nonkemp_signaltype = (1 << 6),
+ non1020_channel = (1 << 7),
+ dup_channels = (1 << 8),
+ sysfail = (1 << 9),
+ too_many_channels = (1 << 10),
+ nonconforming_patient_id = (1 << 11),
+ missing_patient_id = (1 << 12),
+ invalid_subject_details = (1 << 13),
+ extra_patientid_subfields = (1 << 14),
+ bad_channel_count = (1 << 15)
+ };
+ const static unsigned COMMON_STATUS_BITS = 15;
protected:
string _filename;
- int _status;
- void clear_status()
- { _status = 0; }
+ int_least32_t
+ _status;
int _flags;
diff --git a/src/libsigfile/tsv.cc b/src/libsigfile/tsv.cc
index 8b1ffa6..2c11920 100644
--- a/src/libsigfile/tsv.cc
+++ b/src/libsigfile/tsv.cc
@@ -57,11 +57,11 @@ CTSVFile (const string& fname_, const int flags_)
struct stat stat0;
int stst = stat( fname_.c_str(), &stat0);
if ( stst == -1 )
- throw invalid_argument (explain_status(_status |= TStatus::sysfail));
+ throw invalid_argument (explain_status(_status |= CSource::TStatus::sysfail));
}
_f = fopen( fname_.c_str(), "r");
if ( !_f )
- throw invalid_argument (explain_status(_status |= TStatus::sysfail));
+ throw invalid_argument (explain_status(_status |= sysfail));
// parse header
if ( _parse_header() ) { // creates channels list
diff --git a/src/libsigfile/tsv.hh b/src/libsigfile/tsv.hh
index 779f8f7..528639a 100644
--- a/src/libsigfile/tsv.hh
+++ b/src/libsigfile/tsv.hh
@@ -321,23 +321,6 @@ class CTSVFile
enum TStatus : int_least32_t {
- ok = 0,
- bad_header = (1 << 0),
- bad_numfld = (1 << 2),
- date_unparsable = (1 << 4),
- time_unparsable = (1 << 5),
- nosession = (1 << 6),
- noepisode = (1 << 7),
- nonkemp_signaltype = (1 << 8),
- non1020_channel = (1 << 9),
- dup_channels = (1 << 10),
- sysfail = (1 << 12),
- too_many_channels = (1 << 13),
- nonconforming_patient_id = (1 << 14),
- missing_patient_id = (1 << 15),
- invalid_subject_details = (1 << 16),
- extra_patientid_subfields = (1 << 19),
-
inoperable = (bad_header
| bad_numfld
| date_unparsable | time_unparsable
--
Sleep experiment manager
More information about the debian-med-commit
mailing list