File: histogram_writer.h

package info (click to toggle)
kmc 2.3%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,412 kB
  • sloc: cpp: 17,316; perl: 178; makefile: 90; sh: 16
file content (54 lines) | stat: -rw-r--r-- 1,142 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
  This file is a part of KMC software distributed under GNU GPL 3 licence.
  The homepage of the KMC project is http://sun.aei.polsl.pl/kmc
  
  Authors: Marek Kokot
  
  Version: 2.3.0
  Date   : 2015-08-21
*/

#ifndef _HISTOGRAM_WRITER_H
#define _HISTOGRAM_WRITER_H

#include "defs.h"
#include "config.h"
#include <vector>
#include <fstream>

template<typename KMCDB> class CHistogramWriter
{
	KMCDB& kmcdb;
	COutputDesc& output_desc;
	std::vector<uint32> counters;

public:
	CHistogramWriter(KMCDB& kmcdb) :kmcdb(kmcdb), output_desc(CConfig::GetInstance().output_desc)
	{

	}
	bool Process()
	{
		counters.resize(output_desc.cutoff_max + 1);
		uint32 counter;
		while (kmcdb.NextCounter(counter))
		{
			if (counter >= output_desc.cutoff_min && counter <= output_desc.cutoff_max)
				counters[counter]++;
		}
		std::ofstream file(output_desc.file_src);
		if (!file)
		{
			std::cout << "Error: cannot open file: " << output_desc.file_src << "\n";
			exit(1);
		}
		for (uint32 i = output_desc.cutoff_min; i <= output_desc.cutoff_max; ++i)
		{
			file << i << "\t" << counters[i] << "\n";
		}
		file.close();
		return true;
	}
};

#endif