00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigManager.h"
00019
00020
00021
00022
00023 #include <iostream>
00024 #include <iomanip>
00025 #include <fstream>
00026 #include <sstream>
00027
00028
00029
00030
00031
00032 #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
00033
00034 using namespace std;
00035
00036
00037
00038
00039
00040 DTConfigManager::DTConfigManager(){
00041
00042 }
00043
00044
00045
00046
00047
00048 DTConfigManager::~DTConfigManager(){
00049
00050 my_sectcollmap.clear();
00051 my_trigunitmap.clear();
00052 my_tsphimap.clear();
00053 my_tsthetamap.clear();
00054 my_tracomap.clear();
00055 my_btimap.clear();
00056
00057 }
00058
00059
00060
00061
00062
00063 DTConfigBti* DTConfigManager::getDTConfigBti(DTBtiId btiid) const {
00064
00065 DTChamberId chambid = btiid.SLId().chamberId();
00066 BtiMap::const_iterator biter1 = my_btimap.find(chambid);
00067 if (biter1 == my_btimap.end()){
00068 std::cout << "DTConfigManager::getConfigBti : Chamber (" << chambid.wheel()
00069 << "," << chambid.sector()
00070 << "," << chambid.station()
00071 << ") not found, return 0" << std::endl;
00072 return 0;
00073 }
00074
00075 innerBtiMap::const_iterator biter2 = (*biter1).second.find(btiid);
00076 if (biter2 == (*biter1).second.end()){
00077 std::cout << "DTConfigManager::getConfigBti : BTI (" << btiid.wheel()
00078 << "," << btiid.sector()
00079 << "," << btiid.station()
00080 << "," << btiid.superlayer()
00081 << "," << btiid.bti()
00082 << ") not found, return 0" << std::endl;
00083 return 0;
00084 }
00085 return const_cast<DTConfigBti*>(&(*biter2).second);
00086
00087 }
00088
00089 const std::map<DTBtiId,DTConfigBti>& DTConfigManager::getDTConfigBtiMap(DTChamberId chambid) const {
00090
00091 BtiMap::const_iterator biter = my_btimap.find(chambid);
00092 if (biter == my_btimap.end()){
00093 std::cout << "DTConfigManager::getConfigBtiMap : Chamber (" << chambid.wheel()
00094 << "," << chambid.sector()
00095 << "," << chambid.station()
00096 << ") not found, return a reference to the end of the map" << std::endl;
00097 }
00098
00099 return (*biter).second;
00100
00101 }
00102
00103 DTConfigTraco* DTConfigManager::getDTConfigTraco(DTTracoId tracoid) const {
00104
00105 DTChamberId chambid = tracoid.ChamberId();
00106 TracoMap::const_iterator titer1 = my_tracomap.find(chambid);
00107 if (titer1 == my_tracomap.end()){
00108 std::cout << "DTConfigManager::getConfigTraco : Chamber (" << chambid.wheel()
00109 << "," << chambid.sector()
00110 << "," << chambid.station()
00111 << ") not found, return 0" << std::endl;
00112 return 0;
00113 }
00114
00115 innerTracoMap::const_iterator titer2 = (*titer1).second.find(tracoid);
00116 if (titer2 == (*titer1).second.end()){
00117 std::cout << "DTConfigManager::getConfigTraco : TRACO (" << tracoid.wheel()
00118 << "," << tracoid.sector()
00119 << "," << tracoid.station()
00120 << "," << tracoid.traco()
00121 << ") not found, return a reference to the end of the map" << std::endl;
00122 return 0;
00123 }
00124 return const_cast<DTConfigTraco*>(&(*titer2).second);
00125
00126 }
00127
00128 const std::map<DTTracoId,DTConfigTraco>& DTConfigManager::getDTConfigTracoMap(DTChamberId chambid) const {
00129
00130 TracoMap::const_iterator titer = my_tracomap.find(chambid);
00131 if (titer == my_tracomap.end()){
00132 std::cout << "DTConfigManager::getConfigTracoMap : Chamber (" << chambid.wheel()
00133 << "," << chambid.sector()
00134 << "," << chambid.station()
00135 << ") not found, return 0" << std::endl;
00136 }
00137
00138 return (*titer).second;
00139
00140 }
00141
00142 DTConfigTSTheta* DTConfigManager::getDTConfigTSTheta(DTChamberId chambid) const {
00143
00144 TSThetaMap::const_iterator thiter = my_tsthetamap.find(chambid);
00145 if (thiter == my_tsthetamap.end()){
00146 std::cout << "DTConfigManager::getConfigTSTheta : Chamber (" << chambid.wheel()
00147 << "," << chambid.sector()
00148 << "," << chambid.station()
00149 << ") not found, return 0" << std::endl;
00150 return 0;
00151 }
00152
00153 return const_cast<DTConfigTSTheta*>(&(*thiter).second);
00154
00155 }
00156
00157 DTConfigTSPhi* DTConfigManager::getDTConfigTSPhi(DTChamberId chambid) const {
00158
00159 TSPhiMap::const_iterator phiter = my_tsphimap.find(chambid);
00160 if (phiter == my_tsphimap.end()){
00161 std::cout << "DTConfigManager::getConfigTSPhi : Chamber (" << chambid.wheel()
00162 << "," << chambid.sector()
00163 << "," << chambid.station()
00164 << ") not found, return 0" << std::endl;
00165 return 0;
00166 }
00167
00168 return const_cast<DTConfigTSPhi*>(&(*phiter).second);
00169
00170 }
00171
00172 DTConfigTrigUnit* DTConfigManager::getDTConfigTrigUnit(DTChamberId chambid) const {
00173
00174 TrigUnitMap::const_iterator tuiter = my_trigunitmap.find(chambid);
00175 if (tuiter == my_trigunitmap.end()){
00176 std::cout << "DTConfigManager::getConfigTrigUnit : Chamber (" << chambid.wheel()
00177 << "," << chambid.sector()
00178 << "," << chambid.station()
00179 << ") not found, return 0" << std::endl;
00180 return 0;
00181 }
00182
00183 return const_cast<DTConfigTrigUnit*>(&(*tuiter).second);
00184
00185 }
00186
00187 DTConfigLUTs* DTConfigManager::getDTConfigLUTs(DTChamberId chambid) const {
00188
00189 LUTMap::const_iterator lutiter = my_lutmap.find(chambid);
00190 if (lutiter == my_lutmap.end()){
00191 std::cout << "DTConfigManager::getConfigLUTs : Chamber (" << chambid.wheel()
00192 << "," << chambid.sector()
00193 << "," << chambid.station()
00194 << ") not found, return 0" << std::endl;
00195 return 0;
00196 }
00197
00198 return const_cast<DTConfigLUTs*>(&(*lutiter).second);
00199
00200 }
00201
00202 DTConfigSectColl* DTConfigManager::getDTConfigSectColl(DTSectCollId scid) const {
00203
00204 SectCollMap::const_iterator sciter = my_sectcollmap.find(scid);
00205 if (sciter == my_sectcollmap.end()){
00206 std::cout << "DTConfigManager::getConfigSectColl : SectorCollector (" << scid.wheel()
00207 << "," << scid.sector()
00208 << ") not found, return 0" << std::endl;
00209 return 0;
00210 }
00211
00212 return const_cast<DTConfigSectColl*>(&(*sciter).second);
00213
00214 }
00215
00216 void DTConfigManager::setDTConfigBti(DTBtiId btiid,DTConfigBti conf){
00217
00218 DTChamberId chambid = btiid.SLId().chamberId();
00219 my_btimap[chambid][btiid] = conf;
00220
00221 }
00222
00223 void DTConfigManager::setDTConfigTraco(DTTracoId tracoid,DTConfigTraco conf){
00224
00225 DTChamberId chambid = tracoid.ChamberId();
00226 my_tracomap[chambid][tracoid] = conf;
00227
00228 }
00229
00230 int DTConfigManager::getBXOffset() const {
00231
00232 int ST = static_cast<int>(getDTConfigBti(DTBtiId(1,1,1,1,1))->ST());
00233 int coarse = getDTConfigSectColl(DTSectCollId(1,1))->CoarseSync(1);
00234 return (ST/2 + ST%2 + coarse);
00235
00236 }
00237
00238
00239 void DTConfigManager::dumpLUTParam(DTChamberId &chambid) const {
00240
00241
00242 string name = "Lut_from_param";
00243 name += ".txt";
00244
00245 ofstream fout;
00246 fout.open(name.c_str(),ofstream::app);
00247
00248
00249 int wh = chambid.wheel();
00250 int st = chambid.station();
00251 int se = chambid.sector();
00252
00253
00254
00255 fout << wh;
00256 fout << "\t" << st;
00257 fout << "\t" << se;
00258
00259
00260
00261 DTConfigLUTs* _confLUTs = getDTConfigLUTs(chambid);
00262 short int btic = getDTConfigTraco(DTTracoId(wh,st,se,1))->BTIC();
00263 float d = _confLUTs->D();
00264 float xcn = _confLUTs->Xcn();
00265
00266
00267
00268
00269 fout << "\tA8";
00270 short int Low_byte = (btic & 0x00FF);
00271 short int High_byte =( btic>>8 & 0x00FF);
00272 fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte;
00273
00274
00275 short int DSPmantissa = 0;
00276 short int DSPexp = 0;
00277
00278
00279 _confLUTs->IEEE32toDSP(d, DSPmantissa, DSPexp);
00280 Low_byte = (DSPmantissa & 0x00FF);
00281 High_byte =( DSPmantissa>>8 & 0x00FF);
00282 fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte;
00283 Low_byte = (DSPexp & 0x00FF);
00284 High_byte =( DSPexp>>8 & 0x00FF);
00285 fout << setw(2) << setfill('0') << High_byte << setw(2) << setfill('0') << Low_byte;
00286
00287
00288 DSPmantissa = 0;
00289 DSPexp = 0;
00290 _confLUTs->IEEE32toDSP(xcn, DSPmantissa, DSPexp);
00291 Low_byte = (DSPmantissa & 0x00FF);
00292 High_byte =( DSPmantissa>>8 & 0x00FF);
00293 fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte;
00294 Low_byte = (DSPexp & 0x00FF);
00295 High_byte =( DSPexp>>8 & 0x00FF);
00296 fout << setw(2) << setfill('0') << High_byte << setw(2) << setfill('0') << Low_byte;
00297
00298
00299 short int xcn_sign = _confLUTs->Wheel();
00300 Low_byte = (xcn_sign & 0x00FF);
00301 High_byte =( xcn_sign>>8 & 0x00FF);
00302 fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte << dec << "\n";
00303
00304 fout.close();
00305
00306 return;
00307
00308 }