From 83922c343f269917f9ff309d0b71ec66c0e5dc26 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Wed, 5 May 2021 13:28:11 +0200 Subject: [PATCH] * imc_channel, imc_raw: optimize with pass by reference * imc_object: asc_time, localtime: make threadsafe * imc_datatype: satisfy 'rule of two' * python: remove all unused imports --- lib/imc_channel.hpp | 4 ++-- lib/imc_datatype.hpp | 15 +++++++++++++++ lib/imc_object.hpp | 18 +++++++++--------- lib/imc_raw.hpp | 2 +- myfile.raw | 0 parquet/parquet/generate_make.py | 1 - pip/setup.py | 1 - python/example.py | 1 - python/usage_adv.py | 2 -- 9 files changed, 27 insertions(+), 17 deletions(-) delete mode 100644 myfile.raw diff --git a/lib/imc_channel.hpp b/lib/imc_channel.hpp index 2b8896b..fe667ea 100644 --- a/lib/imc_channel.hpp +++ b/lib/imc_channel.hpp @@ -147,8 +147,8 @@ namespace imc std::string group_uuid_, group_name_, group_comment_; // constructor takes channel's block environment - channel(channel_env chnenv, std::map* blocks, - std::vector* buffer): + channel(channel_env &chnenv, std::map* blocks, + std::vector* buffer): chnenv_(chnenv), blocks_(blocks), buffer_(buffer), factor_(1.), offset_(0.), group_index_(-1) diff --git a/lib/imc_datatype.hpp b/lib/imc_datatype.hpp index 7205a6b..58ce727 100644 --- a/lib/imc_datatype.hpp +++ b/lib/imc_datatype.hpp @@ -70,6 +70,21 @@ namespace imc // identify type short int& dtype() { return dtidx_; } + // copy constructor + datatype(const datatype &num) + { + this->ubyte_ = num.ubyte_; + this->sbyte_ = num.sbyte_; + this->ushort_ = num.ushort_; + this->sshort_ = num.sshort_; + this->ulint_ = num.ulint_; + this->slint_ = num.slint_; + this->sfloat_ = num.sfloat_; + this->sdouble_ = num.sdouble_; + this->sdigital_ = num.sdigital_; + this->dtidx_ = num.dtidx_; + } + // overall assignment operator datatype& operator=(const datatype &num) { diff --git a/lib/imc_object.hpp b/lib/imc_object.hpp index 0fdfcd7..7747ec2 100644 --- a/lib/imc_object.hpp +++ b/lib/imc_object.hpp @@ -501,16 +501,16 @@ namespace imc second_ = std::stod( get_parameter(buffer,¶meters[7]) ); time_t rawtime; - struct tm* ts; + struct tm ts; time(&rawtime); - ts = localtime(&rawtime); - ts->tm_mday = day_; - ts->tm_mon = month_-1; - ts->tm_year = year_-1900; - ts->tm_hour = hour_; - ts->tm_min = minute_; - ts->tm_sec = (int)second_; - timestamp_ = asctime(ts); + localtime_r(&rawtime,&ts); + ts.tm_mday = day_; + ts.tm_mon = month_-1; + ts.tm_year = year_-1900; + ts.tm_hour = hour_; + ts.tm_min = minute_; + ts.tm_sec = (int)second_; + asctime_r(&ts,×tamp_[0]); // timestamp_ = std::to_string(year_) + std::string("-") + std::to_string(month_) // + std::string("-") + std::to_string(day_) // + std::string("T") + std::to_string(hour_) diff --git a/lib/imc_raw.hpp b/lib/imc_raw.hpp index b6ef834..8e6b0cd 100644 --- a/lib/imc_raw.hpp +++ b/lib/imc_raw.hpp @@ -300,7 +300,7 @@ namespace imc } // list a particular type of block - std::vector list_blocks(imc::key mykey) + std::vector list_blocks(const imc::key &mykey) { std::vector myblocks; for ( imc::block blk: this->rawblocks_ ) diff --git a/myfile.raw b/myfile.raw deleted file mode 100644 index e69de29..0000000 diff --git a/parquet/parquet/generate_make.py b/parquet/parquet/generate_make.py index 1c42c27..610cf58 100644 --- a/parquet/parquet/generate_make.py +++ b/parquet/parquet/generate_make.py @@ -1,6 +1,5 @@ #-----------------------------------------------------------------------------# -import glob from pathlib import Path # find source files diff --git a/pip/setup.py b/pip/setup.py index ab6f405..8c38f58 100644 --- a/pip/setup.py +++ b/pip/setup.py @@ -1,6 +1,5 @@ from setuptools import setup, Extension -import os with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() diff --git a/python/example.py b/python/example.py index aa43af3..e6a78f7 100644 --- a/python/example.py +++ b/python/example.py @@ -5,7 +5,6 @@ import raw_eater import raw_meat import pyarrow as pa import pyarrow.parquet as pq -import glob from pathlib import Path fileobj1 = Path("smp/Rangerover_Evoque_F-RR534_2019-05-07/").rglob("*.raw") diff --git a/python/usage_adv.py b/python/usage_adv.py index c58c5b4..1c7414f 100644 --- a/python/usage_adv.py +++ b/python/usage_adv.py @@ -1,9 +1,7 @@ import imc_termite import json -import glob import os -from pathlib import Path # list files in sample directory # fileobj1 = Path("samples/").rglob("*.raw")