Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:37:24

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           for (std::vector<FebConnectorSpec>::const_iterator ifc = febs.begin(); ifc != febs.end(); ifc++) {
0074             const FebConnectorSpec &febConnector = (*ifc);
0075             if (febConnector.rawId() != rawDetId)
0076               continue;
0077             int febInLB = febConnector.linkBoardInputNum();
0078             for (int istrip = 0; istrip < febConnector.nstrips(); istrip++) {
0079               int stripPinInFeb = febConnector.cablePinNum(istrip);
0080               if (febConnector.chamberStripNum(istrip) == stripInDU) {
0081                 result.push_back(std::make_pair(eleIndex, LinkBoardPackedStrip(febInLB, stripPinInFeb)));
0082               }
0083             }
0084           }
0085         }
0086       }
0087     }
0088   }
0089   return result;
0090 }
0091 
0092 const LinkBoardSpec *RPCReadOutMapping::location(const LinkBoardElectronicIndex &ele) const {
0093   //FIXME after debugging change to dcc(ele.dccId)->triggerBoard(ele.dccInputChannelNum)->...
0094   const DccSpec *dcc = RPCReadOutMapping::dcc(ele.dccId);
0095   if (dcc) {
0096     const TriggerBoardSpec *tb = dcc->triggerBoard(ele.dccInputChannelNum);
0097     if (tb) {
0098       const LinkConnSpec *lc = tb->linkConn(ele.tbLinkInputNum);
0099       if (lc) {
0100         const LinkBoardSpec *lb = lc->linkBoard(ele.lbNumInLink);
0101         return lb;
0102       }
0103     }
0104   }
0105   return nullptr;
0106 }
0107 
0108 RPCReadOutMapping::StripInDetUnit RPCReadOutMapping::detUnitFrame(const LinkBoardSpec &location,
0109                                                                   const LinkBoardPackedStrip &lbstrip) const {
0110   uint32_t detUnit = 0;
0111   int stripInDU = 0;
0112   int febInLB = lbstrip.febInLB();
0113   int stripPinInFeb = lbstrip.stripPinInFeb();
0114 
0115   const FebConnectorSpec *feb = location.feb(febInLB);
0116   if (feb) {
0117     detUnit = feb->rawId();
0118     const ChamberStripSpec strip = feb->strip(stripPinInFeb);
0119     if (strip.chamberStripNumber > -1) {
0120       stripInDU = strip.chamberStripNumber;
0121     } else {
0122       // LogWarning("detUnitFrame")<<"problem with stip for febInLB: "<<febInLB
0123       //                             <<" strip pin: "<< stripPinInFeb
0124       //                             <<" strip pin: "<< stripPinInFeb;
0125       LogDebug("") << "problem with stip for febInLB: " << febInLB << " strip pin: " << stripPinInFeb
0126                    << " strip pin: " << stripPinInFeb << " for linkBoard: " << location.print(3);
0127     }
0128   } else {
0129     // LogWarning("detUnitFrame")<<"problem with detUnit for febInLB: ";
0130     LogDebug("") << "problem with detUnit for febInLB: " << febInLB << " for linkBoard: " << location.print(1);
0131   }
0132   return std::make_pair(detUnit, stripInDU);
0133 }
0134 
0135 //
0136 // ALL BELOW IS TEMPORARY, TO BE REMOVED !!!!
0137 //
0138 
0139 std::pair<LinkBoardElectronicIndex, int> RPCReadOutMapping::getRAWSpecForCMSChamberSrip(uint32_t detId,
0140                                                                                         int strip,
0141                                                                                         int dccInputChannel) const {
0142   LinkBoardElectronicIndex linkboard;
0143   linkboard.dccId = 790;
0144   linkboard.dccInputChannelNum = dccInputChannel;
0145 
0146   for (int k = 0; k < 18; k++) {
0147     linkboard.tbLinkInputNum = k;
0148     for (int j = 0; j < 3; j++) {
0149       linkboard.lbNumInLink = j;
0150       const LinkBoardSpec *location = this->location(linkboard);
0151       if (location) {
0152         for (int i = 1; i < 7; i++) {
0153           const FebConnectorSpec *feb = location->feb(i);
0154           if (feb && feb->rawId() == detId) {
0155             for (int l = 1; l < 17; l++) {
0156               int pin = l;
0157               const ChamberStripSpec aStrip = feb->strip(pin);
0158               if (aStrip.cmsStripNumber == strip) {
0159                 int bitInLink = (i - 1) * 16 + l - 1;
0160                 std::pair<LinkBoardElectronicIndex, int> stripInfo(linkboard, bitInLink);
0161                 return stripInfo;
0162               }
0163             }
0164           }
0165         }
0166       }
0167     }
0168   }
0169   RPCDetId aDet(detId);
0170   std::cout << "Strip: " << strip << " not found for detector: " << aDet << std::endl;
0171   std::pair<LinkBoardElectronicIndex, int> dummyStripInfo(linkboard, -99);
0172   return dummyStripInfo;
0173 }
0174 
0175 std::vector<const LinkBoardSpec *> RPCReadOutMapping::getLBforChamber(const std::string &name) const {
0176   std::vector<const LinkBoardSpec *> vLBforChamber;
0177 
0178   LinkBoardElectronicIndex linkboard;
0179   linkboard.dccId = 790;
0180   linkboard.dccInputChannelNum = 1;
0181   linkboard.tbLinkInputNum = 1;
0182   linkboard.lbNumInLink = 0;
0183   const LinkBoardSpec *location = this->location(linkboard);
0184 
0185   for (int k = 0; k < 18; k++) {
0186     linkboard.dccInputChannelNum = 1;
0187     linkboard.tbLinkInputNum = k;
0188     for (int j = 0; j < 3; j++) {
0189       linkboard.lbNumInLink = j;
0190       int febInputNum = 1;
0191       location = this->location(linkboard);
0192       if (location) {
0193         //location->print();
0194         for (int j = 0; j < 6; j++) {
0195           const FebConnectorSpec *feb = location->feb(febInputNum + j);
0196           if (feb) {
0197             //feb->print();
0198             std::string chName = feb->chamber().chamberLocationName();
0199             if (chName == name) {
0200               vLBforChamber.push_back(location);
0201               //feb->chamber().print();
0202               break;
0203             }
0204           }
0205         }
0206       }
0207     }
0208   }
0209   return vLBforChamber;
0210 }