Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:28

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 
0003 #include "CondFormats/RPCObjects/interface/RPCReadOutMapping.h"
0004 #include "CondFormats/RPCObjects/interface/TriggerBoardSpec.h"
0005 #include "CondFormats/RPCObjects/interface/LinkConnSpec.h"
0006 #include "CondFormats/RPCObjects/interface/LinkBoardSpec.h"
0007 #include "CondFormats/RPCObjects/interface/FebConnectorSpec.h"
0008 #include "CondFormats/RPCObjects/interface/ChamberStripSpec.h"
0009 
0010 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0011 
0012 #include <iostream>
0013 
0014 using namespace edm;
0015 
0016 RPCReadOutMapping::RPCReadOutMapping(const std::string &version) : theVersion(version) {}
0017 
0018 const DccSpec *RPCReadOutMapping::dcc(int dccId) const {
0019   IMAP im = theFeds.find(dccId);
0020   const DccSpec &ddc = (*im).second;
0021   return (im != theFeds.end()) ? &ddc : nullptr;
0022 }
0023 
0024 void RPCReadOutMapping::add(const DccSpec &dcc) { theFeds[dcc.id()] = dcc; }
0025 
0026 std::vector<const DccSpec *> RPCReadOutMapping::dccList() const {
0027   std::vector<const DccSpec *> result;
0028   result.reserve(theFeds.size());
0029   for (IMAP im = theFeds.begin(); im != theFeds.end(); im++) {
0030     result.push_back(&(im->second));
0031   }
0032   return result;
0033 }
0034 
0035 std::pair<int, int> RPCReadOutMapping::dccNumberRange() const {
0036   if (theFeds.empty())
0037     return std::make_pair(0, -1);
0038   else {
0039     IMAP first = theFeds.begin();
0040     IMAP last = theFeds.end();
0041     last--;
0042     return std::make_pair(first->first, last->first);
0043   }
0044 }
0045 
0046 std::vector<std::pair<LinkBoardElectronicIndex, LinkBoardPackedStrip> > RPCReadOutMapping::rawDataFrame(
0047     const StripInDetUnit &stripInDetUnit) const {
0048   std::vector<std::pair<LinkBoardElectronicIndex, LinkBoardPackedStrip> > result;
0049   LinkBoardElectronicIndex eleIndex = {0, 0, 0, 0};
0050 
0051   const uint32_t &rawDetId = stripInDetUnit.first;
0052   const int &stripInDU = stripInDetUnit.second;
0053 
0054   for (IMAP im = theFeds.begin(); im != theFeds.end(); im++) {
0055     const DccSpec &dccSpec = (*im).second;
0056     const std::vector<TriggerBoardSpec> &triggerBoards = dccSpec.triggerBoards();
0057     for (std::vector<TriggerBoardSpec>::const_iterator it = triggerBoards.begin(); it != triggerBoards.end(); it++) {
0058       const TriggerBoardSpec &triggerBoard = (*it);
0059       typedef std::vector<const LinkConnSpec *> LINKS;
0060       LINKS linkConns = triggerBoard.enabledLinkConns();
0061       for (LINKS::const_iterator ic = linkConns.begin(); ic != linkConns.end(); ic++) {
0062         const LinkConnSpec &link = **ic;
0063         const std::vector<LinkBoardSpec> &boards = link.linkBoards();
0064         for (std::vector<LinkBoardSpec>::const_iterator ib = boards.begin(); ib != boards.end(); ib++) {
0065           const LinkBoardSpec &board = (*ib);
0066 
0067           eleIndex.dccId = dccSpec.id();
0068           eleIndex.dccInputChannelNum = triggerBoard.dccInputChannelNum();
0069           eleIndex.tbLinkInputNum = link.triggerBoardInputNumber();
0070           eleIndex.lbNumInLink = board.linkBoardNumInLink();
0071 
0072           const std::vector<FebConnectorSpec> &febs = board.febs();
0073           int febCheck = 0;
0074           for (std::vector<FebConnectorSpec>::const_iterator ifc = febs.begin(); ifc != febs.end(); ifc++) {
0075             const FebConnectorSpec &febConnector = (*ifc);
0076             febCheck++;
0077             if (febConnector.rawId() != rawDetId)
0078               continue;
0079             int febInLB = febConnector.linkBoardInputNum();
0080             /* if (febInLB != febCheck) {
0081               edm::LogError("rawDataFrame") << " problem with febInLB: " <<febInLB<<" "<<febCheck;
0082           } */
0083             for (int istrip = 0; istrip < febConnector.nstrips(); istrip++) {
0084               int stripPinInFeb = febConnector.cablePinNum(istrip);
0085               if (febConnector.chamberStripNum(istrip) == stripInDU) {
0086                 result.push_back(std::make_pair(eleIndex, LinkBoardPackedStrip(febInLB, stripPinInFeb)));
0087               }
0088             }
0089           }
0090         }
0091       }
0092     }
0093   }
0094   return result;
0095 }
0096 
0097 const LinkBoardSpec *RPCReadOutMapping::location(const LinkBoardElectronicIndex &ele) const {
0098   //FIXME after debugging change to dcc(ele.dccId)->triggerBoard(ele.dccInputChannelNum)->...
0099   const DccSpec *dcc = RPCReadOutMapping::dcc(ele.dccId);
0100   if (dcc) {
0101     const TriggerBoardSpec *tb = dcc->triggerBoard(ele.dccInputChannelNum);
0102     if (tb) {
0103       const LinkConnSpec *lc = tb->linkConn(ele.tbLinkInputNum);
0104       if (lc) {
0105         const LinkBoardSpec *lb = lc->linkBoard(ele.lbNumInLink);
0106         return lb;
0107       }
0108     }
0109   }
0110   return nullptr;
0111 }
0112 
0113 RPCReadOutMapping::StripInDetUnit RPCReadOutMapping::detUnitFrame(const LinkBoardSpec &location,
0114                                                                   const LinkBoardPackedStrip &lbstrip) const {
0115   uint32_t detUnit = 0;
0116   int stripInDU = 0;
0117   int febInLB = lbstrip.febInLB();
0118   int stripPinInFeb = lbstrip.stripPinInFeb();
0119 
0120   const FebConnectorSpec *feb = location.feb(febInLB);
0121   if (feb) {
0122     detUnit = feb->rawId();
0123     const ChamberStripSpec strip = feb->strip(stripPinInFeb);
0124     if (strip.chamberStripNumber > -1) {
0125       stripInDU = strip.chamberStripNumber;
0126     } else {
0127       // LogWarning("detUnitFrame")<<"problem with stip for febInLB: "<<febInLB
0128       //                             <<" strip pin: "<< stripPinInFeb
0129       //                             <<" strip pin: "<< stripPinInFeb;
0130       LogDebug("") << "problem with stip for febInLB: " << febInLB << " strip pin: " << stripPinInFeb
0131                    << " strip pin: " << stripPinInFeb << " for linkBoard: " << location.print(3);
0132     }
0133   } else {
0134     // LogWarning("detUnitFrame")<<"problem with detUnit for febInLB: ";
0135     LogDebug("") << "problem with detUnit for febInLB: " << febInLB << " for linkBoard: " << location.print(1);
0136   }
0137   return std::make_pair(detUnit, stripInDU);
0138 }
0139 
0140 //
0141 // ALL BELOW IS TEMPORARY, TO BE REMOVED !!!!
0142 //
0143 
0144 std::pair<LinkBoardElectronicIndex, int> RPCReadOutMapping::getRAWSpecForCMSChamberSrip(uint32_t detId,
0145                                                                                         int strip,
0146                                                                                         int dccInputChannel) const {
0147   LinkBoardElectronicIndex linkboard;
0148   linkboard.dccId = 790;
0149   linkboard.dccInputChannelNum = dccInputChannel;
0150 
0151   for (int k = 0; k < 18; k++) {
0152     linkboard.tbLinkInputNum = k;
0153     for (int j = 0; j < 3; j++) {
0154       linkboard.lbNumInLink = j;
0155       const LinkBoardSpec *location = this->location(linkboard);
0156       if (location) {
0157         for (int i = 1; i < 7; i++) {
0158           const FebConnectorSpec *feb = location->feb(i);
0159           if (feb && feb->rawId() == detId) {
0160             for (int l = 1; l < 17; l++) {
0161               int pin = l;
0162               const ChamberStripSpec aStrip = feb->strip(pin);
0163               if (aStrip.cmsStripNumber == strip) {
0164                 int bitInLink = (i - 1) * 16 + l - 1;
0165                 std::pair<LinkBoardElectronicIndex, int> stripInfo(linkboard, bitInLink);
0166                 return stripInfo;
0167               }
0168             }
0169           }
0170         }
0171       }
0172     }
0173   }
0174   RPCDetId aDet(detId);
0175   std::cout << "Strip: " << strip << " not found for detector: " << aDet << std::endl;
0176   std::pair<LinkBoardElectronicIndex, int> dummyStripInfo(linkboard, -99);
0177   return dummyStripInfo;
0178 }
0179 
0180 std::vector<const LinkBoardSpec *> RPCReadOutMapping::getLBforChamber(const std::string &name) const {
0181   std::vector<const LinkBoardSpec *> vLBforChamber;
0182 
0183   LinkBoardElectronicIndex linkboard;
0184   linkboard.dccId = 790;
0185   linkboard.dccInputChannelNum = 1;
0186   linkboard.tbLinkInputNum = 1;
0187   linkboard.lbNumInLink = 0;
0188   const LinkBoardSpec *location = this->location(linkboard);
0189 
0190   for (int k = 0; k < 18; k++) {
0191     linkboard.dccInputChannelNum = 1;
0192     linkboard.tbLinkInputNum = k;
0193     for (int j = 0; j < 3; j++) {
0194       linkboard.lbNumInLink = j;
0195       int febInputNum = 1;
0196       location = this->location(linkboard);
0197       if (location) {
0198         //location->print();
0199         for (int j = 0; j < 6; j++) {
0200           const FebConnectorSpec *feb = location->feb(febInputNum + j);
0201           if (feb) {
0202             //feb->print();
0203             std::string chName = feb->chamber().chamberLocationName();
0204             if (chName == name) {
0205               vLBforChamber.push_back(location);
0206               //feb->chamber().print();
0207               break;
0208             }
0209           }
0210         }
0211       }
0212     }
0213   }
0214   return vLBforChamber;
0215 }