00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "CondFormats/L1TObjects/interface/L1MuDTExtLut.h"
00022
00023
00024
00025
00026
00027 #include <iostream>
00028 #include <ostream>
00029 #include <iomanip>
00030 #include <string>
00031
00032
00033
00034
00035
00036 #include "FWCore/ParameterSet/interface/FileInPath.h"
00037
00038 #include "CondFormats/L1TObjects/interface/L1MuDTExtParam.h"
00039 #include "CondFormats/L1TObjects/interface/L1TriggerLutFile.h"
00040
00041 using namespace std;
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 L1MuDTExtLut::L1MuDTExtLut() {
00052
00053 ext_lut.reserve(MAX_EXT);
00054 setPrecision();
00055
00056
00057
00058
00059
00060
00061 }
00062
00063
00064
00065
00066
00067
00068 L1MuDTExtLut::~L1MuDTExtLut() {
00069
00070 typedef vector<LUT>::iterator LI;
00071 for ( LI iter = ext_lut.begin(); iter != ext_lut.end(); iter++ ) {
00072 (*iter).low.clear();
00073 (*iter).high.clear();
00074 }
00075
00076 ext_lut.clear();
00077
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 void L1MuDTExtLut::reset() {
00089
00090 ext_lut.clear();
00091
00092 }
00093
00094
00095
00096
00097
00098 int L1MuDTExtLut::load() {
00099
00100
00101 string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
00102 string ext_dir = "L1TriggerData/DTTrackFinder/Ext/";
00103 string ext_str = "";
00104
00105
00106
00107
00108
00109 int sh_phi = 12 - nbit_phi;
00110 int sh_phib = 10 - nbit_phib;
00111
00112
00113 for ( int ext = 0; ext < MAX_EXT; ext++ ) {
00114 switch (ext) {
00115 case EX12 : ext_str = "ext12"; break;
00116 case EX13 : ext_str = "ext13"; break;
00117 case EX14 : ext_str = "ext14"; break;
00118 case EX21 : ext_str = "ext21"; break;
00119 case EX23 : ext_str = "ext23"; break;
00120 case EX24 : ext_str = "ext24"; break;
00121 case EX34 : ext_str = "ext34"; break;
00122 case EX15 : ext_str = "ext15"; break;
00123 case EX16 : ext_str = "ext16"; break;
00124 case EX25 : ext_str = "ext25"; break;
00125 case EX26 : ext_str = "ext26"; break;
00126 case EX56 : ext_str = "ext56"; break;
00127 }
00128
00129
00130 edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + ext_dir + ext_str + ".lut"));
00131 string ext_file = lut_f.fullPath();
00132
00133
00134 L1TriggerLutFile file(ext_file);
00135 if ( file.open() != 0 ) return -1;
00136
00137
00138
00139 LUT tmplut;
00140
00141 int number = -1;
00142 int adr_old = -512 >> sh_phib;
00143 int sum_low = 0;
00144 int sum_high = 0;
00145
00146
00147 while ( file.good() ) {
00148
00149 int adr = ( file.readInteger() ) >> sh_phib;
00150 int low = ( file.readInteger() );
00151 int high = ( file.readInteger() );
00152
00153 number++;
00154
00155 if ( adr != adr_old ) {
00156
00157 tmplut.low[adr_old] = sum_low >> sh_phi;
00158 tmplut.high[adr_old] = sum_high >> sh_phi;
00159
00160 adr_old = adr;
00161 number = 0;
00162 sum_low = 0;
00163 sum_high = 0;
00164
00165 }
00166
00167 if (number == 0) sum_low = low;
00168 if (number == 0) sum_high = high;
00169
00170 if ( !file.good() ) file.close();
00171 }
00172
00173 file.close();
00174 ext_lut.push_back(tmplut);
00175 }
00176 return 0;
00177
00178 }
00179
00180
00181
00182
00183
00184 void L1MuDTExtLut::print() const {
00185
00186 cout << endl;
00187 cout << "L1 barrel Track Finder Extrapolation look-up tables :" << endl;
00188 cout << "=====================================================" << endl;
00189 cout << endl;
00190 cout << "Precision : " << endl;
00191 cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
00192 cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
00193
00194
00195 for ( int ext = 0; ext < MAX_EXT; ext++ ) {
00196
00197 cout << endl;
00198 cout << "Extrapolation : " << static_cast<Extrapolation>(ext) << endl;
00199 cout << "====================" << endl;
00200 cout << endl;
00201
00202 cout << " address";
00203 for ( int i = 0; i < nbit_phib; i++ ) cout << ' ';
00204 cout << " low-value";
00205 for ( int i = 0; i < nbit_phi; i++ ) cout << ' ';
00206 cout << " high-value " << endl;
00207 for ( int i = 0; i < 2*nbit_phi + nbit_phib; i++ ) cout << '-';
00208 cout << "---------------------------------" << endl;
00209
00210 LUT::LUTmap::const_iterator iter = ext_lut[ext].low.begin();
00211 LUT::LUTmap::const_iterator iter1;
00212 while ( iter != ext_lut[ext].low.end() ) {
00213 int address = (*iter).first;
00214 int low = (*iter).second;
00215 iter1 = ext_lut[ext].high.find(address);
00216 int high = (*iter1).second;
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 iter++;
00236 }
00237
00238 }
00239
00240 cout << endl;
00241
00242 }
00243
00244
00245
00246
00247
00248 int L1MuDTExtLut::getLow(int ext_ind, int address) const {
00249
00250 LUT::LUTmap::const_iterator iter = ext_lut[ext_ind].low.find(address);
00251 if ( iter != ext_lut[ext_ind].low.end() ) {
00252 return (*iter).second;
00253 }
00254 else {
00255 cerr << "ExtLut::getLow : can not find address " << address << endl;
00256 return 99999;
00257 }
00258 }
00259
00260
00261
00262
00263
00264 int L1MuDTExtLut::getHigh(int ext_ind, int address) const {
00265
00266 LUT::LUTmap::const_iterator iter = ext_lut[ext_ind].high.find(address);
00267 if ( iter != ext_lut[ext_ind].high.end() ) {
00268 return (*iter).second;
00269 }
00270 else {
00271 cerr << "ExtLut::getHigh : can not find address " << address << endl;
00272 return 99999;
00273 }
00274 }
00275
00276
00277
00278
00279
00280 void L1MuDTExtLut::setPrecision() {
00281
00282 nbit_phi = 12;
00283 nbit_phib = 10;
00284
00285 }