Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:18

0001 /**
0002  * \class L1GtBoardMapsTrivialProducer
0003  *
0004  *
0005  * Description: ESProducer for various mappings of the L1 GT boards.
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *
0010  * \author: Vasile Mihai Ghete - HEPHY Vienna
0011  *
0012  *
0013  */
0014 
0015 // this class header
0016 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtBoardMapsTrivialProducer.h"
0017 
0018 // system include files
0019 #include <memory>
0020 
0021 #include <string>
0022 
0023 // user include files
0024 //   base class
0025 #include "FWCore/Utilities/interface/EDMException.h"
0026 
0027 #include "FWCore/Framework/interface/ModuleFactory.h"
0028 #include "FWCore/Framework/interface/ESHandle.h"
0029 
0030 #include "CondFormats/L1TObjects/interface/L1GtFwd.h"
0031 
0032 // forward declarations
0033 
0034 //
0035 
0036 std::vector<L1GtObject> chInputObjects(const std::vector<std::string>& chInputStrings) {
0037   std::vector<L1GtObject> chInputObjectsV;
0038   chInputObjectsV.reserve(chInputStrings.size());
0039 
0040   L1GtObject obj;
0041 
0042   for (std::vector<std::string>::const_iterator itObj = chInputStrings.begin(); itObj != chInputStrings.end();
0043        ++itObj) {
0044     if ((*itObj) == "Mu") {
0045       obj = Mu;
0046     } else if ((*itObj) == "NoIsoEG") {
0047       obj = NoIsoEG;
0048     } else if ((*itObj) == "IsoEG") {
0049       obj = IsoEG;
0050     } else if ((*itObj) == "CenJet") {
0051       obj = CenJet;
0052     } else if ((*itObj) == "ForJet") {
0053       obj = ForJet;
0054     } else if ((*itObj) == "TauJet") {
0055       obj = TauJet;
0056     } else if ((*itObj) == "ETM") {
0057       obj = ETM;
0058     } else if ((*itObj) == "ETT") {
0059       obj = ETT;
0060     } else if ((*itObj) == "HTT") {
0061       obj = HTT;
0062     } else if ((*itObj) == "HTM") {
0063       obj = HTM;
0064     } else if ((*itObj) == "JetCounts") {
0065       obj = JetCounts;
0066     } else if ((*itObj) == "HfBitCounts") {
0067       obj = HfBitCounts;
0068     } else if ((*itObj) == "HfRingEtSums") {
0069       obj = HfRingEtSums;
0070     } else if ((*itObj) == "TechTrig") {
0071       obj = TechTrig;
0072     } else if ((*itObj) == "BPTX") {
0073       obj = BPTX;
0074     } else if ((*itObj) == "GtExternal") {
0075       obj = GtExternal;
0076     } else {
0077       throw cms::Exception("Configuration") << "\nError: no such L1 GT object: " << (*itObj) << "\n"
0078                                             << "\n       Can not define the mapping of the L1 GT boards.     \n"
0079                                             << std::endl;
0080     }
0081 
0082     chInputObjectsV.push_back(obj);
0083   }
0084 
0085   return chInputObjectsV;
0086 }
0087 
0088 // constructor(s)
0089 L1GtBoardMapsTrivialProducer::L1GtBoardMapsTrivialProducer(const edm::ParameterSet& parSet) {
0090   // tell the framework what data is being produced
0091   setWhatProduced(this, &L1GtBoardMapsTrivialProducer::produceBoardMaps);
0092 
0093   // now do what ever other initialization is needed
0094 
0095   // get the list of the board names and indices
0096   std::vector<std::string> boardList = parSet.getParameter<std::vector<std::string> >("BoardList");
0097 
0098   std::vector<int> boardIndexVec = parSet.getParameter<std::vector<int> >("BoardIndex");
0099 
0100   // check if the board list and the board indices are consistent
0101   // i.e. have the same number of entries
0102 
0103   if (boardList.size() != boardIndexVec.size()) {
0104     throw cms::Exception("Configuration") << "\nError: inconsistent length of board list and board indices.\n"
0105                                           << "\n       Can not define the mapping of the L1 GT boards.     \n"
0106                                           << std::endl;
0107   }
0108 
0109   // L1 GT DAQ record map
0110   std::vector<int> boardPositionDaqRecord = parSet.getParameter<std::vector<int> >("BoardPositionDaqRecord");
0111 
0112   if (boardList.size() != boardPositionDaqRecord.size()) {
0113     throw cms::Exception("Configuration")
0114         << "\nError: inconsistent length of board list and board indices in GT DAQ record.\n"
0115         << "\n       Can not define the mapping of the L1 GT boards.     \n"
0116         << std::endl;
0117   }
0118 
0119   // L1 GT EVM record map
0120   std::vector<int> boardPositionEvmRecord = parSet.getParameter<std::vector<int> >("BoardPositionEvmRecord");
0121 
0122   if (boardList.size() != boardPositionEvmRecord.size()) {
0123     throw cms::Exception("Configuration")
0124         << "\nError: inconsistent length of board list and board indices in GT EVM record.\n"
0125         << "\n       Can not define the mapping of the L1 GT boards.     \n"
0126         << std::endl;
0127   }
0128 
0129   // L1 GT "active boards" map for DAQ record
0130   std::vector<int> activeBoardsDaqRecord = parSet.getParameter<std::vector<int> >("ActiveBoardsDaqRecord");
0131 
0132   if (boardList.size() != activeBoardsDaqRecord.size()) {
0133     throw cms::Exception("Configuration")
0134         << "\nError: inconsistent length of board list and active boards in GT DAQ record.\n"
0135         << "\n       Can not define the mapping of the L1 GT boards.     \n"
0136         << std::endl;
0137   }
0138 
0139   // L1 GT "active boards" map for EVM record
0140   std::vector<int> activeBoardsEvmRecord = parSet.getParameter<std::vector<int> >("ActiveBoardsEvmRecord");
0141 
0142   if (boardList.size() != activeBoardsEvmRecord.size()) {
0143     throw cms::Exception("Configuration")
0144         << "\nError: inconsistent length of board list and active boards in GT EVM record.\n"
0145         << "\n       Can not define the mapping of the L1 GT boards.     \n"
0146         << std::endl;
0147   }
0148 
0149   // L1 GT board - slot map
0150   std::vector<int> boardSlotMap = parSet.getParameter<std::vector<int> >("BoardSlotMap");
0151 
0152   if (boardList.size() != boardSlotMap.size()) {
0153     throw cms::Exception("Configuration") << "\nError: inconsistent length of board list and board - slot map.\n"
0154                                           << "\n       Can not define the mapping of the L1 GT boards.     \n"
0155                                           << std::endl;
0156   }
0157 
0158   // L1 GT board name in hw record map
0159   std::vector<int> boardHexNameMap = parSet.getParameter<std::vector<int> >("BoardHexNameMap");
0160 
0161   if (boardList.size() != boardHexNameMap.size()) {
0162     throw cms::Exception("Configuration")
0163         << "\nError: inconsistent length of board list and board name in hw record map.\n"
0164         << "\n       Can not define the mapping of the L1 GT boards.     \n"
0165         << std::endl;
0166   }
0167 
0168   // GCT PSB to GT - map cables to input quadruplets  and PSB indices
0169 
0170   // L1 GT cable list (GCT input to PSB)
0171   std::vector<std::string> cableList = parSet.getParameter<std::vector<std::string> >("CableList");
0172 
0173   // L1 GT calo input to PSB map
0174   //    gives the mapping of GT calorimeter input to GT PSBs via PSB index
0175   //    4 infinicables per PSB (last PSB can use only 2!)
0176   std::vector<int> cableToPsbMap = parSet.getParameter<std::vector<int> >("CableToPsbMap");
0177 
0178   if (cableList.size() != cableToPsbMap.size()) {
0179     throw cms::Exception("Configuration") << "\nError: inconsistent length of cable list and input to PSB list.\n"
0180                                           << "\n       Can not define the mapping of GCT quadruplets to GT PSBs.\n"
0181                                           << std::endl;
0182   }
0183 
0184   // detailed input configuration for PSB
0185   std::vector<edm::ParameterSet> psbInput = parSet.getParameter<std::vector<edm::ParameterSet> >("PsbInput");
0186 
0187   // reserve space for L1 GT boards
0188   m_gtBoardMaps.reserve(boardList.size());
0189 
0190   // fill the maps
0191   int posVec = 0;
0192 
0193   for (std::vector<std::string>::const_iterator it = boardList.begin(); it != boardList.end(); ++it) {
0194     L1GtBoardType boardType;
0195 
0196     if ((*it) == "GTFE") {
0197       boardType = GTFE;
0198     } else if ((*it) == "FDL") {
0199       boardType = FDL;
0200     } else if ((*it) == "PSB") {
0201       boardType = PSB;
0202     } else if ((*it) == "GMT") {
0203       boardType = GMT;
0204     } else if ((*it) == "TCS") {
0205       boardType = TCS;
0206     } else if ((*it) == "TIM") {
0207       boardType = TIM;
0208     } else {
0209       throw cms::Exception("Configuration") << "\nError: no such board: " << (*it).c_str() << "\n"
0210                                             << "\n       Can not define the mapping of the L1 GT boards.     \n"
0211                                             << std::endl;
0212     }
0213 
0214     // construct from board type and board index
0215 
0216     int iBoard = boardIndexVec.at(posVec);
0217     L1GtBoard gtBoard = L1GtBoard(boardType, iBoard);
0218 
0219     // set the position of board data block
0220     // in the GT DAQ readout record
0221     gtBoard.setGtPositionDaqRecord(boardPositionDaqRecord.at(posVec));
0222 
0223     // set the position of board data block
0224     // in the GT EVM readout record
0225     gtBoard.setGtPositionEvmRecord(boardPositionEvmRecord.at(posVec));
0226 
0227     // set the bit of board in the GTFE ACTIVE_BOARDS
0228     // for the GT DAQ readout record
0229     gtBoard.setGtBitDaqActiveBoards(activeBoardsDaqRecord.at(posVec));
0230 
0231     // set the bit of board in the GTFE ACTIVE_BOARDS
0232     // for the GT EVM readout record
0233     gtBoard.setGtBitEvmActiveBoards(activeBoardsEvmRecord.at(posVec));
0234 
0235     // set board slot
0236     int boardSlot = boardSlotMap.at(posVec);
0237     gtBoard.setGtBoardSlot(boardSlot);
0238 
0239     // set board hex fragment name in hw record
0240     gtBoard.setGtBoardHexName(boardHexNameMap.at(posVec));
0241 
0242     // set L1 quadruplet (4x16 bits)(cable) in the PSB input
0243     // valid for PSB only
0244 
0245     if (boardType == PSB) {
0246       L1GtPsbQuad psbQuad = Free;
0247       int posCable = 0;
0248       int iPsb = 0;
0249       std::vector<L1GtPsbQuad> quadVec(L1GtBoard::NumberCablesBoard);
0250 
0251       for (std::vector<std::string>::const_iterator cIt = cableList.begin(); cIt != cableList.end(); ++cIt) {
0252         if (*cIt == "TechTr") {
0253           psbQuad = TechTr;
0254         } else if (*cIt == "IsoEGQ") {
0255           psbQuad = IsoEGQ;
0256         } else if (*cIt == "NoIsoEGQ") {
0257           psbQuad = NoIsoEGQ;
0258         } else if (*cIt == "CenJetQ") {
0259           psbQuad = CenJetQ;
0260         } else if (*cIt == "ForJetQ") {
0261           psbQuad = ForJetQ;
0262         } else if (*cIt == "TauJetQ") {
0263           psbQuad = TauJetQ;
0264         } else if (*cIt == "ESumsQ") {
0265           psbQuad = ESumsQ;
0266         } else if (*cIt == "JetCountsQ") {
0267           psbQuad = JetCountsQ;
0268         } else if (*cIt == "MQB1") {
0269           psbQuad = MQB1;
0270         } else if (*cIt == "MQB2") {
0271           psbQuad = MQB2;
0272         } else if (*cIt == "MQF3") {
0273           psbQuad = MQF3;
0274         } else if (*cIt == "MQF4") {
0275           psbQuad = MQF4;
0276         } else if (*cIt == "MQB5") {
0277           psbQuad = MQB5;
0278         } else if (*cIt == "MQB6") {
0279           psbQuad = MQB6;
0280         } else if (*cIt == "MQF7") {
0281           psbQuad = MQF7;
0282         } else if (*cIt == "MQF8") {
0283           psbQuad = MQF8;
0284         } else if (*cIt == "MQB9") {
0285           psbQuad = MQB9;
0286         } else if (*cIt == "MQB10") {
0287           psbQuad = MQB10;
0288         } else if (*cIt == "MQF11") {
0289           psbQuad = MQF11;
0290         } else if (*cIt == "MQF12") {
0291           psbQuad = MQF12;
0292         } else if (*cIt == "Free") {
0293           psbQuad = Free;
0294         } else if (*cIt == "HfQ") {
0295           psbQuad = HfQ;
0296         } else {
0297           // should not arrive here
0298           throw cms::Exception("Configuration")
0299               << "\nError: no such quadruplet: " << (*cIt).c_str() << "\n"
0300               << "\n       Can not define the mapping of quadruplets to the L1 PSB boards.\n"
0301               << std::endl;
0302         }
0303 
0304         int psbIndex = cableToPsbMap.at(posCable);
0305 
0306         if (psbIndex == gtBoard.gtBoardIndex()) {
0307           if (iPsb > L1GtBoard::NumberCablesBoard) {
0308             throw cms::Exception("Configuration")
0309                 << "\nError: too many cables for PSB_" << gtBoard.gtBoardIndex() << "\n\n       "
0310                 << "Can not define the mapping of cables to L1 PSB boards.     \n"
0311                 << std::endl;
0312           }
0313           quadVec[iPsb] = psbQuad;
0314           iPsb++;
0315         }
0316         posCable++;
0317       }
0318 
0319       gtBoard.setGtQuadInPsb(quadVec);
0320     }
0321 
0322     if (boardType == PSB) {
0323       std::map<int, std::vector<L1GtObject> > inputPsbChannels;
0324 
0325       std::vector<std::string> chStrings;
0326       chStrings.reserve(2);  // most channels have 2 objects
0327 
0328       std::vector<L1GtObject> chObjects;
0329 
0330       for (std::vector<edm::ParameterSet>::const_iterator itPSet = psbInput.begin(); itPSet != psbInput.end();
0331            ++itPSet) {
0332         //
0333         int slot = itPSet->getParameter<int>("Slot");
0334 
0335         if (slot == boardSlot) {
0336           chStrings = itPSet->getParameter<std::vector<std::string> >("Ch0");
0337           chObjects = chInputObjects(chStrings);
0338           inputPsbChannels[0] = chObjects;
0339           chStrings.clear();
0340           chObjects.clear();
0341 
0342           chStrings = itPSet->getParameter<std::vector<std::string> >("Ch1");
0343           chObjects = chInputObjects(chStrings);
0344           inputPsbChannels[1] = chObjects;
0345           chStrings.clear();
0346           chObjects.clear();
0347 
0348           chStrings = itPSet->getParameter<std::vector<std::string> >("Ch2");
0349           chObjects = chInputObjects(chStrings);
0350           inputPsbChannels[2] = chObjects;
0351           chStrings.clear();
0352           chObjects.clear();
0353 
0354           chStrings = itPSet->getParameter<std::vector<std::string> >("Ch3");
0355           chObjects = chInputObjects(chStrings);
0356           inputPsbChannels[3] = chObjects;
0357           chStrings.clear();
0358           chObjects.clear();
0359 
0360           chStrings = itPSet->getParameter<std::vector<std::string> >("Ch4");
0361           chObjects = chInputObjects(chStrings);
0362           inputPsbChannels[4] = chObjects;
0363           chStrings.clear();
0364           chObjects.clear();
0365 
0366           chStrings = itPSet->getParameter<std::vector<std::string> >("Ch5");
0367           chObjects = chInputObjects(chStrings);
0368           inputPsbChannels[5] = chObjects;
0369           chStrings.clear();
0370           chObjects.clear();
0371 
0372           chStrings = itPSet->getParameter<std::vector<std::string> >("Ch6");
0373           chObjects = chInputObjects(chStrings);
0374           inputPsbChannels[6] = chObjects;
0375           chStrings.clear();
0376           chObjects.clear();
0377 
0378           chStrings = itPSet->getParameter<std::vector<std::string> >("Ch7");
0379           chObjects = chInputObjects(chStrings);
0380           inputPsbChannels[7] = chObjects;
0381           chStrings.clear();
0382           chObjects.clear();
0383         }
0384       }
0385 
0386       gtBoard.setGtInputPsbChannels(inputPsbChannels);
0387     }
0388 
0389     // push the board in the vector
0390     m_gtBoardMaps.push_back(gtBoard);
0391 
0392     // increase the counter
0393     posVec++;
0394   }
0395 }
0396 
0397 // destructor
0398 L1GtBoardMapsTrivialProducer::~L1GtBoardMapsTrivialProducer() {
0399   // empty
0400 }
0401 
0402 // member functions
0403 
0404 // method called to produce the data
0405 std::unique_ptr<L1GtBoardMaps> L1GtBoardMapsTrivialProducer::produceBoardMaps(const L1GtBoardMapsRcd& iRecord) {
0406   auto pL1GtBoardMaps = std::make_unique<L1GtBoardMaps>();
0407 
0408   pL1GtBoardMaps->setGtBoardMaps(m_gtBoardMaps);
0409 
0410   return pL1GtBoardMaps;
0411 }