File indexing completed on 2024-04-06 12:10:58
0001 #include "RPCReadOutMappingWithFastSearch.h"
0002 #include <vector>
0003 #include <iostream>
0004
0005 using namespace std;
0006
0007 bool RPCReadOutMappingWithFastSearch::lessMap::operator()(const LinkBoardElectronicIndex& lb1,
0008 const LinkBoardElectronicIndex& lb2) const {
0009 if (lb1.dccId < lb2.dccId)
0010 return true;
0011 if (lb1.dccId > lb2.dccId)
0012 return false;
0013 if (lb1.dccInputChannelNum < lb2.dccInputChannelNum)
0014 return true;
0015 if (lb1.dccInputChannelNum > lb2.dccInputChannelNum)
0016 return false;
0017 if (lb1.tbLinkInputNum < lb2.tbLinkInputNum)
0018 return true;
0019 if (lb1.tbLinkInputNum > lb2.tbLinkInputNum)
0020 return false;
0021 if (lb1.lbNumInLink < lb2.lbNumInLink)
0022 return true;
0023 if (lb1.lbNumInLink > lb2.lbNumInLink)
0024 return false;
0025 return false;
0026 }
0027
0028 RPCReadOutMappingWithFastSearch::RPCReadOutMappingWithFastSearch() : theMapping(nullptr) {}
0029
0030 void RPCReadOutMappingWithFastSearch::init(const RPCReadOutMapping* arm) {
0031 if (theVersion == arm->version())
0032 return;
0033
0034 theVersion = arm->version();
0035 theLBMap.clear();
0036 theMapping = arm;
0037
0038 typedef vector<const DccSpec*> DCCLIST;
0039 DCCLIST dccList = arm->dccList();
0040 for (DCCLIST::const_iterator idcc = dccList.begin(), idccEnd = dccList.end(); idcc < idccEnd; ++idcc) {
0041 const DccSpec& dccSpec = **idcc;
0042 const std::vector<TriggerBoardSpec>& triggerBoards = dccSpec.triggerBoards();
0043 for (std::vector<TriggerBoardSpec>::const_iterator it = triggerBoards.begin(); it != triggerBoards.end(); it++) {
0044 const TriggerBoardSpec& triggerBoard = (*it);
0045 typedef std::vector<const LinkConnSpec*> LINKS;
0046 LINKS linkConns = triggerBoard.enabledLinkConns();
0047 for (LINKS::const_iterator ic = linkConns.begin(); ic != linkConns.end(); ic++) {
0048 const LinkConnSpec& link = **ic;
0049 const std::vector<LinkBoardSpec>& boards = link.linkBoards();
0050 for (std::vector<LinkBoardSpec>::const_iterator ib = boards.begin(); ib != boards.end(); ib++) {
0051 const LinkBoardSpec& board = (*ib);
0052
0053 LinkBoardElectronicIndex eleIndex;
0054 eleIndex.dccId = dccSpec.id();
0055 eleIndex.dccInputChannelNum = triggerBoard.dccInputChannelNum();
0056 eleIndex.tbLinkInputNum = link.triggerBoardInputNumber();
0057 eleIndex.lbNumInLink = board.linkBoardNumInLink();
0058 LBMap::iterator inMap = theLBMap.find(eleIndex);
0059 if (inMap != theLBMap.end()) {
0060 cout << "The element in map already exists!" << endl;
0061 } else {
0062 theLBMap[eleIndex] = &board;
0063 }
0064 }
0065 }
0066 }
0067 }
0068 }
0069
0070 RPCReadOutMapping::StripInDetUnit RPCReadOutMappingWithFastSearch::detUnitFrame(
0071 const LinkBoardSpec& location, const LinkBoardPackedStrip& lbstrip) const {
0072 return theMapping->detUnitFrame(location, lbstrip);
0073 }
0074
0075 const LinkBoardSpec* RPCReadOutMappingWithFastSearch::location(const LinkBoardElectronicIndex& ele) const {
0076 LBMap::const_iterator inMap = theLBMap.find(ele);
0077 return (inMap != theLBMap.end()) ? inMap->second : nullptr;
0078
0079 }