30 #ifndef FILEHANDLING_HPP 31 #define FILEHANDLING_HPP 49 std::fstream fs(filename, std::ios_base::binary | std::ios_base::out);
52 throw RuntimeException(
"Could not open the file. Wrong filename or permissions?");
66 std::fstream fs(filename, std::ios_base::binary | std::ios_base::in);
69 throw RuntimeException(
"Could not open the file. Wrong filename or permissions?");
101 fs.read(reinterpret_cast<char *>(arr.
data()), arr.
size());
104 throw RuntimeException(
"Could not read the data from the file. Not enough data?");
117 fs.seekg(
sizeof(T) * samplesPerTrace * trace);
123 arr.
init(samplesPerTrace);
140 fs.seekg(
sizeof(T) * samplesPerTrace * noOfCandidates * matrix +
sizeof(T) * samplesPerTrace * candidate);
146 arr.
init(samplesPerTrace);
169 arr.
init(samplesPerTrace);
186 fs.write(reinterpret_cast<const char *>(buffer), len *
sizeof(T));
189 throw RuntimeException(
"Could not write the data to the file. Not enough space?");
202 fs.write(reinterpret_cast<const char *>(arr.
data()), arr.
size());
205 throw RuntimeException(
"Could not write the data to the file. Not enough space?");
218 uint64_t ctxAttrs[7];
220 fs.read(reinterpret_cast<char *>(ctxAttrs),
sizeof(uint64_t) * 7);
226 ret.
p1Card() = ctxAttrs[2];
227 ret.
p2Card() = ctxAttrs[3];
229 for(
size_t order = 1; order <= ret.
mOrder(); order++){
234 for(
size_t order = 2; order <= ret.
csOrder(); order++){
239 for(
size_t order = 1; order <= ret.
acsOrder(); order++){
256 uint64_t ctxAttrs[7];
259 ctxAttrs[2] = ctx.
p1Card();
260 ctxAttrs[3] = ctx.
p2Card();
261 ctxAttrs[4] = ctx.
mOrder();
265 fs.write(reinterpret_cast<char *>(ctxAttrs),
sizeof(uint64_t) * 7);
270 for(
size_t order = 1; order <= ctx.
mOrder(); order++){
275 for(
size_t order = 2; order <= ctx.
csOrder(); order++){
280 for(
size_t order = 1; order <= ctx.
acsOrder(); order++){
UnivariateContext< T > readContextFromFile(std::fstream &fs)
Reads context from file, based on the context's file format.
Definition: filehandling.hpp:216
Vector< T > loadTValuesFromFile(std::fstream &fs, size_t samplesPerTrace)
Loads a t-values trace from file, based on parameters given.
Definition: filehandling.hpp:161
virtual size_t size() const =0
Returns the size of the contained data (i.e. length * sizeof(T))
void closeFile(std::fstream &fs)
Flushes and closes the filestream.
Definition: filehandling.hpp:81
A class representing a vector, stored in the machine's free space.
Definition: types_basic.hpp:217
A class representing a Two-population Univariate Moment-based statistical context.
Definition: types_stat.hpp:43
virtual Matrix< T > & p12ACS(size_t order)
Adjusted central moment sum both populations, order 1 upto acsOrder.
Definition: types_stat.hpp:220
This header file contains exceptions.
virtual T * data()=0
Returns a pointer to the contained data.
virtual size_t mOrder() const
Maximum order of the raw moments, 1 upto mOrder.
Definition: types_stat.hpp:183
virtual size_t csOrder() const
Maximum order of the central moment sums, 2 upto csOrder.
Definition: types_stat.hpp:185
std::fstream openInFile(const char *filename)
Opens filestream for reading.
Definition: filehandling.hpp:64
void writeContextToFile(std::fstream &fs, const UnivariateContext< T > &ctx)
Writes context to file.
Definition: filehandling.hpp:254
virtual size_t p2Width() const
Width of the second population.
Definition: types_stat.hpp:180
virtual size_t & p1Card()
Cardinality of the first population.
Definition: types_stat.hpp:190
Vector< T > loadPowerTraceFromFile(std::fstream &fs, size_t samplesPerTrace, size_t trace)
Loads a power trace from file, based on parameters given.
Definition: filehandling.hpp:115
virtual size_t p1Width() const
Width of the first population.
Definition: types_stat.hpp:178
virtual size_t acsOrder() const
Maximum order of the adjusted central moment sums, 1 upto acsOrder.
Definition: types_stat.hpp:187
virtual void init(size_t length)
Initializes the vector with a specified number of elements.
Definition: types_basic.hpp:249
void writeArrayToFile(std::fstream &fs, const T *buffer, size_t len)
Writes array to file.
Definition: filehandling.hpp:184
Vector< T > loadCorrelationTraceFromFile(std::fstream &fs, size_t samplesPerTrace, size_t noOfCandidates, size_t matrix, size_t candidate)
Loads a correlation trace from file, based on parameters given.
Definition: filehandling.hpp:138
virtual Vector< T > & p2CS(size_t order)
Central moment sum of the second population, order 2 upto csOrder.
Definition: types_stat.hpp:215
This header file contains class templates of basic data containers.
This header file contains class templates of power traces and power consumption containers.
virtual size_t & p2Card()
Cardinality of the second population.
Definition: types_stat.hpp:195
std::fstream openOutFile(const char *filename)
Opens filestream for writing.
Definition: filehandling.hpp:47
virtual Vector< T > & p1CS(size_t order)
Central moment sum of the first population, order 2 upto csOrder.
Definition: types_stat.hpp:210
virtual Vector< T > & p2M(size_t order)
Raw moment of the second population, order 1 upto mOrder.
Definition: types_stat.hpp:205
An exception which cannot be directly influenced by the user, or predicted beforehand.
Definition: exceptions.hpp:76
This header file contains class templates of statistical computational contexts.
void fillArrayFromFile(std::fstream &fs, ArrayType< T > &arr)
Fills array from file, based on the given Array's size.
Definition: filehandling.hpp:99
virtual Vector< T > & p1M(size_t order)
Raw moment of the first population, order 1 upto mOrder.
Definition: types_stat.hpp:200
An abstract class, representing all the array-like data types.
Definition: types_basic.hpp:67