CMS 3D CMS Logo

RPCLBLinkNameParser.cc
Go to the documentation of this file.
2 
3 #include <sstream>
4 
6 
8 {
9  lb_link.reset();
10  std::string::size_type size = name.size();
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 }
size
Write out results.
static HepMC::IO_HEPEVT conv
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
uint16_t size_type
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
static void parse(std::string const &name, RPCLBLink &lb_link)