Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:04

0001 //----------------------------------------------------------------------
0002 //
0003 //   Class: DTConfigManager
0004 //
0005 //   Description: DT Configuration manager includes config classes for every single chip
0006 //
0007 //
0008 //   Author List:
0009 //   C.Battilana
0010 //
0011 //   april 07 : SV DTConfigTrigUnit added
0012 //   april 07 : CB Removed DTGeometry dependecies
0013 //-----------------------------------------------------------------------
0014 
0015 //-----------------------
0016 // This Class's Header --
0017 //-----------------------
0018 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigManager.h"
0019 
0020 //---------------
0021 // C++ Headers --
0022 //---------------
0023 #include <iostream>
0024 #include <iomanip>
0025 #include <fstream>
0026 #include <sstream>
0027 
0028 //-------------------------------
0029 // Collaborating Class Headers --
0030 //-------------------------------
0031 #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
0032 
0033 using namespace std;
0034 
0035 //----------------
0036 // Constructors --
0037 //----------------
0038 
0039 DTConfigManager::DTConfigManager() {}
0040 
0041 //--------------
0042 // Destructor --
0043 //--------------
0044 
0045 DTConfigManager::~DTConfigManager() {
0046   my_sectcollmap.clear();
0047   my_trigunitmap.clear();
0048   my_tsphimap.clear();
0049   my_tsthetamap.clear();
0050   my_tracomap.clear();
0051   my_btimap.clear();
0052 }
0053 
0054 //--------------
0055 // Operations --
0056 //--------------
0057 
0058 const DTConfigBti* DTConfigManager::getDTConfigBti(DTBtiId btiid) const {
0059   DTChamberId chambid = btiid.SLId().chamberId();
0060   BtiMap::const_iterator biter1 = my_btimap.find(chambid);
0061   if (biter1 == my_btimap.end()) {
0062     std::cout << "DTConfigManager::getConfigBti : Chamber (" << chambid.wheel() << "," << chambid.sector() << ","
0063               << chambid.station() << ") not found, return 0" << std::endl;
0064     return nullptr;
0065   }
0066 
0067   innerBtiMap::const_iterator biter2 = (*biter1).second.find(btiid);
0068   if (biter2 == (*biter1).second.end()) {
0069     std::cout << "DTConfigManager::getConfigBti : BTI (" << btiid.wheel() << "," << btiid.sector() << ","
0070               << btiid.station() << "," << btiid.superlayer() << "," << btiid.bti() << ") not found, return 0"
0071               << std::endl;
0072     return nullptr;
0073   }
0074   return &(*biter2).second;
0075 }
0076 
0077 const std::map<DTBtiId, DTConfigBti>& DTConfigManager::getDTConfigBtiMap(DTChamberId chambid) const {
0078   BtiMap::const_iterator biter = my_btimap.find(chambid);
0079   if (biter == my_btimap.end()) {
0080     std::cout << "DTConfigManager::getConfigBtiMap : Chamber (" << chambid.wheel() << "," << chambid.sector() << ","
0081               << chambid.station() << ") not found, return a reference to the end of the map" << std::endl;
0082   }
0083 
0084   return (*biter).second;
0085 }
0086 
0087 const DTConfigTraco* DTConfigManager::getDTConfigTraco(DTTracoId tracoid) const {
0088   DTChamberId chambid = tracoid.ChamberId();
0089   TracoMap::const_iterator titer1 = my_tracomap.find(chambid);
0090   if (titer1 == my_tracomap.end()) {
0091     std::cout << "DTConfigManager::getConfigTraco : Chamber (" << chambid.wheel() << "," << chambid.sector() << ","
0092               << chambid.station() << ") not found, return 0" << std::endl;
0093     return nullptr;
0094   }
0095 
0096   innerTracoMap::const_iterator titer2 = (*titer1).second.find(tracoid);
0097   if (titer2 == (*titer1).second.end()) {
0098     std::cout << "DTConfigManager::getConfigTraco : TRACO (" << tracoid.wheel() << "," << tracoid.sector() << ","
0099               << tracoid.station() << "," << tracoid.traco() << ") not found, return a reference to the end of the map"
0100               << std::endl;
0101     return nullptr;
0102   }
0103   return &(*titer2).second;
0104 }
0105 
0106 const std::map<DTTracoId, DTConfigTraco>& DTConfigManager::getDTConfigTracoMap(DTChamberId chambid) const {
0107   TracoMap::const_iterator titer = my_tracomap.find(chambid);
0108   if (titer == my_tracomap.end()) {
0109     std::cout << "DTConfigManager::getConfigTracoMap : Chamber (" << chambid.wheel() << "," << chambid.sector() << ","
0110               << chambid.station() << ") not found, return 0" << std::endl;
0111   }
0112 
0113   return (*titer).second;
0114 }
0115 
0116 const DTConfigTSTheta* DTConfigManager::getDTConfigTSTheta(DTChamberId chambid) const {
0117   TSThetaMap::const_iterator thiter = my_tsthetamap.find(chambid);
0118   if (thiter == my_tsthetamap.end()) {
0119     std::cout << "DTConfigManager::getConfigTSTheta : Chamber (" << chambid.wheel() << "," << chambid.sector() << ","
0120               << chambid.station() << ") not found, return 0" << std::endl;
0121     return nullptr;
0122   }
0123 
0124   return &(*thiter).second;
0125 }
0126 
0127 const DTConfigTSPhi* DTConfigManager::getDTConfigTSPhi(DTChamberId chambid) const {
0128   TSPhiMap::const_iterator phiter = my_tsphimap.find(chambid);
0129   if (phiter == my_tsphimap.end()) {
0130     std::cout << "DTConfigManager::getConfigTSPhi : Chamber (" << chambid.wheel() << "," << chambid.sector() << ","
0131               << chambid.station() << ") not found, return 0" << std::endl;
0132     return nullptr;
0133   }
0134 
0135   return &(*phiter).second;
0136 }
0137 
0138 const DTConfigTrigUnit* DTConfigManager::getDTConfigTrigUnit(DTChamberId chambid) const {
0139   TrigUnitMap::const_iterator tuiter = my_trigunitmap.find(chambid);
0140   if (tuiter == my_trigunitmap.end()) {
0141     std::cout << "DTConfigManager::getConfigTrigUnit : Chamber (" << chambid.wheel() << "," << chambid.sector() << ","
0142               << chambid.station() << ") not found, return 0" << std::endl;
0143     return nullptr;
0144   }
0145 
0146   return &(*tuiter).second;
0147 }
0148 
0149 const DTConfigLUTs* DTConfigManager::getDTConfigLUTs(DTChamberId chambid) const {
0150   LUTMap::const_iterator lutiter = my_lutmap.find(chambid);
0151   if (lutiter == my_lutmap.end()) {
0152     std::cout << "DTConfigManager::getConfigLUTs : Chamber (" << chambid.wheel() << "," << chambid.sector() << ","
0153               << chambid.station() << ") not found, return 0" << std::endl;
0154     return nullptr;
0155   }
0156 
0157   return &(*lutiter).second;
0158 }
0159 
0160 const DTConfigSectColl* DTConfigManager::getDTConfigSectColl(DTSectCollId scid) const {
0161   SectCollMap::const_iterator sciter = my_sectcollmap.find(scid);
0162   if (sciter == my_sectcollmap.end()) {
0163     std::cout << "DTConfigManager::getConfigSectColl : SectorCollector (" << scid.wheel() << "," << scid.sector()
0164               << ") not found, return 0" << std::endl;
0165     return nullptr;
0166   }
0167 
0168   return &(*sciter).second;
0169 }
0170 
0171 const DTConfigPedestals* DTConfigManager::getDTConfigPedestals() const { return &my_pedestals; }
0172 
0173 int DTConfigManager::getBXOffset() const {
0174   int ST = static_cast<int>(getDTConfigBti(DTBtiId(1, 1, 1, 1, 1))->ST());
0175   return (ST / 2 + ST % 2);
0176 }
0177 
0178 void DTConfigManager::setDTConfigBti(DTBtiId btiid, DTConfigBti conf) {
0179   DTChamberId chambid = btiid.SLId().chamberId();
0180   my_btimap[chambid][btiid] = conf;
0181 }
0182 
0183 void DTConfigManager::setDTConfigTraco(DTTracoId tracoid, DTConfigTraco conf) {
0184   DTChamberId chambid = tracoid.ChamberId();
0185   my_tracomap[chambid][tracoid] = conf;
0186 }
0187 
0188 void DTConfigManager::dumpLUTParam(DTChamberId& chambid) const {
0189   // open txt file
0190   string name = "Lut_from_param";
0191   name += ".txt";
0192 
0193   ofstream fout;
0194   fout.open(name.c_str(), ofstream::app);
0195 
0196   // get wheel, station, sector from chamber
0197   int wh = chambid.wheel();
0198   int st = chambid.station();
0199   int se = chambid.sector();
0200 
0201   //cout << "Dumping lut command for wh " << wh << " st " << st << " se " << se << endl;
0202 
0203   fout << wh;
0204   fout << "\t" << st;
0205   fout << "\t" << se;
0206 
0207   // get parameters from configuration
0208   // get DTConfigLUTs for this chamber
0209   const DTConfigLUTs* _confLUTs = getDTConfigLUTs(chambid);
0210   short int btic = getDTConfigTraco(DTTracoId(wh, st, se, 1))->BTIC();
0211   float d = _confLUTs->D();
0212   float xcn = _confLUTs->Xcn();
0213   //fout << "\td\t" << d << "\txcn\t" << xcn << "\t";
0214   //fout << "btic\t" << btic << "\t";
0215 
0216   // *** dump TRACO LUT command
0217   fout << "\tA8";
0218   short int Low_byte = (btic & 0x00FF);  // output in hex bytes format with zero padding
0219   short int High_byte = (btic >> 8 & 0x00FF);
0220   fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte;
0221 
0222   // convert parameters from IEE32 float to DSP float format
0223   short int DSPmantissa = 0;
0224   short int DSPexp = 0;
0225 
0226   // d parameter conversion and dump
0227   _confLUTs->IEEE32toDSP(d, DSPmantissa, DSPexp);
0228   Low_byte = (DSPmantissa & 0x00FF);  // output in hex bytes format with zero padding
0229   High_byte = (DSPmantissa >> 8 & 0x00FF);
0230   fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte;
0231   Low_byte = (DSPexp & 0x00FF);
0232   High_byte = (DSPexp >> 8 & 0x00FF);
0233   fout << setw(2) << setfill('0') << High_byte << setw(2) << setfill('0') << Low_byte;
0234 
0235   // xnc parameter conversion and dump
0236   DSPmantissa = 0;
0237   DSPexp = 0;
0238   _confLUTs->IEEE32toDSP(xcn, DSPmantissa, DSPexp);
0239   Low_byte = (DSPmantissa & 0x00FF);  // output in hex bytes format with zero padding
0240   High_byte = (DSPmantissa >> 8 & 0x00FF);
0241   fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte;
0242   Low_byte = (DSPexp & 0x00FF);
0243   High_byte = (DSPexp >> 8 & 0x00FF);
0244   fout << setw(2) << setfill('0') << High_byte << setw(2) << setfill('0') << Low_byte;
0245 
0246   // sign bits
0247   short int xcn_sign = _confLUTs->Wheel();
0248   Low_byte = (xcn_sign & 0x00FF);  // output in hex bytes format with zero padding
0249   High_byte = (xcn_sign >> 8 & 0x00FF);
0250   fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte << dec << "\n";
0251 
0252   fout.close();
0253 
0254   return;
0255 }