Commit c675f3f5 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

improved reading efficiency - hopefully

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 2891
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 39ea28bc
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsofttest.cc,v 1.12 2009-11-12 07:23:55 tforb Exp $
* $Id: tsofttest.cc,v 1.13 2009-11-12 15:20:26 tforb Exp $
* \author Thomas Forbriger
* \date 17/09/2009
*
......@@ -35,7 +35,7 @@
#define TSOFTTEST_VERSION \
"TSOFTTEST V1.0 test tsoft reading"
#define TSOFTTEST_CVSID \
"$Id: tsofttest.cc,v 1.12 2009-11-12 07:23:55 tforb Exp $"
"$Id: tsofttest.cc,v 1.13 2009-11-12 15:20:26 tforb Exp $"
#include <iostream>
#include <fstream>
......@@ -275,19 +275,21 @@ int main(int iargc, char* argv[])
sff::FREE channelfree;
channelfree.append(datread::tsoft::channelinfofree(ci));
cout << channelfree;
cout << "number of available sequences: " << cd.nsequences() << endl;
for (int iseq=0; iseq<cd.nsequences(); ++iseq)
cout << "number of available sequences: " << cd.ntraces() << endl;
for (int iseq=0; iseq<cd.ntraces(); ++iseq)
{
const datread::tsoft::Datasequence& ds=cd.sequence(iseq);
const datread::tsoft::Datatrace& ds=cd.trace(iseq);
cout << " sequence #" << iseq << ":" << endl;
cout << " =============" << endl;
cout << " start: " << ds.date().timestring() << endl;
cout << " dt: " << ds.interval().timestring() << endl;
cout << " number of samples: " << ds.nsamples() << endl;
int nsmp=ds.nsamples() < 10 ? ds.nsamples() : 10;
datread::Tdseries s=ds.series();
cout << " number of samples: " << s.size() << endl;
int nsmp=s.size() < 10 ? s.size() : 10;
int f=s.f();
for (int isa=0; isa<nsmp; ++isa)
{
cout << " " << ds.sample(isa) << endl;
cout << " " << s(f+isa) << endl;
}
}
}
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsoftdata.cc,v 1.14 2009-11-12 07:38:51 tforb Exp $
* $Id: tsoftdata.cc,v 1.15 2009-11-12 15:20:26 tforb Exp $
* \author Thomas Forbriger
* \date 16/09/2009
*
......@@ -35,7 +35,7 @@
#define DATREAD_TSOFTDATA_CC_VERSION \
"DATREAD_TSOFTDATA_CC V1.0 "
#define DATREAD_TSOFTDATA_CC_CVSID \
"$Id: tsoftdata.cc,v 1.14 2009-11-12 07:38:51 tforb Exp $"
"$Id: tsoftdata.cc,v 1.15 2009-11-12 15:20:26 tforb Exp $"
#include <datreadxx/error.h>
#include <datreadxx/tsoftdata.h>
......@@ -165,8 +165,55 @@ namespace datread {
return(retval);
} // libtime::TAbsoluteTime Datasequence::timeofnextsample() const
/*----------------------------------------------------------------------*/
void Datasequence::initialize()
{
Msamples.reserve(86500);
Msamples.clear();
Mdate=libtime::TAbsoluteTime();
Minterval=0;
} // void Datasequence::initialize()
/*----------------------------------------------------------------------*/
Tdseries Datasequence::series() const
{
Tdseries series(Msamples.size());
Tvod::const_iterator I=Msamples.begin();
for (aff::Tsubscript i=series.f();
((i<=series.l()) && (I!=Msamples.end()));
++i, ++I)
{
series(i)= (*I);
}
return(series);
} // Tdseries Datasequence::series() const
/*======================================================================*/
// class Channeldata
Channeldata::Channeldata()
{
Mcollector.initialize();
} // Channeldata::Channeldata()
/*----------------------------------------------------------------------*/
void Channeldata::flushcollector()
{
if (Mcollector.nsamples()>0)
{
Datatrace trace;
trace.date(Mcollector.date());
trace.interval(Mcollector.interval());
trace.series(Mcollector.series());
Mtraces.push_back(trace);
Mcollector.initialize();
}
} // Channeldata::flushcollector()
/*----------------------------------------------------------------------*/
void Channeldata::push_sample(const libtime::TAbsoluteTime& time,
const std::string& value,
......@@ -180,54 +227,25 @@ namespace datread {
{
std::cout << " yes, take this sample" << std::endl;
}
Datasequence& last=Msequences.back();
std::istringstream iss(value);
double value;
iss >> value;
if (debug)
{
std::cout << " check, if we are in sequence" << std::endl;
}
bool insequence = (this->nsequences() > 0);
if (debug)
{
std::cout << " number of sequences: "
<< this->nsequences() << std::endl;
if (insequence)
{
std::cout << " we still expect to be in sequence"
<< std::endl;
}
}
if (insequence)
{
insequence = ((time == last.timeofnextsample(debug))
&& (dt == last.interval()));
}
if (debug)
{
std::cout << " value: " << value << std::endl;
}
// check, whether collector is already in use
bool insequence = (Mcollector.nsamples() > 0);
// if collector is in use, then check is current value matches
if (insequence)
{
if (debug)
{
std::cout << " we are in the sequence" << std::endl;
}
last.append(value);
insequence = ((time == Mcollector.timeofnextsample(debug))
&& (dt == Mcollector.interval()));
}
else
// if current value does not match: flush collector and start new
if (!insequence)
{
if (debug)
{
std::cout << " we are NOT in the sequence" << std::endl;
}
Datasequence newsequence;
newsequence.append(value);
newsequence.date(time);
newsequence.interval(dt);
this->append(newsequence);
this->flushcollector();
Mcollector.date(time);
Mcollector.interval(dt);
}
Mcollector.append(value);
}
} // void Channeldata::push_sample
......@@ -266,6 +284,16 @@ namespace datread {
}
} // Datacontainer::push_data
/*----------------------------------------------------------------------*/
void Datacontainer::flushchannels()
{
for (unsigned int ich=0; ich<Mchannels.size(); ++ich)
{
Mchannels[ich].flushcollector();
}
} // void Datacontainer::flushchannels()
/*======================================================================*/
// functions
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsoftdata.h,v 1.14 2009-11-12 07:23:55 tforb Exp $
* $Id: tsoftdata.h,v 1.15 2009-11-12 15:20:26 tforb Exp $
* \author Thomas Forbriger
* \date 16/09/2009
*
......@@ -39,7 +39,7 @@
#define DATREAD_TSOFTDATA_H_VERSION \
"DATREAD_TSOFTDATA_H V1.0 "
#define DATREAD_TSOFTDATA_H_CVSID \
"$Id: tsoftdata.h,v 1.14 2009-11-12 07:23:55 tforb Exp $"
"$Id: tsoftdata.h,v 1.15 2009-11-12 15:20:26 tforb Exp $"
#include<iostream>
#include<string>
......@@ -47,6 +47,7 @@
#include<list>
#include<libtime++.h>
#include<datreadxx/error.h>
#include<datreadxx/datread.h>
namespace datread {
......@@ -233,6 +234,34 @@ namespace datread {
/*----------------------------------------------------------------------*/
/*! \brief trace of contiguous data.
* \ingroup tsoft
*/
class Datatrace {
public:
//! set time of first sample
void date(const libtime::TAbsoluteTime d) { Mdate=d; }
//! set sampling interval
void interval(const libtime::TRelativeTime i) { Minterval=i; }
//! set series
void series(const Tdseries& s) { Mseries=s; }
//! return time of first sample
libtime::TAbsoluteTime date() const { return Mdate; }
//! return sampling interval
libtime::TRelativeTime interval() const { return Minterval; }
//! return series
Tdseries series() const { return Mseries; }
private:
//! samples
Tdseries Mseries;
//! time of first sample
libtime::TAbsoluteTime Mdate;
//! sampling interval
libtime::TRelativeTime Minterval;
}; // class Datatrace
/*----------------------------------------------------------------------*/
/*! \brief sequence of contiguous data.
* \ingroup tsoft
*/
......@@ -259,6 +288,10 @@ namespace datread {
libtime::TAbsoluteTime timeofnextsample(const bool& debug=false) const;
//! return sampling interval
libtime::TRelativeTime interval() const { return Minterval; }
//! initialize data sequence
void initialize();
//! return samples in a series container
Tdseries series() const;
private:
//! samples
Tvod Msamples;
......@@ -273,7 +306,7 @@ namespace datread {
/*! \brief vector of sequences.
* \ingroup tsoft
*/
typedef std::vector<Datasequence> Tvods;
typedef std::vector<Datatrace> Tvodt;
/*----------------------------------------------------------------------*/
......@@ -282,27 +315,27 @@ namespace datread {
*/
class Channeldata {
public:
//! constructor to initialize
Channeldata();
//! push a sample
void push_sample(const libtime::TAbsoluteTime& time,
const std::string& values,
const std::string& undetval,
const libtime::TRelativeTime& dt,
const bool& debug=false);
//! append a data sequence
void append(const Datasequence& v) { Msequences.push_back(v); }
//! return data sequence
const Datasequence& sequence(const unsigned int& i) const
//! return data trace
const Datatrace& trace(const unsigned int& i) const
{
DATREAD_assert(((i<Msequences.size()) && (i>=0)),
"illegal sequence index");
return Msequences[i];
DATREAD_assert(((i<Mtraces.size()) && (i>=0)),
"illegal trace index");
return Mtraces[i];
}
//! return data sequence
Datasequence& sequence(const unsigned int& i)
//! return data trace
Datatrace& trace(const unsigned int& i)
{
DATREAD_assert(((i<Msequences.size()) && (i>=0)),
"illegal sequence index");
return Msequences[i];
DATREAD_assert(((i<Mtraces.size()) && (i>=0)),
"illegal trace index");
return Mtraces[i];
}
//! set channel info
void chinfo(const Channelinfo& ci) { Mchannelinfo=ci; }
......@@ -310,11 +343,17 @@ namespace datread {
const Channelinfo& chinfo() const { return(Mchannelinfo); }
//! return channel info
Channelinfo& chinfo() { return(Mchannelinfo); }
//! number of data sequences
int nsequences() const { return Msequences.size(); }
//! number of data traces
int ntraces() const { return Mtraces.size(); }
//! function to flush collector to vector of sequences
void flushcollector();
private:
//! data sequences
Tvods Msequences;
//! function to reset collector
void resetcollector();
//! data traces
Tvodt Mtraces;
//! vector of samples to collect from file
Datasequence Mcollector;
//! channel info
Channelinfo Mchannelinfo;
}; // class Channeldata
......@@ -385,6 +424,8 @@ namespace datread {
}
//! return number of channels
int nchannels() const { return Mchannels.size(); }
//! flush all channels
void flushchannels();
private:
//! data sequences
mutable Tvocd Mchannels;
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsoftsffcontainer.cc,v 1.5 2009-11-12 07:38:51 tforb Exp $
* $Id: tsoftsffcontainer.cc,v 1.6 2009-11-12 15:20:26 tforb Exp $
* \author Thomas Forbriger
* \date 11/11/2009
*
......@@ -35,7 +35,7 @@
#define DATREAD_TSOFTSFFCONTAINER_CC_VERSION \
"DATREAD_TSOFTSFFCONTAINER_CC V1.0 "
#define DATREAD_TSOFTSFFCONTAINER_CC_CVSID \
"$Id: tsoftsffcontainer.cc,v 1.5 2009-11-12 07:38:51 tforb Exp $"
"$Id: tsoftsffcontainer.cc,v 1.6 2009-11-12 15:20:26 tforb Exp $"
#include <datreadxx/tsoftsffcontainer.h>
#include <datreadxx/tsoftreader.h>
......@@ -62,7 +62,7 @@ namespace datread {
std::cout << "ich " << ich <<
" has " << cd.nsequences() << " sequences" << std::endl;
*/
ntraces += cd.nsequences();
ntraces += cd.ntraces();
}
// std::cout << "found " << ntraces << " traces" << std::endl;
......@@ -77,24 +77,18 @@ namespace datread {
const Channelinfo& ci=cd.chinfo();
sff::FREE channelfree;
channelfree.append(channelinfofree(ci));
for (int iseq=0; iseq<cd.nsequences(); ++iseq)
for (int itr=0; itr<cd.ntraces(); ++itr)
{
I->Mfree=channelfree;
const Datasequence& ds=cd.sequence(iseq);
const Datatrace& ds=cd.trace(itr);
// extract samples
I->Mseries=Tdseries(ds.nsamples());
aff::Iterator<Tdseries> IS(I->Mseries);
for (int isa=0; isa<ds.nsamples(); ++isa)
{
*IS = ds.sample(isa);
++IS;
}
I->Mseries=ds.series();
// extract header
I->Mwid2.date=ds.date();
I->Mwid2.dt=libtime::time2double(ds.interval());
I->Mwid2.nsamples=ds.nsamples();
I->Mwid2.nsamples=I->Mseries.size();
TSOFTchannelid tci;
tci.location=ci.thelocation();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment