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 DTConfigPedestals* DTConfigManager::getDTConfigPedestals() const{
00217
00218 return const_cast<DTConfigPedestals*>(&my_pedestals);
00219
00220 }
00221
00222 int DTConfigManager::getBXOffset() const {
00223
00224 int ST = static_cast<int>(getDTConfigBti(DTBtiId(1,1,1,1,1))->ST());
00225 return (ST/2 + ST%2);
00226
00227 }
00228
00229 void DTConfigManager::setDTConfigBti(DTBtiId btiid,DTConfigBti conf){
00230
00231 DTChamberId chambid = btiid.SLId().chamberId();
00232 my_btimap[chambid][btiid] = conf;
00233
00234 }
00235
00236 void DTConfigManager::setDTConfigTraco(DTTracoId tracoid,DTConfigTraco conf){
00237
00238 DTChamberId chambid = tracoid.ChamberId();
00239 my_tracomap[chambid][tracoid] = conf;
00240
00241 }
00242
00243 void DTConfigManager::dumpLUTParam(DTChamberId &chambid) const {
00244
00245
00246 string name = "Lut_from_param";
00247 name += ".txt";
00248
00249 ofstream fout;
00250 fout.open(name.c_str(),ofstream::app);
00251
00252
00253 int wh = chambid.wheel();
00254 int st = chambid.station();
00255 int se = chambid.sector();
00256
00257
00258
00259 fout << wh;
00260 fout << "\t" << st;
00261 fout << "\t" << se;
00262
00263
00264
00265 DTConfigLUTs* _confLUTs = getDTConfigLUTs(chambid);
00266 short int btic = getDTConfigTraco(DTTracoId(wh,st,se,1))->BTIC();
00267 float d = _confLUTs->D();
00268 float xcn = _confLUTs->Xcn();
00269
00270
00271
00272
00273 fout << "\tA8";
00274 short int Low_byte = (btic & 0x00FF);
00275 short int High_byte =( btic>>8 & 0x00FF);
00276 fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte;
00277
00278
00279 short int DSPmantissa = 0;
00280 short int DSPexp = 0;
00281
00282
00283 _confLUTs->IEEE32toDSP(d, DSPmantissa, DSPexp);
00284 Low_byte = (DSPmantissa & 0x00FF);
00285 High_byte =( DSPmantissa>>8 & 0x00FF);
00286 fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte;
00287 Low_byte = (DSPexp & 0x00FF);
00288 High_byte =( DSPexp>>8 & 0x00FF);
00289 fout << setw(2) << setfill('0') << High_byte << setw(2) << setfill('0') << Low_byte;
00290
00291
00292 DSPmantissa = 0;
00293 DSPexp = 0;
00294 _confLUTs->IEEE32toDSP(xcn, DSPmantissa, DSPexp);
00295 Low_byte = (DSPmantissa & 0x00FF);
00296 High_byte =( DSPmantissa>>8 & 0x00FF);
00297 fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte;
00298 Low_byte = (DSPexp & 0x00FF);
00299 High_byte =( DSPexp>>8 & 0x00FF);
00300 fout << setw(2) << setfill('0') << High_byte << setw(2) << setfill('0') << Low_byte;
00301
00302
00303 short int xcn_sign = _confLUTs->Wheel();
00304 Low_byte = (xcn_sign & 0x00FF);
00305 High_byte =( xcn_sign>>8 & 0x00FF);
00306 fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte << dec << "\n";
00307
00308 fout.close();
00309
00310 return;
00311
00312 }