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::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 MessageLogger_cfi::cerr, and Exception.

42  {
43  if (!init (fFlavor, fField1, fField2, fField3)) {
44  std::cerr << "HcalText2DetIdConverter::HcalText2DetIdConverter-> Can not initiate detId from items: "
45  << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
46  throw cms::Exception("HcalGenDetId initialization error")
47  << " Can not initiate detId from items: "
48  << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
49  }
50 }
Definition: init.py:1
HcalText2DetIdConverter::HcalText2DetIdConverter ( DetId  fId)

Definition at line 52 of file HcalText2DetIdConverter.cc.

References init().

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

Member Function Documentation

int HcalText2DetIdConverter::getField ( int  i) const

Definition at line 278 of file HcalText2DetIdConverter.cc.

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

Referenced by getId(), init(), and XMLDocument::makeChId().

278  {
279  char* endptr;
280  const char* nptr = i == 1 ? field1.c_str() :
281  i == 2 ? field2.c_str() : field3.c_str();
282  long result = strtol (nptr, &endptr, 0);
283  if (*nptr != '\0' && *endptr == '\0') {
284  return result;
285  }
286  if (i == 2 && isHcalCalibDetId ()) {
287  int result = calibChannel (field2);
288  if (i) return result;
289  }
290  if (*nptr != '\0') {
291  std::cerr << "HcalText2DetIdConverter::getField-> Can not convert string "<< nptr << " to int. Bad symbol: " << *endptr << std::endl;
292  }
293  return 0;
294  }
const std::string& HcalText2DetIdConverter::getField1 ( ) const
inline
const std::string& HcalText2DetIdConverter::getField2 ( ) const
inline
const std::string& HcalText2DetIdConverter::getField3 ( ) const
inline
const std::string& HcalText2DetIdConverter::getFlavor ( ) const
inline
DetId HcalText2DetIdConverter::getId ( ) const
inline
bool HcalText2DetIdConverter::init ( const std::string &  fFlavor,
const std::string &  fField1,
const std::string &  fField2,
const std::string &  fField3 
)
private

Definition at line 182 of file HcalText2DetIdConverter.cc.

References HcalCalibDetId::CastorRadFacility, MessageLogger_cfi::cerr, HcalZDCDetId::EM, field1, field2, field3, flavorName, getField(), HcalZDCDetId::HAD, HcalCalibDetId::HBX, HcalBarrel, HcalEndcap, HcalForward, HcalOther, HcalOuter, HcalCalibDetId::HEX, HcalCalibDetId::HOCrosstalk, HcalCalibDetId::LASERMON, HcalZDCDetId::LUM, mId, mps_fire::result, submit::rm, HcalZDCDetId::RPD, sd, trackingPlots::section, digitizers_cfi::strip, HcalCalibDetId::uMNqie, HcalDetId::Undefined, and HcalZDCDetId::Unknown.

Referenced by getId(), and HcalText2DetIdConverter().

183  {
184  bool result = true;
185  flavorName = strip (fFlavor);
186  field1 = strip (fField1);
187  field2 = strip (fField2);
188  field3 = strip (fField3);
189  if (flavorName == "HB" ||
190  flavorName == "HE" ||
191  flavorName == "HF" ||
192  flavorName == "HO") {
193  HcalSubdetector sub = flavorName == "HB" ? HcalBarrel :
194  flavorName == "HE" ? HcalEndcap :
195  flavorName == "HO" ? HcalOuter :
196  HcalForward;
197  mId = HcalDetId (sub, getField (1), getField (2), getField (3));
198  }
199  else if (flavorName == "HT") {
200  // We use the depth to signal the "version" being used (RCT or 1x1 HF). RCT
201  // has a 0 in the 10s digit, whereas 1x1 has a 1. The ones digit is still
202  // used to indicate depth, although in the 1x1 case this must be 0, so we
203  // set it as such.
204  mId = HcalTrigTowerDetId (getField (1), getField (2), getField (3));
205 /*
206  const int depth_field = getField(3);
207  const int ones = depth_field % 10;
208  const int tens = (depth_field - ones) / 10;
209  if (tens == 0) {
210  const int depth = ones;
211  const int version = 0;
212  mId = HcalTrigTowerDetId (getField (1), getField (2), depth, version);
213  } else if (tens == 1) {
214  const int depth = 0;
215  const int version = 1;
216  mId = HcalTrigTowerDetId(getField(1), getField(2), depth, version);
217  } else {
218  // Undefined version!
219  }
220 */
221  }
222  else if (flavorName.find ("ZDC_") == 0) {
224  if(flavorName == "ZDC_EM") section = HcalZDCDetId::EM;
225  else if(flavorName == "ZDC_HAD") section = HcalZDCDetId::HAD;
226  else if(flavorName == "ZDC_LUM") section = HcalZDCDetId::LUM;
227  else if(flavorName == "ZDC_RPD") section = HcalZDCDetId::RPD;
228  mId = HcalZDCDetId (section, getField (1)>0, getField (2));
229  }
230  else if (flavorName.find ("CALIB_") == 0) {
232  if (flavorName.find("HB")!=std::string::npos) sd=HcalBarrel;
233  else if (flavorName.find("HE")!=std::string::npos) sd=HcalEndcap;
234  else if (flavorName.find("HO")!=std::string::npos) sd=HcalOuter;
235  else if (flavorName.find("HF")!=std::string::npos) sd=HcalForward;
236 
237  int ieta=getField(1);
238  int iphi=getField(2);
239  int channel = calibChannel (field3);
240  mId = HcalCalibDetId (sd, ieta,iphi,channel);
241  }
242  else if (flavorName=="HOX" || flavorName=="HBX" || flavorName=="HEX") {
243  int ieta=getField(1);
244  int iphi=getField(2);
245  mId = (flavorName=="HOX")?
247  ((flavorName=="HBX")?(HcalCalibDetId(HcalCalibDetId::HBX,ieta,iphi)):
249  );
250  }
251  else if (flavorName=="UMNQIE") {
252  int channel=getField(1);
254  }
255  else if (flavorName == "LASMON" ) {
256  int ieta = getField(1);
257  int iphi = getField(2);
258  int channel = getField(3);
259  mId = HcalCalibDetId (HcalCalibDetId::LASERMON, ieta, iphi, channel);
260  }
261  else if (flavorName=="CRF") {
262  int rm=getField(1);
263  int fiber=getField(2);
264  int channel=getField(3);
266  }
267  else if (flavorName == "NA") {
269  }
270  else {
271  std::cerr << "HcalText2DetIdConverter::init-> Unknown HcalDetId flavor: " << flavorName << std::endl;
272  result = false;
273  }
274  return result;
275 }
static const HcalDetId Undefined
Definition: HcalDetId.h:272
HcalSubdetector
Definition: HcalAssistant.h:31
double sd
rm
Definition: submit.py:77
bool HcalText2DetIdConverter::init ( DetId  fId)
private

Definition at line 72 of file HcalText2DetIdConverter.cc.

References HcalCalibDetId::calibFlavor(), HcalCalibDetId::CalibrationBox, HcalCalibDetId::CastorRadFacility, HcalCalibDetId::cboxChannel(), MessageLogger_cfi::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().

72  {
73  bool result = true;
74  flavorName = "UNKNOWN";
75  mId = fId;
76  HcalGenericDetId genId (mId);
77  if (fId == HcalDetId::Undefined) {
78  flavorName = "NA";
79  }
80  else if (genId.isHcalDetId ()) {
81  HcalDetId hcalId (mId);
82  flavorName = genId.genericSubdet () == HcalGenericDetId::HcalGenBarrel ? "HB" :
83  genId.genericSubdet () == HcalGenericDetId::HcalGenEndcap ? "HE" :
84  genId.genericSubdet () == HcalGenericDetId::HcalGenOuter ? "HO" :
85  genId.genericSubdet () == HcalGenericDetId::HcalGenForward ? "HF" : "H_UNKNOWN";
86  setField (1, hcalId.ieta());
87  setField (2, hcalId.iphi());
88  setField (3, hcalId.depth());
89  }
90  else if (genId.isHcalTrigTowerDetId ()) {
91  HcalTrigTowerDetId triggerId (mId);
92  if (triggerId == HcalTrigTowerDetId::Undefined) {
93  flavorName = "NT";
94  }
95  else {
96  flavorName = "HT";
97  setField (1, triggerId.ieta());
98  setField (2, triggerId.iphi());
99  setField (3, triggerId.version()*10 + triggerId.depth());
100 /*
101  if (triggerId.version() == 0) {
102  setField (1, triggerId.ieta());
103  setField (2, triggerId.iphi());
104  setField (3, 1);
105  } else if (triggerId.version() == 1) {
106  setField (1, triggerId.ieta());
107  setField (2, triggerId.iphi());
108  setField (3, 10); // We use the tens digit to indicate version
109  } else {
110  // Unknown version
111  }
112 */
113  }
114  }
115  else if (genId.isHcalZDCDetId ()) {
116  HcalZDCDetId zdcId (mId);
117  switch (zdcId.section()) {
118  case HcalZDCDetId::EM: flavorName = "ZDC_EM"; break;
119  case HcalZDCDetId::HAD: flavorName = "ZDC_HAD"; break;
120  case HcalZDCDetId::LUM: flavorName = "ZDC_LUM"; break;
121  case HcalZDCDetId::RPD: flavorName = "ZDC_RPD"; break;
122  default: result = false;
123  }
124  setField (1, zdcId.zside());
125  setField (2, zdcId.channel());
126  setField (3, -99);
127  }
128  else if (genId.isHcalCalibDetId ()) {
129  HcalCalibDetId calibId (mId);
130  if (calibId.calibFlavor()==HcalCalibDetId::CalibrationBox) {
131  switch (calibId.hcalSubdet()) {
132  case HcalBarrel: flavorName = "CALIB_HB"; break;
133  case HcalEndcap: flavorName = "CALIB_HE"; break;
134  case HcalOuter: flavorName = "CALIB_HO"; break;
135  case HcalForward: flavorName = "CALIB_HF"; break;
136  default: result = false;
137  }
138  setField (1, calibId.ieta());
139  setField (2, calibId.iphi());
140  setField (3, calibId.cboxChannel() );
141  } else if (calibId.calibFlavor()==HcalCalibDetId::HOCrosstalk) {
142  flavorName="HOX";
143  setField (1, calibId.ieta());
144  setField (2, calibId.iphi());
145  setField (3, -999);
146  } else if (calibId.calibFlavor()==HcalCalibDetId::uMNqie) {
147  flavorName="UMNQIE";
148  setField (1, calibId.channel());
149  setField (2, -999);
150  setField (3, -999);
151  } else if (calibId.calibFlavor()==HcalCalibDetId::LASERMON) {
152  flavorName="LASMON";
153  setField (1, calibId.ieta());
154  setField (2, calibId.iphi());
155  setField (3, calibId.cboxChannel() );
156  } else if (calibId.calibFlavor()==HcalCalibDetId::CastorRadFacility) {
157  flavorName="CRF";
158  setField (1, calibId.rm());
159  setField (2, calibId.fiber());
160  setField (3, calibId.channel());
161  } else if ( calibId.calibFlavor()==HcalCalibDetId::HBX) {
162  flavorName="HBX";
163  setField (1, calibId.ieta());
164  setField (2, calibId.iphi());
165  setField (3, -999);
166  } else if ( calibId.calibFlavor()==HcalCalibDetId::HEX) {
167  flavorName="HEX";
168  setField (1, calibId.ieta());
169  setField (2, calibId.iphi());
170  setField (3, -999);
171  }
172  }
173  else {
174  flavorName = "UNKNOWN_FLAVOR";
175  std::cerr << "HcalText2DetIdConverter::init-> Unknown detId: " << std::hex << std::showbase << mId.rawId() << std::endl;
176  result = false;
177  }
178  return result;
179 }
static const HcalDetId Undefined
Definition: HcalDetId.h:272
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
void setField(int i, int fValue)
static const HcalTrigTowerDetId Undefined
bool HcalText2DetIdConverter::isHcalCalibDetId ( ) const
bool HcalText2DetIdConverter::isHcalDetId ( ) const
bool HcalText2DetIdConverter::isHcalTrigTowerDetId ( ) const
bool HcalText2DetIdConverter::isHcalZDCDetId ( ) const
void HcalText2DetIdConverter::setField ( int  i,
int  fValue 
)
private

Definition at line 296 of file HcalText2DetIdConverter.cc.

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

Referenced by getId(), and init().

296  {
297  char buffer [128];
298  sprintf (buffer, "%d", fValue);
299  if (i == 1) field1 = buffer;
300  else if (i == 2) field2 = buffer;
301  else field3 = buffer;
302 }
std::string HcalText2DetIdConverter::toString ( ) const

Definition at line 304 of file HcalText2DetIdConverter.cc.

References field1, field2, field3, and flavorName.

Referenced by HcalDbXml::dumpObject(), and getId().

304  {
305  return flavorName + " " + field1 + " " + field2 + " " + field3;
306 }

Member Data Documentation

std::string HcalText2DetIdConverter::field1
private

Definition at line 48 of file HcalText2DetIdConverter.h.

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

std::string HcalText2DetIdConverter::field2
private

Definition at line 49 of file HcalText2DetIdConverter.h.

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

std::string HcalText2DetIdConverter::field3
private

Definition at line 50 of file HcalText2DetIdConverter.h.

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

std::string HcalText2DetIdConverter::flavorName
private

Definition at line 47 of file HcalText2DetIdConverter.h.

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

DetId HcalText2DetIdConverter::mId
private