CMS 3D CMS Logo

HcalText2DetIdConverter.cc
Go to the documentation of this file.
1 
4 #include <cstdlib>
5 #include <iostream>
6 #include <iomanip>
7 #include <cstdio>
8 
10 
16 
18 
19 namespace {
20  std::string strip(const std::string& fString) {
21  if (fString.empty())
22  return fString;
23  int startIndex = fString.find_first_not_of(" \t\n");
24  int endIndex = fString.find_last_not_of(" \t\n");
25  return fString.substr(startIndex, (endIndex - startIndex) + 1);
26  }
27 
28  int calibChannel(const std::string& fName) {
29  return fName == "Mixer-High" ? 1
30  : fName == "Mixer-Low" ? 2
31  : fName == "Megatile" ? 3
32  : fName == "Mixer-Scintillator" ? 4
33  : fName == "RadDam1" ? 5
34  : fName == "RadDam2" ? 6
35  : fName == "RadDam3" ? 7
36  : atoi(fName.c_str());
37  // 0;
38  }
39 } // namespace
40 
42  const std::string& fField1,
43  const std::string& fField2,
44  const std::string& fField3) {
45  if (!init(fFlavor, fField1, fField2, fField3)) {
46  std::cerr << "HcalText2DetIdConverter::HcalText2DetIdConverter-> Can not initiate detId from items: " << fFlavor
47  << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
48  throw cms::Exception("HcalGenDetId initialization error")
49  << " Can not initiate detId from items: " << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3
50  << std::endl;
51  }
52 }
53 
55 
57 
59 
61 
63 
65  bool result = true;
66  flavorName = "UNKNOWN";
67  mId = fId;
68  HcalGenericDetId genId(mId);
69  if (fId == HcalDetId::Undefined) {
70  flavorName = "NA";
71  } else if (genId.isHcalDetId()) {
72  HcalDetId hcalId(mId);
77  : "H_UNKNOWN";
78  setField(1, hcalId.ieta());
79  setField(2, hcalId.iphi());
80  setField(3, hcalId.depth());
81  } else if (genId.isHcalTrigTowerDetId()) {
82  HcalTrigTowerDetId triggerId(mId);
83  if (triggerId == HcalTrigTowerDetId::Undefined) {
84  flavorName = "NT";
85  } else {
86  flavorName = "HT";
87  setField(1, triggerId.ieta());
88  setField(2, triggerId.iphi());
89  setField(3, triggerId.version() * 10 + triggerId.depth());
90  /*
91  if (triggerId.version() == 0) {
92  setField (1, triggerId.ieta());
93  setField (2, triggerId.iphi());
94  setField (3, 1);
95  } else if (triggerId.version() == 1) {
96  setField (1, triggerId.ieta());
97  setField (2, triggerId.iphi());
98  setField (3, 10); // We use the tens digit to indicate version
99  } else {
100  // Unknown version
101  }
102 */
103  }
104  } else if (genId.isHcalZDCDetId()) {
105  HcalZDCDetId zdcId(mId);
106  switch (zdcId.section()) {
107  case HcalZDCDetId::EM:
108  flavorName = "ZDC_EM";
109  break;
110  case HcalZDCDetId::HAD:
111  flavorName = "ZDC_HAD";
112  break;
113  case HcalZDCDetId::LUM:
114  flavorName = "ZDC_LUM";
115  break;
116  case HcalZDCDetId::RPD:
117  flavorName = "ZDC_RPD";
118  break;
119  default:
120  result = false;
121  }
122  setField(1, zdcId.zside());
123  setField(2, zdcId.channel());
124  setField(3, -99);
125  } else if (genId.isHcalCalibDetId()) {
126  HcalCalibDetId calibId(mId);
127  if (calibId.calibFlavor() == HcalCalibDetId::CalibrationBox) {
128  switch (calibId.hcalSubdet()) {
129  case HcalBarrel:
130  flavorName = "CALIB_HB";
131  break;
132  case HcalEndcap:
133  flavorName = "CALIB_HE";
134  break;
135  case HcalOuter:
136  flavorName = "CALIB_HO";
137  break;
138  case HcalForward:
139  flavorName = "CALIB_HF";
140  break;
141  default:
142  result = false;
143  }
144  setField(1, calibId.ieta());
145  setField(2, calibId.iphi());
146  setField(3, calibId.cboxChannel());
147  } else if (calibId.calibFlavor() == HcalCalibDetId::HOCrosstalk) {
148  flavorName = "HOX";
149  setField(1, calibId.ieta());
150  setField(2, calibId.iphi());
151  setField(3, -999);
152  } else if (calibId.calibFlavor() == HcalCalibDetId::uMNqie) {
153  flavorName = "UMNQIE";
154  setField(1, calibId.channel());
155  setField(2, -999);
156  setField(3, -999);
157  } else if (calibId.calibFlavor() == HcalCalibDetId::LASERMON) {
158  flavorName = "LASMON";
159  setField(1, calibId.ieta());
160  setField(2, calibId.iphi());
161  setField(3, calibId.cboxChannel());
162  } else if (calibId.calibFlavor() == HcalCalibDetId::CastorRadFacility) {
163  flavorName = "CRF";
164  setField(1, calibId.rm());
165  setField(2, calibId.fiber());
166  setField(3, calibId.channel());
167  } else if (calibId.calibFlavor() == HcalCalibDetId::HBX) {
168  flavorName = "HBX";
169  setField(1, calibId.ieta());
170  setField(2, calibId.iphi());
171  setField(3, -999);
172  } else if (calibId.calibFlavor() == HcalCalibDetId::HEX) {
173  flavorName = "HEX";
174  setField(1, calibId.ieta());
175  setField(2, calibId.iphi());
176  setField(3, -999);
177  }
178  } else {
179  flavorName = "UNKNOWN_FLAVOR";
180  std::cerr << "HcalText2DetIdConverter::init-> Unknown detId: " << std::hex << std::showbase << mId.rawId()
181  << std::endl;
182  result = false;
183  }
184  return result;
185 }
186 
188  const std::string& fField1,
189  const std::string& fField2,
190  const std::string& fField3) {
191  bool result = true;
192  flavorName = strip(fFlavor);
193  field1 = strip(fField1);
194  field2 = strip(fField2);
195  field3 = strip(fField3);
196  if (flavorName == "HB" || flavorName == "HE" || flavorName == "HF" || flavorName == "HO") {
197  HcalSubdetector sub = flavorName == "HB" ? HcalBarrel
198  : flavorName == "HE" ? HcalEndcap
199  : flavorName == "HO" ? HcalOuter
200  : HcalForward;
201  mId = HcalDetId(sub, getField(1), getField(2), getField(3));
202  } else if (flavorName == "HT") {
203  // We use the depth to signal the "version" being used (RCT or 1x1 HF). RCT
204  // has a 0 in the 10s digit, whereas 1x1 has a 1. The ones digit is still
205  // used to indicate depth, although in the 1x1 case this must be 0, so we
206  // set it as such.
208  /*
209  const int depth_field = getField(3);
210  const int ones = depth_field % 10;
211  const int tens = (depth_field - ones) / 10;
212  if (tens == 0) {
213  const int depth = ones;
214  const int version = 0;
215  mId = HcalTrigTowerDetId (getField (1), getField (2), depth, version);
216  } else if (tens == 1) {
217  const int depth = 0;
218  const int version = 1;
219  mId = HcalTrigTowerDetId(getField(1), getField(2), depth, version);
220  } else {
221  // Undefined version!
222  }
223 */
224  } else if (flavorName.find("ZDC_") == 0) {
226  if (flavorName == "ZDC_EM")
228  else if (flavorName == "ZDC_HAD")
230  else if (flavorName == "ZDC_LUM")
232  else if (flavorName == "ZDC_RPD")
234  mId = HcalZDCDetId(section, getField(1) > 0, getField(2));
235  } else if (flavorName.find("CALIB_") == 0) {
237  if (flavorName.find("HB") != std::string::npos)
238  sd = HcalBarrel;
239  else if (flavorName.find("HE") != std::string::npos)
240  sd = HcalEndcap;
241  else if (flavorName.find("HO") != std::string::npos)
242  sd = HcalOuter;
243  else if (flavorName.find("HF") != std::string::npos)
244  sd = HcalForward;
245 
246  int ieta = getField(1);
247  int iphi = getField(2);
248  int channel = calibChannel(field3);
249  mId = HcalCalibDetId(sd, ieta, iphi, channel);
250  } else if (flavorName == "HOX" || flavorName == "HBX" || flavorName == "HEX") {
251  int ieta = getField(1);
252  int iphi = getField(2);
256  } else if (flavorName == "UMNQIE") {
257  int channel = getField(1);
259  } else if (flavorName == "LASMON") {
260  int ieta = getField(1);
261  int iphi = getField(2);
262  int channel = getField(3);
264  } else if (flavorName == "CRF") {
265  int rm = getField(1);
266  int fiber = getField(2);
267  int channel = getField(3);
269  } else if (flavorName == "NA") {
271  } else {
272  std::cerr << "HcalText2DetIdConverter::init-> Unknown HcalDetId flavor: " << flavorName << std::endl;
273  result = false;
274  }
275  return result;
276 }
277 
279  char* endptr;
280  const char* nptr = i == 1 ? field1.c_str() : i == 2 ? field2.c_str() : field3.c_str();
281  long result = strtol(nptr, &endptr, 0);
282  if (*nptr != '\0' && *endptr == '\0') {
283  return result;
284  }
285  if (i == 2 && isHcalCalibDetId()) {
286  int result = calibChannel(field2);
287  if (i)
288  return result;
289  }
290  if (*nptr != '\0') {
291  std::cerr << "HcalText2DetIdConverter::getField-> Can not convert string " << nptr
292  << " to int. Bad symbol: " << *endptr << std::endl;
293  }
294  return 0;
295 }
296 
297 void HcalText2DetIdConverter::setField(int i, int fValue) {
298  char buffer[128];
299  sprintf(buffer, "%d", fValue);
300  if (i == 1)
301  field1 = buffer;
302  else if (i == 2)
303  field2 = buffer;
304  else
305  field3 = buffer;
306 }
307 
309  return flavorName + " " + field1 + " " + field2 + " " + field3;
310 }
HcalOther
Definition: HcalAssistant.h:38
HcalDetId::Undefined
static const HcalDetId Undefined
Definition: HcalDetId.h:273
mps_fire.i
i
Definition: mps_fire.py:428
HcalTrigTowerDetId::ieta
int ieta() const
get the tower ieta
Definition: HcalTrigTowerDetId.h:54
HcalZDCDetId::HAD
Definition: HcalZDCDetId.h:23
HcalGenericDetId
Definition: HcalGenericDetId.h:15
HcalZDCDetId::Section
Section
Definition: HcalZDCDetId.h:23
HcalDetId::iphi
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
HcalCalibDetId
Definition: HcalCalibDetId.h:45
HcalText2DetIdConverter::field3
std::string field3
Definition: HcalText2DetIdConverter.h:53
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
HcalText2DetIdConverter::isHcalCalibDetId
bool isHcalCalibDetId() const
Definition: HcalText2DetIdConverter.cc:58
HcalZDCDetId::channel
int channel() const
get the channel
Definition: HcalZDCDetId.cc:63
HcalCalibDetId::ieta
int ieta() const
Definition: HcalCalibDetId.cc:94
HcalGenericDetId::HcalGenEndcap
Definition: HcalGenericDetId.h:20
HcalCalibDetId::uMNqie
Definition: HcalCalibDetId.h:51
HcalGenericDetId.h
HcalDetId::depth
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164
HcalBarrel
Definition: HcalAssistant.h:33
HcalText2DetIdConverter::mId
DetId mId
Definition: HcalText2DetIdConverter.h:54
HcalZDCDetId.h
HcalText2DetIdConverter::field1
std::string field1
Definition: HcalText2DetIdConverter.h:51
HcalText2DetIdConverter::field2
std::string field2
Definition: HcalText2DetIdConverter.h:52
HcalCalibDetId::HEX
Definition: HcalCalibDetId.h:55
MainPageGenerator.fName
fName
Definition: MainPageGenerator.py:301
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
HcalGenericDetId::isHcalZDCDetId
bool isHcalZDCDetId() const
Definition: HcalGenericDetId.cc:79
DetId
Definition: DetId.h:17
HcalZDCDetId
Definition: HcalZDCDetId.h:16
HcalCalibDetId::HBX
Definition: HcalCalibDetId.h:54
HcalGenericDetId::isHcalCalibDetId
bool isHcalCalibDetId() const
Definition: HcalGenericDetId.cc:69
HcalOuter
Definition: HcalAssistant.h:35
HcalCalibDetId.h
HcalTrigTowerDetId::version
int version() const
get the version code for the trigger tower
Definition: HcalTrigTowerDetId.h:60
HcalText2DetIdConverter::HcalText2DetIdConverter
HcalText2DetIdConverter(const std::string &fFlavor="NA", const std::string &fField1="0", const std::string &fField2="0", const std::string &fField3="0")
Definition: HcalText2DetIdConverter.cc:41
HcalText2DetIdConverter::isHcalTrigTowerDetId
bool isHcalTrigTowerDetId() const
Definition: HcalText2DetIdConverter.cc:60
HcalTrigTowerDetId.h
HcalGenericDetId::isHcalTrigTowerDetId
bool isHcalTrigTowerDetId() const
Definition: HcalGenericDetId.cc:74
HcalText2DetIdConverter::setField
void setField(int i, int fValue)
Definition: HcalText2DetIdConverter.cc:297
HcalZDCDetId::zside
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:39
HcalCalibDetId::CastorRadFacility
Definition: HcalCalibDetId.h:52
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
HcalDetId::ieta
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
HcalCalibDetId::channel
int channel() const
get the channel (for uMNio/qie or similar)
Definition: HcalCalibDetId.cc:143
HcalZDCDetId::RPD
Definition: HcalZDCDetId.h:23
HcalDetId.h
HcalZDCDetId::Unknown
Definition: HcalZDCDetId.h:23
HcalText2DetIdConverter::flavorName
std::string flavorName
Definition: HcalText2DetIdConverter.h:50
HcalTrigTowerDetId::Undefined
static const HcalTrigTowerDetId Undefined
Definition: HcalTrigTowerDetId.h:62
HcalTrigTowerDetId::depth
int depth() const
get the depth (zero for LHC Run 1, may be nonzero for later runs)
Definition: HcalTrigTowerDetId.h:58
HcalDetId
Definition: HcalDetId.h:12
HcalCalibDetId::iphi
int iphi() const
get the low-edge iphi (if relevant)
Definition: HcalCalibDetId.cc:104
HcalGenericDetId::HcalGenBarrel
Definition: HcalGenericDetId.h:19
HcalCalibDetId::hcalSubdet
HcalSubdetector hcalSubdet() const
get the HcalSubdetector (if relevant)
Definition: HcalCalibDetId.cc:90
HcalCalibDetId::LASERMON
Definition: HcalCalibDetId.h:53
HcalText2DetIdConverter::init
bool init(const std::string &fFlavor, const std::string &fField1, const std::string &fField2, const std::string &fField3)
Definition: HcalText2DetIdConverter.cc:187
HcalCalibDetId::calibFlavor
CalibDetType calibFlavor() const
get the flavor of this calibration detid
Definition: HcalCalibDetId.h:77
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalSubdetector
HcalSubdetector
Definition: HcalAssistant.h:31
eostools.rm
def rm(path, rec=False)
Definition: eostools.py:363
HcalForward
Definition: HcalAssistant.h:36
HcalText2DetIdConverter::getField
int getField(int i) const
Definition: HcalText2DetIdConverter.cc:278
HcalCalibDetId::HOCrosstalk
Definition: HcalCalibDetId.h:50
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
HcalGenericDetId::isHcalDetId
bool isHcalDetId() const
Definition: HcalGenericDetId.cc:64
HcalText2DetIdConverter::toString
std::string toString() const
Definition: HcalText2DetIdConverter.cc:308
HcalEndcap
Definition: HcalAssistant.h:34
HcalTrigTowerDetId::iphi
int iphi() const
get the tower iphi
Definition: HcalTrigTowerDetId.h:56
HcalGenericDetId::genericSubdet
HcalGenericSubdetector genericSubdet() const
Definition: HcalGenericDetId.cc:21
Exception
Definition: hltDiff.cc:245
hgcalPlots.section
section
Definition: hgcalPlots.py:2679
HcalCalibDetId::cboxChannel
int cboxChannel() const
get the calibration box channel (if relevant)
Definition: HcalCalibDetId.cc:86
HcalCalibDetId::rm
int rm() const
get the rm (where relevant)
Definition: HcalCalibDetId.cc:147
Exception.h
HcalZDCDetId::LUM
Definition: HcalZDCDetId.h:23
sd
double sd
Definition: CascadeWrapper.h:113
HcalGenericDetId::HcalGenOuter
Definition: HcalGenericDetId.h:21
mps_fire.result
result
Definition: mps_fire.py:311
HcalText2DetIdConverter::isHcalZDCDetId
bool isHcalZDCDetId() const
Definition: HcalText2DetIdConverter.cc:62
HcalCalibDetId::CalibrationBox
Definition: HcalCalibDetId.h:49
HcalCalibDetId::fiber
int fiber() const
get the fiber (where relevant)
Definition: HcalCalibDetId.cc:145
HcalText2DetIdConverter::isHcalDetId
bool isHcalDetId() const
Definition: HcalText2DetIdConverter.cc:56
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
HcalGenericDetId::HcalGenForward
Definition: HcalGenericDetId.h:22
HcalZDCDetId::section
Section section() const
get the section
Definition: HcalZDCDetId.cc:44
HcalZDCDetId::EM
Definition: HcalZDCDetId.h:23
HcalText2DetIdConverter.h
HcalTrigTowerDetId
Definition: HcalTrigTowerDetId.h:14