CMS 3D CMS Logo

RPCLBLinkNameParser.cc
Go to the documentation of this file.
2 
3 #include <sstream>
4 
6 
7 void RPCLBLinkNameParser::parse(std::string const & _name, RPCLBLink & _lb_link)
8 {
9  _lb_link.reset();
10  std::string::size_type _size = _name.size();
11  std::string::size_type _pos(0), _next(0);
12  int _tmp;
13 
14  std::istringstream _conv;
15 
16  // region
17  _pos = _name.find("_R", _pos);
18  if (_pos == std::string::npos || (_pos += 2) >= _size)
19  throw cms::Exception("InvalidLinkBoardName") << "Expected _R[region], got " << _name;
20  switch (_name.at(_pos)) {
21  case 'B': _lb_link.setRegion(0); break;
22  case 'E': _lb_link.setRegion(1); break;
23  default:
24  throw cms::Exception("InvalidLinkBoardName") << "Expected Region B or E, got " << _name.at(_pos) << " in " << _name;
25  break;
26  }
27  if ((++_pos) >= _size)
28  throw cms::Exception("InvalidLinkBoardName") << "Name too short: " << _name;
29 
30  // yoke
31  _next = _name.find_first_not_of("+-0123456789", _pos);
32  _conv.clear();
33  _conv.str(_name.substr(_pos, _next - _pos));
34  _conv >> _tmp;
35  _lb_link.setYoke(_tmp);
36  _pos = _next;
37 
38  // sector
39  _pos = _name.find("_S", _pos);
40  if (_pos == std::string::npos || (_pos += 2) >= _size)
41  throw cms::Exception("InvalidLinkBoardName") << "Expected _S[sector], got " << _name;
42  _next = _name.find_first_not_of("+-0123456789", _pos);
43  _conv.clear();
44  _conv.str(_name.substr(_pos, _next - _pos));
45  _conv >> _tmp;
46  _lb_link.setSector(_tmp);
47  _pos = _next;
48 
49  // (region) side
50  _pos = _name.find("_", _pos);
51  if (_pos == std::string::npos || (_pos += 2) >= _size)
52  throw cms::Exception("InvalidLinkBoardName") << "Name too short: " << _name;
53  switch (_name.at(_pos)) {
54  case 'N': _lb_link.setSide(0); break;
55  case 'M': _lb_link.setSide(1); break;
56  case 'P': _lb_link.setSide(2); break;
57  default:
58  throw cms::Exception("InvalidLinkBoardName") << "Expected Side N, M or P, got " << _name.at(_pos) << " in " << _name;
59  break;
60  }
61  if ((++_pos) >= _size)
62  throw cms::Exception("InvalidLinkBoardName") << "Name too short: " << _name;
63 
64  // wheelordisk
65  _conv.clear();
66  _conv.str(_name.substr(_pos, 1));
67  _conv >> _tmp;
68  _lb_link.setWheelOrDisk(_tmp);
69  if ((++_pos) >= _size)
70  throw cms::Exception("InvalidLinkBoardName") << "Name too short: " << _name;
71 
72  // fibre
73  {
74  std::string _fibre("123ABCDE");
75  char const * _tmpchar = std::find(&(_fibre[0]), &(_fibre[0]) + 8, _name.at(_pos));
76  _lb_link.setFibre(_tmpchar - &(_fibre[0]));
77  }
78  if ((++_pos) >= _size)
79  return;
80 
81  // radial
82  _next = _name.find("_CH", _pos);
83  if (_next == std::string::npos)
84  _next = _size;
85  if (_next - _pos == 2) {
86  std::string _radial = _name.substr(_pos, 2);
87  if (_radial == "ab")
88  _lb_link.setRadial(0);
89  else if (_radial == "cd")
90  _lb_link.setRadial(1);
91  }
92 
93  if (_next == _size)
94  return;
95 
96  // linkboard
97  _pos = _next;
98  if (_pos + 3 >= _size)
99  throw cms::Exception("InvalidLinkBoardName") << "Name too short: " << _name;
100  _pos += 3;
101  _next = _name.find_first_not_of("+-0123456789", _pos);
102  _conv.clear();
103  _conv.str(_name.substr(_pos, _next - _pos));
104  _conv >> _tmp;
105  _lb_link.setLinkBoard(_tmp);
106 }
107 
108 
110 {
111  RPCLBLink _lb_link;
112  parse(_name, _lb_link);
113  return _lb_link;
114 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
uint16_t size_type
static void parse(std::string const &_name, RPCLBLink &_lb_link)