Aufgrund von Umarbeiten des s3 Storage wird es in GitLab, in nächster Zeit, mögliche Performance-Einbußen geben. Näheres dazu unter: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/43/show_ticket/6670

Fixing problems with TIADataLog template class

parent 9810f41f
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
// $Id: ITADataLog.h,v 1.7 2009-01-18 02:04:10 stienen Exp $
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_DATA_LOG
#define INCLUDE_WATCHER_ITA_DATA_LOG
......@@ -33,7 +32,7 @@
/**
* Realisiert Formattierungsfunktionen fr Konsolen-/Dateiausgabe
*/
class ITALogDataBase
ITA_BASE_API class ITALogDataBase
{
public:
inline virtual ~ITALogDataBase() {};
......@@ -41,20 +40,19 @@ public:
//! Hook: Ausgabe der Beschreibung des Datums (z.B. Felder) in einen Stream
// Dies wird fr den Header in der Datei verwendet
// Zum Beispiel so: [0] Index, [1] Time, ...
virtual std::ostream& outputDesc(std::ostream& os) const=0;
virtual std::ostream& outputDesc( std::ostream& os ) const = 0;
//! Hook: Ausgabe eines konkreten Datums in einen Stream (Formattierer)
virtual std::ostream& outputData(std::ostream& os) const=0;
virtual std::ostream& outputData( std::ostream& os ) const = 0;
};
//! Gepufferter Logger fr Daten
template <class T> class ITABufferedDataLogger
{
public:
ITABufferedDataLogger();
ITABufferedDataLogger( int iNumItems );
ITABufferedDataLogger( int iNumItems = 100, bool bMatlab = true );
ITABufferedDataLogger(const std::string& sOutputFile, int iNumItems, bool bMatlab=true);
ITABufferedDataLogger( const std::string& sOutputFilePath, int iNumItems, bool bMatlab = true );
virtual ~ITABufferedDataLogger();
......@@ -63,7 +61,7 @@ public:
* Falls diese angegeben wird, so werden alle geloggten Daten
* beim Aufruf des Destruktors in diese Datei geschrieben
*/
void setOutputFile(const std::string& sFilename);
void setOutputFile( const std::string& sFilePath );
std::string GetOutputFileName() const;
......@@ -71,13 +69,13 @@ public:
void clear();
//! Platz fr Datenfelder reservieren
void reserve(int iNumItems);
void reserve( int iNumItems );
//! Datum loggen
void log(const T& oLogItem);
void log( const T& oLogItem );
//! Alle geloggten Eintrge in eine Datei schreiben
void store( std::string sFilename="" );
void store( const std::string& sFilePath );
private:
std::vector<T> m_vLogItems;
......@@ -88,23 +86,24 @@ private:
// Header impl to avoid explicit definitions
template <class T> ITABufferedDataLogger<T>::ITABufferedDataLogger()
: m_bMatlab(true)
template< class T > ITABufferedDataLogger< T >::ITABufferedDataLogger( int iNumItems, bool bMatlab )
: m_bMatlab( bMatlab )
{
// Default size for log: 100 elements
m_vLogItems.reserve(100);
m_vLogItems.reserve( iNumItems );
}
template< class T > ITABufferedDataLogger< T >::ITABufferedDataLogger(const std::string& sOutputFile, int iNumItems, bool bMatlab)
: m_sOutputFile(sOutputFile), m_bMatlab(bMatlab)
template< class T > ITABufferedDataLogger< T >::ITABufferedDataLogger( const std::string& sOutputFile, int iNumItems, bool bMatlab )
: m_sOutputFile( sOutputFile )
, m_bMatlab( bMatlab )
{
m_vLogItems.reserve(iNumItems);
m_vLogItems.reserve( iNumItems );
}
template< class T > ITABufferedDataLogger< T >::~ITABufferedDataLogger()
{
if (!m_sOutputFile.empty())
store(m_sOutputFile);
if( !m_sOutputFile.empty() )
store( m_sOutputFile );
}
template< class T > std::string ITABufferedDataLogger< T >::GetOutputFileName() const
......@@ -112,39 +111,39 @@ template< class T > std::string ITABufferedDataLogger< T >::GetOutputFileName()
return m_sOutputFile;
}
template <class T> ITABufferedDataLogger<T>::ITABufferedDataLogger(int iNumItems)
{
m_vLogItems.reserve(iNumItems);
}
template< class T > void ITABufferedDataLogger<T>::setOutputFile(const std::string& sFilename)
template< class T > void ITABufferedDataLogger< T >::setOutputFile( const std::string& sFilename )
{
m_sOutputFile = sFilename;
}
template <class T> void ITABufferedDataLogger<T>::clear() {
template< class T > void ITABufferedDataLogger< T >::clear() {
m_vLogItems.clear();
}
template <class T> void ITABufferedDataLogger<T>::reserve(int iNumItems) {
m_vLogItems.reserve(iNumItems);
template< class T > void ITABufferedDataLogger< T >::reserve( int iNumItems )
{
m_vLogItems.reserve( iNumItems );
}
template <class T> void ITABufferedDataLogger<T>::log(const T& oLogItem) {
m_vLogItems.push_back(oLogItem);
template< class T > void ITABufferedDataLogger< T >::log( const T& oLogItem )
{
m_vLogItems.push_back( oLogItem );
}
template <class T> void ITABufferedDataLogger<T>::store(const std::string& sFilename) {
std::ofstream os(sFilename.c_str(), std::ios::out | std::ios::trunc | std::ios::binary);
if (!os.is_open())
ITA_EXCEPT1(IO_ERROR, std::string("Could not create log output file \"") + sFilename + std::string("\""));
template< class T > void ITABufferedDataLogger< T >::store( const std::string& sFilename )
{
std::ofstream os( sFilename.c_str(), std::ios::out | std::ios::trunc | std::ios::binary );
if( !os.is_open() )
ITA_EXCEPT1( IO_ERROR, std::string( "Could not create log output file \"" ) + sFilename + std::string( "\"" ) );
for (int i = 0; i<(int)m_vLogItems.size(); i++) {
T& oItem = m_vLogItems[i];
if (i == 0 && !m_bMatlab)
oItem.outputDesc(os);
for( int i = 0; i < ( int ) m_vLogItems.size(); i++ )
{
T& oItem = m_vLogItems[ i ];
if( i == 0 && !m_bMatlab )
oItem.outputDesc( os );
else
oItem.outputData(os);
oItem.outputData( os );
}
os.close();
......
Markdown is supported
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