File indexing completed on 2023-03-17 10:48:34
0001 #include "CondTools/RPC/interface/RPCLBLinkNameParser.h"
0002
0003 #include <sstream>
0004 #include <algorithm>
0005 #include "FWCore/Utilities/interface/Exception.h"
0006
0007 void RPCLBLinkNameParser::parse(std::string const& name, RPCLBLink& lb_link) {
0008 lb_link.reset();
0009 std::string::size_type size = name.size();
0010 std::string::size_type pos(0), next(0);
0011 int tmp;
0012
0013 std::istringstream conv;
0014
0015
0016 pos = name.find("_R", pos);
0017 if (pos == std::string::npos || (pos += 2) >= size)
0018 throw cms::Exception("InvalidLinkBoardName") << "Expected _R[region], got " << name;
0019 switch (name.at(pos)) {
0020 case 'B':
0021 lb_link.setRegion(0);
0022 break;
0023 case 'E':
0024 lb_link.setRegion(1);
0025 break;
0026 default:
0027 throw cms::Exception("InvalidLinkBoardName") << "Expected Region B or E, got " << name.at(pos) << " in " << name;
0028 break;
0029 }
0030 if ((++pos) >= size)
0031 throw cms::Exception("InvalidLinkBoardName") << "Name too short: " << name;
0032
0033
0034 next = name.find_first_not_of("+-0123456789", pos);
0035 conv.clear();
0036 conv.str(name.substr(pos, next - pos));
0037 conv >> tmp;
0038 lb_link.setYoke(tmp);
0039 pos = next;
0040
0041
0042 pos = name.find("_S", pos);
0043 if (pos == std::string::npos || (pos += 2) >= size)
0044 throw cms::Exception("InvalidLinkBoardName") << "Expected _S[sector], got " << name;
0045 next = name.find_first_not_of("+-0123456789", pos);
0046 conv.clear();
0047 conv.str(name.substr(pos, next - pos));
0048 conv >> tmp;
0049 lb_link.setSector(tmp);
0050 pos = next;
0051
0052
0053 pos = name.find('_', pos);
0054 if (pos == std::string::npos || (pos += 2) >= size)
0055 throw cms::Exception("InvalidLinkBoardName") << "Name too short: " << name;
0056 switch (name.at(pos)) {
0057 case 'N':
0058 lb_link.setSide(0);
0059 break;
0060 case 'M':
0061 lb_link.setSide(1);
0062 break;
0063 case 'P':
0064 lb_link.setSide(2);
0065 break;
0066 default:
0067 throw cms::Exception("InvalidLinkBoardName") << "Expected Side N, M or P, got " << name.at(pos) << " in " << name;
0068 break;
0069 }
0070 if ((++pos) >= size)
0071 throw cms::Exception("InvalidLinkBoardName") << "Name too short: " << name;
0072
0073
0074 conv.clear();
0075 conv.str(name.substr(pos, 1));
0076 conv >> tmp;
0077 lb_link.setWheelOrDisk(tmp);
0078 if ((++pos) >= size)
0079 throw cms::Exception("InvalidLinkBoardName") << "Name too short: " << name;
0080
0081
0082 {
0083 std::string fibre("123ABCDE");
0084 char const* tmpchar = std::find(&(fibre[0]), &(fibre[0]) + 8, name.at(pos));
0085 lb_link.setFibre(tmpchar - &(fibre[0]));
0086 }
0087 if ((++pos) >= size)
0088 return;
0089
0090
0091 next = name.find("_CH", pos);
0092 if (next == std::string::npos)
0093 next = size;
0094 if (next - pos == 2) {
0095 std::string radial = name.substr(pos, 2);
0096 if (radial == "ab")
0097 lb_link.setRadial(0);
0098 else if (radial == "cd")
0099 lb_link.setRadial(1);
0100 }
0101
0102 if (next == size)
0103 return;
0104
0105
0106 pos = next;
0107 if (pos + 3 >= size)
0108 throw cms::Exception("InvalidLinkBoardName") << "Name too short: " << name;
0109 pos += 3;
0110 next = name.find_first_not_of("+-0123456789", pos);
0111 conv.clear();
0112 conv.str(name.substr(pos, next - pos));
0113 conv >> tmp;
0114 lb_link.setLinkBoard(tmp);
0115 }
0116
0117 RPCLBLink RPCLBLinkNameParser::parse(std::string const& name) {
0118 RPCLBLink lb_link;
0119 parse(name, lb_link);
0120 return lb_link;
0121 }