CMS 3D CMS Logo

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