[med-svn] [aghermann] 21/23: ICM

andrei zavada hmmr-guest at alioth.debian.org
Sat Aug 17 18:05:44 UTC 2013


This is an automated email from the git hooks/post-receive script.

hmmr-guest pushed a commit to branch master
in repository aghermann.

commit 3544b57e7de0a634b8c0ceb607e99e68b8c5eac9
Author: Andrei Zavada <johnhommer at gmail.com>
Date:   Thu Aug 15 14:32:39 2013 +0300

    ICM
---
 src/aghermann/expdesign/Makefile.am                |    9 +-
 .../expdesign/{primaries.cc => expdesign.cc}       |   70 +----------
 src/aghermann/expdesign/loadsave.cc                |   10 +-
 src/aghermann/expdesign/primaries.hh               |   95 ++++----------
 src/aghermann/expdesign/subject.cc                 |  132 ++++++++++++++++++++
 src/common/containers.hh                           |    8 ++
 6 files changed, 172 insertions(+), 152 deletions(-)

diff --git a/src/aghermann/expdesign/Makefile.am b/src/aghermann/expdesign/Makefile.am
index 3d7a57a..355905d 100644
--- a/src/aghermann/expdesign/Makefile.am
+++ b/src/aghermann/expdesign/Makefile.am
@@ -7,13 +7,14 @@ noinst_LIBRARIES := liba.a
 
 liba_a_SOURCES := \
 	forward-decls.hh \
-	loadsave.cc \
-	tree-scanner.cc \
-	primaries.cc \
 	primaries.hh \
+	profile.hh \
+	expdesign.cc \
+	loadsave.cc \
 	recording.cc \
 	recording.hh \
-	profile.hh
+	subject.cc \
+	tree-scanner.cc
 
 if DO_PCH
 BUILT_SOURCES := \
diff --git a/src/aghermann/expdesign/primaries.cc b/src/aghermann/expdesign/expdesign.cc
similarity index 91%
rename from src/aghermann/expdesign/primaries.cc
rename to src/aghermann/expdesign/expdesign.cc
index d864d13..d807de3 100644
--- a/src/aghermann/expdesign/primaries.cc
+++ b/src/aghermann/expdesign/expdesign.cc
@@ -1,5 +1,5 @@
 /*
- *       File name:  aghermann/expdesign/primaries.cc
+ *       File name:  aghermann/expdesign/expdesign.cc
  *         Project:  Aghermann
  *          Author:  Andrei Zavada <johnhommer at gmail.com>
  * Initial version:  2010-04-28
@@ -11,10 +11,7 @@
 
 
 #include <stdarg.h>
-#include <errno.h>
-#include <cassert>
 #include <string>
-#include <fstream>
 
 #ifdef _OPENMP
 #include <omp.h>
@@ -35,7 +32,7 @@ const char
 };
 
 double
-agh::CExpDesign::freq_bands[metrics::TBand::TBand_total][2] = {
+	agh::CExpDesign::freq_bands[metrics::TBand::TBand_total][2] = {
 	{  1.5,  4.0 },
 	{  4.0,  8.0 },
 	{  8.0, 12.0 },
@@ -44,6 +41,7 @@ agh::CExpDesign::freq_bands[metrics::TBand::TBand_total][2] = {
 };
 
 
+
 agh::CExpDesign::
 CExpDesign (const string& session_dir_,
 	    TMsmtCollectProgressIndicatorFun progress_fun)
@@ -429,68 +427,6 @@ used_samplerates( sigfile::SChannel::TType type) const
 
 
 
-float
-agh::CSubject::
-age() const
-{
-	time_t now = time(NULL);
-	if ( unlikely (now == -1) ) {
-		perror( "What's wrong with localtime? ");
-		return 21.;
-	}
-	return age_rel(now);
-}
-
-float
-agh::CSubject::
-age_rel( time_t rel) const
-{
-	return (difftime(rel, dob))/365.25/24/60/60;
-}
-
-
-
-
-agh::CSubject::SEpisode::
-SEpisode (sigfile::CTypedSource&& F_,
-	  const metrics::psd::SPPack& fft_params,
-	  const metrics::swu::SPPack& swu_params,
-	  const metrics::mc::SPPack& mc_params)
-{
-      // move it in place
-	sources.emplace_back( move(F_));
-	auto& F = sources.back();
-	auto HH = F().channel_list();
-	printf( "CSubject::SEpisode::SEpisode( \"%s\"): %s\n",
-		F().filename(), sigfile::join_channel_names(HH, ", ").c_str());
-	int h = 0;
-	for ( auto& H : HH )
-		recordings.insert( {H, {F, h++, fft_params, swu_params, mc_params}});
-}
-
-
-list<agh::CSubject::SEpisode::SAnnotation>
-agh::CSubject::SEpisode::
-get_annotations() const
-{
-	list<agh::CSubject::SEpisode::SAnnotation>
-		ret;
-	for ( auto &F : sources ) {
-		auto HH = F().channel_list();
-		for ( size_t h = 0; h < HH.size(); ++h ) {
-			auto &AA = F().annotations(h);
-			for ( auto &A : AA )
-				ret.emplace_back( F(), h, A);
-		}
-		for ( auto& A : F().annotations() )
-			ret.emplace_back( F(), -1, A);
-	}
-	ret.sort();
-	return ret;
-}
-
-
-
 
 void
 agh::CExpDesign::
diff --git a/src/aghermann/expdesign/loadsave.cc b/src/aghermann/expdesign/loadsave.cc
index 3b6b999..5a35b40 100644
--- a/src/aghermann/expdesign/loadsave.cc
+++ b/src/aghermann/expdesign/loadsave.cc
@@ -9,12 +9,6 @@
  *         License:  GPL
  */
 
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#include <memory>
-
 #include "common/config-validate.hh"
 #include "aghermann/model/achermann.hh"
 #include "primaries.hh"
@@ -28,7 +22,7 @@ using namespace agh;
 
 
 int
-agh::CExpDesign::
+CExpDesign::
 load_settings()
 {
 	libconfig::Config conf;
@@ -111,7 +105,7 @@ load_settings()
 
 
 int
-agh::CExpDesign::
+CExpDesign::
 save_settings()
 {
 	libconfig::Config conf;
diff --git a/src/aghermann/expdesign/primaries.hh b/src/aghermann/expdesign/primaries.hh
index 6c4d085..186082b 100644
--- a/src/aghermann/expdesign/primaries.hh
+++ b/src/aghermann/expdesign/primaries.hh
@@ -14,21 +14,18 @@
 #define AGH_AGHERMANN_EXPDESIGN_PRIMARIES_H_
 
 
-#include <cstring>
 #include <string>
 #include <list>
-#include <functional>
 #include <forward_list>
 #include <map>
-#include <stdexcept>
 
 #include "common/config-validate.hh"
+#include "common/containers.hh"
 #include "common/subject_id.hh"
 #include "libsigproc/winfun.hh"
 #include "libmetrics/bands.hh"
 #include "aghermann/model/achermann.hh"
 
-#include "recording.hh"
 #include "forward-decls.hh"
 
 #if HAVE_CONFIG_H && !defined(VERSION)
@@ -70,34 +67,18 @@ class CSubject : public SSubjectId {
 		{ return _dir.c_str(); }
 
 	int try_update_subject_details( const agh::SSubjectId& j)
-		{
-			return SSubjectId::update_from( j);
-		}
+		{ return SSubjectId::update_from( j); }
 
-	float age( const string& d) const // age when recordings in this session were made
-		{
-			if ( measurements.find(d) != measurements.end() &&
-			     measurements.at(d).episodes.size() > 0 )
-				return age_rel(
-					measurements.at(d).episodes.front().start_time());
-			else
-				return -1.;
-		}
+	float age( const string& d) const; // age when recordings in this session were made
 	float age() const; // now
 	float age_rel( time_t) const;
 
 	bool operator==( const CSubject &o) const
-		{
-			return id == o.id;
-		}
+		{ return id == o.id; }
 	bool operator==( const string& n) const
-		{
-			return SSubjectId::id == n;
-		}
+		{ return SSubjectId::id == n; }
 	bool operator==( sid_t id) const
-		{
-			return _id == id;
-		}
+		{ return _id == id; }
 
       // contents
 	struct SEpisodeSequence;
@@ -121,14 +102,10 @@ class CSubject : public SSubjectId {
 
 		const char*
 		name() const
-			{
-				return sources.front()().episode();
-			}
+			{ return sources.front()().episode(); }
 		bool
 		operator==( const string& e) const
-			{
-				return e == name();
-			}
+			{ return e == name(); }
 		bool
 		operator<( const SEpisode& rv) const
 			{
@@ -150,20 +127,14 @@ class CSubject : public SSubjectId {
 
 			bool
 			operator<( const SAnnotation& rv) const
-				{
-					return span < rv.span;
-				}
+				{ return span < rv.span; }
 
 			const char*
 			channel() const
-				{
-					return (_h == -1) ? "(embedded)" : _source.channel_by_id(_h).name();
-				}
+				{ return (_h == -1) ? "(embedded)" : _source.channel_by_id(_h).name(); }
 			agh::alg::SSpan<float>
 			page_span( size_t pagesize) const
-				{
-					return span / (float)pagesize;
-				}
+				{ return span / (float)pagesize; }
 		};
 		list<SAnnotation>
 		get_annotations() const;
@@ -182,42 +153,21 @@ class CSubject : public SSubjectId {
 	    public:
 		list<SEpisode> episodes;
 		size_t
-		__attribute__ ((pure))
 		size() const
-			{
-				return episodes.size();
-			}
+			{ return episodes.size(); }
+
 		list<SEpisode>::const_iterator
 		episode_iter_by_name( const string& e) const
-			{
-				return find( episodes.begin(), episodes.end(), e);
-			}
+			{ return find( episodes.begin(), episodes.end(), e); }
 		bool
 		have_episode( const string& e) const
-			{
-				return episode_iter_by_name(e) != episodes.cend();
-			}
+			{ return episode_iter_by_name(e) != episodes.cend(); }
+
 		const SEpisode&
-		operator[]( const string& e) const
-			{
-				auto E = find( episodes.begin(), episodes.end(), e);
-				if ( E != episodes.end() )
-					return *E;
-				else
-					throw invalid_argument( string("no such episode: ") + e);
-			}
+		operator[]( const string& e) const;
 		SEpisode&
-		operator[]( const string& e)
-			{
-				auto E = find( episodes.begin(), episodes.end(), e);
-				if ( E != episodes.end() )
-					return *E;
-				else // or don't throw, go and make one?
-					throw invalid_argument( string("no such episode: ") + e);
-				// no, let it be created in
-				// CExpDesign::add_measurement, when
-				// episode start/end times are known
-			}
+		operator[]( const string& e);
+
 	      // either construct a new episode from F, or update an
 	      // existing one (add F to its sources)
 		int
@@ -296,10 +246,9 @@ class CExpDesign {
 	session_dir() const
 		{ return _session_dir.c_str(); }
 
-	string name() const // dirname
-		{
-			return _session_dir.substr( _session_dir.rfind( '/'));
-		}
+	string
+	name() const // dirname
+		{ return _session_dir.substr( _session_dir.rfind( '/')); }
 
       // error log
 	enum class TLogEntryStyle { plain, bold, italic };
diff --git a/src/aghermann/expdesign/subject.cc b/src/aghermann/expdesign/subject.cc
new file mode 100644
index 0000000..8577753
--- /dev/null
+++ b/src/aghermann/expdesign/subject.cc
@@ -0,0 +1,132 @@
+/*
+ *       File name:  aghermann/expdesign/subject.cc
+ *         Project:  Aghermann
+ *          Author:  Andrei Zavada <johnhommer at gmail.com>
+ * Initial version:  2013-08-14
+ *
+ *         Purpose:  experimental design primary classes: CSubject
+ *
+ *         License:  GPL
+ */
+
+
+#include "primaries.hh"
+
+
+using namespace std;
+
+using namespace agh;
+
+
+float
+CSubject::
+age( const string& d) const // age when recordings in this session were made
+{
+	if ( alg::member(d, measurements) &&
+	     measurements.at(d).episodes.size() > 0 )
+		return age_rel(
+			measurements.at(d).episodes.front().start_time());
+	else
+		return -1.;
+}
+
+
+
+float
+CSubject::
+age() const
+{
+	time_t now = time(NULL);
+	if ( unlikely (now == -1) ) {
+		perror( "What's wrong with localtime? ");
+		return 21.;
+	}
+	return age_rel(now);
+}
+
+float
+CSubject::
+age_rel( time_t rel) const
+{
+	return (difftime(rel, dob))/365.25/24/60/60;
+}
+
+
+
+
+
+
+CSubject::SEpisode::
+SEpisode (sigfile::CTypedSource&& F_,
+	  const metrics::psd::SPPack& fft_params,
+	  const metrics::swu::SPPack& swu_params,
+	  const metrics::mc::SPPack& mc_params)
+{
+      // move it in place
+	sources.emplace_back( move(F_));
+	auto& F = sources.back();
+	auto HH = F().channel_list();
+	printf( "CSubject::SEpisode::SEpisode( \"%s\"): %s\n",
+		F().filename(), sigfile::join_channel_names(HH, ", ").c_str());
+	int h = 0;
+	for ( auto& H : HH )
+		recordings.insert( {H, {F, h++, fft_params, swu_params, mc_params}});
+}
+
+
+list<CSubject::SEpisode::SAnnotation>
+CSubject::SEpisode::
+get_annotations() const
+{
+	list<agh::CSubject::SEpisode::SAnnotation>
+		ret;
+	for ( auto &F : sources ) {
+		auto HH = F().channel_list();
+		for ( size_t h = 0; h < HH.size(); ++h ) {
+			auto &AA = F().annotations(h);
+			for ( auto &A : AA )
+				ret.emplace_back( F(), h, A);
+		}
+		for ( auto& A : F().annotations() )
+			ret.emplace_back( F(), -1, A);
+	}
+	ret.sort();
+	return ret;
+}
+
+
+
+const CSubject::SEpisode&
+CSubject::SEpisodeSequence::
+operator[]( const string& e) const
+{
+	auto E = find( episodes.begin(), episodes.end(), e);
+	if ( E != episodes.end() )
+		return *E;
+	else
+		throw invalid_argument( string("no such episode: ") + e);
+}
+
+CSubject::SEpisode&
+CSubject::SEpisodeSequence::
+operator[]( const string& e)
+{
+	auto E = find( episodes.begin(), episodes.end(), e);
+	if ( E != episodes.end() )
+		return *E;
+	else // or don't throw, go and make one?
+		throw invalid_argument( string("no such episode: ") + e);
+	// no, let it be created in
+	// CExpDesign::add_measurement, when
+	// episode start/end times are known
+}
+
+
+
+
+// Local Variables:
+// Mode: c++
+// indent-tabs-mode: 8
+// tab-width: 8
+// c-basic-offset: 8
+// End:
diff --git a/src/common/containers.hh b/src/common/containers.hh
index ec84ec2..5f2abee 100644
--- a/src/common/containers.hh
+++ b/src/common/containers.hh
@@ -15,6 +15,7 @@
 #include <list>
 #include <forward_list>
 #include <vector>
+#include <map>
 
 #if HAVE_CONFIG_H && !defined(VERSION)
 #  include "config.h"
@@ -46,6 +47,13 @@ member( const T& x, const vector<T>& v)
 	return any( v.begin(), v.end(), x);
 }
 
+template <typename K, typename V>
+bool
+member( const K& x, const map<K, V>& m)
+{
+	return m.find(x) != m.end();
+}
+
 } // namespace alg
 } // namespace agh
 

-- 
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/aghermann.git



More information about the debian-med-commit mailing list