CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
HcalText2DetIdConverter Class Reference

#include <HcalText2DetIdConverter.h>

Public Member Functions

int getField (int i) const
 
const std::string & getField1 () const
 
const std::string & getField2 () const
 
const std::string & getField3 () const
 
const std::string & getFlavor () const
 
DetId getId () const
 
 HcalText2DetIdConverter (const std::string &fFlavor="NA", const std::string &fField1="0", const std::string &fField2="0", const std::string &fField3="0")
 
 HcalText2DetIdConverter (DetId fId)
 
bool isHcalCalibDetId () const
 
bool isHcalDetId () const
 
bool isHcalTrigTowerDetId () const
 
bool isHcalZDCDetId () const
 
std::string toString () const
 

Private Member Functions

bool init (const std::string &fFlavor, const std::string &fField1, const std::string &fField2, const std::string &fField3)
 
bool init (DetId fId)
 
void setField (int i, int fValue)
 

Private Attributes

std::string field1
 
std::string field2
 
std::string field3
 
std::string flavorName
 
DetId mId
 

Detailed Description

Author
F.Ratnikov, UMd Converts any flavour of HcalDetId to/from ascii strings

For Calibration DetIds:

Flavor = "CALIB_[HB|HE|HO|HF]" or "HOX"

fField1 is ieta (-2:2 for CALIB) fField2 is iphi fField3 is ctype (CALIB only)

Author
F.Ratnikov, UMd

Definition at line 21 of file HcalText2DetIdConverter.h.

Constructor & Destructor Documentation

◆ HcalText2DetIdConverter() [1/2]

HcalText2DetIdConverter::HcalText2DetIdConverter ( const std::string &  fFlavor = "NA",
const std::string &  fField1 = "0",
const std::string &  fField2 = "0",
const std::string &  fField3 = "0" 
)

Definition at line 41 of file HcalText2DetIdConverter.cc.

References DMR_cfg::cerr, Exception, and init().

44  {
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 }
bool init(const std::string &fFlavor, const std::string &fField1, const std::string &fField2, const std::string &fField3)

◆ HcalText2DetIdConverter() [2/2]

HcalText2DetIdConverter::HcalText2DetIdConverter ( DetId  fId)

Definition at line 54 of file HcalText2DetIdConverter.cc.

References init().

54 { init(fId); }
bool init(const std::string &fFlavor, const std::string &fField1, const std::string &fField2, const std::string &fField3)

Member Function Documentation

◆ getField()

int HcalText2DetIdConverter::getField ( int  i) const

Definition at line 278 of file HcalText2DetIdConverter.cc.

References DMR_cfg::cerr, field1, field2, field3, mps_fire::i, isHcalCalibDetId(), and mps_fire::result.

Referenced by init().

278  {
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 }

◆ getField1()

const std::string& HcalText2DetIdConverter::getField1 ( ) const
inline

Definition at line 36 of file HcalText2DetIdConverter.h.

References field1.

36 { return field1; }

◆ getField2()

const std::string& HcalText2DetIdConverter::getField2 ( ) const
inline

Definition at line 37 of file HcalText2DetIdConverter.h.

References field2.

37 { return field2; }

◆ getField3()

const std::string& HcalText2DetIdConverter::getField3 ( ) const
inline

Definition at line 38 of file HcalText2DetIdConverter.h.

References field3.

38 { return field3; }

◆ getFlavor()

const std::string& HcalText2DetIdConverter::getFlavor ( ) const
inline

Definition at line 35 of file HcalText2DetIdConverter.h.

References flavorName.

35 { return flavorName; }

◆ getId()

DetId HcalText2DetIdConverter::getId ( ) const
inline

Definition at line 39 of file HcalText2DetIdConverter.h.

References mId.

◆ init() [1/2]

bool HcalText2DetIdConverter::init ( const std::string &  fFlavor,
const std::string &  fField1,
const std::string &  fField2,
const std::string &  fField3 
)
private

Definition at line 187 of file HcalText2DetIdConverter.cc.

References HcalCalibDetId::CastorRadFacility, DMR_cfg::cerr, HcalZDCDetId::EM, field1, field2, field3, flavorName, getField(), HcalZDCDetId::HAD, HcalCalibDetId::HBX, HcalBarrel, HcalEndcap, HcalForward, HcalOther, HcalOuter, HcalCalibDetId::HEX, HcalCalibDetId::HOCrosstalk, hcalRecHitTable_cff::ieta, hcalRecHitTable_cff::iphi, HcalCalibDetId::LASERMON, HcalZDCDetId::LUM, mId, mps_fire::result, eostools::rm(), HcalZDCDetId::RPD, hgcalPlots::section, nano_mu_digi_cff::strip, HcalCalibDetId::uMNqie, HcalDetId::Undefined, and HcalZDCDetId::Unknown.

Referenced by HcalText2DetIdConverter().

190  {
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 }
def rm(path, rec=False)
Definition: eostools.py:363
static const HcalDetId Undefined
Definition: HcalDetId.h:273
HcalSubdetector
Definition: HcalAssistant.h:31

◆ init() [2/2]

bool HcalText2DetIdConverter::init ( DetId  fId)
private

Definition at line 64 of file HcalText2DetIdConverter.cc.

References HcalCalibDetId::calibFlavor(), HcalCalibDetId::CalibrationBox, HcalCalibDetId::CastorRadFacility, HcalCalibDetId::cboxChannel(), DMR_cfg::cerr, HcalZDCDetId::channel(), HcalCalibDetId::channel(), HcalTrigTowerDetId::depth(), HcalDetId::depth(), HcalZDCDetId::EM, HcalCalibDetId::fiber(), flavorName, HcalGenericDetId::genericSubdet(), HcalZDCDetId::HAD, HcalCalibDetId::HBX, HcalBarrel, HcalEndcap, HcalForward, HcalGenericDetId::HcalGenBarrel, HcalGenericDetId::HcalGenEndcap, HcalGenericDetId::HcalGenForward, HcalGenericDetId::HcalGenOuter, HcalOuter, HcalCalibDetId::hcalSubdet(), HcalCalibDetId::HEX, HcalCalibDetId::HOCrosstalk, HcalTrigTowerDetId::ieta(), HcalCalibDetId::ieta(), HcalDetId::ieta(), HcalTrigTowerDetId::iphi(), HcalCalibDetId::iphi(), HcalDetId::iphi(), HcalGenericDetId::isHcalCalibDetId(), HcalGenericDetId::isHcalDetId(), HcalGenericDetId::isHcalTrigTowerDetId(), HcalGenericDetId::isHcalZDCDetId(), HcalCalibDetId::LASERMON, HcalZDCDetId::LUM, mId, DetId::rawId(), mps_fire::result, HcalCalibDetId::rm(), HcalZDCDetId::RPD, HcalZDCDetId::section(), setField(), HcalCalibDetId::uMNqie, HcalTrigTowerDetId::Undefined, HcalDetId::Undefined, HcalTrigTowerDetId::version(), and HcalZDCDetId::zside().

64  {
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);
73  flavorName = genId.genericSubdet() == HcalGenericDetId::HcalGenBarrel ? "HB"
74  : genId.genericSubdet() == HcalGenericDetId::HcalGenEndcap ? "HE"
75  : genId.genericSubdet() == HcalGenericDetId::HcalGenOuter ? "HO"
76  : genId.genericSubdet() == HcalGenericDetId::HcalGenForward ? "HF"
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 }
static const HcalDetId Undefined
Definition: HcalDetId.h:273
void setField(int i, int fValue)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static const HcalTrigTowerDetId Undefined

◆ isHcalCalibDetId()

bool HcalText2DetIdConverter::isHcalCalibDetId ( ) const

◆ isHcalDetId()

bool HcalText2DetIdConverter::isHcalDetId ( ) const

◆ isHcalTrigTowerDetId()

bool HcalText2DetIdConverter::isHcalTrigTowerDetId ( ) const

◆ isHcalZDCDetId()

bool HcalText2DetIdConverter::isHcalZDCDetId ( ) const

◆ setField()

void HcalText2DetIdConverter::setField ( int  i,
int  fValue 
)
private

Definition at line 297 of file HcalText2DetIdConverter.cc.

References edmScanValgrind::buffer, field1, field2, field3, and mps_fire::i.

Referenced by init().

297  {
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 }

◆ toString()

std::string HcalText2DetIdConverter::toString ( ) const

Definition at line 308 of file HcalText2DetIdConverter.cc.

References field1, field2, field3, and flavorName.

Referenced by HcalDbXml::dumpObject().

308  {
309  return flavorName + " " + field1 + " " + field2 + " " + field3;
310 }

Member Data Documentation

◆ field1

std::string HcalText2DetIdConverter::field1
private

Definition at line 51 of file HcalText2DetIdConverter.h.

Referenced by getField(), getField1(), init(), setField(), and toString().

◆ field2

std::string HcalText2DetIdConverter::field2
private

Definition at line 52 of file HcalText2DetIdConverter.h.

Referenced by getField(), getField2(), init(), setField(), and toString().

◆ field3

std::string HcalText2DetIdConverter::field3
private

Definition at line 53 of file HcalText2DetIdConverter.h.

Referenced by getField(), getField3(), init(), setField(), and toString().

◆ flavorName

std::string HcalText2DetIdConverter::flavorName
private

Definition at line 50 of file HcalText2DetIdConverter.h.

Referenced by getFlavor(), init(), and toString().

◆ mId

DetId HcalText2DetIdConverter::mId
private