Belle II Software  release-05-01-25
LUT.cc
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : LUT.cc
5 // Section : TRG CDC
6 // Owner : KyungTae KIM (K.U.)
7 // Email : ktkim@hep.korea.ac.kr
8 //-----------------------------------------------------------------------------
9 // Description : A class to use LUTs for TRGCDC
10 //-----------------------------------------------------------------------------
11 // $Log$
12 //-----------------------------------------------------------------------------
13 
14 #define TRG_SHORT_NAMES
15 #define TRGCDC_SHORT_NAMES
16 
17 #include <fstream>
18 #include "trg/cdc/LUT.h"
19 #include "trg/cdc/Track.h"
20 #include "trg/cdc/Link.h"
21 #include <cstdlib>
22 #include <math.h>
23 
24 using namespace std;
25 
26 namespace Belle2 {
32  map<string, TRGCDCLUT> TRGCDCLUT::dictionary;
33 
34  std::string TRGCDCLUT::version(void) const
35  {
36  return string("TRGCDCLUT 1.00");
37  }
38 
39  TRGCDCLUT::TRGCDCLUT() :
40  m_data{}, m_bitsize(), m_name() // 2019/07/31 by ytlai
41  {
42  }
43 
45  {
46  }
47 
48  int TRGCDCLUT::getValue(unsigned id) const
49  {
50  unsigned range = pow(2, m_bitsize);
51  if (id >= range) {
52  return 0;
53  } else {
54  return m_data[id];
55  }
56  }
57 
58  void TRGCDCLUT::setDataFile(const string& filename, int nInputBit)
59  {
60  m_bitsize = nInputBit;
61  m_name = filename;
62 
63  ifstream openFile;
64  string tmpstr;
65  int tmpint;
66  int i = 0;
67  int range = pow(2, nInputBit);
68  openFile.open(filename.c_str());
69  m_data.resize(range);
70  while (getline(openFile, tmpstr) && i < range) {
71  if (!(tmpstr.size() == 0)) {
72  if (tmpstr[0] >= '0' && tmpstr[0] <= '9') {
73  tmpint = atoi(tmpstr.c_str());
74  m_data[i] = tmpint;
75  i++;
76  } else {
77  continue;
78  }
79  }
80  }
81  openFile.close();
82  }
83 
84  TRGCDCLUT* TRGCDCLUT::getLUT(const std::string& filename, int nInputBit)
85  {
86  if (TRGCDCLUT::dictionary.find(filename) == TRGCDCLUT::dictionary.end()) {
87  TRGCDCLUT::dictionary[filename] = TRGCDCLUT();
88  TRGCDCLUT::dictionary[filename].setDataFile(filename, nInputBit);
89  }
90  return &(TRGCDCLUT::dictionary[filename]);
91  }
93 }
94 
Belle2::TRGCDCLUT::m_data
std::vector< int > m_data
LUT data.
Definition: LUT.h:65
Belle2::TRGCDCLUT::~TRGCDCLUT
virtual ~TRGCDCLUT()
Destructor.
Definition: LUT.cc:44
Belle2::TRGCDCLUT
A class to use LUTs for TRGCDC.
Definition: LUT.h:32
Belle2::TRGCDCLUT::getValue
int getValue(unsigned) const
get LUT Values
Definition: LUT.cc:48
Belle2::TRGCDCLUT::m_name
std::string m_name
LUT name.
Definition: LUT.h:71
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TRGCDCLUT::dictionary
static std::map< std::string, TRGCDCLUT > dictionary
list of LUTs, to avoid reading LUT data 2336 times
Definition: LUT.h:57
Belle2::TRGCDCLUT::TRGCDCLUT
TRGCDCLUT()
Contructor.
Definition: LUT.cc:39
Belle2::TRGCDCLUT::m_bitsize
int m_bitsize
Input bit size.
Definition: LUT.h:68
Belle2::TRGCDCLUT::setDataFile
void setDataFile(const std::string &filename, int)
set LUT data.
Definition: LUT.cc:58
Belle2::TRGCDCLUT::getLUT
static TRGCDCLUT * getLUT(const std::string &filename, int)
get LUT from dictionary, load new LUT if it doesn't exist
Definition: LUT.cc:84