Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:30

0001 #include <vector>
0002 #include "L1Trigger/Phase2L1ParticleFlow/interface/deregionizer/deregionizer_input.h"
0003 #include "L1Trigger/Phase2L1ParticleFlow/interface/dbgPrintf.h"
0004 
0005 #ifdef CMSSW_GIT_HASH
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 l1ct::DeregionizerInput::DeregionizerInput(const std::vector<edm::ParameterSet> linkConfigs) {
0008   for (const auto &pset : linkConfigs) {
0009     DeregionizerInput::BoardInfo boardInfo;
0010     boardInfo.nOutputFramesPerBX_ = pset.getParameter<uint32_t>("nOutputFramesPerBX");
0011     boardInfo.nLinksPuppi_ = pset.getParameter<uint32_t>("nLinksPuppi");
0012     boardInfo.nPuppiPerRegion_ = pset.getParameter<uint32_t>("nPuppiPerRegion");
0013     boardInfo.order_ = pset.getParameter<int32_t>("outputBoard");
0014     boardInfo.regions_ = pset.getParameter<std::vector<uint32_t>>("outputRegions");
0015     boardInfo.nPuppiFramesPerRegion_ = (boardInfo.nOutputFramesPerBX_ * tmuxFactor_) / boardInfo.regions_.size();
0016     boardInfos_.push_back(boardInfo);
0017   }
0018 }
0019 #endif
0020 
0021 std::vector<l1ct::DeregionizerInput::PlacedPuppi> l1ct::DeregionizerInput::inputOrderInfo(
0022     const std::vector<l1ct::OutputRegion> &inputRegions) const {
0023   // Vector of all puppis in event paired with LinkPlacementInfo
0024   std::vector<PlacedPuppi> linkPlacedPuppis;
0025   for (BoardInfo boardInfo : boardInfos_) {
0026     for (uint iRegion = 0; iRegion < boardInfo.regions_.size(); iRegion++) {
0027       uint iRegionEvent = boardInfo.regions_.at(iRegion);
0028       auto puppi = inputRegions.at(iRegionEvent).puppi;
0029       unsigned int npuppi = puppi.size();
0030       for (unsigned int i = 0; i < boardInfo.nLinksPuppi_ * boardInfo.nPuppiFramesPerRegion_; ++i) {
0031         if (i < npuppi) {
0032           uint iClock =
0033               iRegion * boardInfo.nPuppiPerRegion_ / boardInfo.nLinksPuppi_ + i % boardInfo.nPuppiFramesPerRegion_;
0034           uint iLink = i / boardInfo.nPuppiFramesPerRegion_;
0035           LPI lpi = {boardInfo.order_, iLink, iClock};
0036           linkPlacedPuppis.push_back(std::make_pair(puppi.at(i), lpi));
0037         }
0038       }
0039     }
0040   }
0041   return linkPlacedPuppis;
0042 }
0043 
0044 std::vector<std::vector<std::vector<l1ct::PuppiObjEmu>>> l1ct::DeregionizerInput::orderInputs(
0045     const std::vector<l1ct::OutputRegion> &inputRegions) const {
0046   std::vector<PlacedPuppi> linkPlacedPuppis = inputOrderInfo(inputRegions);
0047   std::vector<std::vector<std::vector<l1ct::PuppiObjEmu>>> layer2inReshape(nInputFramesPerBX_ * tmuxFactor_);
0048   for (uint iClock = 0; iClock < nInputFramesPerBX_ * tmuxFactor_; iClock++) {
0049     std::vector<std::vector<l1ct::PuppiObjEmu>> orderedPupsOnClock(boardInfos_.size());
0050     // Find all the puppis on this clock cycle
0051     for (BoardInfo boardInfo : boardInfos_) {
0052       // find all puppis on this clock cycle, from this board
0053       std::vector<l1ct::PuppiObjEmu> orderedPupsOnClockOnBoard;
0054       for (uint iLink = 0; iLink < boardInfo.nLinksPuppi_; iLink++) {
0055         // find all puppis from this clock cycle, from this board, from this link
0056         auto onClockOnBoardOnLink = [&](PlacedPuppi p) {
0057           return (p.second.clock_cycle_ == iClock) && (p.second.board_ == boardInfo.order_) &&
0058                  (p.second.link_ == iLink);
0059         };
0060         std::vector<PlacedPuppi> allPupsOnClockOnBoardOnLink;
0061         std::copy_if(std::begin(linkPlacedPuppis),
0062                      std::end(linkPlacedPuppis),
0063                      std::back_inserter(allPupsOnClockOnBoardOnLink),
0064                      onClockOnBoardOnLink);
0065         linkPlacedPuppis.erase(
0066             std::remove_if(std::begin(linkPlacedPuppis), std::end(linkPlacedPuppis), onClockOnBoardOnLink),
0067             std::end(linkPlacedPuppis));  // erase already placed pups
0068         if (!allPupsOnClockOnBoardOnLink.empty()) {
0069           orderedPupsOnClockOnBoard.push_back(allPupsOnClockOnBoardOnLink.at(0).first);
0070         }
0071       }
0072       orderedPupsOnClock.at(boardInfo.order_) = orderedPupsOnClockOnBoard;
0073     }
0074     layer2inReshape.at(iClock) = orderedPupsOnClock;
0075   }
0076   return layer2inReshape;
0077 }