Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:37:09

0001 // -*- C++ -*-
0002 //
0003 // Package:     DTTPGConfigProducers
0004 // Class:       DTConfigDBProducer
0005 //
0006 /**\class  DTConfigDBProducer  DTConfigDBProducer.h
0007  L1TriggerConfig/DTTPGConfigProducers/interface/DTConfigDBProducer.h
0008 
0009  Description: A Producer for the DT config, data retrieved from DB
0010 
0011  Implementation:
0012      <Notes on implementation>
0013 */
0014 //
0015 // Original Author:  Sara Vanini
0016 //         Created:  September 2008
0017 //
0018 //
0019 // system include files
0020 #include <memory>
0021 #include <vector>
0022 #include <iomanip>
0023 #include <iostream>
0024 
0025 // user include files
0026 #include "FWCore/Framework/interface/ESProducer.h"
0027 #include "FWCore/Framework/interface/ModuleFactory.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 #include "FWCore/Framework/interface/ESHandle.h"
0030 #include "FWCore/Framework/interface/ModuleFactory.h"
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032 #include "FWCore/Utilities/interface/Exception.h"
0033 
0034 #include "CondTools/DT/interface/DTKeyedConfigCache.h"
0035 
0036 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigManager.h"
0037 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigManagerRcd.h"
0038 
0039 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0040 #include "DataFormats/MuonDetId/interface/DTLayerId.h"
0041 #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
0042 
0043 #include "CondFormats/DTObjects/interface/DTCCBConfig.h"
0044 #include "CondFormats/DTObjects/interface/DTKeyedConfig.h"
0045 #include "CondFormats/DataRecord/interface/DTCCBConfigRcd.h"
0046 #include "CondFormats/DataRecord/interface/DTKeyedConfigListRcd.h"
0047 #include "CondFormats/DataRecord/interface/DTT0Rcd.h"
0048 #include "CondFormats/DataRecord/interface/DTTPGParametersRcd.h"
0049 
0050 #include "L1TriggerConfig/DTTPGConfigProducers/src/DTPosNegType.h"
0051 
0052 using std::cout;
0053 using std::endl;
0054 using std::unique_ptr;
0055 using std::vector;
0056 
0057 //
0058 // class declaration
0059 //
0060 
0061 class DTConfigDBProducer : public edm::ESProducer {
0062 public:
0063   //! Constructor
0064   DTConfigDBProducer(const edm::ParameterSet &);
0065 
0066   //! Destructor
0067   ~DTConfigDBProducer() override;
0068 
0069   //! ES produce method
0070   std::unique_ptr<DTConfigManager> produce(const DTConfigManagerRcd &);
0071 
0072 private:
0073   //! Read DTTPG pedestal configuration
0074   void readDBPedestalsConfig(const DTConfigManagerRcd &iRecord, DTConfigManager &dttpgConfig);
0075 
0076   //! Read CCB string configuration
0077   int readDTCCBConfig(const DTConfigManagerRcd &iRecord, DTConfigManager &dttpgConfig);
0078 
0079   //! SV for debugging purpose ONLY
0080   void configFromCfg(DTConfigManager &dttpgConfig);
0081 
0082   //! SV for debugging purpose ONLY
0083   DTConfigPedestals buildTrivialPedestals();
0084 
0085   //! 110629 SV function for CCB configuration check
0086   int checkDTCCBConfig(DTConfigManager &dttpgConfig);
0087 
0088   std::string mapEntryName(const DTChamberId &chambid) const;
0089 
0090   // ----------member data ---------------------------
0091   edm::ParameterSet m_ps;
0092 
0093   edm::ESGetToken<DTTPGParameters, DTTPGParametersRcd> m_dttpgParamsToken;
0094   edm::ESGetToken<DTT0, DTT0Rcd> m_t0iToken;
0095   edm::ESGetToken<DTCCBConfig, DTCCBConfigRcd> m_ccb_confToken;
0096   edm::ESGetToken<cond::persistency::KeyList, DTKeyedConfigListRcd> m_keyListToken;
0097 
0098   // debug flags
0099   bool m_debugDB;
0100   int m_debugBti;
0101   int m_debugTraco;
0102   bool m_debugTSP;
0103   bool m_debugTST;
0104   bool m_debugTU;
0105   bool m_debugSC;
0106   bool m_debugLUTs;
0107   bool m_debugPed;
0108 
0109   // general DB requests
0110   bool m_UseT0;
0111 
0112   bool cfgConfig;
0113 
0114   bool flagDBBti, flagDBTraco, flagDBTSS, flagDBTSM, flagDBLUTS;
0115 
0116   DTKeyedConfigCache cfgCache;
0117 };
0118 
0119 //
0120 // constructors and destructor
0121 //
0122 
0123 DTConfigDBProducer::DTConfigDBProducer(const edm::ParameterSet &p) {
0124   // tell the framework what record is being produced
0125   auto cc = setWhatProduced(this, &DTConfigDBProducer::produce);
0126 
0127   cfgConfig = p.getParameter<bool>("cfgConfig");
0128 
0129   // get and store parameter set and config manager pointer
0130   m_ps = p;
0131 
0132   // debug flags
0133   m_debugDB = p.getParameter<bool>("debugDB");
0134   m_debugBti = p.getParameter<int>("debugBti");
0135   m_debugTraco = p.getParameter<int>("debugTraco");
0136   m_debugTSP = p.getParameter<bool>("debugTSP");
0137   m_debugTST = p.getParameter<bool>("debugTST");
0138   m_debugTU = p.getParameter<bool>("debugTU");
0139   m_debugSC = p.getParameter<bool>("debugSC");
0140   m_debugLUTs = p.getParameter<bool>("debugLUTs");
0141   m_debugPed = p.getParameter<bool>("debugPed");
0142 
0143   m_UseT0 = p.getParameter<bool>("UseT0");  // CB check for a better way to do it
0144 
0145   if (not cfgConfig) {
0146     m_dttpgParamsToken = cc.consumes();
0147     m_ccb_confToken = cc.consumes();
0148     m_keyListToken = cc.consumes();
0149     if (m_UseT0) {
0150       m_t0iToken = cc.consumes();
0151     }
0152   }
0153 }
0154 
0155 DTConfigDBProducer::~DTConfigDBProducer() {}
0156 
0157 //
0158 // member functions
0159 //
0160 
0161 std::unique_ptr<DTConfigManager> DTConfigDBProducer::produce(const DTConfigManagerRcd &iRecord) {
0162   using namespace edm;
0163 
0164   std::unique_ptr<DTConfigManager> dtConfig = std::make_unique<DTConfigManager>();
0165   DTConfigManager &dttpgConfig = *(dtConfig.get());
0166 
0167   // DB specific requests
0168   bool tracoLutsFromDB = m_ps.getParameter<bool>("TracoLutsFromDB");
0169   bool useBtiAcceptParam = m_ps.getParameter<bool>("UseBtiAcceptParam");
0170 
0171   // set specific DB requests
0172   dttpgConfig.setLutFromDB(tracoLutsFromDB);
0173   dttpgConfig.setUseAcceptParam(useBtiAcceptParam);
0174 
0175   // set debug
0176   edm::ParameterSet conf_ps = m_ps.getParameter<edm::ParameterSet>("DTTPGParameters");
0177   bool dttpgdebug = conf_ps.getUntrackedParameter<bool>("Debug");
0178   dttpgConfig.setDTTPGDebug(dttpgdebug);
0179 
0180   int code;
0181   if (cfgConfig) {
0182     dttpgConfig.setLutFromDB(false);
0183     configFromCfg(dttpgConfig);
0184     code = 2;
0185   } else {
0186     code = readDTCCBConfig(iRecord, dttpgConfig);
0187     readDBPedestalsConfig(iRecord, dttpgConfig);
0188     // 110628 SV add config check
0189     if (code != -1 && checkDTCCBConfig(dttpgConfig) > 0)
0190       code = -1;
0191   }
0192   // cout << "DTConfigDBProducer::produce CODE " << code << endl;
0193   if (code == -1) {
0194     dttpgConfig.setCCBConfigValidity(false);
0195   } else if (code == 2) {
0196     LogVerbatim("DTTPG") << "DTConfigDBProducer::produce : Trivial : " << endl
0197                          << "configurations has been read from cfg" << endl;
0198   } else if (code == 0) {
0199     LogVerbatim("DTTPG") << "DTConfigDBProducer::produce : " << endl
0200                          << "Configurations successfully read from OMDS" << endl;
0201   } else {
0202     LogProblem("DTTPG") << "DTConfigDBProducer::produce : " << endl << "Wrong configuration return CODE" << endl;
0203   }
0204 
0205   return dtConfig;
0206 }
0207 
0208 void DTConfigDBProducer::readDBPedestalsConfig(const DTConfigManagerRcd &iRecord, DTConfigManager &dttpgConfig) {
0209   const auto &dttpgParams = iRecord.get(m_dttpgParamsToken);
0210 
0211   DTConfigPedestals pedestals;
0212   pedestals.setDebug(m_debugPed);
0213 
0214   if (m_UseT0) {
0215     pedestals.setUseT0(true);
0216     pedestals.setES(&dttpgParams, &iRecord.get(m_t0iToken));
0217     // cout << "checkDTCCBConfig CODE is " << checkDTCCBConfig() << endl;
0218 
0219   } else {
0220     pedestals.setUseT0(false);
0221     pedestals.setES(&dttpgParams);
0222   }
0223 
0224   dttpgConfig.setDTConfigPedestals(pedestals);
0225 }
0226 
0227 int DTConfigDBProducer::checkDTCCBConfig(DTConfigManager &dttpgConfig) {
0228   // 110627 SV test if configuration from CCB has correct number of chips,
0229   // return error code:
0230   // check_cfg_code = 1 : NO correct BTI number
0231   // check_cfg_code = 2 : NO correct TRACO number
0232   // check_cfg_code = 3 : NO correct valid TSS number
0233   // check_cfg_code = 4 : NO correct valid TSM number
0234 
0235   int check_cfg_code = 0;
0236 
0237   // do not take chambers from MuonGeometryRecord to avoid geometry dependency
0238   for (int iwh = -2; iwh <= 2; iwh++) {
0239     for (int ise = 1; ise <= 12; ise++) {
0240       for (int ist = 1; ist <= 4; ist++) {
0241         check_cfg_code = 0;
0242         DTChamberId chid(iwh, ist, ise);
0243 
0244         // retrive number of configurated chip
0245         int nbti = dttpgConfig.getDTConfigBtiMap(chid).size();
0246         int ntraco = dttpgConfig.getDTConfigTracoMap(chid).size();
0247         int ntss = dttpgConfig.getDTConfigTSPhi(chid)->nValidTSS();
0248         int ntsm = dttpgConfig.getDTConfigTSPhi(chid)->nValidTSM();
0249 
0250         // check BTIs
0251         if ((ist == 1 && nbti != 168) || (ist == 2 && nbti != 192) || (ist == 3 && nbti != 224) ||
0252             (ist == 4 &&
0253              (ise == 1 || ise == 2 || ise == 3 || ise == 5 || ise == 6 || ise == 7 || ise == 8 || ise == 12) &&
0254              nbti != 192) ||
0255             (ist == 4 && (ise == 9 || ise == 11) && nbti != 96) || (ist == 4 && ise == 10 && nbti != 128) ||
0256             (ist == 4 && ise == 4 && nbti != 160)) {
0257           check_cfg_code = 1;
0258           return check_cfg_code;
0259         }
0260 
0261         // check TRACOs
0262         if ((ist == 1 && ntraco != 13) || (ist == 2 && ntraco != 16) || (ist == 3 && ntraco != 20) ||
0263             (ist == 4 &&
0264              (ise == 1 || ise == 2 || ise == 3 || ise == 5 || ise == 6 || ise == 7 || ise == 8 || ise == 12) &&
0265              ntraco != 24) ||
0266             (ist == 4 && (ise == 9 || ise == 11) && ntraco != 12) || (ist == 4 && ise == 10 && ntraco != 16) ||
0267             (ist == 4 && ise == 4 && ntraco != 20)) {
0268           check_cfg_code = 2;
0269           return check_cfg_code;
0270         }
0271 
0272         // check TSS
0273         if ((ist == 1 && ntss != 4) || (ist == 2 && ntss != 4) || (ist == 3 && ntss != 5) ||
0274             (ist == 4 &&
0275              (ise == 1 || ise == 2 || ise == 3 || ise == 5 || ise == 6 || ise == 7 || ise == 8 || ise == 12) &&
0276              ntss != 6) ||
0277             (ist == 4 && (ise == 9 || ise == 11) && ntss != 3) || (ist == 4 && ise == 10 && ntss != 4) ||
0278             (ist == 4 && ise == 4 && ntss != 5)) {
0279           check_cfg_code = 3;
0280           return check_cfg_code;
0281         }
0282 
0283         // check TSM
0284         if (ntsm != 1) {
0285           check_cfg_code = 4;
0286           return check_cfg_code;
0287         }
0288 
0289         // if(check_cfg_code){
0290         // cout << "nbti " << nbti << " ntraco " << ntraco << " ntss " << ntss
0291         // << " ntsm " << ntsm << endl; cout << "Check: ch " << ist << " sec "
0292         // << ise << " wh " << iwh << " == >check_cfg_code " << check_cfg_code
0293         // << endl;
0294         //}
0295       }  // end st loop
0296     }  // end sec loop
0297 
0298     // SV MB4 has two more chambers
0299     for (int ise = 13; ise <= 14; ise++) {
0300       DTChamberId chid(iwh, 4, ise);
0301 
0302       int nbti = dttpgConfig.getDTConfigBtiMap(chid).size();
0303       int ntraco = dttpgConfig.getDTConfigTracoMap(chid).size();
0304       int ntss = dttpgConfig.getDTConfigTSPhi(chid)->nValidTSS();
0305       int ntsm = dttpgConfig.getDTConfigTSPhi(chid)->nValidTSM();
0306 
0307       if ((ise == 13 && nbti != 160) || (ise == 14 && nbti != 128)) {
0308         check_cfg_code = 1;
0309         return check_cfg_code;
0310       }
0311       if ((ise == 13 && ntraco != 20) || (ise == 14 && ntraco != 16)) {
0312         check_cfg_code = 2;
0313         return check_cfg_code;
0314       }
0315       if ((ise == 13 && ntss != 5) || (ise == 14 && ntss != 4)) {
0316         check_cfg_code = 3;
0317         return check_cfg_code;
0318       }
0319       if (ntsm != 1) {
0320         check_cfg_code = 4;
0321         return check_cfg_code;
0322       }
0323       // if(check_cfg_code){
0324       // cout << "nbti " << nbti << " ntraco " << ntraco << " ntss " << ntss <<
0325       // " ntsm " << ntsm << endl; cout << "Check: ch " << 4 << " sec " << ise
0326       // << " wh " << iwh << " == >check_cfg_code " << check_cfg_code << endl;
0327       //}
0328     }  // end sec 13 14
0329 
0330   }  // end wh loop
0331 
0332   // cout << "CheckDTCCB: config OK! check_cfg_code = " << check_cfg_code <<
0333   // endl;
0334   return check_cfg_code;
0335 }
0336 
0337 int DTConfigDBProducer::readDTCCBConfig(const DTConfigManagerRcd &iRecord, DTConfigManager &dttpgConfig) {
0338   using namespace edm::eventsetup;
0339 
0340   // initialize CCB validity flag
0341   dttpgConfig.setCCBConfigValidity(true);
0342 
0343   // get DTCCBConfigRcd from DTConfigManagerRcd (they are dependent records)
0344   const auto &ccb_conf = iRecord.get(m_ccb_confToken);
0345   int ndata = std::distance(ccb_conf.begin(), ccb_conf.end());
0346 
0347   const DTKeyedConfigListRcd &keyRecord = iRecord.getRecord<DTKeyedConfigListRcd>();
0348 
0349   if (m_debugDB) {
0350     cout << ccb_conf.version() << endl;
0351     cout << ndata << " data in the container" << endl;
0352   }
0353 
0354   edm::ValidityInterval iov(iRecord.getRecord<DTCCBConfigRcd>().validityInterval());
0355   unsigned int currValidityStart = iov.first().eventID().run();
0356   unsigned int currValidityEnd = iov.last().eventID().run();
0357 
0358   if (m_debugDB)
0359     cout << "valid since run " << currValidityStart << " to run " << currValidityEnd << endl;
0360 
0361   // if there are no data in the container, configuration from cfg files...
0362   if (ndata == 0) {
0363     return -1;
0364   }
0365 
0366   // get DTTPGMap for retrieving bti number and traco number
0367   edm::ParameterSet conf_map = m_ps.getUntrackedParameter<edm::ParameterSet>("DTTPGMap");
0368 
0369   // loop over chambers
0370   DTCCBConfig::ccb_config_map configKeys(ccb_conf.configKeyMap());
0371   DTCCBConfig::ccb_config_iterator iter = configKeys.begin();
0372   DTCCBConfig::ccb_config_iterator iend = configKeys.end();
0373 
0374   // 110628 SV check that number of CCB is equal to total number of chambers
0375   if (ccb_conf.configKeyMap().size() != 250)  // check the number of chambers!!!
0376     return -1;
0377 
0378   auto const &keyList = keyRecord.get(m_keyListToken);
0379 
0380   // read data from CCBConfig
0381   while (iter != iend) {
0382     // 110628 SV moved here from constructor, to check config consistency for
0383     // EVERY chamber initialize flags to check if data are present in OMDS
0384     flagDBBti = false;
0385     flagDBTraco = false;
0386     flagDBTSS = false;
0387     flagDBTSM = false;
0388     flagDBLUTS = false;
0389 
0390     // get chamber id
0391     const DTCCBId &ccbId = iter->first;
0392     if (m_debugDB)
0393       cout << " Filling configuration for chamber : wh " << ccbId.wheelId << " st " << ccbId.stationId << " se "
0394            << ccbId.sectorId << " -> " << endl;
0395 
0396     // get chamber type and id from ccbId
0397     int mbtype = DTPosNegType::getCT(ccbId.wheelId, ccbId.sectorId, ccbId.stationId);
0398     int posneg = DTPosNegType::getPN(ccbId.wheelId, ccbId.sectorId, ccbId.stationId);
0399     if (m_debugDB)
0400       cout << "Chamber type : " << mbtype << " posneg : " << posneg << endl;
0401     DTChamberId chambid(ccbId.wheelId, ccbId.stationId, ccbId.sectorId);
0402 
0403     // get brick identifiers list
0404     const std::vector<int> &ccbConf = iter->second;
0405     std::vector<int>::const_iterator cfgIter = ccbConf.begin();
0406     std::vector<int>::const_iterator cfgIend = ccbConf.end();
0407 
0408     // TSS-TSM buffers
0409     unsigned short int tss_buffer[7][31];
0410     unsigned short int tsm_buffer[9];
0411     int ntss = 0;
0412 
0413     // loop over configuration bricks
0414     while (cfgIter != cfgIend) {
0415       // get brick identifier
0416       int id = *cfgIter++;
0417       if (m_debugDB)
0418         cout << " BRICK " << id << endl;
0419 
0420       // create strings list
0421       std::vector<std::string> list;
0422 
0423       cfgCache.getData(keyList, id, list);
0424 
0425       // loop over strings
0426       std::vector<std::string>::const_iterator s_iter = list.begin();
0427       std::vector<std::string>::const_iterator s_iend = list.end();
0428       while (s_iter != s_iend) {
0429         if (m_debugDB)
0430           cout << "        ----> " << *s_iter << endl;
0431 
0432         // copy string in unsigned int buffer
0433         std::string str = *s_iter++;
0434         unsigned short int buffer[100];  // 2 bytes
0435         int c = 0;
0436         const char *cstr = str.c_str();
0437         const char *ptr = cstr + 2;
0438         const char *end = cstr + str.length();
0439         while (ptr < end) {
0440           char c1 = *ptr++;
0441           int i1 = 0;
0442           if ((c1 >= '0') && (c1 <= '9'))
0443             i1 = c1 - '0';
0444           if ((c1 >= 'a') && (c1 <= 'f'))
0445             i1 = 10 + c1 - 'a';
0446           if ((c1 >= 'A') && (c1 <= 'F'))
0447             i1 = 10 + c1 - 'A';
0448           char c2 = *ptr++;
0449           int i2 = 0;
0450           if ((c2 >= '0') && (c2 <= '9'))
0451             i2 = c2 - '0';
0452           if ((c2 >= 'a') && (c2 <= 'f'))
0453             i2 = 10 + c2 - 'a';
0454           if ((c2 >= 'A') && (c2 <= 'F'))
0455             i2 = 10 + c2 - 'A';
0456           buffer[c] = (i1 * 16) + i2;
0457           c++;
0458         }  // end loop over string
0459 
0460         // BTI configuration string
0461         if (buffer[2] == 0x54) {
0462           if (m_debugDB)
0463             cout << "BTI STRING found in DB" << endl;
0464 
0465           // BTI configuration read for BTI
0466           flagDBBti = true;
0467 
0468           // compute sl and bti number from board and chip
0469           int brd = buffer[3];   // Board Nr.
0470           int chip = buffer[4];  // Chip Nr.
0471 
0472           if (brd > 7) {
0473             cout << "Not existing board ... " << brd << endl;
0474             return -1;  // Non-existing board
0475           }
0476           if (chip > 31) {
0477             cout << "Not existing chip... " << chip << endl;
0478             return -1;  // Non existing chip
0479           }
0480 
0481           // Is it Phi or Theta board?
0482           bool ThetaSL, PhiSL;
0483           PhiSL = false;
0484           ThetaSL = false;
0485           switch (mbtype) {
0486             case 1:  // mb1
0487               if (brd == 6 || brd == 7) {
0488                 ThetaSL = true;
0489                 brd -= 6;
0490               } else if ((brd < 3 && chip < 32) || (brd == 3 && chip < 8))
0491                 PhiSL = true;
0492               break;
0493             case 2:  // mb2
0494               if (brd == 6 || brd == 7) {
0495                 ThetaSL = true;
0496                 brd -= 6;
0497               } else if (brd < 4 && chip < 32)
0498                 PhiSL = true;
0499               break;
0500             case 3:  // mb3
0501               if (brd == 6 || brd == 7) {
0502                 ThetaSL = true;
0503                 brd -= 6;
0504               } else if (brd < 5 && chip < 32)
0505                 PhiSL = true;
0506               break;
0507             case 4:  // mb4-s, mb4_8
0508               if (brd < 6 && chip < 32)
0509                 PhiSL = true;
0510               break;
0511             case 5:  // mb4-9
0512               if (brd < 3 && chip < 32)
0513                 PhiSL = true;
0514               break;
0515             case 6:  // mb4-4
0516               if (brd < 5 && chip < 32)
0517                 PhiSL = true;
0518               break;
0519             case 7:  // mb4-10
0520               if (brd < 4 && chip < 32)
0521                 PhiSL = true;
0522               break;
0523           }
0524           if (!PhiSL && !ThetaSL) {
0525             cout << "MB type " << mbtype << endl;
0526             cout << "Board " << brd << " chip " << chip << endl;
0527             cout << "Not phi SL nor Theta SL" << endl;
0528             return -1;  // Not PhiSL nor ThetaSL
0529           }
0530 
0531           // compute SL number and bti number
0532           int isl = 0;
0533           int ibti = 0;
0534           if (PhiSL) {
0535             if ((chip % 8) < 4)
0536               isl = 1;  // Phi1
0537             else
0538               isl = 3;  // Phi2
0539             ibti = brd * 16 + (int)(chip / 8) * 4 + (chip % 4);
0540           } else if (ThetaSL) {
0541             isl = 2;  // Theta
0542             if ((chip % 8) < 4)
0543               ibti = brd * 32 + chip - 4 * (int)(chip / 8);
0544             else
0545               ibti = brd * 32 + chip + 12 - 4 * (int)(chip / 8);
0546           }
0547 
0548           // BTI config constructor from strings
0549           DTConfigBti bticonf(m_debugBti, buffer);
0550 
0551           dttpgConfig.setDTConfigBti(DTBtiId(chambid, isl, ibti + 1), bticonf);
0552 
0553           if (m_debugDB)
0554             cout << "Filling BTI config for chamber : wh " << chambid.wheel() << ", st " << chambid.station() << ", se "
0555                  << chambid.sector() << "... sl " << isl << ", bti " << ibti + 1 << endl;
0556         }
0557 
0558         // TRACO configuration string
0559         if (buffer[2] == 0x15) {
0560           if (m_debugDB)
0561             cout << "TRACO STRING found in DB" << endl;
0562           // TRACO configuration read from OMDS
0563           flagDBTraco = true;
0564 
0565           // TRACO config constructor from strings
0566           int traco_brd = buffer[3];   // Board Nr.;
0567           int traco_chip = buffer[4];  // Chip Nr.;
0568           int itraco = traco_brd * 4 + traco_chip + 1;
0569           DTConfigTraco tracoconf(m_debugTraco, buffer);
0570           dttpgConfig.setDTConfigTraco(DTTracoId(chambid, itraco), tracoconf);
0571 
0572           if (m_debugDB)
0573             cout << "Filling TRACO config for chamber : wh " << chambid.wheel() << ", st " << chambid.station()
0574                  << ", se " << chambid.sector() << ", board " << traco_brd << ", chip " << traco_chip << ", traco "
0575                  << itraco << endl;
0576         }
0577 
0578         // TSS configuration string
0579         if (buffer[2] == 0x16) {
0580           if (m_debugDB)
0581             cout << "TSS STRING found in DB" << endl;
0582           // TSS configuration read from OMDS
0583           flagDBTSS = true;
0584 
0585           unsigned short int itss = buffer[3];
0586           for (int i = 0; i < 31; i++)
0587             tss_buffer[itss][i] = buffer[i];
0588           ntss++;
0589         }
0590 
0591         // TSM configuration string
0592         if (buffer[2] == 0x17) {
0593           if (m_debugDB)
0594             cout << "TSM STRING found in DB" << endl;
0595 
0596           // TSM configuration read from OMDS
0597           flagDBTSM = true;
0598 
0599           for (int i = 0; i < 9; i++)
0600             tsm_buffer[i] = buffer[i];
0601         }
0602 
0603         // LUT configuration string
0604         if (buffer[2] == 0xA8) {
0605           if (m_debugDB)
0606             cout << "LUT STRING found in DB" << endl;
0607 
0608           // LUT parameters read from OMDS
0609           flagDBLUTS = true;
0610           DTConfigLUTs lutconf(m_debugLUTs, buffer);
0611           // lutconf.setDebug(m_debugLUTs);
0612           dttpgConfig.setDTConfigLUTs(chambid, lutconf);
0613         }
0614 
0615       }  // end string iteration
0616     }  // end brick iteration
0617 
0618     // TSS + TSM configurations are set in DTConfigTSPhi constructor
0619     if (flagDBTSM && flagDBTSS) {
0620       DTConfigTSPhi tsphiconf(m_debugTSP, tss_buffer, ntss, tsm_buffer);
0621       dttpgConfig.setDTConfigTSPhi(chambid, tsphiconf);
0622     }
0623 
0624     // get configuration for TSTheta, SC and TU from .cfg
0625     edm::ParameterSet conf_ps = m_ps.getParameter<edm::ParameterSet>("DTTPGParameters");
0626     edm::ParameterSet tups = conf_ps.getParameter<edm::ParameterSet>("TUParameters");
0627 
0628     // TSTheta configuration from .cfg
0629     DTConfigTSTheta tsthetaconf(tups.getParameter<edm::ParameterSet>("TSThetaParameters"));
0630     tsthetaconf.setDebug(m_debugTST);
0631     dttpgConfig.setDTConfigTSTheta(chambid, tsthetaconf);
0632 
0633     // SC configuration from .cfg
0634     DTConfigSectColl sectcollconf(conf_ps.getParameter<edm::ParameterSet>("SectCollParameters"));
0635     sectcollconf.setDebug(m_debugSC);
0636     dttpgConfig.setDTConfigSectColl(DTSectCollId(chambid.wheel(), chambid.sector()), sectcollconf);
0637 
0638     // TU configuration from .cfg
0639     DTConfigTrigUnit trigunitconf(tups);
0640     trigunitconf.setDebug(m_debugTU);
0641     dttpgConfig.setDTConfigTrigUnit(chambid, trigunitconf);
0642 
0643     ++iter;
0644 
0645     // 110628 SV moved inside CCB loop to check for every chamber
0646     // moved to exception handling no attempt to configure from cfg is DB is
0647     // missing SV comment exception handling and activate flag in
0648     // DTConfigManager
0649     if (!flagDBBti || !flagDBTraco || !flagDBTSS || !flagDBTSM) {
0650       return -1;
0651     }
0652     if (!flagDBLUTS && dttpgConfig.lutFromDB() == true) {
0653       return -1;
0654     }
0655   }  // end loop over CCB
0656 
0657   return 0;
0658 }
0659 
0660 std::string DTConfigDBProducer::mapEntryName(const DTChamberId &chambid) const {
0661   int iwh = chambid.wheel();
0662   std::ostringstream os;
0663   os << "wh";
0664   if (iwh < 0) {
0665     os << 'm' << -iwh;
0666   } else {
0667     os << iwh;
0668   }
0669   os << "st" << chambid.station() << "se" << chambid.sector();
0670   return os.str();
0671 }
0672 
0673 void DTConfigDBProducer::configFromCfg(DTConfigManager &dttpgConfig) {
0674   // ... but still set CCB validity flag to let the emulator run
0675   dttpgConfig.setCCBConfigValidity(true);
0676 
0677   // create config classes&C.
0678   edm::ParameterSet conf_ps = m_ps.getParameter<edm::ParameterSet>("DTTPGParameters");
0679   edm::ParameterSet conf_map = m_ps.getUntrackedParameter<edm::ParameterSet>("DTTPGMap");
0680   bool dttpgdebug = conf_ps.getUntrackedParameter<bool>("Debug");
0681   DTConfigSectColl sectcollconf(conf_ps.getParameter<edm::ParameterSet>("SectCollParameters"));
0682   edm::ParameterSet tups = conf_ps.getParameter<edm::ParameterSet>("TUParameters");
0683   DTConfigBti bticonf(tups.getParameter<edm::ParameterSet>("BtiParameters"));
0684   DTConfigTraco tracoconf(tups.getParameter<edm::ParameterSet>("TracoParameters"));
0685   DTConfigTSTheta tsthetaconf(tups.getParameter<edm::ParameterSet>("TSThetaParameters"));
0686   DTConfigTSPhi tsphiconf(tups.getParameter<edm::ParameterSet>("TSPhiParameters"));
0687   DTConfigTrigUnit trigunitconf(tups);
0688   DTConfigLUTs lutconf(tups.getParameter<edm::ParameterSet>("LutParameters"));
0689 
0690   for (int iwh = -2; iwh <= 2; ++iwh) {
0691     for (int ist = 1; ist <= 4; ++ist) {
0692       for (int ise = 1; ise <= 12; ++ise) {
0693         DTChamberId chambid(iwh, ist, ise);
0694         vector<int> nmap = conf_map.getUntrackedParameter<vector<int>>(mapEntryName(chambid).c_str());
0695 
0696         if (dttpgdebug) {
0697           cout << " Filling configuration for chamber : wh " << chambid.wheel() << ", st " << chambid.station()
0698                << ", se " << chambid.sector() << endl;
0699         }
0700 
0701         // fill the bti map
0702         if (!flagDBBti) {
0703           for (int isl = 1; isl <= 3; isl++) {
0704             int ncell = nmap[isl - 1];
0705             //    cout << ncell <<" , ";
0706             for (int ibti = 0; ibti < ncell; ibti++) {
0707               dttpgConfig.setDTConfigBti(DTBtiId(chambid, isl, ibti + 1), bticonf);
0708               if (dttpgdebug)
0709                 cout << "Filling BTI config for chamber : wh " << chambid.wheel() << ", st " << chambid.station()
0710                      << ", se " << chambid.sector() << "... sl " << isl << ", bti " << ibti + 1 << endl;
0711             }
0712           }
0713         }
0714 
0715         // fill the traco map
0716         if (!flagDBTraco) {
0717           int ntraco = nmap[3];
0718           // cout << ntraco << " }" << endl;
0719           for (int itraco = 0; itraco < ntraco; itraco++) {
0720             dttpgConfig.setDTConfigTraco(DTTracoId(chambid, itraco + 1), tracoconf);
0721             if (dttpgdebug)
0722               cout << "Filling TRACO config for chamber : wh " << chambid.wheel() << ", st " << chambid.station()
0723                    << ", se " << chambid.sector() << ", traco " << itraco + 1 << endl;
0724           }
0725         }
0726 
0727         // fill TS & TrigUnit
0728         if (!flagDBTSS || !flagDBTSM) {
0729           dttpgConfig.setDTConfigTSTheta(chambid, tsthetaconf);
0730           dttpgConfig.setDTConfigTSPhi(chambid, tsphiconf);
0731           dttpgConfig.setDTConfigTrigUnit(chambid, trigunitconf);
0732         }
0733       }
0734     }
0735   }
0736 
0737   for (int iwh = -2; iwh <= 2; ++iwh) {
0738     for (int ise = 13; ise <= 14; ++ise) {
0739       int ist = 4;
0740       DTChamberId chambid(iwh, ist, ise);
0741       vector<int> nmap = conf_map.getUntrackedParameter<vector<int>>(mapEntryName(chambid).c_str());
0742 
0743       if (dttpgdebug) {
0744         cout << " Filling configuration for chamber : wh " << chambid.wheel() << ", st " << chambid.station() << ", se "
0745              << chambid.sector() << endl;
0746       }
0747 
0748       // fill the bti map
0749       if (!flagDBBti) {
0750         for (int isl = 1; isl <= 3; isl++) {
0751           int ncell = nmap[isl - 1];
0752           //    cout << ncell <<" , ";
0753           for (int ibti = 0; ibti < ncell; ibti++) {
0754             dttpgConfig.setDTConfigBti(DTBtiId(chambid, isl, ibti + 1), bticonf);
0755             if (dttpgdebug)
0756               cout << "Filling BTI config for chamber : wh " << chambid.wheel() << ", st " << chambid.station()
0757                    << ", se " << chambid.sector() << "... sl " << isl << ", bti " << ibti + 1 << endl;
0758           }
0759         }
0760       }
0761 
0762       // fill the traco map
0763       if (!flagDBTraco) {
0764         int ntraco = nmap[3];
0765         //       cout << ntraco << " }" << endl;
0766         for (int itraco = 0; itraco < ntraco; itraco++) {
0767           dttpgConfig.setDTConfigTraco(DTTracoId(chambid, itraco + 1), tracoconf);
0768           if (dttpgdebug)
0769             cout << "Filling TRACO config for chamber : wh " << chambid.wheel() << ", st " << chambid.station()
0770                  << ", se " << chambid.sector() << ", traco " << itraco + 1 << endl;
0771         }
0772       }
0773 
0774       // fill TS & TrigUnit
0775       if (!flagDBTSS || !flagDBTSM) {
0776         dttpgConfig.setDTConfigTSTheta(chambid, tsthetaconf);
0777         dttpgConfig.setDTConfigTSPhi(chambid, tsphiconf);
0778         dttpgConfig.setDTConfigTrigUnit(chambid, trigunitconf);
0779       }
0780     }
0781   }
0782 
0783   // loop on Sector Collectors
0784   for (int wh = -2; wh <= 2; wh++)
0785     for (int se = 1; se <= 12; se++)
0786       dttpgConfig.setDTConfigSectColl(DTSectCollId(wh, se), sectcollconf);
0787 
0788   // fake collection of pedestals
0789   dttpgConfig.setDTConfigPedestals(buildTrivialPedestals());
0790 
0791   return;
0792 }
0793 
0794 DTConfigPedestals DTConfigDBProducer::buildTrivialPedestals() {
0795   DTTPGParameters *m_tpgParams = new DTTPGParameters();
0796 
0797   int counts = m_ps.getParameter<int>("bxOffset");
0798   float fine = m_ps.getParameter<double>("finePhase");
0799 
0800   if (m_debugPed)
0801     cout << "DTConfigTrivialProducer::buildPedestals()" << endl;
0802 
0803   // DTTPGParameters tpgParams;
0804   for (int iwh = -2; iwh <= 2; ++iwh) {
0805     for (int ist = 1; ist <= 4; ++ist) {
0806       for (int ise = 1; ise <= 14; ++ise) {
0807         if (ise > 12 && ist != 4)
0808           continue;
0809 
0810         DTChamberId chId(iwh, ist, ise);
0811         m_tpgParams->set(chId, counts, fine, DTTimeUnits::ns);
0812       }
0813     }
0814   }
0815 
0816   DTConfigPedestals tpgPedestals;
0817   tpgPedestals.setUseT0(false);
0818   tpgPedestals.setES(m_tpgParams);
0819 
0820   return tpgPedestals;
0821 }
0822 
0823 DEFINE_FWK_EVENTSETUP_MODULE(DTConfigDBProducer);