CMS 3D CMS Logo

L1MuBMTQualPatternLut.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuDTQualPatternLut
4 //
5 // Description: Look-up tables for eta matching unit (EMU)
6 // stores lists of qualified patterns and
7 // coarse eta values
8 //
9 //
10 // $Date: 2007/03/30 07:48:02 $
11 // $Revision: 1.1 $
12 //
13 // Author :
14 // N. Neumeister CERN EP
15 // J. Troconiz UAM Madrid
16 //
17 //--------------------------------------------------
18 
19 //-----------------------
20 // This Class's Header --
21 //-----------------------
22 
24 
25 //---------------
26 // C++ Headers --
27 //---------------
28 
29 #include <iostream>
30 #include <iomanip>
31 #include <string>
32 
33 //-------------------------------
34 // Collaborating Class Headers --
35 //-------------------------------
36 
40 
41 using namespace std;
42 
43 // --------------------------------
44 // class L1MuDTQualPatternLut
45 //---------------------------------
46 
47 //----------------
48 // Constructors --
49 //----------------
50 
52 
53  // if ( load() != 0 ) {
54  // cout << "Can not open files to load eta matching look-up tables for DTTrackFinder!" << endl;
55  // }
56 
57  // if ( L1MuDTTFConfig::Debug(6) ) print();
58 
59 }
60 
61 
62 //--------------
63 // Destructor --
64 //--------------
65 
67 
68 }
69 
70 
71 //--------------
72 // Operations --
73 //--------------
74 
75 //
76 // reset look-up tables
77 //
79 
80  m_lut.clear();
81 
82 }
83 
84 
85 //
86 // load look-up tables for EMU
87 //
89 
90  // get directory name
91  string defaultPath ="L1Trigger/"; //"L1TriggerConfig/DTTrackFinder/parameters/";
92  string eau_dir = "L1TMuon/data/bmtf_luts/LUTs_Ass/";//"L1TriggerData/DTTrackFinder/Eau/";
93  string emu_str = "";
94 
95  // loop over all sector processors
96  for ( int sp = 0; sp < 6; sp++ ) {
97 
98  emu_str="QualPatternList_SP"+std::to_string(sp+1);
99 
100  // assemble file name
101  edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + eau_dir + emu_str + ".lut"));
102  string emu_file = lut_f.fullPath();
103 
104  // open file
105  L1TriggerLutFile file(emu_file);
106  if ( file.open() != 0 ) return -1;
107  // if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
108  // << file.getName() << endl;
109 
110  // ignore comment lines
111  int skip2=getIgnoredLines(file);
112  file.ignoreLines(skip2);
113 
114  // read file
115  while ( file.good() ) {
116 
117  int id = file.readInteger();
118  if ( !file.good() ) break;
119  int eta = file.readInteger();
120  if ( !file.good() ) break;
121  int num = file.readInteger();
122  if ( !file.good() ) break;
123 
124  vector<short> patternlist;
125  patternlist.reserve(num);
126 
127  for ( int i = 0; i < num; i++ ) {
128  int pattern = file.readInteger();
129  patternlist.push_back(pattern);
130  }
131 
132  m_lut[make_pair(sp+1,id)] = make_pair(eta,patternlist);
133 
134  if ( !file.good() ) { file.close(); break; }
135 
136  }
137 
138  file.close();
139  }
140 
141  return 0;
142 
143 }
144 
145 
146 //
147 // print look-up tables for EMU
148 //
150 
151  cout << endl;
152  cout << "L1 barrel Track Finder Qual Pattern look-up tables :" << endl;
153  cout << "====================================================" << endl;
154  cout << endl;
155 
156  int spold = 0;
157 
158  LUT::const_iterator iter = m_lut.begin();
159  while ( iter != m_lut.end() ) {
160  int sp = (*iter).first.first;
161  if ( sp != spold ) {
162  cout << endl;
163  cout << "Qualified Patterns for Sector Processor " << setw(1) << sp << " :" << endl;
164  cout << "===========================================" << endl;
165  cout << endl;
166  spold = sp;
167  }
168  cout << setw(2) << (*iter).first.second << " "
169  << setw(3) << (*iter).second.first << " "
170  << setw(5) << (*iter).second.second.size() << " : ";
171  const vector<short>& patternlist = (*iter).second.second;
172  vector<short>::const_iterator it;
173  for ( it = patternlist.begin(); it != patternlist.end(); it++ ) {
174  cout << setw(5) << (*it) << " ";
175  }
176  cout << endl;
177  iter++;
178  }
179 
180  cout << endl;
181 
182 }
183 
184 
185 //
186 // get coarse eta value for a given sector processor [1-6] and address [1-22]
187 //
188 int L1MuBMTQualPatternLut::getCoarseEta(int sp, int adr) const {
189 
190  LUT::const_iterator it = m_lut.find(make_pair(sp,adr));
191  if ( it == m_lut.end() ) {
192  edm::LogError ("L1MuBMTQualPatternLut") << "Error: L1MuBMTQualPatternLut: no coarse eta found for address " << adr << endl;
193  return 0;
194  }
195  return (*it).second.first;
196 
197 }
198 
199 
200 //
201 // get list of qualified patterns for a given sector processor [1-6] and address [1-22]
202 //
203 const vector<short>& L1MuBMTQualPatternLut::getQualifiedPatterns(int sp, int adr) const {
204 
205  LUT::const_iterator it = m_lut.find(make_pair(sp,adr));
206  if ( it == m_lut.end() ) {
207  edm::LogError ("L1MuBMTQualPatternLut") << "Error: L1MuBMTQualPatternLut: no pattern list found for address " << adr << endl;
208  }
209  return (*it).second.second;
210 
211 }
212 
214  if ( file.open() != 0 ) return -1;
215  int skip=0;
216  while ( file.good() ) {
217 
218  string str=file.readString();
219  if (str.find("#")==0) skip+=1;
220  //cout<<"here "<<str<<" found "<<str.find("#")<<endl;
221  if ( !file.good() ) { file.close(); break; }
222  }
223  file.close();
224 
225  // skip aditional lines of comments between "---".
226  skip += 2;
227 
228  return skip;
229 }
const std::vector< short > & getQualifiedPatterns(int sp, int adr) const
get list of qualified patterns for a given sector processor [1-6] and address [1-22] ...
int getCoarseEta(int sp, int adr) const
get coarse eta value for a given sector processor [1-6] and address [1-22]
int load()
load look-up tables
bool good()
return status of file stream
virtual ~L1MuBMTQualPatternLut()
destructor
void print() const
print look-up tables
void close()
close file
void ignoreLines(int n)
read and ignore n lines from file
int getIgnoredLines(L1TriggerLutFile file) const
void reset()
reset look-up tables
std::string readString()
read one string from file
int readInteger()
read one integer from file
std::string fullPath() const
Definition: FileInPath.cc:197
#define str(s)
int open()
open file