CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 ecal_dqm_sourceclient-live_cfg::cerr, Exception, and init().

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 }
bool init(const std::string &fFlavor, const std::string &fField1, const std::string &fField2, const std::string &fField3)
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 230 of file HcalText2DetIdConverter.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, field1, field2, field3, isHcalCalibDetId(), and query::result.

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

230  {
231  char* endptr;
232  const char* nptr = i == 1 ? field1.c_str() :
233  i == 2 ? field2.c_str() : field3.c_str();
234  long result = strtol (nptr, &endptr, 0);
235  if (*nptr != '\0' && *endptr == '\0') {
236  return result;
237  }
238  if (i == 2 && isHcalCalibDetId ()) {
239  int result = calibChannel (field2);
240  if (i) return result;
241  }
242  if (*nptr != '\0') {
243  std::cerr << "HcalText2DetIdConverter::getField-> Can not convert string "<< nptr << " to int. Bad symbol: " << *endptr << std::endl;
244  }
245  return 0;
246  }
int i
Definition: DBlmapReader.cc:9
tuple result
Definition: query.py:137
const std::string& HcalText2DetIdConverter::getField1 ( ) const
inline

Definition at line 35 of file HcalText2DetIdConverter.h.

References field1.

35 {return field1;}
const std::string& HcalText2DetIdConverter::getField2 ( ) const
inline

Definition at line 36 of file HcalText2DetIdConverter.h.

References field2.

Referenced by XMLDocument::makeChId().

36 {return field2;}
const std::string& HcalText2DetIdConverter::getField3 ( ) const
inline

Definition at line 37 of file HcalText2DetIdConverter.h.

References field3.

Referenced by XMLDocument::makeChId().

37 {return field3;}
const std::string& HcalText2DetIdConverter::getFlavor ( ) const
inline

Definition at line 34 of file HcalText2DetIdConverter.h.

References flavorName.

Referenced by HcalDQMDbInterface::createChannel(), and XMLDocument::makeChId().

34 {return flavorName;}
DetId HcalText2DetIdConverter::getId ( ) const
inline

Definition at line 38 of file HcalText2DetIdConverter.h.

References mId.

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

Definition at line 156 of file HcalText2DetIdConverter.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, HcalZDCDetId::EM, field1, field2, field3, flavorName, getField(), HcalZDCDetId::HAD, HcalBarrel, HcalEndcap, HcalForward, HcalOther, HcalOuter, HcalZDCDetId::LUM, mId, query::result, sd, HcalDetId::Undefined, and HcalZDCDetId::Unknown.

Referenced by HcalText2DetIdConverter().

157  {
158  bool result = true;
159  flavorName = strip (fFlavor);
160  field1 = strip (fField1);
161  field2 = strip (fField2);
162  field3 = strip (fField3);
163  if (flavorName == "HB" ||
164  flavorName == "HE" ||
165  flavorName == "HF" ||
166  flavorName == "HO") {
167  HcalSubdetector sub = flavorName == "HB" ? HcalBarrel :
168  flavorName == "HE" ? HcalEndcap :
169  flavorName == "HO" ? HcalOuter :
170  HcalForward;
171  mId = HcalDetId (sub, getField (1), getField (2), getField (3));
172  }
173  else if (flavorName == "HT") {
174  // We use the depth to signal the "version" being used (RCT or 1x1 HF). RCT
175  // has a 0 in the 10s digit, whereas 1x1 has a 1. The ones digit is still
176  // used to indicate depth, although in the 1x1 case this must be 0, so we
177  // set it as such.
178  mId = HcalTrigTowerDetId (getField (1), getField (2), getField (3));
179 /*
180  const int depth_field = getField(3);
181  const int ones = depth_field % 10;
182  const int tens = (depth_field - ones) / 10;
183  if (tens == 0) {
184  const int depth = ones;
185  const int version = 0;
186  mId = HcalTrigTowerDetId (getField (1), getField (2), depth, version);
187  } else if (tens == 1) {
188  const int depth = 0;
189  const int version = 1;
190  mId = HcalTrigTowerDetId(getField(1), getField(2), depth, version);
191  } else {
192  // Undefined version!
193  }
194 */
195  }
196  else if (flavorName.find ("ZDC_") == 0) {
197  HcalZDCDetId::Section section = flavorName == "ZDC_EM" ? HcalZDCDetId::EM :
198  flavorName == "ZDC_HAD" ? HcalZDCDetId::HAD :
200  mId = HcalZDCDetId (section, getField (1)>0, getField (2));
201  }
202  else if (flavorName.find ("CALIB_") == 0) {
204  if (flavorName.find("HB")!=std::string::npos) sd=HcalBarrel;
205  else if (flavorName.find("HE")!=std::string::npos) sd=HcalEndcap;
206  else if (flavorName.find("HO")!=std::string::npos) sd=HcalOuter;
207  else if (flavorName.find("HF")!=std::string::npos) sd=HcalForward;
208 
209  int ieta=getField(1);
210  int iphi=getField(2);
211  int channel = calibChannel (field3);
212  mId = HcalCalibDetId (sd, ieta,iphi,channel);
213  }
214  else if (flavorName=="HOX") {
215  int ieta=getField(1);
216  int iphi=getField(2);
217  mId = HcalCalibDetId (ieta,iphi);
218  }
219  else if (flavorName == "NA") {
221  }
222  else {
223  std::cerr << "HcalText2DetIdConverter::init-> Unknown HcalDetId flavor: " << flavorName << std::endl;
224  result = false;
225  }
226  return result;
227 }
static const HcalDetId Undefined
Definition: HcalDetId.h:80
tuple result
Definition: query.py:137
HcalSubdetector
Definition: HcalAssistant.h:31
double sd
bool HcalText2DetIdConverter::init ( DetId  fId)
private

Definition at line 72 of file HcalText2DetIdConverter.cc.

References HcalCalibDetId::calibFlavor(), HcalCalibDetId::CalibrationBox, HcalCalibDetId::cboxChannel(), ecal_dqm_sourceclient-live_cfg::cerr, HcalZDCDetId::channel(), HcalTrigTowerDetId::depth(), HcalDetId::depth(), HcalZDCDetId::EM, flavorName, HcalGenericDetId::genericSubdet(), HcalZDCDetId::HAD, HcalBarrel, HcalEndcap, HcalForward, HcalGenericDetId::HcalGenBarrel, HcalGenericDetId::HcalGenEndcap, HcalGenericDetId::HcalGenForward, HcalGenericDetId::HcalGenOuter, HcalOuter, HcalCalibDetId::hcalSubdet(), HcalCalibDetId::HOCrosstalk, HcalCalibDetId::ieta(), HcalTrigTowerDetId::ieta(), HcalDetId::ieta(), HcalTrigTowerDetId::iphi(), HcalCalibDetId::iphi(), HcalDetId::iphi(), HcalGenericDetId::isHcalCalibDetId(), HcalGenericDetId::isHcalDetId(), HcalGenericDetId::isHcalTrigTowerDetId(), HcalGenericDetId::isHcalZDCDetId(), HcalZDCDetId::LUM, mId, DetId::rawId(), query::result, HcalZDCDetId::section(), setField(), 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  default: result = false;
122  }
123  setField (1, zdcId.zside());
124  setField (2, zdcId.channel());
125  setField (3, -99);
126  }
127  else if (genId.isHcalCalibDetId ()) {
128  HcalCalibDetId calibId (mId);
129  if (calibId.calibFlavor()==HcalCalibDetId::CalibrationBox) {
130  switch (calibId.hcalSubdet()) {
131  case HcalBarrel: flavorName = "CALIB_HB"; break;
132  case HcalEndcap: flavorName = "CALIB_HE"; break;
133  case HcalOuter: flavorName = "CALIB_HO"; break;
134  case HcalForward: flavorName = "CALIB_HF"; break;
135  default: result = false;
136  }
137  setField (1, calibId.ieta());
138  setField (2, calibId.iphi());
139  setField (3, calibId.cboxChannel() );
140  } else if (calibId.calibFlavor()==HcalCalibDetId::HOCrosstalk) {
141  flavorName="HOX";
142  setField (1, calibId.ieta());
143  setField (2, calibId.iphi());
144  setField (3, -999);
145  }
146  }
147  else {
148  flavorName = "UNKNOWN_FLAVOR";
149  std::cerr << "HcalText2DetIdConverter::init-> Unknown detId: " << std::hex << std::showbase << mId.rawId() << std::endl;
150  result = false;
151  }
152  return result;
153 }
static const HcalDetId Undefined
Definition: HcalDetId.h:80
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
void setField(int i, int fValue)
tuple result
Definition: query.py:137
static const HcalTrigTowerDetId Undefined
bool HcalText2DetIdConverter::isHcalCalibDetId ( ) const

Definition at line 60 of file HcalText2DetIdConverter.cc.

References HcalGenericDetId::isHcalCalibDetId(), and mId.

Referenced by getField().

bool HcalText2DetIdConverter::isHcalDetId ( ) const
bool HcalText2DetIdConverter::isHcalTrigTowerDetId ( ) const
bool HcalText2DetIdConverter::isHcalZDCDetId ( ) const
void HcalText2DetIdConverter::setField ( int  i,
int  fValue 
)
private

Definition at line 248 of file HcalText2DetIdConverter.cc.

References field1, field2, and field3.

Referenced by init().

248  {
249  char buffer [128];
250  sprintf (buffer, "%d", fValue);
251  if (i == 1) field1 = buffer;
252  else if (i == 2) field2 = buffer;
253  else field3 = buffer;
254 }
int i
Definition: DBlmapReader.cc:9
std::string HcalText2DetIdConverter::toString ( ) const

Definition at line 256 of file HcalText2DetIdConverter.cc.

References field1, field2, field3, and flavorName.

Referenced by HcalDbXml::dumpObject().

256  {
257  return flavorName + " " + field1 + " " + field2 + " " + field3;
258 }

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