CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1MuDTExtLut.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuDTExtLut
4 //
5 // Description: Look-up tables for extrapolation
6 //
7 //
8 // $Date: 2009/05/13 06:36:48 $
9 // $Revision: 1.6 $
10 //
11 // Author :
12 // N. Neumeister CERN EP
13 // J. Troconiz UAM Madrid
14 //
15 //--------------------------------------------------
16 
17 //-----------------------
18 // This Class's Header --
19 //-----------------------
20 
22 
23 //---------------
24 // C++ Headers --
25 //---------------
26 
27 #include <iostream>
28 #include <ostream>
29 #include <iomanip>
30 #include <string>
31 #include <cstdlib>
32 
33 //-------------------------------
34 // Collaborating Class Headers --
35 //-------------------------------
36 
41 
42 using namespace std;
43 
44 // --------------------------------
45 // class L1MuDTExtLut
46 //---------------------------------
47 
48 //----------------
49 // Constructors --
50 //----------------
51 
53 
54  ext_lut.reserve(MAX_EXT);
55  setPrecision();
56  // if ( load() != 0 ) {
57  // cout << "Can not open files to load extrapolation look-up tables for DTTrackFinder!" << endl;
58  // }
59 
60  // if ( L1MuDTTFConfig::Debug(6) ) print();
61 
62 }
63 
64 
65 //--------------
66 // Destructor --
67 //--------------
68 
70 
71  typedef vector<LUT>::iterator LI;
72  for ( LI iter = ext_lut.begin(); iter != ext_lut.end(); iter++ ) {
73  (*iter).low.clear();
74  (*iter).high.clear();
75  }
76 
77  ext_lut.clear();
78 
79 }
80 
81 
82 //--------------
83 // Operations --
84 //--------------
85 
86 //
87 // reset extrapolation look-up tables
88 //
90 
91  ext_lut.clear();
92 
93 }
94 
95 
96 //
97 // load extrapolation look-up tables
98 //
100 
101  // get directory name
102  string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
103  string ext_dir = "L1TriggerData/DTTrackFinder/Ext/";
104  string ext_str = "";
105 
106  // precision : in the look-up tables the following precision is used :
107  // phi ...12 bits (low, high), phib ...10 bits (address)
108  // now convert phi and phib to the required precision
109 
110  int sh_phi = 12 - nbit_phi;
111  int sh_phib = 10 - nbit_phib;
112 
113  // loop over all extrapolations
114  for ( int ext = 0; ext < MAX_EXT; ext++ ) {
115  switch (ext) {
116  case EX12 : ext_str = "ext12"; break;
117  case EX13 : ext_str = "ext13"; break;
118  case EX14 : ext_str = "ext14"; break;
119  case EX21 : ext_str = "ext21"; break;
120  case EX23 : ext_str = "ext23"; break;
121  case EX24 : ext_str = "ext24"; break;
122  case EX34 : ext_str = "ext34"; break;
123  case EX15 : ext_str = "ext15"; break;
124  case EX16 : ext_str = "ext16"; break;
125  case EX25 : ext_str = "ext25"; break;
126  case EX26 : ext_str = "ext26"; break;
127  case EX56 : ext_str = "ext56"; break;
128  }
129 
130  // assemble file name
131  edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + ext_dir + ext_str + ".lut"));
132  string ext_file = lut_f.fullPath();
133 
134  // open file
135  L1TriggerLutFile file(ext_file);
136  if ( file.open() != 0 ) return -1;
137  // if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
138  // << file.getName() << endl;
139 
140  LUT tmplut;
141 
142  int number = -1;
143  int adr_old = -512 >> sh_phib;
144  int sum_low = 0;
145  int sum_high = 0;
146 
147  // read values and shift to correct precision
148  while ( file.good() ) {
149 
150  int adr = ( file.readInteger() ) >> sh_phib; // address (phib)
151  int low = ( file.readInteger() ); // low value (phi)
152  int high = ( file.readInteger() ); // high value (phi)
153 
154  number++;
155 
156  if ( adr != adr_old ) {
157 
158  tmplut.low[adr_old] = sum_low >> sh_phi;
159  tmplut.high[adr_old] = sum_high >> sh_phi;
160 
161  adr_old = adr;
162  number = 0;
163  sum_low = 0;
164  sum_high = 0;
165 
166  }
167 
168  if (number == 0) sum_low = low;
169  if (number == 0) sum_high = high;
170 
171  if ( !file.good() ) file.close();
172  }
173 
174  file.close();
175  ext_lut.push_back(tmplut);
176  }
177  return 0;
178 
179 }
180 
181 
182 //
183 // print extrapolation look-up tables
184 //
185 void L1MuDTExtLut::print() const {
186 
187  cout << endl;
188  cout << "L1 barrel Track Finder Extrapolation look-up tables :" << endl;
189  cout << "=====================================================" << endl;
190  cout << endl;
191  cout << "Precision : " << endl;
192  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
193  cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
194 
195  // loop over all extrapolations
196  for ( int ext = 0; ext < MAX_EXT; ext++ ) {
197 
198  cout << endl;
199  cout << "Extrapolation : " << static_cast<Extrapolation>(ext) << endl;
200  cout << "====================" << endl;
201  cout << endl;
202 
203  cout << " address";
204  for ( int i = 0; i < nbit_phib; i++ ) cout << ' ';
205  cout << " low-value";
206  for ( int i = 0; i < nbit_phi; i++ ) cout << ' ';
207  cout << " high-value " << endl;
208  for ( int i = 0; i < 2*nbit_phi + nbit_phib; i++ ) cout << '-';
209  cout << "---------------------------------" << endl;
210 
211  LUT::LUTmap::const_iterator iter = ext_lut[ext].low.begin();
212  LUT::LUTmap::const_iterator iter1;
213  while ( iter != ext_lut[ext].low.end() ) {
214  int address = (*iter).first;
215  int low = (*iter).second;
216  iter1 = ext_lut[ext].high.find(address);
217  int high = (*iter1).second;
218 
219  DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
220  DTTFBitArray<12> b_low(static_cast<unsigned>(abs(low)));
221  DTTFBitArray<12> b_high(static_cast<unsigned>(abs(high)));
222 
223  if ( address < 0 ) b_address.twoComplement();
224  if ( low < 0 ) b_low.twoComplement();
225  if ( high < 0 ) b_high.twoComplement();
226 
227  cout.setf(ios::right,ios::adjustfield);
228  cout << " " << setbase(10) << setw(5) << address << " (";
229  for ( int i = nbit_phib-1; i >= 0; i-- ) cout << b_address[i];
230  cout << ") " << setw(5) << low << " (";
231  for ( int i = nbit_phi-1; i >= 0; i-- ) cout << b_low[i];
232  cout << ") " << setw(5) << high << " (";
233  for ( int i = nbit_phi-1; i >= 0; i-- ) cout << b_high[i];
234  cout << ") " << endl;
235 
236  iter++;
237  }
238 
239  }
240 
241  cout << endl;
242 
243 }
244 
245 
246 //
247 // get low_value for a given address
248 //
249 int L1MuDTExtLut::getLow(int ext_ind, int address) const {
250 
251  LUT::LUTmap::const_iterator iter = ext_lut[ext_ind].low.find(address);
252  if ( iter != ext_lut[ext_ind].low.end() ) {
253  return (*iter).second;
254  }
255  else {
256  cerr << "ExtLut::getLow : can not find address " << address << endl;
257  return 99999;
258  }
259 }
260 
261 
262 //
263 // get high_value for a given address
264 //
265 int L1MuDTExtLut::getHigh(int ext_ind, int address) const {
266 
267  LUT::LUTmap::const_iterator iter = ext_lut[ext_ind].high.find(address);
268  if ( iter != ext_lut[ext_ind].high.end() ) {
269  return (*iter).second;
270  }
271  else {
272  cerr << "ExtLut::getHigh : can not find address " << address << endl;
273  return 99999;
274  }
275 }
276 
277 
278 //
279 // set precision for Look-up tables
280 //
282 
283  nbit_phi = 12;
284  nbit_phib = 10;
285 
286 }
int i
Definition: DBlmapReader.cc:9
DTTFBitArray< N > twoComplement() const
Definition: DTTFBitArray.h:500
bool good()
return status of file stream
helper class for look-up tables
Definition: L1MuDTExtLut.h:47
L1MuDTExtLut()
constructor
Definition: L1MuDTExtLut.cc:52
int load()
load extrapolation look-up tables
Definition: L1MuDTExtLut.cc:99
void close()
close file
int getLow(int ext_ind, int address) const
get low_value for a given address
const int MAX_EXT
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int getHigh(int ext_ind, int address) const
get high_value for a given address
void print() const
print extrapolation look-up tables
Extrapolation
void reset()
reset extrapolation look-up tables
Definition: L1MuDTExtLut.cc:89
void setPrecision()
set precision for look-up tables
int readInteger()
read one integer from file
virtual ~L1MuDTExtLut()
destructor
Definition: L1MuDTExtLut.cc:69
tuple cout
Definition: gather_cfg.py:121
std::string fullPath() const
Definition: FileInPath.cc:165
int open()
open file