Belle II Software development
LUT.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9//-----------------------------------------------------------------------------
10// Description : A class to use LUTs for TRGCDC
11//-----------------------------------------------------------------------------
12
13#define TRG_SHORT_NAMES
14#define TRGCDC_SHORT_NAMES
15
16#include <fstream>
17#include "trg/cdc/LUT.h"
18#include "trg/cdc/TRGCDCTrack.h"
19#include "trg/cdc/Link.h"
20#include <cstdlib>
21#include <math.h>
22
23using namespace std;
24
25namespace Belle2 {
31 map<string, TRGCDCLUT> TRGCDCLUT::dictionary;
32
33 std::string TRGCDCLUT::version(void) const
34 {
35 return string("TRGCDCLUT 1.00");
36 }
37
39 m_data{}, m_bitsize(), m_name() // 2019/07/31 by ytlai
40 {
41 }
42
44 {
45 }
46
47 int TRGCDCLUT::getValue(unsigned id) const
48 {
49 unsigned range = pow(2, m_bitsize);
50 if (id >= range) {
51 return 0;
52 } else {
53 return m_data[id];
54 }
55 }
56
57 void TRGCDCLUT::setDataFile(const string& filename, int nInputBit)
58 {
59 m_bitsize = nInputBit;
60 m_name = filename;
61
62 ifstream openFile;
63 string tmpstr;
64 int tmpint;
65 int i = 0;
66 int range = pow(2, nInputBit);
67 openFile.open(filename.c_str());
68 m_data.resize(range);
69 while (getline(openFile, tmpstr) && i < range) {
70 if (!(tmpstr.size() == 0)) {
71 if (tmpstr[0] >= '0' && tmpstr[0] <= '9') {
72 tmpint = atoi(tmpstr.c_str());
73 m_data[i] = tmpint;
74 i++;
75 } else {
76 continue;
77 }
78 }
79 }
80 openFile.close();
81 }
82
83 TRGCDCLUT* TRGCDCLUT::getLUT(const std::string& filename, int nInputBit)
84 {
85 if (!TRGCDCLUT::dictionary.count(filename)) {
86 TRGCDCLUT::dictionary[filename] = TRGCDCLUT();
87 TRGCDCLUT::dictionary[filename].setDataFile(filename, nInputBit);
88 }
89 return &(TRGCDCLUT::dictionary[filename]);
90 }
92}
93
A class to use LUTs for TRGCDC.
Definition: LUT.h:39
std::vector< int > m_data
LUT data.
Definition: LUT.h:72
int m_bitsize
Input bit size.
Definition: LUT.h:75
std::string m_name
LUT name.
Definition: LUT.h:78
void setDataFile(const std::string &filename, int)
set LUT data.
Definition: LUT.cc:57
virtual ~TRGCDCLUT()
Destructor.
Definition: LUT.cc:43
std::string version(void) const
returns version.
Definition: LUT.cc:33
int getValue(unsigned) const
get LUT Values
Definition: LUT.cc:47
TRGCDCLUT()
Contructor.
Definition: LUT.cc:38
static TRGCDCLUT * getLUT(const std::string &filename, int)
get LUT from dictionary, load new LUT if it doesn't exist
Definition: LUT.cc:83
static std::map< std::string, TRGCDCLUT > dictionary
list of LUTs, to avoid reading LUT data 2336 times
Definition: LUT.h:64
Abstract base class for different kinds of events.
STL namespace.