File indexing completed on 2024-04-06 12:02:31
0001 #include "CondFormats/RPCObjects/interface/FebConnectorSpec.h"
0002 #include "CondFormats/RPCObjects/interface/DBSpecToDetUnit.h"
0003 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0004 #include <sstream>
0005
0006 FebConnectorSpec::FebConnectorSpec(int num, const ChamberLocationSpec& chamber, const FebLocationSpec& feb)
0007 : theLinkBoardInputNum(num), theChamber(chamber), theFeb(feb), theAlgo(0), theRawId(0) {}
0008
0009 FebConnectorSpec::FebConnectorSpec(FebConnectorSpec const& iOther)
0010 : theLinkBoardInputNum(iOther.theLinkBoardInputNum),
0011 theChamber(iOther.theChamber),
0012 theFeb(iOther.theFeb),
0013 theAlgo(iOther.theAlgo),
0014 theRawId(iOther.theRawId.load()) {}
0015
0016 FebConnectorSpec& FebConnectorSpec::operator=(FebConnectorSpec const& iOther) {
0017 theLinkBoardInputNum = iOther.theLinkBoardInputNum;
0018 theChamber = iOther.theChamber;
0019 theFeb = iOther.theFeb;
0020 theAlgo = iOther.theAlgo;
0021 theRawId.store(iOther.theRawId.load());
0022 return *this;
0023 }
0024
0025 const ChamberStripSpec FebConnectorSpec::strip(int pinNumber) const {
0026 int nStrips = theAlgo / 10000;
0027 int firstChamberStrip = (theAlgo - 10000 * nStrips) / 100;
0028 int pinAlgo = theAlgo - 10000 * nStrips - 100 * firstChamberStrip;
0029 int slope = 1;
0030 if (pinAlgo > 3) {
0031 pinAlgo = pinAlgo - 4;
0032 slope = -1;
0033 }
0034 bool valid = true;
0035 if (pinNumber < pinAlgo)
0036 valid = false;
0037 if (!pinAlgo && (pinNumber < 2))
0038 valid = false;
0039 if (pinAlgo && (pinNumber > pinAlgo + nStrips - 1))
0040 valid = false;
0041 if (!pinAlgo && (pinNumber > nStrips + 2 || pinNumber == 9))
0042 valid = false;
0043 int chamberStripNumber = -1;
0044 if (valid) {
0045 if (pinAlgo != 0)
0046 chamberStripNumber = firstChamberStrip + slope * (pinNumber - pinAlgo);
0047 else if (pinNumber < 9)
0048 chamberStripNumber = firstChamberStrip + slope * (pinNumber - 2);
0049 else
0050 chamberStripNumber = firstChamberStrip + slope * (pinNumber - 3);
0051 }
0052 ChamberStripSpec aStrip = {pinNumber, chamberStripNumber, 0};
0053 return aStrip;
0054 }
0055
0056 const int FebConnectorSpec::chamberStripNum(int istrip) const {
0057 int nStrips = theAlgo / 10000;
0058 if (istrip < 0 || istrip > nStrips - 1)
0059 return 0;
0060 int firstChamberStrip = (theAlgo - 10000 * nStrips) / 100;
0061 int pinAlgo = theAlgo - 10000 * nStrips - 100 * firstChamberStrip;
0062 int theStrip = firstChamberStrip + istrip;
0063 if (pinAlgo > 3)
0064 theStrip = firstChamberStrip - istrip;
0065 return theStrip;
0066 }
0067
0068 const int FebConnectorSpec::cablePinNum(int istrip) const {
0069 int nStrips = theAlgo / 10000;
0070 if (istrip < 0 || istrip > nStrips - 1)
0071 return 0;
0072 int pinAlgo = theAlgo % 100;
0073 if (pinAlgo > 3)
0074 pinAlgo = pinAlgo - 4;
0075 bool holeatpin9 = (pinAlgo == 0 && istrip > 6);
0076 int thePin = istrip + pinAlgo + holeatpin9 + 2 * (pinAlgo == 0);
0077 return thePin;
0078 }
0079
0080 uint32_t FebConnectorSpec::rawId() const {
0081 DBSpecToDetUnit toDU;
0082 if (!theRawId) {
0083 uint32_t expected = 0;
0084 theRawId.compare_exchange_strong(expected, toDU(theChamber, theFeb));
0085 }
0086 return theRawId.load();
0087 }
0088
0089 std::string FebConnectorSpec::print(int depth) const {
0090 std::ostringstream str;
0091 str << "FebConnectorSpec in LinkBoardNum =" << linkBoardInputNum() << " rawId: " << rawId() << std::endl;
0092 RPCDetId aDet(rawId());
0093 str << aDet << std::endl;
0094 str << theChamber.print(depth) << std::endl << theFeb.print(depth);
0095 depth--;
0096 if (depth >= 0) {
0097 int nStrips = theAlgo / 10000;
0098 for (int istrip = 0; istrip < nStrips; istrip++) {
0099 ChamberStripSpec aStrip = {cablePinNum(istrip), chamberStripNum(istrip), cmsStripNum(istrip)};
0100 str << aStrip.print(depth);
0101 }
0102 }
0103 return str.str();
0104 }